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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 109473004: change 'n' toggle to cycle through all filterlevels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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') | no next file » | 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 const char* label; 481 const char* label;
482 }; 482 };
483 static HintingState gHintingStates[] = { 483 static HintingState gHintingStates[] = {
484 {SkPaint::kNo_Hinting, "Mixed", NULL }, 484 {SkPaint::kNo_Hinting, "Mixed", NULL },
485 {SkPaint::kNo_Hinting, "None", "H0 " }, 485 {SkPaint::kNo_Hinting, "None", "H0 " },
486 {SkPaint::kSlight_Hinting, "Slight", "Hs " }, 486 {SkPaint::kSlight_Hinting, "Slight", "Hs " },
487 {SkPaint::kNormal_Hinting, "Normal", "Hn " }, 487 {SkPaint::kNormal_Hinting, "Normal", "Hn " },
488 {SkPaint::kFull_Hinting, "Full", "Hf " }, 488 {SkPaint::kFull_Hinting, "Full", "Hf " },
489 }; 489 };
490 490
491 struct FilterLevelState {
492 SkPaint::FilterLevel fLevel;
493 const char* fName;
494 const char* fLabel;
495 };
496 static FilterLevelState gFilterLevelStates[] = {
497 { SkPaint::kNone_FilterLevel, "Mixed", NULL },
498 { SkPaint::kNone_FilterLevel, "None", "F0 " },
499 { SkPaint::kLow_FilterLevel, "Low", "F1 " },
500 { SkPaint::kMedium_FilterLevel, "Medium", "F2 " },
501 { SkPaint::kHigh_FilterLevel, "High", "F3 " },
502 };
503
491 class FlagsDrawFilter : public SkDrawFilter { 504 class FlagsDrawFilter : public SkDrawFilter {
492 public: 505 public:
493 FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa, SkOSMenu::Tri State filter, 506 FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa,
494 SkOSMenu::TriState subpixel, int hinting) 507 SkOSMenu::TriState subpixel, int hinting, int filterlevel)
495 : fLCDState(lcd), fAAState(aa), fFilterState(filter), fSubpixelState(sub pixel) 508 : fLCDState(lcd)
496 , fHintingState(hinting) {} 509 , fAAState(aa)
510 , fSubpixelState(subpixel)
511 , fHintingState(hinting)
512 , fFilterLevelIndex(filterlevel)
513 {
514 SkASSERT((unsigned)filterlevel < SK_ARRAY_COUNT(gFilterLevelStates));
515 }
497 516
498 virtual bool filter(SkPaint* paint, Type t) { 517 virtual bool filter(SkPaint* paint, Type t) {
499 if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) { 518 if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
500 paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState); 519 paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
501 } 520 }
502 if (SkOSMenu::kMixedState != fAAState) { 521 if (SkOSMenu::kMixedState != fAAState) {
503 paint->setAntiAlias(SkOSMenu::kOnState == fAAState); 522 paint->setAntiAlias(SkOSMenu::kOnState == fAAState);
504 } 523 }
505 if (SkOSMenu::kMixedState != fFilterState) { 524 if (0 != fFilterLevelIndex) {
506 paint->setFilterLevel(SkOSMenu::kOnState == fFilterState ? 525 paint->setFilterLevel(gFilterLevelStates[fFilterLevelIndex].fLevel);
507 SkPaint::kLow_FilterLevel : SkPaint::kNone_Fil terLevel);
508 } 526 }
509 if (SkOSMenu::kMixedState != fSubpixelState) { 527 if (SkOSMenu::kMixedState != fSubpixelState) {
510 paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState); 528 paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState);
511 } 529 }
512 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt ates)) { 530 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt ates)) {
513 paint->setHinting(gHintingStates[fHintingState].hinting); 531 paint->setHinting(gHintingStates[fHintingState].hinting);
514 } 532 }
515 return true; 533 return true;
516 } 534 }
517 535
518 private: 536 private:
519 SkOSMenu::TriState fLCDState; 537 SkOSMenu::TriState fLCDState;
520 SkOSMenu::TriState fAAState; 538 SkOSMenu::TriState fAAState;
521 SkOSMenu::TriState fFilterState;
522 SkOSMenu::TriState fSubpixelState; 539 SkOSMenu::TriState fSubpixelState;
523 int fHintingState; 540 int fHintingState;
541 int fFilterLevelIndex;
524 }; 542 };
525 543
526 ////////////////////////////////////////////////////////////////////////////// 544 //////////////////////////////////////////////////////////////////////////////
527 545
528 #define MAX_ZOOM_LEVEL 8 546 #define MAX_ZOOM_LEVEL 8
529 #define MIN_ZOOM_LEVEL -8 547 #define MIN_ZOOM_LEVEL -8
530 548
531 static const char gCharEvtName[] = "SampleCode_Char_Event"; 549 static const char gCharEvtName[] = "SampleCode_Char_Event";
532 static const char gKeyEvtName[] = "SampleCode_Key_Event"; 550 static const char gKeyEvtName[] = "SampleCode_Key_Event";
533 static const char gTitleEvtName[] = "SampleCode_Title_Event"; 551 static const char gTitleEvtName[] = "SampleCode_Title_Event";
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 fRotate = false; 882 fRotate = false;
865 fRotateAnimTime = 0; 883 fRotateAnimTime = 0;
866 fPerspAnim = false; 884 fPerspAnim = false;
867 fPerspAnimTime = 0; 885 fPerspAnimTime = 0;
868 fRequestGrabImage = false; 886 fRequestGrabImage = false;
869 fPipeState = SkOSMenu::kOffState; 887 fPipeState = SkOSMenu::kOffState;
870 fTilingMode = kNo_Tiling; 888 fTilingMode = kNo_Tiling;
871 fMeasureFPS = false; 889 fMeasureFPS = false;
872 fLCDState = SkOSMenu::kMixedState; 890 fLCDState = SkOSMenu::kMixedState;
873 fAAState = SkOSMenu::kMixedState; 891 fAAState = SkOSMenu::kMixedState;
874 fFilterState = SkOSMenu::kMixedState;
875 fSubpixelState = SkOSMenu::kMixedState; 892 fSubpixelState = SkOSMenu::kMixedState;
876 fHintingState = 0; 893 fHintingState = 0;
894 fFilterLevelIndex = 0;
877 fFlipAxis = 0; 895 fFlipAxis = 0;
878 fScrollTestX = fScrollTestY = 0; 896 fScrollTestX = fScrollTestY = 0;
879 897
880 fMouseX = fMouseY = 0; 898 fMouseX = fMouseY = 0;
881 fFatBitsScale = 8; 899 fFatBitsScale = 8;
882 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold); 900 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold);
883 fShowZoomer = false; 901 fShowZoomer = false;
884 902
885 fZoomLevel = 0; 903 fZoomLevel = 0;
886 fZoomScale = SK_Scalar1; 904 fZoomScale = SK_Scalar1;
(...skipping 15 matching lines...) Expand all
902 "Raster", "Picture", "OpenGL", 920 "Raster", "Picture", "OpenGL",
903 #if SK_ANGLE 921 #if SK_ANGLE
904 "ANGLE", 922 "ANGLE",
905 #endif 923 #endif
906 NULL); 924 NULL);
907 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); 925 fAppMenu->assignKeyEquivalentToItem(itemID, 'd');
908 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); 926 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState);
909 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); 927 fAppMenu->assignKeyEquivalentToItem(itemID, 'b');
910 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); 928 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState);
911 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); 929 fAppMenu->assignKeyEquivalentToItem(itemID, 'l');
912 itemID = fAppMenu->appendTriState("Filter", "Filter", sinkID, fFilterState); 930 itemID = fAppMenu->appendList("FilterLevel", "FilterLevel", sinkID, fFilterL evelIndex,
931 gFilterLevelStates[0].fName,
932 gFilterLevelStates[1].fName,
933 gFilterLevelStates[2].fName,
934 gFilterLevelStates[3].fName,
935 gFilterLevelStates[4].fName,
936 NULL);
913 fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); 937 fAppMenu->assignKeyEquivalentToItem(itemID, 'n');
914 itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelS tate); 938 itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelS tate);
915 fAppMenu->assignKeyEquivalentToItem(itemID, 's'); 939 fAppMenu->assignKeyEquivalentToItem(itemID, 's');
916 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, 940 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState,
917 gHintingStates[0].name, 941 gHintingStates[0].name,
918 gHintingStates[1].name, 942 gHintingStates[1].name,
919 gHintingStates[2].name, 943 gHintingStates[2].name,
920 gHintingStates[3].name, 944 gHintingStates[3].name,
921 gHintingStates[4].name, 945 gHintingStates[4].name,
922 NULL); 946 NULL);
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 return fSamples.count(); 1691 return fSamples.count();
1668 } 1692 }
1669 1693
1670 void SampleWindow::showOverview() { 1694 void SampleWindow::showOverview() {
1671 this->loadView(create_transition(curr_view(this), 1695 this->loadView(create_transition(curr_view(this),
1672 create_overview(fSamples.count(), fSamples. begin()), 1696 create_overview(fSamples.count(), fSamples. begin()),
1673 4)); 1697 4));
1674 } 1698 }
1675 1699
1676 void SampleWindow::installDrawFilter(SkCanvas* canvas) { 1700 void SampleWindow::installDrawFilter(SkCanvas* canvas) {
1677 canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fFilterState, fSubpixelState, 1701 canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fSubpixelStat e,
1678 fHintingState))->unref(); 1702 fHintingState, fFilterLevelIndex)) ->unref();
1679 } 1703 }
1680 1704
1681 void SampleWindow::postAnimatingEvent() { 1705 void SampleWindow::postAnimatingEvent() {
1682 if (fAnimating) { 1706 if (fAnimating) {
1683 (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATI NG_DELAY); 1707 (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATI NG_DELAY);
1684 } 1708 }
1685 } 1709 }
1686 1710
1687 bool SampleWindow::onEvent(const SkEvent& evt) { 1711 bool SampleWindow::onEvent(const SkEvent& evt) {
1688 if (evt.isType(gUpdateWindowTitleEvtName)) { 1712 if (evt.isType(gUpdateWindowTitleEvtName)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 this->updateTitle(); 1746 this->updateTitle();
1723 this->inval(NULL); 1747 this->inval(NULL);
1724 return true; 1748 return true;
1725 } 1749 }
1726 if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) { 1750 if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) {
1727 this->toggleSlideshow(); 1751 this->toggleSlideshow();
1728 return true; 1752 return true;
1729 } 1753 }
1730 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || 1754 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) ||
1731 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || 1755 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) ||
1732 SkOSMenu::FindTriState(evt, "Filter", &fFilterState) || 1756 SkOSMenu::FindListIndex(evt, "FilterLevel", &fFilterLevelIndex) ||
1733 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || 1757 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) ||
1734 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || 1758 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) ||
1735 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || 1759 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) ||
1736 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) || 1760 SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) ||
1737 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) || 1761 SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) ||
1738 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) || 1762 SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) ||
1739 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev) || 1763 SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev) ||
1740 SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) { 1764 SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
1741 this->inval(NULL); 1765 this->inval(NULL);
1742 this->updateTitle(); 1766 this->updateTitle();
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 } 2188 }
2165 if (fNClip) { 2189 if (fNClip) {
2166 title.prepend("<C> "); 2190 title.prepend("<C> ");
2167 } 2191 }
2168 if (fPerspAnim) { 2192 if (fPerspAnim) {
2169 title.prepend("<K> "); 2193 title.prepend("<K> ");
2170 } 2194 }
2171 2195
2172 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); 2196 title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
2173 title.prepend(trystate_str(fAAState, "AA ", "aa ")); 2197 title.prepend(trystate_str(fAAState, "AA ", "aa "));
2174 title.prepend(trystate_str(fFilterState, "N ", "n ")); 2198 title.prepend(gFilterLevelStates[fFilterLevelIndex].fLabel);
2175 title.prepend(trystate_str(fSubpixelState, "S ", "s ")); 2199 title.prepend(trystate_str(fSubpixelState, "S ", "s "));
2176 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL); 2200 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL);
2177 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL); 2201 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
2178 title.prepend(gHintingStates[fHintingState].label); 2202 title.prepend(gHintingStates[fHintingState].label);
2179 2203
2180 if (fZoomLevel) { 2204 if (fZoomLevel) {
2181 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); 2205 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
2182 } 2206 }
2183 2207
2184 if (fMeasureFPS) { 2208 if (fMeasureFPS) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 SkGraphics::Init(); 2607 SkGraphics::Init();
2584 SkEvent::Init(); 2608 SkEvent::Init();
2585 } 2609 }
2586 2610
2587 // FIXME: this should be in a header 2611 // FIXME: this should be in a header
2588 void application_term(); 2612 void application_term();
2589 void application_term() { 2613 void application_term() {
2590 SkEvent::Term(); 2614 SkEvent::Term();
2591 SkGraphics::Term(); 2615 SkGraphics::Term();
2592 } 2616 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698