hide setImageFilter(ptr)

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4184

Change-Id: Iad792cfdf54087ad4c424fd268559c162a9a5f5c
Reviewed-on: https://skia-review.googlesource.com/4184
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2016-11-01 11:22:05 -04:00 committed by Skia Commit-Bot
parent c633abbb34
commit 5e25717ab6
16 changed files with 38 additions and 33 deletions

View File

@ -732,7 +732,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
}
static SkImageFilter* make_serialized_image_filter() {
static sk_sp<SkImageFilter> make_serialized_image_filter() {
sk_sp<SkImageFilter> filter(make_image_filter(false));
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
@ -759,9 +759,7 @@ static SkImageFilter* make_serialized_image_filter() {
}
}
#endif // SK_ADD_RANDOM_BIT_FLIPS
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
SkImageFilter::GetFlattenableType());
return static_cast<SkImageFilter*>(flattenable);
return SkValidatingDeserializeImageFilter(ptr, len);
}
static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
@ -774,10 +772,9 @@ static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai
DEF_FUZZ(SerializedImageFilter, f) {
fuzz = f;
SkImageFilter* filter = make_serialized_image_filter();
SkPaint paint;
SkSafeUnref(paint.setImageFilter(filter));
paint.setImageFilter(make_serialized_image_filter());
SkBitmap bitmap;
SkCanvas canvas(bitmap);
drawClippedBitmap(&canvas, 0, 0, paint);

View File

@ -16,4 +16,5 @@ android_framework_defines = [
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_COLOR_SPACE_FACTORIES",
"SK_SUPPORT_LEGACY_SHADER_ASALOCALMATRIXSHADER",
"SK_SUPPORT_LEGACY_SETIMAGEFILTER_PTR",
]

View File

@ -11,9 +11,12 @@
#include "SkFlattenable.h"
class SkData;
class SkImageFilter;
SK_API SkData* SkValidatingSerializeFlattenable(SkFlattenable*);
SK_API SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
SkFlattenable::Type type);
SK_API sk_sp<SkImageFilter> SkValidatingDeserializeImageFilter(const void* data, size_t size);
#endif

View File

@ -603,8 +603,10 @@ public:
void setRasterizer(sk_sp<SkRasterizer>);
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
SkImageFilter* setImageFilter(SkImageFilter*);
void setImageFilter(sk_sp<SkImageFilter>);
#ifdef SK_SUPPORT_LEGACY_SETIMAGEFILTER_PTR
SkImageFilter* setImageFilter(SkImageFilter*);
#endif
/**
* Return the paint's SkDrawLooper (if any). Does not affect the looper's

View File

@ -602,6 +602,7 @@ DEFINES_ALL = [
"SK_SUPPORT_LEGACY_ACCESSBITMAP",
"SK_SUPPORT_LEGACY_CLIP_REGIONOPS",
"SK_SUPPORT_LEGACY_COLOR_SPACE_FACTORIES",
"SK_SUPPORT_LEGACY_SETIMAGEFILTER_PTR",
"SK_SUPPORT_LEGACY_SHADER_ASALOCALMATRIXSHADER",
"SK_SUPPORT_LEGACY_XFERMODE_PARAM",
]

View File

@ -736,7 +736,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
}
static SkImageFilter* make_serialized_image_filter() {
static sk_sp<SkImageFilter> make_serialized_image_filter() {
sk_sp<SkImageFilter> filter(make_image_filter(false));
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
@ -763,9 +763,7 @@ static SkImageFilter* make_serialized_image_filter() {
}
}
#endif // SK_ADD_RANDOM_BIT_FLIPS
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
SkImageFilter::GetFlattenableType());
return static_cast<SkImageFilter*>(flattenable);
return SkValidatingDeserializeImageFilter(ptr, len);
}
static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
@ -777,7 +775,7 @@ static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai
}
static void do_fuzz(SkCanvas* canvas) {
SkImageFilter* filter = make_serialized_image_filter();
sk_sp<SkImageFilter> filter = make_serialized_image_filter();
#ifdef SK_FUZZER_IS_VERBOSE
static uint32_t numFilters = 0;
@ -794,7 +792,7 @@ static void do_fuzz(SkCanvas* canvas) {
#endif
SkPaint paint;
SkSafeUnref(paint.setImageFilter(filter));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, 0, 0, paint);
}

View File

@ -481,7 +481,7 @@ public:
* draw onto the previous layer using the xfermode from the original paint.
*/
SkPaint tmp;
tmp.setImageFilter(fPaint->getImageFilter());
tmp.setImageFilter(sk_ref_sp(fPaint->getImageFilter()));
tmp.setBlendMode(fPaint->getBlendMode());
SkRect storage;
if (rawBounds) {

View File

@ -25,3 +25,8 @@ SkFlattenable* SkValidatingDeserializeFlattenable(const void* data, size_t size,
SkValidatingReadBuffer buffer(data, size);
return buffer.readFlattenable(type);
}
sk_sp<SkImageFilter> SkValidatingDeserializeImageFilter(const void* data, size_t size) {
return sk_sp<SkImageFilter>((SkImageFilter*)SkValidatingDeserializeFlattenable(
data, size, SkImageFilter::GetFlattenableType()));
}

View File

@ -367,11 +367,12 @@ MOVE_FIELD(DrawLooper)
#undef MOVE_FIELD
void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fDrawLooper = std::move(looper); }
// TODO: remove this variant
#ifdef SK_SUPPORT_LEGACY_SETIMAGEFILTER_PTR
SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imf) {
this->setImageFilter(sk_ref_sp(imf));
return imf;
}
#endif
///////////////////////////////////////////////////////////////////////////////

