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 20 matching lines...) Expand all Loading... |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" | 33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" |
34 | 34 |
35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > | 35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > |
36 g_all_contexts(base::LINKER_INITIALIZED); | 36 g_all_contexts(base::LINKER_INITIALIZED); |
37 | 37 |
38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() | 38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() |
39 : context_(NULL), | 39 : context_(NULL), |
40 gl_(NULL), | 40 gl_(NULL), |
| 41 #ifndef WTF_USE_THREADED_COMPOSITING |
41 web_view_(NULL), | 42 web_view_(NULL), |
| 43 #endif |
42 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
43 plugin_handle_(NULL), | 45 plugin_handle_(NULL), |
44 #endif // defined(OS_MACOSX) | 46 #endif // defined(OS_MACOSX) |
45 context_lost_callback_(0), | 47 context_lost_callback_(0), |
46 context_lost_reason_(GL_NO_ERROR), | 48 context_lost_reason_(GL_NO_ERROR), |
47 swapbuffers_complete_callback_(0), | 49 swapbuffers_complete_callback_(0), |
48 cached_width_(0), | 50 cached_width_(0), |
49 cached_height_(0), | 51 cached_height_(0), |
50 bound_fbo_(0) { | 52 bound_fbo_(0) { |
51 } | 53 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // HACK: Assume this is a WebGL context by looking for the noExtensions | 118 // HACK: Assume this is a WebGL context by looking for the noExtensions |
117 // attribute. WebGL contexts must not go in the share group because they | 119 // attribute. WebGL contexts must not go in the share group because they |
118 // rely on destruction of the context to clean up owned resources. Putting | 120 // rely on destruction of the context to clean up owned resources. Putting |
119 // them in a share group would prevent this from happening. | 121 // them in a share group would prevent this from happening. |
120 RendererGLContext* share_group = NULL; | 122 RendererGLContext* share_group = NULL; |
121 if (!attributes.noExtensions) { | 123 if (!attributes.noExtensions) { |
122 share_group = g_all_contexts.Pointer()->empty() ? | 124 share_group = g_all_contexts.Pointer()->empty() ? |
123 NULL : (*g_all_contexts.Pointer()->begin())->context_; | 125 NULL : (*g_all_contexts.Pointer()->begin())->context_; |
124 } | 126 } |
125 | 127 |
| 128 render_directly_to_web_view_ = render_directly_to_web_view; |
126 if (render_directly_to_web_view) { | 129 if (render_directly_to_web_view) { |
| 130 #ifndef WTF_USE_THREADED_COMPOSITING |
127 RenderView* renderview = RenderView::FromWebView(web_view); | 131 RenderView* renderview = RenderView::FromWebView(web_view); |
128 if (!renderview) | 132 if (!renderview) |
129 return false; | 133 return false; |
130 | |
131 web_view_ = web_view; | 134 web_view_ = web_view; |
| 135 #endif |
132 context_ = RendererGLContext::CreateViewContext( | 136 context_ = RendererGLContext::CreateViewContext( |
133 host, | 137 host, |
134 renderview->routing_id(), | 138 renderview->routing_id(), |
135 !attributes.noExtensions, | 139 !attributes.noExtensions, |
136 share_group, | 140 share_group, |
137 preferred_extensions, | 141 preferred_extensions, |
138 attribs, | 142 attribs, |
139 active_url); | 143 active_url); |
140 if (context_) { | 144 if (context_) { |
141 context_->SetSwapBuffersCallback( | 145 context_->SetSwapBuffersCallback( |
142 NewCallback(this, | 146 NewCallback(this, |
143 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); | 147 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); |
144 } | 148 } |
145 } else { | 149 } else { |
146 context_ = RendererGLContext::CreateOffscreenContext( | 150 context_ = RendererGLContext::CreateOffscreenContext( |
147 host, | 151 host, |
148 gfx::Size(1, 1), | 152 gfx::Size(1, 1), |
149 !attributes.noExtensions, | 153 !attributes.noExtensions, |
150 share_group, | 154 share_group, |
151 preferred_extensions, | 155 preferred_extensions, |
152 attribs, | 156 attribs, |
153 active_url); | 157 active_url); |
| 158 #ifndef WTF_USE_THREADED_COMPOSITING |
154 web_view_ = NULL; | 159 web_view_ = NULL; |
| 160 #endif |
155 } | 161 } |
156 if (!context_) | 162 if (!context_) |
157 return false; | 163 return false; |
158 | 164 |
159 gl_ = context_->GetImplementation(); | 165 gl_ = context_->GetImplementation(); |
160 context_->SetContextLostCallback( | 166 context_->SetContextLostCallback( |
161 NewCallback(this, | 167 NewCallback(this, |
162 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); | 168 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); |
163 | 169 |
164 // TODO(gman): Remove this. | 170 // TODO(gman): Remove this. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 221 } |
216 | 222 |
217 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { | 223 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { |
218 DCHECK(context_); | 224 DCHECK(context_); |
219 return context_->GetParentTextureId(); | 225 return context_->GetParentTextureId(); |
220 } | 226 } |
221 | 227 |
222 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { | 228 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { |
223 // Copies the contents of the off-screen render target into the texture | 229 // Copies the contents of the off-screen render target into the texture |
224 // used by the compositor. | 230 // used by the compositor. |
| 231 #ifndef WTF_USE_THREADED_COMPOSITING |
225 RenderView* renderview = | 232 RenderView* renderview = |
226 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 233 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
227 if (renderview) | 234 if (renderview) |
228 renderview->OnViewContextSwapBuffersPosted(); | 235 renderview->OnViewContextSwapBuffersPosted(); |
| 236 #endif |
229 context_->SwapBuffers(); | 237 context_->SwapBuffers(); |
230 } | 238 } |
231 | 239 |
232 void WebGraphicsContext3DCommandBufferImpl::reshape(int width, int height) { | 240 void WebGraphicsContext3DCommandBufferImpl::reshape(int width, int height) { |
233 cached_width_ = width; | 241 cached_width_ = width; |
234 cached_height_ = height; | 242 cached_height_ = height; |
235 | 243 |
236 if (web_view_) { | 244 if (render_directly_to_web_view_) { |
237 #if defined(OS_MACOSX) | 245 #if defined(OS_MACOSX) |
238 context_->ResizeOnscreen(gfx::Size(width, height)); | 246 context_->ResizeOnscreen(gfx::Size(width, height)); |
239 #else | 247 #else |
240 gl_->ResizeCHROMIUM(width, height); | 248 gl_->ResizeCHROMIUM(width, height); |
241 #endif | 249 #endif |
242 } else { | 250 } else { |
243 context_->ResizeOffscreen(gfx::Size(width, height)); | 251 context_->ResizeOffscreen(gfx::Size(width, height)); |
244 // Force a SwapBuffers to get the framebuffer to resize. | 252 // Force a SwapBuffers to get the framebuffer to resize. |
245 context_->SwapBuffers(); | 253 context_->SwapBuffers(); |
246 } | 254 } |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 | 1005 |
998 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) { | 1006 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) { |
999 gl_->DeleteShader(shader); | 1007 gl_->DeleteShader(shader); |
1000 } | 1008 } |
1001 | 1009 |
1002 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { | 1010 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { |
1003 gl_->DeleteTextures(1, &texture); | 1011 gl_->DeleteTextures(1, &texture); |
1004 } | 1012 } |
1005 | 1013 |
1006 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { | 1014 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { |
| 1015 #ifndef WTF_USE_THREADED_COMPOSITING |
1007 // This may be called after tear-down of the RenderView. | 1016 // This may be called after tear-down of the RenderView. |
1008 RenderView* renderview = | 1017 RenderView* renderview = |
1009 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1018 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
1010 if (renderview) | 1019 if (renderview) |
1011 renderview->OnViewContextSwapBuffersComplete(); | 1020 renderview->OnViewContextSwapBuffersComplete(); |
| 1021 #endif |
1012 if (swapbuffers_complete_callback_) | 1022 if (swapbuffers_complete_callback_) |
1013 swapbuffers_complete_callback_->onSwapBuffersComplete(); | 1023 swapbuffers_complete_callback_->onSwapBuffersComplete(); |
1014 } | 1024 } |
1015 | 1025 |
1016 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback( | 1026 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback( |
1017 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { | 1027 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { |
1018 context_lost_callback_ = cb; | 1028 context_lost_callback_ = cb; |
1019 } | 1029 } |
1020 | 1030 |
1021 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() { | 1031 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() { |
(...skipping 28 matching lines...) Expand all Loading... |
1050 } | 1060 } |
1051 | 1061 |
1052 } // anonymous namespace | 1062 } // anonymous namespace |
1053 | 1063 |
1054 void WebGraphicsContext3DCommandBufferImpl::OnContextLost( | 1064 void WebGraphicsContext3DCommandBufferImpl::OnContextLost( |
1055 RendererGLContext::ContextLostReason reason) { | 1065 RendererGLContext::ContextLostReason reason) { |
1056 context_lost_reason_ = convertReason(reason); | 1066 context_lost_reason_ = convertReason(reason); |
1057 if (context_lost_callback_) { | 1067 if (context_lost_callback_) { |
1058 context_lost_callback_->onContextLost(); | 1068 context_lost_callback_->onContextLost(); |
1059 } | 1069 } |
1060 | 1070 #ifndef WTF_USE_THREADED_COMPOSITING |
1061 RenderView* renderview = | 1071 RenderView* renderview = |
1062 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1072 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
1063 if (renderview) | 1073 if (renderview) |
1064 renderview->OnViewContextSwapBuffersAborted(); | 1074 renderview->OnViewContextSwapBuffersAborted(); |
| 1075 #endif |
1065 } | 1076 } |
1066 | 1077 |
1067 #endif // defined(ENABLE_GPU) | 1078 #endif // defined(ENABLE_GPU) |
OLD | NEW |