Make SkPictures valid regardless of SK_SUPPORT_HINTING_SCALE_FACTOR.
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 9 Oct 2012 20:02:20 +0000 (20:02 +0000)
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 9 Oct 2012 20:02:20 +0000 (20:02 +0000)
When the build flag is not set, read/write dummy values
so that the creator of an SKP file need not have the same
support/lack of support of the feature as the reader.

Will separately update the checked in skps to the new version when checking in.

BUG=http://code.google.com/p/skia/issues/detail?id=922

Review URL: https://codereview.appspot.com/6642057

git-svn-id: http://skia.googlecode.com/svn/trunk@5869 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkPaint.cpp
src/core/SkPicture.cpp

index f611e6d..58a8c1c 100644 (file)
@@ -1897,18 +1897,14 @@ enum FlatFlags {
 };
 
 // The size of a flat paint's POD fields
+// Include an SkScalar for hinting scale factor whether it is
+// supported or not so that an SKP is valid whether it was
+// created with support or not.
 
-#ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
 static const uint32_t kPODPaintSize =   6 * sizeof(SkScalar) +
                                         1 * sizeof(SkColor) +
                                         1 * sizeof(uint16_t) +
                                         6 * sizeof(uint8_t);
-#else
-static const uint32_t kPODPaintSize =   5 * sizeof(SkScalar) +
-                                        1 * sizeof(SkColor) +
-                                        1 * sizeof(uint16_t) +
-                                        6 * sizeof(uint8_t);
-#endif
 
 /*  To save space/time, we analyze the paint, and write a truncated version of
     it if there are not tricky elements like shaders, etc.
@@ -1940,6 +1936,9 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
         ptr = write_scalar(ptr, this->getTextSkewX());
 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
         ptr = write_scalar(ptr, this->getHintingScaleFactor());
+#else
+        // Dummy value.
+        ptr = write_scalar(ptr, SK_Scalar1);
 #endif
         ptr = write_scalar(ptr, this->getStrokeWidth());
         ptr = write_scalar(ptr, this->getStrokeMiter());
@@ -1959,6 +1958,9 @@ void SkPaint::flatten(SkFlattenableWriteBuffer& buffer) const {
         buffer.writeScalar(fTextSkewX);
 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
         buffer.writeScalar(fHintingScaleFactor);
+#else
+        // Dummy value.
+        buffer.writeScalar(SK_Scalar1);
 #endif
         buffer.writeScalar(fWidth);
         buffer.writeScalar(fMiterLimit);
@@ -2007,6 +2009,9 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
         this->setTextSkewX(read_scalar(pod));
 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
         this->setHintingScaleFactor(read_scalar(pod));
+#else
+        // Skip the hinting scalar factor, which is not supported.
+        read_scalar(pod);
 #endif
         this->setStrokeWidth(read_scalar(pod));
         this->setStrokeMiter(read_scalar(pod));
@@ -2036,6 +2041,9 @@ void SkPaint::unflatten(SkFlattenableReadBuffer& buffer) {
         this->setTextSkewX(buffer.readScalar());
 #ifdef SK_SUPPORT_HINTING_SCALE_FACTOR
         this->setHintingScaleFactor(buffer.readScalar());
+#else
+        // Skip the hinting scalar factor, which is not supported.
+        buffer.readScalar();
 #endif
         this->setStrokeWidth(buffer.readScalar());
         this->setStrokeMiter(buffer.readScalar());
index 3e356ce..cc73bda 100644 (file)
@@ -243,8 +243,10 @@ void SkPicture::draw(SkCanvas* surface) {
 // V5 : don't read/write FunctionPtr on cross-process (we can detect that)
 // V6 : added serialization of SkPath's bounds (and packed its flags tighter)
 // V7 : changed drawBitmapRect(IRect) to drawBitmapRectToRect(Rect)
-// V8 : PNG encode bitmaps
-#define PICTURE_VERSION     8
+// V8 : Add an option for encoding bitmaps
+// V9 : Allow the reader and writer of an SKP disagree on whether to support
+//      SK_SUPPORT_HINTING_SCALE_FACTOR
+#define PICTURE_VERSION     9
 
 SkPicture::SkPicture(SkStream* stream, bool* success, SkSerializationHelpers::DecodeBitmap decoder) : SkRefCnt() {
     if (success) {