blob: 12c56929e3ea2b4b88ca94bcec6b50c940ef098c [file] [log] [blame]
yangsu@google.com688823f2011-08-30 19:14:13 +00001#import "SkSampleUIView.h"
2
3//#define SKWIND_CONFIG SkBitmap::kRGB_565_Config
4#define SKWIND_CONFIG SkBitmap::kARGB_8888_Config
5#define SKGL_CONFIG kEAGLColorFormatRGB565
6//#define SKGL_CONFIG kEAGLColorFormatRGBA8
7
8#define FORCE_REDRAW
9
caryclark@google.com5987f582012-10-02 18:33:14 +000010#include "SkCanvas.h"
11#include "SkCGUtils.h"
12#include "SampleApp.h"
13
14#if SK_SUPPORT_GPU
yangsu@google.com688823f2011-08-30 19:14:13 +000015//#define USE_GL_1
16#define USE_GL_2
17
tomhudson@google.com02f90e82012-02-14 15:43:01 +000018#include "gl/GrGLInterface.h"
caryclark@google.com5987f582012-10-02 18:33:14 +000019#include "GrContext.h"
yangsu@google.com688823f2011-08-30 19:14:13 +000020#include "SkGpuDevice.h"
caryclark@google.com5987f582012-10-02 18:33:14 +000021#endif
bsalomon@google.com230504d2012-09-27 16:04:54 +000022
yangsu@google.com688823f2011-08-30 19:14:13 +000023class SkiOSDeviceManager : public SampleWindow::DeviceManager {
24public:
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +000025 SkiOSDeviceManager(GLint layerFBO) {
bsalomon@google.com230504d2012-09-27 16:04:54 +000026#if SK_SUPPORT_GPU
27 fCurContext = NULL;
28 fCurIntf = NULL;
29 fCurRenderTarget = NULL;
30 fMSAASampleCount = 0;
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +000031 fLayerFBO = layerFBO;
bsalomon@google.com230504d2012-09-27 16:04:54 +000032#endif
33 fBackend = SkOSWindow::kNone_BackEndType;
yangsu@google.com688823f2011-08-30 19:14:13 +000034 }
35
bsalomon@google.com230504d2012-09-27 16:04:54 +000036 virtual ~SkiOSDeviceManager() {
37#if SK_SUPPORT_GPU
38 SkSafeUnref(fCurContext);
39 SkSafeUnref(fCurIntf);
40 SkSafeUnref(fCurRenderTarget);
yangsu@google.com688823f2011-08-30 19:14:13 +000041#endif
bsalomon@google.com230504d2012-09-27 16:04:54 +000042 }
43
44 virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) SK_OVERRIDE {
45 SkASSERT(SkOSWindow::kNone_BackEndType == fBackend);
46
47 fBackend = SkOSWindow::kNone_BackEndType;
48
49#if SK_SUPPORT_GPU
50 switch (win->getDeviceType()) {
51 // these two don't use GL
52 case SampleWindow::kRaster_DeviceType:
53 case SampleWindow::kPicture_DeviceType:
54 break;
55 // these guys use the native backend
56 case SampleWindow::kGPU_DeviceType:
57 case SampleWindow::kNullGPU_DeviceType:
58 fBackend = SkOSWindow::kNativeGL_BackEndType;
59 break;
60 default:
61 SkASSERT(false);
62 break;
yangsu@google.com688823f2011-08-30 19:14:13 +000063 }
64
bsalomon@google.com230504d2012-09-27 16:04:54 +000065 bool result = win->attach(fBackend, msaaSampleCount);
66 if (!result) {
67 SkDebugf("Failed to initialize GL");
68 return;
yangsu@google.com688823f2011-08-30 19:14:13 +000069 }
bsalomon@google.com230504d2012-09-27 16:04:54 +000070 fMSAASampleCount = msaaSampleCount;
71
72 SkASSERT(NULL == fCurIntf);
73 switch (win->getDeviceType()) {
74 // these two don't use GL
yangsu@google.com688823f2011-08-30 19:14:13 +000075 case SampleWindow::kRaster_DeviceType:
bsalomon@google.com230504d2012-09-27 16:04:54 +000076 case SampleWindow::kPicture_DeviceType:
77 fCurIntf = NULL;
78 break;
yangsu@google.com688823f2011-08-30 19:14:13 +000079 case SampleWindow::kGPU_DeviceType:
bsalomon@google.com230504d2012-09-27 16:04:54 +000080 fCurIntf = GrGLCreateNativeInterface();
81 break;
82 case SampleWindow::kNullGPU_DeviceType:
83 fCurIntf = GrGLCreateNullInterface();
84 break;
yangsu@google.com688823f2011-08-30 19:14:13 +000085 default:
bsalomon@google.com230504d2012-09-27 16:04:54 +000086 SkASSERT(false);
87 break;
yangsu@google.com688823f2011-08-30 19:14:13 +000088 }
bsalomon@google.com230504d2012-09-27 16:04:54 +000089
90 SkASSERT(NULL == fCurContext);
91 if (SkOSWindow::kNone_BackEndType != fBackend) {
92 fCurContext = GrContext::Create(kOpenGL_Shaders_GrEngine,
93 (GrPlatform3DContext) fCurIntf);
94 }
95
96 if ((NULL == fCurContext || NULL == fCurIntf) &&
97 SkOSWindow::kNone_BackEndType != fBackend) {
98 // We need some context and interface to see results if we're using a GL backend
99 SkSafeUnref(fCurContext);
100 SkSafeUnref(fCurIntf);
101 SkDebugf("Failed to setup 3D");
102 win->detach();
103 }
104#endif // SK_SUPPORT_GPU
105 // call windowSizeChanged to create the render target
106 this->windowSizeChanged(win);
yangsu@google.com688823f2011-08-30 19:14:13 +0000107 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000108
109 virtual void tearDownBackend(SampleWindow *win) SK_OVERRIDE {
110#if SK_SUPPORT_GPU
111 SkSafeUnref(fCurContext);
112 fCurContext = NULL;
113
114 SkSafeUnref(fCurIntf);
115 fCurIntf = NULL;
116
117 SkSafeUnref(fCurRenderTarget);
118 fCurRenderTarget = NULL;
119#endif
120 win->detach();
121 fBackend = SampleWindow::kNone_BackEndType;
122 }
reed@google.com5957f472012-10-01 20:31:56 +0000123
124 virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType,
125 SampleWindow* win) {
bsalomon@google.com230504d2012-09-27 16:04:54 +0000126 switch (dType) {
bsalomon@google.com230504d2012-09-27 16:04:54 +0000127 case SampleWindow::kRaster_DeviceType:
reed@google.com5957f472012-10-01 20:31:56 +0000128 // fallthrough
bsalomon@google.com230504d2012-09-27 16:04:54 +0000129 case SampleWindow::kPicture_DeviceType:
reed@google.com5957f472012-10-01 20:31:56 +0000130 // fallthrough
131#if SK_ANGLE
132 case SampleWindow::kANGLE_DeviceType:
133#endif
bsalomon@google.com230504d2012-09-27 16:04:54 +0000134 break;
135#if SK_SUPPORT_GPU
bsalomon@google.com230504d2012-09-27 16:04:54 +0000136 case SampleWindow::kGPU_DeviceType:
137 case SampleWindow::kNullGPU_DeviceType:
reed@google.com5957f472012-10-01 20:31:56 +0000138 if (fCurContext) {
139 SkAutoTUnref<SkDevice> device(new SkGpuDevice(fCurContext,
140 fCurRenderTarget));
141 return new SkCanvas(device);
bsalomon@google.com230504d2012-09-27 16:04:54 +0000142 } else {
reed@google.com5957f472012-10-01 20:31:56 +0000143 return NULL;
bsalomon@google.com230504d2012-09-27 16:04:54 +0000144 }
145 break;
146#endif
147 default:
148 SkASSERT(false);
reed@google.com5957f472012-10-01 20:31:56 +0000149 return NULL;
yangsu@google.com688823f2011-08-30 19:14:13 +0000150 }
reed@google.com5957f472012-10-01 20:31:56 +0000151 return NULL;
yangsu@google.com688823f2011-08-30 19:14:13 +0000152 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000153
yangsu@google.com688823f2011-08-30 19:14:13 +0000154 virtual void publishCanvas(SampleWindow::DeviceType dType,
155 SkCanvas* canvas,
bsalomon@google.com230504d2012-09-27 16:04:54 +0000156 SampleWindow* win) SK_OVERRIDE {
caryclark@google.com5987f582012-10-02 18:33:14 +0000157#if SK_SUPPORT_GPU
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000158 if (NULL != fCurContext) {
159 fCurContext->flush();
160 }
caryclark@google.com5987f582012-10-02 18:33:14 +0000161#endif
bsalomon@google.com230504d2012-09-27 16:04:54 +0000162 win->present();
yangsu@google.com688823f2011-08-30 19:14:13 +0000163 }
164
bsalomon@google.com230504d2012-09-27 16:04:54 +0000165 virtual void windowSizeChanged(SampleWindow* win) SK_OVERRIDE {
166#if SK_SUPPORT_GPU
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000167 if (NULL != fCurContext) {
bsalomon@google.com230504d2012-09-27 16:04:54 +0000168 win->attach(fBackend, fMSAASampleCount);
yangsu@google.com688823f2011-08-30 19:14:13 +0000169
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000170 glBindFramebuffer(GL_FRAMEBUFFER, fLayerFBO);
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000171 GrBackendRenderTargetDesc desc;
yangsu@google.com688823f2011-08-30 19:14:13 +0000172 desc.fWidth = SkScalarRound(win->width());
173 desc.fHeight = SkScalarRound(win->height());
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000174 desc.fConfig = kSkia8888_GrPixelConfig;
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000175 desc.fRenderTargetHandle = fLayerFBO;
bsalomon@google.com230504d2012-09-27 16:04:54 +0000176 glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt);
177 glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits);
yangsu@google.com688823f2011-08-30 19:14:13 +0000178
bsalomon@google.com230504d2012-09-27 16:04:54 +0000179 SkSafeUnref(fCurRenderTarget);
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000180 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
yangsu@google.com688823f2011-08-30 19:14:13 +0000181 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000182#endif
yangsu@google.com688823f2011-08-30 19:14:13 +0000183 }
184
bsalomon@google.com230504d2012-09-27 16:04:54 +0000185 virtual GrContext* getGrContext() SK_OVERRIDE {
186#if SK_SUPPORT_GPU
187 return fCurContext;
188#else
189 return NULL;
190#endif
191 }
yangsu@google.com688823f2011-08-30 19:14:13 +0000192
bsalomon@google.com11959252012-04-06 20:13:38 +0000193 virtual GrRenderTarget* getGrRenderTarget() SK_OVERRIDE {
bsalomon@google.com230504d2012-09-27 16:04:54 +0000194#if SK_SUPPORT_GPU
195 return fCurRenderTarget;
196#else
197 return NULL;
198#endif
bsalomon@google.com11959252012-04-06 20:13:38 +0000199 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000200
201 bool isUsingGL() const { return SkOSWindow::kNone_BackEndType != fBackend; }
202
yangsu@google.com688823f2011-08-30 19:14:13 +0000203private:
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000204
bsalomon@google.com230504d2012-09-27 16:04:54 +0000205#if SK_SUPPORT_GPU
206 GrContext* fCurContext;
207 const GrGLInterface* fCurIntf;
208 GrRenderTarget* fCurRenderTarget;
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000209 int fMSAASampleCount;
210 GLint fLayerFBO;
bsalomon@google.com230504d2012-09-27 16:04:54 +0000211#endif
212
213 SkOSWindow::SkBackEndTypes fBackend;
214
215 typedef SampleWindow::DeviceManager INHERITED;
yangsu@google.com688823f2011-08-30 19:14:13 +0000216};
217
218////////////////////////////////////////////////////////////////////////////////
219@implementation SkSampleUIView
220
221@synthesize fTitle, fRasterLayer, fGLLayer;
222
223#include "SkApplication.h"
224#include "SkEvent.h"
225#include "SkWindow.h"
226
yangsu@google.com688823f2011-08-30 19:14:13 +0000227struct FPSState {
228 static const int FRAME_COUNT = 60;
229
230 CFTimeInterval fNow0, fNow1;
231 CFTimeInterval fTime0, fTime1, fTotalTime;
232 int fFrameCounter;
yangsu@google.com688823f2011-08-30 19:14:13 +0000233 SkString str;
234 FPSState() {
235 fTime0 = fTime1 = fTotalTime = 0;
236 fFrameCounter = 0;
237 }
238
239 void startDraw() {
240 fNow0 = CACurrentMediaTime();
yangsu@google.com688823f2011-08-30 19:14:13 +0000241 }
242
243 void endDraw() {
244 fNow1 = CACurrentMediaTime();
yangsu@google.com688823f2011-08-30 19:14:13 +0000245 }
246
247 void flush(SkOSWindow* hwnd) {
248 CFTimeInterval now2 = CACurrentMediaTime();
249
250 fTime0 += fNow1 - fNow0;
251 fTime1 += now2 - fNow1;
252
253 if (++fFrameCounter == FRAME_COUNT) {
254 CFTimeInterval totalNow = CACurrentMediaTime();
255 fTotalTime = totalNow - fTotalTime;
256
257 //SkMSec ms0 = (int)(1000 * fTime0 / FRAME_COUNT);
258 //SkMSec msTotal = (int)(1000 * fTotalTime / FRAME_COUNT);
259 //str.printf(" ms: %d [%d], fps: %3.1f", msTotal, ms0,
260 // FRAME_COUNT / fTotalTime);
261 str.printf(" fps:%3.1f", FRAME_COUNT / fTotalTime);
262 hwnd->setTitle(NULL);
263 fTotalTime = totalNow;
264 fTime0 = fTime1 = 0;
265 fFrameCounter = 0;
266 }
267 }
268};
269
270static FPSState gFPS;
271
272#define FPS_StartDraw() gFPS.startDraw()
273#define FPS_EndDraw() gFPS.endDraw()
274#define FPS_Flush(wind) gFPS.flush(wind)
275
276///////////////////////////////////////////////////////////////////////////////
277
278- (id)initWithDefaults {
279 if (self = [super initWithDefaults]) {
280 fRedrawRequestPending = false;
281 fFPSState = new FPSState;
282
283#ifdef USE_GL_1
284 fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
285#else
286 fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
287#endif
288
289 if (!fGL.fContext || ![EAGLContext setCurrentContext:fGL.fContext])
290 {
291 [self release];
292 return nil;
293 }
294
295 // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
296 glGenFramebuffers(1, &fGL.fFramebuffer);
297 glBindFramebuffer(GL_FRAMEBUFFER, fGL.fFramebuffer);
298
299 glGenRenderbuffers(1, &fGL.fRenderbuffer);
300 glGenRenderbuffers(1, &fGL.fStencilbuffer);
301
302 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
303 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fGL.fRenderbuffer);
304
305 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fStencilbuffer);
306 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fGL.fStencilbuffer);
307
308 self.fGLLayer = [CAEAGLLayer layer];
309 fGLLayer.bounds = self.bounds;
310 fGLLayer.anchorPoint = CGPointMake(0, 0);
311 fGLLayer.opaque = TRUE;
312 [self.layer addSublayer:fGLLayer];
313 fGLLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
314 [NSNumber numberWithBool:NO],
315 kEAGLDrawablePropertyRetainedBacking,
316 SKGL_CONFIG,
317 kEAGLDrawablePropertyColorFormat,
318 nil];
319
320 self.fRasterLayer = [CALayer layer];
321 fRasterLayer.anchorPoint = CGPointMake(0, 0);
322 fRasterLayer.opaque = TRUE;
323 [self.layer addSublayer:fRasterLayer];
324
caryclark@google.com5987f582012-10-02 18:33:14 +0000325 NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"onOrderIn",
yangsu@google.com688823f2011-08-30 19:14:13 +0000326 [NSNull null], @"onOrderOut",
327 [NSNull null], @"sublayers",
328 [NSNull null], @"contents",
329 [NSNull null], @"bounds",
330 nil];
331 fGLLayer.actions = newActions;
332 fRasterLayer.actions = newActions;
333 [newActions release];
334
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000335 fDevManager = new SkiOSDeviceManager(fGL.fFramebuffer);
caryclark@google.com5987f582012-10-02 18:33:14 +0000336 static char* kDummyArgv = const_cast<char*>("dummyExecutableName");
bsalomon@google.com230504d2012-09-27 16:04:54 +0000337 fWind = new SampleWindow(self, 1, &kDummyArgv, fDevManager);
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000338
yangsu@google.com688823f2011-08-30 19:14:13 +0000339 fWind->resize(self.frame.size.width, self.frame.size.height, SKWIND_CONFIG);
340 }
341 return self;
342}
343
344- (void)dealloc {
345 delete fDevManager;
346 delete fFPSState;
347 self.fRasterLayer = nil;
348 self.fGLLayer = nil;
349 [fGL.fContext release];
350 [super dealloc];
351}
352
353- (void)layoutSubviews {
354 int W, H;
355
356 // Allocate color buffer backing based on the current layer size
357 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
358 [fGL.fContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:fGLLayer];
359
360 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &fGL.fWidth);
361 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &fGL.fHeight);
362
363 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fStencilbuffer);
364 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, fGL.fWidth, fGL.fHeight);
365
366 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
367 NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
368 }
369
370 if (fDevManager->isUsingGL()) {
371 W = fGL.fWidth;
372 H = fGL.fHeight;
373 CGRect rect = CGRectMake(0, 0, W, H);
374 fGLLayer.bounds = rect;
375 }
376 else {
377 CGRect rect = self.bounds;
378 W = (int)CGRectGetWidth(rect);
379 H = (int)CGRectGetHeight(rect);
380 fRasterLayer.bounds = rect;
381 }
382
383 printf("---- layoutSubviews %d %d\n", W, H);
384 fWind->resize(W, H);
385 fWind->inval(NULL);
386}
387
388///////////////////////////////////////////////////////////////////////////////
389
390- (void)drawWithCanvas:(SkCanvas*)canvas {
391 fRedrawRequestPending = false;
392 fFPSState->startDraw();
393 fWind->draw(canvas);
394 fFPSState->endDraw();
395#ifdef FORCE_REDRAW
396 fWind->inval(NULL);
397#endif
398 fFPSState->flush(fWind);
399}
400
401- (void)drawInGL {
402 // This application only creates a single context which is already set current at this point.
403 // This call is redundant, but needed if dealing with multiple contexts.
404 [EAGLContext setCurrentContext:fGL.fContext];
405
406 // This application only creates a single default framebuffer which is already bound at this point.
407 // This call is redundant, but needed if dealing with multiple framebuffers.
408 glBindFramebuffer(GL_FRAMEBUFFER, fGL.fFramebuffer);
409
410 GLint scissorEnable;
411 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable);
412 glDisable(GL_SCISSOR_TEST);
413 glClearColor(0,0,0,0);
414 glClear(GL_COLOR_BUFFER_BIT);
415 if (scissorEnable) {
416 glEnable(GL_SCISSOR_TEST);
417 }
418 glViewport(0, 0, fGL.fWidth, fGL.fHeight);
419
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000420
reed@google.com5957f472012-10-01 20:31:56 +0000421 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
yangsu@google.com688823f2011-08-30 19:14:13 +0000422 // if we're not "retained", then we have to always redraw everything.
423 // This call forces us to ignore the fDirtyRgn, and draw everywhere.
424 // If we are "retained", we can skip this call (as the raster case does)
425 fWind->forceInvalAll();
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000426
reed@google.com5957f472012-10-01 20:31:56 +0000427 [self drawWithCanvas:canvas];
yangsu@google.com688823f2011-08-30 19:14:13 +0000428
429 // This application only creates a single color renderbuffer which is already bound at this point.
430 // This call is redundant, but needed if dealing with multiple renderbuffers.
431 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
432 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER];
433
yangsu@google.com688823f2011-08-30 19:14:13 +0000434}
435
436- (void)drawInRaster {
reed@google.com5957f472012-10-01 20:31:56 +0000437 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
438 [self drawWithCanvas:canvas];
yangsu@google.com688823f2011-08-30 19:14:13 +0000439 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap());
440 fRasterLayer.contents = (id)cgimage;
441 CGImageRelease(cgimage);
442}
443
444- (void)forceRedraw {
445 if (fDevManager->isUsingGL())
446 [self drawInGL];
447 else
448 [self drawInRaster];
449}
450
451///////////////////////////////////////////////////////////////////////////////
452
453- (void)setSkTitle:(const char *)title {
454 NSString* text = [NSString stringWithUTF8String:title];
455 if ([text length] > 0)
456 self.fTitle = text;
457
458 if (fTitleItem && fTitle) {
459 fTitleItem.title = [NSString stringWithFormat:@"%@%@", fTitle,
460 [NSString stringWithUTF8String:fFPSState->str.c_str()]];
461 }
462}
463
464- (void)postInvalWithRect:(const SkIRect*)r {
465 if (!fRedrawRequestPending) {
466 fRedrawRequestPending = true;
467 bool gl = fDevManager->isUsingGL();
468 [CATransaction begin];
469 [CATransaction setAnimationDuration:0];
470 fRasterLayer.hidden = gl;
471 fGLLayer.hidden = !gl;
472 [CATransaction commit];
473 if (gl) {
474 [self performSelector:@selector(drawInGL) withObject:nil afterDelay:0];
475 }
476 else {
477 [self performSelector:@selector(drawInRaster) withObject:nil afterDelay:0];
478 [self setNeedsDisplay];
479 }
480 }
481}
482
483@end