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 | |
egdaniel | 4132de7 | 2016-06-15 14:28:17 -0700 | [diff] [blame] | 8 | #include "Resources.h" |
dvonbeck | 8811e40 | 2016-06-16 12:39:25 -0700 | [diff] [blame] | 9 | #include "SkAnnotationKeys.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
Khushal | 42f8bc4 | 2018-04-03 17:51:40 -0700 | [diff] [blame] | 11 | #include "SkDashPathEffect.h" |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 12 | #include "SkFixed.h" |
| 13 | #include "SkFontDescriptor.h" |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 14 | #include "SkImage.h" |
| 15 | #include "SkImageSource.h" |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 16 | #include "SkLightingShader.h" |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 17 | #include "SkMakeUnique.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 18 | #include "SkMallocPixelRef.h" |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 19 | #include "SkMatrixPriv.h" |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 20 | #include "SkNormalSource.h" |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 21 | #include "SkOSFile.h" |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 22 | #include "SkReadBuffer.h" |
Cary Clark | efd99cc | 2018-06-11 16:25:43 -0400 | [diff] [blame] | 23 | #include "SkPicturePriv.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 24 | #include "SkPictureRecorder.h" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 25 | #include "SkShaderBase.h" |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 26 | #include "SkTableColorFilter.h" |
commit-bot@chromium.org | 1e7ee99 | 2014-03-14 21:22:22 +0000 | [diff] [blame] | 27 | #include "SkTemplates.h" |
Khushal | 42f8bc4 | 2018-04-03 17:51:40 -0700 | [diff] [blame] | 28 | #include "SkTextBlob.h" |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 29 | #include "SkTypeface.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 30 | #include "SkWriteBuffer.h" |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 31 | #include "SkXfermodeImageFilter.h" |
dvonbeck | 8811e40 | 2016-06-16 12:39:25 -0700 | [diff] [blame] | 32 | #include "sk_tool_utils.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 33 | #include "Test.h" |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 34 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 35 | static const uint32_t kArraySize = 64; |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 36 | static const int kBitmapSize = 256; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 37 | |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 38 | class SerializationTest { |
| 39 | public: |
| 40 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 41 | template<typename T> |
| 42 | static void TestAlignment(T* testObj, skiatest::Reporter* reporter) { |
| 43 | // Test memory read/write functions directly |
| 44 | unsigned char dataWritten[1024]; |
| 45 | size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten); |
| 46 | REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
| 47 | size_t bytesReadFromMemory = testObj->readFromMemory(dataWritten, bytesWrittenToMemory); |
| 48 | REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
| 49 | } |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 50 | }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 51 | |
| 52 | template<typename T> struct SerializationUtils { |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 53 | // Generic case for flattenables |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 54 | static void Write(SkWriteBuffer& writer, const T* flattenable) { |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 55 | writer.writeFlattenable(flattenable); |
| 56 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 57 | static void Read(SkReadBuffer& reader, T** flattenable) { |
mtklein | 3b37545 | 2016-04-04 14:57:19 -0700 | [diff] [blame] | 58 | *flattenable = (T*)reader.readFlattenable(T::GetFlattenableType()); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 59 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | template<> struct SerializationUtils<SkMatrix> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 63 | static void Write(SkWriteBuffer& writer, const SkMatrix* matrix) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 64 | writer.writeMatrix(*matrix); |
| 65 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 66 | static void Read(SkReadBuffer& reader, SkMatrix* matrix) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 67 | reader.readMatrix(matrix); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | template<> struct SerializationUtils<SkPath> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 72 | static void Write(SkWriteBuffer& writer, const SkPath* path) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 73 | writer.writePath(*path); |
| 74 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 75 | static void Read(SkReadBuffer& reader, SkPath* path) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 76 | reader.readPath(path); |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | template<> struct SerializationUtils<SkRegion> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 81 | static void Write(SkWriteBuffer& writer, const SkRegion* region) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 82 | writer.writeRegion(*region); |
| 83 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 84 | static void Read(SkReadBuffer& reader, SkRegion* region) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 85 | reader.readRegion(region); |
| 86 | } |
| 87 | }; |
| 88 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 89 | template<> struct SerializationUtils<SkString> { |
| 90 | static void Write(SkWriteBuffer& writer, const SkString* string) { |
| 91 | writer.writeString(string->c_str()); |
| 92 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 93 | static void Read(SkReadBuffer& reader, SkString* string) { |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 94 | reader.readString(string); |
| 95 | } |
| 96 | }; |
| 97 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 98 | template<> struct SerializationUtils<unsigned char> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 99 | static void Write(SkWriteBuffer& writer, unsigned char* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 100 | writer.writeByteArray(data, arraySize); |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 101 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 102 | static bool Read(SkReadBuffer& reader, unsigned char* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 103 | return reader.readByteArray(data, arraySize); |
| 104 | } |
| 105 | }; |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 106 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 107 | template<> struct SerializationUtils<SkColor> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 108 | static void Write(SkWriteBuffer& writer, SkColor* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 109 | writer.writeColorArray(data, arraySize); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 110 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 111 | static bool Read(SkReadBuffer& reader, SkColor* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 112 | return reader.readColorArray(data, arraySize); |
| 113 | } |
| 114 | }; |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 115 | |
brianosman | 97bbf82 | 2016-09-25 13:15:58 -0700 | [diff] [blame] | 116 | template<> struct SerializationUtils<SkColor4f> { |
| 117 | static void Write(SkWriteBuffer& writer, SkColor4f* data, uint32_t arraySize) { |
| 118 | writer.writeColor4fArray(data, arraySize); |
| 119 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 120 | static bool Read(SkReadBuffer& reader, SkColor4f* data, uint32_t arraySize) { |
brianosman | 97bbf82 | 2016-09-25 13:15:58 -0700 | [diff] [blame] | 121 | return reader.readColor4fArray(data, arraySize); |
| 122 | } |
| 123 | }; |
| 124 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 125 | template<> struct SerializationUtils<int32_t> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 126 | static void Write(SkWriteBuffer& writer, int32_t* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 127 | writer.writeIntArray(data, arraySize); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 128 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 129 | static bool Read(SkReadBuffer& reader, int32_t* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 130 | return reader.readIntArray(data, arraySize); |
| 131 | } |
| 132 | }; |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 133 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 134 | template<> struct SerializationUtils<SkPoint> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 135 | static void Write(SkWriteBuffer& writer, SkPoint* data, uint32_t arraySize) { |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 136 | writer.writePointArray(data, arraySize); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 137 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 138 | static bool Read(SkReadBuffer& reader, SkPoint* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 139 | return reader.readPointArray(data, arraySize); |
| 140 | } |
| 141 | }; |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 142 | |
Michael Ludwig | ea24140 | 2018-08-22 09:26:33 -0400 | [diff] [blame] | 143 | template<> struct SerializationUtils<SkPoint3> { |
| 144 | static void Write(SkWriteBuffer& writer, const SkPoint3* data) { |
| 145 | writer.writePoint3(*data); |
| 146 | } |
| 147 | static void Read(SkReadBuffer& reader, SkPoint3* data) { |
| 148 | reader.readPoint3(data); |
| 149 | } |
| 150 | }; |
| 151 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 152 | template<> struct SerializationUtils<SkScalar> { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 153 | static void Write(SkWriteBuffer& writer, SkScalar* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 154 | writer.writeScalarArray(data, arraySize); |
| 155 | } |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 156 | static bool Read(SkReadBuffer& reader, SkScalar* data, uint32_t arraySize) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 157 | return reader.readScalarArray(data, arraySize); |
| 158 | } |
| 159 | }; |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 160 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 161 | template<typename T, bool testInvalid> struct SerializationTestUtils { |
| 162 | static void InvalidateData(unsigned char* data) {} |
| 163 | }; |
| 164 | |
| 165 | template<> struct SerializationTestUtils<SkString, true> { |
| 166 | static void InvalidateData(unsigned char* data) { |
| 167 | data[3] |= 0x80; // Reverse sign of 1st integer |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 | template<typename T, bool testInvalid> |
| 172 | static void TestObjectSerializationNoAlign(T* testObj, skiatest::Reporter* reporter) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 173 | SkBinaryWriteBuffer writer; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 174 | SerializationUtils<T>::Write(writer, testObj); |
| 175 | size_t bytesWritten = writer.bytesWritten(); |
| 176 | REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); |
reed@google.com | 12a2386 | 2013-11-04 21:35:55 +0000 | [diff] [blame] | 177 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 178 | unsigned char dataWritten[1024]; |
| 179 | writer.writeToMemory(dataWritten); |
| 180 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 181 | SerializationTestUtils<T, testInvalid>::InvalidateData(dataWritten); |
| 182 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 183 | // Make sure this fails when it should (test with smaller size, but still multiple of 4) |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 184 | SkReadBuffer buffer(dataWritten, bytesWritten - 4); |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 185 | T obj; |
| 186 | SerializationUtils<T>::Read(buffer, &obj); |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 187 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 188 | |
| 189 | // Make sure this succeeds when it should |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 190 | SkReadBuffer buffer2(dataWritten, bytesWritten); |
Robert Phillips | b252604 | 2016-09-26 09:00:36 -0400 | [diff] [blame] | 191 | size_t offsetBefore = buffer2.offset(); |
commit-bot@chromium.org | 8f457e3 | 2013-11-08 19:22:57 +0000 | [diff] [blame] | 192 | T obj2; |
| 193 | SerializationUtils<T>::Read(buffer2, &obj2); |
Robert Phillips | b252604 | 2016-09-26 09:00:36 -0400 | [diff] [blame] | 194 | size_t offsetAfter = buffer2.offset(); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 195 | // 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] | 196 | REPORTER_ASSERT(reporter, buffer2.isValid() == !testInvalid); |
| 197 | // Note: This following test should always succeed, regardless of whether the buffer is valid, |
| 198 | // since if it is invalid, it will simply skip to the end, as if it had read the whole buffer. |
Robert Phillips | b252604 | 2016-09-26 09:00:36 -0400 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, offsetAfter - offsetBefore == bytesWritten); |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 200 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 201 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 202 | template<typename T> |
| 203 | static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) { |
| 204 | TestObjectSerializationNoAlign<T, false>(testObj, reporter); |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 205 | SerializationTest::TestAlignment(testObj, reporter); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | template<typename T> |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 209 | static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, |
| 210 | skiatest::Reporter* reporter) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 211 | SkBinaryWriteBuffer writer; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 212 | SerializationUtils<T>::Write(writer, testObj); |
| 213 | size_t bytesWritten = writer.bytesWritten(); |
| 214 | REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); |
| 215 | |
dvonbeck | 8811e40 | 2016-06-16 12:39:25 -0700 | [diff] [blame] | 216 | SkASSERT(bytesWritten <= 4096); |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 217 | unsigned char dataWritten[4096]; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 218 | writer.writeToMemory(dataWritten); |
| 219 | |
| 220 | // Make sure this fails when it should (test with smaller size, but still multiple of 4) |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 221 | SkReadBuffer buffer(dataWritten, bytesWritten - 4); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 222 | T* obj = nullptr; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 223 | SerializationUtils<T>::Read(buffer, &obj); |
commit-bot@chromium.org | c2e9db3 | 2013-12-06 20:14:46 +0000 | [diff] [blame] | 224 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 225 | REPORTER_ASSERT(reporter, nullptr == obj); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 226 | |
| 227 | // Make sure this succeeds when it should |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 228 | SkReadBuffer buffer2(dataWritten, bytesWritten); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 229 | const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 230 | T* obj2 = nullptr; |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 231 | SerializationUtils<T>::Read(buffer2, &obj2); |
| 232 | const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
| 233 | if (shouldSucceed) { |
| 234 | // 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] | 235 | REPORTER_ASSERT(reporter, buffer2.isValid()); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 236 | REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 237 | REPORTER_ASSERT(reporter, obj2); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 238 | } else { |
| 239 | // 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] | 240 | REPORTER_ASSERT(reporter, !buffer.isValid()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 241 | REPORTER_ASSERT(reporter, nullptr == obj2); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | return obj2; // Return object to perform further validity tests on it |
| 245 | } |
| 246 | |
| 247 | template<typename T> |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 248 | static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 249 | SkBinaryWriteBuffer writer; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 250 | SerializationUtils<T>::Write(writer, data, kArraySize); |
| 251 | size_t bytesWritten = writer.bytesWritten(); |
| 252 | // This should write the length (in 4 bytes) and the array |
| 253 | REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten); |
| 254 | |
brianosman | 97bbf82 | 2016-09-25 13:15:58 -0700 | [diff] [blame] | 255 | unsigned char dataWritten[2048]; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 256 | writer.writeToMemory(dataWritten); |
| 257 | |
| 258 | // Make sure this fails when it should |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 259 | SkReadBuffer buffer(dataWritten, bytesWritten); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 260 | T dataRead[kArraySize]; |
| 261 | bool success = SerializationUtils<T>::Read(buffer, dataRead, kArraySize / 2); |
| 262 | // This should have failed, since the provided size was too small |
| 263 | REPORTER_ASSERT(reporter, !success); |
| 264 | |
| 265 | // Make sure this succeeds when it should |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 266 | SkReadBuffer buffer2(dataWritten, bytesWritten); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 267 | success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize); |
| 268 | // This should have succeeded, since there are enough bytes to read this |
| 269 | REPORTER_ASSERT(reporter, success); |
| 270 | } |
| 271 | |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 272 | static void TestBitmapSerialization(const SkBitmap& validBitmap, |
| 273 | const SkBitmap& invalidBitmap, |
| 274 | bool shouldSucceed, |
| 275 | skiatest::Reporter* reporter) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 276 | sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap)); |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 277 | sk_sp<SkImageFilter> validBitmapSource(SkImageSource::Make(std::move(validImage))); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 278 | sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap)); |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 279 | sk_sp<SkImageFilter> invalidBitmapSource(SkImageSource::Make(std::move(invalidImage))); |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 280 | sk_sp<SkImageFilter> xfermodeImageFilter( |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 281 | SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver, |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 282 | std::move(invalidBitmapSource), |
| 283 | std::move(validBitmapSource), nullptr)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 284 | |
Mike Reed | 5e25717 | 2016-11-01 11:22:05 -0400 | [diff] [blame] | 285 | sk_sp<SkImageFilter> deserializedFilter( |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 286 | TestFlattenableSerialization<SkImageFilter>( |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 287 | xfermodeImageFilter.get(), shouldSucceed, reporter)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 288 | |
| 289 | // Try to render a small bitmap using the invalid deserialized filter |
| 290 | // to make sure we don't crash while trying to render it |
| 291 | if (shouldSucceed) { |
| 292 | SkBitmap bitmap; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 293 | bitmap.allocN32Pixels(24, 24); |
| 294 | SkCanvas canvas(bitmap); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 295 | canvas.clear(0x00000000); |
| 296 | SkPaint paint; |
| 297 | paint.setImageFilter(deserializedFilter); |
| 298 | canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar(24))); |
| 299 | canvas.drawBitmap(bitmap, 0, 0, &paint); |
| 300 | } |
| 301 | } |
| 302 | |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 303 | static void TestColorFilterSerialization(skiatest::Reporter* reporter) { |
| 304 | uint8_t table[256]; |
| 305 | for (int i = 0; i < 256; ++i) { |
| 306 | table[i] = (i * 41) % 256; |
| 307 | } |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 308 | auto colorFilter(SkTableColorFilter::Make(table)); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 309 | sk_sp<SkColorFilter> copy( |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 310 | TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, reporter)); |
| 311 | } |
| 312 | |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 313 | static SkBitmap draw_picture(SkPicture& picture) { |
| 314 | SkBitmap bitmap; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 315 | bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 316 | SkScalarCeilToInt(picture.cullRect().height())); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 317 | SkCanvas canvas(bitmap); |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 318 | picture.playback(&canvas); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 319 | return bitmap; |
| 320 | } |
| 321 | |
| 322 | static void compare_bitmaps(skiatest::Reporter* reporter, |
| 323 | const SkBitmap& b1, const SkBitmap& b2) { |
| 324 | REPORTER_ASSERT(reporter, b1.width() == b2.width()); |
| 325 | REPORTER_ASSERT(reporter, b1.height() == b2.height()); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 326 | |
| 327 | if ((b1.width() != b2.width()) || |
| 328 | (b1.height() != b2.height())) { |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | int pixelErrors = 0; |
| 333 | for (int y = 0; y < b2.height(); ++y) { |
| 334 | for (int x = 0; x < b2.width(); ++x) { |
| 335 | if (b1.getColor(x, y) != b2.getColor(x, y)) |
| 336 | ++pixelErrors; |
| 337 | } |
| 338 | } |
| 339 | REPORTER_ASSERT(reporter, 0 == pixelErrors); |
| 340 | } |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 341 | static void serialize_and_compare_typeface(sk_sp<SkTypeface> typeface, const char* text, |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 342 | skiatest::Reporter* reporter) |
| 343 | { |
Hal Canary | 3560ea7 | 2019-01-08 13:01:58 -0500 | [diff] [blame] | 344 | // Create a font with the typeface. |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 345 | SkPaint paint; |
| 346 | paint.setColor(SK_ColorGRAY); |
Hal Canary | 3560ea7 | 2019-01-08 13:01:58 -0500 | [diff] [blame] | 347 | SkFont font(std::move(typeface), 30); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 348 | |
| 349 | // Paint some text. |
| 350 | SkPictureRecorder recorder; |
| 351 | SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 352 | SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()), |
| 353 | SkIntToScalar(canvasRect.height()), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 354 | nullptr, 0); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 355 | canvas->drawColor(SK_ColorWHITE); |
Hal Canary | 3560ea7 | 2019-01-08 13:01:58 -0500 | [diff] [blame] | 356 | canvas->drawString(text, 24, 32, font, paint); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 357 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 358 | |
| 359 | // Serlialize picture and create its clone from stream. |
| 360 | SkDynamicMemoryWStream stream; |
| 361 | picture->serialize(&stream); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 362 | std::unique_ptr<SkStream> inputStream(stream.detachAsStream()); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 363 | sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get())); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 364 | |
| 365 | // Draw both original and clone picture and compare bitmaps -- they should be identical. |
| 366 | SkBitmap origBitmap = draw_picture(*picture); |
| 367 | SkBitmap destBitmap = draw_picture(*loadedPicture); |
| 368 | compare_bitmaps(reporter, origBitmap, destBitmap); |
| 369 | } |
| 370 | |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 371 | static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { |
| 372 | { |
| 373 | // Load typeface from file to test CreateFromFile with index. |
Mike Reed | 271d1d9 | 2018-09-03 21:10:10 -0400 | [diff] [blame] | 374 | auto typeface = MakeResourceAsTypeface("fonts/test.ttc", 1); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 375 | if (!typeface) { |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 376 | INFOF(reporter, "Could not run fontstream test because test.ttc not found."); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 377 | } else { |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 378 | serialize_and_compare_typeface(std::move(typeface), "A!", reporter); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | { |
| 383 | // Load typeface as stream to create with axis settings. |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 384 | std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("fonts/Distortable.ttf")); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 385 | if (!distortable) { |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 386 | INFOF(reporter, "Could not run fontstream test because Distortable.ttf not found."); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 387 | } else { |
| 388 | SkFixed axis = SK_FixedSqrt2; |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 389 | sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData( |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 390 | skstd::make_unique<SkFontData>(std::move(distortable), 0, &axis, 1))); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 391 | if (!typeface) { |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 392 | INFOF(reporter, "Could not run fontstream test because Distortable.ttf not created."); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 393 | } else { |
Hal Canary | 3560ea7 | 2019-01-08 13:01:58 -0500 | [diff] [blame] | 394 | serialize_and_compare_typeface(std::move(typeface), "ab", reporter); |
bungeman | 41868fe | 2015-05-20 09:21:04 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 400 | static void setup_bitmap_for_canvas(SkBitmap* bitmap) { |
| 401 | bitmap->allocN32Pixels(kBitmapSize, kBitmapSize); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 402 | } |
| 403 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 404 | static void make_checkerboard_bitmap(SkBitmap& bitmap) { |
| 405 | setup_bitmap_for_canvas(&bitmap); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 406 | |
| 407 | SkCanvas canvas(bitmap); |
| 408 | canvas.clear(0x00000000); |
| 409 | SkPaint darkPaint; |
| 410 | darkPaint.setColor(0xFF804020); |
| 411 | SkPaint lightPaint; |
| 412 | lightPaint.setColor(0xFF244484); |
| 413 | const int i = kBitmapSize / 8; |
| 414 | const SkScalar f = SkIntToScalar(i); |
| 415 | for (int y = 0; y < kBitmapSize; y += i) { |
| 416 | for (int x = 0; x < kBitmapSize; x += i) { |
| 417 | canvas.save(); |
| 418 | canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 419 | canvas.drawRect(SkRect::MakeXYWH(0, 0, f, f), darkPaint); |
| 420 | canvas.drawRect(SkRect::MakeXYWH(f, 0, f, f), lightPaint); |
| 421 | canvas.drawRect(SkRect::MakeXYWH(0, f, f, f), lightPaint); |
| 422 | canvas.drawRect(SkRect::MakeXYWH(f, f, f, f), darkPaint); |
| 423 | canvas.restore(); |
| 424 | } |
| 425 | } |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 426 | } |
| 427 | |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 428 | static void draw_something(SkCanvas* canvas) { |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 429 | SkPaint paint; |
| 430 | SkBitmap bitmap; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 431 | make_checkerboard_bitmap(bitmap); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 432 | |
| 433 | canvas->save(); |
| 434 | canvas->scale(0.5f, 0.5f); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 435 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 436 | canvas->restore(); |
| 437 | |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 438 | paint.setAntiAlias(true); |
| 439 | |
| 440 | paint.setColor(SK_ColorRED); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 441 | 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] | 442 | paint.setColor(SK_ColorBLACK); |
Mike Reed | 1af9b48 | 2019-01-07 11:01:57 -0500 | [diff] [blame] | 443 | |
| 444 | SkFont font; |
| 445 | font.setSize(kBitmapSize/3); |
| 446 | canvas->drawString("Picture", SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), font, paint); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 447 | } |
| 448 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 449 | DEF_TEST(Serialization, reporter) { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 450 | // Test matrix serialization |
| 451 | { |
| 452 | SkMatrix matrix = SkMatrix::I(); |
| 453 | TestObjectSerialization(&matrix, reporter); |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 454 | } |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 455 | |
Michael Ludwig | ea24140 | 2018-08-22 09:26:33 -0400 | [diff] [blame] | 456 | // Test point3 serialization |
| 457 | { |
| 458 | SkPoint3 point; |
| 459 | TestObjectSerializationNoAlign<SkPoint3, false>(&point, reporter); |
| 460 | } |
| 461 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 462 | // Test path serialization |
| 463 | { |
| 464 | SkPath path; |
| 465 | TestObjectSerialization(&path, reporter); |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 466 | } |
sugoi@google.com | 305f78e | 2013-11-04 16:18:15 +0000 | [diff] [blame] | 467 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 468 | // Test region serialization |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 469 | { |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 470 | SkRegion region; |
| 471 | TestObjectSerialization(®ion, reporter); |
| 472 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 473 | |
senorblanco | 91c395a | 2014-09-25 15:51:35 -0700 | [diff] [blame] | 474 | // Test color filter serialization |
| 475 | { |
| 476 | TestColorFilterSerialization(reporter); |
| 477 | } |
| 478 | |
commit-bot@chromium.org | 1ac99c8 | 2014-04-29 15:35:23 +0000 | [diff] [blame] | 479 | // Test string serialization |
| 480 | { |
| 481 | SkString string("string"); |
| 482 | TestObjectSerializationNoAlign<SkString, false>(&string, reporter); |
| 483 | TestObjectSerializationNoAlign<SkString, true>(&string, reporter); |
| 484 | } |
| 485 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 486 | // Test rrect serialization |
| 487 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 488 | // SkRRect does not initialize anything. |
| 489 | // An uninitialized SkRRect can be serialized, |
| 490 | // but will branch on uninitialized data when deserialized. |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 491 | SkRRect rrect; |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 492 | SkRect rect = SkRect::MakeXYWH(1, 2, 20, 30); |
| 493 | SkVector corners[4] = { {1, 2}, {2, 3}, {3,4}, {4,5} }; |
| 494 | rrect.setRectRadii(rect, corners); |
Cary Clark | 6d6d603 | 2017-10-20 12:14:33 -0400 | [diff] [blame] | 495 | SerializationTest::TestAlignment(&rrect, reporter); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 496 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 497 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 498 | // Test readByteArray |
| 499 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 500 | unsigned char data[kArraySize] = { 1, 2, 3 }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 501 | TestArraySerialization(data, reporter); |
| 502 | } |
sugoi@google.com | b48a59a | 2013-11-04 20:28:23 +0000 | [diff] [blame] | 503 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 504 | // Test readColorArray |
| 505 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 506 | SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 507 | TestArraySerialization(data, reporter); |
| 508 | } |
| 509 | |
brianosman | 97bbf82 | 2016-09-25 13:15:58 -0700 | [diff] [blame] | 510 | // Test readColor4fArray |
| 511 | { |
| 512 | SkColor4f data[kArraySize] = { |
| 513 | SkColor4f::FromColor(SK_ColorBLACK), |
| 514 | SkColor4f::FromColor(SK_ColorWHITE), |
| 515 | SkColor4f::FromColor(SK_ColorRED), |
| 516 | { 1.f, 2.f, 4.f, 8.f } |
| 517 | }; |
| 518 | TestArraySerialization(data, reporter); |
| 519 | } |
| 520 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 521 | // Test readIntArray |
| 522 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 523 | int32_t data[kArraySize] = { 1, 2, 4, 8 }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 524 | TestArraySerialization(data, reporter); |
| 525 | } |
| 526 | |
| 527 | // Test readPointArray |
| 528 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 529 | SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 530 | TestArraySerialization(data, reporter); |
| 531 | } |
| 532 | |
| 533 | // Test readScalarArray |
| 534 | { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 535 | SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 536 | TestArraySerialization(data, reporter); |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 537 | } |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 538 | |
| 539 | // Test invalid deserializations |
| 540 | { |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 541 | SkImageInfo info = SkImageInfo::MakeN32Premul(kBitmapSize, kBitmapSize); |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 542 | |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 543 | SkBitmap validBitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 544 | validBitmap.setInfo(info); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 545 | |
| 546 | // Create a bitmap with a really large height |
| 547 | SkBitmap invalidBitmap; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 548 | invalidBitmap.setInfo(info.makeWH(info.width(), 1000000000)); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 549 | |
| 550 | // The deserialization should succeed, and the rendering shouldn't crash, |
| 551 | // even when the device fails to initialize, due to its size |
| 552 | TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 553 | } |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 554 | |
| 555 | // Test simple SkPicture serialization |
| 556 | { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 557 | SkPictureRecorder recorder; |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 558 | draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), |
| 559 | SkIntToScalar(kBitmapSize), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 560 | nullptr, 0)); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 561 | sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 562 | |
| 563 | // Serialize picture |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 564 | SkBinaryWriteBuffer writer; |
Cary Clark | efd99cc | 2018-06-11 16:25:43 -0400 | [diff] [blame] | 565 | SkPicturePriv::Flatten(pict, writer); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 566 | size_t size = writer.bytesWritten(); |
commit-bot@chromium.org | 1e7ee99 | 2014-03-14 21:22:22 +0000 | [diff] [blame] | 567 | SkAutoTMalloc<unsigned char> data(size); |
| 568 | writer.writeToMemory(static_cast<void*>(data.get())); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 569 | |
| 570 | // Deserialize picture |
Mike Reed | fadbfcd | 2017-12-06 16:09:20 -0500 | [diff] [blame] | 571 | SkReadBuffer reader(static_cast<void*>(data.get()), size); |
Cary Clark | efd99cc | 2018-06-11 16:25:43 -0400 | [diff] [blame] | 572 | sk_sp<SkPicture> readPict(SkPicturePriv::MakeFromBuffer(reader)); |
reed | d921dbb | 2016-09-30 09:27:20 -0700 | [diff] [blame] | 573 | REPORTER_ASSERT(reporter, reader.isValid()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 574 | REPORTER_ASSERT(reporter, readPict.get()); |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 575 | } |
caseq | 26337e9 | 2014-06-30 12:14:52 -0700 | [diff] [blame] | 576 | |
| 577 | TestPictureTypefaceSerialization(reporter); |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 578 | |
| 579 | // Test SkLightingShader/NormalMapSource serialization |
| 580 | { |
| 581 | const int kTexSize = 2; |
| 582 | |
| 583 | SkLights::Builder builder; |
| 584 | |
| 585 | builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f), |
| 586 | SkVector3::Make(1.0f, 0.0f, 0.0f))); |
| 587 | builder.setAmbientLightColor(SkColor3f::Make(0.2f, 0.2f, 0.2f)); |
| 588 | |
| 589 | sk_sp<SkLights> fLights = builder.finish(); |
| 590 | |
| 591 | SkBitmap diffuse = sk_tool_utils::create_checkerboard_bitmap( |
| 592 | kTexSize, kTexSize, |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 593 | 0x00000000, |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 594 | sk_tool_utils::color_to_565(0xFF804020), |
| 595 | 8); |
| 596 | |
| 597 | SkRect bitmapBounds = SkRect::MakeIWH(diffuse.width(), diffuse.height()); |
| 598 | |
| 599 | SkMatrix matrix; |
| 600 | SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)); |
| 601 | matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); |
| 602 | |
| 603 | SkMatrix ctm; |
| 604 | ctm.setRotate(45); |
| 605 | SkBitmap normals; |
| 606 | normals.allocN32Pixels(kTexSize, kTexSize); |
| 607 | |
| 608 | sk_tool_utils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexSize, kTexSize)); |
| 609 | sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(normals, SkShader::kClamp_TileMode, |
| 610 | SkShader::kClamp_TileMode, &matrix); |
| 611 | sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), |
| 612 | ctm); |
| 613 | sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(diffuse, |
| 614 | SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix); |
| 615 | |
| 616 | sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuseShader, |
| 617 | normalSource, |
| 618 | fLights); |
| 619 | sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter)); |
| 620 | |
| 621 | lightingShader = SkLightingShader::Make(std::move(diffuseShader), |
| 622 | nullptr, |
| 623 | fLights); |
| 624 | sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter)); |
| 625 | |
| 626 | lightingShader = SkLightingShader::Make(nullptr, |
| 627 | std::move(normalSource), |
| 628 | fLights); |
| 629 | sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter)); |
| 630 | |
| 631 | lightingShader = SkLightingShader::Make(nullptr, |
| 632 | nullptr, |
| 633 | fLights); |
| 634 | sk_sp<SkShader>(TestFlattenableSerialization(as_SB(lightingShader.get()), true, reporter)); |
| 635 | } |
commit-bot@chromium.org | 0251288 | 2013-10-31 18:37:50 +0000 | [diff] [blame] | 636 | } |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 637 | |
| 638 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 639 | #include "SkAnnotation.h" |
| 640 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 641 | static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) { |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 642 | SkDynamicMemoryWStream wstream; |
| 643 | src->serialize(&wstream); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 644 | std::unique_ptr<SkStreamAsset> rstream(wstream.detachAsStream()); |
| 645 | return SkPicture::MakeFromStream(rstream.get()); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | struct AnnotationRec { |
| 649 | const SkRect fRect; |
| 650 | const char* fKey; |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 651 | sk_sp<SkData> fValue; |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 652 | }; |
| 653 | |
| 654 | class TestAnnotationCanvas : public SkCanvas { |
| 655 | skiatest::Reporter* fReporter; |
| 656 | const AnnotationRec* fRec; |
| 657 | int fCount; |
| 658 | int fCurrIndex; |
| 659 | |
| 660 | public: |
| 661 | TestAnnotationCanvas(skiatest::Reporter* reporter, const AnnotationRec rec[], int count) |
| 662 | : SkCanvas(100, 100) |
| 663 | , fReporter(reporter) |
| 664 | , fRec(rec) |
| 665 | , fCount(count) |
| 666 | , fCurrIndex(0) |
| 667 | {} |
| 668 | |
| 669 | ~TestAnnotationCanvas() { |
| 670 | REPORTER_ASSERT(fReporter, fCount == fCurrIndex); |
| 671 | } |
| 672 | |
| 673 | protected: |
| 674 | void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
| 675 | REPORTER_ASSERT(fReporter, fCurrIndex < fCount); |
| 676 | REPORTER_ASSERT(fReporter, rect == fRec[fCurrIndex].fRect); |
| 677 | REPORTER_ASSERT(fReporter, !strcmp(key, fRec[fCurrIndex].fKey)); |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 678 | REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue.get())); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 679 | fCurrIndex += 1; |
| 680 | } |
| 681 | }; |
| 682 | |
| 683 | /* |
| 684 | * Test the 3 annotation types by recording them into a picture, serializing, and then playing |
| 685 | * them back into another canvas. |
| 686 | */ |
| 687 | DEF_TEST(Annotations, reporter) { |
| 688 | SkPictureRecorder recorder; |
| 689 | SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100)); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 690 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 691 | const char* str0 = "rect-with-url"; |
| 692 | const SkRect r0 = SkRect::MakeWH(10, 10); |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 693 | sk_sp<SkData> d0(SkData::MakeWithCString(str0)); |
| 694 | SkAnnotateRectWithURL(recordingCanvas, r0, d0.get()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 695 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 696 | const char* str1 = "named-destination"; |
| 697 | const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 698 | sk_sp<SkData> d1(SkData::MakeWithCString(str1)); |
| 699 | SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1.get()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 700 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 701 | const char* str2 = "link-to-destination"; |
| 702 | const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6); |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 703 | sk_sp<SkData> d2(SkData::MakeWithCString(str2)); |
| 704 | SkAnnotateLinkToDestination(recordingCanvas, r2, d2.get()); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 705 | |
| 706 | const AnnotationRec recs[] = { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 707 | { r0, SkAnnotationKeys::URL_Key(), std::move(d0) }, |
| 708 | { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) }, |
| 709 | { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) }, |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 710 | }; |
| 711 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 712 | sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); |
| 713 | sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 714 | |
| 715 | TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); |
| 716 | canvas.drawPicture(pict1); |
| 717 | } |
Mike Reed | 2532584 | 2018-03-14 09:52:02 -0400 | [diff] [blame] | 718 | |
| 719 | DEF_TEST(WriteBuffer_storage, reporter) { |
| 720 | enum { |
| 721 | kSize = 32 |
| 722 | }; |
| 723 | int32_t storage[kSize/4]; |
| 724 | char src[kSize]; |
| 725 | sk_bzero(src, kSize); |
| 726 | |
| 727 | SkBinaryWriteBuffer writer(storage, kSize); |
| 728 | REPORTER_ASSERT(reporter, writer.usingInitialStorage()); |
| 729 | REPORTER_ASSERT(reporter, writer.bytesWritten() == 0); |
| 730 | writer.write(src, kSize - 4); |
| 731 | REPORTER_ASSERT(reporter, writer.usingInitialStorage()); |
| 732 | REPORTER_ASSERT(reporter, writer.bytesWritten() == kSize - 4); |
| 733 | writer.writeInt(0); |
| 734 | REPORTER_ASSERT(reporter, writer.usingInitialStorage()); |
| 735 | REPORTER_ASSERT(reporter, writer.bytesWritten() == kSize); |
| 736 | |
| 737 | writer.reset(storage, kSize-4); |
| 738 | REPORTER_ASSERT(reporter, writer.usingInitialStorage()); |
| 739 | REPORTER_ASSERT(reporter, writer.bytesWritten() == 0); |
| 740 | writer.write(src, kSize - 4); |
| 741 | REPORTER_ASSERT(reporter, writer.usingInitialStorage()); |
| 742 | REPORTER_ASSERT(reporter, writer.bytesWritten() == kSize - 4); |
| 743 | writer.writeInt(0); |
| 744 | REPORTER_ASSERT(reporter, !writer.usingInitialStorage()); // this is the change |
| 745 | REPORTER_ASSERT(reporter, writer.bytesWritten() == kSize); |
| 746 | } |
Khushal | 42f8bc4 | 2018-04-03 17:51:40 -0700 | [diff] [blame] | 747 | |
| 748 | DEF_TEST(WriteBuffer_external_memory_textblob, reporter) { |
Mike Reed | 2ed7820 | 2018-11-21 15:10:08 -0500 | [diff] [blame] | 749 | SkFont font; |
Khushal | 42f8bc4 | 2018-04-03 17:51:40 -0700 | [diff] [blame] | 750 | font.setTypeface(SkTypeface::MakeDefault()); |
| 751 | |
| 752 | SkTextBlobBuilder builder; |
| 753 | int glyph_count = 5; |
| 754 | const auto& run = builder.allocRun(font, glyph_count, 1.2f, 2.3f); |
| 755 | // allocRun() allocates only the glyph buffer. |
| 756 | std::fill(run.glyphs, run.glyphs + glyph_count, 0); |
| 757 | auto blob = builder.make(); |
| 758 | SkSerialProcs procs; |
| 759 | SkAutoTMalloc<uint8_t> storage; |
| 760 | size_t blob_size = 0u; |
| 761 | size_t storage_size = 0u; |
| 762 | |
| 763 | blob_size = SkAlign4(blob->serialize(procs)->size()); |
| 764 | REPORTER_ASSERT(reporter, blob_size > 4u); |
| 765 | storage_size = blob_size - 4; |
| 766 | storage.realloc(storage_size); |
| 767 | REPORTER_ASSERT(reporter, blob->serialize(procs, storage.get(), storage_size) == 0u); |
| 768 | storage_size = blob_size; |
| 769 | storage.realloc(storage_size); |
| 770 | REPORTER_ASSERT(reporter, blob->serialize(procs, storage.get(), storage_size) != 0u); |
| 771 | } |
| 772 | |
| 773 | DEF_TEST(WriteBuffer_external_memory_flattenable, reporter) { |
| 774 | SkScalar intervals[] = {1.f, 1.f}; |
| 775 | auto path_effect = SkDashPathEffect::Make(intervals, 2, 0); |
| 776 | size_t path_size = SkAlign4(path_effect->serialize()->size()); |
| 777 | REPORTER_ASSERT(reporter, path_size > 4u); |
| 778 | SkAutoTMalloc<uint8_t> storage; |
| 779 | |
| 780 | size_t storage_size = path_size - 4; |
| 781 | storage.realloc(storage_size); |
| 782 | REPORTER_ASSERT(reporter, path_effect->serialize(storage.get(), storage_size) == 0u); |
| 783 | |
| 784 | storage_size = path_size; |
| 785 | storage.realloc(storage_size); |
| 786 | REPORTER_ASSERT(reporter, path_effect->serialize(storage.get(), storage_size) != 0u); |
| 787 | } |