OLD | NEW |
---|---|
1 #import "SkSampleUIView.h" | 1 #import "SkSampleUIView.h" |
2 | 2 |
3 #define SKGL_CONFIG kEAGLColorFormatRGB565 | 3 #define SKGL_CONFIG kEAGLColorFormatRGB565 |
4 //#define SKGL_CONFIG kEAGLColorFormatRGBA8 | 4 //#define SKGL_CONFIG kEAGLColorFormatRGBA8 |
5 | 5 |
6 #define FORCE_REDRAW | 6 #define FORCE_REDRAW |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkCGUtils.h" | 9 #include "SkCGUtils.h" |
10 #include "SkSurface.h" | |
10 #include "SampleApp.h" | 11 #include "SampleApp.h" |
11 | 12 |
12 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
13 //#define USE_GL_1 | 14 //#define USE_GL_1 |
14 #define USE_GL_2 | 15 #define USE_GL_2 |
15 | 16 |
16 #include "gl/GrGLInterface.h" | 17 #include "gl/GrGLInterface.h" |
17 #include "GrContext.h" | 18 #include "GrContext.h" |
18 #include "SkGpuDevice.h" | 19 #include "SkGpuDevice.h" |
19 #endif | 20 #endif |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 SkSafeUnref(fCurIntf); | 113 SkSafeUnref(fCurIntf); |
113 fCurIntf = NULL; | 114 fCurIntf = NULL; |
114 | 115 |
115 SkSafeUnref(fCurRenderTarget); | 116 SkSafeUnref(fCurRenderTarget); |
116 fCurRenderTarget = NULL; | 117 fCurRenderTarget = NULL; |
117 #endif | 118 #endif |
118 win->detach(); | 119 win->detach(); |
119 fBackend = SampleWindow::kNone_BackEndType; | 120 fBackend = SampleWindow::kNone_BackEndType; |
120 } | 121 } |
121 | 122 |
122 virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType, | 123 virtual SkSurface* createSurface(SampleWindow::DeviceType dType, SampleWindo w* win) SK_OVERRIDE{ |
123 SampleWindow* win) { | 124 #if SK_SUPPORT_GPU |
124 switch (dType) { | 125 if (SampleWindow::IsGpuDeviceType(dType) && fCurContext) { |
125 case SampleWindow::kRaster_DeviceType: | 126 SkSurfaceProps props(win->getSurfaceProps()); |
126 // fallthrough | 127 return SkSurface::NewRenderTargetDirect(fCurRenderTarget, &props); |
127 case SampleWindow::kPicture_DeviceType: | 128 } |
128 // fallthrough | |
129 #if SK_ANGLE | |
130 case SampleWindow::kANGLE_DeviceType: | |
131 #endif | 129 #endif |
132 break; | |
133 #if SK_SUPPORT_GPU | |
134 case SampleWindow::kGPU_DeviceType: | |
135 case SampleWindow::kNullGPU_DeviceType: | |
136 if (fCurContext) { | |
137 SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(fCurContex t, | |
138 fCurRender Target)); | |
139 return new SkCanvas(device); | |
140 } else { | |
141 return NULL; | |
142 } | |
143 break; | |
144 #endif | |
145 default: | |
146 SkASSERT(false); | |
147 return NULL; | |
148 } | |
149 return NULL; | 130 return NULL; |
150 } | 131 } |
151 | 132 |
152 virtual void publishCanvas(SampleWindow::DeviceType dType, | 133 virtual void publishCanvas(SampleWindow::DeviceType dType, |
153 SkCanvas* canvas, | 134 SkCanvas* canvas, |
154 SampleWindow* win) SK_OVERRIDE { | 135 SampleWindow* win) SK_OVERRIDE { |
155 #if SK_SUPPORT_GPU | 136 #if SK_SUPPORT_GPU |
156 if (NULL != fCurContext) { | 137 if (NULL != fCurContext) { |
157 fCurContext->flush(); | 138 fCurContext->flush(); |
158 } | 139 } |
159 #endif | 140 #endif |
160 win->present(); | 141 win->present(); |
161 } | 142 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable); | 393 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable); |
413 glDisable(GL_SCISSOR_TEST); | 394 glDisable(GL_SCISSOR_TEST); |
414 glClearColor(0,0,0,0); | 395 glClearColor(0,0,0,0); |
415 glClear(GL_COLOR_BUFFER_BIT); | 396 glClear(GL_COLOR_BUFFER_BIT); |
416 if (scissorEnable) { | 397 if (scissorEnable) { |
417 glEnable(GL_SCISSOR_TEST); | 398 glEnable(GL_SCISSOR_TEST); |
418 } | 399 } |
419 glViewport(0, 0, fGL.fWidth, fGL.fHeight); | 400 glViewport(0, 0, fGL.fWidth, fGL.fHeight); |
420 | 401 |
421 | 402 |
422 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas()); | 403 SkAutoTUnref<SkSurface> surface(fWind->createSurface()); |
404 SkCanvas* canvas = surface->getCanvas(); | |
405 | |
423 // if we're not "retained", then we have to always redraw everything. | 406 // if we're not "retained", then we have to always redraw everything. |
424 // This call forces us to ignore the fDirtyRgn, and draw everywhere. | 407 // This call forces us to ignore the fDirtyRgn, and draw everywhere. |
425 // If we are "retained", we can skip this call (as the raster case does) | 408 // If we are "retained", we can skip this call (as the raster case does) |
426 fWind->forceInvalAll(); | 409 fWind->forceInvalAll(); |
427 | 410 |
428 [self drawWithCanvas:canvas]; | 411 [self drawWithCanvas:canvas]; |
429 | 412 |
413 // Do we need to call canvas->flush() here? <reed> | |
414 | |
jvanverth1
2014/10/20 15:03:22
It appears to be working without it.
reed1
2014/10/22 19:56:53
Done.
| |
430 // This application only creates a single color renderbuffer which is alread y bound at this point. | 415 // This application only creates a single color renderbuffer which is alread y bound at this point. |
431 // This call is redundant, but needed if dealing with multiple renderbuffers . | 416 // This call is redundant, but needed if dealing with multiple renderbuffers . |
432 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); | 417 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); |
433 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER]; | 418 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER]; |
434 | |
435 } | 419 } |
436 | 420 |
437 - (void)drawInRaster { | 421 - (void)drawInRaster { |
438 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas()); | 422 SkAutoTUnref<SkSurface> surface(fWind->createSurface()); |
423 SkCanvas* canvas = surface->getCanvas(); | |
439 [self drawWithCanvas:canvas]; | 424 [self drawWithCanvas:canvas]; |
440 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); | 425 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); |
441 fRasterLayer.contents = (id)cgimage; | 426 fRasterLayer.contents = (id)cgimage; |
442 CGImageRelease(cgimage); | 427 CGImageRelease(cgimage); |
443 } | 428 } |
444 | 429 |
445 - (void)forceRedraw { | 430 - (void)forceRedraw { |
446 if (fDevManager->isUsingGL()) | 431 if (fDevManager->isUsingGL()) |
447 [self drawInGL]; | 432 [self drawInGL]; |
448 else | 433 else |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); | 470 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); |
486 glGetRenderbufferParameteriv(GL_RENDERBUFFER, | 471 glGetRenderbufferParameteriv(GL_RENDERBUFFER, |
487 GL_RENDERBUFFER_STENCIL_SIZE, | 472 GL_RENDERBUFFER_STENCIL_SIZE, |
488 &info->fStencilBits); | 473 &info->fStencilBits); |
489 glGetRenderbufferParameteriv(GL_RENDERBUFFER, | 474 glGetRenderbufferParameteriv(GL_RENDERBUFFER, |
490 GL_RENDERBUFFER_SAMPLES_APPLE, | 475 GL_RENDERBUFFER_SAMPLES_APPLE, |
491 &info->fSampleCount); | 476 &info->fSampleCount); |
492 } | 477 } |
493 | 478 |
494 @end | 479 @end |
OLD | NEW |