Update SkAlphaThresholdFilter to sk_sp
TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1847053004 Review URL: https://codereview.chromium.org/1847053004
This commit is contained in:
parent
8f1dcaa6f3
commit
f624204300
@ -35,7 +35,7 @@ SkPaint create_filter_paint() {
|
||||
region.setRects(rects, 2);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
|
||||
paint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
|
||||
return paint;
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
#ifndef SkAlphaThresholdFilter_DEFINED
|
||||
#define SkAlphaThresholdFilter_DEFINED
|
||||
|
||||
#include "SkRegion.h"
|
||||
#include "SkImageFilter.h"
|
||||
#include "SkRegion.h"
|
||||
|
||||
class SK_API SkAlphaThresholdFilter {
|
||||
public:
|
||||
@ -20,8 +20,17 @@ public:
|
||||
* The 0,0 point of the region corresponds to the upper left corner of the
|
||||
* source image.
|
||||
*/
|
||||
static sk_sp<SkImageFilter> Make(const SkRegion& region, SkScalar innerMin,
|
||||
SkScalar outerMax, sk_sp<SkImageFilter> input);
|
||||
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkRegion& region, SkScalar innerMin,
|
||||
SkScalar outerMax, SkImageFilter* input = NULL);
|
||||
SkScalar outerMax, SkImageFilter* input = nullptr) {
|
||||
return Make(region, innerMin, outerMax, sk_ref_sp<SkImageFilter>(input)).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
|
||||
};
|
||||
|
||||
|
@ -555,9 +555,10 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
|
||||
|
||||
switch (R(NUM_FILTERS)) {
|
||||
case ALPHA_THRESHOLD:
|
||||
filter = sk_sp<SkImageFilter>(SkAlphaThresholdFilter::Create(make_region(),
|
||||
make_scalar(),
|
||||
make_scalar()));
|
||||
filter = SkAlphaThresholdFilter::Make(make_region(),
|
||||
make_scalar(),
|
||||
make_scalar(),
|
||||
nullptr);
|
||||
break;
|
||||
case MERGE:
|
||||
filter = SkMergeImageFilter::Make(make_image_filter(),
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "SkAlphaThresholdFilter.h"
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkReadBuffer.h"
|
||||
@ -18,7 +19,7 @@
|
||||
class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter {
|
||||
public:
|
||||
SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
|
||||
SkScalar outerThreshold, SkImageFilter* input);
|
||||
SkScalar outerThreshold, sk_sp<SkImageFilter> input);
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterImpl)
|
||||
@ -49,16 +50,17 @@ static SkScalar pin_0_1(SkScalar x) {
|
||||
return SkMinScalar(SkMaxScalar(x, 0), 1);
|
||||
}
|
||||
|
||||
SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
|
||||
SkScalar innerThreshold,
|
||||
SkScalar outerThreshold,
|
||||
SkImageFilter* input) {
|
||||
sk_sp<SkImageFilter> SkAlphaThresholdFilter::Make(const SkRegion& region,
|
||||
SkScalar innerThreshold,
|
||||
SkScalar outerThreshold,
|
||||
sk_sp<SkImageFilter> input) {
|
||||
innerThreshold = pin_0_1(innerThreshold);
|
||||
outerThreshold = pin_0_1(outerThreshold);
|
||||
if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold)) {
|
||||
return nullptr;
|
||||
}
|
||||
return new SkAlphaThresholdFilterImpl(region, innerThreshold, outerThreshold, input);
|
||||
return sk_sp<SkImageFilter>(new SkAlphaThresholdFilterImpl(region, innerThreshold,
|
||||
outerThreshold, std::move(input)));
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
@ -269,14 +271,14 @@ SkFlattenable* SkAlphaThresholdFilterImpl::CreateProc(SkReadBuffer& buffer) {
|
||||
SkScalar outer = buffer.readScalar();
|
||||
SkRegion rgn;
|
||||
buffer.readRegion(&rgn);
|
||||
return SkAlphaThresholdFilter::Create(rgn, inner, outer, common.getInput(0).get());
|
||||
return SkAlphaThresholdFilter::Make(rgn, inner, outer, common.getInput(0)).release();
|
||||
}
|
||||
|
||||
SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region,
|
||||
SkScalar innerThreshold,
|
||||
SkScalar outerThreshold,
|
||||
SkImageFilter* input)
|
||||
: INHERITED(1, &input)
|
||||
sk_sp<SkImageFilter> input)
|
||||
: INHERITED(&input, 1, nullptr)
|
||||
, fRegion(region)
|
||||
, fInnerThreshold(innerThreshold)
|
||||
, fOuterThreshold(outerThreshold) {
|
||||
|
@ -29,8 +29,8 @@ DEF_TEST(FlattenableFactoryToName, r) {
|
||||
rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500);
|
||||
SkRegion region;
|
||||
region.setRects(rects, 2);
|
||||
SkAutoTUnref<SkImageFilter> filter( SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f));
|
||||
test_flattenable(r, filter, "SkAlphaThresholdFilter()");
|
||||
sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
|
||||
test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()");
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocN32Pixels(8, 8);
|
||||
|
Loading…
Reference in New Issue
Block a user