OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkAnnotationKeys.h" | 9 #include "SkAnnotationKeys.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 template<> struct SerializationUtils<SkColor> { | 97 template<> struct SerializationUtils<SkColor> { |
98 static void Write(SkWriteBuffer& writer, SkColor* data, uint32_t arraySize)
{ | 98 static void Write(SkWriteBuffer& writer, SkColor* data, uint32_t arraySize)
{ |
99 writer.writeColorArray(data, arraySize); | 99 writer.writeColorArray(data, arraySize); |
100 } | 100 } |
101 static bool Read(SkValidatingReadBuffer& reader, SkColor* data, uint32_t arr
aySize) { | 101 static bool Read(SkValidatingReadBuffer& reader, SkColor* data, uint32_t arr
aySize) { |
102 return reader.readColorArray(data, arraySize); | 102 return reader.readColorArray(data, arraySize); |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
| 106 template<> struct SerializationUtils<SkColor4f> { |
| 107 static void Write(SkWriteBuffer& writer, SkColor4f* data, uint32_t arraySize
) { |
| 108 writer.writeColor4fArray(data, arraySize); |
| 109 } |
| 110 static bool Read(SkValidatingReadBuffer& reader, SkColor4f* data, uint32_t a
rraySize) { |
| 111 return reader.readColor4fArray(data, arraySize); |
| 112 } |
| 113 }; |
| 114 |
106 template<> struct SerializationUtils<int32_t> { | 115 template<> struct SerializationUtils<int32_t> { |
107 static void Write(SkWriteBuffer& writer, int32_t* data, uint32_t arraySize)
{ | 116 static void Write(SkWriteBuffer& writer, int32_t* data, uint32_t arraySize)
{ |
108 writer.writeIntArray(data, arraySize); | 117 writer.writeIntArray(data, arraySize); |
109 } | 118 } |
110 static bool Read(SkValidatingReadBuffer& reader, int32_t* data, uint32_t arr
aySize) { | 119 static bool Read(SkValidatingReadBuffer& reader, int32_t* data, uint32_t arr
aySize) { |
111 return reader.readIntArray(data, arraySize); | 120 return reader.readIntArray(data, arraySize); |
112 } | 121 } |
113 }; | 122 }; |
114 | 123 |
115 template<> struct SerializationUtils<SkPoint> { | 124 template<> struct SerializationUtils<SkPoint> { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 226 } |
218 | 227 |
219 template<typename T> | 228 template<typename T> |
220 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { | 229 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { |
221 SkBinaryWriteBuffer writer; | 230 SkBinaryWriteBuffer writer; |
222 SerializationUtils<T>::Write(writer, data, kArraySize); | 231 SerializationUtils<T>::Write(writer, data, kArraySize); |
223 size_t bytesWritten = writer.bytesWritten(); | 232 size_t bytesWritten = writer.bytesWritten(); |
224 // This should write the length (in 4 bytes) and the array | 233 // This should write the length (in 4 bytes) and the array |
225 REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten); | 234 REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten); |
226 | 235 |
227 unsigned char dataWritten[1024]; | 236 unsigned char dataWritten[2048]; |
228 writer.writeToMemory(dataWritten); | 237 writer.writeToMemory(dataWritten); |
229 | 238 |
230 // Make sure this fails when it should | 239 // Make sure this fails when it should |
231 SkValidatingReadBuffer buffer(dataWritten, bytesWritten); | 240 SkValidatingReadBuffer buffer(dataWritten, bytesWritten); |
232 T dataRead[kArraySize]; | 241 T dataRead[kArraySize]; |
233 bool success = SerializationUtils<T>::Read(buffer, dataRead, kArraySize / 2)
; | 242 bool success = SerializationUtils<T>::Read(buffer, dataRead, kArraySize / 2)
; |
234 // This should have failed, since the provided size was too small | 243 // This should have failed, since the provided size was too small |
235 REPORTER_ASSERT(reporter, !success); | 244 REPORTER_ASSERT(reporter, !success); |
236 | 245 |
237 // Make sure this succeeds when it should | 246 // Make sure this succeeds when it should |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 unsigned char data[kArraySize] = { 1, 2, 3 }; | 495 unsigned char data[kArraySize] = { 1, 2, 3 }; |
487 TestArraySerialization(data, reporter); | 496 TestArraySerialization(data, reporter); |
488 } | 497 } |
489 | 498 |
490 // Test readColorArray | 499 // Test readColorArray |
491 { | 500 { |
492 SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }
; | 501 SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }
; |
493 TestArraySerialization(data, reporter); | 502 TestArraySerialization(data, reporter); |
494 } | 503 } |
495 | 504 |
| 505 // Test readColor4fArray |
| 506 { |
| 507 SkColor4f data[kArraySize] = { |
| 508 SkColor4f::FromColor(SK_ColorBLACK), |
| 509 SkColor4f::FromColor(SK_ColorWHITE), |
| 510 SkColor4f::FromColor(SK_ColorRED), |
| 511 { 1.f, 2.f, 4.f, 8.f } |
| 512 }; |
| 513 TestArraySerialization(data, reporter); |
| 514 } |
| 515 |
496 // Test readIntArray | 516 // Test readIntArray |
497 { | 517 { |
498 int32_t data[kArraySize] = { 1, 2, 4, 8 }; | 518 int32_t data[kArraySize] = { 1, 2, 4, 8 }; |
499 TestArraySerialization(data, reporter); | 519 TestArraySerialization(data, reporter); |
500 } | 520 } |
501 | 521 |
502 // Test readPointArray | 522 // Test readPointArray |
503 { | 523 { |
504 SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; | 524 SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; |
505 TestArraySerialization(data, reporter); | 525 TestArraySerialization(data, reporter); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) }, | 713 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) }, |
694 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) }, | 714 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) }, |
695 }; | 715 }; |
696 | 716 |
697 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); | 717 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); |
698 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); | 718 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); |
699 | 719 |
700 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); | 720 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); |
701 canvas.drawPicture(pict1); | 721 canvas.drawPicture(pict1); |
702 } | 722 } |
OLD | NEW |