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

Side by Side Diff: gm/lcdblendmodes.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/imagetoyuvplanes.cpp ('k') | gm/lumafilter.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 2015 Google Inc. 2 * Copyright 2015 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 8
9 /* 9 /*
10 * Tests text rendering with LCD and the various blend modes. 10 * Tests text rendering with LCD and the various blend modes.
11 */ 11 */
12 12
13 #include "gm.h" 13 #include "gm.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
16 #include "SkSurface.h" 16 #include "SkSurface.h"
17 17
18 namespace skiagm { 18 namespace skiagm {
19 19
20 static const int kColWidth = 180; 20 static const int kColWidth = 180;
21 static const int kNumCols = 4; 21 static const int kNumCols = 4;
22 static const int kWidth = kColWidth * kNumCols; 22 static const int kWidth = kColWidth * kNumCols;
23 static const int kHeight = 750; 23 static const int kHeight = 750;
24 24
25 static SkShader* make_shader(const SkRect& bounds) { 25 static sk_sp<SkShader> make_shader(const SkRect& bounds) {
26 const SkPoint pts[] = { 26 const SkPoint pts[] = {
27 { bounds.left(), bounds.top() }, 27 { bounds.left(), bounds.top() },
28 { bounds.right(), bounds.bottom() }, 28 { bounds.right(), bounds.bottom() },
29 }; 29 };
30 const SkColor colors[] = { 30 const SkColor colors[] = {
31 SK_ColorRED, SK_ColorGREEN, 31 SK_ColorRED, SK_ColorGREEN,
32 }; 32 };
33 return SkGradientShader::CreateLinear(pts, 33 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col ors),
34 colors, nullptr, SK_ARRAY_COUNT(colors ), 34 SkShader::kRepeat_TileMode);
35 SkShader::kRepeat_TileMode);
36 } 35 }
37 36
38 class LcdBlendGM : public skiagm::GM { 37 class LcdBlendGM : public skiagm::GM {
39 public: 38 public:
40 LcdBlendGM() { 39 LcdBlendGM() {
41 const int kPointSize = 25; 40 const int kPointSize = 25;
42 fTextHeight = SkIntToScalar(kPointSize); 41 fTextHeight = SkIntToScalar(kPointSize);
43 } 42 }
44 43
45 protected: 44 protected:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 paint.setColor(textColor); 128 paint.setColor(textColor);
130 paint.setAntiAlias(true); 129 paint.setAntiAlias(true);
131 paint.setSubpixelText(true); 130 paint.setSubpixelText(true);
132 paint.setLCDRenderText(true); 131 paint.setLCDRenderText(true);
133 paint.setTextSize(fTextHeight); 132 paint.setTextSize(fTextHeight);
134 paint.setXfermode(xfermode); 133 paint.setXfermode(xfermode);
135 sk_tool_utils::set_portable_typeface(&paint); 134 sk_tool_utils::set_portable_typeface(&paint);
136 if (useGrad) { 135 if (useGrad) {
137 SkRect r; 136 SkRect r;
138 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei ght); 137 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei ght);
139 paint.setShader(make_shader(r))->unref(); 138 paint.setShader(make_shader(r));
140 } 139 }
141 SkString string(gModes[m].fLabel); 140 SkString string(gModes[m].fLabel);
142 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); 141 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
143 y+=fTextHeight; 142 y+=fTextHeight;
144 } 143 }
145 } 144 }
146 145
147 private: 146 private:
148 SkScalar fTextHeight; 147 SkScalar fTextHeight;
149 sk_sp<SkShader> fCheckerboard; 148 sk_sp<SkShader> fCheckerboard;
150 typedef skiagm::GM INHERITED; 149 typedef skiagm::GM INHERITED;
151 }; 150 };
152 151
153 ////////////////////////////////////////////////////////////////////////////// 152 //////////////////////////////////////////////////////////////////////////////
154 153
155 DEF_GM( return new LcdBlendGM; ) 154 DEF_GM( return new LcdBlendGM; )
156 } 155 }
OLDNEW
« no previous file with comments | « gm/imagetoyuvplanes.cpp ('k') | gm/lumafilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698