Flutter Engine
The Flutter Engine
ImageBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
12
14public:
16 fName.set("native_image_to_raster_surface");
17 }
18
19 bool isSuitableFor(Backend backend) override {
21 }
22
23protected:
24 const char* onGetName() override {
25 return fName.c_str();
26 }
27
28 // We explicitly want to bench drawing a Image [cpu or gpu backed] into a raster target,
29 // to ensure that we can cache the read-back in the case of gpu -> raster
30 //
31 void onPerCanvasPreDraw(SkCanvas* canvas) override {
32 // create an Image reflecting the canvas (gpu or cpu)
33 SkImageInfo info = canvas->imageInfo().makeWH(100, 100);
34 auto surface(canvas->makeSurface(info));
35 canvas->drawColor(SK_ColorRED);
36 fImage = surface->makeImageSnapshot();
37
38 // create a cpu-backed Surface
39 SkImageInfo n32Info = SkImageInfo::MakeN32Premul(100, 100);
40 fRasterSurface = SkSurfaces::Raster(n32Info);
41 }
42
43 void onPerCanvasPostDraw(SkCanvas*) override {
44 // Release the image and raster surface here to prevent out of order destruction
45 // between these and the gpu interface.
46 fRasterSurface.reset(nullptr);
47 fImage.reset(nullptr);
48 }
49
50 void onDraw(int loops, SkCanvas*) override {
51 for (int i = 0; i < loops; i++) {
52 for (int inner = 0; inner < 10; ++inner) {
53 fRasterSurface->getCanvas()->drawImage(fImage.get(), 0, 0);
54 }
55 }
56 }
57
58private:
59 SkString fName;
60 sk_sp<SkImage> fImage;
61 sk_sp<SkSurface> fRasterSurface;
62
63 using INHERITED = Benchmark;
64};
65DEF_BENCH( return new Image2RasterBench; )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
const char * onGetName() override
Definition: ImageBench.cpp:24
bool isSuitableFor(Backend backend) override
Definition: ImageBench.cpp:19
void onDraw(int loops, SkCanvas *) override
Definition: ImageBench.cpp:50
void onPerCanvasPostDraw(SkCanvas *) override
Definition: ImageBench.cpp:43
void onPerCanvasPreDraw(SkCanvas *canvas) override
Definition: ImageBench.cpp:31
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
void set(const SkString &src)
Definition: SkString.h:186
const char * c_str() const
Definition: SkString.h:133
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444
static SkImageInfo MakeN32Premul(int width, int height)