Flutter Engine
The Flutter Engine
MergeBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
10#include "include/core/SkFont.h"
14
15#define FILTER_WIDTH_SMALL SkIntToScalar(32)
16#define FILTER_HEIGHT_SMALL SkIntToScalar(32)
17#define FILTER_WIDTH_LARGE SkIntToScalar(256)
18#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
19
22 surface->getCanvas()->clear(0x00000000);
24 paint.setColor(0xFF884422);
26 font.setSize(SkIntToScalar(96));
27 surface->getCanvas()->drawSimpleText("g", 1, SkTextEncoding::kUTF8, 15, 55, font, paint);
28 return surface->makeImageSnapshot();
29}
30
33 SkCanvas* canvas = surface->getCanvas();
34 canvas->clear(0x00000000);
35 SkPaint darkPaint;
36 darkPaint.setColor(0xFF804020);
37 SkPaint lightPaint;
38 lightPaint.setColor(0xFF244484);
39 for (int y = 0; y < 80; y += 16) {
40 for (int x = 0; x < 80; x += 16) {
41 canvas->save();
43 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
44 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
45 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
46 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
47 canvas->restore();
48 }
49 }
50
51 return surface->makeImageSnapshot();
52}
53
54class MergeBench : public Benchmark {
55public:
56 MergeBench(bool small) : fIsSmall(small), fInitialized(false) { }
57
58protected:
59 const char* onGetName() override {
60 return fIsSmall ? "merge_small" : "merge_large";
61 }
62
63 void onDelayedSetup() override {
64 if (!fInitialized) {
65 fImage = make_bitmap();
66 fCheckerboard = make_checkerboard();
67 fInitialized = true;
68 }
69 }
70
71 void onDraw(int loops, SkCanvas* canvas) override {
75 paint.setImageFilter(SkImageFilters::Merge(
78 for (int i = 0; i < loops; i++) {
79 canvas->drawRect(r, paint);
80 }
81 }
82
83private:
84 bool fIsSmall;
85 bool fInitialized;
86 sk_sp<SkImage> fImage, fCheckerboard;
87
88 using INHERITED = Benchmark;
89};
90
91///////////////////////////////////////////////////////////////////////////////
92
93DEF_BENCH( return new MergeBench(true); )
94DEF_BENCH( return new MergeBench(false); )
#define DEF_BENCH(code)
Definition: Benchmark.h:20
#define FILTER_WIDTH_SMALL
Definition: MergeBench.cpp:15
static sk_sp< SkImage > make_checkerboard()
Definition: MergeBench.cpp:31
#define FILTER_WIDTH_LARGE
Definition: MergeBench.cpp:17
#define FILTER_HEIGHT_SMALL
Definition: MergeBench.cpp:16
static sk_sp< SkImage > make_bitmap()
Definition: MergeBench.cpp:20
#define FILTER_HEIGHT_LARGE
Definition: MergeBench.cpp:18
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SkIntToScalar(x)
Definition: SkScalar.h:57
const char * onGetName() override
Definition: MergeBench.cpp:59
MergeBench(bool small)
Definition: MergeBench.cpp:56
void onDelayedSetup() override
Definition: MergeBench.cpp:63
void onDraw(int loops, SkCanvas *canvas) override
Definition: MergeBench.cpp:71
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
Definition: SkFont.h:35
static sk_sp< SkImageFilter > Merge(sk_sp< SkImageFilter > *const filters, int count, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
void setColor(SkColor color)
Definition: SkPaint.cpp:119
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
double y
double x
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkFont DefaultFont()
font
Font Metadata and Metrics.
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609