| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 9 |
| 10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
| 11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
| 12 #include "SkBitmapSource.h" | 12 #include "SkBitmapSource.h" |
| 13 #include "SkBlurImageFilter.h" | 13 #include "SkBlurImageFilter.h" |
| 14 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
| 15 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
| 16 #include "SkColorMatrixFilter.h" | 16 #include "SkColorMatrixFilter.h" |
| 17 #include "SkReadBuffer.h" | 17 #include "SkReadBuffer.h" |
| 18 #include "SkWriteBuffer.h" | 18 #include "SkWriteBuffer.h" |
| 19 #include "SkMergeImageFilter.h" | 19 #include "SkMergeImageFilter.h" |
| 20 #include "SkMorphologyImageFilter.h" | 20 #include "SkMorphologyImageFilter.h" |
| 21 #include "SkOnce.h" | |
| 22 #include "SkTestImageFilters.h" | 21 #include "SkTestImageFilters.h" |
| 23 #include "SkXfermodeImageFilter.h" | 22 #include "SkXfermodeImageFilter.h" |
| 24 | 23 |
| 25 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm
ageFilter doesn't | 24 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm
ageFilter doesn't |
| 26 // perform a draw and this one does. | 25 // perform a draw and this one does. |
| 27 class SimpleOffsetFilter : public SkImageFilter { | 26 class SimpleOffsetFilter : public SkImageFilter { |
| 28 public: | 27 public: |
| 29 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input)
{ | 28 static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkImageFilter* input)
{ |
| 30 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); | 29 return SkNEW_ARGS(SimpleOffsetFilter, (dx, dy, input)); |
| 31 } | 30 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 buffer.writeScalar(fDY); | 69 buffer.writeScalar(fDY); |
| 71 } | 70 } |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) | 73 SimpleOffsetFilter(SkScalar dx, SkScalar dy, SkImageFilter* input) |
| 75 : SkImageFilter(input), fDX(dx), fDY(dy) {} | 74 : SkImageFilter(input), fDX(dx), fDY(dy) {} |
| 76 | 75 |
| 77 SkScalar fDX, fDY; | 76 SkScalar fDX, fDY; |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 static void init_flattenable(int*) { | 79 SkFlattenable::Registrar registrar("SimpleOffsetFilter", |
| 81 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SimpleOffsetFilter) | 80 SimpleOffsetFilter::CreateProc, |
| 82 } | 81 SimpleOffsetFilter::GetFlattenableType()); |
| 83 | 82 |
| 84 class ImageFiltersGraphGM : public skiagm::GM { | 83 class ImageFiltersGraphGM : public skiagm::GM { |
| 85 public: | 84 public: |
| 86 ImageFiltersGraphGM() : fInitialized(false) { | 85 ImageFiltersGraphGM() {} |
| 87 int dummy; | |
| 88 SK_DECLARE_STATIC_ONCE(once); | |
| 89 SkOnce(&once, init_flattenable, &dummy); | |
| 90 } | |
| 91 | 86 |
| 92 protected: | 87 protected: |
| 93 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 88 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 94 return kSkipTiled_Flag; | 89 return kSkipTiled_Flag; |
| 95 } | 90 } |
| 96 | 91 |
| 97 virtual SkString onShortName() { | 92 virtual SkString onShortName() { |
| 98 return SkString("imagefiltersgraph"); | 93 return SkString("imagefiltersgraph"); |
| 99 } | 94 } |
| 100 | 95 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint) { | 108 void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPai
nt& paint) { |
| 114 canvas->save(); | 109 canvas->save(); |
| 115 canvas->clipRect(SkRect::MakeXYWH(0, 0, | 110 canvas->clipRect(SkRect::MakeXYWH(0, 0, |
| 116 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); | 111 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
| 117 canvas->drawBitmap(bitmap, 0, 0, &paint); | 112 canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 118 canvas->restore(); | 113 canvas->restore(); |
| 119 } | 114 } |
| 120 | 115 |
| 121 virtual SkISize onISize() { return SkISize::Make(500, 150); } | 116 virtual SkISize onISize() { return SkISize::Make(500, 150); } |
| 122 | 117 |
| 118 virtual void onOnceBeforeDraw() { |
| 119 this->make_bitmap(); |
| 120 } |
| 121 |
| 123 virtual void onDraw(SkCanvas* canvas) { | 122 virtual void onDraw(SkCanvas* canvas) { |
| 124 if (!fInitialized) { | |
| 125 this->make_bitmap(); | |
| 126 fInitialized = true; | |
| 127 } | |
| 128 canvas->clear(0x00000000); | 123 canvas->clear(0x00000000); |
| 129 { | 124 { |
| 130 SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBit
map)); | 125 SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBit
map)); |
| 131 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, | 126 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, |
| 132 SkXfermode::kSrcIn_Mode
)); | 127 SkXfermode::kSrcIn_Mode
)); |
| 133 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f, bitmapSource)); | 128 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f, bitmapSource)); |
| 134 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b
lur)); | 129 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b
lur)); |
| 135 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); | 130 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); |
| 136 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c
olor)); | 131 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c
olor)); |
| 137 | 132 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 paint.setImageFilter(color2); | 203 paint.setImageFilter(color2); |
| 209 paint.setColor(0xFFFF0000); | 204 paint.setColor(0xFFFF0000); |
| 210 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); | 205 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); |
| 211 canvas->translate(SkIntToScalar(100), 0); | 206 canvas->translate(SkIntToScalar(100), 0); |
| 212 } | 207 } |
| 213 } | 208 } |
| 214 | 209 |
| 215 private: | 210 private: |
| 216 typedef GM INHERITED; | 211 typedef GM INHERITED; |
| 217 SkBitmap fBitmap; | 212 SkBitmap fBitmap; |
| 218 bool fInitialized; | |
| 219 }; | 213 }; |
| 220 | 214 |
| 221 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
| 222 | 216 |
| 223 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } | 217 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } |
| 224 static skiagm::GMRegistry reg(MyFactory); | 218 static skiagm::GMRegistry reg(MyFactory); |
| OLD | NEW |