Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: gm/imagefiltersbase.cpp

Issue 1530203002: Reland of move drawSprite from canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/dropshadowimagefilter.cpp ('k') | gm/imagefilterscropped.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 SkBitmap bm; 159 SkBitmap bm;
160 bm.allocN32Pixels(bounds.width(), bounds.height()); 160 bm.allocN32Pixels(bounds.width(), bounds.height());
161 bm.eraseColor(SK_ColorTRANSPARENT); 161 bm.eraseColor(SK_ColorTRANSPARENT);
162 SkCanvas c(bm); 162 SkCanvas c(bm);
163 draw_path(&c, r, nullptr); 163 draw_path(&c, r, nullptr);
164 164
165 canvas->drawBitmap(bm, 0, 0, &paint); 165 canvas->drawBitmap(bm, 0, 0, &paint);
166 } 166 }
167 167
168 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
169 SkPaint paint;
170 paint.setImageFilter(imf);
171
172 SkIRect bounds;
173 r.roundOut(&bounds);
174
175 SkBitmap bm;
176 bm.allocN32Pixels(bounds.width(), bounds.height());
177 bm.eraseColor(SK_ColorTRANSPARENT);
178 SkCanvas c(bm);
179 draw_path(&c, r, nullptr);
180
181 SkPoint loc = { r.fLeft, r.fTop };
182 canvas->getTotalMatrix().mapPoints(&loc, 1);
183 canvas->drawSprite(bm,
184 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY),
185 &paint);
186 }
187
188 /////////////////////////////////////////////////////////////////////////////// 168 ///////////////////////////////////////////////////////////////////////////////
189 169
190 class ImageFiltersBaseGM : public skiagm::GM { 170 class ImageFiltersBaseGM : public skiagm::GM {
191 public: 171 public:
192 ImageFiltersBaseGM () {} 172 ImageFiltersBaseGM () {}
193 173
194 protected: 174 protected:
195 SkString onShortName() override { 175 SkString onShortName() override {
196 return SkString("imagefiltersbase"); 176 return SkString("imagefiltersbase");
197 } 177 }
198 178
199 SkISize onISize() override { return SkISize::Make(700, 500); } 179 SkISize onISize() override { return SkISize::Make(700, 500); }
200 180
201 void draw_frame(SkCanvas* canvas, const SkRect& r) { 181 void draw_frame(SkCanvas* canvas, const SkRect& r) {
202 SkPaint paint; 182 SkPaint paint;
203 paint.setStyle(SkPaint::kStroke_Style); 183 paint.setStyle(SkPaint::kStroke_Style);
204 paint.setColor(SK_ColorRED); 184 paint.setColor(SK_ColorRED);
205 canvas->drawRect(r, paint); 185 canvas->drawRect(r, paint);
206 } 186 }
207 187
208 void onDraw(SkCanvas* canvas) override { 188 void onDraw(SkCanvas* canvas) override {
209 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 189 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
210 draw_paint, 190 draw_paint,
211 draw_line, draw_rect, draw_path, draw_text, 191 draw_line, draw_rect, draw_path, draw_text,
212 draw_bitmap, 192 draw_bitmap,
213 draw_sprite
214 }; 193 };
215 194
216 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, 195 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
217 SkXfermode::kSrcIn_Mode); 196 SkXfermode::kSrcIn_Mode);
218 SkImageFilter* filters[] = { 197 SkImageFilter* filters[] = {
219 nullptr, 198 nullptr,
220 IdentityImageFilter::Create(), 199 IdentityImageFilter::Create(),
221 FailImageFilter::Create(), 200 FailImageFilter::Create(),
222 SkColorFilterImageFilter::Create(cf), 201 SkColorFilterImageFilter::Create(cf),
223 SkBlurImageFilter::Create(12.0f, 0.0f), 202 SkBlurImageFilter::Create(12.0f, 0.0f),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { 318 class ImageFiltersText_CF : public ImageFiltersTextBaseGM {
340 public: 319 public:
341 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} 320 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {}
342 321
343 void installFilter(SkPaint* paint) override { 322 void installFilter(SkPaint* paint) override {
344 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf ermode::kSrcIn_Mode))->unref(); 323 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf ermode::kSrcIn_Mode))->unref();
345 } 324 }
346 }; 325 };
347 DEF_GM( return new ImageFiltersText_CF; ) 326 DEF_GM( return new ImageFiltersText_CF; )
348 327
OLDNEW
« no previous file with comments | « gm/dropshadowimagefilter.cpp ('k') | gm/imagefilterscropped.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698