OLD | NEW |
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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 630 |
631 // some GMs rely on having a skiagm::GetGr function defined | 631 // some GMs rely on having a skiagm::GetGr function defined |
632 namespace skiagm { | 632 namespace skiagm { |
633 // FIXME: this should be moved into a header | 633 // FIXME: this should be moved into a header |
634 GrContext* GetGr(); | 634 GrContext* GetGr(); |
635 GrContext* GetGr() { return SampleCode::GetGr(); } | 635 GrContext* GetGr() { return SampleCode::GetGr(); } |
636 } | 636 } |
637 | 637 |
638 ////////////////////////////////////////////////////////////////////////////// | 638 ////////////////////////////////////////////////////////////////////////////// |
639 | 639 |
| 640 enum TilingMode { |
| 641 kNo_Tiling, |
| 642 kAbs_128x128_Tiling, |
| 643 kAbs_256x256_Tiling, |
| 644 kRel_4x4_Tiling, |
| 645 kRel_1x16_Tiling, |
| 646 kRel_16x1_Tiling, |
| 647 |
| 648 kLast_TilingMode_Enum |
| 649 }; |
| 650 |
| 651 struct TilingInfo { |
| 652 const char* label; |
| 653 SkScalar w, h; |
| 654 }; |
| 655 |
| 656 static struct TilingInfo gTilingInfo[] = { |
| 657 { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling |
| 658 { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_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 |
| 661 { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling |
| 662 { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling |
| 663 }; |
| 664 SK_COMPILE_ASSERT((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum), |
| 665 Incomplete_tiling_labels); |
| 666 |
| 667 ////////////////////////////////////////////////////////////////////////////// |
| 668 |
640 static SkView* curr_view(SkWindow* wind) { | 669 static SkView* curr_view(SkWindow* wind) { |
641 SkView::F2BIter iter(wind); | 670 SkView::F2BIter iter(wind); |
642 return iter.next(); | 671 return iter.next(); |
643 } | 672 } |
644 | 673 |
645 static bool curr_title(SkWindow* wind, SkString* title) { | 674 static bool curr_title(SkWindow* wind, SkString* title) { |
646 SkView* view = curr_view(wind); | 675 SkView* view = curr_view(wind); |
647 if (view) { | 676 if (view) { |
648 SkEvent evt(gTitleEvtName); | 677 SkEvent evt(gTitleEvtName); |
649 if (view->doQuery(&evt)) { | 678 if (view->doQuery(&evt)) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 860 |
832 fUseClip = false; | 861 fUseClip = false; |
833 fNClip = false; | 862 fNClip = false; |
834 fAnimating = false; | 863 fAnimating = false; |
835 fRotate = false; | 864 fRotate = false; |
836 fRotateAnimTime = 0; | 865 fRotateAnimTime = 0; |
837 fPerspAnim = false; | 866 fPerspAnim = false; |
838 fPerspAnimTime = 0; | 867 fPerspAnimTime = 0; |
839 fRequestGrabImage = false; | 868 fRequestGrabImage = false; |
840 fPipeState = SkOSMenu::kOffState; | 869 fPipeState = SkOSMenu::kOffState; |
841 fTilingState = SkOSMenu::kOffState; | 870 fTilingMode = kNo_Tiling; |
842 fTileCount.set(1, 1); | |
843 fMeasureFPS = false; | 871 fMeasureFPS = false; |
844 fLCDState = SkOSMenu::kMixedState; | 872 fLCDState = SkOSMenu::kMixedState; |
845 fAAState = SkOSMenu::kMixedState; | 873 fAAState = SkOSMenu::kMixedState; |
846 fFilterState = SkOSMenu::kMixedState; | 874 fFilterState = SkOSMenu::kMixedState; |
847 fSubpixelState = SkOSMenu::kMixedState; | 875 fSubpixelState = SkOSMenu::kMixedState; |
848 fHintingState = 0; | 876 fHintingState = 0; |
849 fFlipAxis = 0; | 877 fFlipAxis = 0; |
850 fScrollTestX = fScrollTestY = 0; | 878 fScrollTestX = fScrollTestY = 0; |
851 | 879 |
852 fMouseX = fMouseY = 0; | 880 fMouseX = fMouseY = 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 gHintingStates[2].name, | 919 gHintingStates[2].name, |
892 gHintingStates[3].name, | 920 gHintingStates[3].name, |
893 gHintingStates[4].name, | 921 gHintingStates[4].name, |
894 NULL); | 922 NULL); |
895 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); | 923 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); |
896 | 924 |
897 fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID, | 925 fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID, |
898 fPipeState); | 926 fPipeState); |
899 fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P'); | 927 fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P'); |
900 | 928 |
901 itemID = fAppMenu->appendTriState("Tiling", "Tiling", sinkID, fTilingState); | 929 itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, |
| 930 gTilingInfo[kNo_Tiling].label, |
| 931 gTilingInfo[kAbs_128x128_Tiling].label, |
| 932 gTilingInfo[kAbs_256x256_Tiling].label, |
| 933 gTilingInfo[kRel_4x4_Tiling].label, |
| 934 gTilingInfo[kRel_1x16_Tiling].label, |
| 935 gTilingInfo[kRel_16x1_Tiling].label, |
| 936 NULL); |
902 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); | 937 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); |
903 | 938 |
904 itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); | 939 itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); |
905 fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); | 940 fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); |
906 itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); | 941 itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); |
907 fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); | 942 fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); |
908 itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); | 943 itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); |
909 fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); | 944 fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); |
910 itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); | 945 itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); |
911 fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); | 946 fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 } | 1191 } |
1157 canvas->clipRect(r); | 1192 canvas->clipRect(r); |
1158 this->INHERITED::draw(canvas); | 1193 this->INHERITED::draw(canvas); |
1159 } | 1194 } |
1160 } | 1195 } |
1161 | 1196 |
1162 SkBitmap diff; | 1197 SkBitmap diff; |
1163 if (bitmap_diff(canvas, orig, &diff)) { | 1198 if (bitmap_diff(canvas, orig, &diff)) { |
1164 } | 1199 } |
1165 } else { | 1200 } else { |
1166 const SkScalar cw = SkScalarDiv(this->width(), SkIntToScalar(fTileCount.
width())); | 1201 SkSize tile; |
1167 const SkScalar ch = SkScalarDiv(this->height(), SkIntToScalar(fTileCount
.height())); | 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); |
1168 | 1206 |
1169 for (int y = 0; y < fTileCount.height(); ++y) { | 1207 for (SkScalar y = 0; y < height(); y += tile.height()) { |
1170 for (int x = 0; x < fTileCount.width(); ++x) { | 1208 for (SkScalar x = 0; x < width(); x += tile.width()) { |
1171 SkAutoCanvasRestore acr(canvas, true); | 1209 SkAutoCanvasRestore acr(canvas, true); |
1172 canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch)); | 1210 canvas->clipRect(SkRect::MakeXYWH(x, y, |
| 1211 tile.width(), |
| 1212 tile.height())); |
1173 this->INHERITED::draw(canvas); | 1213 this->INHERITED::draw(canvas); |
1174 } | 1214 } |
1175 } | 1215 } |
1176 | 1216 |
1177 if (!fTileCount.equals(1, 1)) { | 1217 if (fTilingMode != kNo_Tiling) { |
1178 SkPaint paint; | 1218 SkPaint paint; |
1179 paint.setColor(0x60FF00FF); | 1219 paint.setColor(0x60FF00FF); |
1180 paint.setStyle(SkPaint::kStroke_Style); | 1220 paint.setStyle(SkPaint::kStroke_Style); |
1181 for (int y = 0; y < fTileCount.height(); ++y) { | 1221 |
1182 for (int x = 0; x < fTileCount.width(); ++x) { | 1222 for (SkScalar y = 0; y < height(); y += tile.height()) { |
1183 canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), p
aint); | 1223 for (SkScalar x = 0; x < width(); x += tile.width()) { |
| 1224 canvas->drawRect(SkRect::MakeXYWH(x, y, |
| 1225 tile.width(), |
| 1226 tile.height()), |
| 1227 paint); |
1184 } | 1228 } |
1185 } | 1229 } |
1186 } | 1230 } |
1187 } | 1231 } |
1188 if (fShowZoomer && !fSaveToPdf) { | 1232 if (fShowZoomer && !fSaveToPdf) { |
1189 showZoomer(canvas); | 1233 showZoomer(canvas); |
1190 } | 1234 } |
1191 if (fMagnify && !fSaveToPdf) { | 1235 if (fMagnify && !fSaveToPdf) { |
1192 magnify(canvas); | 1236 magnify(canvas); |
1193 } | 1237 } |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) { | 1716 if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) { |
1673 #ifdef PIPE_NET | 1717 #ifdef PIPE_NET |
1674 if (!fPipeState != SkOSMenu::kOnState) | 1718 if (!fPipeState != SkOSMenu::kOnState) |
1675 gServer.disconnectAll(); | 1719 gServer.disconnectAll(); |
1676 #endif | 1720 #endif |
1677 (void)SampleView::SetUsePipe(curr_view(this), fPipeState); | 1721 (void)SampleView::SetUsePipe(curr_view(this), fPipeState); |
1678 this->updateTitle(); | 1722 this->updateTitle(); |
1679 this->inval(NULL); | 1723 this->inval(NULL); |
1680 return true; | 1724 return true; |
1681 } | 1725 } |
1682 if (SkOSMenu::FindTriState(evt, "Tiling", &fTilingState)) { | |
1683 int nx = 1, ny = 1; | |
1684 switch (fTilingState) { | |
1685 case SkOSMenu::kOffState: nx = 1; ny = 1; break; | |
1686 case SkOSMenu::kMixedState: nx = 1; ny = 16; break; | |
1687 case SkOSMenu::kOnState: nx = 4; ny = 4; break; | |
1688 } | |
1689 fTileCount.set(nx, ny); | |
1690 this->inval(NULL); | |
1691 return true; | |
1692 } | |
1693 if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) { | 1726 if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) { |
1694 this->toggleSlideshow(); | 1727 this->toggleSlideshow(); |
1695 return true; | 1728 return true; |
1696 } | 1729 } |
1697 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || | 1730 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
1698 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || | 1731 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
1699 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) || | 1732 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) || |
1700 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || | 1733 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || |
1701 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || | 1734 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || |
1702 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || | 1735 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || |
1703 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || | 1736 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || |
1704 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) || | 1737 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) || |
1705 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) || | 1738 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) || |
1706 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) { | 1739 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev) || |
| 1740 SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) { |
1707 this->inval(NULL); | 1741 this->inval(NULL); |
1708 this->updateTitle(); | 1742 this->updateTitle(); |
1709 return true; | 1743 return true; |
1710 } | 1744 } |
1711 if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) { | 1745 if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) { |
1712 fFlipAxis ^= kFlipAxis_X; | 1746 fFlipAxis ^= kFlipAxis_X; |
1713 this->updateMatrix(); | 1747 this->updateMatrix(); |
1714 return true; | 1748 return true; |
1715 } | 1749 } |
1716 if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) { | 1750 if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 SkString title; | 2146 SkString title; |
2113 if (!curr_title(this, &title)) { | 2147 if (!curr_title(this, &title)) { |
2114 title.set("<unknown>"); | 2148 title.set("<unknown>"); |
2115 } | 2149 } |
2116 | 2150 |
2117 title.prepend(gDeviceTypePrefix[fDeviceType]); | 2151 title.prepend(gDeviceTypePrefix[fDeviceType]); |
2118 | 2152 |
2119 title.prepend(" "); | 2153 title.prepend(" "); |
2120 title.prepend(configToString(this->getBitmap().config())); | 2154 title.prepend(configToString(this->getBitmap().config())); |
2121 | 2155 |
| 2156 if (fTilingMode != kNo_Tiling) { |
| 2157 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); |
| 2158 } |
2122 if (fAnimating) { | 2159 if (fAnimating) { |
2123 title.prepend("<A> "); | 2160 title.prepend("<A> "); |
2124 } | 2161 } |
2125 if (fRotate) { | 2162 if (fRotate) { |
2126 title.prepend("<R> "); | 2163 title.prepend("<R> "); |
2127 } | 2164 } |
2128 if (fNClip) { | 2165 if (fNClip) { |
2129 title.prepend("<C> "); | 2166 title.prepend("<C> "); |
2130 } | 2167 } |
2131 if (fPerspAnim) { | 2168 if (fPerspAnim) { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2546 SkGraphics::Init(); | 2583 SkGraphics::Init(); |
2547 SkEvent::Init(); | 2584 SkEvent::Init(); |
2548 } | 2585 } |
2549 | 2586 |
2550 // FIXME: this should be in a header | 2587 // FIXME: this should be in a header |
2551 void application_term(); | 2588 void application_term(); |
2552 void application_term() { | 2589 void application_term() { |
2553 SkEvent::Term(); | 2590 SkEvent::Term(); |
2554 SkGraphics::Term(); | 2591 SkGraphics::Term(); |
2555 } | 2592 } |
OLD | NEW |