Clean up unflattening paints

Attempting reland after breaking G3
-- fixed by updating layerdrawlooper

Change-Id: I9013baae4ff2acad2040741ba53188d616f2920c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/437679
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-08-09 10:46:33 -04:00 committed by SkCQ
parent 49914e5813
commit 22cada0a38
9 changed files with 37 additions and 60 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

@ -231,7 +231,7 @@ sk_sp<SkFlattenable> 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;
}

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.