diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index b388e1c75e..0c91d1ddec 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -322,48 +322,48 @@ void SkPaintPriv::Flatten(const SkPaint& paint, SkWriteBuffer& buffer) { } } -SkReadPaintResult SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer, SkFont* font) { - SkSafeRange safe; +SkPaint SkPaintPriv::Unflatten(SkReadBuffer& buffer) { + SkPaint paint; - paint->setStrokeWidth(buffer.readScalar()); - paint->setStrokeMiter(buffer.readScalar()); + paint.setStrokeWidth(buffer.readScalar()); + paint.setStrokeMiter(buffer.readScalar()); { SkColor4f color; buffer.readColor4f(&color); - paint->setColor(color, sk_srgb_singleton()); + paint.setColor(color, sk_srgb_singleton()); } - unsigned flatFlags = unpack_v68(paint, buffer.readUInt(), safe); + SkSafeRange safe; + unsigned flatFlags = unpack_v68(&paint, buffer.readUInt(), safe); if (!(flatFlags & kHasEffects_FlatFlag)) { // This is a simple SkPaint without any effects, so clear all the effect-related fields. - paint->setPathEffect(nullptr); - paint->setShader(nullptr); - paint->setMaskFilter(nullptr); - paint->setColorFilter(nullptr); - paint->setImageFilter(nullptr); + paint.setPathEffect(nullptr); + paint.setShader(nullptr); + paint.setMaskFilter(nullptr); + paint.setColorFilter(nullptr); + paint.setImageFilter(nullptr); } else if (buffer.isVersionLT(SkPicturePriv::kSkBlenderInSkPaint)) { // This paint predates the introduction of user blend functions (via SkBlender). - paint->setPathEffect(buffer.readPathEffect()); - paint->setShader(buffer.readShader()); - paint->setMaskFilter(buffer.readMaskFilter()); - paint->setColorFilter(buffer.readColorFilter()); + paint.setPathEffect(buffer.readPathEffect()); + paint.setShader(buffer.readShader()); + paint.setMaskFilter(buffer.readMaskFilter()); + paint.setColorFilter(buffer.readColorFilter()); (void)buffer.read32(); // was drawLooper (now deprecated) - paint->setImageFilter(buffer.readImageFilter()); + paint.setImageFilter(buffer.readImageFilter()); } else { - paint->setPathEffect(buffer.readPathEffect()); - paint->setShader(buffer.readShader()); - paint->setMaskFilter(buffer.readMaskFilter()); - paint->setColorFilter(buffer.readColorFilter()); - paint->setImageFilter(buffer.readImageFilter()); - paint->setBlender(buffer.readBlender()); + paint.setPathEffect(buffer.readPathEffect()); + paint.setShader(buffer.readShader()); + paint.setMaskFilter(buffer.readMaskFilter()); + paint.setColorFilter(buffer.readColorFilter()); + paint.setImageFilter(buffer.readImageFilter()); + paint.setBlender(buffer.readBlender()); } - if (!buffer.validate(safe)) { - paint->reset(); - return kFailed_ReadPaint; + if (!buffer.validate(safe.ok())) { + paint.reset(); } - return kSuccess_JustPaint; + return paint; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkPaintPriv.h b/src/core/SkPaintPriv.h index f3447979ed..1f0955e20f 100644 --- a/src/core/SkPaintPriv.h +++ b/src/core/SkPaintPriv.h @@ -10,16 +10,9 @@ #include "include/core/SkPaint.h" -class SkFont; class SkReadBuffer; class SkWriteBuffer; -enum SkReadPaintResult { - kFailed_ReadPaint, - kSuccess_JustPaint, - kSuccess_PaintAndFont, -}; - class SkPaintPriv { public: enum ShaderOverrideOpacity { @@ -54,18 +47,8 @@ public: /** Populates SkPaint, typically from a serialized stream, created by calling flatten() at an earlier time. - - SkReadBuffer class is not public, so unflatten() cannot be meaningfully called - by the client. - - Older formats also stored font info in the serialized data. On success, this - returns if it deserialized just a paint, or both a font and paint. The font - param is optional. - - @param buffer serialized data describing SkPaint content - @return false if the buffer contains invalid data */ - static SkReadPaintResult Unflatten(SkPaint* paint, SkReadBuffer& buffer, SkFont* font); + static SkPaint Unflatten(SkReadBuffer& buffer); // If this paint has any color filter, fold it into the shader and/or paint color // so that it draws the same but getColorFilter() returns nullptr. diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 55790e2a32..2513cd013e 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -415,8 +415,8 @@ void SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t const int count = SkToInt(size); for (int i = 0; i < count; ++i) { - // Do we need to keep an array of fFonts for legacy draws? - if (!buffer.readPaint(&fPaints.push_back(), nullptr)) { + fPaints.push_back(buffer.readPaint()); + if (!buffer.isValid()) { return; } } diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index cffaac6e0a..08338ca018 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -108,8 +108,8 @@ public: void readPath(SkPath* path); - SkReadPaintResult readPaint(SkPaint* paint, SkFont* font) { - return SkPaintPriv::Unflatten(paint, *this, font); + SkPaint readPaint() { + return SkPaintPriv::Unflatten(*this); } SkFlattenable* readFlattenable(SkFlattenable::Type); diff --git a/src/core/SkTextBlobTrace.cpp b/src/core/SkTextBlobTrace.cpp index 88275427a6..df461f54bf 100644 --- a/src/core/SkTextBlobTrace.cpp +++ b/src/core/SkTextBlobTrace.cpp @@ -34,7 +34,7 @@ std::vector SkTextBlobTrace::CreateBlobTrace(SkStream* while (!readBuffer.eof()) { SkTextBlobTrace::Record record; record.origUniqueID = readBuffer.readUInt(); - readBuffer.readPaint(&record.paint, nullptr); + record.paint = readBuffer.readPaint(); readBuffer.readPoint(&record.offset); record.blob = SkTextBlobPriv::MakeFromBuffer(readBuffer); trace.push_back(std::move(record)); diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index b898c06ef6..63a5639476 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -231,7 +231,7 @@ sk_sp SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) { info.fColorMode = (SkBlendMode)buffer.readInt(); buffer.readPoint(&info.fOffset); info.fPostTranslate = buffer.readBool(); - buffer.readPaint(builder.addLayerOnTop(info), nullptr); + *builder.addLayerOnTop(info) = buffer.readPaint(); if (!buffer.isValid()) { return nullptr; } diff --git a/src/effects/imagefilters/SkShaderImageFilter.cpp b/src/effects/imagefilters/SkShaderImageFilter.cpp index c1127fc0c6..a3f4895452 100644 --- a/src/effects/imagefilters/SkShaderImageFilter.cpp +++ b/src/effects/imagefilters/SkShaderImageFilter.cpp @@ -66,9 +66,7 @@ void SkRegisterShaderImageFilterFlattenable() { sk_sp SkShaderImageFilter::CreateProc(SkReadBuffer& buffer) { SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); - SkPaint paint; - buffer.readPaint(&paint, nullptr); - return SkShaderImageFilter::Make(paint, common.cropRect()); + return SkShaderImageFilter::Make(buffer.readPaint(), common.cropRect()); } void SkShaderImageFilter::flatten(SkWriteBuffer& buffer) const { diff --git a/tests/FlattenDrawableTest.cpp b/tests/FlattenDrawableTest.cpp index 08d61bdc46..0d164aa76b 100644 --- a/tests/FlattenDrawableTest.cpp +++ b/tests/FlattenDrawableTest.cpp @@ -71,9 +71,7 @@ public: } static sk_sp CreateProc(SkReadBuffer& buffer) { - SkPaint paint; - buffer.readPaint(&paint, nullptr); - return sk_sp(new PaintDrawable(paint)); + return sk_sp(new PaintDrawable(buffer.readPaint())); } Factory getFactory() const override { return CreateProc; } diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index f221003008..1728241fbb 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -116,8 +116,7 @@ DEF_TEST(Paint_flattening, reporter) { writer.writeToMemory(buf.get()); SkReadBuffer reader(buf.get(), writer.bytesWritten()); - SkPaint paint2; - SkPaintPriv::Unflatten(&paint2, reader, nullptr); + SkPaint paint2 = reader.readPaint(); REPORTER_ASSERT(reporter, paint2 == paint); }}} @@ -153,8 +152,7 @@ DEF_TEST(Paint_MoreFlattening, r) { writer.writeToMemory(buf.get()); SkReadBuffer reader(buf.get(), writer.bytesWritten()); - SkPaint other; - SkPaintPriv::Unflatten(&other, reader, nullptr); + SkPaint other = reader.readPaint(); ASSERT(reader.offset() == writer.bytesWritten()); // No matter the encoding, these must always hold.