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 |
430 // This application only creates a single color renderbuffer which is alread
y bound at this point. | 413 // 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
. | 414 // This call is redundant, but needed if dealing with multiple renderbuffers
. |
432 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); | 415 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); |
433 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER]; | 416 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER]; |
434 | |
435 } | 417 } |
436 | 418 |
437 - (void)drawInRaster { | 419 - (void)drawInRaster { |
438 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas()); | 420 SkAutoTUnref<SkSurface> surface(fWind->createSurface()); |
| 421 SkCanvas* canvas = surface->getCanvas(); |
439 [self drawWithCanvas:canvas]; | 422 [self drawWithCanvas:canvas]; |
440 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); | 423 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); |
441 fRasterLayer.contents = (id)cgimage; | 424 fRasterLayer.contents = (id)cgimage; |
442 CGImageRelease(cgimage); | 425 CGImageRelease(cgimage); |
443 } | 426 } |
444 | 427 |
445 - (void)forceRedraw { | 428 - (void)forceRedraw { |
446 if (fDevManager->isUsingGL()) | 429 if (fDevManager->isUsingGL()) |
447 [self drawInGL]; | 430 [self drawInGL]; |
448 else | 431 else |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); | 468 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer); |
486 glGetRenderbufferParameteriv(GL_RENDERBUFFER, | 469 glGetRenderbufferParameteriv(GL_RENDERBUFFER, |
487 GL_RENDERBUFFER_STENCIL_SIZE, | 470 GL_RENDERBUFFER_STENCIL_SIZE, |
488 &info->fStencilBits); | 471 &info->fStencilBits); |
489 glGetRenderbufferParameteriv(GL_RENDERBUFFER, | 472 glGetRenderbufferParameteriv(GL_RENDERBUFFER, |
490 GL_RENDERBUFFER_SAMPLES_APPLE, | 473 GL_RENDERBUFFER_SAMPLES_APPLE, |
491 &info->fSampleCount); | 474 &info->fSampleCount); |
492 } | 475 } |
493 | 476 |
494 @end | 477 @end |
OLD | NEW |