Update docs and samplecode to use new image filter factories

Bug: skia:9280
Change-Id: I03ba9bf1cc952dec77664721fdb3a311f47f7e89
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230884
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
This commit is contained in:
Michael Ludwig 2019-08-01 16:38:24 -04:00 committed by Skia Commit-Bot
parent ef43f68697
commit a861106e49
12 changed files with 29 additions and 37 deletions

View File

@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) {
canvas->drawCircle(31, 21, 8, bluePaint);
SkMatrix matrix;
matrix.setScale(4, 4);
auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr);
auto scaler = SkImageFilters::MatrixTransform(matrix, kNone_SkFilterQuality, nullptr);
SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0);
canvas->saveLayer(saveLayerRec);
canvas->drawCircle(125, 85, 8, redPaint);

View File

@ -13,7 +13,7 @@ void draw(SkCanvas* canvas) {
matrix.setScale(4, 4);
scalePaint.setAlpha(0x40);
scalePaint.setImageFilter(
SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr));
SkImageFilters::MatrixTransform(matrix, kNone_SkFilterQuality, nullptr));
SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint,
SkCanvas::kInitWithPrevious_SaveLayerFlag);
canvas->saveLayer(saveLayerRec);

View File

@ -3,11 +3,11 @@
#include "tools/fiddle/examples.h"
// HASH=42318b18d403e17e07a541652da91ee2
REG_FIDDLE(Canvas_saveLayer, 256, 128, false, 0) {
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkImageFilters.h"
void draw(SkCanvas* canvas) {
SkPaint paint, blur;
blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr));
blur.setImageFilter(SkImageFilters::Blur(3, 3, nullptr));
canvas->saveLayer(nullptr, &blur);
SkRect rect = { 25, 25, 50, 50};
canvas->drawRect(rect, paint);

View File

@ -3,11 +3,11 @@
#include "tools/fiddle/examples.h"
// HASH=a17aec3aa4909527be039e26a7eda694
REG_FIDDLE(Canvas_saveLayer_2, 256, 128, false, 0) {
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkImageFilters.h"
void draw(SkCanvas* canvas) {
SkPaint paint, blur;
blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr));
blur.setImageFilter(SkImageFilters::Blur(3, 3, nullptr));
canvas->saveLayer(SkRect::MakeWH(90, 90), &blur);
SkRect rect = { 25, 25, 50, 50};
canvas->drawRect(rect, paint);

View File

@ -19,7 +19,7 @@ void draw(SkCanvas* canvas) {
SkMatrix matrix;
matrix.setScale(6, 6);
scalePaint.setImageFilter(
SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr));
SkImageFilters::MatrixTransform(matrix, kNone_SkFilterQuality, nullptr));
SkCanvas::SaveLayerRec saveLayerRec(
nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag);
canvas->saveLayer(saveLayerRec);

View File

@ -3,7 +3,7 @@
#include "tools/fiddle/examples.h"
// HASH=ece04ee3d3761e3425f37c8f06f054c1
REG_FIDDLE(Image_Filter_Methods, 256, 256, false, 0) {
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkImageFilters.h"
void draw(SkCanvas* canvas) {
SkPaint paint;
@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) {
SkRegion region;
region.op( 10, 10, 50, 50, SkRegion::kUnion_Op);
region.op( 10, 50, 90, 90, SkRegion::kUnion_Op);
paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr));
paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr));
canvas->drawRegion(region, paint);
paint.setImageFilter(nullptr);
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5));

View File

