OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 SkCanvas c(bm); | 60 SkCanvas c(bm); |
61 draw_path(&c, r, nullptr); | 61 draw_path(&c, r, nullptr); |
62 | 62 |
63 paint.setImageFilter(imf); | 63 paint.setImageFilter(imf); |
64 canvas->save(); | 64 canvas->save(); |
65 canvas->clipRect(r); | 65 canvas->clipRect(r); |
66 canvas->drawBitmap(bm, 0, 0, &paint); | 66 canvas->drawBitmap(bm, 0, 0, &paint); |
67 canvas->restore(); | 67 canvas->restore(); |
68 } | 68 } |
69 | 69 |
| 70 static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
| 71 SkPaint paint; |
| 72 |
| 73 SkIRect bounds; |
| 74 r.roundOut(&bounds); |
| 75 |
| 76 SkBitmap bm; |
| 77 bm.allocN32Pixels(bounds.width(), bounds.height()); |
| 78 bm.eraseColor(SK_ColorRED); |
| 79 SkCanvas c(bm); |
| 80 |
| 81 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); |
| 82 paint.setColor(SK_ColorGREEN); |
| 83 c.drawRect(SkRect::Make(cropRect), paint); |
| 84 |
| 85 paint.setImageFilter(imf); |
| 86 SkPoint loc = { r.fLeft, r.fTop }; |
| 87 canvas->getTotalMatrix().mapPoints(&loc, 1); |
| 88 canvas->drawSprite(bm, |
| 89 SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), |
| 90 &paint); |
| 91 } |
| 92 |
70 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
71 | 94 |
72 class DropShadowImageFilterGM : public skiagm::GM { | 95 class DropShadowImageFilterGM : public skiagm::GM { |
73 public: | 96 public: |
74 DropShadowImageFilterGM () {} | 97 DropShadowImageFilterGM () {} |
75 | 98 |
76 protected: | 99 protected: |
77 | 100 |
78 virtual SkString onShortName() { | 101 virtual SkString onShortName() { |
79 return SkString("dropshadowimagefilter"); | 102 return SkString("dropshadowimagefilter"); |
80 } | 103 } |
81 | 104 |
82 virtual SkISize onISize() { return SkISize::Make(400, 656); } | 105 virtual SkISize onISize() { return SkISize::Make(400, 656); } |
83 | 106 |
84 void draw_frame(SkCanvas* canvas, const SkRect& r) { | 107 void draw_frame(SkCanvas* canvas, const SkRect& r) { |
85 SkPaint paint; | 108 SkPaint paint; |
86 paint.setStyle(SkPaint::kStroke_Style); | 109 paint.setStyle(SkPaint::kStroke_Style); |
87 paint.setColor(SK_ColorRED); | 110 paint.setColor(SK_ColorRED); |
88 canvas->drawRect(r, paint); | 111 canvas->drawRect(r, paint); |
89 } | 112 } |
90 | 113 |
91 virtual void onDraw(SkCanvas* canvas) { | 114 virtual void onDraw(SkCanvas* canvas) { |
92 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 115 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
93 draw_bitmap, draw_path, draw_paint, draw_text | 116 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text |
94 }; | 117 }; |
95 | 118 |
96 SkAutoTUnref<SkColorFilter> cf( | 119 SkAutoTUnref<SkColorFilter> cf( |
97 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_
Mode)); | 120 SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_
Mode)); |
98 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get
())); | 121 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get
())); |
99 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), | 122 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10,
44, 44)), |
100 SkImageFilter::CropRect::kHasAll_CropEd
ge); | 123 SkImageFilter::CropRect::kHasAll_CropEd
ge); |
101 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), | 124 SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -
100, 10, 10)), |
102 SkImageFilter::CropRect::kHasAll_CropE
dge); | 125 SkImageFilter::CropRect::kHasAll_CropE
dge); |
103 | 126 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 163 } |
141 } | 164 } |
142 | 165 |
143 private: | 166 private: |
144 typedef GM INHERITED; | 167 typedef GM INHERITED; |
145 }; | 168 }; |
146 | 169 |
147 /////////////////////////////////////////////////////////////////////////////// | 170 /////////////////////////////////////////////////////////////////////////////// |
148 | 171 |
149 DEF_GM( return new DropShadowImageFilterGM; ) | 172 DEF_GM( return new DropShadowImageFilterGM; ) |
OLD | NEW |