Chromium Code Reviews| 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); |
| +} |