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

Side by Side Diff: bench/PatchBench.cpp

Issue 1803763002: 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 | « bench/ImageFilterCollapse.cpp ('k') | bench/PatchGridBench.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 #include "Benchmark.h" 7 #include "Benchmark.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 virtual void setTexCoords() { 64 virtual void setTexCoords() {
65 const SkPoint texCoords[SkPatchUtils::kNumCorners] = { 65 const SkPoint texCoords[SkPatchUtils::kNumCorners] = {
66 {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f,1.0f}, {0.0f, 1.0f} 66 {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f,1.0f}, {0.0f, 1.0f}
67 }; 67 };
68 memcpy(fTexCoords, texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint )); 68 memcpy(fTexCoords, texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint ));
69 } 69 }
70 70
71 // override this method to change the shader 71 // override this method to change the shader
72 virtual SkShader* createShader() { 72 virtual sk_sp<SkShader> createShader() {
73 const SkColor colors[] = { 73 const SkColor colors[] = {
74 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, 74 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
75 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, 75 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
76 }; 76 };
77 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } }; 77 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } };
78 78
79 return SkGradientShader::CreateLinear(pts, colors, nullptr, 79 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT (colors),
80 SK_ARRAY_COUNT(colors), 80 SkShader::kMirror_TileMode);
81 SkShader::kMirror_TileMode);
82 } 81 }
83 82
84 protected: 83 protected:
85 const char* onGetName() override { 84 const char* onGetName() override {
86 SkString vertexMode; 85 SkString vertexMode;
87 switch (fVertexMode) { 86 switch (fVertexMode) {
88 case kNone_VertexMode: 87 case kNone_VertexMode:
89 vertexMode.set("meshlines"); 88 vertexMode.set("meshlines");
90 break; 89 break;
91 case kColors_VertexMode: 90 case kColors_VertexMode:
(...skipping 16 matching lines...) Expand all
108 } 107 }
109 108
110 void onDelayedSetup() override { 109 void onDelayedSetup() override {
111 this->setCubics(); 110 this->setCubics();
112 this->setColors(); 111 this->setColors();
113 this->setTexCoords(); 112 this->setTexCoords();
114 this->setupPaint(&fPaint); 113 this->setupPaint(&fPaint);
115 switch (fVertexMode) { 114 switch (fVertexMode) {
116 case kTexCoords_VertexMode: 115 case kTexCoords_VertexMode:
117 case kBoth_VertexMode: 116 case kBoth_VertexMode:
118 fPaint.setShader(this->createShader())->unref(); 117 fPaint.setShader(this->createShader());
119 break; 118 break;
120 default: 119 default:
121 fPaint.setShader(nullptr); 120 fPaint.setShader(nullptr);
122 break; 121 break;
123 } 122 }
124 } 123 }
125 124
126 void onDraw(int loops, SkCanvas* canvas) override { 125 void onDraw(int loops, SkCanvas* canvas) override {
127 canvas->scale(fScale.x(), fScale.y()); 126 canvas->scale(fScale.x(), fScale.y());
128 for (int i = 0; i < loops; i++) { 127 for (int i = 0; i < loops; i++) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f), 315 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
317 PatchBench::kBoth_VertexMode); ) 316 PatchBench::kBoth_VertexMode); )
318 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), 317 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
319 PatchBench::kNone_VertexMode); ) 318 PatchBench::kNone_VertexMode); )
320 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), 319 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
321 PatchBench::kColors_VertexMode); ) 320 PatchBench::kColors_VertexMode); )
322 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), 321 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
323 PatchBench::kTexCoords_VertexMode); ) 322 PatchBench::kTexCoords_VertexMode); )
324 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f), 323 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
325 PatchBench::kBoth_VertexMode); ) 324 PatchBench::kBoth_VertexMode); )
OLDNEW
« no previous file with comments | « bench/ImageFilterCollapse.cpp ('k') | bench/PatchGridBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698