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