| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 168 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
| 169 | 189 |
| 170 class ImageFiltersBaseGM : public skiagm::GM { | 190 class ImageFiltersBaseGM : public skiagm::GM { |
| 171 public: | 191 public: |
| 172 ImageFiltersBaseGM () {} | 192 ImageFiltersBaseGM () {} |
| 173 | 193 |
| 174 protected: | 194 protected: |
| 175 SkString onShortName() override { | 195 SkString onShortName() override { |
| 176 return SkString("imagefiltersbase"); | 196 return SkString("imagefiltersbase"); |
| 177 } | 197 } |
| 178 | 198 |
| 179 SkISize onISize() override { return SkISize::Make(700, 500); } | 199 SkISize onISize() override { return SkISize::Make(700, 500); } |
| 180 | 200 |
| 181 void draw_frame(SkCanvas* canvas, const SkRect& r) { | 201 void draw_frame(SkCanvas* canvas, const SkRect& r) { |
| 182 SkPaint paint; | 202 SkPaint paint; |
| 183 paint.setStyle(SkPaint::kStroke_Style); | 203 paint.setStyle(SkPaint::kStroke_Style); |
| 184 paint.setColor(SK_ColorRED); | 204 paint.setColor(SK_ColorRED); |
| 185 canvas->drawRect(r, paint); | 205 canvas->drawRect(r, paint); |
| 186 } | 206 } |
| 187 | 207 |
| 188 void onDraw(SkCanvas* canvas) override { | 208 void onDraw(SkCanvas* canvas) override { |
| 189 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 209 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
| 190 draw_paint, | 210 draw_paint, |
| 191 draw_line, draw_rect, draw_path, draw_text, | 211 draw_line, draw_rect, draw_path, draw_text, |
| 192 draw_bitmap, | 212 draw_bitmap, |
| 213 draw_sprite |
| 193 }; | 214 }; |
| 194 | 215 |
| 195 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, | 216 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, |
| 196 SkXfermode::kSrcIn_Mode); | 217 SkXfermode::kSrcIn_Mode); |
| 197 SkImageFilter* filters[] = { | 218 SkImageFilter* filters[] = { |
| 198 nullptr, | 219 nullptr, |
| 199 IdentityImageFilter::Create(), | 220 IdentityImageFilter::Create(), |
| 200 FailImageFilter::Create(), | 221 FailImageFilter::Create(), |
| 201 SkColorFilterImageFilter::Create(cf), | 222 SkColorFilterImageFilter::Create(cf), |
| 202 SkBlurImageFilter::Create(12.0f, 0.0f), | 223 SkBlurImageFilter::Create(12.0f, 0.0f), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { | 339 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { |
| 319 public: | 340 public: |
| 320 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} | 341 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} |
| 321 | 342 |
| 322 void installFilter(SkPaint* paint) override { | 343 void installFilter(SkPaint* paint) override { |
| 323 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf
ermode::kSrcIn_Mode))->unref(); | 344 paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXf
ermode::kSrcIn_Mode))->unref(); |
| 324 } | 345 } |
| 325 }; | 346 }; |
| 326 DEF_GM( return new ImageFiltersText_CF; ) | 347 DEF_GM( return new ImageFiltersText_CF; ) |
| 327 | 348 |
| OLD | NEW |