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

Side by Side Diff: gm/gradtext.cpp

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