blob: 9fc95bd1524d17a2d9b3ee4133c8a3fb5f19f7ca [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 }
bsalomon@google.com64cc8102013-03-05 20:06:05 +000064 SkOSWindow::AttachmentInfo info;
65 bool result = win->attach(fBackend, msaaSampleCount, &info);
bsalomon@google.com230504d2012-09-27 16:04:54 +000066 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) {
bsalomon@google.com365d7872013-02-07 17:01:39 +000092 fCurContext = GrContext::Create(kOpenGL_GrBackend,
93 (GrBackendContext) fCurIntf);
bsalomon@google.com230504d2012-09-27 16:04:54 +000094 }
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) {
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000139 SkAutoTUnref<SkDevice> device(new SkGpuDevice(fCurContext,
140 fCurRenderTarget));
reed@google.com5957f472012-10-01 20:31:56 +0000141 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.com64cc8102013-03-05 20:06:05 +0000168 SkOSWindow::AttachmentInfo info;
169
170 win->attach(fBackend, fMSAASampleCount, &info);
yangsu@google.com688823f2011-08-30 19:14:13 +0000171
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000172 glBindFramebuffer(GL_FRAMEBUFFER, fLayerFBO);
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000173 GrBackendRenderTargetDesc desc;
yangsu@google.com688823f2011-08-30 19:14:13 +0000174 desc.fWidth = SkScalarRound(win->width());
175 desc.fHeight = SkScalarRound(win->height());
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000176 desc.fConfig = kSkia8888_GrPixelConfig;
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000177 desc.fRenderTargetHandle = fLayerFBO;
bsalomon@google.com64cc8102013-03-05 20:06:05 +0000178 desc.fSampleCnt = info.fSampleCount;
179 desc.fStencilBits = info.fStencilBits;
180
bsalomon@google.com230504d2012-09-27 16:04:54 +0000181 SkSafeUnref(fCurRenderTarget);
bsalomon@google.comf67bd9d2013-02-07 16:23:58 +0000182 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
yangsu@google.com688823f2011-08-30 19:14:13 +0000183 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000184#endif
yangsu@google.com688823f2011-08-30 19:14:13 +0000185 }
186
bsalomon@google.com230504d2012-09-27 16:04:54 +0000187 virtual GrContext* getGrContext() SK_OVERRIDE {
188#if SK_SUPPORT_GPU
189 return fCurContext;
190#else
191 return NULL;
192#endif
193 }
yangsu@google.com688823f2011-08-30 19:14:13 +0000194
bsalomon@google.com11959252012-04-06 20:13:38 +0000195 virtual GrRenderTarget* getGrRenderTarget() SK_OVERRIDE {
bsalomon@google.com230504d2012-09-27 16:04:54 +0000196#if SK_SUPPORT_GPU
197 return fCurRenderTarget;
198#else
199 return NULL;
200#endif
bsalomon@google.com11959252012-04-06 20:13:38 +0000201 }
bsalomon@google.com230504d2012-09-27 16:04:54 +0000202
203 bool isUsingGL() const { return SkOSWindow::kNone_BackEndType != fBackend; }
204
yangsu@google.com688823f2011-08-30 19:14:13 +0000205private:
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000206
bsalomon@google.com230504d2012-09-27 16:04:54 +0000207#if SK_SUPPORT_GPU
208 GrContext* fCurContext;
209 const GrGLInterface* fCurIntf;
210 GrRenderTarget* fCurRenderTarget;
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000211 int fMSAASampleCount;
212 GLint fLayerFBO;
bsalomon@google.com230504d2012-09-27 16:04:54 +0000213#endif
214
215 SkOSWindow::SkBackEndTypes fBackend;
216
217 typedef SampleWindow::DeviceManager INHERITED;
yangsu@google.com688823f2011-08-30 19:14:13 +0000218};
219
220////////////////////////////////////////////////////////////////////////////////
221@implementation SkSampleUIView
222
223@synthesize fTitle, fRasterLayer, fGLLayer;
224
225#include "SkApplication.h"
226#include "SkEvent.h"
227#include "SkWindow.h"
228
yangsu@google.com688823f2011-08-30 19:14:13 +0000229struct FPSState {
230 static const int FRAME_COUNT = 60;
231
232 CFTimeInterval fNow0, fNow1;
233 CFTimeInterval fTime0, fTime1, fTotalTime;
234 int fFrameCounter;
yangsu@google.com688823f2011-08-30 19:14:13 +0000235 SkString str;
236 FPSState() {
237 fTime0 = fTime1 = fTotalTime = 0;
238 fFrameCounter = 0;
239 }
240
241 void startDraw() {
242 fNow0 = CACurrentMediaTime();
yangsu@google.com688823f2011-08-30 19:14:13 +0000243 }
244
245 void endDraw() {
246 fNow1 = CACurrentMediaTime();
yangsu@google.com688823f2011-08-30 19:14:13 +0000247 }
248
249 void flush(SkOSWindow* hwnd) {
250 CFTimeInterval now2 = CACurrentMediaTime();
251
252 fTime0 += fNow1 - fNow0;
253 fTime1 += now2 - fNow1;
254
255 if (++fFrameCounter == FRAME_COUNT) {
256 CFTimeInterval totalNow = CACurrentMediaTime();
257 fTotalTime = totalNow - fTotalTime;
258
259 //SkMSec ms0 = (int)(1000 * fTime0 / FRAME_COUNT);
260 //SkMSec msTotal = (int)(1000 * fTotalTime / FRAME_COUNT);
261 //str.printf(" ms: %d [%d], fps: %3.1f", msTotal, ms0,
262 // FRAME_COUNT / fTotalTime);
263 str.printf(" fps:%3.1f", FRAME_COUNT / fTotalTime);
264 hwnd->setTitle(NULL);
265 fTotalTime = totalNow;
266 fTime0 = fTime1 = 0;
267 fFrameCounter = 0;
268 }
269 }
270};
271
272static FPSState gFPS;
273
274#define FPS_StartDraw() gFPS.startDraw()
275#define FPS_EndDraw() gFPS.endDraw()
276#define FPS_Flush(wind) gFPS.flush(wind)
277
278///////////////////////////////////////////////////////////////////////////////
279
280- (id)initWithDefaults {
281 if (self = [super initWithDefaults]) {
282 fRedrawRequestPending = false;
283 fFPSState = new FPSState;
284
285#ifdef USE_GL_1
286 fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
287#else
288 fGL.fContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
289#endif
290
291 if (!fGL.fContext || ![EAGLContext setCurrentContext:fGL.fContext])
292 {
293 [self release];
294 return nil;
295 }
296
297 // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
298 glGenFramebuffers(1, &fGL.fFramebuffer);
299 glBindFramebuffer(GL_FRAMEBUFFER, fGL.fFramebuffer);
300
301 glGenRenderbuffers(1, &fGL.fRenderbuffer);
302 glGenRenderbuffers(1, &fGL.fStencilbuffer);
303
304 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
305 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fGL.fRenderbuffer);
306
307 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fStencilbuffer);
308 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fGL.fStencilbuffer);
309
310 self.fGLLayer = [CAEAGLLayer layer];
311 fGLLayer.bounds = self.bounds;
312 fGLLayer.anchorPoint = CGPointMake(0, 0);
313 fGLLayer.opaque = TRUE;
314 [self.layer addSublayer:fGLLayer];
315 fGLLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
316 [NSNumber numberWithBool:NO],
317 kEAGLDrawablePropertyRetainedBacking,
318 SKGL_CONFIG,
319 kEAGLDrawablePropertyColorFormat,
320 nil];
321
322 self.fRasterLayer = [CALayer layer];
323 fRasterLayer.anchorPoint = CGPointMake(0, 0);
324 fRasterLayer.opaque = TRUE;
325 [self.layer addSublayer:fRasterLayer];
326
caryclark@google.com5987f582012-10-02 18:33:14 +0000327 NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"onOrderIn",
yangsu@google.com688823f2011-08-30 19:14:13 +0000328 [NSNull null], @"onOrderOut",
329 [NSNull null], @"sublayers",
330 [NSNull null], @"contents",
331 [NSNull null], @"bounds",
332 nil];
333 fGLLayer.actions = newActions;
334 fRasterLayer.actions = newActions;
335 [newActions release];
336
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000337 fDevManager = new SkiOSDeviceManager(fGL.fFramebuffer);
caryclark@google.com5987f582012-10-02 18:33:14 +0000338 static char* kDummyArgv = const_cast<char*>("dummyExecutableName");
bsalomon@google.com230504d2012-09-27 16:04:54 +0000339 fWind = new SampleWindow(self, 1, &kDummyArgv, fDevManager);
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000340
yangsu@google.com688823f2011-08-30 19:14:13 +0000341 fWind->resize(self.frame.size.width, self.frame.size.height, SKWIND_CONFIG);
342 }
343 return self;
344}
345
346- (void)dealloc {
347 delete fDevManager;
348 delete fFPSState;
349 self.fRasterLayer = nil;
350 self.fGLLayer = nil;
351 [fGL.fContext release];
352 [super dealloc];
353}
354
355- (void)layoutSubviews {
356 int W, H;
357
358 // Allocate color buffer backing based on the current layer size
359 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
360 [fGL.fContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:fGLLayer];
361
362 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &fGL.fWidth);
363 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &fGL.fHeight);
364
365 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fStencilbuffer);
366 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, fGL.fWidth, fGL.fHeight);
367
368 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
369 NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
370 }
371
372 if (fDevManager->isUsingGL()) {
373 W = fGL.fWidth;
374 H = fGL.fHeight;
375 CGRect rect = CGRectMake(0, 0, W, H);
376 fGLLayer.bounds = rect;
377 }
378 else {
379 CGRect rect = self.bounds;
380 W = (int)CGRectGetWidth(rect);
381 H = (int)CGRectGetHeight(rect);
382 fRasterLayer.bounds = rect;
383 }
384
385 printf("---- layoutSubviews %d %d\n", W, H);
386 fWind->resize(W, H);
387 fWind->inval(NULL);
388}
389
390///////////////////////////////////////////////////////////////////////////////
391
392- (void)drawWithCanvas:(SkCanvas*)canvas {
393 fRedrawRequestPending = false;
394 fFPSState->startDraw();
395 fWind->draw(canvas);
396 fFPSState->endDraw();
397#ifdef FORCE_REDRAW
398 fWind->inval(NULL);
399#endif
400 fFPSState->flush(fWind);
401}
402
403- (void)drawInGL {
404 // This application only creates a single context which is already set current at this point.
405 // This call is redundant, but needed if dealing with multiple contexts.
406 [EAGLContext setCurrentContext:fGL.fContext];
407
408 // This application only creates a single default framebuffer which is already bound at this point.
409 // This call is redundant, but needed if dealing with multiple framebuffers.
410 glBindFramebuffer(GL_FRAMEBUFFER, fGL.fFramebuffer);
411
412 GLint scissorEnable;
413 glGetIntegerv(GL_SCISSOR_TEST, &scissorEnable);
414 glDisable(GL_SCISSOR_TEST);
415 glClearColor(0,0,0,0);
416 glClear(GL_COLOR_BUFFER_BIT);
417 if (scissorEnable) {
418 glEnable(GL_SCISSOR_TEST);
419 }
420 glViewport(0, 0, fGL.fWidth, fGL.fHeight);
421
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000422
reed@google.com5957f472012-10-01 20:31:56 +0000423 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
yangsu@google.com688823f2011-08-30 19:14:13 +0000424 // if we're not "retained", then we have to always redraw everything.
425 // This call forces us to ignore the fDirtyRgn, and draw everywhere.
426 // If we are "retained", we can skip this call (as the raster case does)
427 fWind->forceInvalAll();
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +0000428
reed@google.com5957f472012-10-01 20:31:56 +0000429 [self drawWithCanvas:canvas];
yangsu@google.com688823f2011-08-30 19:14:13 +0000430
431 // This application only creates a single color renderbuffer which is already bound at this point.
432 // This call is redundant, but needed if dealing with multiple renderbuffers.
433 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
434 [fGL.fContext presentRenderbuffer:GL_RENDERBUFFER];
435
yangsu@google.com688823f2011-08-30 19:14:13 +0000436}
437
438- (void)drawInRaster {
reed@google.com5957f472012-10-01 20:31:56 +0000439 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
440 [self drawWithCanvas:canvas];
yangsu@google.com688823f2011-08-30 19:14:13 +0000441 CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap());
442 fRasterLayer.contents = (id)cgimage;
443 CGImageRelease(cgimage);
444}
445
446- (void)forceRedraw {
447 if (fDevManager->isUsingGL())
448 [self drawInGL];
449 else
450 [self drawInRaster];
451}
452
453///////////////////////////////////////////////////////////////////////////////
454
455- (void)setSkTitle:(const char *)title {
456 NSString* text = [NSString stringWithUTF8String:title];
457 if ([text length] > 0)
458 self.fTitle = text;
459
460 if (fTitleItem && fTitle) {
461 fTitleItem.title = [NSString stringWithFormat:@"%@%@", fTitle,
462 [NSString stringWithUTF8String:fFPSState->str.c_str()]];
463 }
464}
465
466- (void)postInvalWithRect:(const SkIRect*)r {
467 if (!fRedrawRequestPending) {
468 fRedrawRequestPending = true;
469 bool gl = fDevManager->isUsingGL();
470 [CATransaction begin];
471 [CATransaction setAnimationDuration:0];
472 fRasterLayer.hidden = gl;
473 fGLLayer.hidden = !gl;
474 [CATransaction commit];
475 if (gl) {
476 [self performSelector:@selector(drawInGL) withObject:nil afterDelay:0];
477 }
478 else {
479 [self performSelector:@selector(drawInRaster) withObject:nil afterDelay:0];
480 [self setNeedsDisplay];
481 }
482 }
483}
484
bsalomon@google.com64cc8102013-03-05 20:06:05 +0000485- (void)getAttachmentInfo:(SkOSWindow::AttachmentInfo*)info {
486 glBindRenderbuffer(GL_RENDERBUFFER, fGL.fRenderbuffer);
487 glGetRenderbufferParameteriv(GL_RENDERBUFFER,
488 GL_RENDERBUFFER_STENCIL_SIZE,
489 &info->fStencilBits);
490 glGetRenderbufferParameteriv(GL_RENDERBUFFER,
491 GL_RENDERBUFFER_SAMPLES_APPLE,
492 &info->fSampleCount);
493}
494
yangsu@google.com688823f2011-08-30 19:14:13 +0000495@end