Clean up unflattening paints

Just removing legacy cruft for fonts, and also change to return by
value (cleaner).

Change-Id: If120931119c32542e06801da2b6d60ba84ba2186
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/437676
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-08-09 07:25:03 -04:00 committed by SkCQ
parent fdf7b3c41f
commit 717ef9472b
8 changed files with 36 additions and 59 deletions

View File

@ -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;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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);

View File

@ -34,7 +34,7 @@ std::vector<SkTextBlobTrace::Record> 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));

View File

@ -66,9 +66,7 @@ void SkRegisterShaderImageFilterFlattenable() {
sk_sp<SkFlattenable> 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 {

View File

@ -71,9 +71,7 @@ public:
}
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer) {
SkPaint paint;
buffer.readPaint(&paint, nullptr);
return sk_sp<PaintDrawable>(new PaintDrawable(paint));
return sk_sp<PaintDrawable>(new PaintDrawable(buffer.readPaint()));
}
Factory getFactory() const override { return CreateProc; }

View File

@ -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.