From: reed@google.com Date: Wed, 15 Aug 2012 14:41:58 +0000 (+0000) Subject: add 't' to toggle tiling modes X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~15167 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67b89eeeb07aa0485db233b5f356031fe15b57c4;p=platform%2Fupstream%2FlibSkiaSharp.git add 't' to toggle tiling modes Review URL: https://codereview.appspot.com/6446138 git-svn-id: http://skia.googlecode.com/svn/trunk@5109 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index a101853..8c6a2bd 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -792,6 +792,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev fScale = false; fRequestGrabImage = false; fPipeState = SkOSMenu::kOffState; + fTilingState = SkOSMenu::kOffState; fMeasureFPS = false; fLCDState = SkOSMenu::kMixedState; fAAState = SkOSMenu::kMixedState; @@ -837,9 +838,14 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); itemID = fAppMenu->appendTriState("Hinting", "Hinting", sinkID, fHintingState); fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); + fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID, fPipeState); fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P'); + + itemID = fAppMenu->appendTriState("Tiling", "Tiling", sinkID, fTilingState); + fAppMenu->assignKeyEquivalentToItem(itemID, 't'); + #ifdef DEBUGGER itemID = fAppMenu->appendSwitch("Debugger", "Debugger", sinkID, fDebugger); fAppMenu->assignKeyEquivalentToItem(itemID, 'q'); @@ -1618,6 +1624,18 @@ bool SampleWindow::onEvent(const SkEvent& evt) { this->inval(NULL); return true; } + if (SkOSMenu::FindTriState(evt, "Tiling", &fTilingState)) { + int nx = 1, ny = 1; + switch (fTilingState) { + case SkOSMenu::kOffState: nx = 1; ny = 1; break; + case SkOSMenu::kMixedState: nx = 1; ny = 4; break; + case SkOSMenu::kOnState: nx = 2; ny = 2; break; + } + (void)SampleView::SetTileCount(curr_view(this), nx, ny); + this->updateTitle(); + this->inval(NULL); + return true; + } if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) { this->toggleSlideshow(); return true; @@ -2152,6 +2170,7 @@ 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); @@ -2170,11 +2189,22 @@ 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); @@ -2291,9 +2321,28 @@ 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++) { - SkAutoCanvasRestore acr(canvas, true); - this->onDrawContent(canvas); + 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); + } + } } } diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 6d24bd5..00353b2 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -180,6 +180,7 @@ private: SkOSMenu::TriState fAAState; SkOSMenu::TriState fFilterState; SkOSMenu::TriState fHintingState; + SkOSMenu::TriState fTilingState; unsigned fFlipAxis; int fMSAASampleCount; diff --git a/samplecode/SampleCode.h b/samplecode/SampleCode.h index e86ddd6..6b32185 100644 --- a/samplecode/SampleCode.h +++ b/samplecode/SampleCode.h @@ -109,6 +109,7 @@ class SampleView : public SkView { public: SampleView() : fPipeState(SkOSMenu::kOffState), fBGColor(SK_ColorWHITE), fRepeatCount(1) { + fTileCount.set(1, 1); } void setBGColor(SkColor color) { fBGColor = color; } @@ -116,6 +117,7 @@ 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. @@ -141,6 +143,7 @@ protected: private: int fRepeatCount; + SkISize fTileCount; typedef SkView INHERITED; };