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

Side by Side Diff: gm/gammatext.cpp

Issue 492963002: extend SkShader to report a luminance-color to be used for gamma correction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase, add SkShader::CreateColorShader(c) Created 6 years, 4 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 | « no previous file | include/core/SkColorShader.h » ('j') | src/effects/gradients/SkGradientShader.cpp » ('J')
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"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 cgSetPaintForText(cg, paint); 92 cgSetPaintForText(cg, paint);
93 93
94 uint16_t glyphs[200]; 94 uint16_t glyphs[200];
95 int count = paint.textToGlyphs(text, len, glyphs); 95 int count = paint.textToGlyphs(text, len, glyphs);
96 96
97 CGContextShowGlyphsAtPoint(cg, x, y, glyphs, count); 97 CGContextShowGlyphsAtPoint(cg, x, y, glyphs, count);
98 } 98 }
99 } 99 }
100 #endif 100 #endif
101 101
102 namespace skiagm {
103
104 /** 102 /**
105 Test a set of clipping problems discovered while writing blitAntiRect, 103 Test a set of clipping problems discovered while writing blitAntiRect,
106 and test all the code paths through the clipping blitters. 104 and test all the code paths through the clipping blitters.
107 Each region should show as a blue center surrounded by a 2px green 105 Each region should show as a blue center surrounded by a 2px green
108 border, with no red. 106 border, with no red.
109 */ 107 */
110 108
111 #define HEIGHT 480 109 #define HEIGHT 480
112 110
113 class GammaTextGM : public GM { 111 class GammaTextGM : public skiagm::GM {
114 public: 112 public:
115 GammaTextGM() { 113 GammaTextGM() {
116 114
117 } 115 }
118 116
119 protected: 117 protected:
120 virtual SkString onShortName() { 118 virtual SkString onShortName() {
121 return SkString("gammatext"); 119 return SkString("gammatext");
122 } 120 }
123 121
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 y += paint.getTextSize() * 2; 190 y += paint.getTextSize() * 2;
193 } 191 }
194 x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg); 192 x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg);
195 } 193 }
196 #ifdef SK_BUILD_FOR_MAC 194 #ifdef SK_BUILD_FOR_MAC
197 CGContextRelease(cg); 195 CGContextRelease(cg);
198 #endif 196 #endif
199 } 197 }
200 198
201 private: 199 private:
202 typedef GM INHERITED; 200 typedef skiagm::GM INHERITED;
203 }; 201 };
204 202
203 DEF_GM( return new GammaTextGM; )
204
205 ////////////////////////////////////////////////////////////////////////////// 205 //////////////////////////////////////////////////////////////////////////////
206 206
207 static GM* MyFactory(void*) { return new GammaTextGM; } 207 static SkShader* make_gradient(SkColor c) {
208 static GMRegistry reg(MyFactory); 208 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } };
209 SkColor colors[2];
210 colors[0] = c;
211 colors[1] = SkColorSetA(c, 0);
212 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp _TileMode);
213 }
209 214
215 static void set_face(SkPaint* paint) {
216 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic);
217 SkSafeUnref(paint->setTypeface(face));
210 } 218 }
219
220 static void draw_pair(SkCanvas* canvas, SkPaint* paint, SkShader* shader) {
221 const char text[] = "Now is the time for all good";
222 const size_t len = strlen(text);
223
224 paint->setShader(NULL);
225 canvas->drawText(text, len, 10, 20, *paint);
226 paint->setShader(SkShader::CreateColorShader(paint->getColor()))->unref();
227 canvas->drawText(text, len, 10, 40, *paint);
228 paint->setShader(shader);
229 canvas->drawText(text, len, 10, 60, *paint);
230 }
231
232 class GammaShaderTextGM : public skiagm::GM {
233 SkShader* fShaders[3];
234 SkColor fColors[3];
235
236 public:
237 GammaShaderTextGM() {
238 const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE };
239 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
240 fShaders[i] = NULL;
241 fColors[i] = colors[i];
242 }
243 }
244
245 virtual ~GammaShaderTextGM() {
246 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
247 SkSafeUnref(fShaders[i]);
248 }
249 }
250
251 protected:
252 virtual SkString onShortName() {
253 return SkString("gammagradienttext");
254 }
255
256 virtual SkISize onISize() {
257 return SkISize::Make(300, 300);
258 }
259
260 virtual void onOnceBeforeDraw() {
261 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
262 fShaders[i] = make_gradient(fColors[i]);
263 }
264 }
265
266 virtual void onDraw(SkCanvas* canvas) {
267 SkPaint paint;
268 paint.setAntiAlias(true);
269 paint.setLCDRenderText(true);
270 paint.setTextSize(18);
271 set_face(&paint);
272
273 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
274 paint.setColor(fColors[i]);
275 draw_pair(canvas, &paint, fShaders[i]);
276 canvas->translate(0, 80);
277 }
278 }
279
280 private:
281 typedef skiagm::GM INHERITED;
282 };
283
284 DEF_GM( return new GammaShaderTextGM; )
285
OLDNEW
« no previous file with comments | « no previous file | include/core/SkColorShader.h » ('j') | src/effects/gradients/SkGradientShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698