Chromium Code Reviews| 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/renderer_host/compositing_iosurface_layer_mac.h" | 5 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 | 9 |
| 10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 13 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 13 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
| 14 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 14 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
| 15 #include "ui/base/cocoa/animation_utils.h" | 15 #include "ui/base/cocoa/animation_utils.h" |
| 16 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" |
| 17 #include "ui/gl/gpu_switching_manager.h" | |
| 17 | 18 |
| 18 @implementation CompositingIOSurfaceLayer | 19 @implementation CompositingIOSurfaceLayer |
| 19 | 20 |
| 20 @synthesize context = context_; | 21 @synthesize context = context_; |
| 21 | 22 |
| 22 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r { | 23 - (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r { |
| 23 if (self = [super init]) { | 24 if (self = [super init]) { |
| 24 renderWidgetHostView_ = r; | 25 renderWidgetHostView_ = r; |
| 25 | 26 |
| 26 ScopedCAActionDisabler disabler; | 27 ScopedCAActionDisabler disabler; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 55 } | 56 } |
| 56 | 57 |
| 57 - (void)disableCompositing{ | 58 - (void)disableCompositing{ |
| 58 ScopedCAActionDisabler disabler; | 59 ScopedCAActionDisabler disabler; |
| 59 [self removeFromSuperlayer]; | 60 [self removeFromSuperlayer]; |
| 60 renderWidgetHostView_ = nil; | 61 renderWidgetHostView_ = nil; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // The remaining methods implement the CAOpenGLLayer interface. | 64 // The remaining methods implement the CAOpenGLLayer interface. |
| 64 | 65 |
| 66 - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { | |
| 67 std::vector<CGLPixelFormatAttribute> attribs; | |
| 68 attribs.push_back(kCGLPFADepthSize); | |
| 69 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); | |
| 70 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { | |
| 71 attribs.push_back(kCGLPFAAllowOfflineRenderers); | |
| 72 attribs.push_back(static_cast<CGLPixelFormatAttribute>(1)); | |
| 73 } | |
| 74 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); | |
| 75 | |
| 76 GLint npix = 0; | |
|
Nico
2014/01/30 01:56:23
nit: npix isn't very style guide conforming ;-)
ccameron
2014/01/30 06:37:30
Done. I should stop copy-pasting functions directl
| |
| 77 CGLPixelFormatObj pixel_format = NULL; | |
| 78 CGLError error = CGLChoosePixelFormat(&attribs.front(), &pixel_format, &npix); | |
| 79 if (error != kCGLNoError) { | |
| 80 LOG(ERROR) << "Failed to create pixel format for layer."; | |
| 81 return nil; | |
| 82 } | |
| 83 return pixel_format; | |
| 84 } | |
| 85 | |
| 86 - (void)releaseCGLPixelFormat:(CGLPixelFormatObj)pixelFormat { | |
| 87 CGLReleasePixelFormat(pixelFormat); | |
| 88 } | |
| 89 | |
| 65 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { | 90 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { |
| 66 if (!renderWidgetHostView_) | 91 if (!renderWidgetHostView_) { |
| 92 LOG(ERROR) << "Cannot create layer context because there is no host."; | |
| 67 return nil; | 93 return nil; |
| 94 } | |
| 68 | 95 |
| 69 context_ = renderWidgetHostView_->compositing_iosurface_context_; | 96 context_ = renderWidgetHostView_->compositing_iosurface_context_; |
| 70 if (!context_) | 97 if (!context_) { |
| 98 LOG(ERROR) << "Cannot create layer context because host has no context."; | |
| 71 return nil; | 99 return nil; |
| 100 } | |
| 72 | 101 |
| 73 return context_->cgl_context(); | 102 return context_->cgl_context(); |
| 74 } | 103 } |
| 75 | 104 |
| 76 - (void)releaseCGLContext:(CGLContextObj)glContext { | 105 - (void)releaseCGLContext:(CGLContextObj)glContext { |
| 77 if (!context_.get()) | 106 if (!context_.get()) |
| 78 return; | 107 return; |
| 79 | 108 |
| 80 DCHECK(glContext == context_->cgl_context()); | 109 DCHECK(glContext == context_->cgl_context()); |
| 81 context_ = nil; | 110 context_ = nil; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( | 153 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( |
| 125 context_, | 154 context_, |
| 126 window_rect, | 155 window_rect, |
| 127 window_scale_factor, | 156 window_scale_factor, |
| 128 false)) { | 157 false)) { |
| 129 renderWidgetHostView_->GotAcceleratedCompositingError(); | 158 renderWidgetHostView_->GotAcceleratedCompositingError(); |
| 130 } | 159 } |
| 131 } | 160 } |
| 132 | 161 |
| 133 @end | 162 @end |
| OLD | NEW |