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 24 matching lines...) Expand all Loading... |
35 #if SK_SUPPORT_GPU | 35 #if SK_SUPPORT_GPU |
36 #include "gl/GrGLInterface.h" | 36 #include "gl/GrGLInterface.h" |
37 #include "gl/GrGLUtil.h" | 37 #include "gl/GrGLUtil.h" |
38 #include "GrRenderTarget.h" | 38 #include "GrRenderTarget.h" |
39 #include "GrContext.h" | 39 #include "GrContext.h" |
40 #include "SkGpuDevice.h" | 40 #include "SkGpuDevice.h" |
41 #else | 41 #else |
42 class GrContext; | 42 class GrContext; |
43 #endif | 43 #endif |
44 | 44 |
| 45 const struct { |
| 46 SkColorType fColorType; |
| 47 SkColorProfileType fProfileType; |
| 48 const char* fName; |
| 49 } gConfig[] = { |
| 50 { kN32_SkColorType, kLinear_SkColorProfileType, "L32" }, |
| 51 { kN32_SkColorType, kSRGB_SkColorProfileType, "S32" }, |
| 52 { kRGBA_F16_SkColorType, kLinear_SkColorProfileType, "F16" }, |
| 53 }; |
| 54 |
| 55 static const char* find_config_name(const SkImageInfo& info) { |
| 56 for (const auto& config : gConfig) { |
| 57 if (config.fColorType == info.colorType() && config.fProfileType == info
.profileType()) { |
| 58 return config.fName; |
| 59 } |
| 60 } |
| 61 return "???"; |
| 62 } |
| 63 |
45 // Should be 3x + 1 | 64 // Should be 3x + 1 |
46 #define kMaxFatBitsScale 28 | 65 #define kMaxFatBitsScale 28 |
47 | 66 |
48 extern SampleView* CreateSamplePictFileView(const char filename[]); | 67 extern SampleView* CreateSamplePictFileView(const char filename[]); |
49 | 68 |
50 class PictFileFactory : public SkViewFactory { | 69 class PictFileFactory : public SkViewFactory { |
51 SkString fFilename; | 70 SkString fFilename; |
52 public: | 71 public: |
53 PictFileFactory(const SkString& filename) : fFilename(filename) {} | 72 PictFileFactory(const SkString& filename) : fFilename(filename) {} |
54 SkView* operator() () const override { | 73 SkView* operator() () const override { |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 fMagnify = false; | 888 fMagnify = false; |
870 | 889 |
871 fSaveToPdf = false; | 890 fSaveToPdf = false; |
872 fSaveToSKP = false; | 891 fSaveToSKP = false; |
873 | 892 |
874 int sinkID = this->getSinkID(); | 893 int sinkID = this->getSinkID(); |
875 fAppMenu = new SkOSMenu; | 894 fAppMenu = new SkOSMenu; |
876 fAppMenu->setTitle("Global Settings"); | 895 fAppMenu->setTitle("Global Settings"); |
877 int itemID; | 896 int itemID; |
878 | 897 |
| 898 itemID = fAppMenu->appendList("ColorType", "ColorType", sinkID, 0, |
| 899 gConfig[0].fName, gConfig[1].fName, gConfig[2]
.fName, nullptr); |
| 900 fAppMenu->assignKeyEquivalentToItem(itemID, 'C'); |
| 901 |
879 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, | 902 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
880 "Raster", | 903 "Raster", |
881 "OpenGL", | 904 "OpenGL", |
882 #if SK_ANGLE | 905 #if SK_ANGLE |
883 "ANGLE", | 906 "ANGLE", |
884 #endif | 907 #endif |
885 #if SK_COMMAND_BUFFER | 908 #if SK_COMMAND_BUFFER |
886 "Command Buffer", | 909 "Command Buffer", |
887 #endif | 910 #endif |
888 nullptr); | 911 nullptr); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 } | 1573 } |
1551 if (isInvalEvent(evt)) { | 1574 if (isInvalEvent(evt)) { |
1552 this->inval(nullptr); | 1575 this->inval(nullptr); |
1553 return true; | 1576 return true; |
1554 } | 1577 } |
1555 int selected = -1; | 1578 int selected = -1; |
1556 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { | 1579 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { |
1557 this->setDeviceType((DeviceType)selected); | 1580 this->setDeviceType((DeviceType)selected); |
1558 return true; | 1581 return true; |
1559 } | 1582 } |
| 1583 if (SkOSMenu::FindListIndex(evt, "ColorType", &selected)) { |
| 1584 this->setDeviceColorType(gConfig[selected].fColorType, gConfig[selected]
.fProfileType); |
| 1585 return true; |
| 1586 } |
1560 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { | 1587 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { |
1561 this->toggleSlideshow(); | 1588 this->toggleSlideshow(); |
1562 return true; | 1589 return true; |
1563 } | 1590 } |
1564 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || | 1591 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
1565 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || | 1592 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
1566 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || | 1593 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || |
1567 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || | 1594 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || |
1568 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || | 1595 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || |
1569 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || | 1596 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 this->onUpdateMenu(fAppMenu); | 1781 this->onUpdateMenu(fAppMenu); |
1755 this->onUpdateMenu(fSlideMenu); | 1782 this->onUpdateMenu(fSlideMenu); |
1756 return true; | 1783 return true; |
1757 } | 1784 } |
1758 return this->INHERITED::onHandleChar(uni); | 1785 return this->INHERITED::onHandleChar(uni); |
1759 } | 1786 } |
1760 | 1787 |
1761 void SampleWindow::setDeviceType(DeviceType type) { | 1788 void SampleWindow::setDeviceType(DeviceType type) { |
1762 if (type == fDeviceType) | 1789 if (type == fDeviceType) |
1763 return; | 1790 return; |
1764 | 1791 |
1765 fDevManager->tearDownBackend(this); | 1792 fDevManager->tearDownBackend(this); |
1766 | 1793 |
1767 fDeviceType = type; | 1794 fDeviceType = type; |
1768 | 1795 |
1769 fDevManager->setUpBackend(this, fMSAASampleCount); | 1796 fDevManager->setUpBackend(this, fMSAASampleCount); |
1770 | 1797 |
1771 this->updateTitle(); | 1798 this->updateTitle(); |
1772 this->inval(nullptr); | 1799 this->inval(nullptr); |
1773 } | 1800 } |
| 1801 |
| 1802 void SampleWindow::setDeviceColorType(SkColorType ct, SkColorProfileType pt) { |
| 1803 this->setColorType(ct, pt); |
| 1804 |
| 1805 fDevManager->tearDownBackend(this); |
| 1806 |
| 1807 fDevManager->setUpBackend(this, fMSAASampleCount); |
| 1808 |
| 1809 this->updateTitle(); |
| 1810 this->inval(nullptr); |
| 1811 } |
1774 | 1812 |
1775 void SampleWindow::toggleSlideshow() { | 1813 void SampleWindow::toggleSlideshow() { |
1776 fAnimating = !fAnimating; | 1814 fAnimating = !fAnimating; |
1777 this->postAnimatingEvent(); | 1815 this->postAnimatingEvent(); |
1778 this->updateTitle(); | 1816 this->updateTitle(); |
1779 } | 1817 } |
1780 | 1818 |
1781 void SampleWindow::toggleRendering() { | 1819 void SampleWindow::toggleRendering() { |
1782 this->setDeviceType(cycle_devicetype(fDeviceType)); | 1820 this->setDeviceType(cycle_devicetype(fDeviceType)); |
1783 this->updateTitle(); | 1821 this->updateTitle(); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2020 #if SK_SUPPORT_GPU | 2058 #if SK_SUPPORT_GPU |
2021 if (IsGpuDeviceType(fDeviceType) && | 2059 if (IsGpuDeviceType(fDeviceType) && |
2022 fDevManager && | 2060 fDevManager && |
2023 fDevManager->getGrRenderTarget() && | 2061 fDevManager->getGrRenderTarget() && |
2024 fDevManager->getGrRenderTarget()->numColorSamples() > 0) { | 2062 fDevManager->getGrRenderTarget()->numColorSamples() > 0) { |
2025 title.appendf(" [MSAA: %d]", | 2063 title.appendf(" [MSAA: %d]", |
2026 fDevManager->getGrRenderTarget()->numColorSamples()); | 2064 fDevManager->getGrRenderTarget()->numColorSamples()); |
2027 } | 2065 } |
2028 #endif | 2066 #endif |
2029 | 2067 |
| 2068 title.appendf(" %s", find_config_name(this->info())); |
| 2069 |
2030 this->setTitle(title.c_str()); | 2070 this->setTitle(title.c_str()); |
2031 } | 2071 } |
2032 | 2072 |
2033 void SampleWindow::onSizeChange() { | 2073 void SampleWindow::onSizeChange() { |
2034 this->INHERITED::onSizeChange(); | 2074 this->INHERITED::onSizeChange(); |
2035 | 2075 |
2036 SkView::F2BIter iter(this); | 2076 SkView::F2BIter iter(this); |
2037 SkView* view = iter.next(); | 2077 SkView* view = iter.next(); |
2038 view->setSize(this->width(), this->height()); | 2078 view->setSize(this->width(), this->height()); |
2039 | 2079 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 #ifdef SK_BUILD_FOR_MAC | 2302 #ifdef SK_BUILD_FOR_MAC |
2263 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2303 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2264 #endif | 2304 #endif |
2265 SkGraphics::Init(); | 2305 SkGraphics::Init(); |
2266 SkEvent::Init(); | 2306 SkEvent::Init(); |
2267 } | 2307 } |
2268 | 2308 |
2269 void application_term() { | 2309 void application_term() { |
2270 SkEvent::Term(); | 2310 SkEvent::Term(); |
2271 } | 2311 } |
OLD | NEW |