| 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" |
| 11 #include "Resources.h" | 11 #include "Resources.h" |
| 12 #include "SampleCode.h" | 12 #include "SampleCode.h" |
| 13 #include "SamplePipeControllers.h" | |
| 14 #include "SkAnimTimer.h" | 13 #include "SkAnimTimer.h" |
| 15 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
| 16 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
| 17 #include "SkData.h" | 16 #include "SkData.h" |
| 18 #include "SkDevice.h" | 17 #include "SkDevice.h" |
| 19 #include "SkDocument.h" | 18 #include "SkDocument.h" |
| 20 #include "SkGPipe.h" | |
| 21 #include "SkGraphics.h" | 19 #include "SkGraphics.h" |
| 22 #include "SkImageEncoder.h" | 20 #include "SkImageEncoder.h" |
| 23 #include "SkOSFile.h" | 21 #include "SkOSFile.h" |
| 24 #include "SkPaint.h" | 22 #include "SkPaint.h" |
| 25 #include "SkPaintFilterCanvas.h" | 23 #include "SkPaintFilterCanvas.h" |
| 26 #include "SkPicture.h" | 24 #include "SkPicture.h" |
| 27 #include "SkPictureRecorder.h" | 25 #include "SkPictureRecorder.h" |
| 28 #include "SkStream.h" | 26 #include "SkStream.h" |
| 29 #include "SkSurface.h" | 27 #include "SkSurface.h" |
| 30 #include "SkTemplates.h" | 28 #include "SkTemplates.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 class PdfFileViewerFactory : public SkViewFactory { | 62 class PdfFileViewerFactory : public SkViewFactory { |
| 65 SkString fFilename; | 63 SkString fFilename; |
| 66 public: | 64 public: |
| 67 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} | 65 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} |
| 68 SkView* operator() () const override { | 66 SkView* operator() () const override { |
| 69 return CreateSamplePdfFileViewer(fFilename.c_str()); | 67 return CreateSamplePdfFileViewer(fFilename.c_str()); |
| 70 } | 68 } |
| 71 }; | 69 }; |
| 72 #endif // SAMPLE_PDF_FILE_VIEWER | 70 #endif // SAMPLE_PDF_FILE_VIEWER |
| 73 | 71 |
| 74 #define PIPE_FILEx | |
| 75 #ifdef PIPE_FILE | |
| 76 #define FILE_PATH "/path/to/drawing.data" | |
| 77 #endif | |
| 78 | |
| 79 #define PIPE_NETx | |
| 80 #ifdef PIPE_NET | |
| 81 #include "SkSockets.h" | |
| 82 SkTCPServer gServer; | |
| 83 #endif | |
| 84 | |
| 85 #if SK_COMMAND_BUFFER | 72 #if SK_COMMAND_BUFFER |
| 86 #define DEFAULT_TO_COMMAND_BUFFER 1 | 73 #define DEFAULT_TO_COMMAND_BUFFER 1 |
| 87 #elif SK_ANGLE | 74 #elif SK_ANGLE |
| 88 //#define DEFAULT_TO_ANGLE 1 | 75 //#define DEFAULT_TO_ANGLE 1 |
| 89 #else | 76 #else |
| 90 #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU | 77 #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU |
| 91 #endif | 78 #endif |
| 92 | 79 |
| 93 #define ANIMATING_EVENTTYPE "nextSample" | 80 #define ANIMATING_EVENTTYPE "nextSample" |
| 94 #define ANIMATING_DELAY 250 | 81 #define ANIMATING_DELAY 250 |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 815 } |
| 829 } | 816 } |
| 830 | 817 |
| 831 if (fCurrIndex < 0) { | 818 if (fCurrIndex < 0) { |
| 832 fCurrIndex = 0; | 819 fCurrIndex = 0; |
| 833 } | 820 } |
| 834 | 821 |
| 835 static SkTaskGroup::Enabler enabled(-1); | 822 static SkTaskGroup::Enabler enabled(-1); |
| 836 gSampleWindow = this; | 823 gSampleWindow = this; |
| 837 | 824 |
| 838 #ifdef PIPE_FILE | |
| 839 //Clear existing file or create file if it doesn't exist | |
| 840 FILE* f = fopen(FILE_PATH, "wb"); | |
| 841 fclose(f); | |
| 842 #endif | |
| 843 | |
| 844 fDeviceType = kRaster_DeviceType; | 825 fDeviceType = kRaster_DeviceType; |
| 845 #if SK_SUPPORT_GPU | 826 #if SK_SUPPORT_GPU |
| 846 if (FLAGS_gpu) { | 827 if (FLAGS_gpu) { |
| 847 fDeviceType = kGPU_DeviceType; | 828 fDeviceType = kGPU_DeviceType; |
| 848 } | 829 } |
| 849 #endif | 830 #endif |
| 850 | 831 |
| 851 #if DEFAULT_TO_GPU | 832 #if DEFAULT_TO_GPU |
| 852 fDeviceType = kGPU_DeviceType; | 833 fDeviceType = kGPU_DeviceType; |
| 853 #endif | 834 #endif |
| 854 #if SK_ANGLE && DEFAULT_TO_ANGLE | 835 #if SK_ANGLE && DEFAULT_TO_ANGLE |
| 855 fDeviceType = kANGLE_DeviceType; | 836 fDeviceType = kANGLE_DeviceType; |
| 856 #endif | 837 #endif |
| 857 #if SK_COMMAND_BUFFER && DEFAULT_TO_COMMAND_BUFFER | 838 #if SK_COMMAND_BUFFER && DEFAULT_TO_COMMAND_BUFFER |
| 858 fDeviceType = kCommandBuffer_DeviceType; | 839 fDeviceType = kCommandBuffer_DeviceType; |
| 859 #endif | 840 #endif |
| 860 | 841 |
| 861 fUseClip = false; | 842 fUseClip = false; |
| 862 fUseMPD = false; | 843 fUseMPD = false; |
| 863 fAnimating = false; | 844 fAnimating = false; |
| 864 fRotate = false; | 845 fRotate = false; |
| 865 fPerspAnim = false; | 846 fPerspAnim = false; |
| 866 fRequestGrabImage = false; | 847 fRequestGrabImage = false; |
| 867 fPipeState = SkOSMenu::kOffState; | |
| 868 fTilingMode = kNo_Tiling; | 848 fTilingMode = kNo_Tiling; |
| 869 fMeasureFPS = false; | 849 fMeasureFPS = false; |
| 870 fLCDState = SkOSMenu::kMixedState; | 850 fLCDState = SkOSMenu::kMixedState; |
| 871 fAAState = SkOSMenu::kMixedState; | 851 fAAState = SkOSMenu::kMixedState; |
| 872 fSubpixelState = SkOSMenu::kMixedState; | 852 fSubpixelState = SkOSMenu::kMixedState; |
| 873 fHintingState = 0; | 853 fHintingState = 0; |
| 874 fFilterQualityIndex = 0; | 854 fFilterQualityIndex = 0; |
| 875 fFlipAxis = 0; | 855 fFlipAxis = 0; |
| 876 fScrollTestX = fScrollTestY = 0; | 856 fScrollTestX = fScrollTestY = 0; |
| 877 | 857 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 fAppMenu->assignKeyEquivalentToItem(itemID, 's'); | 900 fAppMenu->assignKeyEquivalentToItem(itemID, 's'); |
| 921 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, | 901 itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState, |
| 922 gHintingStates[0].name, | 902 gHintingStates[0].name, |
| 923 gHintingStates[1].name, | 903 gHintingStates[1].name, |
| 924 gHintingStates[2].name, | 904 gHintingStates[2].name, |
| 925 gHintingStates[3].name, | 905 gHintingStates[3].name, |
| 926 gHintingStates[4].name, | 906 gHintingStates[4].name, |
| 927 nullptr); | 907 nullptr); |
| 928 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); | 908 fAppMenu->assignKeyEquivalentToItem(itemID, 'h'); |
| 929 | 909 |
| 930 fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID, | |
| 931 fPipeState); | |
| 932 fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P'); | |
| 933 | |
| 934 itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, | 910 itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode, |
| 935 gTilingInfo[kNo_Tiling].label, | 911 gTilingInfo[kNo_Tiling].label, |
| 936 gTilingInfo[kAbs_128x128_Tiling].label, | 912 gTilingInfo[kAbs_128x128_Tiling].label, |
| 937 gTilingInfo[kAbs_256x256_Tiling].label, | 913 gTilingInfo[kAbs_256x256_Tiling].label, |
| 938 gTilingInfo[kRel_4x4_Tiling].label, | 914 gTilingInfo[kRel_4x4_Tiling].label, |
| 939 gTilingInfo[kRel_1x16_Tiling].label, | 915 gTilingInfo[kRel_1x16_Tiling].label, |
| 940 gTilingInfo[kRel_16x1_Tiling].label, | 916 gTilingInfo[kRel_16x1_Tiling].label, |
| 941 nullptr); | 917 nullptr); |
| 942 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); | 918 fAppMenu->assignKeyEquivalentToItem(itemID, 't'); |
| 943 | 919 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 } | 1593 } |
| 1618 if (isInvalEvent(evt)) { | 1594 if (isInvalEvent(evt)) { |
| 1619 this->inval(nullptr); | 1595 this->inval(nullptr); |
| 1620 return true; | 1596 return true; |
| 1621 } | 1597 } |
| 1622 int selected = -1; | 1598 int selected = -1; |
| 1623 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { | 1599 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { |
| 1624 this->setDeviceType((DeviceType)selected); | 1600 this->setDeviceType((DeviceType)selected); |
| 1625 return true; | 1601 return true; |
| 1626 } | 1602 } |
| 1627 if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) { | |
| 1628 #ifdef PIPE_NET | |
| 1629 if (!fPipeState != SkOSMenu::kOnState) | |
| 1630 gServer.disconnectAll(); | |
| 1631 #endif | |
| 1632 (void)SampleView::SetUsePipe(curr_view(this), fPipeState); | |
| 1633 this->updateTitle(); | |
| 1634 this->inval(nullptr); | |
| 1635 return true; | |
| 1636 } | |
| 1637 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { | 1603 if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) { |
| 1638 this->toggleSlideshow(); | 1604 this->toggleSlideshow(); |
| 1639 return true; | 1605 return true; |
| 1640 } | 1606 } |
| 1641 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || | 1607 if (SkOSMenu::FindTriState(evt, "AA", &fAAState) || |
| 1642 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || | 1608 SkOSMenu::FindTriState(evt, "LCD", &fLCDState) || |
| 1643 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || | 1609 SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) || |
| 1644 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || | 1610 SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) || |
| 1645 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || | 1611 SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) || |
| 1646 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || | 1612 SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) || |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 } | 1977 } |
| 2012 | 1978 |
| 2013 view->setVisibleP(true); | 1979 view->setVisibleP(true); |
| 2014 view->setClipToBounds(false); | 1980 view->setClipToBounds(false); |
| 2015 this->attachChildToFront(view)->unref(); | 1981 this->attachChildToFront(view)->unref(); |
| 2016 view->setSize(this->width(), this->height()); | 1982 view->setSize(this->width(), this->height()); |
| 2017 | 1983 |
| 2018 //repopulate the slide menu when a view is loaded | 1984 //repopulate the slide menu when a view is loaded |
| 2019 fSlideMenu->reset(); | 1985 fSlideMenu->reset(); |
| 2020 | 1986 |
| 2021 (void)SampleView::SetUsePipe(view, fPipeState); | |
| 2022 if (SampleView::IsSampleView(view)) { | |
| 2023 SampleView* sampleView = (SampleView*)view; | |
| 2024 sampleView->requestMenu(fSlideMenu); | |
| 2025 sampleView->onTileSizeChanged(this->tileSize()); | |
| 2026 } | |
| 2027 this->onUpdateMenu(fSlideMenu); | 1987 this->onUpdateMenu(fSlideMenu); |
| 2028 this->updateTitle(); | 1988 this->updateTitle(); |
| 2029 } | 1989 } |
| 2030 | 1990 |
| 2031 static const char* gDeviceTypePrefix[] = { | 1991 static const char* gDeviceTypePrefix[] = { |
| 2032 "raster: ", | 1992 "raster: ", |
| 2033 #if SK_SUPPORT_GPU | 1993 #if SK_SUPPORT_GPU |
| 2034 "opengl: ", | 1994 "opengl: ", |
| 2035 #if SK_ANGLE | 1995 #if SK_ANGLE |
| 2036 "angle: ", | 1996 "angle: ", |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2096 title.prepend(gHintingStates[fHintingState].label); | 2056 title.prepend(gHintingStates[fHintingState].label); |
| 2097 | 2057 |
| 2098 if (fZoomLevel) { | 2058 if (fZoomLevel) { |
| 2099 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); | 2059 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
| 2100 } | 2060 } |
| 2101 | 2061 |
| 2102 if (fMeasureFPS) { | 2062 if (fMeasureFPS) { |
| 2103 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); | 2063 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
| 2104 } | 2064 } |
| 2105 | 2065 |
| 2106 SkView* view = curr_view(this); | |
| 2107 if (SampleView::IsSampleView(view)) { | |
| 2108 switch (fPipeState) { | |
| 2109 case SkOSMenu::kOnState: | |
| 2110 title.prepend("<Pipe> "); | |
| 2111 break; | |
| 2112 case SkOSMenu::kMixedState: | |
| 2113 title.prepend("<Tiled Pipe> "); | |
| 2114 break; | |
| 2115 | |
| 2116 default: | |
| 2117 break; | |
| 2118 } | |
| 2119 title.prepend("! "); | |
| 2120 } | |
| 2121 | |
| 2122 #if SK_SUPPORT_GPU | 2066 #if SK_SUPPORT_GPU |
| 2123 if (IsGpuDeviceType(fDeviceType) && | 2067 if (IsGpuDeviceType(fDeviceType) && |
| 2124 fDevManager && | 2068 fDevManager && |
| 2125 fDevManager->getGrRenderTarget() && | 2069 fDevManager->getGrRenderTarget() && |
| 2126 fDevManager->getGrRenderTarget()->numColorSamples() > 0) { | 2070 fDevManager->getGrRenderTarget()->numColorSamples() > 0) { |
| 2127 title.appendf(" [MSAA: %d]", | 2071 title.appendf(" [MSAA: %d]", |
| 2128 fDevManager->getGrRenderTarget()->numColorSamples()); | 2072 fDevManager->getGrRenderTarget()->numColorSamples()); |
| 2129 } | 2073 } |
| 2130 #endif | 2074 #endif |
| 2131 | 2075 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 | 2118 |
| 2175 if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) { | 2119 if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) { |
| 2176 ((SampleView*)view)->onTileSizeChanged(this->tileSize()); | 2120 ((SampleView*)view)->onTileSizeChanged(this->tileSize()); |
| 2177 } | 2121 } |
| 2178 } | 2122 } |
| 2179 | 2123 |
| 2180 /////////////////////////////////////////////////////////////////////////////// | 2124 /////////////////////////////////////////////////////////////////////////////// |
| 2181 | 2125 |
| 2182 static const char is_sample_view_tag[] = "sample-is-sample-view"; | 2126 static const char is_sample_view_tag[] = "sample-is-sample-view"; |
| 2183 static const char repeat_count_tag[] = "sample-set-repeat-count"; | 2127 static const char repeat_count_tag[] = "sample-set-repeat-count"; |
| 2184 static const char set_use_pipe_tag[] = "sample-set-use-pipe"; | |
| 2185 | 2128 |
| 2186 bool SampleView::IsSampleView(SkView* view) { | 2129 bool SampleView::IsSampleView(SkView* view) { |
| 2187 SkEvent evt(is_sample_view_tag); | 2130 SkEvent evt(is_sample_view_tag); |
| 2188 return view->doQuery(&evt); | 2131 return view->doQuery(&evt); |
| 2189 } | 2132 } |
| 2190 | 2133 |
| 2191 bool SampleView::SetRepeatDraw(SkView* view, int count) { | 2134 bool SampleView::SetRepeatDraw(SkView* view, int count) { |
| 2192 SkEvent evt(repeat_count_tag); | 2135 SkEvent evt(repeat_count_tag); |
| 2193 evt.setFast32(count); | 2136 evt.setFast32(count); |
| 2194 return view->doEvent(evt); | 2137 return view->doEvent(evt); |
| 2195 } | 2138 } |
| 2196 | 2139 |
| 2197 bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) { | |
| 2198 SkEvent evt; | |
| 2199 evt.setS32(set_use_pipe_tag, state); | |
| 2200 return view->doEvent(evt); | |
| 2201 } | |
| 2202 | |
| 2203 bool SampleView::onEvent(const SkEvent& evt) { | 2140 bool SampleView::onEvent(const SkEvent& evt) { |
| 2204 if (evt.isType(repeat_count_tag)) { | 2141 if (evt.isType(repeat_count_tag)) { |
| 2205 fRepeatCount = evt.getFast32(); | 2142 fRepeatCount = evt.getFast32(); |
| 2206 return true; | 2143 return true; |
| 2207 } | 2144 } |
| 2208 | |
| 2209 int32_t pipeHolder; | |
| 2210 if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { | |
| 2211 fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder); | |
| 2212 return true; | |
| 2213 } | |
| 2214 | |
| 2215 return this->INHERITED::onEvent(evt); | 2145 return this->INHERITED::onEvent(evt); |
| 2216 } | 2146 } |
| 2217 | 2147 |
| 2218 bool SampleView::onQuery(SkEvent* evt) { | 2148 bool SampleView::onQuery(SkEvent* evt) { |
| 2219 if (evt->isType(is_sample_view_tag)) { | 2149 if (evt->isType(is_sample_view_tag)) { |
| 2220 return true; | 2150 return true; |
| 2221 } | 2151 } |
| 2222 return this->INHERITED::onQuery(evt); | 2152 return this->INHERITED::onQuery(evt); |
| 2223 } | 2153 } |
| 2224 | 2154 |
| 2225 | |
| 2226 class SimplePC : public SkGPipeController { | |
| 2227 public: | |
| 2228 SimplePC(SkCanvas* target); | |
| 2229 ~SimplePC(); | |
| 2230 | |
| 2231 virtual void* requestBlock(size_t minRequest, size_t* actual); | |
| 2232 virtual void notifyWritten(size_t bytes); | |
| 2233 | |
| 2234 private: | |
| 2235 SkGPipeReader fReader; | |
| 2236 void* fBlock; | |
| 2237 size_t fBlockSize; | |
| 2238 size_t fBytesWritten; | |
| 2239 int fAtomsWritten; | |
| 2240 SkGPipeReader::Status fStatus; | |
| 2241 | |
| 2242 size_t fTotalWritten; | |
| 2243 }; | |
| 2244 | |
| 2245 SimplePC::SimplePC(SkCanvas* target) : fReader(target) { | |
| 2246 fBlock = nullptr; | |
| 2247 fBlockSize = fBytesWritten = 0; | |
| 2248 fStatus = SkGPipeReader::kDone_Status; | |
| 2249 fTotalWritten = 0; | |
| 2250 fAtomsWritten = 0; | |
| 2251 fReader.setBitmapDecoder(&SkImageDecoder::DecodeMemory); | |
| 2252 } | |
| 2253 | |
| 2254 SimplePC::~SimplePC() { | |
| 2255 // SkASSERT(SkGPipeReader::kDone_Status == fStatus); | |
| 2256 if (fTotalWritten) { | |
| 2257 SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten, | |
| 2258 fAtomsWritten, fStatus); | |
| 2259 #ifdef PIPE_FILE | |
| 2260 //File is open in append mode | |
| 2261 FILE* f = fopen(FILE_PATH, "ab"); | |
| 2262 SkASSERT(f != nullptr); | |
| 2263 fwrite((const char*)fBlock + fBytesWritten, 1, bytes, f); | |
| 2264 fclose(f); | |
| 2265 #endif | |
| 2266 #ifdef PIPE_NET | |
| 2267 if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done | |
| 2268 gServer.acceptConnections(); | |
| 2269 gServer.writePacket(fBlock, fTotalWritten); | |
| 2270 } | |
| 2271 #endif | |
| 2272 } | |
| 2273 sk_free(fBlock); | |
| 2274 } | |
| 2275 | |
| 2276 void* SimplePC::requestBlock(size_t minRequest, size_t* actual) { | |
| 2277 sk_free(fBlock); | |
| 2278 | |
| 2279 fBlockSize = minRequest * 4; | |
| 2280 fBlock = sk_malloc_throw(fBlockSize); | |
| 2281 fBytesWritten = 0; | |
| 2282 *actual = fBlockSize; | |
| 2283 return fBlock; | |
| 2284 } | |
| 2285 | |
| 2286 void SimplePC::notifyWritten(size_t bytes) { | |
| 2287 SkASSERT(fBytesWritten + bytes <= fBlockSize); | |
| 2288 fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes); | |
| 2289 SkASSERT(SkGPipeReader::kError_Status != fStatus); | |
| 2290 fBytesWritten += bytes; | |
| 2291 fTotalWritten += bytes; | |
| 2292 | |
| 2293 fAtomsWritten += 1; | |
| 2294 } | |
| 2295 | |
| 2296 void SampleView::draw(SkCanvas* canvas) { | |
| 2297 if (SkOSMenu::kOffState == fPipeState) { | |
| 2298 this->INHERITED::draw(canvas); | |
| 2299 } else { | |
| 2300 SkGPipeWriter writer; | |
| 2301 SimplePC controller(canvas); | |
| 2302 SkBitmap bitmap = capture_bitmap(canvas); | |
| 2303 TiledPipeController tc(bitmap, &SkImageDecoder::DecodeMemory, &canvas->g
etTotalMatrix()); | |
| 2304 SkGPipeController* pc; | |
| 2305 if (SkOSMenu::kMixedState == fPipeState) { | |
| 2306 pc = &tc; | |
| 2307 } else { | |
| 2308 pc = &controller; | |
| 2309 } | |
| 2310 uint32_t flags = SkGPipeWriter::kCrossProcess_Flag; | |
| 2311 | |
| 2312 canvas = writer.startRecording(pc, flags); | |
| 2313 //Must draw before controller goes out of scope and sends data | |
| 2314 this->INHERITED::draw(canvas); | |
| 2315 //explicitly end recording to ensure writer is flushed before the memory | |
| 2316 //is freed in the deconstructor of the controller | |
| 2317 writer.endRecording(); | |
| 2318 } | |
| 2319 } | |
| 2320 | |
| 2321 void SampleView::onDraw(SkCanvas* canvas) { | 2155 void SampleView::onDraw(SkCanvas* canvas) { |
| 2322 if (!fHaveCalledOnceBeforeDraw) { | 2156 if (!fHaveCalledOnceBeforeDraw) { |
| 2323 fHaveCalledOnceBeforeDraw = true; | 2157 fHaveCalledOnceBeforeDraw = true; |
| 2324 this->onOnceBeforeDraw(); | 2158 this->onOnceBeforeDraw(); |
| 2325 } | 2159 } |
| 2326 this->onDrawBackground(canvas); | 2160 this->onDrawBackground(canvas); |
| 2327 | 2161 |
| 2328 for (int i = 0; i < fRepeatCount; i++) { | 2162 for (int i = 0; i < fRepeatCount; i++) { |
| 2329 SkAutoCanvasRestore acr(canvas, true); | 2163 SkAutoCanvasRestore acr(canvas, true); |
| 2330 this->onDrawContent(canvas); | 2164 this->onDrawContent(canvas); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 #ifdef SK_BUILD_FOR_MAC | 2308 #ifdef SK_BUILD_FOR_MAC |
| 2475 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2309 setenv("ANDROID_ROOT", "/android/device/data", 0); |
| 2476 #endif | 2310 #endif |
| 2477 SkGraphics::Init(); | 2311 SkGraphics::Init(); |
| 2478 SkEvent::Init(); | 2312 SkEvent::Init(); |
| 2479 } | 2313 } |
| 2480 | 2314 |
| 2481 void application_term() { | 2315 void application_term() { |
| 2482 SkEvent::Term(); | 2316 SkEvent::Term(); |
| 2483 } | 2317 } |
| OLD | NEW |