formalize named picture versions
BUG=skia: R=mtklein@google.com, robertphillips@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/291913004 git-svn-id: http://skia.googlecode.com/svn/trunk@14807 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
731b28daaa
commit
7ed173b1eb
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
@ -41,13 +40,25 @@ public:
|
||||
SkReadBuffer(SkStream* stream);
|
||||
virtual ~SkReadBuffer();
|
||||
|
||||
/** Return the version of the serialized picture this buffer holds, or 0 if unset. */
|
||||
int pictureVersion() const { return fPictureVersion; }
|
||||
enum Version {
|
||||
kFilterLevelIsEnum_Version = 23,
|
||||
kGradientFlippedFlag_Version = 24,
|
||||
kDashWritesPhaseIntervals_Version = 25,
|
||||
kColorShaderNoBool_Version = 26,
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true IFF the version is older than the specified version.
|
||||
*/
|
||||
bool isVersionLT(Version targetVersion) const {
|
||||
SkASSERT(targetVersion > 0);
|
||||
return fVersion > 0 && fVersion < targetVersion;
|
||||
}
|
||||
|
||||
/** This may be called at most once; most clients of SkReadBuffer should not mess with it. */
|
||||
void setPictureVersion(int version) {
|
||||
SkASSERT(0 == fPictureVersion || version == fPictureVersion);
|
||||
fPictureVersion = version;
|
||||
void setVersion(int version) {
|
||||
SkASSERT(0 == fVersion || version == fVersion);
|
||||
fVersion = version;
|
||||
}
|
||||
|
||||
enum Flags {
|
||||
@ -188,7 +199,7 @@ private:
|
||||
bool readArray(void* value, size_t size, size_t elementSize);
|
||||
|
||||
uint32_t fFlags;
|
||||
int fPictureVersion;
|
||||
int fVersion;
|
||||
|
||||
void* fMemoryPtr;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
@ -2182,9 +2181,8 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
|
||||
this->setStrokeMiter(read_scalar(pod));
|
||||
this->setColor(*pod++);
|
||||
|
||||
const int picVer = buffer.pictureVersion();
|
||||
unsigned flatFlags = 0;
|
||||
if (picVer > 0 && picVer <= 22) {
|
||||
if (buffer.isVersionLT(SkReadBuffer::kFilterLevelIsEnum_Version)) {
|
||||
flatFlags = unpack_paint_flags_v22(this, *pod++);
|
||||
} else {
|
||||
flatFlags = unpack_paint_flags(this, *pod++);
|
||||
|
@ -534,7 +534,7 @@ bool SkPicturePlayback::parseStreamTag(SkPicture* picture,
|
||||
|
||||
SkReadBuffer buffer(storage.get(), size);
|
||||
buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags));
|
||||
buffer.setPictureVersion(fInfo.fVersion);
|
||||
buffer.setVersion(fInfo.fVersion);
|
||||
|
||||
fFactoryPlayback->setupBuffer(buffer);
|
||||
fTFPlayback.setupBuffer(buffer);
|
||||
@ -634,7 +634,7 @@ SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkPicture* picture,
|
||||
SkReadBuffer& buffer,
|
||||
const SkPictInfo& info) {
|
||||
SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (picture, info)));
|
||||
buffer.setPictureVersion(info.fVersion);
|
||||
buffer.setVersion(info.fVersion);
|
||||
|
||||
if (!playback->parseBuffer(picture, buffer)) {
|
||||
return NULL;
|
||||
|
@ -25,7 +25,7 @@ static uint32_t default_flags() {
|
||||
|
||||
SkReadBuffer::SkReadBuffer() {
|
||||
fFlags = default_flags();
|
||||
fPictureVersion = 0;
|
||||
fVersion = 0;
|
||||
fMemoryPtr = NULL;
|
||||
|
||||
fBitmapStorage = NULL;
|
||||
@ -43,7 +43,7 @@ SkReadBuffer::SkReadBuffer() {
|
||||
|
||||
SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
|
||||
fFlags = default_flags();
|
||||
fPictureVersion = 0;
|
||||
fVersion = 0;
|
||||
fReader.setMemory(data, size);
|
||||
fMemoryPtr = NULL;
|
||||
|
||||
@ -62,7 +62,7 @@ SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
|
||||
|
||||
SkReadBuffer::SkReadBuffer(SkStream* stream) {
|
||||
fFlags = default_flags();
|
||||
fPictureVersion = 0;
|
||||
fVersion = 0;
|
||||
const size_t length = stream->getLength();
|
||||
fMemoryPtr = sk_malloc_throw(length);
|
||||
stream->read(fMemoryPtr, length);
|
||||
|
@ -255,7 +255,7 @@ bool SkColorShader::isOpaque() const {
|
||||
SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) {
|
||||
// V25_COMPATIBILITY_CODE We had a boolean to make the color shader inherit the paint's
|
||||
// color. We don't support that any more.
|
||||
if (b.pictureVersion() < 26 && 0 != b.pictureVersion()) {
|
||||
if (b.isVersionLT(SkReadBuffer::kColorShaderNoBool_Version)) {
|
||||
if (b.readBool()) {
|
||||
SkDEBUGFAIL("We shouldn't have pictures that recorded the inherited case.");
|
||||
fColor = SK_ColorWHITE;
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Android Open Source Project
|
||||
*
|
||||
@ -6,7 +5,6 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "SkDashPathEffect.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
@ -544,7 +542,7 @@ SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) {
|
||||
}
|
||||
|
||||
SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
|
||||
bool useOldPic = buffer.pictureVersion() < 25 && 0 != buffer.pictureVersion();
|
||||
bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_Version);
|
||||
if (useOldPic) {
|
||||
fInitialDashIndex = buffer.readInt();
|
||||
fInitialDashLength = buffer.readScalar();
|
||||
|
@ -351,9 +351,7 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient(
|
||||
fCenter2(buffer.readPoint()),
|
||||
fRadius1(buffer.readScalar()),
|
||||
fRadius2(buffer.readScalar()) {
|
||||
if (buffer.pictureVersion() >= 24 || 0 == buffer.pictureVersion()) {
|
||||
fFlippedGrad = buffer.readBool();
|
||||
} else {
|
||||
if (buffer.isVersionLT(SkReadBuffer::kGradientFlippedFlag_Version)) {
|
||||
// V23_COMPATIBILITY_CODE
|
||||
// Sort gradient by radius size for old pictures
|
||||
if (fRadius2 < fRadius1) {
|
||||
@ -364,6 +362,8 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient(
|
||||
} else {
|
||||
fFlippedGrad = false;
|
||||
}
|
||||
} else {
|
||||
fFlippedGrad = buffer.readBool();
|
||||
}
|
||||
this->init();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user