Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: samplecode/SampleApp.cpp

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

Powered by Google App Engine
This is Rietveld 408576698