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 #include "SampleCode.h" | 7 #include "SampleCode.h" |
8 #include "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
9 #include "SkBicubicImageFilter.h" | 9 #include "SkBicubicImageFilter.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkBitmapSource.h" | 11 #include "SkBitmapSource.h" |
12 #include "SkBlurImageFilter.h" | 12 #include "SkBlurImageFilter.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
15 #include "SkColorFilterImageFilter.h" | 15 #include "SkColorFilterImageFilter.h" |
16 #include "SkComposeImageFilter.h" | 16 #include "SkComposeImageFilter.h" |
17 #include "SkData.h" | 17 #include "SkData.h" |
18 #include "SkDisplacementMapEffect.h" | 18 #include "SkDisplacementMapEffect.h" |
19 #include "SkDropShadowImageFilter.h" | 19 #include "SkDropShadowImageFilter.h" |
20 #include "SkFlattenableSerialization.h" | 20 #include "SkFlattenableSerialization.h" |
21 #include "SkLightingImageFilter.h" | 21 #include "SkLightingImageFilter.h" |
22 #include "SkMagnifierImageFilter.h" | 22 #include "SkMagnifierImageFilter.h" |
23 #include "SkMatrixImageFilter.h" | 23 #include "SkMatrixImageFilter.h" |
24 #include "SkMatrixConvolutionImageFilter.h" | 24 #include "SkMatrixConvolutionImageFilter.h" |
25 #include "SkMergeImageFilter.h" | 25 #include "SkMergeImageFilter.h" |
26 #include "SkMorphologyImageFilter.h" | 26 #include "SkMorphologyImageFilter.h" |
27 #include "SkOffsetImageFilter.h" | 27 #include "SkOffsetImageFilter.h" |
28 #include "SkPerlinNoiseShader.h" | 28 #include "SkPerlinNoiseShader.h" |
29 #include "SkPictureImageFilter.h" | 29 #include "SkPictureImageFilter.h" |
| 30 #include "SkPictureRecorder.h" |
30 #include "SkRandom.h" | 31 #include "SkRandom.h" |
31 #include "SkRectShaderImageFilter.h" | 32 #include "SkRectShaderImageFilter.h" |
32 #include "SkTestImageFilters.h" | 33 #include "SkTestImageFilters.h" |
33 #include "SkTileImageFilter.h" | 34 #include "SkTileImageFilter.h" |
34 #include "SkView.h" | 35 #include "SkView.h" |
35 #include "SkXfermodeImageFilter.h" | 36 #include "SkXfermodeImageFilter.h" |
36 #include <stdio.h> | 37 #include <stdio.h> |
37 #include <time.h> | 38 #include <time.h> |
38 | 39 |
39 //#define SK_ADD_RANDOM_BIT_FLIPS | 40 //#define SK_ADD_RANDOM_BIT_FLIPS |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 static SkBitmap bitmap[2]; | 200 static SkBitmap bitmap[2]; |
200 static bool initialized = false; | 201 static bool initialized = false; |
201 if (!initialized) { | 202 if (!initialized) { |
202 make_g_bitmap(bitmap[0]); | 203 make_g_bitmap(bitmap[0]); |
203 make_checkerboard_bitmap(bitmap[1]); | 204 make_checkerboard_bitmap(bitmap[1]); |
204 initialized = true; | 205 initialized = true; |
205 } | 206 } |
206 return bitmap[R(2)]; | 207 return bitmap[R(2)]; |
207 } | 208 } |
208 | 209 |
209 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION | |
210 static void drawSomething(SkCanvas* canvas) { | 210 static void drawSomething(SkCanvas* canvas) { |
211 SkPaint paint; | 211 SkPaint paint; |
212 | 212 |
213 canvas->save(); | 213 canvas->save(); |
214 canvas->scale(0.5f, 0.5f); | 214 canvas->scale(0.5f, 0.5f); |
215 canvas->drawBitmap(make_bitmap(), 0, 0, NULL); | 215 canvas->drawBitmap(make_bitmap(), 0, 0, NULL); |
216 canvas->restore(); | 216 canvas->restore(); |
217 | 217 |
218 const char beforeStr[] = "before circle"; | 218 const char beforeStr[] = "before circle"; |
219 const char afterStr[] = "after circle"; | 219 const char afterStr[] = "after circle"; |
220 | 220 |
221 paint.setAntiAlias(true); | 221 paint.setAntiAlias(true); |
222 | 222 |
223 paint.setColor(SK_ColorRED); | 223 paint.setColor(SK_ColorRED); |
224 canvas->drawData(beforeStr, sizeof(beforeStr)); | 224 canvas->drawData(beforeStr, sizeof(beforeStr)); |
225 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2
), SkIntToScalar(kBitmapSize/3), paint); | 225 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2
), SkIntToScalar(kBitmapSize/3), paint); |
226 canvas->drawData(afterStr, sizeof(afterStr)); | 226 canvas->drawData(afterStr, sizeof(afterStr)); |
227 paint.setColor(SK_ColorBLACK); | 227 paint.setColor(SK_ColorBLACK); |
228 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); | 228 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); |
229 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k
BitmapSize/4), paint); | 229 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k
BitmapSize/4), paint); |
230 } | 230 } |
231 #endif | |
232 | 231 |
233 static SkImageFilter* make_image_filter(bool canBeNull = true) { | 232 static SkImageFilter* make_image_filter(bool canBeNull = true) { |
234 SkImageFilter* filter = 0; | 233 SkImageFilter* filter = 0; |
235 | 234 |
236 // Add a 1 in 3 chance to get a NULL input | 235 // Add a 1 in 3 chance to get a NULL input |
237 if (canBeNull && (R(3) == 1)) { return filter; } | 236 if (canBeNull && (R(3) == 1)) { return filter; } |
238 | 237 |
239 enum { ALPHA_THRESHOLD, BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, | 238 enum { ALPHA_THRESHOLD, BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, |
240 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, | 239 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, |
241 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 240 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 case DISPLACE: | 368 case DISPLACE: |
370 filter = SkDisplacementMapEffect::Create(make_channel_selector_type(), | 369 filter = SkDisplacementMapEffect::Create(make_channel_selector_type(), |
371 make_channel_selector_type(), m
ake_scalar(), | 370 make_channel_selector_type(), m
ake_scalar(), |
372 make_image_filter(false), make_
image_filter()); | 371 make_image_filter(false), make_
image_filter()); |
373 break; | 372 break; |
374 case TILE: | 373 case TILE: |
375 filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_
filter(false)); | 374 filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_
filter(false)); |
376 break; | 375 break; |
377 case PICTURE: | 376 case PICTURE: |
378 { | 377 { |
379 SkPicture* pict = NULL; | 378 SkRTreeFactory factory; |
380 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION | 379 SkPictureRecorder recorder; |
381 pict = new SkPicture; | 380 SkCanvas* recordingCanvas = recorder.beginRecording(kBitmapSize, kBitmap
Size, &factory, 0); |
382 SkAutoUnref aur(pict); | 381 drawSomething(recordingCanvas); |
383 drawSomething(pict->beginRecording(kBitmapSize, kBitmapSize)); | 382 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
384 pict->endRecording(); | 383 filter = SkPictureImageFilter::Create(pict.get(), make_rect()); |
385 #endif | |
386 filter = SkPictureImageFilter::Create(pict, make_rect()); | |
387 } | 384 } |
388 break; | 385 break; |
389 default: | 386 default: |
390 break; | 387 break; |
391 } | 388 } |
392 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); | 389 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); |
393 } | 390 } |
394 | 391 |
395 static SkImageFilter* make_serialized_image_filter() { | 392 static SkImageFilter* make_serialized_image_filter() { |
396 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); | 393 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 479 } |
483 | 480 |
484 private: | 481 private: |
485 typedef SkView INHERITED; | 482 typedef SkView INHERITED; |
486 }; | 483 }; |
487 | 484 |
488 ////////////////////////////////////////////////////////////////////////////// | 485 ////////////////////////////////////////////////////////////////////////////// |
489 | 486 |
490 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 487 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
491 static SkViewRegister reg(MyFactory); | 488 static SkViewRegister reg(MyFactory); |
OLD | NEW |