move blur impl into core
Ever since we added drawShadow to the public api, blurs have necessarily part of the core. This CL just formalizes that. This should also allow us to have builds that exclude all of /effects (for code size) and still be valid. Will follow-up with a change to deprecate SkBlurMaskFilter and SkBlurQuality (both no longer needed). Bug: skia: Change-Id: Ifbbd8b47a30a0386d215726b67bcf1e8b84fb8f5 Reviewed-on: https://skia-review.googlesource.com/113713 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
05cb229e58
commit
18e7556371
@ -58,6 +58,7 @@ skia_core_sources = [
|
||||
"$_src/core/SkBlurImageFilter.cpp",
|
||||
"$_src/core/SkBlurMask.cpp",
|
||||
"$_src/core/SkBlurMask.h",
|
||||
"$_src/core/SkBlurMF.cpp",
|
||||
"$_src/core/SkBuffer.cpp",
|
||||
"$_src/core/SkCachedData.cpp",
|
||||
"$_src/core/SkCanvas.cpp",
|
||||
|
@ -10,8 +10,6 @@ _include = get_path_info("../include", "abspath")
|
||||
skia_effects_sources = [
|
||||
"$_src/c/sk_effects.cpp",
|
||||
|
||||
"$_src/effects/GrCircleBlurFragmentProcessor.cpp",
|
||||
"$_src/effects/GrCircleBlurFragmentProcessor.h",
|
||||
"$_src/effects/GrAlphaThresholdFragmentProcessor.cpp",
|
||||
"$_src/effects/GrAlphaThresholdFragmentProcessor.h",
|
||||
|
||||
|
@ -328,6 +328,8 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/effects/GrArithmeticFP.h",
|
||||
"$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.cpp",
|
||||
"$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.h",
|
||||
"$_src/gpu/effects/GrCircleBlurFragmentProcessor.cpp",
|
||||
"$_src/gpu/effects/GrCircleBlurFragmentProcessor.h",
|
||||
"$_src/gpu/effects/GrCircleEffect.cpp",
|
||||
"$_src/gpu/effects/GrCircleEffect.h",
|
||||
"$_src/gpu/effects/GrConfigConversionEffect.cpp",
|
||||
|
@ -27,10 +27,10 @@ skia_sksl_sources = [
|
||||
|
||||
skia_gpu_processor_sources = [
|
||||
"$_src/effects/GrAlphaThresholdFragmentProcessor.fp",
|
||||
"$_src/effects/GrCircleBlurFragmentProcessor.fp",
|
||||
"$_src/gpu/effects/GrAARectEffect.fp",
|
||||
"$_src/gpu/effects/GrArithmeticFP.fp",
|
||||
"$_src/gpu/effects/GrBlurredEdgeFragmentProcessor.fp",
|
||||
"$_src/gpu/effects/GrCircleBlurFragmentProcessor.fp",
|
||||
"$_src/gpu/effects/GrCircleEffect.fp",
|
||||
"$_src/gpu/effects/GrConfigConversionEffect.fp",
|
||||
"$_src/gpu/effects/GrConstColorProcessor.fp",
|
||||
|
@ -19,6 +19,7 @@ enum SkBlurStyle {
|
||||
kLastEnum_SkBlurStyle = kInner_SkBlurStyle
|
||||
};
|
||||
|
||||
// DEPRECATED
|
||||
enum SkBlurQuality {
|
||||
kLow_SkBlurQuality, //!< e.g. box filter
|
||||
kHigh_SkBlurQuality, //!< e.g. 3-pass similar to gaussian
|
||||
|
@ -8,10 +8,13 @@
|
||||
#ifndef SkMaskFilter_DEFINED
|
||||
#define SkMaskFilter_DEFINED
|
||||
|
||||
#include "SkBlurTypes.h"
|
||||
#include "SkCoverageMode.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
class SkMatrix;
|
||||
struct SkRect;
|
||||
class SkString;
|
||||
|
||||
/** \class SkMaskFilter
|
||||
@ -21,6 +24,20 @@ class SkString;
|
||||
*/
|
||||
class SK_API SkMaskFilter : public SkFlattenable {
|
||||
public:
|
||||
/** Create a blur maskfilter.
|
||||
* @param style The SkBlurStyle to use
|
||||
* @param sigma Standard deviation of the Gaussian blur to apply. Must be > 0.
|
||||
* @param occluder The rect for which no pixels need be drawn (b.c. it will be overdrawn
|
||||
* with some opaque object. This is just a hint which backends are free to
|
||||
* ignore.
|
||||
* @param respectCTM if true the blur's sigma is modified by the CTM.
|
||||
* @return The new blur maskfilter
|
||||
*/
|
||||
static sk_sp<SkMaskFilter> MakeBlur(SkBlurStyle style, SkScalar sigma, const SkRect& occluder,
|
||||
bool respectCTM = true);
|
||||
static sk_sp<SkMaskFilter> MakeBlur(SkBlurStyle style, SkScalar sigma,
|
||||
bool respectCTM = true);
|
||||
|
||||
/**
|
||||
* Construct a maskfilter whose effect is to first apply the inner filter and then apply
|
||||
* the outer filter to the result of the inner's. Returns nullptr on failure.
|
||||
|
@ -58,8 +58,6 @@ public:
|
||||
SkScalar ambient, SkScalar specular);
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||
|
||||
private:
|
||||
SkBlurMaskFilter(); // can't be instantiated
|
||||
};
|
||||
|
@ -144,8 +144,8 @@ sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "../../include/effects/SkBlurMaskFilter.h"
|
||||
#include "sk_maskfilter.h"
|
||||
#include "SkMaskFilter.h"
|
||||
|
||||
const struct {
|
||||
sk_blurstyle_t fC;
|
||||
@ -182,5 +182,5 @@ sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t cstyle, float sigma) {
|
||||
if (!find_blurstyle(cstyle, &style)) {
|
||||
return nullptr;
|
||||
}
|
||||
return ToMaskFilter(SkBlurMaskFilter::Make(style, sigma).release());
|
||||
return ToMaskFilter(SkMaskFilter::MakeBlur(style, sigma).release());
|
||||
}
|
||||
|
1029
src/core/SkBlurMF.cpp
Normal file
1029
src/core/SkBlurMF.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -33,5 +33,6 @@ bool SkComputeBlurredRRectParams(const SkRRect& srcRRect, const SkRRect& devRRec
|
||||
SkScalar texYs[kSkBlurRRectMaxDivisions],
|
||||
int* numXs, int* numYs, uint32_t* skipMask);
|
||||
|
||||
extern void sk_register_blur_maskfilter_createproc();
|
||||
|
||||
#endif
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "SkAutoMalloc.h"
|
||||
#include "SkBlitter.h"
|
||||
#include "SkBlurPriv.h"
|
||||
#include "SkCachedData.h"
|
||||
#include "SkCoverageModePriv.h"
|
||||
#include "SkDraw.h"
|
||||
@ -752,5 +753,6 @@ void SkMaskFilter::InitializeFlattenables() {
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLocalMatrixMF)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposeMF)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkCombineMF)
|
||||
sk_register_blur_maskfilter_createproc();
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@
|
||||
*/
|
||||
#include "SkArenaAlloc.h"
|
||||
#include "SkBlurDrawLooper.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorSpaceXformer.h"
|
||||
#include "SkColor.h"
|
||||
@ -404,7 +404,7 @@ sk_sp<SkDrawLooper> SkBlurDrawLooper::Make(SkColor color, SkScalar sigma, SkScal
|
||||
{
|
||||
sk_sp<SkMaskFilter> blur = nullptr;
|
||||
if (sigma > 0.0f) {
|
||||
blur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, sigma, SkBlurMaskFilter::kNone_BlurFlag);
|
||||
blur = SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, true);
|
||||
}
|
||||
|
||||
SkLayerDrawLooper::Builder builder;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "Sk2DPathEffect.h"
|
||||
#include "SkAlphaThresholdFilter.h"
|
||||
#include "SkBlurImageFilter.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkColorFilterImageFilter.h"
|
||||
#include "SkColorMatrixFilterRowMajor255.h"
|
||||
#include "SkComposeImageFilter.h"
|
||||
@ -64,7 +63,6 @@ void SkFlattenable::PrivateInitializer::InitEffects() {
|
||||
// MaskFilter
|
||||
SkMaskFilter::InitializeFlattenables();
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkEmbossMaskFilter)
|
||||
SkBlurMaskFilter::InitializeFlattenables();
|
||||
SkRRectsGaussianEdgeMaskFilter::InitializeFlattenables();
|
||||
SkShaderMaskFilter::InitializeFlattenables();
|
||||
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
#include "SkShadowUtils.h"
|
||||
#include "SkBlurMask.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkColorData.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkDrawShadowInfo.h"
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPM4f.h"
|
||||
#include "SkRandom.h"
|
||||
@ -642,8 +642,8 @@ void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) {
|
||||
paint.setStrokeWidth(strokeWidth);
|
||||
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
||||
SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
|
||||
uint32_t flags = SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
|
||||
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, sigma, flags));
|
||||
bool respectCTM = false;
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
|
||||
this->drawPath(devSpacePath, paint);
|
||||
}
|
||||
}
|
||||
@ -727,8 +727,8 @@ void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) {
|
||||
SkPaint paint;
|
||||
paint.setColor(rec.fSpotColor);
|
||||
SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(radius);
|
||||
uint32_t flags = SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
|
||||
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, sigma, flags));
|
||||
bool respectCTM = false;
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM));
|
||||
this->drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "SkBlendMode.h"
|
||||
#include "SkBlurDrawLooper.h"
|
||||
#include "SkBlurMask.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkBlurPriv.h"
|
||||
#include "SkBlurTypes.h"
|
||||
#include "SkCanvas.h"
|
||||
@ -133,9 +132,8 @@ DEF_TEST(BlurDrawing, reporter) {
|
||||
for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) {
|
||||
SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style);
|
||||
|
||||
const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag;
|
||||
for (uint32_t flags = 0; flags < flagPermutations; ++flags) {
|
||||
paint.setMaskFilter(SkBlurMaskFilter::Make(blurStyle, sigma, flags));
|
||||
for (bool respectCTM : { false, true }) {
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(blurStyle, sigma, respectCTM));
|
||||
|
||||
for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) {
|
||||
SkPath path;
|
||||
@ -254,8 +252,7 @@ static void blur_path(SkCanvas* canvas, const SkPath& path,
|
||||
|
||||
SkPaint blurPaint;
|
||||
blurPaint.setColor(SK_ColorWHITE);
|
||||
blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, gaussianSigma,
|
||||
SkBlurMaskFilter::kHighQuality_BlurFlag));
|
||||
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, gaussianSigma));
|
||||
|
||||
canvas->drawColor(SK_ColorBLACK);
|
||||
canvas->drawPath(path, blurPaint);
|
||||
@ -363,13 +360,7 @@ DEF_TEST(BlurSigmaRange, reporter) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkBlurQuality blurMaskFilterFlags_as_quality(uint32_t blurMaskFilterFlags) {
|
||||
return (blurMaskFilterFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ?
|
||||
kHigh_SkBlurQuality : kLow_SkBlurQuality;
|
||||
}
|
||||
|
||||
static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
|
||||
SkBlurStyle style, uint32_t blurMaskFilterFlags) {
|
||||
static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma, SkBlurStyle style) {
|
||||
if (kNormal_SkBlurStyle != style) {
|
||||
return; // blurdrawlooper only supports normal
|
||||
}
|
||||
@ -392,13 +383,13 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
|
||||
REPORTER_ASSERT(reporter, rec.fOffset.y() == dy);
|
||||
REPORTER_ASSERT(reporter, rec.fColor == color);
|
||||
REPORTER_ASSERT(reporter, rec.fStyle == style);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == kLow_SkBlurQuality);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == kHigh_SkBlurQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_looper(skiatest::Reporter* reporter, sk_sp<SkDrawLooper> lp, SkScalar sigma,
|
||||
SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) {
|
||||
SkBlurStyle style, bool expectSuccess) {
|
||||
SkDrawLooper::BlurShadowRec rec;
|
||||
bool success = lp->asABlurShadow(&rec);
|
||||
REPORTER_ASSERT(reporter, success == expectSuccess);
|
||||
@ -408,7 +399,7 @@ static void test_looper(skiatest::Reporter* reporter, sk_sp<SkDrawLooper> lp, Sk
|
||||
if (success) {
|
||||
REPORTER_ASSERT(reporter, rec.fSigma == sigma);
|
||||
REPORTER_ASSERT(reporter, rec.fStyle == style);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == quality);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == kHigh_SkBlurQuality);
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,31 +421,30 @@ static void make_blur_layer(SkLayerDrawLooper::Builder* builder, sk_sp<SkMaskFil
|
||||
}
|
||||
|
||||
static void test_layerDrawLooper(skiatest::Reporter* reporter, sk_sp<SkMaskFilter> mf,
|
||||
SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
|
||||
bool expectSuccess) {
|
||||
SkScalar sigma, SkBlurStyle style, bool expectSuccess) {
|
||||
|
||||
SkLayerDrawLooper::LayerInfo info;
|
||||
SkLayerDrawLooper::Builder builder;
|
||||
|
||||
// 1 layer is too few
|
||||
make_noop_layer(&builder);
|
||||
test_looper(reporter, builder.detach(), sigma, style, quality, false);
|
||||
test_looper(reporter, builder.detach(), sigma, style, false);
|
||||
|
||||
// 2 layers is good, but need blur
|
||||
make_noop_layer(&builder);
|
||||
make_noop_layer(&builder);
|
||||
test_looper(reporter, builder.detach(), sigma, style, quality, false);
|
||||
test_looper(reporter, builder.detach(), sigma, style, false);
|
||||
|
||||
// 2 layers is just right
|
||||
make_noop_layer(&builder);
|
||||
make_blur_layer(&builder, mf);
|
||||
test_looper(reporter, builder.detach(), sigma, style, quality, expectSuccess);
|
||||
test_looper(reporter, builder.detach(), sigma, style, expectSuccess);
|
||||
|
||||
// 3 layers is too many
|
||||
make_noop_layer(&builder);
|
||||
make_blur_layer(&builder, mf);
|
||||
make_noop_layer(&builder);
|
||||
test_looper(reporter, builder.detach(), sigma, style, quality, false);
|
||||
test_looper(reporter, builder.detach(), sigma, style, false);
|
||||
}
|
||||
|
||||
DEF_TEST(BlurAsABlur, reporter) {
|
||||
@ -472,27 +462,25 @@ DEF_TEST(BlurAsABlur, reporter) {
|
||||
const SkBlurStyle style = styles[i];
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) {
|
||||
const SkScalar sigma = sigmas[j];
|
||||
for (int flags = 0; flags <= SkBlurMaskFilter::kAll_BlurFlag; ++flags) {
|
||||
const SkBlurQuality quality = blurMaskFilterFlags_as_quality(flags);
|
||||
|
||||
sk_sp<SkMaskFilter> mf(SkBlurMaskFilter::Make(style, sigma, flags));
|
||||
for (bool respectCTM : { false, true }) {
|
||||
sk_sp<SkMaskFilter> mf(SkMaskFilter::MakeBlur(style, sigma, respectCTM));
|
||||
if (nullptr == mf.get()) {
|
||||
REPORTER_ASSERT(reporter, sigma <= 0);
|
||||
} else {
|
||||
REPORTER_ASSERT(reporter, sigma > 0);
|
||||
SkMaskFilterBase::BlurRec rec;
|
||||
bool success = as_MFB(mf)->asABlur(&rec);
|
||||
if (flags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) {
|
||||
REPORTER_ASSERT(reporter, !success);
|
||||
} else {
|
||||
if (respectCTM) {
|
||||
REPORTER_ASSERT(reporter, success);
|
||||
REPORTER_ASSERT(reporter, rec.fSigma == sigma);
|
||||
REPORTER_ASSERT(reporter, rec.fStyle == style);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == quality);
|
||||
REPORTER_ASSERT(reporter, rec.fQuality == kHigh_SkBlurQuality);
|
||||
} else {
|
||||
REPORTER_ASSERT(reporter, !success);
|
||||
}
|
||||
test_layerDrawLooper(reporter, std::move(mf), sigma, style, quality, success);
|
||||
test_layerDrawLooper(reporter, std::move(mf), sigma, style, success);
|
||||
}
|
||||
test_blurDrawLooper(reporter, sigma, style, flags);
|
||||
test_blurDrawLooper(reporter, sigma, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -529,7 +517,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctxInfo) {
|
||||
SkRRect rr = SkRRect::MakeRectXY(r, 10, 10);
|
||||
|
||||
SkPaint p;
|
||||
p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 0.01f));
|
||||
p.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 0.01f));
|
||||
|
||||
canvas->drawRRect(rr, p);
|
||||
}
|
||||
@ -706,7 +694,7 @@ DEF_TEST(BlurZeroSigma, reporter) {
|
||||
// if sigma is zero (or nearly so), we need to draw correctly (unblurred) and not crash
|
||||
// or assert.
|
||||
for (auto sigma : sigmas) {
|
||||
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, sigma));
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
|
||||
surf->getCanvas()->drawRect(r, paint);
|
||||
|
||||
sk_tool_utils::PixelIter iter(surf.get());
|
||||
|
Loading…
Reference in New Issue
Block a user