Allow creating a picture from skp to fail.
Replace the current constructor for creating an
SkPicturePlayback to a factory. In the factory,
check for incorrect data that would result in an invalid
playback. If the playback is invalid, return NULL, and
return NULL from SkPicture's factory as well.
Update SkTimedPicture(Playback) as well.
BUG=skia:1672
R=caryclark@google.com
Review URL: https://codereview.chromium.org/24826002
git-svn-id: http://skia.googlecode.com/svn/trunk@11554 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index d444152..4383f65 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -147,10 +147,20 @@
// offsets to individual commands.
class SkTimedPicturePlayback : public SkPicturePlayback {
public:
- SkTimedPicturePlayback(SkStream* stream, const SkPictInfo& info,
- SkPicture::InstallPixelRefProc proc,
- const SkTDArray<bool>& deletedCommands)
- : INHERITED(stream, info, proc)
+ static SkTimedPicturePlayback* CreateFromStream(SkStream* stream, const SkPictInfo& info,
+ SkPicture::InstallPixelRefProc proc,
+ const SkTDArray<bool>& deletedCommands) {
+ // Mimics SkPicturePlayback::CreateFromStream
+ SkAutoTDelete<SkTimedPicturePlayback> playback(SkNEW_ARGS(SkTimedPicturePlayback,
+ (deletedCommands)));
+ if (!playback->parseStream(stream, info, proc)) {
+ return NULL; // we're invalid
+ }
+ return playback.detach();
+ }
+
+ SkTimedPicturePlayback(const SkTDArray<bool>& deletedCommands)
+ : INHERITED()
, fSkipCommands(deletedCommands)
, fTot(0.0)
, fCurCommand(0) {
@@ -232,6 +242,14 @@
#endif
private:
+ // SkPicturePlayback::parseStream is protected, so it can be
+ // called here, but not by our static factory function. This
+ // allows the factory function to call it.
+ bool parseStream(SkStream* stream, const SkPictInfo& info,
+ SkPicture::InstallPixelRefProc proc) {
+ return this->INHERITED::parseStream(stream, info, proc);
+ }
+
typedef SkPicturePlayback INHERITED;
};
@@ -249,8 +267,11 @@
SkTimedPicturePlayback* playback;
// Check to see if there is a playback to recreate.
if (stream->readBool()) {
- playback = SkNEW_ARGS(SkTimedPicturePlayback,
- (stream, info, proc, deletedCommands));
+ playback = SkTimedPicturePlayback::CreateFromStream(stream, info, proc,
+ deletedCommands);
+ if (NULL == playback) {
+ return NULL;
+ }
} else {
playback = NULL;
}