| 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 <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #ifndef GL_GLEXT_PROTOTYPES | 10 #ifndef GL_GLEXT_PROTOTYPES |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 4); | 97 4); |
| 98 if (attributes.canRecoverFromContextLoss == false) { | 98 if (attributes.canRecoverFromContextLoss == false) { |
| 99 if (gpu_info.can_lose_context) | 99 if (gpu_info.can_lose_context) |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 GURL active_url; | 103 GURL active_url; |
| 104 if (web_view && web_view->mainFrame()) | 104 if (web_view && web_view->mainFrame()) |
| 105 active_url = GURL(web_view->mainFrame()->url()); | 105 active_url = GURL(web_view->mainFrame()->url()); |
| 106 | 106 |
| 107 RendererGLContext* parent_context = NULL; |
| 107 if (render_directly_to_web_view) { | 108 if (render_directly_to_web_view) { |
| 108 RenderView* renderview = RenderView::FromWebView(web_view); | 109 RenderView* renderview = RenderView::FromWebView(web_view); |
| 109 if (!renderview) | 110 if (!renderview) |
| 110 return false; | 111 return false; |
| 111 | 112 |
| 112 web_view_ = web_view; | 113 web_view_ = web_view; |
| 113 context_ = RendererGLContext::CreateViewContext( | 114 context_ = RendererGLContext::CreateViewContext( |
| 114 host, | 115 host, |
| 115 renderview->compositing_surface(), | 116 renderview->compositing_surface(), |
| 116 renderview->routing_id(), | 117 renderview->routing_id(), |
| 117 preferred_extensions, | 118 preferred_extensions, |
| 118 attribs, | 119 attribs, |
| 119 active_url); | 120 active_url); |
| 120 if (context_) { | 121 if (context_) { |
| 121 context_->SetSwapBuffersCallback( | 122 context_->SetSwapBuffersCallback( |
| 122 NewCallback(this, | 123 NewCallback(this, |
| 123 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); | 124 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); |
| 124 } | 125 } |
| 125 } else { | 126 } else { |
| 126 bool compositing_enabled = !CommandLine::ForCurrentProcess()->HasSwitch( | 127 bool compositing_enabled = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 127 switches::kDisableAcceleratedCompositing); | 128 switches::kDisableAcceleratedCompositing); |
| 128 RendererGLContext* parent_context = NULL; | |
| 129 // If GPU compositing is enabled we need to create a GL context that shares | 129 // If GPU compositing is enabled we need to create a GL context that shares |
| 130 // resources with the compositor's context. | 130 // resources with the compositor's context. |
| 131 if (compositing_enabled) { | 131 if (compositing_enabled) { |
| 132 // Asking for the WebGraphicsContext3D on the WebView will force one to | 132 // Asking for the WebGraphicsContext3D on the WebView will force one to |
| 133 // be created if it doesn't already exist. When the compositor is created | 133 // be created if it doesn't already exist. When the compositor is created |
| 134 // for the view it will use the same context. | 134 // for the view it will use the same context. |
| 135 WebKit::WebGraphicsContext3D* view_context = | 135 WebKit::WebGraphicsContext3D* view_context = |
| 136 web_view->graphicsContext3D(); | 136 web_view->graphicsContext3D(); |
| 137 if (view_context) { | 137 if (view_context) { |
| 138 WebGraphicsContext3DCommandBufferImpl* context_impl = | 138 WebGraphicsContext3DCommandBufferImpl* context_impl = |
| 139 static_cast<WebGraphicsContext3DCommandBufferImpl*>(view_context); | 139 static_cast<WebGraphicsContext3DCommandBufferImpl*>(view_context); |
| 140 parent_context = context_impl->context_; | 140 parent_context = context_impl->context_; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 context_ = RendererGLContext::CreateOffscreenContext( | 143 context_ = RendererGLContext::CreateOffscreenContext( |
| 144 host, | 144 host, |
| 145 parent_context, | |
| 146 gfx::Size(1, 1), | 145 gfx::Size(1, 1), |
| 147 preferred_extensions, | 146 preferred_extensions, |
| 148 attribs, | 147 attribs, |
| 149 active_url); | 148 active_url); |
| 150 web_view_ = NULL; | 149 web_view_ = NULL; |
| 151 } | 150 } |
| 152 if (!context_) | 151 if (!context_) |
| 153 return false; | 152 return false; |
| 154 | 153 |
| 154 if (!context_->SetParent(parent_context)) |
| 155 return false; |
| 156 |
| 155 gl_ = context_->GetImplementation(); | 157 gl_ = context_->GetImplementation(); |
| 156 context_->SetContextLostCallback( | 158 context_->SetContextLostCallback( |
| 157 NewCallback(this, | 159 NewCallback(this, |
| 158 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); | 160 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); |
| 159 | 161 |
| 160 // TODO(gman): Remove this. | 162 // TODO(gman): Remove this. |
| 161 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 163 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 162 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { | 164 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { |
| 163 context_->DisableShaderTranslation(); | 165 context_->DisableShaderTranslation(); |
| 164 } | 166 } |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 context_lost_callback_->onContextLost(); | 1031 context_lost_callback_->onContextLost(); |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1032 RenderView* renderview = | 1034 RenderView* renderview = |
| 1033 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1035 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
| 1034 if (renderview) | 1036 if (renderview) |
| 1035 renderview->OnViewContextSwapBuffersAborted(); | 1037 renderview->OnViewContextSwapBuffersAborted(); |
| 1036 } | 1038 } |
| 1037 | 1039 |
| 1038 #endif // defined(ENABLE_GPU) | 1040 #endif // defined(ENABLE_GPU) |
| OLD | NEW |