aboutsummaryrefslogtreecommitdiffhomepage
path: root/debugger
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-28 21:32:00 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-28 21:32:00 +0000
commitf1754ec69131801c1a6ed3c704501a9400bbf324 (patch)
tree1a54d42c519ed1d15b25ed291f04274cbb0d0120 /debugger
parent925cdca8055fe6d6aab7c271d93d224d9b4e4fc8 (diff)
Replace SkPicture(SkStream) constructors with a factory.
SkPicture: Remove the constructors which take an SkStream as an argument. Rather than having to check a variable for success, the factory will return NULL on failure. Add a protected function for determining if an SkStream is an SKP to share code with SkTimedPicture. In the factory, check for a NULL SkStream. Use a default decoder (from BUG: https://code.google.com/p/skia/issues/detail?id=1325) SkDebuggerGUI: Call SkPicture::CreateFromStream when necessary. Write a factory for creating SkTimedPictures and use it. Use the factory throughout tools. Add include/lazy to utils and effects gyp include_dirs so SkPicture.h can reference SkImageDecoder.h which references SkBitmapFactory.h (in include/lazy). Changes code Chromium uses, so this will require a temporary Skia and then a change to Chromium to use the new Skia code. TODO: Create a decoder that does nothing to be used by pinspect, lua pictures, etc, and allow it to not assert in SkOrderedReadBuffer. R=reed@google.com Review URL: https://codereview.chromium.org/17113004 git-svn-id: http://skia.googlecode.com/svn/trunk@9822 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'debugger')
-rw-r--r--debugger/QT/SkDebuggerGUI.cpp62
1 files changed, 25 insertions, 37 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index f5f9bc6331..67277070e5 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -237,35 +237,24 @@ private:
// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
class SkTimedPicture : public SkPicture {
public:
- explicit SkTimedPicture(SkStream* stream, bool* success, SkPicture::InstallPixelRefProc proc,
- const SkTDArray<bool>& deletedCommands) {
- if (success) {
- *success = false;
- }
- fRecord = NULL;
- fPlayback = NULL;
- fWidth = fHeight = 0;
-
+ static SkTimedPicture* CreateTimedPicture(SkStream* stream,
+ SkPicture::InstallPixelRefProc proc,
+ const SkTDArray<bool>& deletedCommands) {
SkPictInfo info;
-
- if (!stream->read(&info, sizeof(info))) {
- return;
- }
- if (SkPicture::PICTURE_VERSION != info.fVersion) {
- return;
+ if (!StreamIsSKP(stream, &info)) {
+ return NULL;
}
+ SkTimedPicturePlayback* playback;
+ // Check to see if there is a playback to recreate.
if (stream->readBool()) {
- fPlayback = SkNEW_ARGS(SkTimedPicturePlayback,
- (stream, info, proc, deletedCommands));
+ playback = SkNEW_ARGS(SkTimedPicturePlayback,
+ (stream, info, proc, deletedCommands));
+ } else {
+ playback = NULL;
}
- // do this at the end, so that they will be zero if we hit an error.
- fWidth = info.fWidth;
- fHeight = info.fHeight;
- if (success) {
- *success = true;
- }
+ return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
}
void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
@@ -282,6 +271,9 @@ public:
private:
// disallow default ctor b.c. we don't have a good way to setup the fPlayback ptr
SkTimedPicture();
+ // Private ctor only used by CreateTimedPicture, which has created the playback.
+ SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
+ : INHERITED(playback, width, height) {}
// disallow the copy ctor - enabling would require copying code from SkPicture
SkTimedPicture(const SkTimedPicture& src);
@@ -338,10 +330,9 @@ void SkDebuggerGUI::actionProfile() {
return;
}
- bool success = false;
- SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeMemory,
- fSkipCommands);
- if (!success) {
+ SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inputStream,
+ &SkImageDecoder::DecodeMemory, fSkipCommands));
+ if (NULL == picture.get()) {
return;
}
@@ -377,20 +368,20 @@ void SkDebuggerGUI::actionProfile() {
static const int kNumRepeats = 10;
- run(&picture, renderer, kNumRepeats);
+ run(picture.get(), renderer, kNumRepeats);
- SkASSERT(picture.count() == fListWidget.count());
+ SkASSERT(picture->count() == fListWidget.count());
// extract the individual command times from the SkTimedPlaybackPicture
- for (int i = 0; i < picture.count(); ++i) {
- double temp = picture.time(i);
+ for (int i = 0; i < picture->count(); ++i) {
+ double temp = picture->time(i);
QListWidgetItem* item = fListWidget.item(i);
item->setData(Qt::UserRole + 4, 100.0*temp);
}
- setupOverviewText(picture.typeTimes(), picture.totTime(), kNumRepeats);
+ setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
}
void SkDebuggerGUI::actionCancel() {
@@ -905,12 +896,9 @@ void SkDebuggerGUI::loadPicture(const SkString& fileName) {
fLoading = true;
SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
- bool success = false;
-
- SkPicture* picture = SkNEW_ARGS(SkPicture,
- (stream, &success, &SkImageDecoder::DecodeMemory));
+ SkPicture* picture = SkPicture::CreateFromStream(stream);
- if (!success) {
+ if (NULL == picture) {
QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
SkSafeUnref(stream);
return;