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 "third_party/khronos/GLES2/gl2.h" | 9 #include "third_party/khronos/GLES2/gl2.h" |
10 #ifndef GL_GLEXT_PROTOTYPES | 10 #ifndef GL_GLEXT_PROTOTYPES |
11 #define GL_GLEXT_PROTOTYPES 1 | 11 #define GL_GLEXT_PROTOTYPES 1 |
12 #endif | 12 #endif |
13 #include "third_party/khronos/GLES2/gl2ext.h" | 13 #include "third_party/khronos/GLES2/gl2ext.h" |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/string_tokenizer.h" | 20 #include "base/string_tokenizer.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/debug/trace_event.h" | 22 #include "base/debug/trace_event.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 26 #include "content/common/child_process.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "content/renderer/gpu/command_buffer_proxy.h" | 28 #include "content/renderer/gpu/command_buffer_proxy.h" |
28 #include "content/renderer/gpu/gpu_channel_host.h" | 29 #include "content/renderer/gpu/gpu_channel_host.h" |
29 #include "content/renderer/render_thread_impl.h" | 30 #include "content/renderer/render_thread_impl.h" |
30 #include "content/renderer/render_view_impl.h" | 31 #include "content/renderer/render_view_impl.h" |
31 #include "gpu/command_buffer/client/gles2_implementation.h" | 32 #include "gpu/command_buffer/client/gles2_implementation.h" |
32 #include "gpu/command_buffer/common/constants.h" | 33 #include "gpu/command_buffer/common/constants.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 141 } |
141 | 142 |
142 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { | 143 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { |
143 if (context_) | 144 if (context_) |
144 return true; | 145 return true; |
145 if (initialize_failed_) | 146 if (initialize_failed_) |
146 return false; | 147 return false; |
147 | 148 |
148 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 149 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
149 | 150 |
| 151 // If the context is being initialized on something other than the main |
| 152 // thread, then drop the web_view_ pointer so we don't accidentally |
| 153 // dereference it. |
| 154 MessageLoop* main_message_loop = |
| 155 ChildProcess::current()->main_thread()->message_loop(); |
| 156 if (MessageLoop::current() != main_message_loop) |
| 157 web_view_ = NULL; |
| 158 |
150 // Convert WebGL context creation attributes into RendererGLContext / EGL size | 159 // Convert WebGL context creation attributes into RendererGLContext / EGL size |
151 // requests. | 160 // requests. |
152 const int alpha_size = attributes_.alpha ? 8 : 0; | 161 const int alpha_size = attributes_.alpha ? 8 : 0; |
153 const int depth_size = attributes_.depth ? 24 : 0; | 162 const int depth_size = attributes_.depth ? 24 : 0; |
154 const int stencil_size = attributes_.stencil ? 8 : 0; | 163 const int stencil_size = attributes_.stencil ? 8 : 0; |
155 const int samples = attributes_.antialias ? 4 : 0; | 164 const int samples = attributes_.antialias ? 4 : 0; |
156 const int sample_buffers = attributes_.antialias ? 1 : 0; | 165 const int sample_buffers = attributes_.antialias ? 1 : 0; |
157 const int32 attribs[] = { | 166 const int32 attribs[] = { |
158 RendererGLContext::ALPHA_SIZE, alpha_size, | 167 RendererGLContext::ALPHA_SIZE, alpha_size, |
159 RendererGLContext::DEPTH_SIZE, depth_size, | 168 RendererGLContext::DEPTH_SIZE, depth_size, |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 if (context_lost_callback_) { | 1185 if (context_lost_callback_) { |
1177 context_lost_callback_->onContextLost(); | 1186 context_lost_callback_->onContextLost(); |
1178 } | 1187 } |
1179 RenderViewImpl* renderview = | 1188 RenderViewImpl* renderview = |
1180 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; | 1189 web_view_ ? RenderViewImpl::FromWebView(web_view_) : NULL; |
1181 if (renderview) | 1190 if (renderview) |
1182 renderview->OnViewContextSwapBuffersAborted(); | 1191 renderview->OnViewContextSwapBuffersAborted(); |
1183 } | 1192 } |
1184 | 1193 |
1185 #endif // defined(ENABLE_GPU) | 1194 #endif // defined(ENABLE_GPU) |
OLD | NEW |