2015-08-03 21:18:04 +00:00
|
|
|
/*
|
|
|
|
* 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 "Benchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
2015-08-04 15:42:40 +00:00
|
|
|
class Image2RasterBench : public Benchmark {
|
2015-08-03 21:18:04 +00:00
|
|
|
public:
|
2015-08-04 15:42:40 +00:00
|
|
|
Image2RasterBench() {
|
|
|
|
fName.set("native_image_to_raster_surface");
|
2015-08-03 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
2015-08-04 15:42:40 +00:00
|
|
|
return kGPU_Backend == backend || kRaster_Backend == backend;
|
2015-08-03 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-08-04 15:42:40 +00:00
|
|
|
// 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
|
|
|
|
//
|
2015-08-03 21:18:04 +00:00
|
|
|
void onPerCanvasPreDraw(SkCanvas* canvas) override {
|
2015-08-04 15:42:40 +00:00
|
|
|
// create an Image reflecting the canvas (gpu or cpu)
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
2015-08-03 21:18:04 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
|
|
|
|
canvas->drawColor(SK_ColorRED);
|
2015-08-04 15:42:40 +00:00
|
|
|
fImage.reset(surface->newImageSnapshot());
|
2015-08-03 21:18:04 +00:00
|
|
|
|
|
|
|
// create a cpu-backed Surface
|
|
|
|
fRasterSurface.reset(SkSurface::NewRaster(info));
|
|
|
|
}
|
|
|
|
|
2015-11-24 13:50:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2015-08-03 21:18:04 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
for (int inner = 0; inner < 10; ++inner) {
|
2015-08-04 15:42:40 +00:00
|
|
|
fRasterSurface->getCanvas()->drawImage(fImage, 0, 0);
|
2015-08-03 21:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
2015-08-04 15:42:40 +00:00
|
|
|
SkAutoTUnref<SkImage> fImage;
|
2015-08-03 21:18:04 +00:00
|
|
|
SkAutoTUnref<SkSurface> fRasterSurface;
|
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-08-04 15:42:40 +00:00
|
|
|
DEF_BENCH( return new Image2RasterBench; )
|