Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: tests/FlattenDrawableTest.cpp

Issue 1913843002: Enable flattening of SkRecordedDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Consider registering SkRecordedDrawable without the global registry Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/core/SkReadBuffer.cpp ('K') | « src/core/SkReadBuffer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FlattenDrawableTest.cpp
diff --git a/tests/FlattenDrawableTest.cpp b/tests/FlattenDrawableTest.cpp
index dd06b410b23e168fbef305ce5af9433a4ba3ccb3..e94f4ed38650dfe0ada9fd7f86614d0d77472b89 100644
--- a/tests/FlattenDrawableTest.cpp
+++ b/tests/FlattenDrawableTest.cpp
@@ -247,6 +247,47 @@ DEF_TEST(FlattenDrawable, r) {
REPORTER_ASSERT(r, 4 == integer->d());
}
+DEF_TEST(FlattenRecordedDrawable, r) {
+ register_test_drawables_once();
+
+ // 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", 354.0f, 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());
+ readBuffer.initDrawableFactories();
djsollen 2016/04/27 13:05:40 seems awkward that I need to need to register fact
msarett 2016/04/27 13:24:17 That was original approach in Patch Sets 1 and 2.
+
+ // 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()));
+}
+
static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) {
sk_sp<SkFlattenable> drawable = IntDrawable::CreateProc(buffer);
IntDrawable* intDrawable = (IntDrawable*) drawable.get();
« src/core/SkReadBuffer.cpp ('K') | « src/core/SkReadBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698