View File

@ -108,7 +108,7 @@ void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) {
if (flatFlags & SAVELAYERREC_HAS_BACKDROP) {
// overkill, but we didn't already track single flattenables, so using a paint for that
SkPaint paint;
paint.setImageFilter(const_cast<SkImageFilter*>(rec.fBackdrop));
paint.setImageFilter(sk_ref_sp(const_cast<SkImageFilter*>(rec.fBackdrop)));
this->addPaint(paint);
}
if (flatFlags & SAVELAYERREC_HAS_FLAGS) {

View File

@ -1102,7 +1102,7 @@ static int lpaint_getImageFilter(lua_State* L) {
static int lpaint_setImageFilter(lua_State* L) {
SkPaint* paint = get_obj<SkPaint>(L, 1);
paint->setImageFilter(get_ref<SkImageFilter>(L, 2));
paint->setImageFilter(sk_ref_sp(get_ref<SkImageFilter>(L, 2)));
return 0;
}

View File

@ -731,7 +731,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
tiledCanvas.clear(0);
untiledCanvas.clear(0);
SkPaint paint;
paint.setImageFilter(filters.getFilter(i));
paint.setImageFilter(sk_ref_sp(filters.getFilter(i)));
paint.setTextSize(SkIntToScalar(height));
paint.setColor(SK_ColorWHITE);
SkString str;
@ -1231,9 +1231,8 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
// deserialize its contained picture when the filter is serialized
// cross-process. Do this by "laundering" it through SkValidatingReadBuffer.
sk_sp<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()));
sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
data->data(), data->size(), SkImageFilter::GetFlattenableType()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
sk_sp<SkImageFilter> unflattenedFilter = SkValidatingDeserializeImageFilter(data->data(),
data->size());
redPaintWithFilter.setImageFilter(unflattenedFilter);
SkPictureRecorder crossProcessRecorder;
@ -1686,9 +1685,8 @@ DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image)));
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
data->data(), data->size(), SkImageFilter::GetFlattenableType()));
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
sk_sp<SkImageFilter> unflattenedFilter = SkValidatingDeserializeImageFilter(data->data(),
data->size());
REPORTER_ASSERT(reporter, unflattenedFilter);
SkBitmap bm;

View File

@ -400,7 +400,7 @@ DEF_TEST(SkPDF_ImageFilter, reporter) {
// Filter just created; should be unvisited.
REPORTER_ASSERT(reporter, !filter->visited());
SkPaint paint;
paint.setImageFilter(filter.get());
paint.setImageFilter(filter);
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
doc->close();

View File

@ -264,7 +264,7 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
std::move(invalidBitmapSource),
std::move(validBitmapSource), nullptr));
SkAutoTUnref<SkImageFilter> deserializedFilter(
sk_sp<SkImageFilter> deserializedFilter(
TestFlattenableSerialization<SkImageFilter>(
xfermodeImageFilter.get(), shouldSucceed, reporter));

View File

@ -27,18 +27,18 @@ static bool read_test_case(const char* filename, SkString* testdata) {
}
static void run_test_case(const SkString& testdata, const SkBitmap& bitmap,
SkCanvas* canvas) {
SkCanvas* canvas) {
// This call shouldn't crash or cause ASAN to flag any memory issues
// If nothing bad happens within this call, everything is fine
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
testdata.c_str(), testdata.size(), SkImageFilter::GetFlattenableType());
sk_sp<SkImageFilter> flattenable = SkValidatingDeserializeImageFilter(testdata.c_str(),
testdata.size());
// Adding some info, but the test passed if we got here without any trouble
if (flattenable != nullptr) {
SkDebugf("Valid stream detected.\n");
// Let's see if using the filters can cause any trouble...
SkPaint paint;
paint.setImageFilter(static_cast<SkImageFilter*>(flattenable))->unref();
paint.setImageFilter(flattenable);
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(
0, 0, SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)));

View File

@ -1252,11 +1252,10 @@ static void extract_json_paint_imagefilter(Json::Value& jsonPaint, UrlDataManage
SkPaint* target) {
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER)) {
Json::Value jsonImageFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER];
SkImageFilter* imageFilter = (SkImageFilter*) load_flattenable(jsonImageFilter,
urlDataManager);
sk_sp<SkImageFilter> imageFilter((SkImageFilter*) load_flattenable(jsonImageFilter,
urlDataManager));
if (imageFilter != nullptr) {
target->setImageFilter(imageFilter);
imageFilter->unref();
}
}
}