Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 68 |
| 69 bool WebGraphicsContext3DCommandBufferImpl::initialize( | 69 bool WebGraphicsContext3DCommandBufferImpl::initialize( |
| 70 WebGraphicsContext3D::Attributes attributes, | 70 WebGraphicsContext3D::Attributes attributes, |
| 71 WebKit::WebView* web_view, | 71 WebKit::WebView* web_view, |
| 72 bool render_directly_to_web_view) { | 72 bool render_directly_to_web_view) { |
| 73 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); | 73 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); |
| 74 webkit_glue::BindSkiaToCommandBufferGL(); | 74 webkit_glue::BindSkiaToCommandBufferGL(); |
| 75 RenderThread* render_thread = RenderThread::current(); | 75 RenderThread* render_thread = RenderThread::current(); |
| 76 if (!render_thread) | 76 if (!render_thread) |
| 77 return false; | 77 return false; |
| 78 GpuChannelHost* host = render_thread->EstablishGpuChannelSync( | 78 host_ = render_thread->EstablishGpuChannelSync( |
| 79 content:: | 79 content:: |
| 80 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); | 80 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); |
| 81 if (!host) | 81 if (!host_) |
| 82 return false; | 82 return false; |
| 83 DCHECK(host->state() == GpuChannelHost::kConnected); | 83 DCHECK(host_->state() == GpuChannelHost::kConnected); |
| 84 | |
| 85 const GPUInfo& gpu_info = host_->gpu_info(); | |
| 86 UMA_HISTOGRAM_ENUMERATION( | |
| 87 "GPU.WebGraphicsContext3D_Init_CanLoseContext", | |
| 88 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, | |
| 89 4); | |
| 90 if (attributes.canRecoverFromContextLoss == false) { | |
| 91 if (gpu_info.can_lose_context) | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 95 if (web_view && web_view->mainFrame()) | |
| 96 active_url_ = GURL(web_view->mainFrame()->document().url()); | |
| 97 | |
| 98 attributes_ = attributes; | |
| 99 render_directly_to_web_view_ = render_directly_to_web_view; | |
| 100 if (render_directly_to_web_view_) { | |
| 101 RenderView* renderview = RenderView::FromWebView(web_view); | |
| 102 if (!renderview) | |
| 103 return false; | |
| 104 render_view_routing_id_ = renderview->routing_id(), | |
| 105 #ifndef WTF_USE_THREADED_COMPOSITING | |
| 106 web_view_ = web_view; | |
| 107 } else { | |
| 108 web_view_ = NULL; | |
| 109 #endif | |
| 110 } | |
| 111 context_ = NULL; | |
| 112 gl_ = NULL; | |
| 113 return true; | |
| 114 } | |
| 115 | |
| 116 bool WebGraphicsContext3DCommandBufferImpl::InitializeGLES2() { | |
| 117 DCHECK(!context_); | |
| 118 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::InitializeGLES2"); | |
| 84 | 119 |
| 85 // Convert WebGL context creation attributes into RendererGLContext / EGL size | 120 // Convert WebGL context creation attributes into RendererGLContext / EGL size |
| 86 // requests. | 121 // requests. |
| 87 const int alpha_size = attributes.alpha ? 8 : 0; | 122 const int alpha_size = attributes_.alpha ? 8 : 0; |
| 88 const int depth_size = attributes.depth ? 24 : 0; | 123 const int depth_size = attributes_.depth ? 24 : 0; |
| 89 const int stencil_size = attributes.stencil ? 8 : 0; | 124 const int stencil_size = attributes_.stencil ? 8 : 0; |
| 90 const int samples = attributes.antialias ? 4 : 0; | 125 const int samples = attributes_.antialias ? 4 : 0; |
| 91 const int sample_buffers = attributes.antialias ? 1 : 0; | 126 const int sample_buffers = attributes_.antialias ? 1 : 0; |
| 92 const int32 attribs[] = { | 127 const int32 attribs[] = { |
| 93 RendererGLContext::ALPHA_SIZE, alpha_size, | 128 RendererGLContext::ALPHA_SIZE, alpha_size, |
| 94 RendererGLContext::DEPTH_SIZE, depth_size, | 129 RendererGLContext::DEPTH_SIZE, depth_size, |
| 95 RendererGLContext::STENCIL_SIZE, stencil_size, | 130 RendererGLContext::STENCIL_SIZE, stencil_size, |
| 96 RendererGLContext::SAMPLES, samples, | 131 RendererGLContext::SAMPLES, samples, |
| 97 RendererGLContext::SAMPLE_BUFFERS, sample_buffers, | 132 RendererGLContext::SAMPLE_BUFFERS, sample_buffers, |
| 98 RendererGLContext::NONE, | 133 RendererGLContext::NONE, |
| 99 }; | 134 }; |
| 100 | 135 |
| 101 const char* preferred_extensions = attributes.noExtensions ? | 136 const char* preferred_extensions = attributes_.noExtensions ? |
| 102 kWebGLPreferredGLExtensions : "*"; | 137 kWebGLPreferredGLExtensions : "*"; |
| 103 | 138 |
| 104 const GPUInfo& gpu_info = host->gpu_info(); | |
| 105 UMA_HISTOGRAM_ENUMERATION( | |
| 106 "GPU.WebGraphicsContext3D_Init_CanLoseContext", | |
| 107 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, | |
| 108 4); | |
| 109 if (attributes.canRecoverFromContextLoss == false) { | |
| 110 if (gpu_info.can_lose_context) | |
| 111 return false; | |
| 112 } | |
| 113 | |
| 114 GURL active_url; | |
| 115 if (web_view && web_view->mainFrame()) | |
| 116 active_url = GURL(web_view->mainFrame()->document().url()); | |
| 117 | |
| 118 // HACK: Assume this is a WebGL context by looking for the noExtensions | 139 // HACK: Assume this is a WebGL context by looking for the noExtensions |
| 119 // attribute. WebGL contexts must not go in the share group because they | 140 // attribute. WebGL contexts must not go in the share group because they |
| 120 // rely on destruction of the context to clean up owned resources. Putting | 141 // rely on destruction of the context to clean up owned resources. Putting |
| 121 // them in a share group would prevent this from happening. | 142 // them in a share group would prevent this from happening. |
| 122 RendererGLContext* share_group = NULL; | 143 RendererGLContext* share_group = NULL; |
| 123 if (!attributes.noExtensions) { | 144 if (!attributes_.noExtensions) { |
| 124 share_group = g_all_contexts.Pointer()->empty() ? | 145 share_group = g_all_contexts.Pointer()->empty() ? |
| 125 NULL : (*g_all_contexts.Pointer()->begin())->context_; | 146 NULL : (*g_all_contexts.Pointer()->begin())->context_; |
| 126 } | 147 } |
| 127 | 148 |
| 128 render_directly_to_web_view_ = render_directly_to_web_view; | 149 if (render_directly_to_web_view_) { |
| 129 if (render_directly_to_web_view) { | 150 RenderView* renderview = RenderView::FromWebView(web_view_); |
|
jamesr
2011/08/23 01:23:23
this is highly thread unsafe - it depends on a glo
lain Merrick
2011/08/23 01:31:03
Ack, seem to have lost my earlier CL while updatin
| |
| 130 #ifndef WTF_USE_THREADED_COMPOSITING | |
| 131 RenderView* renderview = RenderView::FromWebView(web_view); | |
| 132 if (!renderview) | 151 if (!renderview) |
| 133 return false; | 152 return false; |
| 134 web_view_ = web_view; | |
|
nduca
2011/08/23 05:08:19
I guess this whole block is gonna go away?
| |
| 135 #endif | |
| 136 context_ = RendererGLContext::CreateViewContext( | 153 context_ = RendererGLContext::CreateViewContext( |
| 137 host, | 154 host_, |
| 138 renderview->routing_id(), | 155 render_view_routing_id_, |
| 139 !attributes.noExtensions, | 156 !attributes_.noExtensions, |
| 140 share_group, | 157 share_group, |
| 141 preferred_extensions, | 158 preferred_extensions, |
| 142 attribs, | 159 attribs, |
| 143 active_url); | 160 active_url_); |
| 144 if (context_) { | 161 if (context_) { |
| 145 context_->SetSwapBuffersCallback( | 162 context_->SetSwapBuffersCallback( |
| 146 NewCallback(this, | 163 NewCallback(this, |
| 147 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); | 164 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); |
| 148 } | 165 } |
| 149 } else { | 166 } else { |
| 150 context_ = RendererGLContext::CreateOffscreenContext( | 167 context_ = RendererGLContext::CreateOffscreenContext( |
| 151 host, | 168 host_, |
| 152 gfx::Size(1, 1), | 169 gfx::Size(1, 1), |
| 153 !attributes.noExtensions, | 170 !attributes_.noExtensions, |
| 154 share_group, | 171 share_group, |
| 155 preferred_extensions, | 172 preferred_extensions, |
| 156 attribs, | 173 attribs, |
| 157 active_url); | 174 active_url_); |
| 158 #ifndef WTF_USE_THREADED_COMPOSITING | |
| 159 web_view_ = NULL; | |
| 160 #endif | |
| 161 } | 175 } |
| 162 if (!context_) | 176 if (!context_) |
| 163 return false; | 177 return false; |
| 164 | 178 |
| 165 gl_ = context_->GetImplementation(); | 179 gl_ = context_->GetImplementation(); |
| 166 context_->SetContextLostCallback( | 180 context_->SetContextLostCallback( |
| 167 NewCallback(this, | 181 NewCallback(this, |
| 168 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); | 182 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); |
| 169 | 183 |
| 170 // TODO(gman): Remove this. | 184 // TODO(gman): Remove this. |
| 171 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 185 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 172 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { | 186 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { |
| 173 context_->DisableShaderTranslation(); | 187 context_->DisableShaderTranslation(); |
| 174 } | 188 } |
| 175 | 189 |
| 176 // Set attributes_ from created offscreen context. | 190 // Set attributes_ from created offscreen context. |
| 177 { | 191 { |
| 178 attributes_ = attributes; | |
| 179 GLint alpha_bits = 0; | 192 GLint alpha_bits = 0; |
| 180 getIntegerv(GL_ALPHA_BITS, &alpha_bits); | 193 getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
| 181 attributes_.alpha = alpha_bits > 0; | 194 attributes_.alpha = alpha_bits > 0; |
| 182 GLint depth_bits = 0; | 195 GLint depth_bits = 0; |
| 183 getIntegerv(GL_DEPTH_BITS, &depth_bits); | 196 getIntegerv(GL_DEPTH_BITS, &depth_bits); |
| 184 attributes_.depth = depth_bits > 0; | 197 attributes_.depth = depth_bits > 0; |
| 185 GLint stencil_bits = 0; | 198 GLint stencil_bits = 0; |
| 186 getIntegerv(GL_STENCIL_BITS, &stencil_bits); | 199 getIntegerv(GL_STENCIL_BITS, &stencil_bits); |
| 187 attributes_.stencil = stencil_bits > 0; | 200 attributes_.stencil = stencil_bits > 0; |
| 188 GLint samples = 0; | 201 GLint samples = 0; |
| 189 getIntegerv(GL_SAMPLES, &samples); | 202 getIntegerv(GL_SAMPLES, &samples); |
| 190 attributes_.antialias = samples > 0; | 203 attributes_.antialias = samples > 0; |
| 191 } | 204 } |
| 192 | 205 |
| 193 if (!attributes.noExtensions) | 206 if (!attributes_.noExtensions) |
| 194 g_all_contexts.Pointer()->insert(this); | 207 g_all_contexts.Pointer()->insert(this); |
|
jamesr
2011/08/23 01:23:23
It does not appear that you've made this threadsaf
lain Merrick
2011/08/23 01:31:03
Will fix.
nduca
2011/08/23 05:08:19
Hmm, lets talk about this tomorrow... I'd like to
| |
| 195 | 208 |
| 196 return true; | 209 return true; |
| 197 } | 210 } |
| 198 | 211 |
| 199 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { | 212 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { |
| 213 if (!context_) { | |
| 214 if (!InitializeGLES2()) { | |
|
nduca
2011/08/23 05:08:19
or maybe InitializeContext
lain Merrick
2011/08/23 15:14:01
That would work, I really don't mind. I think I we
| |
| 215 return false; | |
| 216 } | |
| 217 } | |
| 200 return RendererGLContext::MakeCurrent(context_); | 218 return RendererGLContext::MakeCurrent(context_); |
| 201 } | 219 } |
| 202 | 220 |
| 203 int WebGraphicsContext3DCommandBufferImpl::width() { | 221 int WebGraphicsContext3DCommandBufferImpl::width() { |
| 204 return cached_width_; | 222 return cached_width_; |
| 205 } | 223 } |
| 206 | 224 |
| 207 int WebGraphicsContext3DCommandBufferImpl::height() { | 225 int WebGraphicsContext3DCommandBufferImpl::height() { |
| 208 return cached_height_; | 226 return cached_height_; |
| 209 } | 227 } |
| 210 | 228 |
| 211 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() { | 229 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() { |
| 212 return true; | 230 return true; |
| 213 } | 231 } |
| 214 | 232 |
| 215 bool WebGraphicsContext3DCommandBufferImpl::setParentContext( | 233 bool WebGraphicsContext3DCommandBufferImpl::setParentContext( |
| 216 WebGraphicsContext3D* parent_context) { | 234 WebGraphicsContext3D* parent_context) { |
| 217 WebGraphicsContext3DCommandBufferImpl* parent_context_impl = | 235 WebGraphicsContext3DCommandBufferImpl* parent_context_impl = |
| 218 static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context); | 236 static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context); |
| 219 return context_->SetParent( | 237 return context_->SetParent( |
| 220 parent_context_impl ? parent_context_impl->context() : NULL); | 238 parent_context_impl ? parent_context_impl->context() : NULL); |
| 221 } | 239 } |
| 222 | 240 |
| 223 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { | 241 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { |
| 224 DCHECK(context_); | |
| 225 return context_->GetParentTextureId(); | 242 return context_->GetParentTextureId(); |
| 226 } | 243 } |
| 227 | 244 |
| 228 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { | 245 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { |
| 229 // Copies the contents of the off-screen render target into the texture | 246 // Copies the contents of the off-screen render target into the texture |
| 230 // used by the compositor. | 247 // used by the compositor. |
| 231 #ifndef WTF_USE_THREADED_COMPOSITING | 248 #ifndef WTF_USE_THREADED_COMPOSITING |
| 232 RenderView* renderview = | 249 RenderView* renderview = |
| 233 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 250 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
| 234 if (renderview) | 251 if (renderview) |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 } | 1076 } |
| 1060 #ifndef WTF_USE_THREADED_COMPOSITING | 1077 #ifndef WTF_USE_THREADED_COMPOSITING |
| 1061 RenderView* renderview = | 1078 RenderView* renderview = |
| 1062 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1079 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
| 1063 if (renderview) | 1080 if (renderview) |
| 1064 renderview->OnViewContextSwapBuffersAborted(); | 1081 renderview->OnViewContextSwapBuffersAborted(); |
| 1065 #endif | 1082 #endif |
| 1066 } | 1083 } |
| 1067 | 1084 |
| 1068 #endif // defined(ENABLE_GPU) | 1085 #endif // defined(ENABLE_GPU) |
| OLD | NEW |