@ -4,11 +4,9 @@
// HASH=85a76163138a2720ac003691d6363938
REG_FIDDLE(Image_makeWithFilter, 256, 256, false, 5) {
void draw(SkCanvas* canvas) {
sk_sp<SkImageFilter> shadowFilter = SkDropShadowImageFilter::Make(
-10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
nullptr);
sk_sp<SkImageFilter> offsetFilter = SkOffsetImageFilter::Make(40, 40, shadowFilter, nullptr);
sk_sp<SkImageFilter> shadowFilter = SkImageFilters::DropShadow(
-10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, nullptr);
sk_sp<SkImageFilter> offsetFilter = SkImageFilters::Offset(40, 40, shadowFilter, nullptr);
SkIRect subset = image->bounds();
SkIRect clipBounds = image->bounds();
clipBounds.outset(60, 60);

View File

@ -13,8 +13,8 @@ void draw(SkCanvas* canvas) {
matrix.setRotate(90);
SkVector offset = { 7, 7 };
for (int i = 0; i < 4; ++i) {
paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3,
SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
paint.setImageFilter(SkImageFilters::DropShadow(offset.fX, offset.fY, 3, 3,
SK_ColorBLUE, nullptr));
matrix.mapVector(offset.fX, offset.fY, &offset);
canvas->translate(0, 60);
canvas->drawString("Text", 50, 0, paint);

View File

@ -13,8 +13,8 @@ void draw(SkCanvas* canvas) {
matrix.setRotate(90);
SkVector offset = { 7, 7 };
for (int i = 0; i < 4; ++i) {
paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3,
SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
paint.setImageFilter(SkImageFilters::DropShadow(offset.fX, offset.fY, 3, 3,
SK_ColorBLUE, nullptr));
offset = matrix.mapVector(offset.fX, offset.fY);
canvas->translate(0, 60);
canvas->drawString("Text", 50, 0, paint);

View File

@ -3,12 +3,12 @@
#include "tools/fiddle/examples.h"
// HASH=c11f8eaa1dd149bc18db21e23ce26904
REG_FIDDLE(Paint_getImageFilter, 256, 256, true, 0) {
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkImageFilters.h"
void draw(SkCanvas* canvas) {
SkPaint paint;
SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '=');
paint.setImageFilter(SkBlurImageFilter::Make(kOuter_SkBlurStyle, 3, nullptr, nullptr));
paint.setImageFilter(SkImageFilters::Blur(3, 3, nullptr, nullptr));
SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '=');
}
} // END FIDDLE

View File

@ -9,6 +9,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
@ -18,13 +19,9 @@
#include "include/core/SkRect.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkColorFilterImageFilter.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkDropShadowImageFilter.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkMergeImageFilter.h"
#include "include/effects/SkOffsetImageFilter.h"
#include "include/effects/SkImageFilters.h"
#include "src/core/SkImageFilterPriv.h"
#include "src/core/SkSpecialImage.h"
@ -497,17 +494,16 @@ public:
// /--- Color Filter <---- Blur <--- Offset
// Merge <
// \--- Blur <--- Drop Shadow
sk_sp<SkImageFilter> drop2 = SkDropShadowImageFilter::Make(
10.f, 5.f, 3.f, 3.f, SK_ColorBLACK,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr);
sk_sp<SkImageFilter> blur1 = SkBlurImageFilter::Make(2.f, 2.f, std::move(drop2));
sk_sp<SkImageFilter> drop2 = SkImageFilters::DropShadow(
10.f, 5.f, 3.f, 3.f, SK_ColorBLACK, nullptr);
sk_sp<SkImageFilter> blur1 = SkImageFilters::Blur(2.f, 2.f, std::move(drop2));
sk_sp<SkImageFilter> offset3 = SkOffsetImageFilter::Make(-5.f, -5.f, nullptr);
sk_sp<SkImageFilter> blur2 = SkBlurImageFilter::Make(4.f, 4.f, std::move(offset3));
sk_sp<SkImageFilter> cf1 = SkColorFilterImageFilter::Make(
sk_sp<SkImageFilter> offset3 = SkImageFilters::Offset(-5.f, -5.f, nullptr);
sk_sp<SkImageFilter> blur2 = SkImageFilters::Blur(4.f, 4.f, std::move(offset3));
sk_sp<SkImageFilter> cf1 = SkImageFilters::ColorFilter(
SkColorFilters::Blend(SK_ColorGRAY, SkBlendMode::kModulate), std::move(blur2));
sk_sp<SkImageFilter> merge0 = SkMergeImageFilter::Make(std::move(blur1), std::move(cf1));
sk_sp<SkImageFilter> merge0 = SkImageFilters::Merge(std::move(blur1), std::move(cf1));
draw_dag(canvas, std::move(merge0), kFilterRect, kFilterSurfaceSize);
}

View File

@ -174,9 +174,7 @@ DEF_SAMPLE( return new LayersView; )
//////////////////////////////////////////////////////////////////////////////
#include "include/effects/SkBlurImageFilter.h"
#include "include/effects/SkMatrixConvolutionImageFilter.h"
#include "include/effects/SkMorphologyImageFilter.h"
#include "include/effects/SkImageFilters.h"
#include "tools/Resources.h"
@ -190,7 +188,7 @@ public:
fCenter.set(200, 150);
fAngle = 0;
fImage = GetResourceAsImage("images/mandrill_512.png");
fFilter = SkDilateImageFilter::Make(8, 8, nullptr);
fFilter = SkImageFilters::Dilate(8, 8, nullptr);
}
protected: