OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDrawable.h" | 9 #include "SkDrawable.h" |
10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 buffer.setCustomFactory(SkString("CompoundDrawable"), CompoundDrawable::Crea
teProc); | 203 buffer.setCustomFactory(SkString("CompoundDrawable"), CompoundDrawable::Crea
teProc); |
204 buffer.setCustomFactory(SkString("RootDrawable"), RootDrawable::CreateProc); | 204 buffer.setCustomFactory(SkString("RootDrawable"), RootDrawable::CreateProc); |
205 } | 205 } |
206 | 206 |
207 DEF_TEST(FlattenDrawable, r) { | 207 DEF_TEST(FlattenDrawable, r) { |
208 // Create and serialize the test drawable | 208 // Create and serialize the test drawable |
209 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); | 209 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); |
210 SkPaint paint; | 210 SkPaint paint; |
211 paint.setColor(SK_ColorBLUE); | 211 paint.setColor(SK_ColorBLUE); |
212 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1
1, 12, drawable)); | 212 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1
1, 12, drawable)); |
213 SkWriteBuffer writeBuffer; | 213 SkBinaryWriteBuffer writeBuffer; |
214 writeBuffer.writeFlattenable(root); | 214 writeBuffer.writeFlattenable(root); |
215 | 215 |
216 // Copy the contents of the write buffer into a read buffer | 216 // Copy the contents of the write buffer into a read buffer |
217 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); | 217 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); |
218 writeBuffer.writeToMemory(data->writable_data()); | 218 writeBuffer.writeToMemory(data->writable_data()); |
219 SkReadBuffer readBuffer(data->data(), data->size()); | 219 SkReadBuffer readBuffer(data->data(), data->size()); |
220 register_test_drawables(readBuffer); | 220 register_test_drawables(readBuffer); |
221 | 221 |
222 // Deserialize and verify the drawable | 222 // Deserialize and verify the drawable |
223 SkAutoTUnref<SkDrawable> out((SkDrawable*) | 223 SkAutoTUnref<SkDrawable> out((SkDrawable*) |
(...skipping 15 matching lines...) Expand all Loading... |
239 | 239 |
240 // Note that we can still recognize the generic drawable as an IntDrawable | 240 // Note that we can still recognize the generic drawable as an IntDrawable |
241 SkDrawable* generic = rootOut->drawable(); | 241 SkDrawable* generic = rootOut->drawable(); |
242 REPORTER_ASSERT(r, !strcmp("IntDrawable", generic->getTypeName())); | 242 REPORTER_ASSERT(r, !strcmp("IntDrawable", generic->getTypeName())); |
243 IntDrawable* integer = (IntDrawable*) generic; | 243 IntDrawable* integer = (IntDrawable*) generic; |
244 REPORTER_ASSERT(r, 1 == integer->a()); | 244 REPORTER_ASSERT(r, 1 == integer->a()); |
245 REPORTER_ASSERT(r, 2 == integer->b()); | 245 REPORTER_ASSERT(r, 2 == integer->b()); |
246 REPORTER_ASSERT(r, 3 == integer->c()); | 246 REPORTER_ASSERT(r, 3 == integer->c()); |
247 REPORTER_ASSERT(r, 4 == integer->d()); | 247 REPORTER_ASSERT(r, 4 == integer->d()); |
248 } | 248 } |
OLD | NEW |