Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ShadowBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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"
10#include "include/core/SkPath.h"
14
15class ShadowBench : public Benchmark {
16// Draws a set of shadowed rrects filling the canvas, in various modes:
17// * opaque or transparent
18// * use analytic fast path or geometric tessellation
19public:
20 ShadowBench(bool transparent, bool forceGeometric)
21 : fTransparent(transparent)
22 , fForceGeometric(forceGeometric) {
23 computeName("shadows");
24 }
25
26protected:
27 enum {
28 kWidth = 640,
29 kHeight = 480,
30 kRRSize = 50,
36 };
37
38 void computeName(const char root[]) {
39 static const char kTransChars[2] = {
40 'o', 't'
41 };
42 static const char kGeomChars[2] = {
43 'a', 'g'
44 };
45
46 fBaseName.printf("%s_%c_%c", root, kTransChars[fTransparent], kGeomChars[fForceGeometric]);
47 }
48
49 void genRRects() {
50 int i = 0;
51 for (int x = kRRSpace; x < kWidth - kRRStep; x += kRRStep) {
52 for (int y = kRRSpace; y < kHeight - kRRStep; y += kRRStep) {
55 ++i;
56 }
57 }
58 SkASSERT(i == kNumRRects);
59 }
60
61 const char* onGetName() override { return fBaseName.c_str(); }
62
63 void onDelayedSetup() override {
65 fRec.fLightPos = SkPoint3::Make(270, 0, 600);
66 fRec.fLightRadius = 800;
67 fRec.fAmbientColor = 0x19000000;
68 fRec.fSpotColor = 0x40000000;
69 fRec.fFlags = 0;
70 if (fTransparent) {
72 }
73 if (fForceGeometric) {
75 }
76
77 this->genRRects();
78 }
79
80 void onDraw(int loops, SkCanvas* canvas) override {
82 paint.setColor(SK_ColorWHITE);
83 this->setupPaint(&paint);
84
85 for (int i = 0; i < loops; ++i) {
86 // use the private canvas call so we don't include the time to stuff data in the Rec
87 canvas->private_draw_shadow_rec(fRRects[i % kNumRRects], fRec);
88 }
89 }
90
91private:
92 SkString fBaseName;
93
94 SkPath fRRects[kNumRRects];
95 SkDrawShadowRec fRec;
96 int fTransparent;
97 int fForceGeometric;
98
99 using INHERITED = Benchmark;
100};
101
102DEF_BENCH(return new ShadowBench(false, false);)
103DEF_BENCH(return new ShadowBench(false, true);)
104DEF_BENCH(return new ShadowBench(true, false);)
105DEF_BENCH(return new ShadowBench(true, true);)
106
#define DEF_BENCH(code)
Definition Benchmark.h:20
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
@ kGeometricOnly_ShadowFlag
@ kTransparentOccluder_ShadowFlag
virtual void setupPaint(SkPaint *paint)
Definition Benchmark.cpp:55
void computeName(const char root[])
void genRRects()
const char * onGetName() override
void onDelayedSetup() override
void onDraw(int loops, SkCanvas *canvas) override
ShadowBench(bool transparent, bool forceGeometric)
void private_draw_shadow_rec(const SkPath &, const SkDrawShadowRec &)
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:990
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
const Paint & paint
double y
double x
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:18
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659