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

Unified Diff: samplecode/SampleFilterFuzz.cpp

Issue 1556553002: Implement an SkPaint-based image filter (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Add more randomness Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkPaintImageFilter.h ('k') | src/effects/SkPaintImageFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleFilterFuzz.cpp
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index a0f7aff5ef3ac339d055be7f99d35aef8ed9412a..a9e5a96702f3baacc85dbb90ef1050fbd8ea54e0 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -6,31 +6,36 @@
*/
#include "SampleCode.h"
#include "SkAlphaThresholdFilter.h"
+#include "SkAnnotation.h"
#include "SkBlurImageFilter.h"
+#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkColorCubeFilter.h"
#include "SkColorFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkComposeImageFilter.h"
+#include "SkCornerPathEffect.h"
#include "SkData.h"
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
#include "SkImageSource.h"
+#include "SkLayerRasterizer.h"
#include "SkLightingImageFilter.h"
#include "SkMagnifierImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
#include "SkMergeImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOffsetImageFilter.h"
+#include "SkPaintImageFilter.h"
#include "SkPerlinNoiseShader.h"
#include "SkPictureImageFilter.h"
#include "SkPictureRecorder.h"
#include "SkPoint3.h"
#include "SkRandom.h"
-#include "SkRectShaderImageFilter.h"
#include "SkTestImageFilters.h"
#include "SkTileImageFilter.h"
+#include "SkTypeface.h"
#include "SkView.h"
#include "SkXfermodeImageFilter.h"
#include <stdio.h>
@@ -94,6 +99,35 @@ static SkScalar make_scalar(bool positiveOnly = false) {
return make_number(positiveOnly);
}
+static SkString make_string() {
+ int length = R(1000);
+ SkString str(length);
+ for (int i = 0; i < length; ++i) {
+ str[i] = static_cast<char>(R(256));
+ }
+ return str;
+}
+
+static const char* make_font_name() {
+ int sel = R(8);
+
+ switch(sel) {
+ case 0: return "Courier New";
+ case 1: return "Helvetica";
+ case 3: return "monospace";
+ case 4: return "sans-serif";
+ case 5: return "serif";
+ case 6: return "Times";
+ case 7:
+ default:
+ return "Times New Roman";
sugoi1 2016/01/07 16:06:20 Nit: Maybe add an option to get a garbage string.
ajuma 2016/01/08 17:44:28 Done.
+ }
+}
+
+static bool make_bool() {
+ return R(2) == 1;
+}
+
static SkRect make_rect() {
return SkRect::MakeWH(SkIntToScalar(R(static_cast<float>(kBitmapSize))),
SkIntToScalar(R(static_cast<float>(kBitmapSize))));
@@ -119,6 +153,46 @@ static SkXfermode::Mode make_xfermode() {
return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1));
}
+static SkPaint::Align make_paint_align() {
+ return static_cast<SkPaint::Align>(R(SkPaint::kRight_Align+1));
+}
+
+static SkPaint::Hinting make_paint_hinting() {
+ return static_cast<SkPaint::Hinting>(R(SkPaint::kFull_Hinting+1));
+}
+
+static SkPaint::Style make_paint_style() {
+ return static_cast<SkPaint::Style>(R(SkPaint::kStrokeAndFill_Style+1));
+}
+
+static SkPaint::Cap make_paint_cap() {
+ return static_cast<SkPaint::Cap>(R(SkPaint::kDefault_Cap+1));
+}
+
+static SkPaint::Join make_paint_join() {
+ return static_cast<SkPaint::Join>(R(SkPaint::kDefault_Join+1));
+}
+
+static SkPaint::TextEncoding make_paint_text_encoding() {
+ return static_cast<SkPaint::TextEncoding>(R(SkPaint::kGlyphID_TextEncoding+1));
+}
+
+static SkBlurStyle make_blur_style() {
+ return static_cast<SkBlurStyle>(R(kLastEnum_SkBlurStyle+1));
+}
+
+static SkBlurMaskFilter::BlurFlags make_blur_mask_filter_flag() {
+ return static_cast<SkBlurMaskFilter::BlurFlags>(R(SkBlurMaskFilter::kAll_BlurFlag+1));
+}
+
+static SkFilterQuality make_filter_quality() {
+ return static_cast<SkFilterQuality>(R(kHigh_SkFilterQuality+1));
+}
+
+static SkTypeface::Style make_typeface_style() {
+ return static_cast<SkTypeface::Style>(R(SkTypeface::kBoldItalic+1));
+}
+
static SkColor make_color() {
return (R(2) == 1) ? 0xFFC0F0A0 : 0xFF000090;
}
@@ -266,7 +340,7 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
- MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS };
+ MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS };
switch (R(NUM_FILTERS)) {
case ALPHA_THRESHOLD:
@@ -372,9 +446,11 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
SkPerlinNoiseShader::CreateTurbulence(
make_scalar(true), make_scalar(true), R(10.0f), make_scalar()));
+ SkPaint paint;
+ paint.setShader(shader);
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
SkIntToScalar(kBitmapSize)));
- filter = SkRectShaderImageFilter::Create(shader, &cropR);
+ filter = SkPaintImageFilter::Create(paint, &cropR);
}
break;
case DROP_SHADOW:
@@ -421,6 +497,61 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
filter = SkPictureImageFilter::Create(pict.get(), make_rect());
}
break;
+ case PAINT:
+ {
+ SkPaint paint;
+ paint.setHinting(make_paint_hinting());
+ paint.setAntiAlias(make_bool());
+ paint.setDither(make_bool());
+ paint.setLinearText(make_bool());
+ paint.setSubpixelText(make_bool());
+ paint.setLCDRenderText(make_bool());
+ paint.setEmbeddedBitmapText(make_bool());
+ paint.setAutohinted(make_bool());
+ paint.setVerticalText(make_bool());
+ paint.setUnderlineText(make_bool());
+ paint.setStrikeThruText(make_bool());
+ paint.setFakeBoldText(make_bool());
+ paint.setDevKernText(make_bool());
+ paint.setFilterQuality(make_filter_quality());
+ paint.setStyle(make_paint_style());
+ paint.setColor(make_color());
+ paint.setStrokeWidth(make_scalar());
+ paint.setStrokeMiter(make_scalar());
+ paint.setStrokeCap(make_paint_cap());
+ paint.setStrokeJoin(make_paint_join());
+ SkAutoTUnref<SkColorFilter> colorFilter(
+ SkColorFilter::CreateLightingFilter(make_color(), make_color()));
Stephen White 2016/01/07 16:17:33 Not new to this CL, but when it comes to SkColorFi
ajuma 2016/01/08 17:44:28 Done.
+ paint.setColorFilter(colorFilter);
+ paint.setXfermodeMode(make_xfermode());
+ SkAutoTUnref<SkPathEffect> pathEffect(SkCornerPathEffect::Create(make_scalar()));
Stephen White 2016/01/07 16:17:33 We should be exercising all the serializable path
ajuma 2016/01/08 17:44:28 Done.
+ paint.setPathEffect(pathEffect);
+ SkAutoTUnref<SkMaskFilter> maskFilter(
+ SkBlurMaskFilter::Create(make_blur_style(),
Stephen White 2016/01/07 16:17:33 Also SkEmbossMaskFilter.
ajuma 2016/01/08 17:44:28 Done.
+ make_scalar(),
+ make_blur_mask_filter_flag()));
+ paint.setMaskFilter(maskFilter);
+ SkAutoTUnref<SkTypeface> typeface(
+ SkTypeface::CreateFromName(make_font_name(), make_typeface_style()));
+ paint.setTypeface(typeface);
+ SkLayerRasterizer::Builder rasterizerBuilder;
+ SkPaint paintForRasterizer;
+ rasterizerBuilder.addLayer(paintForRasterizer);
+ SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer());
+ paint.setRasterizer(rasterizer);
+ paint.setImageFilter(make_image_filter());
+ SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
+ SkAutoTUnref<SkAnnotation> annotation(
+ SkAnnotation::Create(make_string().c_str(), data));
+ paint.setAnnotation(annotation);
+ paint.setTextAlign(make_paint_align());
+ paint.setTextSize(make_scalar());
+ paint.setTextScaleX(make_scalar());
+ paint.setTextSkewX(make_scalar());
+ paint.setTextEncoding(make_paint_text_encoding());
+ SkImageFilter::CropRect cropR(make_rect());
+ filter = SkPaintImageFilter::Create(paint, &cropR);
+ }
default:
break;
}
« no previous file with comments | « include/effects/SkPaintImageFilter.h ('k') | src/effects/SkPaintImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698