From 85cade0a10217a50aebb495099ecc0435fe08b23 Mon Sep 17 00:00:00 2001 From: "scroggo@google.com" Date: Fri, 17 Aug 2012 13:29:50 +0000 Subject: [PATCH] Move tiling up into SampleWindow. Now the tiles do not move with the view, and tiling persists when changing slides. Review URL: https://codereview.appspot.com/6450143 git-svn-id: http://skia.googlecode.com/svn/trunk@5146 2bbb7eff-a529-9590-31e7-b0007b416f81 --- samplecode/SampleApp.cpp | 61 ++++++++++++++++++++---------------------------- samplecode/SampleApp.h | 1 + samplecode/SampleCode.h | 3 --- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 254d209..25a0e87 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -795,6 +795,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev fRequestGrabImage = false; fPipeState = SkOSMenu::kOffState; fTilingState = SkOSMenu::kOffState; + fTileCount.set(1, 1); fMeasureFPS = false; fLCDState = SkOSMenu::kMixedState; fAAState = SkOSMenu::kMixedState; @@ -1090,7 +1091,27 @@ void SampleWindow::draw(SkCanvas* canvas) { if (bitmap_diff(canvas, orig, &diff)) { } } else { - this->INHERITED::draw(canvas); + const SkScalar cw = SkScalarDiv(this->width(), SkIntToScalar(fTileCount.width())); + const SkScalar ch = SkScalarDiv(this->height(), SkIntToScalar(fTileCount.height())); + + for (int y = 0; y < fTileCount.height(); ++y) { + for (int x = 0; x < fTileCount.width(); ++x) { + SkAutoCanvasRestore acr(canvas, true); + canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch)); + this->INHERITED::draw(canvas); + } + } + + if (!fTileCount.equals(1, 1)) { + SkPaint paint; + paint.setColor(0x60FF00FF); + paint.setStyle(SkPaint::kStroke_Style); + for (int y = 0; y < fTileCount.height(); ++y) { + for (int x = 0; x < fTileCount.width(); ++x) { + canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), paint); + } + } + } } if (fShowZoomer && !fSaveToPdf) { showZoomer(canvas); @@ -1633,8 +1654,7 @@ bool SampleWindow::onEvent(const SkEvent& evt) { case SkOSMenu::kMixedState: nx = 1; ny = 16; break; case SkOSMenu::kOnState: nx = 4; ny = 4; break; } - (void)SampleView::SetTileCount(curr_view(this), nx, ny); - this->updateTitle(); + fTileCount.set(nx, ny); this->inval(NULL); return true; } @@ -2174,7 +2194,6 @@ void SampleWindow::onSizeChange() { static const char is_sample_view_tag[] = "sample-is-sample-view"; static const char repeat_count_tag[] = "sample-set-repeat-count"; static const char set_use_pipe_tag[] = "sample-set-use-pipe"; -static const char set_tile_count_tag[] = "sample-set-tile-count"; bool SampleView::IsSampleView(SkView* view) { SkEvent evt(is_sample_view_tag); @@ -2193,22 +2212,11 @@ bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) { return view->doEvent(evt); } -bool SampleView::SetTileCount(SkView* view, int nx, int ny) { - SkEvent evt(set_tile_count_tag); - evt.setFast32((ny << 16) | nx); - return view->doEvent(evt); -} - bool SampleView::onEvent(const SkEvent& evt) { if (evt.isType(repeat_count_tag)) { fRepeatCount = evt.getFast32(); return true; } - if (evt.isType(set_tile_count_tag)) { - unsigned packed = evt.getFast32(); - fTileCount.set(packed & 0xFFFF, packed >> 16); - return true; - } int32_t pipeHolder; if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { fPipeState = static_cast(pipeHolder); @@ -2325,28 +2333,9 @@ void SampleView::draw(SkCanvas* canvas) { void SampleView::onDraw(SkCanvas* canvas) { this->onDrawBackground(canvas); - const SkScalar cw = this->width() / fTileCount.width(); - const SkScalar ch = this->height() / fTileCount.height(); - for (int i = 0; i < fRepeatCount; i++) { - for (int y = 0; y < fTileCount.height(); ++y) { - for (int x = 0; x < fTileCount.width(); ++x) { - SkAutoCanvasRestore acr(canvas, true); - canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch)); - this->onDrawContent(canvas); - } - } - } - - if (!fTileCount.equals(1, 1)) { - SkPaint paint; - paint.setColor(0x60FF00FF); - paint.setStyle(SkPaint::kStroke_Style); - for (int y = 0; y < fTileCount.height(); ++y) { - for (int x = 0; x < fTileCount.width(); ++x) { - canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), paint); - } - } + SkAutoCanvasRestore acr(canvas, true); + this->onDrawContent(canvas); } } diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index cb4446f..202fe21a 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -164,6 +164,7 @@ private: bool fMeasureFPS; SkMSec fMeasureFPS_Time; bool fMagnify; + SkISize fTileCount; SkOSMenu::TriState fPipeState; // Mixed uses a tiled pipe diff --git a/samplecode/SampleCode.h b/samplecode/SampleCode.h index 6b32185..e86ddd6 100644 --- a/samplecode/SampleCode.h +++ b/samplecode/SampleCode.h @@ -109,7 +109,6 @@ class SampleView : public SkView { public: SampleView() : fPipeState(SkOSMenu::kOffState), fBGColor(SK_ColorWHITE), fRepeatCount(1) { - fTileCount.set(1, 1); } void setBGColor(SkColor color) { fBGColor = color; } @@ -117,7 +116,6 @@ public: static bool IsSampleView(SkView*); static bool SetRepeatDraw(SkView*, int count); static bool SetUsePipe(SkView*, SkOSMenu::TriState); - static bool SetTileCount(SkView*, int nx, int ny); /** * Call this to request menu items from a SampleView. @@ -143,7 +141,6 @@ protected: private: int fRepeatCount; - SkISize fTileCount; typedef SkView INHERITED; }; -- 2.7.4