OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 SkBitmap bm; | 58 SkBitmap bm; |
59 bm.allocN32Pixels(bounds.width(), bounds.height()); | 59 bm.allocN32Pixels(bounds.width(), bounds.height()); |
60 bm.eraseColor(SK_ColorTRANSPARENT); | 60 bm.eraseColor(SK_ColorTRANSPARENT); |
61 SkCanvas c(bm); | 61 SkCanvas c(bm); |
62 draw_path(&c, r, nullptr); | 62 draw_path(&c, r, nullptr); |
63 | 63 |
64 paint.setImageFilter(imf); | 64 paint.setImageFilter(imf); |
65 canvas->drawBitmap(bm, 0, 0, &paint); | 65 canvas->drawBitmap(bm, 0, 0, &paint); |
66 } | 66 } |
67 | 67 |
| 68 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 69 SkPaint paint; |
| 70 |
| 71 SkIRect bounds; |
| 72 r.roundOut(&bounds); |
| 73 |
| 74 SkBitmap bm; |
| 75 bm.allocN32Pixels(bounds.width(), bounds.height()); |
| 76 bm.eraseColor(SK_ColorRED); |
| 77 SkCanvas c(bm); |
| 78 |
| 79 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); |
| 80 paint.setColor(SK_ColorGREEN); |
| 81 c.drawRect(SkRect::Make(cropRect), paint); |
| 82 |
| 83 paint.setImageFilter(imf); |
| 84 SkPoint loc = { r.fLeft, r.fTop }; |
| 85 canvas->getTotalMatrix().mapPoints(&loc, 1); |
| 86 canvas->drawSprite(bm, |
| 87 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), |
| 88 &paint); |
| 89 } |
| 90 |
68 /////////////////////////////////////////////////////////////////////////////// | 91 /////////////////////////////////////////////////////////////////////////////// |
69 | 92 |
70 class ImageFiltersCroppedGM : public skiagm::GM { | 93 class ImageFiltersCroppedGM : public skiagm::GM { |
71 public: | 94 public: |
72 ImageFiltersCroppedGM () {} | 95 ImageFiltersCroppedGM () {} |
73 | 96 |
74 protected: | 97 protected: |
75 virtual SkString onShortName() override { | 98 virtual SkString onShortName() override { |
76 return SkString("imagefilterscropped"); | 99 return SkString("imagefilterscropped"); |
77 } | 100 } |
(...skipping 27 matching lines...) Expand all Loading... |
105 paint.setColor(SK_ColorRED); | 128 paint.setColor(SK_ColorRED); |
106 canvas->drawRect(r, paint); | 129 canvas->drawRect(r, paint); |
107 } | 130 } |
108 | 131 |
109 virtual void onOnceBeforeDraw() override{ | 132 virtual void onOnceBeforeDraw() override{ |
110 make_checkerboard(); | 133 make_checkerboard(); |
111 } | 134 } |
112 | 135 |
113 virtual void onDraw(SkCanvas* canvas) override { | 136 virtual void onDraw(SkCanvas* canvas) override { |
114 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 137 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
115 draw_bitmap, draw_path, draw_paint, draw_text | 138 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text |
116 }; | 139 }; |
117 | 140 |
118 SkAutoTUnref<SkColorFilter> cf( | 141 SkAutoTUnref<SkColorFilter> cf( |
119 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); | 142 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); |
120 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); | 143 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); |
121 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); | 144 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); |
122 | 145 |
123 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( | 146 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( |
124 SkIntToScalar(-10), SkIntToScalar(-10))); | 147 SkIntToScalar(-10), SkIntToScalar(-10))); |
125 | 148 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 191 } |
169 | 192 |
170 private: | 193 private: |
171 SkBitmap fCheckerboard; | 194 SkBitmap fCheckerboard; |
172 typedef GM INHERITED; | 195 typedef GM INHERITED; |
173 }; | 196 }; |
174 | 197 |
175 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
176 | 199 |
177 DEF_GM( return new ImageFiltersCroppedGM; ) | 200 DEF_GM( return new ImageFiltersCroppedGM; ) |
OLD | NEW |