Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: bench/XfermodeBench.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkString.h" 12 #include "SkString.h"
13 #include "SkXfermode.h" 13 #include "SkXfermode.h"
14 14
15 // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode. 15 // Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
16 class XfermodeBench : public Benchmark { 16 class XfermodeBench : public Benchmark {
17 public: 17 public:
18 XfermodeBench(SkXfermode::Mode mode, bool aa) { 18 XfermodeBench(SkXfermode::Mode mode, bool aa) {
19 fXfermode.reset(SkXfermode::Create(mode)); 19 fXfermode = SkXfermode::Make(mode);
20 fAA = aa; 20 fAA = aa;
21 SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode); 21 SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
22 fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : " "); 22 fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : " ");
23 } 23 }
24 24
25 XfermodeBench(SkXfermode* xferMode, const char* name, bool aa) { 25 XfermodeBench(SkXfermode* xferMode, const char* name, bool aa) {
26 SkASSERT(xferMode); 26 SkASSERT(xferMode);
27 fXfermode.reset(xferMode); 27 fXfermode.reset(xferMode);
28 fAA = aa; 28 fAA = aa;
29 fName.printf("Xfermode_%s%s", name, aa ? "_aa" : ""); 29 fName.printf("Xfermode_%s%s", name, aa ? "_aa" : "");
30 } 30 }
31 31
32 protected: 32 protected:
33 const char* onGetName() override { return fName.c_str(); } 33 const char* onGetName() override { return fName.c_str(); }
34 34
35 void onDraw(int loops, SkCanvas* canvas) override { 35 void onDraw(int loops, SkCanvas* canvas) override {
36 const char* text = "Hamburgefons"; 36 const char* text = "Hamburgefons";
37 size_t len = strlen(text); 37 size_t len = strlen(text);
38 SkISize size = canvas->getDeviceSize(); 38 SkISize size = canvas->getDeviceSize();
39 SkRandom random; 39 SkRandom random;
40 for (int i = 0; i < loops; ++i) { 40 for (int i = 0; i < loops; ++i) {
41 SkPaint paint; 41 SkPaint paint;
42 paint.setXfermode(fXfermode.get()); 42 paint.setXfermode(fXfermode);
43 paint.setColor(random.nextU()); 43 paint.setColor(random.nextU());
44 if (fAA) { 44 if (fAA) {
45 // Draw text to exercise AA code paths. 45 // Draw text to exercise AA code paths.
46 paint.setAntiAlias(true); 46 paint.setAntiAlias(true);
47 paint.setTextSize(random.nextRangeScalar(12, 96)); 47 paint.setTextSize(random.nextRangeScalar(12, 96));
48 SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth), 48 SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
49 y = random.nextRangeScalar(0, (SkScalar)size.fHeight); 49 y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
50 for (int j = 0; j < 1000; ++j) { 50 for (int j = 0; j < 1000; ++j) {
51 canvas->drawText(text, len, x, y, paint); 51 canvas->drawText(text, len, x, y, paint);
52 } 52 }
53 } else { 53 } else {
54 // Draw rects to exercise non-AA code paths. 54 // Draw rects to exercise non-AA code paths.
55 SkScalar w = random.nextRangeScalar(50, 100); 55 SkScalar w = random.nextRangeScalar(50, 100);
56 SkScalar h = random.nextRangeScalar(50, 100); 56 SkScalar h = random.nextRangeScalar(50, 100);
57 SkRect rect = SkRect::MakeXYWH( 57 SkRect rect = SkRect::MakeXYWH(
58 random.nextUScalar1() * (size.fWidth - w), 58 random.nextUScalar1() * (size.fWidth - w),
59 random.nextUScalar1() * (size.fHeight - h), 59 random.nextUScalar1() * (size.fHeight - h),
60 w, 60 w,
61 h 61 h
62 ); 62 );
63 for (int j = 0; j < 1000; ++j) { 63 for (int j = 0; j < 1000; ++j) {
64 canvas->drawRect(rect, paint); 64 canvas->drawRect(rect, paint);
65 } 65 }
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 private: 70 private:
71 SkAutoTUnref<SkXfermode> fXfermode; 71 sk_sp<SkXfermode> fXfermode;
72 SkString fName; 72 SkString fName;
73 bool fAA; 73 bool fAA;
74 74
75 typedef Benchmark INHERITED; 75 typedef Benchmark INHERITED;
76 }; 76 };
77 77
78 class XferCreateBench : public Benchmark { 78 class XferCreateBench : public Benchmark {
79 public: 79 public:
80 bool isSuitableFor(Backend backend) override { 80 bool isSuitableFor(Backend backend) override {
81 return backend == kNonRendering_Backend; 81 return backend == kNonRendering_Backend;
82 } 82 }
83 83
84 protected: 84 protected:
85 const char* onGetName() override { return "xfermode_create"; } 85 const char* onGetName() override { return "xfermode_create"; }
86 86
87 void onDraw(int loops, SkCanvas* canvas) override { 87 void onDraw(int loops, SkCanvas* canvas) override {
88 for (int outer = 0; outer < loops * 10; ++outer) { 88 for (int outer = 0; outer < loops * 10; ++outer) {
89 for (int i = 0; i <= SkXfermode::kLastMode; ++i) { 89 for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
90 SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i)); 90 (void)SkXfermode::Make(SkXfermode::Mode(i));
91 SkSafeUnref(xfer);
92 } 91 }
93 } 92 }
94 } 93 }
95 94
96 private: 95 private:
97 typedef Benchmark INHERITED; 96 typedef Benchmark INHERITED;
98 }; 97 };
99 98
100 ////////////////////////////////////////////////////////////////////////////// 99 //////////////////////////////////////////////////////////////////////////////
101 100
(...skipping 28 matching lines...) Expand all
130 BENCH(SkXfermode::kDifference_Mode) 129 BENCH(SkXfermode::kDifference_Mode)
131 BENCH(SkXfermode::kExclusion_Mode) 130 BENCH(SkXfermode::kExclusion_Mode)
132 BENCH(SkXfermode::kMultiply_Mode) 131 BENCH(SkXfermode::kMultiply_Mode)
133 132
134 BENCH(SkXfermode::kHue_Mode) 133 BENCH(SkXfermode::kHue_Mode)
135 BENCH(SkXfermode::kSaturation_Mode) 134 BENCH(SkXfermode::kSaturation_Mode)
136 BENCH(SkXfermode::kColor_Mode) 135 BENCH(SkXfermode::kColor_Mode)
137 BENCH(SkXfermode::kLuminosity_Mode) 136 BENCH(SkXfermode::kLuminosity_Mode)
138 137
139 DEF_BENCH(return new XferCreateBench;) 138 DEF_BENCH(return new XferCreateBench;)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698