skia2/bench/ImageBench.cpp
John Stiles 7571f9e490 Replace 'typedef xxxxx INHERITED' with 'using INHERITED = xxxx;'.
Mechanically updated via Xcode "Replace Regular Expression":

  typedef (.*) INHERITED;
    -->
  using INHERITED = $1;

The ClangTidy approach generated an even larger CL which would have
required a significant amount of hand-tweaking to be usable.

Change-Id: I671dc9d9efdf6d60151325c8d4d13fad7e10a15b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314999
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-03 03:41:26 +00:00

66 lines
2.0 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkSurface.h"
class Image2RasterBench : public Benchmark {
public:
Image2RasterBench() {
fName.set("native_image_to_raster_surface");
}
bool isSuitableFor(Backend backend) override {
return kGPU_Backend == backend || kRaster_Backend == backend;
}
protected:
const char* onGetName() override {
return fName.c_str();
}
// We explicitly want to bench drawing a Image [cpu or gpu backed] into a raster target,
// to ensure that we can cache the read-back in the case of gpu -> raster
//
void onPerCanvasPreDraw(SkCanvas* canvas) override {
// create an Image reflecting the canvas (gpu or cpu)
SkImageInfo info = canvas->imageInfo().makeWH(100, 100);
auto surface(canvas->makeSurface(info));
canvas->drawColor(SK_ColorRED);
fImage = surface->makeImageSnapshot();
// create a cpu-backed Surface
SkImageInfo n32Info = SkImageInfo::MakeN32Premul(100, 100);
fRasterSurface = SkSurface::MakeRaster(n32Info);
}
void onPerCanvasPostDraw(SkCanvas*) override {
// Release the image and raster surface here to prevent out of order destruction
// between these and the gpu interface.
fRasterSurface.reset(nullptr);
fImage.reset(nullptr);
}
void onDraw(int loops, SkCanvas*) override {
for (int i = 0; i < loops; i++) {
for (int inner = 0; inner < 10; ++inner) {
fRasterSurface->getCanvas()->drawImage(fImage.get(), 0, 0);
}
}
}
private:
SkString fName;
sk_sp<SkImage> fImage;
sk_sp<SkSurface> fRasterSurface;
using INHERITED = Benchmark;
};
DEF_BENCH( return new Image2RasterBench; )