diff options
author | msarett <msarett@google.com> | 2016-04-27 09:03:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-27 09:03:17 -0700 |
commit | d636950e8ecba89c0021ce4e76037c67aa6ee2cd (patch) | |
tree | 514b71dbcd0d6486b2f019ec60f106aff01c3a71 /tests | |
parent | f62b2354b376ef56028fde357e8a081436955581 (diff) |
Enable flattening of SkRecordedDrawable
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1913843002
Review-Url: https://codereview.chromium.org/1913843002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FlattenDrawableTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/FlattenDrawableTest.cpp b/tests/FlattenDrawableTest.cpp index c7fff12326..2132729330 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())); +} |