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

Side by Side Diff: gm/modecolorfilters.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on 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 | « gm/matrixconvolution.cpp ('k') | gm/ovals.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 2012 Google Inc. 2 * Copyright 2012 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 "gm.h" 8 #include "gm.h"
9 #include "SkBitmapProcShader.h"
10 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
11 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
12 11
13 #define WIDTH 512 12 #define WIDTH 512
14 #define HEIGHT 1024 13 #define HEIGHT 1024
15 14
16 namespace skiagm { 15 namespace skiagm {
17 16
18 // Using gradients because GPU doesn't currently have an implementation of SkCol orShader (duh!) 17 // Using gradients because GPU doesn't currently have an implementation of SkCol orShader (duh!)
19 static SkShader* make_color_shader(SkColor color) { 18 static sk_sp<SkShader> make_color_shader(SkColor color) {
20 static const SkPoint kPts[] = {{0, 0}, {1, 1}}; 19 static const SkPoint kPts[] = {{0, 0}, {1, 1}};
21 SkColor colors[] = {color, color}; 20 SkColor colors[] = {color, color};
22 21
23 return SkGradientShader::CreateLinear(kPts, colors, nullptr, 2, SkShader::kC lamp_TileMode); 22 return SkGradientShader::MakeLinear(kPts, colors, nullptr, 2, SkShader::kCla mp_TileMode);
24 } 23 }
25 24
26 static SkShader* make_solid_shader() { 25 static sk_sp<SkShader> make_solid_shader() {
27 return make_color_shader(SkColorSetARGB(0xFF, 0x42, 0x82, 0x21)); 26 return make_color_shader(SkColorSetARGB(0xFF, 0x42, 0x82, 0x21));
28 } 27 }
29 28
30 static SkShader* make_transparent_shader() { 29 static sk_sp<SkShader> make_transparent_shader() {
31 return make_color_shader(SkColorSetARGB(0x80, 0x10, 0x70, 0x20)); 30 return make_color_shader(SkColorSetARGB(0x80, 0x10, 0x70, 0x20));
32 } 31 }
33 32
34 static SkShader* make_trans_black_shader() { 33 static sk_sp<SkShader> make_trans_black_shader() {
35 return make_color_shader(0x0); 34 return make_color_shader(0x0);
36 } 35 }
37 36
38 // draws a background behind each test rect to see transparency 37 // draws a background behind each test rect to see transparency
39 static SkShader* make_bg_shader(int checkSize) { 38 static sk_sp<SkShader> make_bg_shader(int checkSize) {
40 SkBitmap bmp; 39 SkBitmap bmp;
41 bmp.allocN32Pixels(2 * checkSize, 2 * checkSize); 40 bmp.allocN32Pixels(2 * checkSize, 2 * checkSize);
42 SkCanvas canvas(bmp); 41 SkCanvas canvas(bmp);
43 canvas.clear(sk_tool_utils::color_to_565(0xFF800000)); 42 canvas.clear(sk_tool_utils::color_to_565(0xFF800000));
44 SkPaint paint; 43 SkPaint paint;
45 paint.setColor(sk_tool_utils::color_to_565(0xFF000080)); 44 paint.setColor(sk_tool_utils::color_to_565(0xFF000080));
46 SkRect rect0 = SkRect::MakeXYWH(0, 0, 45 SkRect rect0 = SkRect::MakeXYWH(0, 0,
47 SkIntToScalar(checkSize), SkIntToScalar(chec kSize)); 46 SkIntToScalar(checkSize), SkIntToScalar(chec kSize));
48 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(checkSize), SkIntToScalar(chec kSize), 47 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(checkSize), SkIntToScalar(chec kSize),
49 SkIntToScalar(checkSize), SkIntToScalar(chec kSize)); 48 SkIntToScalar(checkSize), SkIntToScalar(chec kSize));
50 canvas.drawRect(rect1, paint); 49 canvas.drawRect(rect1, paint);
51 canvas.drawRect(rect0, paint); 50 canvas.drawRect(rect0, paint);
52 return new SkBitmapProcShader(bmp, SkShader::kRepeat_TileMode, SkShader::kRe peat_TileMode); 51 return SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode, SkShader: :kRepeat_TileMode);
53 } 52 }
54 53
55 class ModeColorFilterGM : public GM { 54 class ModeColorFilterGM : public GM {
56 public: 55 public:
57 ModeColorFilterGM() { 56 ModeColorFilterGM() {
58 this->setBGColor(sk_tool_utils::color_to_565(0xFF303030)); 57 this->setBGColor(sk_tool_utils::color_to_565(0xFF303030));
59 } 58 }
60 59
61 protected: 60 protected:
62 virtual SkString onShortName() { 61 SkString onShortName() override {
63 return SkString("modecolorfilters"); 62 return SkString("modecolorfilters");
64 } 63 }
65 64
66 virtual SkISize onISize() { 65 SkISize onISize() override {
67 return SkISize::Make(WIDTH, HEIGHT); 66 return SkISize::Make(WIDTH, HEIGHT);
68 } 67 }
69 68
70 virtual void onDraw(SkCanvas* canvas) { 69 void onDraw(SkCanvas* canvas) override {
71 // size of rect for each test case 70 // size of rect for each test case
72 static const int kRectWidth = 20; 71 static const int kRectWidth = 20;
73 static const int kRectHeight = 20; 72 static const int kRectHeight = 20;
74 73
75 static const int kCheckSize = 10; 74 static const int kCheckSize = 10;
76 75
77 if (!fBmpShader) { 76 if (!fBmpShader) {
78 fBmpShader.reset(make_bg_shader(kCheckSize)); 77 fBmpShader = make_bg_shader(kCheckSize);
79 } 78 }
80 SkPaint bgPaint; 79 SkPaint bgPaint;
81 bgPaint.setShader(fBmpShader); 80 bgPaint.setShader(fBmpShader);
82 bgPaint.setXfermodeMode(SkXfermode::kSrc_Mode); 81 bgPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
83 82
84 SkShader* shaders[] = { 83 sk_sp<SkShader> shaders[] = {
85 nullptr, // use a paint color inst ead of a shader 84 nullptr, // use a paint color inst ead of a shader
86 make_solid_shader(), 85 make_solid_shader(),
87 make_transparent_shader(), 86 make_transparent_shader(),
88 make_trans_black_shader(), 87 make_trans_black_shader(),
89 }; 88 };
90 89
91 // used without shader 90 // used without shader
92 SkColor colors[] = { 91 SkColor colors[] = {
93 SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF), 92 SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF),
94 SkColorSetARGB(0xFF, 0x00, 0x00, 0x00), 93 SkColorSetARGB(0xFF, 0x00, 0x00, 0x00),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 SkIntToScalar(kRectHeight )); 138 SkIntToScalar(kRectHeight ));
140 canvas->saveLayer(&rect, nullptr); 139 canvas->saveLayer(&rect, nullptr);
141 canvas->drawRect(rect, bgPaint); 140 canvas->drawRect(rect, bgPaint);
142 canvas->drawRect(rect, paint); 141 canvas->drawRect(rect, paint);
143 canvas->restore(); 142 canvas->restore();
144 ++idx; 143 ++idx;
145 } 144 }
146 } 145 }
147 } 146 }
148 } 147 }
149
150 for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
151 SkSafeUnref(shaders[i]);
152 }
153 } 148 }
154 149
155 private: 150 private:
156 SkAutoTUnref<SkShader> fBmpShader; 151 sk_sp<SkShader> fBmpShader;
157 typedef GM INHERITED; 152 typedef GM INHERITED;
158 }; 153 };
159 154
160 ////////////////////////////////////////////////////////////////////////////// 155 //////////////////////////////////////////////////////////////////////////////
161 156
162 static GM* MyFactory(void*) { return new ModeColorFilterGM; } 157 static GM* MyFactory(void*) { return new ModeColorFilterGM; }
163 static GMRegistry reg(MyFactory); 158 static GMRegistry reg(MyFactory);
164 159
165 } 160 }
OLDNEW
« no previous file with comments | « gm/matrixconvolution.cpp ('k') | gm/ovals.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698