Added the following 3 features to sample app.

1) Imported SKP files can now be run using the bbox playback ('b' key)
2) Imported SKP files are displayed using their basename
3) FPS counter has been updated to print time to draw all tiles

Review URL: https://codereview.appspot.com/6904057

git-svn-id: http://skia.googlecode.com/svn/trunk@6718 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2012-12-07 21:52:34 +00:00
parent d3d377f1d6
commit bcedc22012
3 changed files with 59 additions and 14 deletions

View File

@ -1051,6 +1051,10 @@ void SampleWindow::draw(SkCanvas* canvas) {
this->updateMatrix(); this->updateMatrix();
} }
if (fMeasureFPS) {
fMeasureFPS_Time = 0;
}
if (fNClip) { if (fNClip) {
this->INHERITED::draw(canvas); this->INHERITED::draw(canvas);
SkBitmap orig = capture_bitmap(canvas); SkBitmap orig = capture_bitmap(canvas);
@ -1111,6 +1115,11 @@ void SampleWindow::draw(SkCanvas* canvas) {
magnify(canvas); magnify(canvas);
} }
if (fMeasureFPS && fMeasureFPS_Time) {
this->updateTitle();
this->postInvalDelay();
}
// do this last // do this last
fDevManager->publishCanvas(fDeviceType, canvas, this); fDevManager->publishCanvas(fDeviceType, canvas, this);
} }
@ -1396,10 +1405,8 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
} }
// Do this after presentGL and other finishing, rather than in afterChild // Do this after presentGL and other finishing, rather than in afterChild
if (fMeasureFPS && fMeasureFPS_Time) { if (fMeasureFPS && fMeasureFPS_StartTime) {
fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time; fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime;
this->updateTitle();
this->postInvalDelay();
} }
// if ((fScrollTestX | fScrollTestY) != 0) // if ((fScrollTestX | fScrollTestY) != 0)
@ -1471,9 +1478,8 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
this->installDrawFilter(canvas); this->installDrawFilter(canvas);
if (fMeasureFPS) { if (fMeasureFPS) {
fMeasureFPS_Time = 0; // 0 means the child is not aware of repeat-draw
if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) { if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
fMeasureFPS_Time = SkTime::GetMSecs(); fMeasureFPS_StartTime = SkTime::GetMSecs();
} }
} else { } else {
(void)SampleView::SetRepeatDraw(child, 1); (void)SampleView::SetRepeatDraw(child, 1);
@ -1778,6 +1784,13 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
} }
switch (uni) { switch (uni) {
case 'b':
{
postEventToSink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
this->updateTitle();
this->inval(NULL);
break;
}
case 'B': case 'B':
// gIgnoreFastBlurRect = !gIgnoreFastBlurRect; // gIgnoreFastBlurRect = !gIgnoreFastBlurRect;
this->inval(NULL); this->inval(NULL);

View File

@ -168,6 +168,7 @@ private:
bool fRequestGrabImage; bool fRequestGrabImage;
bool fMeasureFPS; bool fMeasureFPS;
SkMSec fMeasureFPS_Time; SkMSec fMeasureFPS_Time;
SkMSec fMeasureFPS_StartTime;
bool fMagnify; bool fMagnify;
SkISize fTileCount; SkISize fTileCount;

View File

@ -13,6 +13,7 @@
#include "SkGradientShader.h" #include "SkGradientShader.h"
#include "SkGraphics.h" #include "SkGraphics.h"
#include "SkImageDecoder.h" #include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkPath.h" #include "SkPath.h"
#include "SkPicture.h" #include "SkPicture.h"
#include "SkRandom.h" #include "SkRandom.h"
@ -31,8 +32,10 @@
class PictFileView : public SampleView { class PictFileView : public SampleView {
SkString fFilename; SkString fFilename;
SkPicture* fPicture; SkPicture* fPicture;
SkPicture* fBBoxPicture;
bool fUseBBox;
static SkPicture* LoadPicture(const char path[]) { static SkPicture* LoadPicture(const char path[], bool useBBox) {
SkPicture* pic = NULL; SkPicture* pic = NULL;
SkBitmap bm; SkBitmap bm;
@ -60,16 +63,30 @@ class PictFileView : public SampleView {
p2.serialize(&writer); p2.serialize(&writer);
} }
} }
return pic;
if (useBBox) {
SkPicture* bboxPicture = SkNEW(SkPicture);
pic->draw(bboxPicture->beginRecording(pic->width(), pic->height(),
SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
bboxPicture->endRecording();
SkDELETE(pic);
return bboxPicture;
} else {
return pic;
}
} }
public: public:
PictFileView(const char name[] = NULL) : fFilename(name) { PictFileView(const char name[] = NULL) : fFilename(name) {
fPicture = NULL; fPicture = NULL;
fBBoxPicture = NULL;
fUseBBox = false;
} }
virtual ~PictFileView() { virtual ~PictFileView() {
SkSafeUnref(fPicture); SkSafeUnref(fPicture);
SkSafeUnref(fBBoxPicture);
} }
protected: protected:
@ -77,19 +94,33 @@ protected:
virtual bool onQuery(SkEvent* evt) { virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) { if (SampleCode::TitleQ(*evt)) {
SkString name("P:"); SkString name("P:");
name.append(fFilename); char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR);
name.append(basename ? basename+1: fFilename.c_str());
if (fUseBBox) {
name.append(" <bbox>");
}
SampleCode::TitleR(evt, name.c_str()); SampleCode::TitleR(evt, name.c_str());
return true; return true;
} }
return this->INHERITED::onQuery(evt); return this->INHERITED::onQuery(evt);
} }
virtual void onDrawContent(SkCanvas* canvas) { virtual bool onEvent(const SkEvent& evt) {
if (!fPicture) { if (evt.isType("PictFileView::toggleBBox")) {
fPicture = LoadPicture(fFilename.c_str()); fUseBBox = !fUseBBox;
return true;
} }
if (fPicture) { return this->INHERITED::onEvent(evt);
canvas->drawPicture(*fPicture); }
virtual void onDrawContent(SkCanvas* canvas) {
SkPicture** picture = fUseBBox ? &fBBoxPicture : &fPicture;
if (!*picture) {
*picture = LoadPicture(fFilename.c_str(), fUseBBox);
}
if (*picture) {
canvas->drawPicture(**picture);
} }
} }