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" | 13 #include "SamplePipeControllers.h" |
14 #include "SkAnimTimer.h" | 14 #include "SkAnimTimer.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 #include "SkCommandLineFlags.h" | 16 #include "SkCommandLineFlags.h" |
17 #include "SkData.h" | 17 #include "SkData.h" |
| 18 #include "SkDeferredCanvas.h" |
18 #include "SkDevice.h" | 19 #include "SkDevice.h" |
19 #include "SkDocument.h" | 20 #include "SkDocument.h" |
20 #include "SkGPipe.h" | 21 #include "SkGPipe.h" |
21 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
22 #include "SkImageEncoder.h" | 23 #include "SkImageEncoder.h" |
23 #include "SkOSFile.h" | 24 #include "SkOSFile.h" |
24 #include "SkPaint.h" | 25 #include "SkPaint.h" |
25 #include "SkPicture.h" | 26 #include "SkPicture.h" |
26 #include "SkPictureRecorder.h" | 27 #include "SkPictureRecorder.h" |
27 #include "SkStream.h" | 28 #include "SkStream.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 #endif | 175 #endif |
175 } | 176 } |
176 | 177 |
177 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) { | 178 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) { |
178 SkASSERT(kNone_BackEndType == fBackend); | 179 SkASSERT(kNone_BackEndType == fBackend); |
179 | 180 |
180 fBackend = kNone_BackEndType; | 181 fBackend = kNone_BackEndType; |
181 | 182 |
182 #if SK_SUPPORT_GPU | 183 #if SK_SUPPORT_GPU |
183 switch (win->getDeviceType()) { | 184 switch (win->getDeviceType()) { |
184 case kRaster_DeviceType: | 185 case kRaster_DeviceType: // fallthrough |
185 // fallthrough | 186 case kPicture_DeviceType: // fallthrough |
186 case kPicture_DeviceType: | 187 case kDeferred_DeviceType: // fallthrough |
187 // fallthrough | |
188 case kGPU_DeviceType: | 188 case kGPU_DeviceType: |
189 // all these guys use the native backend | 189 // all these guys use the native backend |
190 fBackend = kNativeGL_BackEndType; | 190 fBackend = kNativeGL_BackEndType; |
191 break; | 191 break; |
192 #if SK_ANGLE | 192 #if SK_ANGLE |
193 case kANGLE_DeviceType: | 193 case kANGLE_DeviceType: |
194 // ANGLE is really the only odd man out | 194 // ANGLE is really the only odd man out |
195 fBackend = kANGLE_BackEndType; | 195 fBackend = kANGLE_BackEndType; |
196 break; | 196 break; |
197 #endif // SK_ANGLE | 197 #endif // SK_ANGLE |
198 default: | 198 default: |
199 SkASSERT(false); | 199 SkASSERT(false); |
200 break; | 200 break; |
201 } | 201 } |
202 AttachmentInfo attachmentInfo; | 202 AttachmentInfo attachmentInfo; |
203 bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo); | 203 bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo); |
204 if (!result) { | 204 if (!result) { |
205 SkDebugf("Failed to initialize GL"); | 205 SkDebugf("Failed to initialize GL"); |
206 return; | 206 return; |
207 } | 207 } |
208 fMSAASampleCount = msaaSampleCount; | 208 fMSAASampleCount = msaaSampleCount; |
209 | 209 |
210 SkASSERT(NULL == fCurIntf); | 210 SkASSERT(NULL == fCurIntf); |
211 SkAutoTUnref<const GrGLInterface> glInterface; | 211 SkAutoTUnref<const GrGLInterface> glInterface; |
212 switch (win->getDeviceType()) { | 212 switch (win->getDeviceType()) { |
213 case kRaster_DeviceType: | 213 case kRaster_DeviceType: // fallthrough |
214 // fallthrough | 214 case kPicture_DeviceType: // fallthrough |
215 case kPicture_DeviceType: | 215 case kDeferred_DeviceType: // fallthrough |
216 // fallthrough | |
217 case kGPU_DeviceType: | 216 case kGPU_DeviceType: |
218 // all these guys use the native interface | 217 // all these guys use the native interface |
219 glInterface.reset(GrGLCreateNativeInterface()); | 218 glInterface.reset(GrGLCreateNativeInterface()); |
220 break; | 219 break; |
221 #if SK_ANGLE | 220 #if SK_ANGLE |
222 case kANGLE_DeviceType: | 221 case kANGLE_DeviceType: |
223 glInterface.reset(GrGLCreateANGLEInterface()); | 222 glInterface.reset(GrGLCreateANGLEInterface()); |
224 break; | 223 break; |
225 #endif // SK_ANGLE | 224 #endif // SK_ANGLE |
226 default: | 225 default: |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 | 665 |
667 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
ct) { | 666 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
ct) { |
668 static const SampleWindow::DeviceType gCT[] = { | 667 static const SampleWindow::DeviceType gCT[] = { |
669 SampleWindow::kPicture_DeviceType, | 668 SampleWindow::kPicture_DeviceType, |
670 #if SK_SUPPORT_GPU | 669 #if SK_SUPPORT_GPU |
671 SampleWindow::kGPU_DeviceType, | 670 SampleWindow::kGPU_DeviceType, |
672 #if SK_ANGLE | 671 #if SK_ANGLE |
673 SampleWindow::kANGLE_DeviceType, | 672 SampleWindow::kANGLE_DeviceType, |
674 #endif // SK_ANGLE | 673 #endif // SK_ANGLE |
675 #endif // SK_SUPPORT_GPU | 674 #endif // SK_SUPPORT_GPU |
676 SampleWindow::kRaster_DeviceType | 675 SampleWindow::kDeferred_DeviceType, |
| 676 SampleWindow::kRaster_DeviceType, |
677 }; | 677 }; |
678 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); | 678 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); |
679 return gCT[ct]; | 679 return gCT[ct]; |
680 } | 680 } |
681 | 681 |
682 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { | 682 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
683 SkView* view = (*sampleFactory)(); | 683 SkView* view = (*sampleFactory)(); |
684 SkString title; | 684 SkString title; |
685 SampleCode::RequestTitle(view, &title); | 685 SampleCode::RequestTitle(view, &title); |
686 view->unref(); | 686 view->unref(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 822 |
823 fTransitionNext = 6; | 823 fTransitionNext = 6; |
824 fTransitionPrev = 2; | 824 fTransitionPrev = 2; |
825 | 825 |
826 int sinkID = this->getSinkID(); | 826 int sinkID = this->getSinkID(); |
827 fAppMenu = new SkOSMenu; | 827 fAppMenu = new SkOSMenu; |
828 fAppMenu->setTitle("Global Settings"); | 828 fAppMenu->setTitle("Global Settings"); |
829 int itemID; | 829 int itemID; |
830 | 830 |
831 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, | 831 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
832 "Raster", "Picture", "OpenGL", | 832 "Raster", "Picture", "OpenGL", "Deferred", |
833 #if SK_ANGLE | 833 #if SK_ANGLE |
834 "ANGLE", | 834 "ANGLE", |
835 #endif | 835 #endif |
836 NULL); | 836 NULL); |
837 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); | 837 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); |
838 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); | 838 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); |
839 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); | 839 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); |
840 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); | 840 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); |
841 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); | 841 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); |
842 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, | 842 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 name.set("unknown_sample"); | 1189 name.set("unknown_sample"); |
1190 } | 1190 } |
1191 name.append(".pdf"); | 1191 name.append(".pdf"); |
1192 #ifdef SK_BUILD_FOR_ANDROID | 1192 #ifdef SK_BUILD_FOR_ANDROID |
1193 name.prepend("/sdcard/"); | 1193 name.prepend("/sdcard/"); |
1194 #endif | 1194 #endif |
1195 fPDFDocument.reset(SkDocument::CreatePDF(name.c_str())); | 1195 fPDFDocument.reset(SkDocument::CreatePDF(name.c_str())); |
1196 canvas = fPDFDocument->beginPage(this->width(), this->height()); | 1196 canvas = fPDFDocument->beginPage(this->width(), this->height()); |
1197 } else if (kPicture_DeviceType == fDeviceType) { | 1197 } else if (kPicture_DeviceType == fDeviceType) { |
1198 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); | 1198 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); |
| 1199 } else if (kDeferred_DeviceType == fDeviceType) { |
| 1200 fDeferredSurface.reset(canvas->newSurface(canvas->imageInfo())); |
| 1201 if (fDeferredSurface.get()) { |
| 1202 fDeferredCanvas.reset(SkDeferredCanvas::Create(fDeferredSurface)); |
| 1203 canvas = fDeferredCanvas; |
| 1204 } |
1199 } else { | 1205 } else { |
1200 canvas = this->INHERITED::beforeChildren(canvas); | 1206 canvas = this->INHERITED::beforeChildren(canvas); |
1201 } | 1207 } |
1202 | 1208 |
1203 if (fUseClip) { | 1209 if (fUseClip) { |
1204 canvas->drawColor(0xFFFF88FF); | 1210 canvas->drawColor(0xFFFF88FF); |
1205 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); | 1211 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
1206 } | 1212 } |
1207 | 1213 |
1208 return canvas; | 1214 return canvas; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 | 1283 |
1278 SkAutoDataUnref data(ostream.copyToData()); | 1284 SkAutoDataUnref data(ostream.copyToData()); |
1279 SkMemoryStream istream(data->data(), data->size()); | 1285 SkMemoryStream istream(data->data(), data->size()); |
1280 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); | 1286 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); |
1281 if (pict.get() != NULL) { | 1287 if (pict.get() != NULL) { |
1282 orig->drawPicture(pict.get()); | 1288 orig->drawPicture(pict.get()); |
1283 } | 1289 } |
1284 } else { | 1290 } else { |
1285 picture->playback(orig); | 1291 picture->playback(orig); |
1286 } | 1292 } |
| 1293 } else if (kDeferred_DeviceType == fDeviceType) { |
| 1294 SkAutoTUnref<SkImage> image(fDeferredCanvas->newImageSnapshot()); |
| 1295 if (image) { |
| 1296 orig->drawImage(image, 0, 0, NULL); |
| 1297 } |
| 1298 fDeferredCanvas.reset(NULL); |
| 1299 fDeferredSurface.reset(NULL); |
1287 } | 1300 } |
1288 | 1301 |
1289 // Do this after presentGL and other finishing, rather than in afterChild | 1302 // Do this after presentGL and other finishing, rather than in afterChild |
1290 if (fMeasureFPS && fMeasureFPS_StartTime) { | 1303 if (fMeasureFPS && fMeasureFPS_StartTime) { |
1291 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; | 1304 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; |
1292 } | 1305 } |
1293 } | 1306 } |
1294 | 1307 |
1295 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { | 1308 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { |
1296 if (fRotate) { | 1309 if (fRotate) { |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 | 1864 |
1852 static const char* gDeviceTypePrefix[] = { | 1865 static const char* gDeviceTypePrefix[] = { |
1853 "raster: ", | 1866 "raster: ", |
1854 "picture: ", | 1867 "picture: ", |
1855 #if SK_SUPPORT_GPU | 1868 #if SK_SUPPORT_GPU |
1856 "opengl: ", | 1869 "opengl: ", |
1857 #if SK_ANGLE | 1870 #if SK_ANGLE |
1858 "angle: ", | 1871 "angle: ", |
1859 #endif // SK_ANGLE | 1872 #endif // SK_ANGLE |
1860 #endif // SK_SUPPORT_GPU | 1873 #endif // SK_SUPPORT_GPU |
| 1874 "deferred: ", |
1861 }; | 1875 }; |
1862 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceType
Cnt, | 1876 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceType
Cnt, |
1863 array_size_mismatch); | 1877 array_size_mismatch); |
1864 | 1878 |
1865 static const char* trystate_str(SkOSMenu::TriState state, | 1879 static const char* trystate_str(SkOSMenu::TriState state, |
1866 const char trueStr[], const char falseStr[]) { | 1880 const char trueStr[], const char falseStr[]) { |
1867 if (SkOSMenu::kOnState == state) { | 1881 if (SkOSMenu::kOnState == state) { |
1868 return trueStr; | 1882 return trueStr; |
1869 } else if (SkOSMenu::kOffState == state) { | 1883 } else if (SkOSMenu::kOffState == state) { |
1870 return falseStr; | 1884 return falseStr; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2299 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2286 #endif | 2300 #endif |
2287 SkGraphics::Init(); | 2301 SkGraphics::Init(); |
2288 SkEvent::Init(); | 2302 SkEvent::Init(); |
2289 } | 2303 } |
2290 | 2304 |
2291 void application_term() { | 2305 void application_term() { |
2292 SkEvent::Term(); | 2306 SkEvent::Term(); |
2293 SkGraphics::Term(); | 2307 SkGraphics::Term(); |
2294 } | 2308 } |
OLD | NEW |