OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #import "SkNSView.h" | 9 #import "SkNSView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample; | 284 msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample; |
285 msaaAttributes[kAttributeCount + 2] = kCGLPFASamples; | 285 msaaAttributes[kAttributeCount + 2] = kCGLPFASamples; |
286 msaaAttributes[kAttributeCount + 3] = | 286 msaaAttributes[kAttributeCount + 3] = |
287 (CGLPixelFormatAttribute)msaaSampleCount; | 287 (CGLPixelFormatAttribute)msaaSampleCount; |
288 msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0; | 288 msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0; |
289 CGLChoosePixelFormat(msaaAttributes, &format, &npix); | 289 CGLChoosePixelFormat(msaaAttributes, &format, &npix); |
290 } | 290 } |
291 if (!npix) { | 291 if (!npix) { |
292 CGLChoosePixelFormat(attributes, &format, &npix); | 292 CGLChoosePixelFormat(attributes, &format, &npix); |
293 } | 293 } |
294 | |
295 CGLContextObj ctx; | 294 CGLContextObj ctx; |
296 CGLCreateContext(format, NULL, &ctx); | 295 CGLCreateContext(format, NULL, &ctx); |
297 CGLDestroyPixelFormat(format); | 296 CGLDestroyPixelFormat(format); |
298 | 297 |
299 static const GLint interval = 1; | 298 static const GLint interval = 1; |
300 CGLSetParameter(ctx, kCGLCPSwapInterval, &interval); | 299 CGLSetParameter(ctx, kCGLCPSwapInterval, &interval); |
301 CGLSetCurrentContext(ctx); | 300 CGLSetCurrentContext(ctx); |
302 return ctx; | 301 return ctx; |
303 } | 302 } |
304 } | 303 } |
305 | 304 |
306 - (void)viewDidMoveToWindow { | 305 - (void)viewDidMoveToWindow { |
307 [super viewDidMoveToWindow]; | 306 [super viewDidMoveToWindow]; |
308 | 307 |
309 //Attaching view to fGLContext requires that the view to be part of a window
, | 308 //Attaching view to fGLContext requires that the view to be part of a window
, |
310 //and that the NSWindow instance must have a CoreGraphics counterpart (or | 309 //and that the NSWindow instance must have a CoreGraphics counterpart (or |
311 //it must NOT be deferred or should have been on screen at least once) | 310 //it must NOT be deferred or should have been on screen at least once) |
312 if ([fGLContext view] != self && nil != self.window) { | 311 if ([fGLContext view] != self && nil != self.window) { |
313 [fGLContext setView:self]; | 312 [fGLContext setView:self]; |
314 } | 313 } |
315 } | 314 } |
316 - (bool)attach:(SkOSWindow::SkBackEndTypes)attachType | 315 - (bool)attach:(SkOSWindow::SkBackEndTypes)attachType |
317 withMSAASampleCount:(int) sampleCount { | 316 withMSAASampleCount:(int) sampleCount |
| 317 andGetInfo:(SkOSWindow::AttachmentInfo*) info { |
318 if (nil == fGLContext) { | 318 if (nil == fGLContext) { |
319 CGLContextObj ctx = createGLContext(sampleCount); | 319 CGLContextObj ctx = createGLContext(sampleCount); |
320 fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; | 320 fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; |
321 CGLReleaseContext(ctx); | 321 CGLReleaseContext(ctx); |
322 if (NULL == fGLContext) { | 322 if (NULL == fGLContext) { |
323 return false; | 323 return false; |
324 } | 324 } |
325 [fGLContext setView:self]; | 325 [fGLContext setView:self]; |
326 } | 326 } |
327 | 327 |
328 [fGLContext makeCurrentContext]; | 328 [fGLContext makeCurrentContext]; |
329 | 329 CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLC
ontextObj]); |
| 330 CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount); |
| 331 CGLDescribePixelFormat(format, 0, kCGLPFAStencilSize, &info->fStencilBits); |
330 glViewport(0, 0, (int) self.bounds.size.width, (int) self.bounds.size.width)
; | 332 glViewport(0, 0, (int) self.bounds.size.width, (int) self.bounds.size.width)
; |
331 glClearColor(0, 0, 0, 0); | 333 glClearColor(0, 0, 0, 0); |
332 glClearStencil(0); | 334 glClearStencil(0); |
333 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 335 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
334 return true; | 336 return true; |
335 } | 337 } |
336 | 338 |
337 - (void)detach { | 339 - (void)detach { |
338 [fGLContext release]; | 340 [fGLContext release]; |
339 fGLContext = nil; | 341 fGLContext = nil; |
340 } | 342 } |
341 | 343 |
342 - (void)present { | 344 - (void)present { |
343 if (nil != fGLContext) { | 345 if (nil != fGLContext) { |
344 [fGLContext flushBuffer]; | 346 [fGLContext flushBuffer]; |
345 } | 347 } |
346 } | 348 } |
347 @end | 349 @end |
OLD | NEW |