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

Unified Diff: debugger/QT/SkDebuggerGUI.cpp

Issue 17113004: Replace SkPicture(SkStream) constructors with a factory. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove a change in behavior Created 7 years, 6 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
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: debugger/QT/SkDebuggerGUI.cpp
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index f5f9bc63312999d1bf753f7334e32b946e4a2048..67277070e5124576607754c402ecf261d82713a2 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;
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698