OLD | NEW |
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 "SkPath.h" | 10 #include "SkPath.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 | 13 |
14 static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) { | 14 static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) { |
15 const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE }; | 15 const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE }; |
16 | 16 |
17 return SkGradientShader::MakeLinear(pts, bw, nullptr, SK_ARRAY_COUNT(bw), | 17 return SkGradientShader::MakeLinear(pts, bw, nullptr, SK_ARRAY_COUNT(bw), |
18 SkShader::kClamp_TileMode); | 18 SkShader::kClamp_TileMode); |
19 } | 19 } |
20 | 20 |
21 static bool setFont(SkPaint* paint, const char name[]) { | 21 static bool setFont(SkPaint* paint, const char name[]) { |
22 SkTypeface* tf = SkTypeface::CreateFromName(name, SkTypeface::kNormal); | 22 paint->setTypeface(SkTypeface::MakeFromName(name, SkTypeface::kNormal)); |
23 if (tf) { | 23 return SkToBool(paint->getTypeface()); |
24 paint->setTypeface(tf)->unref(); | |
25 return true; | |
26 } | |
27 return false; | |
28 } | 24 } |
29 | 25 |
30 /** | 26 /** |
31 Test a set of clipping problems discovered while writing blitAntiRect, | 27 Test a set of clipping problems discovered while writing blitAntiRect, |
32 and test all the code paths through the clipping blitters. | 28 and test all the code paths through the clipping blitters. |
33 Each region should show as a blue center surrounded by a 2px green | 29 Each region should show as a blue center surrounded by a 2px green |
34 border, with no red. | 30 border, with no red. |
35 */ | 31 */ |
36 | 32 |
37 #define HEIGHT 480 | 33 #define HEIGHT 480 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 97 |
102 static sk_sp<SkShader> make_gradient(SkColor c) { | 98 static sk_sp<SkShader> make_gradient(SkColor c) { |
103 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } }; | 99 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } }; |
104 SkColor colors[2]; | 100 SkColor colors[2]; |
105 colors[0] = c; | 101 colors[0] = c; |
106 colors[1] = SkColorSetA(c, 0); | 102 colors[1] = SkColorSetA(c, 0); |
107 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); | 103 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); |
108 } | 104 } |
109 | 105 |
110 static void set_face(SkPaint* paint) { | 106 static void set_face(SkPaint* paint) { |
111 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); | 107 paint->setTypeface(SkTypeface::MakeFromName("serif", SkTypeface::kItalic)); |
112 SkSafeUnref(paint->setTypeface(face)); | |
113 } | 108 } |
114 | 109 |
115 static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& s
hader) { | 110 static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& s
hader) { |
116 const char text[] = "Now is the time for all good"; | 111 const char text[] = "Now is the time for all good"; |
117 const size_t len = strlen(text); | 112 const size_t len = strlen(text); |
118 | 113 |
119 paint->setShader(nullptr); | 114 paint->setShader(nullptr); |
120 canvas->drawText(text, len, 10, 20, *paint); | 115 canvas->drawText(text, len, 10, 20, *paint); |
121 paint->setShader(SkShader::MakeColorShader(paint->getColor())); | 116 paint->setShader(SkShader::MakeColorShader(paint->getColor())); |
122 canvas->drawText(text, len, 10, 40, *paint); | 117 canvas->drawText(text, len, 10, 40, *paint); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 draw_pair(canvas, &paint, fShaders[i]); | 158 draw_pair(canvas, &paint, fShaders[i]); |
164 canvas->translate(0, 80); | 159 canvas->translate(0, 80); |
165 } | 160 } |
166 } | 161 } |
167 | 162 |
168 private: | 163 private: |
169 typedef skiagm::GM INHERITED; | 164 typedef skiagm::GM INHERITED; |
170 }; | 165 }; |
171 | 166 |
172 DEF_GM( return new GammaShaderTextGM; ) | 167 DEF_GM( return new GammaShaderTextGM; ) |
OLD | NEW |