diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-09-08 18:48:12 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-09-08 18:48:12 +0000 |
commit | e8f091093509d946a7f6722b40033a3dc946dc0f (patch) | |
tree | 5b76116be7c37439aacfefe6385439532cc0af74 | |
parent | 4ee1433844401df5b136e420a2548172de56c8ab (diff) |
Add 'K' to SampleApp to trigger animated perspective rendering
Review URL: http://codereview.appspot.com/4967061/
git-svn-id: http://skia.googlecode.com/svn/trunk@2244 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | samplecode/SampleApp.cpp | 39 | ||||
-rw-r--r-- | samplecode/SampleApp.h | 2 |
2 files changed, 39 insertions, 2 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 3805ca6607..7dbec175c1 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -432,6 +432,8 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev fRepeatDrawing = false; fAnimating = false; fRotate = false; + fPerspAnim = false; + fPerspAnimTime = 0; fScale = false; fRequestGrabImage = false; fUsePipe = false; @@ -615,8 +617,14 @@ void SampleWindow::draw(SkCanvas* canvas) { return; } // update the animation time - gAnimTimePrev = gAnimTime; - gAnimTime = SkTime::GetMSecs(); + if (!gAnimTimePrev && !gAnimTime) { + // first time make delta be 0 + gAnimTime = SkTime::GetMSecs(); + gAnimTimePrev = gAnimTime; + } else { + gAnimTimePrev = gAnimTime; + gAnimTime = SkTime::GetMSecs(); + } SkScalar cx = fZoomCenterX; SkScalar cy = fZoomCenterY; @@ -1023,6 +1031,22 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { canvas->rotate(SkIntToScalar(30)); canvas->translate(-cx, -cy); } + if (fPerspAnim) { + fPerspAnimTime += SampleCode::GetAnimSecondsDelta();
+
+ static const SkScalar gAnimPeriod = 10 * SK_Scalar1;
+ static const SkScalar gAnimMag = SK_Scalar1 / 1000;
+ SkScalar t = SkScalarMod(fPerspAnimTime, gAnimPeriod);
+ if (SkScalarFloorToInt(SkScalarDiv(fPerspAnimTime, gAnimPeriod)) & 0x1) {
+ t = gAnimPeriod - t;
+ }
+ t = 2 * t - gAnimPeriod;
+ t = SkScalarMul(SkScalarDiv(t, gAnimPeriod), gAnimMag);
+ SkMatrix m;
+ m.reset();
+ m.setPerspY(t);
+ canvas->concat(m); + } canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fFilterState, fHintingState))->unref(); @@ -1035,6 +1059,9 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { } else { (void)SampleView::SetRepeatDraw(child, 1); } + if (fPerspAnim) { + this->inval(NULL); + } //(void)SampleView::SetUsePipe(child, fUsePipe); } @@ -1302,6 +1329,11 @@ bool SampleWindow::onHandleChar(SkUnichar uni) { this->inval(NULL); this->updateTitle(); return true; + case 'k': + fPerspAnim = !fPerspAnim; + this->inval(NULL); + this->updateTitle(); + return true; case 's': fScale = !fScale; this->inval(NULL); @@ -1555,6 +1587,9 @@ void SampleWindow::updateTitle() { if (fNClip) { title.prepend("<C> "); } + if (fPerspAnim) { + title.prepend("<K> "); + } title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); title.prepend(trystate_str(fAAState, "AA ", "aa ")); diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 729b7b1139..1d7e66b98b 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -141,6 +141,8 @@ private: bool fRepeatDrawing; bool fAnimating; bool fRotate; + bool fPerspAnim; + SkScalar fPerspAnimTime; bool fScale; bool fRequestGrabImage; bool fMeasureFPS; |