Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 311443003: Allow SkPictureImageFilter to be serialized when not run cross-process. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkPicture* pict = NULL;
380 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION
381 pict = new SkPicture; 379 pict = new SkPicture;
382 SkAutoUnref aur(pict); 380 SkAutoUnref aur(pict);
383 drawSomething(pict->beginRecording(kBitmapSize, kBitmapSize)); 381
384 pict->endRecording(); 382 SkRTreeFactory factory;
385 #endif 383 SkPictureRecorder recorder;
384 SkCanvas* recordingCanvas = recorder.beginRecording(kBitmapSize, kBitmap Size, &factory, 0);
385 drawSomething(recordingCanvas);
386 recorder.endRecording();
sugoi 2014/05/30 20:24:45 missing "pict = " ?
386 filter = SkPictureImageFilter::Create(pict, make_rect()); 387 filter = SkPictureImageFilter::Create(pict, make_rect());
387 } 388 }
388 break; 389 break;
389 default: 390 default:
390 break; 391 break;
391 } 392 }
392 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); 393 return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
393 } 394 }
394 395
395 static SkImageFilter* make_serialized_image_filter() { 396 static SkImageFilter* make_serialized_image_filter() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 483 }
483 484
484 private: 485 private:
485 typedef SkView INHERITED; 486 typedef SkView INHERITED;
486 }; 487 };
487 488
488 ////////////////////////////////////////////////////////////////////////////// 489 //////////////////////////////////////////////////////////////////////////////
489 490
490 static SkView* MyFactory() { return new ImageFilterFuzzView; } 491 static SkView* MyFactory() { return new ImageFilterFuzzView; }
491 static SkViewRegister reg(MyFactory); 492 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkPictureImageFilter.cpp » ('j') | src/effects/SkPictureImageFilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698