| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); | 263 SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4)); |
| 264 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1
1, 12, drawable)); | 264 SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 1
1, 12, drawable)); |
| 265 canvas->drawDrawable(root, 747.0f, 242.0f); | 265 canvas->drawDrawable(root, 747.0f, 242.0f); |
| 266 SkAutoTUnref<PaintDrawable> paintDrawable(new PaintDrawable(paint)); | 266 SkAutoTUnref<PaintDrawable> paintDrawable(new PaintDrawable(paint)); |
| 267 canvas->drawDrawable(paintDrawable, 500.0, 500.0f); | 267 canvas->drawDrawable(paintDrawable, 500.0, 500.0f); |
| 268 SkAutoTUnref<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15,
16, textPaint)); | 268 SkAutoTUnref<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15,
16, textPaint)); |
| 269 canvas->drawDrawable(comDrawable, 10.0f, 10.0f); | 269 canvas->drawDrawable(comDrawable, 10.0f, 10.0f); |
| 270 | 270 |
| 271 // Serialize the recorded drawable | 271 // Serialize the recorded drawable |
| 272 sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable(); | 272 sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable(); |
| 273 SkWriteBuffer writeBuffer; | 273 SkBinaryWriteBuffer writeBuffer; |
| 274 writeBuffer.writeFlattenable(recordedDrawable.get()); | 274 writeBuffer.writeFlattenable(recordedDrawable.get()); |
| 275 | 275 |
| 276 // Copy the contents of the write buffer into a read buffer | 276 // Copy the contents of the write buffer into a read buffer |
| 277 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); | 277 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); |
| 278 writeBuffer.writeToMemory(data->writable_data()); | 278 writeBuffer.writeToMemory(data->writable_data()); |
| 279 SkReadBuffer readBuffer(data->data(), data->size()); | 279 SkReadBuffer readBuffer(data->data(), data->size()); |
| 280 register_test_drawables(readBuffer); | 280 register_test_drawables(readBuffer); |
| 281 | 281 |
| 282 // Deserialize and verify the drawable | 282 // Deserialize and verify the drawable |
| 283 SkAutoTUnref<SkDrawable> out((SkDrawable*) | 283 SkAutoTUnref<SkDrawable> out((SkDrawable*) |
| 284 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type)); | 284 readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type)); |
| 285 REPORTER_ASSERT(r, out); | 285 REPORTER_ASSERT(r, out); |
| 286 REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName())); | 286 REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName())); |
| 287 } | 287 } |
| OLD | NEW |