| Index: tests/FlattenDrawableTest.cpp
|
| diff --git a/tests/FlattenDrawableTest.cpp b/tests/FlattenDrawableTest.cpp
|
| index c7fff12326e2548c61eef954b15f42808aec13df..2132729330870905d934a399af9f0eb605b15d54 100644
|
| --- a/tests/FlattenDrawableTest.cpp
|
| +++ b/tests/FlattenDrawableTest.cpp
|
| @@ -246,3 +246,42 @@ DEF_TEST(FlattenDrawable, r) {
|
| REPORTER_ASSERT(r, 3 == integer->c());
|
| REPORTER_ASSERT(r, 4 == integer->d());
|
| }
|
| +
|
| +DEF_TEST(FlattenRecordedDrawable, r) {
|
| + // Record a set of canvas draw commands
|
| + SkPictureRecorder recorder;
|
| + SkCanvas* canvas = recorder.beginRecording(1000.0f, 1000.0f);
|
| + canvas->drawPoint(42.0f, 17.0f, SK_ColorGREEN);
|
| + SkPaint paint;
|
| + paint.setColor(SK_ColorRED);
|
| + canvas->drawPaint(paint);
|
| + SkPaint textPaint;
|
| + textPaint.setColor(SK_ColorBLUE);
|
| + canvas->drawText("TEXT", 4, 467.0f, 100.0f, textPaint);
|
| +
|
| + // Draw some drawables as well
|
| + SkAutoTUnref<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4));
|
| + SkAutoTUnref<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 11, 12, drawable));
|
| + canvas->drawDrawable(root, 747.0f, 242.0f);
|
| + SkAutoTUnref<PaintDrawable> paintDrawable(new PaintDrawable(paint));
|
| + canvas->drawDrawable(paintDrawable, 500.0, 500.0f);
|
| + SkAutoTUnref<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15, 16, textPaint));
|
| + canvas->drawDrawable(comDrawable, 10.0f, 10.0f);
|
| +
|
| + // Serialize the recorded drawable
|
| + sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable();
|
| + SkWriteBuffer writeBuffer;
|
| + writeBuffer.writeFlattenable(recordedDrawable.get());
|
| +
|
| + // Copy the contents of the write buffer into a read buffer
|
| + sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten());
|
| + writeBuffer.writeToMemory(data->writable_data());
|
| + SkReadBuffer readBuffer(data->data(), data->size());
|
| + register_test_drawables(readBuffer);
|
| +
|
| + // Deserialize and verify the drawable
|
| + SkAutoTUnref<SkDrawable> out((SkDrawable*)
|
| + readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type));
|
| + REPORTER_ASSERT(r, out);
|
| + REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName()));
|
| +}
|
|
|