Reapply (r6718) with fix for compiler error on linux.
authordjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 10 Dec 2012 14:12:55 +0000 (14:12 +0000)
committerdjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 10 Dec 2012 14:12:55 +0000 (14:12 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@6729 2bbb7eff-a529-9590-31e7-b0007b416f81

samplecode/SampleApp.cpp
samplecode/SampleApp.h
samplecode/SamplePictFile.cpp

index cc06e0425039377d68c1ddbde00ed42e434e0b40..716998f9600dde0a76db0ff7892cc42f2549d285 100644 (file)
@@ -1051,6 +1051,10 @@ void SampleWindow::draw(SkCanvas* canvas) {
         this->updateMatrix();
     }
 
+    if (fMeasureFPS) {
+        fMeasureFPS_Time = 0;
+    }
+
     if (fNClip) {
         this->INHERITED::draw(canvas);
         SkBitmap orig = capture_bitmap(canvas);
@@ -1111,6 +1115,11 @@ void SampleWindow::draw(SkCanvas* canvas) {
         magnify(canvas);
     }
 
+    if (fMeasureFPS && fMeasureFPS_Time) {
+        this->updateTitle();
+        this->postInvalDelay();
+    }
+
     // do this last
     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
-    if (fMeasureFPS && fMeasureFPS_Time) {
-        fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time;
-        this->updateTitle();
-        this->postInvalDelay();
+    if (fMeasureFPS && fMeasureFPS_StartTime) {
+        fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime;
     }
 
     //    if ((fScrollTestX | fScrollTestY) != 0)
@@ -1471,9 +1478,8 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
     this->installDrawFilter(canvas);
 
     if (fMeasureFPS) {
-        fMeasureFPS_Time = 0;   // 0 means the child is not aware of repeat-draw
         if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
-            fMeasureFPS_Time = SkTime::GetMSecs();
+            fMeasureFPS_StartTime = SkTime::GetMSecs();
         }
     } else {
         (void)SampleView::SetRepeatDraw(child, 1);
@@ -1778,6 +1784,13 @@ bool SampleWindow::onHandleChar(SkUnichar uni) {
     }
 
     switch (uni) {
+        case 'b':
+            {
+            postEventToSink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
+            this->updateTitle();
+            this->inval(NULL);
+            break;
+            }
         case 'B':
 //            gIgnoreFastBlurRect = !gIgnoreFastBlurRect;
             this->inval(NULL);
index 85392e0c9a2fba0074707ba26efa7ec94a37dc4f..2308a121ab05458ab54391fab5f93a7e8f99bf15 100644 (file)
@@ -168,6 +168,7 @@ private:
     bool fRequestGrabImage;
     bool fMeasureFPS;
     SkMSec fMeasureFPS_Time;
+    SkMSec fMeasureFPS_StartTime;
     bool fMagnify;
     SkISize fTileCount;
 
index 22c81d1d9461b96c439724fe45402f086e3a3e0b..b53ba83600700742bfb48ca1c6fa3c16bf6ad4ad 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkGradientShader.h"
 #include "SkGraphics.h"
 #include "SkImageDecoder.h"
+#include "SkOSFile.h"
 #include "SkPath.h"
 #include "SkPicture.h"
 #include "SkRandom.h"
 class PictFileView : public SampleView {
     SkString    fFilename;
     SkPicture*  fPicture;
+    SkPicture*  fBBoxPicture;
+    bool        fUseBBox;
 
-    static SkPicture* LoadPicture(const char path[]) {
+    static SkPicture* LoadPicture(const char path[], bool useBBox) {
         SkPicture* pic = NULL;
 
         SkBitmap bm;
@@ -60,16 +63,30 @@ class PictFileView : public SampleView {
                 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:
     PictFileView(const char name[] = NULL) : fFilename(name) {
         fPicture = NULL;
+        fBBoxPicture = NULL;
+        fUseBBox = false;
     }
 
     virtual ~PictFileView() {
         SkSafeUnref(fPicture);
+        SkSafeUnref(fBBoxPicture);
     }
 
 protected:
@@ -77,19 +94,33 @@ protected:
     virtual bool onQuery(SkEvent* evt) {
         if (SampleCode::TitleQ(*evt)) {
             SkString name("P:");
-            name.append(fFilename);
+            const 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());
             return true;
         }
         return this->INHERITED::onQuery(evt);
     }
 
+    virtual bool onEvent(const SkEvent& evt) {
+        if (evt.isType("PictFileView::toggleBBox")) {
+            fUseBBox = !fUseBBox;
+            return true;
+        }
+        return this->INHERITED::onEvent(evt);
+    }
+
     virtual void onDrawContent(SkCanvas* canvas) {
-        if (!fPicture) {
-            fPicture = LoadPicture(fFilename.c_str());
+        SkPicture** picture = fUseBBox ? &fBBoxPicture : &fPicture;
+
+        if (!*picture) {
+            *picture = LoadPicture(fFilename.c_str(), fUseBBox);
         }
-        if (fPicture) {
-            canvas->drawPicture(*fPicture);
+        if (*picture) {
+            canvas->drawPicture(**picture);
         }
     }