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

Side by Side Diff: gm/gradtext.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/gradients_no_texture.cpp ('k') | gm/hairmodes.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 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 #include "SkTypeface.h" 11 #include "SkTypeface.h"
12 12
13 // test shader w/ transparency 13 // test shader w/ transparency
14 static SkShader* make_grad(SkScalar width) { 14 static sk_sp<SkShader> make_grad(SkScalar width) {
15 SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE }; 15 SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
16 SkPoint pts[] = { { 0, 0 }, { width, 0 } }; 16 SkPoint pts[] = { { 0, 0 }, { width, 0 } };
17 return SkGradientShader::CreateLinear(pts, colors, nullptr, 17 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors),
18 SK_ARRAY_COUNT(colors), 18 SkShader::kMirror_TileMode);
19 SkShader::kMirror_TileMode);
20 } 19 }
21 20
22 // test opaque shader 21 // test opaque shader
23 static SkShader* make_grad2(SkScalar width) { 22 static sk_sp<SkShader> make_grad2(SkScalar width) {
24 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; 23 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
25 SkPoint pts[] = { { 0, 0 }, { width, 0 } }; 24 SkPoint pts[] = { { 0, 0 }, { width, 0 } };
26 return SkGradientShader::CreateLinear(pts, colors, nullptr, 25 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors),
27 SK_ARRAY_COUNT(colors), 26 SkShader::kMirror_TileMode);
28 SkShader::kMirror_TileMode);
29 } 27 }
30 28
31 static SkShader* make_chrome_solid() { 29 static sk_sp<SkShader> make_chrome_solid() {
32 SkColor colors[] = { SK_ColorGREEN, SK_ColorGREEN }; 30 SkColor colors[] = { SK_ColorGREEN, SK_ColorGREEN };
33 SkPoint pts[] = { { 0, 0 }, { 1, 0 } }; 31 SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
34 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, 32 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam p_TileMode);
35 SkShader::kClamp_TileMode);
36 } 33 }
37 34
38 namespace skiagm { 35 namespace skiagm {
39 36
40 // Replicate chrome layout test - clipped pathed gradient-shaded text 37 // Replicate chrome layout test - clipped pathed gradient-shaded text
41 class ChromeGradTextGM1 : public GM { 38 class ChromeGradTextGM1 : public GM {
42 public: 39 public:
43 ChromeGradTextGM1() { } 40 ChromeGradTextGM1() { }
44 protected: 41 protected:
45 42
46 virtual SkString onShortName() { return SkString("chrome_gradtext1"); } 43 virtual SkString onShortName() { return SkString("chrome_gradtext1"); }
47 virtual SkISize onISize() { return SkISize::Make(500, 480); } 44 virtual SkISize onISize() { return SkISize::Make(500, 480); }
48 virtual void onDraw(SkCanvas* canvas) { 45 virtual void onDraw(SkCanvas* canvas) {
49 SkPaint paint; 46 SkPaint paint;
50 sk_tool_utils::set_portable_typeface(&paint); 47 sk_tool_utils::set_portable_typeface(&paint);
51 SkRect r = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); 48 SkRect r = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
52 49
53 canvas->clipRect(r); 50 canvas->clipRect(r);
54 51
55 paint.setColor(SK_ColorRED); 52 paint.setColor(SK_ColorRED);
56 canvas->drawRect(r, paint); 53 canvas->drawRect(r, paint);
57 54
58 // Minimal repro doesn't require AA, LCD, or a nondefault typeface 55 // Minimal repro doesn't require AA, LCD, or a nondefault typeface
59 paint.setShader(make_chrome_solid())->unref(); 56 paint.setShader(make_chrome_solid());
60 paint.setTextSize(SkIntToScalar(500)); 57 paint.setTextSize(SkIntToScalar(500));
61 58
62 canvas->drawText("I", 1, 0, 100, paint); 59 canvas->drawText("I", 1, 0, 100, paint);
63 } 60 }
64 private: 61 private:
65 typedef GM INHERITED; 62 typedef GM INHERITED;
66 }; 63 };
67 64
68 65
69 // Replicate chrome layout test - switching between solid & gradient text 66 // Replicate chrome layout test - switching between solid & gradient text
70 class ChromeGradTextGM2 : public GM { 67 class ChromeGradTextGM2 : public GM {
71 public: 68 public:
72 ChromeGradTextGM2() { } 69 ChromeGradTextGM2() { }
73 protected: 70 protected:
74 71
75 virtual SkString onShortName() { return SkString("chrome_gradtext2"); } 72 virtual SkString onShortName() { return SkString("chrome_gradtext2"); }
76 virtual SkISize onISize() { return SkISize::Make(500, 480); } 73 virtual SkISize onISize() { return SkISize::Make(500, 480); }
77 virtual void onDraw(SkCanvas* canvas) { 74 virtual void onDraw(SkCanvas* canvas) {
78 SkPaint paint; 75 SkPaint paint;
79 sk_tool_utils::set_portable_typeface(&paint); 76 sk_tool_utils::set_portable_typeface(&paint);
80 77
81 paint.setStyle(SkPaint::kFill_Style); 78 paint.setStyle(SkPaint::kFill_Style);
82 canvas->drawText("Normal Fill Text", 16, 0, 50, paint); 79 canvas->drawText("Normal Fill Text", 16, 0, 50, paint);
83 paint.setStyle(SkPaint::kStroke_Style); 80 paint.setStyle(SkPaint::kStroke_Style);
84 canvas->drawText("Normal Stroke Text", 18, 0, 100, paint); 81 canvas->drawText("Normal Stroke Text", 18, 0, 100, paint);
85 82
86 // Minimal repro doesn't require AA, LCD, or a nondefault typeface 83 // Minimal repro doesn't require AA, LCD, or a nondefault typeface
87 paint.setShader(make_chrome_solid())->unref(); 84 paint.setShader(make_chrome_solid());
88 85
89 paint.setStyle(SkPaint::kFill_Style); 86 paint.setStyle(SkPaint::kFill_Style);
90 canvas->drawText("Gradient Fill Text", 18, 0, 150, paint); 87 canvas->drawText("Gradient Fill Text", 18, 0, 150, paint);
91 paint.setStyle(SkPaint::kStroke_Style); 88 paint.setStyle(SkPaint::kStroke_Style);
92 canvas->drawText("Gradient Stroke Text", 20, 0, 200, paint); 89 canvas->drawText("Gradient Stroke Text", 20, 0, 200, paint);
93 } 90 }
94 private: 91 private:
95 typedef GM INHERITED; 92 typedef GM INHERITED;
96 }; 93 };
97 94
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 paint.setTextSize(SkIntToScalar(26)); 130 paint.setTextSize(SkIntToScalar(26));
134 131
135 const SkISize& size = this->getISize(); 132 const SkISize& size = this->getISize();
136 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), 133 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
137 SkIntToScalar(size.height()) / 2); 134 SkIntToScalar(size.height()) / 2);
138 canvas->drawRect(r, paint); 135 canvas->drawRect(r, paint);
139 136
140 canvas->translate(SkIntToScalar(20), paint.getTextSize()); 137 canvas->translate(SkIntToScalar(20), paint.getTextSize());
141 138
142 for (int i = 0; i < 2; ++i) { 139 for (int i = 0; i < 2; ++i) {
143 paint.setShader(make_grad(SkIntToScalar(80)))->unref(); 140 paint.setShader(make_grad(SkIntToScalar(80)));
144 draw_text3(canvas, paint); 141 draw_text3(canvas, paint);
145 142
146 canvas->translate(0, paint.getTextSize() * 2); 143 canvas->translate(0, paint.getTextSize() * 2);
147 144
148 paint.setShader(make_grad2(SkIntToScalar(80)))->unref(); 145 paint.setShader(make_grad2(SkIntToScalar(80)));
149 draw_text3(canvas, paint); 146 draw_text3(canvas, paint);
150 147
151 canvas->translate(0, paint.getTextSize() * 2); 148 canvas->translate(0, paint.getTextSize() * 2);
152 } 149 }
153 } 150 }
154 151
155 private: 152 private:
156 typedef GM INHERITED; 153 typedef GM INHERITED;
157 }; 154 };
158 155
159 ////////////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////////////////////////////////////////
160 157
161 static GM* MyFactory(void*) { return new GradTextGM; } 158 static GM* MyFactory(void*) { return new GradTextGM; }
162 static GM* CMyFactory(void*) { return new ChromeGradTextGM1; } 159 static GM* CMyFactory(void*) { return new ChromeGradTextGM1; }
163 static GM* CMyFactory2(void*) { return new ChromeGradTextGM2; } 160 static GM* CMyFactory2(void*) { return new ChromeGradTextGM2; }
164 161
165 static GMRegistry reg(MyFactory); 162 static GMRegistry reg(MyFactory);
166 static GMRegistry Creg(CMyFactory); 163 static GMRegistry Creg(CMyFactory);
167 static GMRegistry Creg2(CMyFactory2); 164 static GMRegistry Creg2(CMyFactory2);
168 } 165 }
OLDNEW
« no previous file with comments | « gm/gradients_no_texture.cpp ('k') | gm/hairmodes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698