OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "sk_tool_utils.h" | 9 #include "sk_tool_utils.h" |
10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
11 #include "SkOffsetImageFilter.h" | 11 #include "SkOffsetImageFilter.h" |
12 #include "SkXfermodeImageFilter.h" | 12 #include "SkXfermodeImageFilter.h" |
13 #include "SkBitmapSource.h" | 13 #include "SkBitmapSource.h" |
14 | 14 |
15 #define WIDTH 600 | 15 #define WIDTH 600 |
16 #define HEIGHT 600 | 16 #define HEIGHT 600 |
17 #define MARGIN 12 | 17 #define MARGIN 12 |
18 | 18 |
19 namespace skiagm { | 19 namespace skiagm { |
20 | 20 |
21 class XfermodeImageFilterGM : public GM { | 21 class XfermodeImageFilterGM : public GM { |
22 public: | 22 public: |
23 XfermodeImageFilterGM(){ | 23 XfermodeImageFilterGM(){ |
24 this->setBGColor(0xFF000000); | 24 this->setBGColor(0xFF000000); |
25 } | 25 } |
26 | 26 |
27 protected: | 27 protected: |
28 SkString onShortName() SK_OVERRIDE { | 28 SkString onShortName() override { |
29 return SkString("xfermodeimagefilter"); | 29 return SkString("xfermodeimagefilter"); |
30 } | 30 } |
31 | 31 |
32 void make_bitmap() { | 32 void make_bitmap() { |
33 fBitmap.allocN32Pixels(80, 80); | 33 fBitmap.allocN32Pixels(80, 80); |
34 SkCanvas canvas(fBitmap); | 34 SkCanvas canvas(fBitmap); |
35 canvas.clear(0x00000000); | 35 canvas.clear(0x00000000); |
36 SkPaint paint; | 36 SkPaint paint; |
37 paint.setAntiAlias(true); | 37 paint.setAntiAlias(true); |
38 sk_tool_utils::set_portable_typeface(&paint); | 38 sk_tool_utils::set_portable_typeface(&paint); |
39 paint.setColor(0xD000D000); | 39 paint.setColor(0xD000D000); |
40 paint.setTextSize(SkIntToScalar(96)); | 40 paint.setTextSize(SkIntToScalar(96)); |
41 const char* str = "e"; | 41 const char* str = "e"; |
42 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); | 42 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); |
43 } | 43 } |
44 | 44 |
45 SkISize onISize() SK_OVERRIDE { | 45 SkISize onISize() override { |
46 return SkISize::Make(WIDTH, HEIGHT); | 46 return SkISize::Make(WIDTH, HEIGHT); |
47 } | 47 } |
48 | 48 |
49 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, | 49 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, |
50 int x, int y) { | 50 int x, int y) { |
51 canvas->save(); | 51 canvas->save(); |
52 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 52 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
53 canvas->clipRect(SkRect::MakeWH( | 53 canvas->clipRect(SkRect::MakeWH( |
54 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 54 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
55 canvas->drawBitmap(bitmap, 0, 0, &paint); | 55 canvas->drawBitmap(bitmap, 0, 0, &paint); |
56 canvas->restore(); | 56 canvas->restore(); |
57 } | 57 } |
58 | 58 |
59 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP
aint& paint, | 59 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP
aint& paint, |
60 int x, int y) { | 60 int x, int y) { |
61 canvas->save(); | 61 canvas->save(); |
62 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 62 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
63 canvas->clipRect(rect); | 63 canvas->clipRect(rect); |
64 canvas->drawPaint(paint); | 64 canvas->drawPaint(paint); |
65 canvas->restore(); | 65 canvas->restore(); |
66 } | 66 } |
67 | 67 |
68 void onOnceBeforeDraw() SK_OVERRIDE { | 68 void onOnceBeforeDraw() override { |
69 make_bitmap(); | 69 make_bitmap(); |
70 | 70 |
71 fCheckerboard.allocN32Pixels(80, 80); | 71 fCheckerboard.allocN32Pixels(80, 80); |
72 SkCanvas checkerboardCanvas(fCheckerboard); | 72 SkCanvas checkerboardCanvas(fCheckerboard); |
73 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF40
4040, 8); | 73 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF40
4040, 8); |
74 } | 74 } |
75 | 75 |
76 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 76 void onDraw(SkCanvas* canvas) override { |
77 canvas->clear(0x00000000); | 77 canvas->clear(0x00000000); |
78 SkPaint paint; | 78 SkPaint paint; |
79 | 79 |
80 const struct { | 80 const struct { |
81 SkXfermode::Mode fMode; | 81 SkXfermode::Mode fMode; |
82 const char* fLabel; | 82 const char* fLabel; |
83 } gModes[] = { | 83 } gModes[] = { |
84 { SkXfermode::kClear_Mode, "Clear" }, | 84 { SkXfermode::kClear_Mode, "Clear" }, |
85 { SkXfermode::kSrc_Mode, "Src" }, | 85 { SkXfermode::kSrc_Mode, "Src" }, |
86 { SkXfermode::kDst_Mode, "Dst" }, | 86 { SkXfermode::kDst_Mode, "Dst" }, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 private: | 201 private: |
202 SkBitmap fBitmap, fCheckerboard; | 202 SkBitmap fBitmap, fCheckerboard; |
203 typedef GM INHERITED; | 203 typedef GM INHERITED; |
204 }; | 204 }; |
205 | 205 |
206 ////////////////////////////////////////////////////////////////////////////// | 206 ////////////////////////////////////////////////////////////////////////////// |
207 | 207 |
208 DEF_GM( return new XfermodeImageFilterGM; ); | 208 DEF_GM( return new XfermodeImageFilterGM; ); |
209 | 209 |
210 } | 210 } |
OLD | NEW |