| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "gm.h" | |
| 9 #include "SkBlendImageFilter.h" | |
| 10 #include "SkBitmapSource.h" | |
| 11 | |
| 12 namespace skiagm { | |
| 13 | |
| 14 class ImageBlendGM : public GM { | |
| 15 public: | |
| 16 ImageBlendGM() : fInitialized(false) { | |
| 17 this->setBGColor(0xFF000000); | |
| 18 } | |
| 19 | |
| 20 protected: | |
| 21 virtual SkString onShortName() { | |
| 22 return SkString("blend"); | |
| 23 } | |
| 24 | |
| 25 void make_bitmap() { | |
| 26 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); | |
| 27 fBitmap.allocPixels(); | |
| 28 SkDevice device(fBitmap); | |
| 29 SkCanvas canvas(&device); | |
| 30 canvas.clear(0x00000000); | |
| 31 SkPaint paint; | |
| 32 paint.setAntiAlias(true); | |
| 33 paint.setColor(0xD000D000); | |
| 34 paint.setTextSize(SkIntToScalar(96)); | |
| 35 const char* str = "e"; | |
| 36 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); | |
| 37 } | |
| 38 | |
| 39 void make_checkerboard() { | |
| 40 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); | |
| 41 fCheckerboard.allocPixels(); | |
| 42 SkDevice device(fCheckerboard); | |
| 43 SkCanvas canvas(&device); | |
| 44 canvas.clear(0x00000000); | |
| 45 SkPaint darkPaint; | |
| 46 darkPaint.setColor(0xFF404040); | |
| 47 SkPaint lightPaint; | |
| 48 lightPaint.setColor(0xFFA0A0A0); | |
| 49 for (int y = 0; y < 80; y += 16) { | |
| 50 for (int x = 0; x < 80; x += 16) { | |
| 51 canvas.save(); | |
| 52 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | |
| 53 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | |
| 54 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | |
| 55 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | |
| 56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | |
| 57 canvas.restore(); | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 virtual SkISize onISize() { | |
| 63 return make_isize(500, 100); | |
| 64 } | |
| 65 | |
| 66 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) { | |
| 67 canvas->save(); | |
| 68 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0, | |
| 69 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); | |
| 70 canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint); | |
| 71 canvas->restore(); | |
| 72 } | |
| 73 | |
| 74 virtual void onDraw(SkCanvas* canvas) { | |
| 75 if (!fInitialized) { | |
| 76 make_bitmap(); | |
| 77 make_checkerboard(); | |
| 78 fInitialized = true; | |
| 79 } | |
| 80 canvas->clear(0x00000000); | |
| 81 SkPaint paint; | |
| 82 SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fChec
kerboard))); | |
| 83 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter:
:kNormal_Mode, background)))->unref(); | |
| 84 drawClippedBitmap(canvas, paint, 0); | |
| 85 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter:
:kMultiply_Mode, background)))->unref(); | |
| 86 drawClippedBitmap(canvas, paint, 100); | |
| 87 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter:
:kScreen_Mode, background)))->unref(); | |
| 88 drawClippedBitmap(canvas, paint, 200); | |
| 89 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter:
:kDarken_Mode, background)))->unref(); | |
| 90 drawClippedBitmap(canvas, paint, 300); | |
| 91 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter, (SkBlendImageFilter:
:kLighten_Mode, background)))->unref(); | |
| 92 drawClippedBitmap(canvas, paint, 400); | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 typedef GM INHERITED; | |
| 97 SkBitmap fBitmap, fCheckerboard; | |
| 98 bool fInitialized; | |
| 99 }; | |
| 100 | |
| 101 ////////////////////////////////////////////////////////////////////////////// | |
| 102 | |
| 103 static GM* MyFactory(void*) { return new ImageBlendGM; } | |
| 104 static GMRegistry reg(MyFactory); | |
| 105 | |
| 106 } | |
| OLD | NEW |