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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 } |
249 | |
250 static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) { | |
251 sk_sp<SkFlattenable> drawable = IntDrawable::CreateProc(buffer); | |
252 IntDrawable* intDrawable = (IntDrawable*) drawable.get(); | |
253 return sk_sp<IntDrawable>(new IntDrawable(intDrawable->a() + 1, intDrawable-
>b() + 1, | |
254 intDrawable->c() + 1, intDrawable-
>d() + 1)); | |
255 } | |
256 | |
257 DEF_TEST(FlattenCustomDrawable, r) { | |
258 // Create and serialize the test drawable | |
259 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); | |
260 SkWriteBuffer writeBuffer; | |
261 writeBuffer.writeFlattenable(drawable); | |
262 | |
263 // Copy the contents of the write buffer into a read buffer | |
264 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); | |
265 writeBuffer.writeToMemory(data->writable_data()); | |
266 SkReadBuffer readBuffer(data->data(), data->size()); | |
267 | |
268 // Register a custom factory with the read buffer | |
269 readBuffer.setCustomFactory(SkString("IntDrawable"), &custom_create_proc); | |
270 | |
271 // Deserialize and verify the drawable | |
272 SkAutoTUnref<IntDrawable> out((IntDrawable*) | |
273 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type)); | |
274 REPORTER_ASSERT(r, out); | |
275 REPORTER_ASSERT(r, 2 == out->a()); | |
276 REPORTER_ASSERT(r, 3 == out->b()); | |
277 REPORTER_ASSERT(r, 4 == out->c()); | |
278 REPORTER_ASSERT(r, 5 == out->d()); | |
279 } | |
OLD | NEW |