aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-07-08 13:07:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-08 13:07:57 -0700
commit92432c7f7c0a878256f139ce6f73d71e1c202a16 (patch)
treed8f421ddc0675ac6427c0119b2b09dcd6acb1d41
parentf7a180b10f6924ad94a69d6d366e5bce6ed31529 (diff)
Fixed up SkTimedPicturePlayback
This was more motivated to remove the preDraw and postDraw virtuals from SkPicturePlayback. R=mtklein@google.com, reed@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/375943002
-rw-r--r--debugger/QT/SkDebuggerGUI.cpp55
-rw-r--r--src/core/SkPicturePlayback.cpp15
-rw-r--r--src/core/SkPicturePlayback.h5
-rw-r--r--src/core/SkPictureRangePlayback.cpp2
4 files changed, 49 insertions, 28 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index b6920a7b3e..1a324fd08b 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -156,9 +156,9 @@ void SkDebuggerGUI::showDeletes() {
}
}
-// The timed picture playback uses the SkPictureData's profiling stubs
-// to time individual commands. The offsets are needed to map SkPicture
-// offsets to individual commands.
+// The timed picture playback just steps through every operation timing
+// each one individually. Note that each picture should be replayed multiple
+// times (via calls to 'draw') before each command's time is accessed via 'time'.
class SkTimedPicturePlayback : public SkPicturePlayback {
public:
@@ -172,6 +172,47 @@ public:
this->resetTimes();
}
+ virtual void draw(SkCanvas* canvas, SkDrawPictureCallback* callback) SK_OVERRIDE {
+ AutoResetOpID aroi(this);
+ SkASSERT(0 == fCurOffset);
+
+ SkReader32 reader(fPictureData->opData()->bytes(), fPictureData->opData()->size());
+
+ // Record this, so we can concat w/ it if we encounter a setMatrix()
+ SkMatrix initialMatrix = canvas->getTotalMatrix();
+
+ SkAutoCanvasRestore acr(canvas, false);
+
+ int opIndex = -1;
+
+ while (!reader.eof()) {
+ if (NULL != callback && callback->abortDrawing()) {
+ return;
+ }
+
+ fCurOffset = reader.offset();
+ uint32_t size;
+ DrawType op = ReadOpAndSize(&reader, &size);
+ if (NOOP == op) {
+ // NOOPs are to be ignored - do not propagate them any further
+ reader.setOffset(fCurOffset + size);
+ continue;
+ }
+
+ opIndex++;
+
+ if (this->preDraw(opIndex, op)) {
+ // This operation is disabled in the debugger's GUI
+ reader.setOffset(fCurOffset + size);
+ continue;
+ }
+
+ this->handleOp(&reader, op, size, canvas, initialMatrix);
+
+ this->postDraw(opIndex);
+ }
+ }
+
void resetTimes() {
for (int i = 0; i < fTimes.count(); ++i) {
fTimes[i] = 0.0;
@@ -184,6 +225,7 @@ public:
int count() const { return fTimes.count(); }
+ // Return the fraction of the total time consumed by the index-th operation
double time(int index) const { return fTimes[index] / fTot; }
const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
@@ -196,11 +238,11 @@ protected:
SkTDArray<double> fTimes; // sum of time consumed for each command
SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
double fTot; // total of all times in 'fTimes'
+
int fCurType;
int fCurCommand; // the current command being executed/timed
-#ifdef SK_DEVELOPER
- virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
+ bool preDraw(int opIndex, int type) {
fCurCommand = opIndex;
if (fSkipCommands[fCurCommand]) {
@@ -227,7 +269,7 @@ protected:
return false;
}
- virtual void postDraw(int opIndex) SK_OVERRIDE {
+ void postDraw(int opIndex) {
#if defined(SK_BUILD_FOR_WIN32)
// CPU timer doesn't work well on Windows
double time = fTimer.endWall();
@@ -242,7 +284,6 @@ protected:
fTypeTimes[fCurType] += time;
fTot += time;
}
-#endif
private:
typedef SkPicturePlayback INHERITED;
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index d8ed082690..734a54a3c7 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -152,10 +152,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
SkAutoCanvasRestore acr(canvas, false);
-#ifdef SK_DEVELOPER
- int opIndex = -1;
-#endif
-
while (!reader.eof()) {
if (callback && callback->abortDrawing()) {
return;
@@ -232,13 +228,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
if (NOOP == op) {
// NOOPs are to be ignored - do not propagate them any further
skipTo = fCurOffset + size;
-#ifdef SK_DEVELOPER
- } else {
- opIndex++;
- if (this->preDraw(opIndex, op)) {
- skipTo = fCurOffset + size;
- }
-#endif
}
if (0 != skipTo) {
@@ -260,10 +249,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
this->handleOp(&reader, op, size, canvas, initialMatrix);
-#ifdef SK_DEVELOPER
- this->postDraw(opIndex);
-#endif
-
if (it.isValid()) {
uint32_t skipTo = it.nextDraw();
if (kDrawComplete == skipTo) {
diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h
index 7966670f6c..4248e2de5c 100644
--- a/src/core/SkPicturePlayback.h
+++ b/src/core/SkPicturePlayback.h
@@ -96,11 +96,6 @@ protected:
SkCanvas* canvas,
const SkMatrix& initialMatrix);
-#ifdef SK_DEVELOPER
- virtual bool preDraw(int opIndex, int type) { return false; }
- virtual void postDraw(int opIndex) { }
-#endif
-
static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size);
class AutoResetOpID {
diff --git a/src/core/SkPictureRangePlayback.cpp b/src/core/SkPictureRangePlayback.cpp
index 16473dbfcc..b5e36d6f22 100644
--- a/src/core/SkPictureRangePlayback.cpp
+++ b/src/core/SkPictureRangePlayback.cpp
@@ -29,7 +29,7 @@ void SkPictureRangePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callb
SkAutoCanvasRestore acr(canvas, false);
while (!reader.eof()) {
- if (callback && callback->abortDrawing()) {
+ if (NULL != callback && callback->abortDrawing()) {
return;
}