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

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 a test case to SampleFilterFuzz Created 4 years, 12 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..74fc68190bef954a48ebd2f99a129bcd0fe8bf5d 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -6,33 +6,39 @@
*/
#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 "sk_tool_utils.h"
#include <stdio.h>
#include <time.h>
@@ -266,7 +272,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 +378,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 +429,64 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
filter = SkPictureImageFilter::Create(pict.get(), make_rect());
}
break;
+ case PAINT:
+ {
+ SkPaint paint;
+ paint.setHinting(SkPaint::kSlight_Hinting);
+ paint.setAntiAlias(true);
+ paint.setDither(true);
+ paint.setLinearText(true);
+ paint.setSubpixelText(false);
+ paint.setLCDRenderText(false);
+ paint.setEmbeddedBitmapText(true);
+ paint.setAutohinted(false);
+ paint.setVerticalText(true);
+ paint.setUnderlineText(false);
+ paint.setStrikeThruText(true);
+ paint.setFakeBoldText(true);
+ paint.setDevKernText(false);
+ paint.setFilterQuality(kLow_SkFilterQuality);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setColor(SK_ColorRED);
+ paint.setStrokeWidth(SkIntToScalar(3));
+ paint.setStrokeMiter(SkIntToScalar(1));
+ paint.setStrokeCap(SkPaint::kRound_Cap);
+ paint.setStrokeJoin(SkPaint::kBevel_Join);
+ SkAutoTUnref<SkColorFilter> colorFilter(
+ SkColorFilter::CreateLightingFilter(make_color(), make_color()));
+ paint.setColorFilter(colorFilter);
+ paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
+ SkAutoTUnref<SkPathEffect> pathEffect(SkCornerPathEffect::Create(SkIntToScalar(3)));
+ paint.setPathEffect(pathEffect);
+ SkAutoTUnref<SkMaskFilter> maskFilter(
+ SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
+ SkIntToScalar(25),
+ SkBlurMaskFilter::kHighQuality_BlurFlag));
+ paint.setMaskFilter(maskFilter);
+ SkAutoTUnref<SkTypeface> typeface(
+ sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold));
+ paint.setTypeface(typeface);
+ SkLayerRasterizer::Builder rasterizerBuilder;
+ SkPaint paintForRasterizer;
+ rasterizerBuilder.addLayer(paintForRasterizer);
+ SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer());
+ paint.setRasterizer(rasterizer);
+ SkAutoTUnref<SkImageFilter> imageFilter(
+ SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2)));
+ paint.setImageFilter(imageFilter);
+ SkAutoDataUnref data(SkData::NewWithCString("This is an annotation."));
+ SkAutoTUnref<SkAnnotation> annotation(
+ SkAnnotation::Create(SkAnnotationKeys::Define_Named_Dest_Key(), data));
+ paint.setAnnotation(annotation);
+ paint.setTextAlign(SkPaint::kCenter_Align);
+ paint.setTextSize(SkIntToScalar(8));
+ paint.setTextScaleX(SkFloatToScalar(0.75));
+ paint.setTextSkewX(SkFloatToScalar(-0.25));
+ paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
+ SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
+ SkIntToScalar(kBitmapSize)));
ajuma 2016/01/04 22:39:46 Is it worthwhile also adding test cases that use s
sugoi1 2016/01/05 15:59:55 You could choose to use each of these functions ra
ajuma 2016/01/06 20:53:39 Thanks for the tips! (And also thanks for all the
+ 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