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 | 11 |
12 #include "SkGradientShader.h" | |
13 static void set_gradient(SkPaint* paint) { | |
14 const SkPoint pts[] = { { 0, 0 }, { 240, 0 } }; | |
15 SkColor colors[2]; | |
16 colors[0] = paint->getColor(); | |
17 colors[1] = SkColorSetA(colors[0], 0); | |
18 SkShader* shader = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkSh ader::kClamp_TileMode); | |
19 paint->setShader(shader)->unref(); | |
20 } | |
21 | |
22 static void set_face(SkPaint* paint) { | |
23 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); | |
24 SkSafeUnref(paint->setTypeface(face)); | |
25 } | |
26 | |
27 static void draw_pair(SkCanvas* canvas, SkPaint* paint) { | |
28 const char text[] = "Now is the time for all good"; | |
29 const size_t len = strlen(text); | |
30 | |
31 paint->setShader(NULL); | |
32 canvas->drawText(text, len, 10, 20, *paint); | |
33 set_gradient(paint); | |
34 canvas->drawText(text, len, 10, 40, *paint); | |
35 } | |
36 | |
37 static void test_gamma(SkCanvas* canvas) { | |
38 SkPaint paint; | |
39 paint.setAntiAlias(true); | |
40 paint.setLCDRenderText(true); | |
41 paint.setTextSize(18); | |
42 set_face(&paint); | |
43 | |
44 draw_pair(canvas, &paint); | |
45 | |
46 canvas->translate(0, 50); | |
47 paint.setColor(SK_ColorRED); | |
48 draw_pair(canvas, &paint); | |
49 | |
50 canvas->translate(0, 50); | |
51 paint.setColor(SK_ColorBLUE); | |
52 draw_pair(canvas, &paint); | |
53 } | |
54 | |
12 /** Draw a 2px border around the target, then red behind the target; | 55 /** Draw a 2px border around the target, then red behind the target; |
13 set the clip to match the target, then draw >> the target in blue. | 56 set the clip to match the target, then draw >> the target in blue. |
14 */ | 57 */ |
15 | 58 |
16 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { | 59 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { |
17 SkPaint borderPaint; | 60 SkPaint borderPaint; |
18 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); | 61 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); |
19 borderPaint.setAntiAlias(true); | 62 borderPaint.setAntiAlias(true); |
20 SkPaint backgroundPaint; | 63 SkPaint backgroundPaint; |
21 backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0)); | 64 backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 protected: | 116 protected: |
74 virtual SkString onShortName() SK_OVERRIDE { | 117 virtual SkString onShortName() SK_OVERRIDE { |
75 return SkString("aaclip"); | 118 return SkString("aaclip"); |
76 } | 119 } |
77 | 120 |
78 virtual SkISize onISize() SK_OVERRIDE { | 121 virtual SkISize onISize() SK_OVERRIDE { |
79 return SkISize::Make(240, 120); | 122 return SkISize::Make(240, 120); |
80 } | 123 } |
81 | 124 |
82 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 125 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
126 if (true) { test_gamma(canvas); return; } | |
bungeman-skia
2014/08/21 14:15:43
I'm supposing this needs to be updated.
reed1
2014/08/21 20:07:38
Done.
| |
83 // Initial pixel-boundary-aligned draw | 127 // Initial pixel-boundary-aligned draw |
84 draw_rect_tests(canvas); | 128 draw_rect_tests(canvas); |
85 | 129 |
86 // Repeat 4x with .2, .4, .6, .8 px offsets | 130 // Repeat 4x with .2, .4, .6, .8 px offsets |
87 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); | 131 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
88 canvas->translate(SkIntToScalar(50), 0); | 132 canvas->translate(SkIntToScalar(50), 0); |
89 draw_rect_tests(canvas); | 133 draw_rect_tests(canvas); |
90 | 134 |
91 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); | 135 canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); |
92 canvas->translate(SkIntToScalar(50), 0); | 136 canvas->translate(SkIntToScalar(50), 0); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPipe_Flag; } | 234 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPipe_Flag; } |
191 | 235 |
192 private: | 236 private: |
193 typedef skiagm::GM INHERITED; | 237 typedef skiagm::GM INHERITED; |
194 }; | 238 }; |
195 | 239 |
196 #if 0 // Disabled pending fix from reed@ | 240 #if 0 // Disabled pending fix from reed@ |
197 DEF_GM( return SkNEW(CGImageGM); ) | 241 DEF_GM( return SkNEW(CGImageGM); ) |
198 #endif | 242 #endif |
199 #endif | 243 #endif |
OLD | NEW |