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 |
11 #define GL_GLEXT_PROTOTYPES 1 | 11 #define GL_GLEXT_PROTOTYPES 1 |
12 #endif | 12 #endif |
13 #include <GLES2/gl2ext.h> | 13 #include <GLES2/gl2ext.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <set> |
16 | 17 |
| 18 #include "base/lazy_instance.h" |
17 #include "base/string_tokenizer.h" | 19 #include "base/string_tokenizer.h" |
18 #include "base/command_line.h" | 20 #include "base/command_line.h" |
19 #include "base/debug/trace_event.h" | 21 #include "base/debug/trace_event.h" |
20 #include "base/logging.h" | 22 #include "base/logging.h" |
21 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
22 #include "content/common/content_switches.h" | 24 #include "content/common/content_switches.h" |
23 #include "content/renderer/gpu/gpu_channel_host.h" | 25 #include "content/renderer/gpu/gpu_channel_host.h" |
24 #include "content/renderer/render_thread.h" | 26 #include "content/renderer/render_thread.h" |
25 #include "content/renderer/render_view.h" | 27 #include "content/renderer/render_view.h" |
26 #include "gpu/command_buffer/client/gles2_implementation.h" | 28 #include "gpu/command_buffer/client/gles2_implementation.h" |
27 #include "gpu/command_buffer/common/constants.h" | 29 #include "gpu/command_buffer/common/constants.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
31 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" | 33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" |
32 | 34 |
| 35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > |
| 36 g_all_contexts(base::LINKER_INITIALIZED); |
| 37 |
33 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() | 38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() |
34 : context_(NULL), | 39 : context_(NULL), |
35 gl_(NULL), | 40 gl_(NULL), |
36 web_view_(NULL), | 41 web_view_(NULL), |
37 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
38 plugin_handle_(NULL), | 43 plugin_handle_(NULL), |
39 #endif // defined(OS_MACOSX) | 44 #endif // defined(OS_MACOSX) |
40 context_lost_callback_(0), | 45 context_lost_callback_(0), |
41 context_lost_reason_(GL_NO_ERROR), | 46 context_lost_reason_(GL_NO_ERROR), |
42 swapbuffers_complete_callback_(0), | 47 swapbuffers_complete_callback_(0), |
43 cached_width_(0), | 48 cached_width_(0), |
44 cached_height_(0), | 49 cached_height_(0), |
45 bound_fbo_(0) { | 50 bound_fbo_(0) { |
46 } | 51 } |
47 | 52 |
48 WebGraphicsContext3DCommandBufferImpl:: | 53 WebGraphicsContext3DCommandBufferImpl:: |
49 ~WebGraphicsContext3DCommandBufferImpl() { | 54 ~WebGraphicsContext3DCommandBufferImpl() { |
| 55 g_all_contexts.Pointer()->erase(this); |
50 delete context_; | 56 delete context_; |
51 } | 57 } |
52 | 58 |
53 // This string should only be passed for WebGL contexts. Nothing ELSE!!! | 59 // This string should only be passed for WebGL contexts. Nothing ELSE!!! |
54 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of | 60 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of |
55 // a context should not pass this string. | 61 // a context should not pass this string. |
56 static const char* kWebGLPreferredGLExtensions = | 62 static const char* kWebGLPreferredGLExtensions = |
57 "GL_OES_packed_depth_stencil " | 63 "GL_OES_packed_depth_stencil " |
58 "GL_OES_depth24 " | 64 "GL_OES_depth24 " |
59 "GL_CHROMIUM_webglsl"; | 65 "GL_CHROMIUM_webglsl"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 4); | 106 4); |
101 if (attributes.canRecoverFromContextLoss == false) { | 107 if (attributes.canRecoverFromContextLoss == false) { |
102 if (gpu_info.can_lose_context) | 108 if (gpu_info.can_lose_context) |
103 return false; | 109 return false; |
104 } | 110 } |
105 | 111 |
106 GURL active_url; | 112 GURL active_url; |
107 if (web_view && web_view->mainFrame()) | 113 if (web_view && web_view->mainFrame()) |
108 active_url = GURL(web_view->mainFrame()->document().url()); | 114 active_url = GURL(web_view->mainFrame()->document().url()); |
109 | 115 |
| 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 |
| 118 // rely on destruction of the context to clean up owned resources. Putting |
| 119 // them in a share group would prevent this from happening. |
| 120 RendererGLContext* share_group = NULL; |
| 121 if (!attributes.noExtensions) { |
| 122 share_group = g_all_contexts.Pointer()->empty() ? |
| 123 NULL : (*g_all_contexts.Pointer()->begin())->context_; |
| 124 } |
| 125 |
110 if (render_directly_to_web_view) { | 126 if (render_directly_to_web_view) { |
111 RenderView* renderview = RenderView::FromWebView(web_view); | 127 RenderView* renderview = RenderView::FromWebView(web_view); |
112 if (!renderview) | 128 if (!renderview) |
113 return false; | 129 return false; |
114 | 130 |
115 web_view_ = web_view; | 131 web_view_ = web_view; |
116 context_ = RendererGLContext::CreateViewContext( | 132 context_ = RendererGLContext::CreateViewContext( |
117 host, | 133 host, |
118 renderview->routing_id(), | 134 renderview->routing_id(), |
| 135 share_group, |
119 preferred_extensions, | 136 preferred_extensions, |
120 attribs, | 137 attribs, |
121 active_url); | 138 active_url); |
122 if (context_) { | 139 if (context_) { |
123 context_->SetSwapBuffersCallback( | 140 context_->SetSwapBuffersCallback( |
124 NewCallback(this, | 141 NewCallback(this, |
125 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); | 142 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); |
126 } | 143 } |
127 } else { | 144 } else { |
128 context_ = RendererGLContext::CreateOffscreenContext( | 145 context_ = RendererGLContext::CreateOffscreenContext( |
129 host, | 146 host, |
130 gfx::Size(1, 1), | 147 gfx::Size(1, 1), |
| 148 share_group, |
131 preferred_extensions, | 149 preferred_extensions, |
132 attribs, | 150 attribs, |
133 active_url); | 151 active_url); |
134 web_view_ = NULL; | 152 web_view_ = NULL; |
135 } | 153 } |
136 if (!context_) | 154 if (!context_) |
137 return false; | 155 return false; |
138 | 156 |
139 gl_ = context_->GetImplementation(); | 157 gl_ = context_->GetImplementation(); |
140 context_->SetContextLostCallback( | 158 context_->SetContextLostCallback( |
(...skipping 16 matching lines...) Expand all Loading... |
157 getIntegerv(GL_DEPTH_BITS, &depth_bits); | 175 getIntegerv(GL_DEPTH_BITS, &depth_bits); |
158 attributes_.depth = depth_bits > 0; | 176 attributes_.depth = depth_bits > 0; |
159 GLint stencil_bits = 0; | 177 GLint stencil_bits = 0; |
160 getIntegerv(GL_STENCIL_BITS, &stencil_bits); | 178 getIntegerv(GL_STENCIL_BITS, &stencil_bits); |
161 attributes_.stencil = stencil_bits > 0; | 179 attributes_.stencil = stencil_bits > 0; |
162 GLint samples = 0; | 180 GLint samples = 0; |
163 getIntegerv(GL_SAMPLES, &samples); | 181 getIntegerv(GL_SAMPLES, &samples); |
164 attributes_.antialias = samples > 0; | 182 attributes_.antialias = samples > 0; |
165 } | 183 } |
166 | 184 |
| 185 if (!attributes.noExtensions) |
| 186 g_all_contexts.Pointer()->insert(this); |
| 187 |
167 return true; | 188 return true; |
168 } | 189 } |
169 | 190 |
170 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { | 191 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { |
171 return RendererGLContext::MakeCurrent(context_); | 192 return RendererGLContext::MakeCurrent(context_); |
172 } | 193 } |
173 | 194 |
174 int WebGraphicsContext3DCommandBufferImpl::width() { | 195 int WebGraphicsContext3DCommandBufferImpl::width() { |
175 return cached_width_; | 196 return cached_width_; |
176 } | 197 } |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 context_lost_callback_->onContextLost(); | 1049 context_lost_callback_->onContextLost(); |
1029 } | 1050 } |
1030 | 1051 |
1031 RenderView* renderview = | 1052 RenderView* renderview = |
1032 web_view_ ? RenderView::FromWebView(web_view_) : NULL; | 1053 web_view_ ? RenderView::FromWebView(web_view_) : NULL; |
1033 if (renderview) | 1054 if (renderview) |
1034 renderview->OnViewContextSwapBuffersAborted(); | 1055 renderview->OnViewContextSwapBuffersAborted(); |
1035 } | 1056 } |
1036 | 1057 |
1037 #endif // defined(ENABLE_GPU) | 1058 #endif // defined(ENABLE_GPU) |
OLD | NEW |