make paint flatten unflatten private
SkPaint flatten and unflatten rely on interfaces that are not public, SkReadBuffer and SkWriteBuffer. R=reed@google.com Bug: skia:6172 Change-Id: I487af9f8931c78daf763c51d9e0d3ff8ff440b22 Reviewed-on: https://skia-review.googlesource.com/112561 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Cary Clark <caryclark@skia.org>
This commit is contained in:
parent
c618a5b3e9
commit
60ca8675e5
@ -393,51 +393,6 @@ The hash returned is platform and implementation specific.
|
||||
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method void flatten(SkWriteBuffer& buffer) const
|
||||
|
||||
#In Management
|
||||
#Line # serializes into a buffer ##
|
||||
Serializes Paint into a buffer. A companion unflatten() call
|
||||
can reconstitute the paint at a later time.
|
||||
|
||||
#Param buffer Write_Buffer receiving the flattened Paint data ##
|
||||
|
||||
# why is flatten() public?
|
||||
#Bug 6172
|
||||
|
||||
#NoExample
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool unflatten(SkReadBuffer& buffer)
|
||||
|
||||
#In Management
|
||||
#Line # populates from a serialized stream ##
|
||||
Populates Paint, 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.
|
||||
|
||||
#Param buffer serialized data describing Paint content ##
|
||||
|
||||
#Return false if the buffer contains invalid data ##
|
||||
|
||||
# why is unflatten() public?
|
||||
#Bug 6172
|
||||
|
||||
#NoExample
|
||||
##
|
||||
|
||||
#SeeAlso SkReadBuffer
|
||||
|
||||
##
|
||||
|
||||
#Subtopic Management ##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
@ -20,8 +20,6 @@ class SkColorFilter;
|
||||
class SkData;
|
||||
class SkDescriptor;
|
||||
class SkDrawLooper;
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
class SkGlyph;
|
||||
struct SkRect;
|
||||
class SkGlyphCache;
|
||||
@ -161,24 +159,6 @@ public:
|
||||
*/
|
||||
uint32_t getHash() const;
|
||||
|
||||
/** Serializes SkPaint into a buffer. A companion unflatten() call
|
||||
can reconstitute the paint at a later time.
|
||||
|
||||
@param buffer SkWriteBuffer receiving the flattened SkPaint data
|
||||
*/
|
||||
void flatten(SkWriteBuffer& buffer) const;
|
||||
|
||||
/** 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.
|
||||
|
||||
@param buffer serialized data describing SkPaint content
|
||||
@return false if the buffer contains invalid data
|
||||
*/
|
||||
bool unflatten(SkReadBuffer& buffer);
|
||||
|
||||
/** Sets all SkPaint contents to their initial values. This is equivalent to replacing
|
||||
SkPaint with the result of SkPaint().
|
||||
*/
|
||||
@ -1725,6 +1705,7 @@ private:
|
||||
friend class SkCanonicalizePaint;
|
||||
friend class SkCanvas;
|
||||
friend class SkDraw;
|
||||
friend class SkPaintPriv;
|
||||
friend class SkPDFDevice;
|
||||
friend class SkScalerContext; // for computeLuminanceColor()
|
||||
friend class SkTextBaseIter;
|
||||
|
@ -1382,93 +1382,93 @@ static FlatFlags unpack_paint_flags(SkPaint* paint, uint32_t packed) {
|
||||
/* To save space/time, we analyze the paint, and write a truncated version of
|
||||
it if there are not tricky elements like shaders, etc.
|
||||
*/
|
||||
void SkPaint::flatten(SkWriteBuffer& buffer) const {
|
||||
void SkPaintPriv::Flatten(const SkPaint& paint, SkWriteBuffer& buffer) {
|
||||
// We force recording our typeface, even if its "default" since the receiver process
|
||||
// may have a different notion of default.
|
||||
SkTypeface* tf = SkPaintPriv::GetTypefaceOrDefault(*this);
|
||||
SkTypeface* tf = SkPaintPriv::GetTypefaceOrDefault(paint);
|
||||
SkASSERT(tf);
|
||||
|
||||
uint8_t flatFlags = kHasTypeface_FlatFlag;
|
||||
|
||||
if (asint(this->getPathEffect()) |
|
||||
asint(this->getShader()) |
|
||||
asint(this->getMaskFilter()) |
|
||||
asint(this->getColorFilter()) |
|
||||
asint(this->getLooper()) |
|
||||
asint(this->getImageFilter())) {
|
||||
if (asint(paint.getPathEffect()) |
|
||||
asint(paint.getShader()) |
|
||||
asint(paint.getMaskFilter()) |
|
||||
asint(paint.getColorFilter()) |
|
||||
asint(paint.getLooper()) |
|
||||
asint(paint.getImageFilter())) {
|
||||
flatFlags |= kHasEffects_FlatFlag;
|
||||
}
|
||||
|
||||
buffer.writeScalar(this->getTextSize());
|
||||
buffer.writeScalar(this->getTextScaleX());
|
||||
buffer.writeScalar(this->getTextSkewX());
|
||||
buffer.writeScalar(this->getStrokeWidth());
|
||||
buffer.writeScalar(this->getStrokeMiter());
|
||||
buffer.writeColor(this->getColor());
|
||||
buffer.writeScalar(paint.getTextSize());
|
||||
buffer.writeScalar(paint.getTextScaleX());
|
||||
buffer.writeScalar(paint.getTextSkewX());
|
||||
buffer.writeScalar(paint.getStrokeWidth());
|
||||
buffer.writeScalar(paint.getStrokeMiter());
|
||||
buffer.writeColor(paint.getColor());
|
||||
|
||||
buffer.writeUInt(pack_paint_flags(this->getFlags(), this->getHinting(), this->getTextAlign(),
|
||||
this->getFilterQuality(), flatFlags));
|
||||
buffer.writeUInt(pack_4(this->getStrokeCap(), this->getStrokeJoin(),
|
||||
(this->getStyle() << 4) | this->getTextEncoding(),
|
||||
fBlendMode));
|
||||
buffer.writeUInt(pack_paint_flags(paint.getFlags(), paint.getHinting(), paint.getTextAlign(),
|
||||
paint.getFilterQuality(), flatFlags));
|
||||
buffer.writeUInt(pack_4(paint.getStrokeCap(), paint.getStrokeJoin(),
|
||||
(paint.getStyle() << 4) | paint.getTextEncoding(),
|
||||
paint.fBlendMode));
|
||||
|
||||
buffer.writeTypeface(tf);
|
||||
|
||||
if (flatFlags & kHasEffects_FlatFlag) {
|
||||
buffer.writeFlattenable(this->getPathEffect());
|
||||
buffer.writeFlattenable(this->getShader());
|
||||
buffer.writeFlattenable(this->getMaskFilter());
|
||||
buffer.writeFlattenable(this->getColorFilter());
|
||||
buffer.writeFlattenable(paint.getPathEffect());
|
||||
buffer.writeFlattenable(paint.getShader());
|
||||
buffer.writeFlattenable(paint.getMaskFilter());
|
||||
buffer.writeFlattenable(paint.getColorFilter());
|
||||
buffer.write32(0); // use to be SkRasterizer
|
||||
buffer.writeFlattenable(this->getLooper());
|
||||
buffer.writeFlattenable(this->getImageFilter());
|
||||
buffer.writeFlattenable(paint.getLooper());
|
||||
buffer.writeFlattenable(paint.getImageFilter());
|
||||
}
|
||||
}
|
||||
|
||||
bool SkPaint::unflatten(SkReadBuffer& buffer) {
|
||||
bool SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer) {
|
||||
SkSafeRange safe;
|
||||
|
||||
this->setTextSize(buffer.readScalar());
|
||||
this->setTextScaleX(buffer.readScalar());
|
||||
this->setTextSkewX(buffer.readScalar());
|
||||
this->setStrokeWidth(buffer.readScalar());
|
||||
this->setStrokeMiter(buffer.readScalar());
|
||||
this->setColor(buffer.readColor());
|
||||
paint->setTextSize(buffer.readScalar());
|
||||
paint->setTextScaleX(buffer.readScalar());
|
||||
paint->setTextSkewX(buffer.readScalar());
|
||||
paint->setStrokeWidth(buffer.readScalar());
|
||||
paint->setStrokeMiter(buffer.readScalar());
|
||||
paint->setColor(buffer.readColor());
|
||||
|
||||
unsigned flatFlags = unpack_paint_flags(this, buffer.readUInt());
|
||||
unsigned flatFlags = unpack_paint_flags(paint, buffer.readUInt());
|
||||
|
||||
uint32_t tmp = buffer.readUInt();
|
||||
this->setStrokeCap(safe.checkLE((tmp >> 24) & 0xFF, kLast_Cap));
|
||||
this->setStrokeJoin(safe.checkLE((tmp >> 16) & 0xFF, kLast_Join));
|
||||
this->setStyle(safe.checkLE((tmp >> 12) & 0xF, kStrokeAndFill_Style));
|
||||
this->setTextEncoding(safe.checkLE((tmp >> 8) & 0xF, kGlyphID_TextEncoding));
|
||||
this->setBlendMode(safe.checkLE(tmp & 0xFF, SkBlendMode::kLastMode));
|
||||
paint->setStrokeCap(safe.checkLE((tmp >> 24) & 0xFF, SkPaint::kLast_Cap));
|
||||
paint->setStrokeJoin(safe.checkLE((tmp >> 16) & 0xFF, SkPaint::kLast_Join));
|
||||
paint->setStyle(safe.checkLE((tmp >> 12) & 0xF, SkPaint::kStrokeAndFill_Style));
|
||||
paint->setTextEncoding(safe.checkLE((tmp >> 8) & 0xF, SkPaint::kGlyphID_TextEncoding));
|
||||
paint->setBlendMode(safe.checkLE(tmp & 0xFF, SkBlendMode::kLastMode));
|
||||
|
||||
if (flatFlags & kHasTypeface_FlatFlag) {
|
||||
this->setTypeface(buffer.readTypeface());
|
||||
paint->setTypeface(buffer.readTypeface());
|
||||
} else {
|
||||
this->setTypeface(nullptr);
|
||||
paint->setTypeface(nullptr);
|
||||
}
|
||||
|
||||
if (flatFlags & kHasEffects_FlatFlag) {
|
||||
this->setPathEffect(buffer.readPathEffect());
|
||||
this->setShader(buffer.readShader());
|
||||
this->setMaskFilter(buffer.readMaskFilter());
|
||||
this->setColorFilter(buffer.readColorFilter());
|
||||
paint->setPathEffect(buffer.readPathEffect());
|
||||
paint->setShader(buffer.readShader());
|
||||
paint->setMaskFilter(buffer.readMaskFilter());
|
||||
paint->setColorFilter(buffer.readColorFilter());
|
||||
(void)buffer.read32(); // use to be SkRasterizer
|
||||
this->setLooper(buffer.readDrawLooper());
|
||||
this->setImageFilter(buffer.readImageFilter());
|
||||
paint->setLooper(buffer.readDrawLooper());
|
||||
paint->setImageFilter(buffer.readImageFilter());
|
||||
} else {
|
||||
this->setPathEffect(nullptr);
|
||||
this->setShader(nullptr);
|
||||
this->setMaskFilter(nullptr);
|
||||
this->setColorFilter(nullptr);
|
||||
this->setLooper(nullptr);
|
||||
this->setImageFilter(nullptr);
|
||||
paint->setPathEffect(nullptr);
|
||||
paint->setShader(nullptr);
|
||||
paint->setMaskFilter(nullptr);
|
||||
paint->setColorFilter(nullptr);
|
||||
paint->setLooper(nullptr);
|
||||
paint->setImageFilter(nullptr);
|
||||
}
|
||||
|
||||
if (!buffer.validate(safe)) {
|
||||
this->reset();
|
||||
paint->reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
class SkBitmap;
|
||||
class SkImage;
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
|
||||
class SkPaintPriv {
|
||||
public:
|
||||
@ -76,6 +78,25 @@ public:
|
||||
static sk_sp<SkTypeface> RefTypefaceOrDefault(const SkPaint& paint) {
|
||||
return paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault();
|
||||
}
|
||||
|
||||
/** Serializes SkPaint into a buffer. A companion unflatten() call
|
||||
can reconstitute the paint at a later time.
|
||||
|
||||
@param buffer SkWriteBuffer receiving the flattened SkPaint data
|
||||
*/
|
||||
static void Flatten(const SkPaint& paint, SkWriteBuffer& buffer);
|
||||
|
||||
/** 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.
|
||||
|
||||
@param buffer serialized data describing SkPaint content
|
||||
@return false if the buffer contains invalid data
|
||||
*/
|
||||
static bool Unflatten(SkPaint* paint, SkReadBuffer& buffer);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "SkDrawLooper.h"
|
||||
#include "SkImageFilter.h"
|
||||
#include "SkMaskFilterBase.h"
|
||||
#include "SkPaintPriv.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkPicture.h"
|
||||
@ -143,7 +144,7 @@ public:
|
||||
void readRegion(SkRegion* region);
|
||||
|
||||
void readPath(SkPath* path);
|
||||
virtual bool readPaint(SkPaint* paint) { return paint->unflatten(*this); }
|
||||
virtual bool readPaint(SkPaint* paint) { return SkPaintPriv::Unflatten(paint, *this); }
|
||||
|
||||
SkFlattenable* readFlattenable(SkFlattenable::Type);
|
||||
template <typename T> sk_sp<T> readFlattenable() {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "SkBitmap.h"
|
||||
#include "SkData.h"
|
||||
#include "SkDeduper.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPaintPriv.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkPtrRecorder.h"
|
||||
#include "SkStream.h"
|
||||
@ -187,7 +187,7 @@ void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) {
|
||||
}
|
||||
|
||||
void SkBinaryWriteBuffer::writePaint(const SkPaint& paint) {
|
||||
paint.flatten(*this);
|
||||
SkPaintPriv::Flatten(paint, *this);
|
||||
}
|
||||
|
||||
SkFactorySet* SkBinaryWriteBuffer::setFactoryRecorder(SkFactorySet* rec) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "SkBlurMask.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkLayerDrawLooper.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPaintPriv.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkRandom.h"
|
||||
#include "SkReadBuffer.h"
|
||||
@ -256,14 +256,14 @@ DEF_TEST(Paint_flattening, reporter) {
|
||||
FOR_SETUP(p, styles, setStyle)
|
||||
|
||||
SkBinaryWriteBuffer writer;
|
||||
paint.flatten(writer);
|
||||
SkPaintPriv::Flatten(paint, writer);
|
||||
|
||||
SkAutoMalloc buf(writer.bytesWritten());
|
||||
writer.writeToMemory(buf.get());
|
||||
SkReadBuffer reader(buf.get(), writer.bytesWritten());
|
||||
|
||||
SkPaint paint2;
|
||||
paint2.unflatten(reader);
|
||||
SkPaintPriv::Unflatten(&paint2, reader);
|
||||
REPORTER_ASSERT(reporter, paint2 == paint);
|
||||
|
||||
}}}}}}}
|
||||
@ -296,14 +296,14 @@ DEF_TEST(Paint_MoreFlattening, r) {
|
||||
paint.setLooper(nullptr); // Default value, ignored.
|
||||
|
||||
SkBinaryWriteBuffer writer;
|
||||
paint.flatten(writer);
|
||||
SkPaintPriv::Flatten(paint, writer);
|
||||
|
||||
SkAutoMalloc buf(writer.bytesWritten());
|
||||
writer.writeToMemory(buf.get());
|
||||
SkReadBuffer reader(buf.get(), writer.bytesWritten());
|
||||
|
||||
SkPaint other;
|
||||
other.unflatten(reader);
|
||||
SkPaintPriv::Unflatten(&other, reader);
|
||||
ASSERT(reader.offset() == writer.bytesWritten());
|
||||
|
||||
// No matter the encoding, these must always hold.
|
||||
|
Loading…
Reference in New Issue
Block a user