Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_layer_mac.mm

Issue 142413008: Ensure that CAOpenGLLayer uses the dGPU when appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ca_1_nobackingstore
Patch Set: Fix variable name Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 number_virtual_screens = 0;
77 CGLPixelFormatObj pixel_format = NULL;
78 CGLError error = CGLChoosePixelFormat(
79 &attribs.front(), &pixel_format, &number_virtual_screens);
80 if (error != kCGLNoError) {
81 LOG(ERROR) << "Failed to create pixel format for layer.";
82 return nil;
83 }
84 return pixel_format;
85 }
86
87 - (void)releaseCGLPixelFormat:(CGLPixelFormatObj)pixelFormat {
88 CGLReleasePixelFormat(pixelFormat);
89 }
90
65 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { 91 - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
66 if (!renderWidgetHostView_) 92 if (!renderWidgetHostView_) {
93 LOG(ERROR) << "Cannot create layer context because there is no host.";
67 return nil; 94 return nil;
95 }
68 96
69 context_ = renderWidgetHostView_->compositing_iosurface_context_; 97 context_ = renderWidgetHostView_->compositing_iosurface_context_;
70 if (!context_) 98 if (!context_) {
99 LOG(ERROR) << "Cannot create layer context because host has no context.";
71 return nil; 100 return nil;
101 }
72 102
73 return context_->cgl_context(); 103 return context_->cgl_context();
74 } 104 }
75 105
76 - (void)releaseCGLContext:(CGLContextObj)glContext { 106 - (void)releaseCGLContext:(CGLContextObj)glContext {
77 if (!context_.get()) 107 if (!context_.get())
78 return; 108 return;
79 109
80 DCHECK(glContext == context_->cgl_context()); 110 DCHECK(glContext == context_->cgl_context());
81 context_ = nil; 111 context_ = nil;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( 154 if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
125 context_, 155 context_,
126 window_rect, 156 window_rect,
127 window_scale_factor, 157 window_scale_factor,
128 false)) { 158 false)) {
129 renderWidgetHostView_->GotAcceleratedCompositingError(); 159 renderWidgetHostView_->GotAcceleratedCompositingError();
130 } 160 }
131 } 161 }
132 162
133 @end 163 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698