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 "SkImage.h" | |
12 #include "SkImageSource.h" | |
11 #include "SkOffsetImageFilter.h" | 13 #include "SkOffsetImageFilter.h" |
12 #include "SkXfermodeImageFilter.h" | 14 #include "SkXfermodeImageFilter.h" |
13 #include "SkBitmapSource.h" | |
14 | 15 |
15 #define WIDTH 600 | 16 #define WIDTH 600 |
16 #define HEIGHT 600 | 17 #define HEIGHT 600 |
17 #define MARGIN 12 | 18 #define MARGIN 12 |
18 | 19 |
19 namespace skiagm { | 20 namespace skiagm { |
20 | 21 |
21 class XfermodeImageFilterGM : public GM { | 22 class XfermodeImageFilterGM : public GM { |
22 public: | 23 public: |
23 XfermodeImageFilterGM(){ | 24 XfermodeImageFilterGM(){ |
(...skipping 11 matching lines...) Expand all Loading... | |
35 | 36 |
36 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, | 37 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons t SkPaint& paint, |
37 int x, int y) { | 38 int x, int y) { |
38 canvas->save(); | 39 canvas->save(); |
39 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 40 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
40 canvas->clipRect(SkRect::MakeWH( | 41 canvas->clipRect(SkRect::MakeWH( |
41 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 42 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
42 canvas->drawBitmap(bitmap, 0, 0, &paint); | 43 canvas->drawBitmap(bitmap, 0, 0, &paint); |
43 canvas->restore(); | 44 canvas->restore(); |
44 } | 45 } |
45 | 46 |
robertphillips
2015/09/15 17:43:52
DrawClippedPaint ?
f(malita)
2015/09/15 18:12:53
Done.
| |
46 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP aint& paint, | 47 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP aint& paint, |
47 int x, int y) { | 48 int x, int y) { |
48 canvas->save(); | 49 canvas->save(); |
49 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 50 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
50 canvas->clipRect(rect); | 51 canvas->clipRect(rect); |
51 canvas->drawPaint(paint); | 52 canvas->drawPaint(paint); |
52 canvas->restore(); | 53 canvas->restore(); |
53 } | 54 } |
54 | 55 |
55 void onOnceBeforeDraw() override { | 56 void onOnceBeforeDraw() override { |
56 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65 , 96, "e"); | 57 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65 , 96, "e"); |
57 | 58 |
58 fCheckerboard = sk_tool_utils::create_checkerboard_bitmap( | 59 fCheckerboard.reset(SkImage::NewFromBitmap( |
59 80, 80, | 60 sk_tool_utils::create_checkerboard_bitmap(80, 80, |
60 sk_tool_utils::color_to_ 565(0xFFA0A0A0), | 61 sk_tool_utils::color_to_56 5(0xFFA0A0A0), |
61 sk_tool_utils::color_to_ 565(0xFF404040), | 62 sk_tool_utils::color_to_56 5(0xFF404040), |
62 8); | 63 8))); |
63 } | 64 } |
64 | 65 |
65 void onDraw(SkCanvas* canvas) override { | 66 void onDraw(SkCanvas* canvas) override { |
66 canvas->clear(SK_ColorBLACK); | 67 canvas->clear(SK_ColorBLACK); |
67 SkPaint paint; | 68 SkPaint paint; |
68 | 69 |
69 const struct { | 70 const struct { |
70 SkXfermode::Mode fMode; | 71 SkXfermode::Mode fMode; |
71 const char* fLabel; | 72 const char* fLabel; |
72 } gModes[] = { | 73 } gModes[] = { |
(...skipping 23 matching lines...) Expand all Loading... | |
96 { SkXfermode::kDifference_Mode, "Difference" }, | 97 { SkXfermode::kDifference_Mode, "Difference" }, |
97 { SkXfermode::kExclusion_Mode, "Exclusion" }, | 98 { SkXfermode::kExclusion_Mode, "Exclusion" }, |
98 { SkXfermode::kMultiply_Mode, "Multiply" }, | 99 { SkXfermode::kMultiply_Mode, "Multiply" }, |
99 { SkXfermode::kHue_Mode, "Hue" }, | 100 { SkXfermode::kHue_Mode, "Hue" }, |
100 { SkXfermode::kSaturation_Mode, "Saturation" }, | 101 { SkXfermode::kSaturation_Mode, "Saturation" }, |
101 { SkXfermode::kColor_Mode, "Color" }, | 102 { SkXfermode::kColor_Mode, "Color" }, |
102 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 103 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
103 }; | 104 }; |
104 | 105 |
105 int x = 0, y = 0; | 106 int x = 0, y = 0; |
106 SkAutoTUnref<SkImageFilter> background(SkBitmapSource::Create(fCheckerbo ard)); | 107 SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboa rd)); |
107 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { | 108 for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { |
108 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); | 109 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode)); |
109 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mod e, background)); | 110 SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mod e, background)); |
110 paint.setImageFilter(filter); | 111 paint.setImageFilter(filter); |
111 drawClippedBitmap(canvas, fBitmap, paint, x, y); | 112 drawClippedBitmap(canvas, fBitmap, paint, x, y); |
112 x += fBitmap.width() + MARGIN; | 113 x += fBitmap.width() + MARGIN; |
113 if (x + fBitmap.width() > WIDTH) { | 114 if (x + fBitmap.width() > WIDTH) { |
114 x = 0; | 115 x = 0; |
115 y += fBitmap.height() + MARGIN; | 116 y += fBitmap.height() + MARGIN; |
116 } | 117 } |
(...skipping 13 matching lines...) Expand all Loading... | |
130 paint.setImageFilter(filter); | 131 paint.setImageFilter(filter); |
131 drawClippedBitmap(canvas, fBitmap, paint, x, y); | 132 drawClippedBitmap(canvas, fBitmap, paint, x, y); |
132 x += fBitmap.width() + MARGIN; | 133 x += fBitmap.width() + MARGIN; |
133 if (x + fBitmap.width() > WIDTH) { | 134 if (x + fBitmap.width() > WIDTH) { |
134 x = 0; | 135 x = 0; |
135 y += fBitmap.height() + MARGIN; | 136 y += fBitmap.height() + MARGIN; |
136 } | 137 } |
137 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), | 138 SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), |
138 SkIntToScalar(fBitmap.height() + 4)); | 139 SkIntToScalar(fBitmap.height() + 4)); |
139 // Test offsets on SrcMode (uses fixed-function blend) | 140 // Test offsets on SrcMode (uses fixed-function blend) |
140 SkAutoTUnref<SkImageFilter> foreground(SkBitmapSource::Create(fBitmap)); | 141 SkAutoTUnref<SkImage> bitmapImage(SkImage::NewFromBitmap(fBitmap)); |
142 SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage )); | |
141 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create ( | 143 SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create ( |
142 SkIntToScalar(4), SkIntToScalar(-4), foreground)); | 144 SkIntToScalar(4), SkIntToScalar(-4), foreground)); |
143 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create ( | 145 SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create ( |
144 SkIntToScalar(4), SkIntToScalar(4), background)); | 146 SkIntToScalar(4), SkIntToScalar(4), background)); |
145 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); | 147 mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
146 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse tForeground)); | 148 filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offse tForeground)); |
147 paint.setImageFilter(filter); | 149 paint.setImageFilter(filter); |
148 drawClippedPaint(canvas, clipRect, paint, x, y); | 150 drawClippedPaint(canvas, clipRect, paint, x, y); |
149 x += fBitmap.width() + MARGIN; | 151 x += fBitmap.width() + MARGIN; |
150 if (x + fBitmap.width() > WIDTH) { | 152 if (x + fBitmap.width() > WIDTH) { |
(...skipping 30 matching lines...) Expand all Loading... | |
181 paint.setImageFilter(filter); | 183 paint.setImageFilter(filter); |
182 drawClippedPaint(canvas, clipRect, paint, x, y); | 184 drawClippedPaint(canvas, clipRect, paint, x, y); |
183 x += fBitmap.width() + MARGIN; | 185 x += fBitmap.width() + MARGIN; |
184 if (x + fBitmap.width() > WIDTH) { | 186 if (x + fBitmap.width() > WIDTH) { |
185 x = 0; | 187 x = 0; |
186 y += fBitmap.height() + MARGIN; | 188 y += fBitmap.height() + MARGIN; |
187 } | 189 } |
188 } | 190 } |
189 } | 191 } |
190 private: | 192 private: |
191 SkBitmap fBitmap, fCheckerboard; | 193 SkBitmap fBitmap; |
194 SkAutoTUnref<SkImage> fCheckerboard; | |
195 | |
192 typedef GM INHERITED; | 196 typedef GM INHERITED; |
193 }; | 197 }; |
194 | 198 |
195 ////////////////////////////////////////////////////////////////////////////// | 199 ////////////////////////////////////////////////////////////////////////////// |
196 | 200 |
197 DEF_GM( return new XfermodeImageFilterGM; ); | 201 DEF_GM( return new XfermodeImageFilterGM; ); |
198 | 202 |
199 } | 203 } |
OLD | NEW |