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

Side by Side Diff: content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc

Issue 8233027: Support dynamic switching between integrated and discrete GPUs on Mac OS X. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #if defined(ENABLE_GPU) 5 #if defined(ENABLE_GPU)
6 6
7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 7 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
8 8
9 #include "gpu/GLES2/gl2.h" 9 #include "gpu/GLES2/gl2.h"
10 #ifndef GL_GLEXT_PROTOTYPES 10 #ifndef GL_GLEXT_PROTOTYPES
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 : initialize_failed_(false), 43 : initialize_failed_(false),
44 context_(NULL), 44 context_(NULL),
45 gl_(NULL), 45 gl_(NULL),
46 web_view_(NULL), 46 web_view_(NULL),
47 #if defined(OS_MACOSX) 47 #if defined(OS_MACOSX)
48 plugin_handle_(NULL), 48 plugin_handle_(NULL),
49 #endif // defined(OS_MACOSX) 49 #endif // defined(OS_MACOSX)
50 context_lost_callback_(0), 50 context_lost_callback_(0),
51 context_lost_reason_(GL_NO_ERROR), 51 context_lost_reason_(GL_NO_ERROR),
52 swapbuffers_complete_callback_(0), 52 swapbuffers_complete_callback_(0),
53 gpu_preference_(gfx::PreferIntegratedGpu),
53 cached_width_(0), 54 cached_width_(0),
54 cached_height_(0), 55 cached_height_(0),
55 bound_fbo_(0), 56 bound_fbo_(0),
56 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 57 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
57 } 58 }
58 59
59 WebGraphicsContext3DCommandBufferImpl:: 60 WebGraphicsContext3DCommandBufferImpl::
60 ~WebGraphicsContext3DCommandBufferImpl() { 61 ~WebGraphicsContext3DCommandBufferImpl() {
62 if (host_) {
63 if (host_->WillGpuSwitchOccur(false, gpu_preference_)) {
64 host_->ForciblyCloseChannel();
65 }
66 }
67
61 { 68 {
62 base::AutoLock lock(g_all_shared_contexts_lock.Get()); 69 base::AutoLock lock(g_all_shared_contexts_lock.Get());
63 g_all_shared_contexts.Pointer()->erase(this); 70 g_all_shared_contexts.Pointer()->erase(this);
64 } 71 }
65 delete context_; 72 delete context_;
66 } 73 }
67 74
68 bool WebGraphicsContext3DCommandBufferImpl::initialize( 75 bool WebGraphicsContext3DCommandBufferImpl::initialize(
69 WebGraphicsContext3D::Attributes attributes, 76 WebGraphicsContext3D::Attributes attributes,
70 WebKit::WebView* web_view, 77 WebKit::WebView* web_view,
71 bool render_directly_to_web_view) { 78 bool render_directly_to_web_view) {
72 DCHECK(!context_); 79 DCHECK(!context_);
73 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); 80 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize");
74 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 81 RenderThreadImpl* render_thread = RenderThreadImpl::current();
75 if (!render_thread) 82 if (!render_thread)
76 return false; 83 return false;
77 host_ = render_thread->EstablishGpuChannelSync( 84
78 content:: 85 // The noExtensions and canRecoverFromContextLoss flags are
79 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); 86 // currently used as hints that we are creating a context on
80 if (!host_) 87 // behalf of WebGL or accelerated 2D canvas, respectively.
81 return false; 88 if (attributes.noExtensions || !attributes.canRecoverFromContextLoss)
82 DCHECK(host_->state() == GpuChannelHost::kConnected); 89 gpu_preference_ = gfx::PreferDiscreteGpu;
90
91 bool retry = false;
92
93 do {
94 host_ = render_thread->EstablishGpuChannelSync(
95 content::
96 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE);
97 if (!host_)
98 return false;
99 DCHECK(host_->state() == GpuChannelHost::kConnected);
100
101 if (!retry) {
102 // If the creation of this context requires all contexts for this
103 // renderer to be destroyed on the GPU process side, then drop the
104 // channel and recreate it.
105 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) {
106 host_->ForciblyCloseChannel();
107 retry = true;
108 }
109 } else {
110 retry = false;
111 }
112 } while (retry);
83 113
84 const GPUInfo& gpu_info = host_->gpu_info(); 114 const GPUInfo& gpu_info = host_->gpu_info();
85 UMA_HISTOGRAM_ENUMERATION( 115 UMA_HISTOGRAM_ENUMERATION(
86 "GPU.WebGraphicsContext3D_Init_CanLoseContext", 116 "GPU.WebGraphicsContext3D_Init_CanLoseContext",
87 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, 117 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context,
88 4); 118 4);
89 if (attributes.canRecoverFromContextLoss == false) { 119 if (attributes.canRecoverFromContextLoss == false) {
90 if (gpu_info.can_lose_context) 120 if (gpu_info.can_lose_context)
91 return false; 121 return false;
92 } 122 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_; 175 NULL : (*g_all_shared_contexts.Pointer()->begin())->context_;
146 } 176 }
147 177
148 if (render_directly_to_web_view_) { 178 if (render_directly_to_web_view_) {
149 context_ = RendererGLContext::CreateViewContext( 179 context_ = RendererGLContext::CreateViewContext(
150 host_, 180 host_,
151 render_view_routing_id_, 181 render_view_routing_id_,
152 share_group, 182 share_group,
153 preferred_extensions, 183 preferred_extensions,
154 attribs, 184 attribs,
155 active_url_); 185 active_url_,
186 gpu_preference_);
156 } else { 187 } else {
157 context_ = RendererGLContext::CreateOffscreenContext( 188 context_ = RendererGLContext::CreateOffscreenContext(
158 host_, 189 host_,
159 gfx::Size(1, 1), 190 gfx::Size(1, 1),
160 share_group, 191 share_group,
161 preferred_extensions, 192 preferred_extensions,
162 attribs, 193 attribs,
163 active_url_); 194 active_url_,
195 gpu_preference_);
164 } 196 }
165 } 197 }
166 198
167 if (!context_) 199 if (!context_)
168 return false; 200 return false;
169 201
170 gl_ = context_->GetImplementation(); 202 gl_ = context_->GetImplementation();
171 203
172 // TODO(twiz): This code is too fragile in that it assumes that only WebGL 204 // TODO(twiz): This code is too fragile in that it assumes that only WebGL
173 // contexts will request noExtensions. 205 // contexts will request noExtensions.
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 if (context_lost_callback_) { 1115 if (context_lost_callback_) {
1084 context_lost_callback_->onContextLost(); 1116 context_lost_callback_->onContextLost();
1085 } 1117 }
1086 RenderViewImpl* renderview = 1118 RenderViewImpl* renderview =
1087 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; 1119 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL;
1088 if (renderview) 1120 if (renderview)
1089 renderview->OnViewContextSwapBuffersAborted(); 1121 renderview->OnViewContextSwapBuffersAborted();
1090 } 1122 }
1091 1123
1092 #endif // defined(ENABLE_GPU) 1124 #endif // defined(ENABLE_GPU)
OLDNEW
« no previous file with comments | « content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h ('k') | content/renderer/pepper_platform_context_3d_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698