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" | |
19 #include "SkDevice.h" | 18 #include "SkDevice.h" |
20 #include "SkDocument.h" | 19 #include "SkDocument.h" |
21 #include "SkGPipe.h" | 20 #include "SkGPipe.h" |
22 #include "SkGraphics.h" | 21 #include "SkGraphics.h" |
23 #include "SkImageEncoder.h" | 22 #include "SkImageEncoder.h" |
24 #include "SkOSFile.h" | 23 #include "SkOSFile.h" |
25 #include "SkPaint.h" | 24 #include "SkPaint.h" |
26 #include "SkPaintFilterCanvas.h" | 25 #include "SkPaintFilterCanvas.h" |
27 #include "SkPicture.h" | 26 #include "SkPicture.h" |
28 #include "SkPictureRecorder.h" | 27 #include "SkPictureRecorder.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 180 |
182 void setUpBackend(SampleWindow* win, int msaaSampleCount) override { | 181 void setUpBackend(SampleWindow* win, int msaaSampleCount) override { |
183 SkASSERT(kNone_BackEndType == fBackend); | 182 SkASSERT(kNone_BackEndType == fBackend); |
184 | 183 |
185 fBackend = kNone_BackEndType; | 184 fBackend = kNone_BackEndType; |
186 | 185 |
187 #if SK_SUPPORT_GPU | 186 #if SK_SUPPORT_GPU |
188 switch (win->getDeviceType()) { | 187 switch (win->getDeviceType()) { |
189 case kRaster_DeviceType: // fallthrough | 188 case kRaster_DeviceType: // fallthrough |
190 case kPicture_DeviceType: // fallthrough | 189 case kPicture_DeviceType: // fallthrough |
191 case kDeferred_DeviceType: // fallthrough | |
192 case kGPU_DeviceType: | 190 case kGPU_DeviceType: |
193 // all these guys use the native backend | 191 // all these guys use the native backend |
194 fBackend = kNativeGL_BackEndType; | 192 fBackend = kNativeGL_BackEndType; |
195 break; | 193 break; |
196 #if SK_ANGLE | 194 #if SK_ANGLE |
197 case kANGLE_DeviceType: | 195 case kANGLE_DeviceType: |
198 // ANGLE is really the only odd man out | 196 // ANGLE is really the only odd man out |
199 fBackend = kANGLE_BackEndType; | 197 fBackend = kANGLE_BackEndType; |
200 break; | 198 break; |
201 #endif // SK_ANGLE | 199 #endif // SK_ANGLE |
202 default: | 200 default: |
203 SkASSERT(false); | 201 SkASSERT(false); |
204 break; | 202 break; |
205 } | 203 } |
206 AttachmentInfo attachmentInfo; | 204 AttachmentInfo attachmentInfo; |
207 bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo); | 205 bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo); |
208 if (!result) { | 206 if (!result) { |
209 SkDebugf("Failed to initialize GL"); | 207 SkDebugf("Failed to initialize GL"); |
210 return; | 208 return; |
211 } | 209 } |
212 fMSAASampleCount = msaaSampleCount; | 210 fMSAASampleCount = msaaSampleCount; |
213 | 211 |
214 SkASSERT(NULL == fCurIntf); | 212 SkASSERT(NULL == fCurIntf); |
215 SkAutoTUnref<const GrGLInterface> glInterface; | 213 SkAutoTUnref<const GrGLInterface> glInterface; |
216 switch (win->getDeviceType()) { | 214 switch (win->getDeviceType()) { |
217 case kRaster_DeviceType: // fallthrough | 215 case kRaster_DeviceType: // fallthrough |
218 case kPicture_DeviceType: // fallthrough | 216 case kPicture_DeviceType: // fallthrough |
219 case kDeferred_DeviceType: // fallthrough | |
220 case kGPU_DeviceType: | 217 case kGPU_DeviceType: |
221 // all these guys use the native interface | 218 // all these guys use the native interface |
222 glInterface.reset(GrGLCreateNativeInterface()); | 219 glInterface.reset(GrGLCreateNativeInterface()); |
223 break; | 220 break; |
224 #if SK_ANGLE | 221 #if SK_ANGLE |
225 case kANGLE_DeviceType: | 222 case kANGLE_DeviceType: |
226 glInterface.reset(GrGLCreateANGLEInterface()); | 223 glInterface.reset(GrGLCreateANGLEInterface()); |
227 break; | 224 break; |
228 #endif // SK_ANGLE | 225 #endif // SK_ANGLE |
229 default: | 226 default: |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 664 |
668 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
ct) { | 665 static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
ct) { |
669 static const SampleWindow::DeviceType gCT[] = { | 666 static const SampleWindow::DeviceType gCT[] = { |
670 SampleWindow::kPicture_DeviceType, | 667 SampleWindow::kPicture_DeviceType, |
671 #if SK_SUPPORT_GPU | 668 #if SK_SUPPORT_GPU |
672 SampleWindow::kGPU_DeviceType, | 669 SampleWindow::kGPU_DeviceType, |
673 #if SK_ANGLE | 670 #if SK_ANGLE |
674 SampleWindow::kANGLE_DeviceType, | 671 SampleWindow::kANGLE_DeviceType, |
675 #endif // SK_ANGLE | 672 #endif // SK_ANGLE |
676 #endif // SK_SUPPORT_GPU | 673 #endif // SK_SUPPORT_GPU |
677 SampleWindow::kDeferred_DeviceType, | |
678 SampleWindow::kRaster_DeviceType, | 674 SampleWindow::kRaster_DeviceType, |
679 }; | 675 }; |
680 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); | 676 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); |
681 return gCT[ct]; | 677 return gCT[ct]; |
682 } | 678 } |
683 | 679 |
684 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { | 680 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
685 SkView* view = (*sampleFactory)(); | 681 SkView* view = (*sampleFactory)(); |
686 SkString title; | 682 SkString title; |
687 SampleCode::RequestTitle(view, &title); | 683 SampleCode::RequestTitle(view, &title); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 819 |
824 fSaveToPdf = false; | 820 fSaveToPdf = false; |
825 fSaveToSKP = false; | 821 fSaveToSKP = false; |
826 | 822 |
827 int sinkID = this->getSinkID(); | 823 int sinkID = this->getSinkID(); |
828 fAppMenu = new SkOSMenu; | 824 fAppMenu = new SkOSMenu; |
829 fAppMenu->setTitle("Global Settings"); | 825 fAppMenu->setTitle("Global Settings"); |
830 int itemID; | 826 int itemID; |
831 | 827 |
832 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, | 828 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
833 "Raster", "Picture", "OpenGL", "Deferred", | 829 "Raster", "Picture", "OpenGL", |
834 #if SK_ANGLE | 830 #if SK_ANGLE |
835 "ANGLE", | 831 "ANGLE", |
836 #endif | 832 #endif |
837 NULL); | 833 NULL); |
838 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); | 834 fAppMenu->assignKeyEquivalentToItem(itemID, 'd'); |
839 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); | 835 itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState); |
840 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); | 836 fAppMenu->assignKeyEquivalentToItem(itemID, 'b'); |
841 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); | 837 itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState); |
842 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); | 838 fAppMenu->assignKeyEquivalentToItem(itemID, 'l'); |
843 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, | 839 itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFil
terQualityIndex, |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 name.set("unknown_sample"); | 1253 name.set("unknown_sample"); |
1258 } | 1254 } |
1259 name.append(".pdf"); | 1255 name.append(".pdf"); |
1260 #ifdef SK_BUILD_FOR_ANDROID | 1256 #ifdef SK_BUILD_FOR_ANDROID |
1261 name.prepend("/sdcard/"); | 1257 name.prepend("/sdcard/"); |
1262 #endif | 1258 #endif |
1263 fPDFDocument.reset(SkDocument::CreatePDF(name.c_str())); | 1259 fPDFDocument.reset(SkDocument::CreatePDF(name.c_str())); |
1264 canvas = fPDFDocument->beginPage(this->width(), this->height()); | 1260 canvas = fPDFDocument->beginPage(this->width(), this->height()); |
1265 } else if (kPicture_DeviceType == fDeviceType) { | 1261 } else if (kPicture_DeviceType == fDeviceType) { |
1266 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); | 1262 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); |
1267 } else if (kDeferred_DeviceType == fDeviceType) { | |
1268 fDeferredSurface.reset(canvas->newSurface(canvas->imageInfo())); | |
1269 if (fDeferredSurface.get()) { | |
1270 fDeferredCanvas.reset(SkDeferredCanvas::Create(fDeferredSurface)); | |
1271 canvas = fDeferredCanvas; | |
1272 } | |
1273 } else { | 1263 } else { |
1274 canvas = this->INHERITED::beforeChildren(canvas); | 1264 canvas = this->INHERITED::beforeChildren(canvas); |
1275 } | 1265 } |
1276 | 1266 |
1277 if (fUseClip) { | 1267 if (fUseClip) { |
1278 canvas->drawColor(0xFFFF88FF); | 1268 canvas->drawColor(0xFFFF88FF); |
1279 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); | 1269 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
1280 } | 1270 } |
1281 | 1271 |
1282 // Install a flags filter proxy canvas if needed | 1272 // Install a flags filter proxy canvas if needed |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 | 1359 |
1370 SkAutoDataUnref data(ostream.copyToData()); | 1360 SkAutoDataUnref data(ostream.copyToData()); |
1371 SkMemoryStream istream(data->data(), data->size()); | 1361 SkMemoryStream istream(data->data(), data->size()); |
1372 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); | 1362 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); |
1373 if (pict.get() != NULL) { | 1363 if (pict.get() != NULL) { |
1374 orig->drawPicture(pict.get()); | 1364 orig->drawPicture(pict.get()); |
1375 } | 1365 } |
1376 } else { | 1366 } else { |
1377 picture->playback(orig); | 1367 picture->playback(orig); |
1378 } | 1368 } |
1379 } else if (kDeferred_DeviceType == fDeviceType) { | |
1380 SkAutoTUnref<SkImage> image(fDeferredCanvas->newImageSnapshot()); | |
1381 if (image) { | |
1382 orig->drawImage(image, 0, 0, NULL); | |
1383 } | |
1384 fDeferredCanvas.reset(NULL); | |
1385 fDeferredSurface.reset(NULL); | |
1386 } | 1369 } |
1387 | 1370 |
1388 // Do this after presentGL and other finishing, rather than in afterChild | 1371 // Do this after presentGL and other finishing, rather than in afterChild |
1389 if (fMeasureFPS) { | 1372 if (fMeasureFPS) { |
1390 fTimer.end(); | 1373 fTimer.end(); |
1391 fMeasureFPS_Time += fTimer.fWall; | 1374 fMeasureFPS_Time += fTimer.fWall; |
1392 } | 1375 } |
1393 } | 1376 } |
1394 | 1377 |
1395 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { | 1378 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 | 1925 |
1943 static const char* gDeviceTypePrefix[] = { | 1926 static const char* gDeviceTypePrefix[] = { |
1944 "raster: ", | 1927 "raster: ", |
1945 "picture: ", | 1928 "picture: ", |
1946 #if SK_SUPPORT_GPU | 1929 #if SK_SUPPORT_GPU |
1947 "opengl: ", | 1930 "opengl: ", |
1948 #if SK_ANGLE | 1931 #if SK_ANGLE |
1949 "angle: ", | 1932 "angle: ", |
1950 #endif // SK_ANGLE | 1933 #endif // SK_ANGLE |
1951 #endif // SK_SUPPORT_GPU | 1934 #endif // SK_SUPPORT_GPU |
1952 "deferred: ", | |
1953 }; | 1935 }; |
1954 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceType
Cnt, | 1936 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceType
Cnt, |
1955 array_size_mismatch); | 1937 array_size_mismatch); |
1956 | 1938 |
1957 static const char* trystate_str(SkOSMenu::TriState state, | 1939 static const char* trystate_str(SkOSMenu::TriState state, |
1958 const char trueStr[], const char falseStr[]) { | 1940 const char trueStr[], const char falseStr[]) { |
1959 if (SkOSMenu::kOnState == state) { | 1941 if (SkOSMenu::kOnState == state) { |
1960 return trueStr; | 1942 return trueStr; |
1961 } else if (SkOSMenu::kOffState == state) { | 1943 } else if (SkOSMenu::kOffState == state) { |
1962 return falseStr; | 1944 return falseStr; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2359 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2378 #endif | 2360 #endif |
2379 SkGraphics::Init(); | 2361 SkGraphics::Init(); |
2380 SkEvent::Init(); | 2362 SkEvent::Init(); |
2381 } | 2363 } |
2382 | 2364 |
2383 void application_term() { | 2365 void application_term() { |
2384 SkEvent::Term(); | 2366 SkEvent::Term(); |
2385 SkGraphics::Term(); | 2367 SkGraphics::Term(); |
2386 } | 2368 } |
OLD | NEW |