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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 virtual SkISize onISize() { return SkISize::Make(500, 150); } | 115 virtual SkISize onISize() { return SkISize::Make(500, 150); } |
116 | 116 |
117 virtual void onDraw(SkCanvas* canvas) { | 117 virtual void onDraw(SkCanvas* canvas) { |
118 if (!fInitialized) { | 118 if (!fInitialized) { |
119 this->make_bitmap(); | 119 this->make_bitmap(); |
120 fInitialized = true; | 120 fInitialized = true; |
121 } | 121 } |
122 canvas->clear(0x00000000); | 122 canvas->clear(0x00000000); |
123 { | 123 { |
124 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap)
); | 124 SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBit
map)); |
125 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, | 125 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_Co
lorRED, |
126 SkXfermode::kSrcIn_Mode
)); | 126 SkXfermode::kSrcIn_Mode
)); |
127 SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter(4.0f, 4.0f, b
itmapSource)); | 127 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f, bitmapSource)); |
128 SkAutoTUnref<SkImageFilter> erode(new SkErodeImageFilter(4, 4, blur)
); | 128 SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, b
lur)); |
129 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); | 129 SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(c
f, erode)); |
130 SkAutoTUnref<SkImageFilter> merge(new SkMergeImageFilter(blur, color
)); | 130 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, c
olor)); |
131 | 131 |
132 SkPaint paint; | 132 SkPaint paint; |
133 paint.setImageFilter(merge); | 133 paint.setImageFilter(merge); |
134 canvas->drawPaint(paint); | 134 canvas->drawPaint(paint); |
135 canvas->translate(SkIntToScalar(100), 0); | 135 canvas->translate(SkIntToScalar(100), 0); |
136 } | 136 } |
137 { | 137 { |
138 SkAutoTUnref<SkImageFilter> morph(new SkDilateImageFilter(5, 5)); | 138 SkAutoTUnref<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5))
; |
139 | 139 |
140 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 140 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
141 0, SK_Scalar1, 0, 0, 0, | 141 0, SK_Scalar1, 0, 0, 0, |
142 0, 0, SK_Scalar1, 0, 0, | 142 0, 0, SK_Scalar1, 0, 0, |
143 0, 0, 0, 0.5f, 0 }; | 143 0, 0, 0, 0.5f, 0 }; |
144 | 144 |
145 SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create
(matrix)); | 145 SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create
(matrix)); |
146 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter, morph)); | 146 SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Cre
ate(matrixFilter, morph)); |
147 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); | 147 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); |
148 SkAutoTUnref<SkImageFilter> blendColor(new SkXfermodeImageFilter(mod
e, colorMorph)); | 148 SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create
(mode, colorMorph)); |
149 | 149 |
150 SkPaint paint; | 150 SkPaint paint; |
151 paint.setImageFilter(blendColor); | 151 paint.setImageFilter(blendColor); |
152 drawClippedBitmap(canvas, fBitmap, paint); | 152 drawClippedBitmap(canvas, fBitmap, paint); |
153 canvas->translate(SkIntToScalar(100), 0); | 153 canvas->translate(SkIntToScalar(100), 0); |
154 } | 154 } |
155 { | 155 { |
156 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, | 156 SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, |
157 0, SK_Scalar1, 0, 0, 0, | 157 0, SK_Scalar1, 0, 0, 0, |
158 0, 0, SK_Scalar1, 0, 0, | 158 0, 0, SK_Scalar1, 0, 0, |
159 0, 0, 0, 0.5f, 0 }; | 159 0, 0, 0, 0.5f, 0 }; |
160 SkAutoTUnref<SkColorMatrixFilter> matrixCF(SkColorMatrixFilter::Crea
te(matrix)); | 160 SkAutoTUnref<SkColorMatrixFilter> matrixCF(SkColorMatrixFilter::Crea
te(matrix)); |
161 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(matrixCF)); | 161 SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::C
reate(matrixCF)); |
162 SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10)
, matrixFilter); | 162 SimpleOffsetFilter offsetFilter(SkIntToScalar(10), SkIntToScalar(10)
, matrixFilter); |
163 | 163 |
164 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); | 164 SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar
1, SK_Scalar1, 0)); |
165 SkXfermodeImageFilter arithFilter(arith, matrixFilter, &offsetFilter
); | 165 SkAutoTUnref<SkXfermodeImageFilter> arithFilter( |
| 166 SkXfermodeImageFilter::Create(arith, matrixFilter, &offsetFilter
)); |
166 | 167 |
167 SkPaint paint; | 168 SkPaint paint; |
168 paint.setImageFilter(&arithFilter); | 169 paint.setImageFilter(arithFilter); |
169 drawClippedBitmap(canvas, fBitmap, paint); | 170 drawClippedBitmap(canvas, fBitmap, paint); |
170 canvas->translate(SkIntToScalar(100), 0); | 171 canvas->translate(SkIntToScalar(100), 0); |
171 } | 172 } |
172 { | 173 { |
173 SkAutoTUnref<SkImageFilter> blur(new SkBlurImageFilter( | 174 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create( |
174 SkIntToScalar(10), SkIntToScalar(10))); | 175 SkIntToScalar(10), SkIntToScalar(10))); |
175 | 176 |
176 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_
Mode)); | 177 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_
Mode)); |
177 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S
kIntToScalar(100))); | 178 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S
kIntToScalar(100))); |
178 SkAutoTUnref<SkImageFilter> blend(new SkXfermodeImageFilter(mode, bl
ur, NULL, &cropRect)); | 179 SkAutoTUnref<SkImageFilter> blend( |
| 180 SkXfermodeImageFilter::Create(mode, blur, NULL, &cropRect)); |
179 | 181 |
180 SkPaint paint; | 182 SkPaint paint; |
181 paint.setImageFilter(blend); | 183 paint.setImageFilter(blend); |
182 drawClippedBitmap(canvas, fBitmap, paint); | 184 drawClippedBitmap(canvas, fBitmap, paint); |
183 canvas->translate(SkIntToScalar(100), 0); | 185 canvas->translate(SkIntToScalar(100), 0); |
184 } | 186 } |
185 { | 187 { |
186 // Test that crop offsets are absolute, not relative to the parent's
crop rect. | 188 // Test that crop offsets are absolute, not relative to the parent's
crop rect. |
187 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C
olorBLUE, | 189 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C
olorBLUE, |
188 SkXf
ermode::kSrcIn_Mode)); | 190 SkXf
ermode::kSrcIn_Mode)); |
(...skipping 17 matching lines...) Expand all Loading... |
206 private: | 208 private: |
207 typedef GM INHERITED; | 209 typedef GM INHERITED; |
208 SkBitmap fBitmap; | 210 SkBitmap fBitmap; |
209 bool fInitialized; | 211 bool fInitialized; |
210 }; | 212 }; |
211 | 213 |
212 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
213 | 215 |
214 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } | 216 static skiagm::GM* MyFactory(void*) { return new ImageFiltersGraphGM; } |
215 static skiagm::GMRegistry reg(MyFactory); | 217 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |