ensure we always set the pictinfo.fVersion
authorMike Reed <reed@google.com>
Tue, 4 Oct 2016 19:12:01 +0000 (15:12 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 4 Oct 2016 19:33:23 +0000 (19:33 +0000)
BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2932

Change-Id: I8864a60f629e0f68b7871e0c388b42f4b6d78dbe
Reviewed-on: https://skia-review.googlesource.com/2932
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>

src/core/SkPicture.cpp
src/core/SkPictureData.cpp
src/core/SkPictureData.h
src/core/SkReadBuffer.h
src/core/SkRecordedDrawable.cpp
tools/skpinfo.cpp

index 60987b64c0a887c19c44588cd3df106e8a195cf5..88da70aacf3bf4bdc9e115bdb79277ed70620268 100644 (file)
@@ -90,7 +90,7 @@ SkPictInfo SkPicture::createHeader() const {
     memcpy(info.fMagic, kMagic, sizeof(kMagic));
 
     // Set picture info after magic bytes in the header
-    info.fVersion = CURRENT_PICTURE_VERSION;
+    info.setVersion(CURRENT_PICTURE_VERSION);
     info.fCullRect = this->cullRect();
     info.fFlags = SkPictInfo::kCrossProcess_Flag;
     // TODO: remove this flag, since we're always float (now)
@@ -106,7 +106,7 @@ bool SkPicture::IsValidPictInfo(const SkPictInfo& info) {
     if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) {
         return false;
     }
-    if (info.fVersion < MIN_PICTURE_VERSION || info.fVersion > CURRENT_PICTURE_VERSION) {
+    if (info.getVersion() < MIN_PICTURE_VERSION || info.getVersion() > CURRENT_PICTURE_VERSION) {
         return false;
     }
     return true;
@@ -123,7 +123,7 @@ bool SkPicture::InternalOnly_StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
         return false;
     }
 
-    info.fVersion          = stream->readU32();
+    info.setVersion(         stream->readU32());
     info.fCullRect.fLeft   = stream->readScalar();
     info.fCullRect.fTop    = stream->readScalar();
     info.fCullRect.fRight  = stream->readScalar();
@@ -144,7 +144,7 @@ bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer* buffer, SkPictInfo* pInfo
         return false;
     }
 
-    info.fVersion = buffer->readUInt();
+    info.setVersion(buffer->readUInt());
     buffer->readRect(&info.fCullRect);
     info.fFlags = buffer->readUInt();
 
@@ -249,7 +249,7 @@ void SkPicture::flatten(SkWriteBuffer& buffer) const {
     SkAutoTDelete<SkPictureData> data(this->backport());
 
     buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic));
-    buffer.writeUInt(info.fVersion);
+    buffer.writeUInt(info.getVersion());
     buffer.writeRect(info.fCullRect);
     buffer.writeUInt(info.fFlags);
     if (data) {
index 8c641097dcac2b580dad60376996ccfde6db7679..68789acddf0f3d48452ea23e49087ac0ad783388 100644 (file)
@@ -426,7 +426,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
             /* Should we use SkValidatingReadBuffer instead? */
             SkReadBuffer buffer(storage.get(), size);
             buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags));
-            buffer.setVersion(fInfo.fVersion);
+            buffer.setVersion(fInfo.getVersion());
 
             if (!fFactoryPlayback) {
                 return false;
@@ -591,7 +591,7 @@ SkPictureData* SkPictureData::CreateFromStream(SkStream* stream,
 SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer,
                                                const SkPictInfo& info) {
     SkAutoTDelete<SkPictureData> data(new SkPictureData(info));
-    buffer.setVersion(info.fVersion);
+    buffer.setVersion(info.getVersion());
 
     if (!data->parseBuffer(buffer)) {
         return nullptr;
index 353bbd935762ac484b44956a715ab5061f0243e6..332b7996383240b9deebfb23756aa1b1f37f3763 100644 (file)
@@ -34,8 +34,23 @@ struct SkPictInfo {
         kPtrIs64Bit_Flag        = 1 << 2,
     };
 
+    SkPictInfo() : fVersion(~0U) {}
+
+    uint32_t getVersion() const {
+        SkASSERT(fVersion != ~0U);
+        return fVersion;
+    }
+
+    void setVersion(uint32_t version) {
+        SkASSERT(version != ~0U);
+        fVersion = version;
+    }
+
+public:
     char        fMagic[8];
+private:
     uint32_t    fVersion;
+public:
     SkRect      fCullRect;
     uint32_t    fFlags;
 };
index 3e6742fde0de9dc873bdc954ab9043aedd9d43eb..8a3b7bac8878a7ffd165fde8be6268ba450751b4 100644 (file)
@@ -79,6 +79,8 @@ public:
         return fVersion > 0 && fVersion < targetVersion;
     }
 
+    uint32_t getVersion() const { return fVersion; }
+
     /** This may be called at most once; most clients of SkReadBuffer should not mess with it. */
     void setVersion(int version) {
         SkASSERT(0 == fVersion || version == fVersion);
index 041fdd20f592d120ea3ff7f09e076d2e86344e12..9e68be1d25acbcffdd08dac3c33e6fa23b991c92 100644 (file)
@@ -78,7 +78,9 @@ sk_sp<SkFlattenable> SkRecordedDrawable::CreateProc(SkReadBuffer& buffer) {
 
     // Unflatten into a SkPictureData.
     SkPictInfo info;
+    info.setVersion(buffer.getVersion());
     info.fCullRect = bounds;
+    info.fFlags = 0;    // ???
     SkAutoTDelete<SkPictureData> pictureData(SkPictureData::CreateFromBuffer(buffer, info));
     if (!pictureData) {
         return nullptr;
index dd5fd75f192a3448b9d515f43144c45b168f25eb..be2aa22d5f1908beadc4cbf7cabc95e5c45c3827 100644 (file)
@@ -57,7 +57,7 @@ int tool_main(int argc, char** argv) {
     }
 
     if (FLAGS_version && !FLAGS_quiet) {
-        SkDebugf("Version: %d\n", info.fVersion);
+        SkDebugf("Version: %d\n", info.getVersion());
     }
     if (FLAGS_cullRect && !FLAGS_quiet) {
         SkDebugf("Cull Rect: %f,%f,%f,%f\n",