| 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 | 7 |
| 8 #include "SampleApp.h" | 8 #include "SampleApp.h" |
| 9 | 9 |
| 10 #include "OverView.h" | 10 #include "OverView.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 class PdfFileViewerFactory : public SkViewFactory { | 62 class PdfFileViewerFactory : public SkViewFactory { |
| 63 SkString fFilename; | 63 SkString fFilename; |
| 64 public: | 64 public: |
| 65 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} | 65 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} |
| 66 SkView* operator() () const override { | 66 SkView* operator() () const override { |
| 67 return CreateSamplePdfFileViewer(fFilename.c_str()); | 67 return CreateSamplePdfFileViewer(fFilename.c_str()); |
| 68 } | 68 } |
| 69 }; | 69 }; |
| 70 #endif // SAMPLE_PDF_FILE_VIEWER | 70 #endif // SAMPLE_PDF_FILE_VIEWER |
| 71 | 71 |
| 72 #if SK_COMMAND_BUFFER | |
| 73 #define DEFAULT_TO_COMMAND_BUFFER 1 | |
| 74 #elif SK_ANGLE | |
| 75 //#define DEFAULT_TO_ANGLE 1 | |
| 76 #else | |
| 77 #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU | |
| 78 #endif | |
| 79 | |
| 80 #define ANIMATING_EVENTTYPE "nextSample" | 72 #define ANIMATING_EVENTTYPE "nextSample" |
| 81 #define ANIMATING_DELAY 250 | 73 #define ANIMATING_DELAY 250 |
| 82 | 74 |
| 83 #ifdef SK_DEBUG | 75 #ifdef SK_DEBUG |
| 84 #define FPS_REPEAT_MULTIPLIER 1 | 76 #define FPS_REPEAT_MULTIPLIER 1 |
| 85 #else | 77 #else |
| 86 #define FPS_REPEAT_MULTIPLIER 10 | 78 #define FPS_REPEAT_MULTIPLIER 10 |
| 87 #endif | 79 #endif |
| 88 #define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER) | 80 #define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER) |
| 89 | 81 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ////////////////////////////////////////////////////////////////////////////// | 421 ////////////////////////////////////////////////////////////////////////////// |
| 430 | 422 |
| 431 enum FlipAxisEnum { | 423 enum FlipAxisEnum { |
| 432 kFlipAxis_X = (1 << 0), | 424 kFlipAxis_X = (1 << 0), |
| 433 kFlipAxis_Y = (1 << 1) | 425 kFlipAxis_Y = (1 << 1) |
| 434 }; | 426 }; |
| 435 | 427 |
| 436 #include "SkDrawFilter.h" | 428 #include "SkDrawFilter.h" |
| 437 | 429 |
| 438 struct HintingState { | 430 struct HintingState { |
| 439 SkPaint::Hinting hinting; | 431 SkPaint::Hinting fHinting; |
| 440 const char* name; | 432 const char* fMenuLabel; |
| 441 const char* label; | 433 const char* fTitleLabel; |
| 442 }; | 434 }; |
| 443 static HintingState gHintingStates[] = { | 435 static HintingState gHintingStates[] = { |
| 444 {SkPaint::kNo_Hinting, "Mixed", nullptr }, | 436 {SkPaint::kNo_Hinting, "Mixed", nullptr }, |
| 445 {SkPaint::kNo_Hinting, "None", "H0 " }, | 437 {SkPaint::kNo_Hinting, "None", "H0 " }, |
| 446 {SkPaint::kSlight_Hinting, "Slight", "Hs " }, | 438 {SkPaint::kSlight_Hinting, "Slight", "Hs " }, |
| 447 {SkPaint::kNormal_Hinting, "Normal", "Hn " }, | 439 {SkPaint::kNormal_Hinting, "Normal", "Hn " }, |
| 448 {SkPaint::kFull_Hinting, "Full", "Hf " }, | 440 {SkPaint::kFull_Hinting, "Full", "Hf " }, |
| 449 }; | 441 }; |
| 450 | 442 |
| 451 struct FilterQualityState { | 443 struct FilterQualityState { |
| 452 SkFilterQuality fQuality; | 444 SkFilterQuality fQuality; |
| 453 const char* fName; | 445 const char* fMenuLabel; |
| 454 const char* fLabel; | 446 const char* fTitleLabel; |
| 455 }; | 447 }; |
| 456 static FilterQualityState gFilterQualityStates[] = { | 448 static FilterQualityState gFilterQualityStates[] = { |
| 457 { kNone_SkFilterQuality, "Mixed", nullptr }, | 449 { kNone_SkFilterQuality, "Mixed", nullptr }, |
| 458 { kNone_SkFilterQuality, "None", "F0 " }, | 450 { kNone_SkFilterQuality, "None", "F0 " }, |
| 459 { kLow_SkFilterQuality, "Low", "F1 " }, | 451 { kLow_SkFilterQuality, "Low", "F1 " }, |
| 460 { kMedium_SkFilterQuality, "Medium", "F2 " }, | 452 { kMedium_SkFilterQuality, "Medium", "F2 " }, |
| 461 { kHigh_SkFilterQuality, "High", "F3 " }, | 453 { kHigh_SkFilterQuality, "High", "F3 " }, |
| 462 }; | 454 }; |
| 463 | 455 |
| 464 class FlagsFilterCanvas : public SkPaintFilterCanvas { | 456 class FlagsFilterCanvas : public SkPaintFilterCanvas { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 486 if (SkOSMenu::kMixedState != fAAState) { | 478 if (SkOSMenu::kMixedState != fAAState) { |
| 487 paint->writable()->setAntiAlias(SkOSMenu::kOnState == fAAState); | 479 paint->writable()->setAntiAlias(SkOSMenu::kOnState == fAAState); |
| 488 } | 480 } |
| 489 if (0 != fFilterQualityIndex) { | 481 if (0 != fFilterQualityIndex) { |
| 490 paint->writable()->setFilterQuality(gFilterQualityStates[fFilterQual
ityIndex].fQuality); | 482 paint->writable()->setFilterQuality(gFilterQualityStates[fFilterQual
ityIndex].fQuality); |
| 491 } | 483 } |
| 492 if (SkOSMenu::kMixedState != fSubpixelState) { | 484 if (SkOSMenu::kMixedState != fSubpixelState) { |
| 493 paint->writable()->setSubpixelText(SkOSMenu::kOnState == fSubpixelSt
ate); | 485 paint->writable()->setSubpixelText(SkOSMenu::kOnState == fSubpixelSt
ate); |
| 494 } | 486 } |
| 495 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt
ates)) { | 487 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt
ates)) { |
| 496 paint->writable()->setHinting(gHintingStates[fHintingState].hinting)
; | 488 paint->writable()->setHinting(gHintingStates[fHintingState].fHinting
); |
| 497 } | 489 } |
| 498 return true; | 490 return true; |
| 499 } | 491 } |
| 500 | 492 |
| 501 private: | 493 private: |
| 502 SkOSMenu::TriState fLCDState; | 494 SkOSMenu::TriState fLCDState; |
| 503 SkOSMenu::TriState fAAState; | 495 SkOSMenu::TriState fAAState; |
| 504 SkOSMenu::TriState fSubpixelState; | 496 SkOSMenu::TriState fSubpixelState; |
| 505 int fHintingState; | 497 int fHintingState; |
| 506 int fFilterQualityIndex; | 498 int fFilterQualityIndex; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 kRel_16x1_Tiling, | 577 kRel_16x1_Tiling, |
| 586 | 578 |
| 587 kLast_TilingMode_Enum | 579 kLast_TilingMode_Enum |
| 588 }; | 580 }; |
| 589 | 581 |
| 590 struct TilingInfo { | 582 struct TilingInfo { |
| 591 const char* label; | 583 const char* label; |
| 592 SkScalar w, h; | 584 SkScalar w, h; |
| 593 }; | 585 }; |
| 594 | 586 |
| 595 static const struct TilingInfo gTilingInfo[] = { | 587 static const struct TilingInfo gTilingInfos[] = { |
| 596 { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling | 588 { "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling |
| 597 { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Til
ing | 589 { "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Til
ing |
| 598 { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Til
ing | 590 { "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Til
ing |
| 599 { "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling | 591 { "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling |
| 600 { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling | 592 { "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling |
| 601 { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling | 593 { "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling |
| 602 }; | 594 }; |
| 603 static_assert((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum), | 595 static_assert((SK_ARRAY_COUNT(gTilingInfos) == kLast_TilingMode_Enum), |
| 604 "Incomplete_tiling_labels"); | 596 "Incomplete_tiling_labels"); |
| 605 | 597 |
| 606 SkSize SampleWindow::tileSize() const { | 598 SkSize SampleWindow::tileSize() const { |
| 607 SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum); | 599 SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum); |
| 608 const struct TilingInfo* info = gTilingInfo + fTilingMode; | 600 const struct TilingInfo* info = &gTilingInfos[fTilingMode]; |
| 609 return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w
, | 601 return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w
, |
| 610 info->h > SK_Scalar1 ? info->h : this->height() * info->
h); | 602 info->h > SK_Scalar1 ? info->h : this->height() * info->
h); |
| 611 } | 603 } |
| 612 ////////////////////////////////////////////////////////////////////////////// | 604 ////////////////////////////////////////////////////////////////////////////// |
| 613 | 605 |
| 614 static SkView* curr_view(SkWindow* wind) { | 606 static SkView* curr_view(SkWindow* wind) { |
| 615 SkView::F2BIter iter(wind); | 607 SkView::F2BIter iter(wind); |
| 616 return iter.next(); | 608 return iter.next(); |
| 617 } | 609 } |
| 618 | 610 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 649 } |
| 658 | 650 |
| 659 void SampleWindow::updatePointer(int x, int y) { | 651 void SampleWindow::updatePointer(int x, int y) { |
| 660 fMouseX = x; | 652 fMouseX = x; |
| 661 fMouseY = y; | 653 fMouseY = y; |
| 662 if (fShowZoomer) { | 654 if (fShowZoomer) { |
| 663 this->inval(nullptr); | 655 this->inval(nullptr); |
| 664 } | 656 } |
| 665 } | 657 } |
| 666 | 658 |
| 667 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
ct) { | |
| 668 static const SampleWindow::DeviceType gCT[] = { | |
| 669 SampleWindow::kRaster_DeviceType | |
| 670 #if SK_SUPPORT_GPU | |
| 671 , SampleWindow::kGPU_DeviceType | |
| 672 #if SK_ANGLE | |
| 673 , SampleWindow::kANGLE_DeviceType | |
| 674 #endif // SK_ANGLE | |
| 675 #if SK_COMMAND_BUFFER | |
| 676 , SampleWindow::kCommandBuffer_DeviceType | |
| 677 #endif // SK_COMMAND_BUFFER | |
| 678 #endif // SK_SUPPORT_GPU | |
| 679 }; | |
| 680 static_assert(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, "array_si
ze_mismatch"); | |
| 681 return gCT[ct]; | |
| 682 } | |
| 683 | |
| 684 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { | 659 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
| 685 SkView* view = (*sampleFactory)(); | 660 SkView* view = (*sampleFactory)(); |
| 686 SkString title; | 661 SkString title; |
| 687 SampleCode::RequestTitle(view, &title); | 662 SampleCode::RequestTitle(view, &title); |
| 688 view->unref(); | 663 view->unref(); |
| 689 return title; | 664 return title; |
| 690 } | 665 } |
| 691 | 666 |
| 692 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { | 667 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { |
| 693 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; | 668 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 717 } | 692 } |
| 718 } | 693 } |
| 719 | 694 |
| 720 DEFINE_string(slide, "", "Start on this sample."); | 695 DEFINE_string(slide, "", "Start on this sample."); |
| 721 DEFINE_int32(msaa, 0, "Request multisampling with this count."); | 696 DEFINE_int32(msaa, 0, "Request multisampling with this count."); |
| 722 DEFINE_string(pictureDir, "", "Read pictures from here."); | 697 DEFINE_string(pictureDir, "", "Read pictures from here."); |
| 723 DEFINE_string(picture, "", "Path to single picture."); | 698 DEFINE_string(picture, "", "Path to single picture."); |
| 724 DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to
show."); | 699 DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to
show."); |
| 725 DEFINE_bool(sort, false, "Sort samples by title."); | 700 DEFINE_bool(sort, false, "Sort samples by title."); |
| 726 DEFINE_bool(list, false, "List samples?"); | 701 DEFINE_bool(list, false, "List samples?"); |
| 727 DEFINE_bool(gpu, false, "Start up with gpu?"); | |
| 728 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec
ific names | 702 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec
ific names |
| 729 #ifdef SAMPLE_PDF_FILE_VIEWER | 703 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 730 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); | 704 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); |
| 731 #endif | 705 #endif |
| 732 | 706 |
| 707 static const char startWithHelp[] = "Start with backend. Options: raster" |
| 708 #if SK_SUPPORT_GPU |
| 709 " gpu" |
| 710 #if SK_ANGLE |
| 711 #ifdef SK_BUILD_FOR_WIN |
| 712 " angle" |
| 713 #endif |
| 714 #endif |
| 715 #if SK_COMMAND_BUFFER |
| 716 " commandbuffer" |
| 717 #endif |
| 718 #endif |
| 719 ""; |
| 720 DEFINE_string(startWith, "raster", startWithHelp); |
| 721 |
| 722 |
| 723 struct DeviceInfo { |
| 724 const char* fName; |
| 725 const char* fMenuLabel; |
| 726 SampleWindow::DeviceType fType; |
| 727 }; |
| 728 static const DeviceInfo gDeviceInfos[] = { |
| 729 { "raster", "Raster", SampleWindow::kRaster_DeviceType } |
| 730 #if SK_SUPPORT_GPU |
| 731 , { "gpu", "GPU", SampleWindow::kGPU_DeviceType } |
| 732 #if SK_ANGLE |
| 733 #ifdef SK_BUILD_FOR_WIN |
| 734 , { "angle", "ANGLE DirectX", SampleWindow::kANGLE_DeviceType } |
| 735 #endif |
| 736 #endif |
| 737 #if SK_COMMAND_BUFFER |
| 738 , { "commandbuffer", "Command Buffer", kCommandBuffer_DeviceType } |
| 739 #endif |
| 740 #endif |
| 741 }; |
| 742 |
| 733 #include "SkTaskGroup.h" | 743 #include "SkTaskGroup.h" |
| 734 | 744 |
| 735 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) | 745 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) |
| 736 : INHERITED(hwnd) | 746 : INHERITED(hwnd) |
| 737 , fDevManager(nullptr) { | 747 , fDevManager(nullptr) { |
| 738 | 748 |
| 739 SkCommandLineFlags::Parse(argc, argv); | 749 SkCommandLineFlags::Parse(argc, argv); |
| 750 for (fDeviceIndex = 0; fDeviceIndex < SK_ARRAY_COUNT(gDeviceInfos); ++fDevic
eIndex) { |
| 751 SkString name(gDeviceInfos[fDeviceIndex].fName); |
| 752 if (name.equals(FLAGS_startWith[0])) { |
| 753 break; |
| 754 } |
| 755 } |
| 756 if (fDeviceIndex == SK_ARRAY_COUNT(gDeviceInfos)) { |
| 757 SkDebugf("WARNING: can not start with unknown device %s\n", FLAGS_start
With[0]); |
| 758 fDeviceIndex = 0; |
| 759 } |
| 740 | 760 |
| 741 fCurrIndex = -1; | 761 fCurrIndex = -1; |
| 742 | 762 |
| 743 if (!FLAGS_pictureDir.isEmpty()) { | 763 if (!FLAGS_pictureDir.isEmpty()) { |
| 744 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); | 764 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); |
| 745 SkString filename; | 765 SkString filename; |
| 746 while (iter.next(&filename)) { | 766 while (iter.next(&filename)) { |
| 747 *fSamples.append() = new PictFileFactory( | 767 *fSamples.append() = new PictFileFactory( |
| 748 SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str())); | 768 SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str())); |
| 749 } | 769 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 } | 818 } |
| 799 | 819 |
| 800 if (!FLAGS_slide.isEmpty()) { | 820 if (!FLAGS_slide.isEmpty()) { |
| 801 fCurrIndex = findByTitle(FLAGS_slide[0]); | 821 fCurrIndex = findByTitle(FLAGS_slide[0]); |
| 802 if (fCurrIndex < 0) { | 822 if (fCurrIndex < 0) { |
| 803 fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); | 823 fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); |
| 804 listTitles(); | 824 listTitles(); |
| 805 } | 825 } |
| 806 } | 826 } |
| 807 | 827 |
| 808 fMSAASampleCount = FLAGS_msaa; | |
| 809 | |
| 810 if (FLAGS_list) { | 828 if (FLAGS_list) { |
| 811 listTitles(); | 829 listTitles(); |
| 812 } | 830 } |
| 813 | 831 |
| 814 if (fCurrIndex < 0) { | 832 if (fCurrIndex < 0) { |
| 815 SkString title; | 833 SkString title; |
| 816 if (readTitleFromPrefs(&title)) { | 834 if (readTitleFromPrefs(&title)) { |
| 817 fCurrIndex = findByTitle(title.c_str()); | 835 fCurrIndex = findByTitle(title.c_str()); |
| 818 } | 836 } |
| 819 } | 837 } |
| 820 | 838 |
| 821 if (fCurrIndex < 0) { | 839 if (fCurrIndex < 0) { |
| 822 fCurrIndex = 0; | 840 fCurrIndex = 0; |
| 823 } | 841 } |
| 824 | 842 |
| 825 static SkTaskGroup::Enabler enabled(-1); | 843 static SkTaskGroup::Enabler enabled(-1); |
| 826 gSampleWindow = this; | 844 gSampleWindow = this; |
| 827 | 845 |
| 828 fDeviceType = kRaster_DeviceType; | |
| 829 #if SK_SUPPORT_GPU | |
| 830 if (FLAGS_gpu) { | |
| 831 fDeviceType = kGPU_DeviceType; | |
| 832 } | |
| 833 #endif | |
| 834 | |
| 835 #if DEFAULT_TO_GPU | |
| 836 fDeviceType = kGPU_DeviceType; | |
| 837 #endif | |
| 838 #if SK_ANGLE && DEFAULT_TO_ANGLE | |
| 839 fDeviceType = kANGLE_DeviceType; | |
| 840 #endif | |
| 841 #if SK_COMMAND_BUFFER && DEFAULT_TO_COMMAND_BUFFER | |
| 842 fDeviceType = kCommandBuffer_DeviceType; | |
| 843 #endif | |
| 844 | |
| 845 fUseClip = false; | 846 fUseClip = false; |
| 846 fUsePicture = false; | 847 fUsePicture = false; |
| 847 fAnimating = false; | 848 fAnimating = false; |
| 848 fRotate = false; | 849 fRotate = false; |
| 849 fPerspAnim = false; | 850 fPerspAnim = false; |
| 850 fRequestGrabImage = false; | 851 fRequestGrabImage = false; |
| 851 fTilingMode = kNo_Tiling; | 852 fTilingMode = kNo_Tiling; |
| 852 fMeasureFPS = false; | 853 fMeasureFPS = false; |
| 853 fLCDState = SkOSMenu::kMixedState; | 854 fLCDState = SkOSMenu::kMixedState; |
| 854 fAAState = SkOSMenu::kMixedState; | 855 fAAState = SkOSMenu::kMixedState; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 869 fMagnify = false; | 870 fMagnify = false; |
| 870 | 871 |
| 871 fSaveToPdf = false; | 872 fSaveToPdf = false; |
| 872 fSaveToSKP = false; | 873 fSaveToSKP = false; |
| 873 | 874 |
| 874 int sinkID = this->getSinkID(); | 875 int sinkID = this->getSinkID(); |
| 875 fAppMenu = new SkOSMenu; | 876 fAppMenu = new SkOSMenu; |
| 876 fAppMenu->setTitle("Global Settings"); | 877 fAppMenu->setTitle("Global Settings"); |
| 877 int itemID; | 878 int itemID; |
| 878 | 879 |
| 879 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, | 880 SkTArray<const char*> deviceLabels; |
| 880 "Raster", | 881 for (auto& deviceInfo : gDeviceInfos) { |
| 881 "OpenGL", | 882 deviceLabels.push_back(deviceInfo.fMenuLabel); |
| 882 #if SK_ANGLE | 883 } |
| 883 "ANGLE", | 884 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, devic
eLabels); |
| 884 #endif | |
| 885 #if SK_COMMAND_BUFFER | |
| 886 "Command Buffer", | |
| 887 #endif | |
| 888 nullptr); | |
| 889 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); | 885 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); |
| 890 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); | 886 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); |
| 891 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); | 887 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); |
| 892 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); | 888 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); |
| 893 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); | 889 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); |
| 890 SkTArray<const char*> filterQualityLabels; |
| 891 for (auto& state : gFilterQualityStates) { |
| 892 filterQualityLabels.push_back(state.fMenuLabel); |
| 893 } |
| 894 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, | 894 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, |
| 895 gFilterQualityStates[0].fName, | 895 filterQualityLabels); |
| 896 gFilterQualityStates[1].fName, | |
| 897 gFilterQualityStates[2].fName, | |
| 898 gFilterQualityStates[3].fName, | |
| 899 gFilterQualityStates[4].fName, | |
| 900 nullptr); | |
| 901 fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); | 896 fAppMenu->assignKeyEquivalentToItem(itemID, 'n'); |
| 902 itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelS
tate); | 897 itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelS
tate); |
| 903 fAppMenu->assignKeyEquivalentToItem(itemID, 's'); | 898 fAppMenu->assignKeyEquivalentToItem(itemID, 's'); |
| 904 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, | 899 SkTArray<const char*> hintingStates; |
| 905 gHintingStates[0].name, | 900 for (auto& hintingState : gHintingStates) { |
| 906 gHintingStates[1].name, | 901 hintingStates.push_back(hintingState.fMenuLabel); |
| 907 gHintingStates[2].name, | 902 } |
| 908 gHintingStates[3].name, | 903 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, h
intingStates); |
| 909 gHintingStates[4].name, | |
| 910 nullptr); | |
| 911 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); | 904 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); |
| 912 | 905 |
| 913 itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, | 906 SkTArray<const char*> tilingInfos; |
| 914 gTilingInfo[kNo_Tiling].label, | 907 for (auto& tilingInfo : gTilingInfos) { |
| 915 gTilingInfo[kAbs_128x128_Tiling].label, | 908 tilingInfos.push_back(tilingInfo.label); |
| 916 gTilingInfo[kAbs_256x256_Tiling].label, | 909 } |
| 917 gTilingInfo[kRel_4x4_Tiling].label, | 910 itemID = fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, tilin
gInfos); |
| 918 gTilingInfo[kRel_1x16_Tiling].label, | |
| 919 gTilingInfo[kRel_16x1_Tiling].label, | |
| 920 nullptr); | |
| 921 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); | 911 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); |
| 922 | 912 |
| 923 itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); | 913 itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false); |
| 924 fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); | 914 fAppMenu->assignKeyEquivalentToItem(itemID, 'a'); |
| 925 itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); | 915 itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip); |
| 926 fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); | 916 fAppMenu->assignKeyEquivalentToItem(itemID, 'c'); |
| 927 itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); | 917 itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false); |
| 928 fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); | 918 fAppMenu->assignKeyEquivalentToItem(itemID, 'x'); |
| 929 itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); | 919 itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false); |
| 930 fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); | 920 fAppMenu->assignKeyEquivalentToItem(itemID, 'y'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 944 this->setClipToBounds(false); | 934 this->setClipToBounds(false); |
| 945 | 935 |
| 946 this->loadView((*fSamples[fCurrIndex])()); | 936 this->loadView((*fSamples[fCurrIndex])()); |
| 947 | 937 |
| 948 if (nullptr == devManager) { | 938 if (nullptr == devManager) { |
| 949 fDevManager = new DefaultDeviceManager(); | 939 fDevManager = new DefaultDeviceManager(); |
| 950 } else { | 940 } else { |
| 951 devManager->ref(); | 941 devManager->ref(); |
| 952 fDevManager = devManager; | 942 fDevManager = devManager; |
| 953 } | 943 } |
| 954 fDevManager->setUpBackend(this, fMSAASampleCount); | 944 fDeviceType = gDeviceInfos[fDeviceIndex].fType; |
| 945 fDevManager->setUpBackend(this, FLAGS_msaa); |
| 955 | 946 |
| 956 // If another constructor set our dimensions, ensure that our | 947 // If another constructor set our dimensions, ensure that our |
| 957 // onSizeChange gets called. | 948 // onSizeChange gets called. |
| 958 if (this->height() && this->width()) { | 949 if (this->height() && this->width()) { |
| 959 this->onSizeChange(); | 950 this->onSizeChange(); |
| 960 } | 951 } |
| 961 | 952 |
| 962 // can't call this synchronously, since it may require a subclass to | 953 // can't call this synchronously, since it may require a subclass to |
| 963 // to implement, or the caller may need us to have returned from the | 954 // to implement, or the caller may need us to have returned from the |
| 964 // constructor first. Hence we post an event to ourselves. | 955 // constructor first. Hence we post an event to ourselves. |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 if (evt.isType("set-curr-index")) { | 1538 if (evt.isType("set-curr-index")) { |
| 1548 this->goToSample(evt.getFast32()); | 1539 this->goToSample(evt.getFast32()); |
| 1549 return true; | 1540 return true; |
| 1550 } | 1541 } |
| 1551 if (isInvalEvent(evt)) { | 1542 if (isInvalEvent(evt)) { |
| 1552 this->inval(nullptr); | 1543 this->inval(nullptr); |
| 1553 return true; | 1544 return true; |
| 1554 } | 1545 } |
| 1555 int selected = -1; | 1546 int selected = -1; |
| 1556 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { | 1547 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { |
| 1557 this->setDeviceType((DeviceType)selected); | 1548 this->setDevice(static_cast<size_t>(selected)); |
| 1558 return true; | 1549 return true; |
| 1559 } | 1550 } |
| 1560 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { | 1551 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { |
| 1561 this->toggleSlideshow(); | 1552 this->toggleSlideshow(); |
| 1562 return true; | 1553 return true; |
| 1563 } | 1554 } |
| 1564 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || | 1555 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
| 1565 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || | 1556 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
| 1566 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || | 1557 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || |
| 1567 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || | 1558 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 } | 1742 } |
| 1752 | 1743 |
| 1753 if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni
)) { | 1744 if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni
)) { |
| 1754 this->onUpdateMenu(fAppMenu); | 1745 this->onUpdateMenu(fAppMenu); |
| 1755 this->onUpdateMenu(fSlideMenu); | 1746 this->onUpdateMenu(fSlideMenu); |
| 1756 return true; | 1747 return true; |
| 1757 } | 1748 } |
| 1758 return this->INHERITED::onHandleChar(uni); | 1749 return this->INHERITED::onHandleChar(uni); |
| 1759 } | 1750 } |
| 1760 | 1751 |
| 1761 void SampleWindow::setDeviceType(DeviceType type) { | 1752 void SampleWindow::setDevice(size_t deviceIndex) { |
| 1762 if (type == fDeviceType) | 1753 if (fDeviceIndex == deviceIndex) |
| 1763 return; | 1754 return; |
| 1764 | 1755 |
| 1765 fDevManager->tearDownBackend(this); | 1756 fDevManager->tearDownBackend(this); |
| 1766 | 1757 fDeviceIndex = deviceIndex; |
| 1767 fDeviceType = type; | 1758 fDeviceType = gDeviceInfos[fDeviceIndex].fType; |
| 1768 | 1759 fDevManager->setUpBackend(this, FLAGS_msaa); |
| 1769 fDevManager->setUpBackend(this, fMSAASampleCount); | |
| 1770 | 1760 |
| 1771 this->updateTitle(); | 1761 this->updateTitle(); |
| 1772 this->inval(nullptr); | 1762 this->inval(nullptr); |
| 1773 } | 1763 } |
| 1774 | 1764 |
| 1775 void SampleWindow::toggleSlideshow() { | 1765 void SampleWindow::toggleSlideshow() { |
| 1776 fAnimating = !fAnimating; | 1766 fAnimating = !fAnimating; |
| 1777 this->postAnimatingEvent(); | 1767 this->postAnimatingEvent(); |
| 1778 this->updateTitle(); | 1768 this->updateTitle(); |
| 1779 } | 1769 } |
| 1780 | 1770 |
| 1781 void SampleWindow::toggleRendering() { | 1771 void SampleWindow::toggleRendering() { |
| 1782 this->setDeviceType(cycle_devicetype(fDeviceType)); | 1772 this->setDevice((fDeviceIndex + 1) % SK_ARRAY_COUNT(gDeviceInfos)); |
| 1783 this->updateTitle(); | 1773 this->updateTitle(); |
| 1784 this->inval(nullptr); | 1774 this->inval(nullptr); |
| 1785 } | 1775 } |
| 1786 | 1776 |
| 1787 void SampleWindow::toggleFPS() { | 1777 void SampleWindow::toggleFPS() { |
| 1788 fMeasureFPS = !fMeasureFPS; | 1778 fMeasureFPS = !fMeasureFPS; |
| 1789 this->updateTitle(); | 1779 this->updateTitle(); |
| 1790 this->inval(nullptr); | 1780 this->inval(nullptr); |
| 1791 } | 1781 } |
| 1792 | 1782 |
| 1793 void SampleWindow::toggleDistanceFieldFonts() { | 1783 void SampleWindow::toggleDistanceFieldFonts() { |
| 1794 // reset backend | 1784 // reset backend |
| 1795 fDevManager->tearDownBackend(this); | 1785 fDevManager->tearDownBackend(this); |
| 1796 fDevManager->setUpBackend(this, fMSAASampleCount); | 1786 fDevManager->setUpBackend(this, FLAGS_msaa); |
| 1797 | 1787 |
| 1798 SkSurfaceProps props = this->getSurfaceProps(); | 1788 SkSurfaceProps props = this->getSurfaceProps(); |
| 1799 uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_
Flag; | 1789 uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_
Flag; |
| 1800 this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); | 1790 this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); |
| 1801 | 1791 |
| 1802 this->updateTitle(); | 1792 this->updateTitle(); |
| 1803 this->inval(nullptr); | 1793 this->inval(nullptr); |
| 1804 } | 1794 } |
| 1805 | 1795 |
| 1806 #include "SkDumpCanvas.h" | 1796 #include "SkDumpCanvas.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 this->attachChildToFront(view)->unref(); | 1928 this->attachChildToFront(view)->unref(); |
| 1939 view->setSize(this->width(), this->height()); | 1929 view->setSize(this->width(), this->height()); |
| 1940 | 1930 |
| 1941 //repopulate the slide menu when a view is loaded | 1931 //repopulate the slide menu when a view is loaded |
| 1942 fSlideMenu->reset(); | 1932 fSlideMenu->reset(); |
| 1943 | 1933 |
| 1944 this->onUpdateMenu(fSlideMenu); | 1934 this->onUpdateMenu(fSlideMenu); |
| 1945 this->updateTitle(); | 1935 this->updateTitle(); |
| 1946 } | 1936 } |
| 1947 | 1937 |
| 1948 static const char* gDeviceTypePrefix[] = { | |
| 1949 "raster: ", | |
| 1950 #if SK_SUPPORT_GPU | |
| 1951 "opengl: ", | |
| 1952 #if SK_ANGLE | |
| 1953 "angle: ", | |
| 1954 #endif // SK_ANGLE | |
| 1955 #if SK_COMMAND_BUFFER | |
| 1956 "command buffer: ", | |
| 1957 #endif // SK_COMMAND_BUFFER | |
| 1958 #endif // SK_SUPPORT_GPU | |
| 1959 }; | |
| 1960 static_assert(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt, | |
| 1961 "array_size_mismatch"); | |
| 1962 | |
| 1963 static const char* trystate_str(SkOSMenu::TriState state, | 1938 static const char* trystate_str(SkOSMenu::TriState state, |
| 1964 const char trueStr[], const char falseStr[]) { | 1939 const char trueStr[], const char falseStr[]) { |
| 1965 if (SkOSMenu::kOnState == state) { | 1940 if (SkOSMenu::kOnState == state) { |
| 1966 return trueStr; | 1941 return trueStr; |
| 1967 } else if (SkOSMenu::kOffState == state) { | 1942 } else if (SkOSMenu::kOffState == state) { |
| 1968 return falseStr; | 1943 return falseStr; |
| 1969 } | 1944 } |
| 1970 return nullptr; | 1945 return nullptr; |
| 1971 } | 1946 } |
| 1972 | 1947 |
| 1973 bool SampleWindow::getRawTitle(SkString* title) { | 1948 bool SampleWindow::getRawTitle(SkString* title) { |
| 1974 return curr_title(this, title); | 1949 return curr_title(this, title); |
| 1975 } | 1950 } |
| 1976 | 1951 |
| 1977 void SampleWindow::updateTitle() { | 1952 void SampleWindow::updateTitle() { |
| 1978 SkString title; | 1953 SkString title; |
| 1979 if (!this->getRawTitle(&title)) { | 1954 if (!this->getRawTitle(&title)) { |
| 1980 title.set("<unknown>"); | 1955 title.set("<unknown>"); |
| 1981 } | 1956 } |
| 1957 title.prependf(" %s: ", gDeviceInfos[fDeviceIndex].fName); |
| 1982 | 1958 |
| 1983 title.prepend(gDeviceTypePrefix[fDeviceType]); | |
| 1984 | |
| 1985 title.prepend(" "); | |
| 1986 title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType())); | 1959 title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType())); |
| 1987 | 1960 |
| 1988 if (fTilingMode != kNo_Tiling) { | 1961 if (fTilingMode != kNo_Tiling) { |
| 1989 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); | 1962 title.prependf("<T: %s> ", gTilingInfos[fTilingMode].label); |
| 1990 } | 1963 } |
| 1991 if (fAnimating) { | 1964 if (fAnimating) { |
| 1992 title.prepend("<A> "); | 1965 title.prepend("<A> "); |
| 1993 } | 1966 } |
| 1994 if (fRotate) { | 1967 if (fRotate) { |
| 1995 title.prepend("<R> "); | 1968 title.prepend("<R> "); |
| 1996 } | 1969 } |
| 1997 if (fPerspAnim) { | 1970 if (fPerspAnim) { |
| 1998 title.prepend("<K> "); | 1971 title.prepend("<K> "); |
| 1999 } | 1972 } |
| 2000 if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDeviceIndependentF
onts_Flag) { | 1973 if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDeviceIndependentF
onts_Flag) { |
| 2001 title.prepend("<DIF> "); | 1974 title.prepend("<DIF> "); |
| 2002 } | 1975 } |
| 2003 if (fUsePicture) { | 1976 if (fUsePicture) { |
| 2004 title.prepend("<P> "); | 1977 title.prepend("<P> "); |
| 2005 } | 1978 } |
| 2006 | 1979 |
| 2007 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); | 1980 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); |
| 2008 title.prepend(trystate_str(fAAState, "AA ", "aa ")); | 1981 title.prepend(trystate_str(fAAState, "AA ", "aa ")); |
| 2009 title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel); | 1982 title.prepend(gFilterQualityStates[fFilterQualityIndex].fTitleLabel); |
| 2010 title.prepend(trystate_str(fSubpixelState, "S ", "s ")); | 1983 title.prepend(trystate_str(fSubpixelState, "S ", "s ")); |
| 2011 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr); | 1984 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr); |
| 2012 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr); | 1985 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr); |
| 2013 title.prepend(gHintingStates[fHintingState].label); | 1986 title.prepend(gHintingStates[fHintingState].fTitleLabel); |
| 2014 | 1987 |
| 2015 if (fZoomLevel) { | 1988 if (fZoomLevel) { |
| 2016 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); | 1989 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
| 2017 } | 1990 } |
| 2018 | 1991 |
| 2019 if (fMeasureFPS) { | 1992 if (fMeasureFPS) { |
| 2020 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); | 1993 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
| 2021 } | 1994 } |
| 2022 | 1995 |
| 2023 #if SK_SUPPORT_GPU | 1996 #if SK_SUPPORT_GPU |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 #ifdef SK_BUILD_FOR_MAC | 2238 #ifdef SK_BUILD_FOR_MAC |
| 2266 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2239 setenv("ANDROID_ROOT", "/android/device/data", 0); |
| 2267 #endif | 2240 #endif |
| 2268 SkGraphics::Init(); | 2241 SkGraphics::Init(); |
| 2269 SkEvent::Init(); | 2242 SkEvent::Init(); |
| 2270 } | 2243 } |
| 2271 | 2244 |
| 2272 void application_term() { | 2245 void application_term() { |
| 2273 SkEvent::Term(); | 2246 SkEvent::Term(); |
| 2274 } | 2247 } |
| OLD | NEW |