| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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() override { | 28 SkString onShortName() override { |
| 29 return SkString("xfermodeimagefilter"); | 29 return SkString("xfermodeimagefilter"); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void make_bitmap() { | |
| 33 fBitmap.allocN32Pixels(80, 80); | |
| 34 SkCanvas canvas(fBitmap); | |
| 35 canvas.clear(0x00000000); | |
| 36 SkPaint paint; | |
| 37 paint.setAntiAlias(true); | |
| 38 sk_tool_utils::set_portable_typeface(&paint); | |
| 39 paint.setColor(0xD000D000); | |
| 40 paint.setTextSize(SkIntToScalar(96)); | |
| 41 const char* str = "e"; | |
| 42 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); | |
| 43 } | |
| 44 | |
| 45 SkISize onISize() override { | 32 SkISize onISize() override { |
| 46 return SkISize::Make(WIDTH, HEIGHT); | 33 return SkISize::Make(WIDTH, HEIGHT); |
| 47 } | 34 } |
| 48 | 35 |
| 49 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, | 36 static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, cons
t SkPaint& paint, |
| 50 int x, int y) { | 37 int x, int y) { |
| 51 canvas->save(); | 38 canvas->save(); |
| 52 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 39 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 53 canvas->clipRect(SkRect::MakeWH( | 40 canvas->clipRect(SkRect::MakeWH( |
| 54 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 41 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
| 55 canvas->drawBitmap(bitmap, 0, 0, &paint); | 42 canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 56 canvas->restore(); | 43 canvas->restore(); |
| 57 } | 44 } |
| 58 | 45 |
| 59 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP
aint& paint, | 46 static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkP
aint& paint, |
| 60 int x, int y) { | 47 int x, int y) { |
| 61 canvas->save(); | 48 canvas->save(); |
| 62 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 49 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 63 canvas->clipRect(rect); | 50 canvas->clipRect(rect); |
| 64 canvas->drawPaint(paint); | 51 canvas->drawPaint(paint); |
| 65 canvas->restore(); | 52 canvas->restore(); |
| 66 } | 53 } |
| 67 | 54 |
| 68 void onOnceBeforeDraw() override { | 55 void onOnceBeforeDraw() override { |
| 69 make_bitmap(); | 56 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65
, 96, "e"); |
| 70 | 57 |
| 71 fCheckerboard.allocN32Pixels(80, 80); | 58 fCheckerboard = sk_tool_utils::create_checkerboard_bitmap( |
| 72 SkCanvas checkerboardCanvas(fCheckerboard); | 59 80, 80, |
| 73 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, | 60 sk_tool_utils::color_to_
565(0xFFA0A0A0), |
| 74 sk_tool_utils::color_to_565(0xFFA0A0A0), | 61 sk_tool_utils::color_to_
565(0xFF404040), |
| 75 sk_tool_utils::color_to_565(0xFF404040), 8); | 62 8); |
| 76 } | 63 } |
| 77 | 64 |
| 78 void onDraw(SkCanvas* canvas) override { | 65 void onDraw(SkCanvas* canvas) override { |
| 79 canvas->clear(SK_ColorBLACK); | 66 canvas->clear(SK_ColorBLACK); |
| 80 SkPaint paint; | 67 SkPaint paint; |
| 81 | 68 |
| 82 const struct { | 69 const struct { |
| 83 SkXfermode::Mode fMode; | 70 SkXfermode::Mode fMode; |
| 84 const char* fLabel; | 71 const char* fLabel; |
| 85 } gModes[] = { | 72 } gModes[] = { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 private: | 190 private: |
| 204 SkBitmap fBitmap, fCheckerboard; | 191 SkBitmap fBitmap, fCheckerboard; |
| 205 typedef GM INHERITED; | 192 typedef GM INHERITED; |
| 206 }; | 193 }; |
| 207 | 194 |
| 208 ////////////////////////////////////////////////////////////////////////////// | 195 ////////////////////////////////////////////////////////////////////////////// |
| 209 | 196 |
| 210 DEF_GM( return new XfermodeImageFilterGM; ); | 197 DEF_GM( return new XfermodeImageFilterGM; ); |
| 211 | 198 |
| 212 } | 199 } |
| OLD | NEW |