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

Side by Side Diff: bench/AlternatingColorPatternBench.cpp

Issue 1798133003: Revert of Finish conversion to sk_sp<SkShader> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | bench/ColorCubeBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 SkScalar s = SkIntToScalar(SkMin32(w, h)); 44 SkScalar s = SkIntToScalar(SkMin32(w, h));
45 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; 45 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
46 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } }; 46 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
47 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 47 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
48 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; 48 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
49 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 }; 49 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 };
50 50
51 51
52 SkPaint paint; 52 SkPaint paint;
53 53
54 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos, SK_ARRAY _COUNT(kColors0), 54 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
55 SkShader::kClamp_TileMode)); 55 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref ();
56 canvas.drawPaint(paint); 56 canvas.drawPaint(paint);
57 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos, SK_ARRAY _COUNT(kColors1), 57 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
58 SkShader::kClamp_TileMode)); 58 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref ();
59 canvas.drawPaint(paint); 59 canvas.drawPaint(paint);
60 } 60 }
61 61
62 /** 62 /**
63 * This bench draws a grid of either rects or filled paths, with two alternating color patterns. 63 * This bench draws a grid of either rects or filled paths, with two alternating color patterns.
64 * This color patterns are passed in as enums to the class. The options are: 64 * This color patterns are passed in as enums to the class. The options are:
65 * 1) solid white color 65 * 1) solid white color
66 * 2) solid blue color 66 * 2) solid blue color
67 * 3) opaque bitmap 67 * 3) opaque bitmap
68 * 4) partial alpha bitmap 68 * 4) partial alpha bitmap
69 * The same color pattern can be set for both arguments to create a uniform patt ern on all draws. 69 * The same color pattern can be set for both arguments to create a uniform patt ern on all draws.
70 * 70 *
71 * The bench is used to test a few things. First it can test any optimizations m ade for a specific 71 * The bench is used to test a few things. First it can test any optimizations m ade for a specific
72 * color pattern (for example drawing an opaque bitmap versus one with partial a lpha). Also it can 72 * color pattern (for example drawing an opaque bitmap versus one with partial a lpha). Also it can
73 * be used to test the cost of program switching and/or batching when alternatin g between different 73 * be used to test the cost of program switching and/or batching when alternatin g between different
74 * patterns when on the gpu. 74 * patterns when on the gpu.
75 */ 75 */
76 class AlternatingColorPatternBench : public Benchmark { 76 class AlternatingColorPatternBench : public Benchmark {
77 public: 77 public:
78 enum { 78 enum {
79 NX = 5, 79 NX = 5,
80 NY = 5, 80 NY = 5,
81 NUM_DRAWS = NX * NY, 81 NUM_DRAWS = NX * NY,
82 }; 82 };
83 sk_sp<SkShader> fBmShader; 83 SkShader* fBmShader;
84 84
85 SkPath fPaths[NUM_DRAWS]; 85 SkPath fPaths[NUM_DRAWS];
86 SkRect fRects[NUM_DRAWS]; 86 SkRect fRects[NUM_DRAWS];
87 SkColor fColors[NUM_DRAWS]; 87 SkColor fColors[NUM_DRAWS];
88 sk_sp<SkShader> fShaders[NUM_DRAWS]; 88 SkShader* fShaders[NUM_DRAWS];
89 89
90 SkString fName; 90 SkString fName;
91 ColorPatternData fPattern1; 91 ColorPatternData fPattern1;
92 ColorPatternData fPattern2; 92 ColorPatternData fPattern2;
93 DrawType fDrawType; 93 DrawType fDrawType;
94 SkBitmap fBmp; 94 SkBitmap fBmp;
95 95
96 96
97 AlternatingColorPatternBench(ColorPattern pattern1, ColorPattern pattern2, D rawType drawType) { 97 AlternatingColorPatternBench(ColorPattern pattern1, ColorPattern pattern2, D rawType drawType)
98 : fBmShader(nullptr) {
98 fPattern1 = gColorPatterns[pattern1]; 99 fPattern1 = gColorPatterns[pattern1];
99 fPattern2 = gColorPatterns[pattern2]; 100 fPattern2 = gColorPatterns[pattern2];
100 fName.printf("colorPattern_%s_%s_%s", 101 fName.printf("colorPattern_%s_%s_%s",
101 fPattern1.fName, fPattern2.fName, 102 fPattern1.fName, fPattern2.fName,
102 kRect_DrawType == drawType ? "rect" : "path"); 103 kRect_DrawType == drawType ? "rect" : "path");
103 fDrawType = drawType; 104 fDrawType = drawType;
104 } 105 }
105 106
107 virtual ~AlternatingColorPatternBench() {
108 SkSafeUnref(fBmShader);
109 }
110
106 protected: 111 protected:
107 const char* onGetName() override { 112 const char* onGetName() override {
108 return fName.c_str(); 113 return fName.c_str();
109 } 114 }
110 115
111 void onDelayedSetup() override { 116 void onDelayedSetup() override {
112 int w = 40; 117 int w = 40;
113 int h = 40; 118 int h = 40;
114 makebm(&fBmp, w, h); 119 makebm(&fBmp, w, h);
115 fBmShader = SkShader::MakeBitmapShader(fBmp, 120 fBmShader = SkShader::CreateBitmapShader(fBmp,
116 SkShader::kRepeat_TileMode, 121 SkShader::kRepeat_TileMode,
117 SkShader::kRepeat_TileMode); 122 SkShader::kRepeat_TileMode);
118 int offset = 2; 123 int offset = 2;
119 int count = 0; 124 int count = 0;
120 for (int j = 0; j < NY; ++j) { 125 for (int j = 0; j < NY; ++j) {
121 for (int i = 0; i < NX; ++i) { 126 for (int i = 0; i < NX; ++i) {
122 int x = (w + offset) * i; 127 int x = (w + offset) * i;
123 int y = (h * offset) * j; 128 int y = (h * offset) * j;
124 if (kRect_DrawType == fDrawType) { 129 if (kRect_DrawType == fDrawType) {
125 fRects[count].set(SkIntToScalar(x), SkIntToScalar(y), 130 fRects[count].set(SkIntToScalar(x), SkIntToScalar(y),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 191
187 DEF_BENCH(return new AlternatingColorPatternBench(kOpaqueBitmap_ColorPattern, 192 DEF_BENCH(return new AlternatingColorPatternBench(kOpaqueBitmap_ColorPattern,
188 kOpaqueBitmap_ColorPattern, 193 kOpaqueBitmap_ColorPattern,
189 kRect_DrawType);) 194 kRect_DrawType);)
190 DEF_BENCH(return new AlternatingColorPatternBench(kAlphaBitmap_ColorPattern, 195 DEF_BENCH(return new AlternatingColorPatternBench(kAlphaBitmap_ColorPattern,
191 kAlphaBitmap_ColorPattern, 196 kAlphaBitmap_ColorPattern,
192 kRect_DrawType);) 197 kRect_DrawType);)
193 DEF_BENCH(return new AlternatingColorPatternBench(kOpaqueBitmap_ColorPattern, 198 DEF_BENCH(return new AlternatingColorPatternBench(kOpaqueBitmap_ColorPattern,
194 kAlphaBitmap_ColorPattern, 199 kAlphaBitmap_ColorPattern,
195 kRect_DrawType);) 200 kRect_DrawType);)
OLDNEW
« no previous file with comments | « no previous file | bench/ColorCubeBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698