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 | |
91 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
92 | 69 |
93 class ImageFiltersCroppedGM : public skiagm::GM { | 70 class ImageFiltersCroppedGM : public skiagm::GM { |
94 public: | 71 public: |
95 ImageFiltersCroppedGM () {} | 72 ImageFiltersCroppedGM () {} |
96 | 73 |
97 protected: | 74 protected: |
98 virtual SkString onShortName() override { | 75 virtual SkString onShortName() override { |
99 return SkString("imagefilterscropped"); | 76 return SkString("imagefilterscropped"); |
100 } | 77 } |
(...skipping 27 matching lines...) Expand all Loading... |
128 paint.setColor(SK_ColorRED); | 105 paint.setColor(SK_ColorRED); |
129 canvas->drawRect(r, paint); | 106 canvas->drawRect(r, paint); |
130 } | 107 } |
131 | 108 |
132 virtual void onOnceBeforeDraw() override{ | 109 virtual void onOnceBeforeDraw() override{ |
133 make_checkerboard(); | 110 make_checkerboard(); |
134 } | 111 } |
135 | 112 |
136 virtual void onDraw(SkCanvas* canvas) override { | 113 virtual void onDraw(SkCanvas* canvas) override { |
137 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 114 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
138 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text | 115 draw_bitmap, draw_path, draw_paint, draw_text |
139 }; | 116 }; |
140 | 117 |
141 SkAutoTUnref<SkColorFilter> cf( | 118 SkAutoTUnref<SkColorFilter> cf( |
142 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); | 119 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); |
143 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); | 120 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); |
144 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); | 121 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); |
145 | 122 |
146 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( | 123 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( |
147 SkIntToScalar(-10), SkIntToScalar(-10))); | 124 SkIntToScalar(-10), SkIntToScalar(-10))); |
148 | 125 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 168 } |
192 | 169 |
193 private: | 170 private: |
194 SkBitmap fCheckerboard; | 171 SkBitmap fCheckerboard; |
195 typedef GM INHERITED; | 172 typedef GM INHERITED; |
196 }; | 173 }; |
197 | 174 |
198 /////////////////////////////////////////////////////////////////////////////// | 175 /////////////////////////////////////////////////////////////////////////////// |
199 | 176 |
200 DEF_GM( return new ImageFiltersCroppedGM; ) | 177 DEF_GM( return new ImageFiltersCroppedGM; ) |
OLD | NEW |