| 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 "Checkerboard.h" |
| 9 #include "SkBitmapSource.h" |
| 10 #include "SkOffsetImageFilter.h" |
| 8 #include "gm.h" | 11 #include "gm.h" |
| 9 #include "SkOffsetImageFilter.h" | |
| 10 #include "SkBitmapSource.h" | |
| 11 | 12 |
| 12 #define WIDTH 600 | 13 #define WIDTH 600 |
| 13 #define HEIGHT 100 | 14 #define HEIGHT 100 |
| 14 #define MARGIN 12 | 15 #define MARGIN 12 |
| 15 | 16 |
| 16 namespace skiagm { | 17 namespace skiagm { |
| 17 | 18 |
| 18 class OffsetImageFilterGM : public GM { | 19 class OffsetImageFilterGM : public GM { |
| 19 public: | 20 public: |
| 20 OffsetImageFilterGM() : fInitialized(false) { | 21 OffsetImageFilterGM() : fInitialized(false) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 canvas.clear(0x00000000); | 33 canvas.clear(0x00000000); |
| 33 SkPaint paint; | 34 SkPaint paint; |
| 34 paint.setAntiAlias(true); | 35 paint.setAntiAlias(true); |
| 35 sk_tool_utils::set_portable_typeface(&paint); | 36 sk_tool_utils::set_portable_typeface(&paint); |
| 36 paint.setColor(0xD000D000); | 37 paint.setColor(0xD000D000); |
| 37 paint.setTextSize(SkIntToScalar(96)); | 38 paint.setTextSize(SkIntToScalar(96)); |
| 38 const char* str = "e"; | 39 const char* str = "e"; |
| 39 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); | 40 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65),
paint); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void make_checkerboard() { | |
| 43 fCheckerboard.allocN32Pixels(80, 80); | |
| 44 SkCanvas canvas(fCheckerboard); | |
| 45 canvas.clear(0x00000000); | |
| 46 SkPaint darkPaint; | |
| 47 darkPaint.setColor(0xFF404040); | |
| 48 SkPaint lightPaint; | |
| 49 lightPaint.setColor(0xFFA0A0A0); | |
| 50 for (int y = 0; y < 80; y += 16) { | |
| 51 for (int x = 0; x < 80; x += 16) { | |
| 52 canvas.save(); | |
| 53 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | |
| 54 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | |
| 55 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | |
| 56 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | |
| 57 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | |
| 58 canvas.restore(); | |
| 59 } | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 virtual SkISize onISize() { | 43 virtual SkISize onISize() { |
| 64 return SkISize::Make(WIDTH, HEIGHT); | 44 return SkISize::Make(WIDTH, HEIGHT); |
| 65 } | 45 } |
| 66 | 46 |
| 67 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, SkScalar scale, const SkIRect& cropRect) { | 47 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint, SkScalar scale, const SkIRect& cropRect) { |
| 68 canvas->save(); | 48 canvas->save(); |
| 69 SkRect clipRect = SkRect::MakeWH( | 49 SkRect clipRect = SkRect::MakeWH( |
| 70 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); | 50 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); |
| 71 canvas->clipRect(clipRect); | 51 canvas->clipRect(clipRect); |
| 72 canvas->scale(scale, scale); | 52 canvas->scale(scale, scale); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 SkRect cropRectFloat; | 63 SkRect cropRectFloat; |
| 84 scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect)); | 64 scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect)); |
| 85 if (clipRect.intersect(cropRectFloat)) { | 65 if (clipRect.intersect(cropRectFloat)) { |
| 86 canvas->drawRect(clipRect, strokePaint); | 66 canvas->drawRect(clipRect, strokePaint); |
| 87 } | 67 } |
| 88 } | 68 } |
| 89 | 69 |
| 90 virtual void onDraw(SkCanvas* canvas) { | 70 virtual void onDraw(SkCanvas* canvas) { |
| 91 if (!fInitialized) { | 71 if (!fInitialized) { |
| 92 make_bitmap(); | 72 make_bitmap(); |
| 93 make_checkerboard(); | 73 |
| 74 fCheckerboard.allocN32Pixels(80, 80); |
| 75 SkCanvas checkerboardCanvas(fCheckerboard); |
| 76 sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF4040
40, 8); |
| 77 |
| 94 fInitialized = true; | 78 fInitialized = true; |
| 95 } | 79 } |
| 96 canvas->clear(0x00000000); | 80 canvas->clear(0x00000000); |
| 97 SkPaint paint; | 81 SkPaint paint; |
| 98 | 82 |
| 99 for (int i = 0; i < 4; i++) { | 83 for (int i = 0; i < 4; i++) { |
| 100 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; | 84 SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; |
| 101 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, | 85 SkIRect cropRect = SkIRect::MakeXYWH(i * 12, |
| 102 i * 8, | 86 i * 8, |
| 103 bitmap->width() - i * 8, | 87 bitmap->width() - i * 8, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 125 SkBitmap fBitmap, fCheckerboard; | 109 SkBitmap fBitmap, fCheckerboard; |
| 126 bool fInitialized; | 110 bool fInitialized; |
| 127 }; | 111 }; |
| 128 | 112 |
| 129 ////////////////////////////////////////////////////////////////////////////// | 113 ////////////////////////////////////////////////////////////////////////////// |
| 130 | 114 |
| 131 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } | 115 static GM* MyFactory(void*) { return new OffsetImageFilterGM; } |
| 132 static GMRegistry reg(MyFactory); | 116 static GMRegistry reg(MyFactory); |
| 133 | 117 |
| 134 } | 118 } |
| OLD | NEW |