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

Side by Side Diff: gm/gammatext.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. 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
« no previous file with comments | « gm/fontscalerdistortable.cpp ('k') | gm/mixedtextblobs.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 "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
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
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; )
OLDNEW
« no previous file with comments | « gm/fontscalerdistortable.cpp ('k') | gm/mixedtextblobs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698