Flutter Engine
The Flutter Engine
RepeatTileBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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#include "bench/Benchmark.h"
15#include "tools/ToolUtils.h"
16
17static void draw_into_bitmap(const SkBitmap& bm) {
18 const int w = bm.width();
19 const int h = bm.height();
20
21 SkCanvas canvas(bm);
22 SkPaint p;
23 p.setAntiAlias(true);
24 p.setColor(SK_ColorRED);
26 SkIntToScalar(std::min(w, h))*3/8, p);
27
28 SkRect r;
30 p.setStyle(SkPaint::kStroke_Style);
31 p.setStrokeWidth(SkIntToScalar(4));
32 p.setColor(SK_ColorBLUE);
33 canvas.drawRect(r, p);
34}
35
36class RepeatTileBench : public Benchmark {
37 const SkAlphaType fAlphaType;
38 SkPaint fPaint;
39 SkString fName;
40 SkBitmap fBitmap;
41public:
43 const int w = 50;
44 const int h = 50;
45
46 fBitmap.setInfo(SkImageInfo::Make(w, h, ct, at));
47 fName.printf("repeatTile_%s_%c",
49 kOpaque_SkAlphaType == at ? 'X' : 'A');
50 }
51
52protected:
53 const char* onGetName() override {
54 return fName.c_str();
55 }
56
57 void onDelayedSetup() override {
58 fBitmap.allocPixels();
59 fBitmap.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorWHITE : 0);
60
61 draw_into_bitmap(fBitmap);
62
65 }
66
67
68 void onDraw(int loops, SkCanvas* canvas) override {
69 SkPaint paint(fPaint);
70 this->setupPaint(&paint);
71
72 for (int i = 0; i < loops; i++) {
73 canvas->drawPaint(paint);
74 }
75 }
76
77private:
78 using INHERITED = Benchmark;
79};
80
81DEF_BENCH(return new RepeatTileBench(kN32_SkColorType, kOpaque_SkAlphaType))
82DEF_BENCH(return new RepeatTileBench(kN32_SkColorType, kPremul_SkAlphaType))
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * fName
static void draw_into_bitmap(const SkBitmap &bm)
SkAlphaType
Definition: SkAlphaType.h:26
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Definition: SkColorType.h:19
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
const char * onGetName() override
void onDelayedSetup() override
RepeatTileBench(SkColorType ct, SkAlphaType at=kPremul_SkAlphaType)
void onDraw(int loops, SkCanvas *canvas) override
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
int width() const
Definition: SkBitmap.h:149
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
int height() const
Definition: SkBitmap.h:158
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setShader(sk_sp< SkShader > shader)
const Paint & paint
Definition: color_source.cc:38
static float min(float r, float g, float b)
Definition: hsl.cpp:48
const char * colortype_name(SkColorType ct)
Definition: ToolUtils.cpp:65
SkScalar w
SkScalar h
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
void setWH(float width, float height)
Definition: SkRect.h:944