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

Side by Side Diff: gm/gammatext.cpp

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

Powered by Google App Engine
This is Rietveld 408576698