Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: samplecode/SampleApp.cpp

Issue 108513006: Add SkTileGridPicture SampleApp playback support. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated per review. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleApp.h ('k') | samplecode/SampleCode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SampleApp.h" 7 #include "SampleApp.h"
8 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 kRel_16x1_Tiling, 646 kRel_16x1_Tiling,
647 647
648 kLast_TilingMode_Enum 648 kLast_TilingMode_Enum
649 }; 649 };
650 650
651 struct TilingInfo { 651 struct TilingInfo {
652 const char* label; 652 const char* label;
653 SkScalar w, h; 653 SkScalar w, h;
654 }; 654 };
655 655
656 static struct TilingInfo gTilingInfo[] = { 656 static const struct TilingInfo gTilingInfo[] = {
657 { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling 657 { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling
658 { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Til ing 658 { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Til ing
659 { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Til ing 659 { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Til ing
660 { "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling 660 { "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling
661 { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling 661 { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling
662 { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling 662 { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling
663 }; 663 };
664 SK_COMPILE_ASSERT((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum), 664 SK_COMPILE_ASSERT((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum),
665 Incomplete_tiling_labels); 665 Incomplete_tiling_labels);
666 666
667 SkSize SampleWindow::tileSize() const {
668 SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum);
669 const struct TilingInfo* info = gTilingInfo + fTilingMode;
670 return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w ,
671 info->h > SK_Scalar1 ? info->h : this->height() * info-> h);
672 }
667 ////////////////////////////////////////////////////////////////////////////// 673 //////////////////////////////////////////////////////////////////////////////
668 674
669 static SkView* curr_view(SkWindow* wind) { 675 static SkView* curr_view(SkWindow* wind) {
670 SkView::F2BIter iter(wind); 676 SkView::F2BIter iter(wind);
671 return iter.next(); 677 return iter.next();
672 } 678 }
673 679
674 static bool curr_title(SkWindow* wind, SkString* title) { 680 static bool curr_title(SkWindow* wind, SkString* title) {
675 SkView* view = curr_view(wind); 681 SkView* view = curr_view(wind);
676 if (view) { 682 if (view) {
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 } 1197 }
1192 canvas->clipRect(r); 1198 canvas->clipRect(r);
1193 this->INHERITED::draw(canvas); 1199 this->INHERITED::draw(canvas);
1194 } 1200 }
1195 } 1201 }
1196 1202
1197 SkBitmap diff; 1203 SkBitmap diff;
1198 if (bitmap_diff(canvas, orig, &diff)) { 1204 if (bitmap_diff(canvas, orig, &diff)) {
1199 } 1205 }
1200 } else { 1206 } else {
1201 SkSize tile; 1207 SkSize tile = this->tileSize();
1202 SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum);
1203 struct TilingInfo* info = gTilingInfo + fTilingMode;
1204 tile.set(info->w > SK_Scalar1 ? info->w : width() * info->w,
1205 info->h > SK_Scalar1 ? info->h : height() * info->h);
1206 1208
1207 for (SkScalar y = 0; y < height(); y += tile.height()) { 1209 for (SkScalar y = 0; y < height(); y += tile.height()) {
1208 for (SkScalar x = 0; x < width(); x += tile.width()) { 1210 for (SkScalar x = 0; x < width(); x += tile.width()) {
1209 SkAutoCanvasRestore acr(canvas, true); 1211 SkAutoCanvasRestore acr(canvas, true);
1210 canvas->clipRect(SkRect::MakeXYWH(x, y, 1212 canvas->clipRect(SkRect::MakeXYWH(x, y,
1211 tile.width(), 1213 tile.width(),
1212 tile.height())); 1214 tile.height()));
1213 this->INHERITED::draw(canvas); 1215 this->INHERITED::draw(canvas);
1214 } 1216 }
1215 } 1217 }
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 } 1731 }
1730 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || 1732 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) ||
1731 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || 1733 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) ||
1732 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) || 1734 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) ||
1733 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || 1735 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) ||
1734 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || 1736 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) ||
1735 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || 1737 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) ||
1736 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || 1738 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) ||
1737 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) || 1739 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) ||
1738 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) || 1740 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) ||
1739 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev) || 1741 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) {
1740 SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
1741 this->inval(NULL); 1742 this->inval(NULL);
1742 this->updateTitle(); 1743 this->updateTitle();
1743 return true; 1744 return true;
1745 }
1746 if (SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
1747 if (SampleView::IsSampleView(curr_view(this))) {
1748 ((SampleView*)curr_view(this))->onTileSizeChanged(this->tileSize());
1749 }
1750 this->inval(NULL);
1751 this->updateTitle();
1752 return true;
1744 } 1753 }
1745 if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) { 1754 if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) {
1746 fFlipAxis ^= kFlipAxis_X; 1755 fFlipAxis ^= kFlipAxis_X;
1747 this->updateMatrix(); 1756 this->updateMatrix();
1748 return true; 1757 return true;
1749 } 1758 }
1750 if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) { 1759 if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) {
1751 fFlipAxis ^= kFlipAxis_Y; 1760 fFlipAxis ^= kFlipAxis_Y;
1752 this->updateMatrix(); 1761 this->updateMatrix();
1753 return true; 1762 return true;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 2099
2091 view->setVisibleP(true); 2100 view->setVisibleP(true);
2092 view->setClipToBounds(false); 2101 view->setClipToBounds(false);
2093 this->attachChildToFront(view)->unref(); 2102 this->attachChildToFront(view)->unref();
2094 view->setSize(this->width(), this->height()); 2103 view->setSize(this->width(), this->height());
2095 2104
2096 //repopulate the slide menu when a view is loaded 2105 //repopulate the slide menu when a view is loaded
2097 fSlideMenu->reset(); 2106 fSlideMenu->reset();
2098 2107
2099 (void)SampleView::SetUsePipe(view, fPipeState); 2108 (void)SampleView::SetUsePipe(view, fPipeState);
2100 if (SampleView::IsSampleView(view)) 2109 if (SampleView::IsSampleView(view)) {
2101 ((SampleView*)view)->requestMenu(fSlideMenu); 2110 SampleView* sampleView = (SampleView*)view;
2111 sampleView->requestMenu(fSlideMenu);
2112 sampleView->onTileSizeChanged(this->tileSize());
2113 }
2102 this->onUpdateMenu(fSlideMenu); 2114 this->onUpdateMenu(fSlideMenu);
2103 this->updateTitle(); 2115 this->updateTitle();
2104 } 2116 }
2105 2117
2106 static const char* gConfigNames[] = { 2118 static const char* gConfigNames[] = {
2107 "unknown config", 2119 "unknown config",
2108 "A8", 2120 "A8",
2109 "Index8", 2121 "Index8",
2110 "565", 2122 "565",
2111 "4444", 2123 "4444",
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 fZoomCenterX = SkScalarHalf(this->width()); 2256 fZoomCenterX = SkScalarHalf(this->width());
2245 fZoomCenterY = SkScalarHalf(this->height()); 2257 fZoomCenterY = SkScalarHalf(this->height());
2246 2258
2247 #ifdef SK_BUILD_FOR_ANDROID 2259 #ifdef SK_BUILD_FOR_ANDROID
2248 // FIXME: The first draw after a size change does not work on Android, so 2260 // FIXME: The first draw after a size change does not work on Android, so
2249 // we post an invalidate. 2261 // we post an invalidate.
2250 this->postInvalDelay(); 2262 this->postInvalDelay();
2251 #endif 2263 #endif
2252 this->updateTitle(); // to refresh our config 2264 this->updateTitle(); // to refresh our config
2253 fDevManager->windowSizeChanged(this); 2265 fDevManager->windowSizeChanged(this);
2266
2267 if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) {
2268 ((SampleView*)view)->onTileSizeChanged(this->tileSize());
2269 }
2254 } 2270 }
2255 2271
2256 /////////////////////////////////////////////////////////////////////////////// 2272 ///////////////////////////////////////////////////////////////////////////////
2257 2273
2258 static const char is_sample_view_tag[] = "sample-is-sample-view"; 2274 static const char is_sample_view_tag[] = "sample-is-sample-view";
2259 static const char repeat_count_tag[] = "sample-set-repeat-count"; 2275 static const char repeat_count_tag[] = "sample-set-repeat-count";
2260 static const char set_use_pipe_tag[] = "sample-set-use-pipe"; 2276 static const char set_use_pipe_tag[] = "sample-set-use-pipe";
2261 2277
2262 bool SampleView::IsSampleView(SkView* view) { 2278 bool SampleView::IsSampleView(SkView* view) {
2263 SkEvent evt(is_sample_view_tag); 2279 SkEvent evt(is_sample_view_tag);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 SkGraphics::Init(); 2599 SkGraphics::Init();
2584 SkEvent::Init(); 2600 SkEvent::Init();
2585 } 2601 }
2586 2602
2587 // FIXME: this should be in a header 2603 // FIXME: this should be in a header
2588 void application_term(); 2604 void application_term();
2589 void application_term() { 2605 void application_term() {
2590 SkEvent::Term(); 2606 SkEvent::Term();
2591 SkGraphics::Term(); 2607 SkGraphics::Term();
2592 } 2608 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | samplecode/SampleCode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698