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

Unified Diff: src/core/SkReadBuffer.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
Index: src/core/SkReadBuffer.cpp
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp
index 70b0d13a40dfe627946b3b792c686092474db429..5110af9845adc8dfb2ab2daf9cf08877d72680cc 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -9,6 +9,10 @@
#include "SkErrorInternals.h"
#include "SkImage.h"
#include "SkImageGenerator.h"
+#include "SkPictureData.h"
+#include "SkPicturePlayback.h"
+#include "SkPictureRecord.h"
+#include "SkPictureRecorder.h"
#include "SkReadBuffer.h"
#include "SkStream.h"
#include "SkTypeface.h"
@@ -419,3 +423,27 @@ void SkReadBuffer::skipFlattenable() {
uint32_t sizeRecorded = fReader.readU32();
fReader.skip(sizeRecorded);
}
+
+static sk_sp<SkFlattenable> unflatten_recorded_drawable(SkReadBuffer& buffer) {
msarett 2016/04/25 16:40:38 Maybe this function belongs in a different file?
+ // Read the bounds.
+ SkRect bounds;
+ buffer.readRect(&bounds);
+
+ // Unflatten into a SkPictureData.
+ SkPictInfo info;
+ info.fCullRect = bounds;
+ SkAutoTDelete<SkPictureData> pictureData(SkPictureData::CreateFromBuffer(buffer, info));
+ if (!pictureData) {
+ return nullptr;
+ }
+
+ // Create a drawable.
+ SkPicturePlayback playback(pictureData);
+ SkPictureRecorder recorder;
+ playback.draw(recorder.beginRecording(bounds), nullptr, &buffer);
+ return recorder.finishRecordingAsDrawable();
+}
+
+void SkReadBuffer::initDrawableFactories() {
+ this->setCustomFactory(SkString("SkRecordedDrawable"), unflatten_recorded_drawable);
+}

Powered by Google App Engine
This is Rietveld 408576698