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" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 #include "SkBlurImageFilter.h" | 14 #include "SkBlurImageFilter.h" |
15 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
| 16 #include "SkMergeImageFilter.h" |
| 17 #include "SkOffsetImageFilter.h" |
16 #include "SkTestImageFilters.h" | 18 #include "SkTestImageFilters.h" |
17 | 19 |
18 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
19 | 21 |
20 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { | 22 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { |
21 SkPaint paint; | 23 SkPaint paint; |
22 paint.setImageFilter(imf); | 24 paint.setImageFilter(imf); |
23 paint.setColor(SK_ColorBLACK); | 25 paint.setColor(SK_ColorBLACK); |
24 canvas->save(); | 26 canvas->save(); |
25 canvas->clipRect(r); | 27 canvas->clipRect(r); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // reciprocal scale that is applied at record time, which is | 124 // reciprocal scale that is applied at record time, which is |
123 // the intended behavior of drawSprite. | 125 // the intended behavior of drawSprite. |
124 return kSkipScaledReplay_Flag; | 126 return kSkipScaledReplay_Flag; |
125 } | 127 } |
126 | 128 |
127 virtual void onDraw(SkCanvas* canvas) { | 129 virtual void onDraw(SkCanvas* canvas) { |
128 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { | 130 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { |
129 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text | 131 draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text |
130 }; | 132 }; |
131 | 133 |
132 SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, | 134 SkAutoTUnref<SkColorFilter> cf( |
133 SkXfermode::kSrcIn_Mode); | 135 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); |
134 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); | 136 SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); |
135 SkIRect bogusRect = SkIRect::MakeXYWH(-100, -100, 10, 10); | 137 SkIRect bogusRect = SkIRect::MakeXYWH(-100, -100, 10, 10); |
136 | 138 |
| 139 SkAutoTUnref<SkImageFilter> offset(new SkOffsetImageFilter( |
| 140 SkIntToScalar(-10), SkIntToScalar(-10))); |
| 141 |
| 142 SkAutoTUnref<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf
.get(), offset.get())); |
| 143 |
137 SkImageFilter* filters[] = { | 144 SkImageFilter* filters[] = { |
138 NULL, | 145 NULL, |
139 SkColorFilterImageFilter::Create(cf, NULL, &cropRect), | 146 SkColorFilterImageFilter::Create(cf.get(), NULL, &cropRect), |
140 new SkBlurImageFilter(1.0f, 1.0f, NULL, &cropRect), | 147 new SkBlurImageFilter(1.0f, 1.0f, NULL, &cropRect), |
141 new SkBlurImageFilter(8.0f, 0.0f, NULL, &cropRect), | 148 new SkBlurImageFilter(8.0f, 0.0f, NULL, &cropRect), |
142 new SkBlurImageFilter(0.0f, 8.0f, NULL, &cropRect), | 149 new SkBlurImageFilter(0.0f, 8.0f, NULL, &cropRect), |
143 new SkBlurImageFilter(8.0f, 8.0f, NULL, &cropRect), | 150 new SkBlurImageFilter(8.0f, 8.0f, NULL, &cropRect), |
| 151 new SkMergeImageFilter(NULL, cfOffset.get(), SkXfermode::kSrcOver_Mo
de, &cropRect), |
144 new SkBlurImageFilter(8.0f, 8.0f, NULL, &bogusRect), | 152 new SkBlurImageFilter(8.0f, 8.0f, NULL, &bogusRect), |
145 SkColorFilterImageFilter::Create(cf, NULL, &bogusRect), | 153 SkColorFilterImageFilter::Create(cf.get(), NULL, &bogusRect), |
146 }; | 154 }; |
147 cf->unref(); | |
148 | 155 |
149 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 156 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
150 SkScalar MARGIN = SkIntToScalar(16); | 157 SkScalar MARGIN = SkIntToScalar(16); |
151 SkScalar DX = r.width() + MARGIN; | 158 SkScalar DX = r.width() + MARGIN; |
152 SkScalar DY = r.height() + MARGIN; | 159 SkScalar DY = r.height() + MARGIN; |
153 | 160 |
154 canvas->translate(MARGIN, MARGIN); | 161 canvas->translate(MARGIN, MARGIN); |
155 for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { | 162 for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { |
156 canvas->save(); | 163 canvas->save(); |
157 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 164 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
168 } | 175 } |
169 | 176 |
170 private: | 177 private: |
171 typedef GM INHERITED; | 178 typedef GM INHERITED; |
172 }; | 179 }; |
173 | 180 |
174 /////////////////////////////////////////////////////////////////////////////// | 181 /////////////////////////////////////////////////////////////////////////////// |
175 | 182 |
176 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } | 183 static skiagm::GM* MyFactory(void*) { return new ImageFiltersCroppedGM; } |
177 static skiagm::GMRegistry reg(MyFactory); | 184 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |