Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: src/core/SkPath.cpp

Issue 1185453003: fix deserialization after FirstDirection change to paths (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPath.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBuffer.h" 8 #include "SkBuffer.h"
9 #include "SkErrorInternals.h" 9 #include "SkErrorInternals.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 if (NULL == storage) { 1854 if (NULL == storage) {
1855 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); 1855 const int byteCount = sizeof(int32_t) + fPathRef->writeSize();
1856 return SkAlign4(byteCount); 1856 return SkAlign4(byteCount);
1857 } 1857 }
1858 1858
1859 SkWBuffer buffer(storage); 1859 SkWBuffer buffer(storage);
1860 1860
1861 int32_t packed = (fConvexity << kConvexity_SerializationShift) | 1861 int32_t packed = (fConvexity << kConvexity_SerializationShift) |
1862 (fFillType << kFillType_SerializationShift) | 1862 (fFillType << kFillType_SerializationShift) |
1863 (fFirstDirection << kDirection_SerializationShift) | 1863 (fFirstDirection << kDirection_SerializationShift) |
1864 (fIsVolatile << kIsVolatile_SerializationShift); 1864 (fIsVolatile << kIsVolatile_SerializationShift) |
1865 kCurrent_Version;
1865 1866
1866 buffer.write32(packed); 1867 buffer.write32(packed);
1867 1868
1868 fPathRef->writeToBuffer(&buffer); 1869 fPathRef->writeToBuffer(&buffer);
1869 1870
1870 buffer.padToAlign4(); 1871 buffer.padToAlign4();
1871 return buffer.pos(); 1872 return buffer.pos();
1872 } 1873 }
1873 1874
1874 size_t SkPath::readFromMemory(const void* storage, size_t length) { 1875 size_t SkPath::readFromMemory(const void* storage, size_t length) {
1875 SkRBufferWithSizeCheck buffer(storage, length); 1876 SkRBufferWithSizeCheck buffer(storage, length);
1876 1877
1877 int32_t packed; 1878 int32_t packed;
1878 if (!buffer.readS32(&packed)) { 1879 if (!buffer.readS32(&packed)) {
1879 return 0; 1880 return 0;
1880 } 1881 }
1881 1882
1883 unsigned version = packed & 0xFF;
1884
1882 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; 1885 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF;
1883 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; 1886 fFillType = (packed >> kFillType_SerializationShift) & 0xFF;
1884 fFirstDirection = (packed >> kDirection_SerializationShift) & 0x3; 1887 uint8_t dir = (packed >> kDirection_SerializationShift) & 0x3;
1885 fIsVolatile = (packed >> kIsVolatile_SerializationShift) & 0x1; 1888 fIsVolatile = (packed >> kIsVolatile_SerializationShift) & 0x1;
1886 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer); 1889 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer);
1887 1890
1891 // compatibility check
1892 if (version < kPathPrivFirstDirection_Version) {
1893 switch (dir) { // old values
1894 case 0:
1895 fFirstDirection = SkPathPriv::kUnknown_FirstDirection;
1896 break;
1897 case 1:
1898 fFirstDirection = SkPathPriv::kCW_FirstDirection;
1899 break;
1900 case 2:
1901 fFirstDirection = SkPathPriv::kCCW_FirstDirection;
1902 break;
1903 default:
1904 SkASSERT(false);
1905 }
1906 } else {
1907 fFirstDirection = dir;
1908 }
1909
1888 size_t sizeRead = 0; 1910 size_t sizeRead = 0;
1889 if (buffer.isValid()) { 1911 if (buffer.isValid()) {
1890 fPathRef.reset(pathRef); 1912 fPathRef.reset(pathRef);
1891 SkDEBUGCODE(this->validate();) 1913 SkDEBUGCODE(this->validate();)
1892 buffer.skipToAlign4(); 1914 buffer.skipToAlign4();
1893 sizeRead = buffer.pos(); 1915 sizeRead = buffer.pos();
1894 } else if (pathRef) { 1916 } else if (pathRef) {
1895 // If the buffer is not valid, pathRef should be NULL 1917 // If the buffer is not valid, pathRef should be NULL
1896 sk_throw(); 1918 sk_throw();
1897 } 1919 }
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 switch (this->getFillType()) { 2809 switch (this->getFillType()) {
2788 case SkPath::kEvenOdd_FillType: 2810 case SkPath::kEvenOdd_FillType:
2789 case SkPath::kInverseEvenOdd_FillType: 2811 case SkPath::kInverseEvenOdd_FillType:
2790 w &= 1; 2812 w &= 1;
2791 break; 2813 break;
2792 default: 2814 default:
2793 break; 2815 break;
2794 } 2816 }
2795 return SkToBool(w); 2817 return SkToBool(w);
2796 } 2818 }
OLDNEW
« no previous file with comments | « include/core/SkPath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698