| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/compositor/io_surface_layer_mac.h" | 5 #include "content/browser/compositor/io_surface_layer_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <OpenGL/CGLIOSurface.h> | 8 #include <OpenGL/CGLIOSurface.h> |
| 9 #include <OpenGL/CGLRenderers.h> | 9 #include <OpenGL/CGLRenderers.h> |
| 10 #include <OpenGL/gl.h> | 10 #include <OpenGL/gl.h> |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // IOSurfaceLayer | 167 // IOSurfaceLayer |
| 168 | 168 |
| 169 @implementation IOSurfaceLayer | 169 @implementation IOSurfaceLayer |
| 170 | 170 |
| 171 - (id)initWithClient:(content::IOSurfaceLayerClient*)client | 171 - (id)initWithClient:(content::IOSurfaceLayerClient*)client |
| 172 withScaleFactor:(float)scale_factor { | 172 withScaleFactor:(float)scale_factor { |
| 173 if (self = [super init]) { | 173 if (self = [super init]) { |
| 174 helper_.reset(new content::IOSurfaceLayerHelper(client, self)); | 174 helper_.reset(new content::IOSurfaceLayerHelper(client, self)); |
| 175 | 175 |
| 176 iosurface_ = content::IOSurfaceTexture::Create(); | 176 iosurface_ = content::IOSurfaceTexture::Create(); |
| 177 if (!iosurface_.get()) { | 177 context_ = content::IOSurfaceContext::Get( |
| 178 content::IOSurfaceContext::kCALayerContext); |
| 179 if (!iosurface_.get() || !context_.get()) { |
| 178 LOG(ERROR) << "Failed create CompositingIOSurface or context"; | 180 LOG(ERROR) << "Failed create CompositingIOSurface or context"; |
| 179 [self resetClient]; | 181 [self resetClient]; |
| 180 [self release]; | 182 [self release]; |
| 181 return nil; | 183 return nil; |
| 182 } | 184 } |
| 183 | 185 |
| 184 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 186 [self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| 185 [self setAnchorPoint:CGPointMake(0, 0)]; | 187 [self setAnchorPoint:CGPointMake(0, 0)]; |
| 186 // Setting contents gravity is necessary to prevent the layer from being | 188 // Setting contents gravity is necessary to prevent the layer from being |
| 187 // scaled during dyanmic resizes (especially with devtools open). | 189 // scaled during dyanmic resizes (especially with devtools open). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 198 [super dealloc]; | 200 [super dealloc]; |
| 199 } | 201 } |
| 200 | 202 |
| 201 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id | 203 - (bool)gotFrameWithIOSurface:(IOSurfaceID)io_surface_id |
| 202 withPixelSize:(gfx::Size)pixel_size | 204 withPixelSize:(gfx::Size)pixel_size |
| 203 withScaleFactor:(float)scale_factor { | 205 withScaleFactor:(float)scale_factor { |
| 204 return iosurface_->SetIOSurface(io_surface_id, pixel_size); | 206 return iosurface_->SetIOSurface(io_surface_id, pixel_size); |
| 205 } | 207 } |
| 206 | 208 |
| 207 - (void)poisonContextAndSharegroup { | 209 - (void)poisonContextAndSharegroup { |
| 208 iosurface_->context()->PoisonContextAndSharegroup(); | 210 context_->PoisonContextAndSharegroup(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 - (bool)hasBeenPoisoned { | 213 - (bool)hasBeenPoisoned { |
| 212 return iosurface_->context()->HasBeenPoisoned(); | 214 return context_->HasBeenPoisoned(); |
| 213 } | 215 } |
| 214 | 216 |
| 215 - (float)scaleFactor { | 217 - (float)scaleFactor { |
| 216 if ([self respondsToSelector:(@selector(contentsScale))]) | 218 if ([self respondsToSelector:(@selector(contentsScale))]) |
| 217 return [self contentsScale]; | 219 return [self contentsScale]; |
| 218 return 1; | 220 return 1; |
| 219 } | 221 } |
| 220 | 222 |
| 221 - (int)rendererID { | 223 - (int)rendererID { |
| 222 GLint current_renderer_id = -1; | 224 GLint current_renderer_id = -1; |
| 223 if (CGLGetParameter(iosurface_->context()->cgl_context(), | 225 if (CGLGetParameter(context_->cgl_context(), |
| 224 kCGLCPCurrentRendererID, | 226 kCGLCPCurrentRendererID, |
| 225 ¤t_renderer_id) == kCGLNoError) { | 227 ¤t_renderer_id) == kCGLNoError) { |
| 226 return current_renderer_id & kCGLRendererIDMatchingMask; | 228 return current_renderer_id & kCGLRendererIDMatchingMask; |
| 227 } | 229 } |
| 228 return -1; | 230 return -1; |
| 229 } | 231 } |
| 230 | 232 |
| 231 - (void)resetClient { | 233 - (void)resetClient { |
| 232 helper_.reset(); | 234 helper_.reset(); |
| 233 } | 235 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 248 helper_->BeginPumpingFrames(); | 250 helper_->BeginPumpingFrames(); |
| 249 } | 251 } |
| 250 | 252 |
| 251 - (void)endPumpingFrames { | 253 - (void)endPumpingFrames { |
| 252 helper_->EndPumpingFrames(); | 254 helper_->EndPumpingFrames(); |
| 253 } | 255 } |
| 254 | 256 |
| 255 // The remaining methods implement the CAOpenGLLayer interface. | 257 // The remaining methods implement the CAOpenGLLayer interface. |
| 256 | 258 |
| 257 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { | 259 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { |
| 258 return CGLRetainPixelFormat( | 260 if (!context_.get()) |
| 259 CGLGetPixelFormat(iosurface_->context()->cgl_context())); | 261 return [super copyCGLPixelFormatForDisplayMask:mask]; |
| 262 return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context())); |
| 260 } | 263 } |
| 261 | 264 |
| 262 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { | 265 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { |
| 263 return CGLRetainContext(iosurface_->context()->cgl_context()); | 266 if (!context_.get()) |
| 267 return [super copyCGLContextForPixelFormat:pixelFormat]; |
| 268 return CGLRetainContext(context_->cgl_context()); |
| 264 } | 269 } |
| 265 | 270 |
| 266 - (void)setNeedsDisplay { | 271 - (void)setNeedsDisplay { |
| 267 if (helper_) | 272 if (helper_) |
| 268 helper_->SetNeedsDisplay(); | 273 helper_->SetNeedsDisplay(); |
| 269 [super setNeedsDisplay]; | 274 [super setNeedsDisplay]; |
| 270 } | 275 } |
| 271 | 276 |
| 272 - (BOOL)canDrawInCGLContext:(CGLContextObj)glContext | 277 - (BOOL)canDrawInCGLContext:(CGLContextObj)glContext |
| 273 pixelFormat:(CGLPixelFormatObj)pixelFormat | 278 pixelFormat:(CGLPixelFormatObj)pixelFormat |
| (...skipping 14 matching lines...) Expand all Loading... |
| 288 if (helper_) | 293 if (helper_) |
| 289 helper_->DidDraw(draw_succeeded); | 294 helper_->DidDraw(draw_succeeded); |
| 290 | 295 |
| 291 [super drawInCGLContext:glContext | 296 [super drawInCGLContext:glContext |
| 292 pixelFormat:pixelFormat | 297 pixelFormat:pixelFormat |
| 293 forLayerTime:timeInterval | 298 forLayerTime:timeInterval |
| 294 displayTime:timeStamp]; | 299 displayTime:timeStamp]; |
| 295 } | 300 } |
| 296 | 301 |
| 297 @end | 302 @end |
| OLD | NEW |