commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 8 | #include "Resources.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 10 | #include "SkFixed.h" |
| 11 | #include "SkFontDescriptor.h" |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 12 | #include "SkImage.h" |
| 13 | #include "SkImageSource.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 14 | #include "SkMallocPixelRef.h" |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 15 | #include "SkOSFile.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 16 | #include "SkPictureRecorder.h" |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 17 | #include "SkTableColorFilter.h" |
commit-bot@chromium.org | 1e7ee99 | 2014-03-14 21:22:22 +0000 | [diff] [blame] | 18 | #include "SkTemplates.h" |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 19 | #include "SkTypeface.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 20 | #include "SkWriteBuffer.h" |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 21 | #include "SkValidatingReadBuffer.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 22 | #include "SkXfermodeImageFilter.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 23 | #include "Test.h" |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 25 | static const uint32_t kArraySize = 64; |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 26 | static const int kBitmapSize = 256; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 27 | |
| 28 | template<typename T> |
| 29 | static void TestAlignment(T* testObj, skiatest::Reporter* reporter) { |
| 30 | // Test memory read/write functions directly |
| 31 | unsigned char dataWritten[1024]; |
| 32 | size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten); |
| 33 | REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
| 34 | size_t bytesReadFromMemory = testObj->readFromMemory(dataWritten, bytesWrittenToMemory); |
| 35 | REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
| 36 | } |
| 37 | |
| 38 | template<typename T> struct SerializationUtils { |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 39 | // Generic case for flattenables |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 40 | static void Write(SkWriteBuffer& writer, const T* flattenable) { |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 41 | writer.writeFlattenable(flattenable); |
| 42 | } |
| 43 | static void Read(SkValidatingReadBuffer& reader, T** flattenable) { |
| 44 | *flattenable = (T*)reader.readFlattenable(T::GetFlattenableType()); |
| 45 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | template<> struct SerializationUtils<SkMatrix> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 49 | static void Write(SkWriteBuffer& writer, const SkMatrix* matrix) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 50 | writer.writeMatrix(*matrix); |
| 51 | } |
| 52 | static void Read(SkValidatingReadBuffer& reader, SkMatrix* matrix) { |
| 53 | reader.readMatrix(matrix); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | template<> struct SerializationUtils<SkPath> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 58 | static void Write(SkWriteBuffer& writer, const SkPath* path) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 59 | writer.writePath(*path); |
| 60 | } |
| 61 | static void Read(SkValidatingReadBuffer& reader, SkPath* path) { |
| 62 | reader.readPath(path); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | template<> struct SerializationUtils<SkRegion> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 67 | static void Write(SkWriteBuffer& writer, const SkRegion* region) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 68 | writer.writeRegion(*region); |
| 69 | } |
| 70 | static void Read(SkValidatingReadBuffer& reader, SkRegion* region) { |
| 71 | reader.readRegion(region); |
| 72 | } |
| 73 | }; |
| 74 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 75 | template<> struct SerializationUtils<SkString> { |
| 76 | static void Write(SkWriteBuffer& writer, const SkString* string) { |
| 77 | writer.writeString(string->c_str()); |
| 78 | } |
| 79 | static void Read(SkValidatingReadBuffer& reader, SkString* string) { |
| 80 | reader.readString(string); |
| 81 | } |
| 82 | }; |
| 83 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 84 | template<> struct SerializationUtils<unsigned char> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 85 | static void Write(SkWriteBuffer& writer, unsigned char* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 86 | writer.writeByteArray(data, arraySize); |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 87 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 88 | static bool Read(SkValidatingReadBuffer& reader, unsigned char* data, uint32_t arraySize) { |
| 89 | return reader.readByteArray(data, arraySize); |
| 90 | } |
| 91 | }; |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 92 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 93 | template<> struct SerializationUtils<SkColor> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 94 | static void Write(SkWriteBuffer& writer, SkColor* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 95 | writer.writeColorArray(data, arraySize); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 96 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 97 | static bool Read(SkValidatingReadBuffer& reader, SkColor* data, uint32_t arraySize) { |
| 98 | return reader.readColorArray(data, arraySize); |
| 99 | } |
| 100 | }; |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 101 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 102 | template<> struct SerializationUtils<int32_t> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 103 | static void Write(SkWriteBuffer& writer, int32_t* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 104 | writer.writeIntArray(data, arraySize); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 105 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 106 | static bool Read(SkValidatingReadBuffer& reader, int32_t* data, uint32_t arraySize) { |
| 107 | return reader.readIntArray(data, arraySize); |
| 108 | } |
| 109 | }; |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 110 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 111 | template<> struct SerializationUtils<SkPoint> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 112 | static void Write(SkWriteBuffer& writer, SkPoint* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 113 | writer.writePointArray(data, arraySize); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 114 | } |
| 115 | static bool Read(SkValidatingReadBuffer& reader, SkPoint* data, uint32_t arraySize) { |
| 116 | return reader.readPointArray(data, arraySize); |
| 117 | } |
| 118 | }; |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 119 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 120 | template<> struct SerializationUtils<SkScalar> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 121 | static void Write(SkWriteBuffer& writer, SkScalar* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 122 | writer.writeScalarArray(data, arraySize); |
| 123 | } |
| 124 | static bool Read(SkValidatingReadBuffer& reader, SkScalar* data, uint32_t arraySize) { |
| 125 | return reader.readScalarArray(data, arraySize); |
| 126 | } |
| 127 | }; |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 128 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 129 | template<typename T, bool testInvalid> struct SerializationTestUtils { |
| 130 | static void InvalidateData(unsigned char* data) {} |
| 131 | }; |
| 132 | |
| 133 | template<> struct SerializationTestUtils<SkString, true> { |
| 134 | static void InvalidateData(unsigned char* data) { |
| 135 | data[3] |= 0x80; // Reverse sign of 1st integer |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | template<typename T, bool testInvalid> |
| 140 | static void TestObjectSerializationNoAlign(T* testObj, skiatest::Reporter* reporter) { |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 141 | SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 142 | SerializationUtils<T>::Write(writer, testObj); |
| 143 | size_t bytesWritten = writer.bytesWritten(); |
| 144 | REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 145 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 146 | unsigned char dataWritten[1024]; |
| 147 | writer.writeToMemory(dataWritten); |
| 148 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 149 | SerializationTestUtils<T, testInvalid>::InvalidateData(dataWritten); |
| 150 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 151 | // Make sure this fails when it should (test with smaller size, but still multiple of 4) |
| 152 | SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 153 | T obj; |
| 154 | SerializationUtils<T>::Read(buffer, &obj); |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 156 | |
| 157 | // Make sure this succeeds when it should |
| 158 | SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 159 | const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
| 160 | T obj2; |
| 161 | SerializationUtils<T>::Read(buffer2, &obj2); |
| 162 | const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 163 | // This should have succeeded, since there are enough bytes to read this |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 164 | REPORTER_ASSERT(reporter, buffer2.isValid() == !testInvalid); |
| 165 | // Note: This following test should always succeed, regardless of whether the buffer is valid, |
| 166 | // since if it is invalid, it will simply skip to the end, as if it had read the whole buffer. |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 167 | REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten); |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 168 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 169 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 170 | template<typename T> |
| 171 | static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) { |
| 172 | TestObjectSerializationNoAlign<T, false>(testObj, reporter); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 173 | TestAlignment(testObj, reporter); |
| 174 | } |
| 175 | |
| 176 | template<typename T> |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 177 | static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, |
| 178 | skiatest::Reporter* reporter) { |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 179 | SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 180 | SerializationUtils<T>::Write(writer, testObj); |
| 181 | size_t bytesWritten = writer.bytesWritten(); |
| 182 | REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); |
| 183 | |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 184 | unsigned char dataWritten[4096]; |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 185 | SkASSERT(bytesWritten <= sizeof(dataWritten)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 186 | writer.writeToMemory(dataWritten); |
| 187 | |
| 188 | // Make sure this fails when it should (test with smaller size, but still multiple of 4) |
| 189 | SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 190 | T* obj = nullptr; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 191 | SerializationUtils<T>::Read(buffer, &obj); |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 192 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 193 | REPORTER_ASSERT(reporter, nullptr == obj); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 194 | |
| 195 | // Make sure this succeeds when it should |
| 196 | SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
| 197 | const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 198 | T* obj2 = nullptr; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 199 | SerializationUtils<T>::Read(buffer2, &obj2); |
| 200 | const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
| 201 | if (shouldSucceed) { |
| 202 | // This should have succeeded, since there are enough bytes to read this |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, buffer2.isValid()); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 204 | REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 205 | REPORTER_ASSERT(reporter, obj2); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 206 | } else { |
| 207 | // If the deserialization was supposed to fail, make sure it did |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 208 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 209 | REPORTER_ASSERT(reporter, nullptr == obj2); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | return obj2; // Return object to perform further validity tests on it |
| 213 | } |
| 214 | |
| 215 | template<typename T> |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 216 | static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 217 | SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 218 | SerializationUtils<T>::Write(writer, data, kArraySize); |
| 219 | size_t bytesWritten = writer.bytesWritten(); |
| 220 | // This should write the length (in 4 bytes) and the array |
| 221 | REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten); |
| 222 | |
| 223 | unsigned char dataWritten[1024]; |
| 224 | writer.writeToMemory(dataWritten); |
| 225 | |
| 226 | // Make sure this fails when it should |
| 227 | SkValidatingReadBuffer buffer(dataWritten, bytesWritten); |
| 228 | T dataRead[kArraySize]; |
| 229 | bool success = SerializationUtils<T>::Read(buffer, dataRead, kArraySize / 2); |
| 230 | // This should have failed, since the provided size was too small |
| 231 | REPORTER_ASSERT(reporter, !success); |
| 232 | |
| 233 | // Make sure this succeeds when it should |
| 234 | SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
| 235 | success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize); |
| 236 | // This should have succeeded, since there are enough bytes to read this |
| 237 | REPORTER_ASSERT(reporter, success); |
| 238 | } |
| 239 | |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 240 | static void TestBitmapSerialization(const SkBitmap& validBitmap, |
| 241 | const SkBitmap& invalidBitmap, |
| 242 | bool shouldSucceed, |
| 243 | skiatest::Reporter* reporter) { |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 244 | SkAutoTUnref<SkImage> validImage(SkImage::NewFromBitmap(validBitmap)); |
| 245 | SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validImage)); |
| 246 | SkAutoTUnref<SkImage> invalidImage(SkImage::NewFromBitmap(invalidBitmap)); |
| 247 | SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invalidImage)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 248 | SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
reed | 2d6ba66 | 2015-12-20 20:08:42 -0800 | [diff] [blame^] | 249 | SkAutoTUnref<SkXfermodeImageFilter> xfermodeImageFilter( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 250 | SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSource)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 251 | |
| 252 | SkAutoTUnref<SkImageFilter> deserializedFilter( |
| 253 | TestFlattenableSerialization<SkImageFilter>( |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 254 | xfermodeImageFilter, shouldSucceed, reporter)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 255 | |
| 256 | // Try to render a small bitmap using the invalid deserialized filter |
| 257 | // to make sure we don't crash while trying to render it |
| 258 | if (shouldSucceed) { |
| 259 | SkBitmap bitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 260 | bitmap.allocN32Pixels(24, 24); |
| 261 | SkCanvas canvas(bitmap); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 262 | canvas.clear(0x00000000); |
| 263 | SkPaint paint; |
| 264 | paint.setImageFilter(deserializedFilter); |
| 265 | canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar(24))); |
| 266 | canvas.drawBitmap(bitmap, 0, 0, &paint); |
| 267 | } |
| 268 | } |
| 269 | |
senorblanco | 0f7197b | 2014-09-24 11:09:38 -0700 | [diff] [blame] | 270 | static void TestXfermodeSerialization(skiatest::Reporter* reporter) { |
| 271 | for (size_t i = 0; i <= SkXfermode::kLastMode; ++i) { |
| 272 | if (i == SkXfermode::kSrcOver_Mode) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 273 | // skip SrcOver, as it is allowed to return nullptr from Create() |
senorblanco | 0f7197b | 2014-09-24 11:09:38 -0700 | [diff] [blame] | 274 | continue; |
| 275 | } |
| 276 | SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode::Mode>(i))); |
| 277 | REPORTER_ASSERT(reporter, mode.get()); |
| 278 | SkAutoTUnref<SkXfermode> copy( |
| 279 | TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter)); |
| 280 | } |
| 281 | } |
| 282 | |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 283 | static void TestColorFilterSerialization(skiatest::Reporter* reporter) { |
| 284 | uint8_t table[256]; |
| 285 | for (int i = 0; i < 256; ++i) { |
| 286 | table[i] = (i * 41) % 256; |
| 287 | } |
| 288 | SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::Create(table)); |
| 289 | SkAutoTUnref<SkColorFilter> copy( |
| 290 | TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, reporter)); |
| 291 | } |
| 292 | |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 293 | static SkBitmap draw_picture(SkPicture& picture) { |
| 294 | SkBitmap bitmap; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 295 | bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), |
| 296 | SkScalarCeilToInt(picture.cullRect().height())); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 297 | SkCanvas canvas(bitmap); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 298 | picture.playback(&canvas); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 299 | return bitmap; |
| 300 | } |
| 301 | |
| 302 | static void compare_bitmaps(skiatest::Reporter* reporter, |
| 303 | const SkBitmap& b1, const SkBitmap& b2) { |
| 304 | REPORTER_ASSERT(reporter, b1.width() == b2.width()); |
| 305 | REPORTER_ASSERT(reporter, b1.height() == b2.height()); |
| 306 | SkAutoLockPixels autoLockPixels1(b1); |
| 307 | SkAutoLockPixels autoLockPixels2(b2); |
| 308 | |
| 309 | if ((b1.width() != b2.width()) || |
| 310 | (b1.height() != b2.height())) { |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | int pixelErrors = 0; |
| 315 | for (int y = 0; y < b2.height(); ++y) { |
| 316 | for (int x = 0; x < b2.width(); ++x) { |
| 317 | if (b1.getColor(x, y) != b2.getColor(x, y)) |
| 318 | ++pixelErrors; |
| 319 | } |
| 320 | } |
| 321 | REPORTER_ASSERT(reporter, 0 == pixelErrors); |
| 322 | } |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 323 | static void serialize_and_compare_typeface(SkTypeface* typeface, const char* text, |
| 324 | skiatest::Reporter* reporter) |
| 325 | { |
| 326 | // Create a paint with the typeface. |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 327 | SkPaint paint; |
| 328 | paint.setColor(SK_ColorGRAY); |
| 329 | paint.setTextSize(SkIntToScalar(30)); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 330 | paint.setTypeface(typeface); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 331 | |
| 332 | // Paint some text. |
| 333 | SkPictureRecorder recorder; |
| 334 | SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 335 | SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()), |
| 336 | SkIntToScalar(canvasRect.height()), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 337 | nullptr, 0); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 338 | canvas->drawColor(SK_ColorWHITE); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 339 | canvas->drawText(text, 2, 24, 32, paint); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 340 | SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 341 | |
| 342 | // Serlialize picture and create its clone from stream. |
| 343 | SkDynamicMemoryWStream stream; |
| 344 | picture->serialize(&stream); |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 345 | SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 346 | SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStream.get())); |
| 347 | |
| 348 | // Draw both original and clone picture and compare bitmaps -- they should be identical. |
| 349 | SkBitmap origBitmap = draw_picture(*picture); |
| 350 | SkBitmap destBitmap = draw_picture(*loadedPicture); |
| 351 | compare_bitmaps(reporter, origBitmap, destBitmap); |
| 352 | } |
| 353 | |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 354 | static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
| 355 | { |
| 356 | // Load typeface from file to test CreateFromFile with index. |
| 357 | SkString filename = GetResourcePath("/fonts/test.ttc"); |
| 358 | SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_str(), 1)); |
| 359 | if (!typeface) { |
| 360 | SkDebugf("Could not run fontstream test because test.ttc not found."); |
| 361 | } else { |
| 362 | serialize_and_compare_typeface(typeface, "A!", reporter); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | { |
| 367 | // Load typeface as stream to create with axis settings. |
| 368 | SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf")); |
| 369 | if (!distortable) { |
| 370 | SkDebugf("Could not run fontstream test because Distortable.ttf not found."); |
| 371 | } else { |
| 372 | SkFixed axis = SK_FixedSqrt2; |
| 373 | SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData( |
| 374 | new SkFontData(distortable.detach(), 0, &axis, 1))); |
| 375 | if (!typeface) { |
| 376 | SkDebugf("Could not run fontstream test because Distortable.ttf not created."); |
| 377 | } else { |
| 378 | serialize_and_compare_typeface(typeface, "abc", reporter); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 384 | static void setup_bitmap_for_canvas(SkBitmap* bitmap) { |
| 385 | bitmap->allocN32Pixels(kBitmapSize, kBitmapSize); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 388 | static void make_checkerboard_bitmap(SkBitmap& bitmap) { |
| 389 | setup_bitmap_for_canvas(&bitmap); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 390 | |
| 391 | SkCanvas canvas(bitmap); |
| 392 | canvas.clear(0x00000000); |
| 393 | SkPaint darkPaint; |
| 394 | darkPaint.setColor(0xFF804020); |
| 395 | SkPaint lightPaint; |
| 396 | lightPaint.setColor(0xFF244484); |
| 397 | const int i = kBitmapSize / 8; |
| 398 | const SkScalar f = SkIntToScalar(i); |
| 399 | for (int y = 0; y < kBitmapSize; y += i) { |
| 400 | for (int x = 0; x < kBitmapSize; x += i) { |
| 401 | canvas.save(); |
| 402 | canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 403 | canvas.drawRect(SkRect::MakeXYWH(0, 0, f, f), darkPaint); |
| 404 | canvas.drawRect(SkRect::MakeXYWH(f, 0, f, f), lightPaint); |
| 405 | canvas.drawRect(SkRect::MakeXYWH(0, f, f, f), lightPaint); |
| 406 | canvas.drawRect(SkRect::MakeXYWH(f, f, f, f), darkPaint); |
| 407 | canvas.restore(); |
| 408 | } |
| 409 | } |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 410 | } |
| 411 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 412 | static void draw_something(SkCanvas* canvas) { |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 413 | SkPaint paint; |
| 414 | SkBitmap bitmap; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 415 | make_checkerboard_bitmap(bitmap); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 416 | |
| 417 | canvas->save(); |
| 418 | canvas->scale(0.5f, 0.5f); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 419 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 420 | canvas->restore(); |
| 421 | |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 422 | paint.setAntiAlias(true); |
| 423 | |
| 424 | paint.setColor(SK_ColorRED); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 425 | canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/3), paint); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 426 | paint.setColor(SK_ColorBLACK); |
| 427 | paint.setTextSize(SkIntToScalar(kBitmapSize/3)); |
| 428 | canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 429 | } |
| 430 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 431 | DEF_TEST(Serialization, reporter) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 432 | // Test matrix serialization |
| 433 | { |
| 434 | SkMatrix matrix = SkMatrix::I(); |
| 435 | TestObjectSerialization(&matrix, reporter); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 436 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 437 | |
| 438 | // Test path serialization |
| 439 | { |
| 440 | SkPath path; |
| 441 | TestObjectSerialization(&path, reporter); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 442 | } |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 443 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 444 | // Test region serialization |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 445 | { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 446 | SkRegion region; |
| 447 | TestObjectSerialization(®ion, reporter); |
| 448 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 449 | |
senorblanco | 0f7197b | 2014-09-24 11:09:38 -0700 | [diff] [blame] | 450 | // Test xfermode serialization |
| 451 | { |
| 452 | TestXfermodeSerialization(reporter); |
| 453 | } |
| 454 | |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 455 | // Test color filter serialization |
| 456 | { |
| 457 | TestColorFilterSerialization(reporter); |
| 458 | } |
| 459 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 460 | // Test string serialization |
| 461 | { |
| 462 | SkString string("string"); |
| 463 | TestObjectSerializationNoAlign<SkString, false>(&string, reporter); |
| 464 | TestObjectSerializationNoAlign<SkString, true>(&string, reporter); |
| 465 | } |
| 466 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 467 | // Test rrect serialization |
| 468 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 469 | // SkRRect does not initialize anything. |
| 470 | // An uninitialized SkRRect can be serialized, |
| 471 | // but will branch on uninitialized data when deserialized. |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 472 | SkRRect rrect; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 473 | SkRect rect = SkRect::MakeXYWH(1, 2, 20, 30); |
| 474 | SkVector corners[4] = { {1, 2}, {2, 3}, {3,4}, {4,5} }; |
| 475 | rrect.setRectRadii(rect, corners); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 476 | TestAlignment(&rrect, reporter); |
| 477 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 478 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 479 | // Test readByteArray |
| 480 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 481 | unsigned char data[kArraySize] = { 1, 2, 3 }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 482 | TestArraySerialization(data, reporter); |
| 483 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 484 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 485 | // Test readColorArray |
| 486 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 487 | SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 488 | TestArraySerialization(data, reporter); |
| 489 | } |
| 490 | |
| 491 | // Test readIntArray |
| 492 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 493 | int32_t data[kArraySize] = { 1, 2, 4, 8 }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 494 | TestArraySerialization(data, reporter); |
| 495 | } |
| 496 | |
| 497 | // Test readPointArray |
| 498 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 499 | SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 500 | TestArraySerialization(data, reporter); |
| 501 | } |
| 502 | |
| 503 | // Test readScalarArray |
| 504 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 505 | SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 506 | TestArraySerialization(data, reporter); |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 507 | } |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 508 | |
| 509 | // Test invalid deserializations |
| 510 | { |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 511 | SkImageInfo info = SkImageInfo::MakeN32Premul(kBitmapSize, kBitmapSize); |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 512 | |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 513 | SkBitmap validBitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 514 | validBitmap.setInfo(info); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 515 | |
| 516 | // Create a bitmap with a really large height |
| 517 | SkBitmap invalidBitmap; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 518 | invalidBitmap.setInfo(info.makeWH(info.width(), 1000000000)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 519 | |
| 520 | // The deserialization should succeed, and the rendering shouldn't crash, |
| 521 | // even when the device fails to initialize, due to its size |
| 522 | TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 523 | } |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 524 | |
| 525 | // Test simple SkPicture serialization |
| 526 | { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 527 | SkPictureRecorder recorder; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 528 | draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), |
| 529 | SkIntToScalar(kBitmapSize), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 530 | nullptr, 0)); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 531 | SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 532 | |
| 533 | // Serialize picture |
| 534 | SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
| 535 | pict->flatten(writer); |
| 536 | size_t size = writer.bytesWritten(); |
commit-bot@chromium.org | 1e7ee99 | 2014-03-14 21:22:22 +0000 | [diff] [blame] | 537 | SkAutoTMalloc<unsigned char> data(size); |
| 538 | writer.writeToMemory(static_cast<void*>(data.get())); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 539 | |
| 540 | // Deserialize picture |
commit-bot@chromium.org | 1e7ee99 | 2014-03-14 21:22:22 +0000 | [diff] [blame] | 541 | SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
commit-bot@chromium.org | e5eee51 | 2014-03-13 16:18:49 +0000 | [diff] [blame] | 542 | SkAutoTUnref<SkPicture> readPict( |
| 543 | SkPicture::CreateFromBuffer(reader)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 544 | REPORTER_ASSERT(reporter, readPict.get()); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 545 | } |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 546 | |
| 547 | TestPictureTypefaceSerialization(reporter); |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 548 | } |