Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc

Issue 7745042: Revert 98392 - Split WebGraphicsContext3DCommandBufferImpl::initialize() into two stages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #define GL_GLEXT_PROTOTYPES 1 11 #define GL_GLEXT_PROTOTYPES 1
12 #endif 12 #endif
13 #include "gpu/GLES2/gl2ext.h" 13 #include "gpu/GLES2/gl2ext.h"
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <set> 16 #include <set>
17 17
18 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
19 #include "base/string_tokenizer.h" 19 #include "base/string_tokenizer.h"
20 #include "base/command_line.h" 20 #include "base/command_line.h"
21 #include "base/debug/trace_event.h" 21 #include "base/debug/trace_event.h"
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/metrics/histogram.h" 23 #include "base/metrics/histogram.h"
24 #include "base/synchronization/lock.h"
25 #include "content/common/content_switches.h" 24 #include "content/common/content_switches.h"
26 #include "content/renderer/gpu/gpu_channel_host.h" 25 #include "content/renderer/gpu/gpu_channel_host.h"
27 #include "content/renderer/render_thread.h" 26 #include "content/renderer/render_thread.h"
28 #include "content/renderer/render_view.h" 27 #include "content/renderer/render_view.h"
29 #include "gpu/command_buffer/client/gles2_implementation.h" 28 #include "gpu/command_buffer/client/gles2_implementation.h"
30 #include "gpu/command_buffer/common/constants.h" 29 #include "gpu/command_buffer/common/constants.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
34 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" 33 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h"
35 34
36 static base::LazyInstance<base::Lock>
37 g_all_contexts_lock(base::LINKER_INITIALIZED);
38 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > 35 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
39 g_all_contexts(base::LINKER_INITIALIZED); 36 g_all_contexts(base::LINKER_INITIALIZED);
40 37
41 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() 38 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
42 : context_(NULL), 39 : context_(NULL),
43 gl_(NULL), 40 gl_(NULL),
44 #ifndef WTF_USE_THREADED_COMPOSITING 41 #ifndef WTF_USE_THREADED_COMPOSITING
45 web_view_(NULL), 42 web_view_(NULL),
46 #endif 43 #endif
47 #if defined(OS_MACOSX) 44 #if defined(OS_MACOSX)
48 plugin_handle_(NULL), 45 plugin_handle_(NULL),
49 #endif // defined(OS_MACOSX) 46 #endif // defined(OS_MACOSX)
50 context_lost_callback_(0), 47 context_lost_callback_(0),
51 context_lost_reason_(GL_NO_ERROR), 48 context_lost_reason_(GL_NO_ERROR),
52 swapbuffers_complete_callback_(0), 49 swapbuffers_complete_callback_(0),
53 cached_width_(0), 50 cached_width_(0),
54 cached_height_(0), 51 cached_height_(0),
55 bound_fbo_(0) { 52 bound_fbo_(0) {
56 } 53 }
57 54
58 WebGraphicsContext3DCommandBufferImpl:: 55 WebGraphicsContext3DCommandBufferImpl::
59 ~WebGraphicsContext3DCommandBufferImpl() { 56 ~WebGraphicsContext3DCommandBufferImpl() {
60 { 57 g_all_contexts.Pointer()->erase(this);
61 base::AutoLock lock(g_all_contexts_lock.Get());
62 g_all_contexts.Pointer()->erase(this);
63 }
64 delete context_; 58 delete context_;
65 } 59 }
66 60
67 // This string should only be passed for WebGL contexts. Nothing ELSE!!! 61 // This string should only be passed for WebGL contexts. Nothing ELSE!!!
68 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of 62 // Compositor contexts, Canvas2D contexts, Pepper Contexts, nor any other use of
69 // a context should not pass this string. 63 // a context should not pass this string.
70 static const char* kWebGLPreferredGLExtensions = 64 static const char* kWebGLPreferredGLExtensions =
71 "GL_OES_packed_depth_stencil " 65 "GL_OES_packed_depth_stencil "
72 "GL_OES_depth24 " 66 "GL_OES_depth24 "
73 "GL_CHROMIUM_webglsl"; 67 "GL_CHROMIUM_webglsl";
74 68
75 bool WebGraphicsContext3DCommandBufferImpl::initialize( 69 bool WebGraphicsContext3DCommandBufferImpl::initialize(
76 WebGraphicsContext3D::Attributes attributes, 70 WebGraphicsContext3D::Attributes attributes,
77 WebKit::WebView* web_view, 71 WebKit::WebView* web_view,
78 bool render_directly_to_web_view) { 72 bool render_directly_to_web_view) {
79 DCHECK(!context_);
80 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); 73 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize");
81 webkit_glue::BindSkiaToCommandBufferGL(); 74 webkit_glue::BindSkiaToCommandBufferGL();
82 RenderThread* render_thread = RenderThread::current(); 75 RenderThread* render_thread = RenderThread::current();
83 if (!render_thread) 76 if (!render_thread)
84 return false; 77 return false;
85 host_ = render_thread->EstablishGpuChannelSync( 78 GpuChannelHost* host = render_thread->EstablishGpuChannelSync(
86 content:: 79 content::
87 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); 80 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE);
88 if (!host_) 81 if (!host)
89 return false; 82 return false;
90 DCHECK(host_->state() == GpuChannelHost::kConnected); 83 DCHECK(host->state() == GpuChannelHost::kConnected);
91 84
92 const GPUInfo& gpu_info = host_->gpu_info(); 85 // Convert WebGL context creation attributes into RendererGLContext / EGL size
86 // requests.
87 const int alpha_size = attributes.alpha ? 8 : 0;
88 const int depth_size = attributes.depth ? 24 : 0;
89 const int stencil_size = attributes.stencil ? 8 : 0;
90 const int samples = attributes.antialias ? 4 : 0;
91 const int sample_buffers = attributes.antialias ? 1 : 0;
92 const int32 attribs[] = {
93 RendererGLContext::ALPHA_SIZE, alpha_size,
94 RendererGLContext::DEPTH_SIZE, depth_size,
95 RendererGLContext::STENCIL_SIZE, stencil_size,
96 RendererGLContext::SAMPLES, samples,
97 RendererGLContext::SAMPLE_BUFFERS, sample_buffers,
98 RendererGLContext::NONE,
99 };
100
101 const char* preferred_extensions = attributes.noExtensions ?
102 kWebGLPreferredGLExtensions : "*";
103
104 const GPUInfo& gpu_info = host->gpu_info();
93 UMA_HISTOGRAM_ENUMERATION( 105 UMA_HISTOGRAM_ENUMERATION(
94 "GPU.WebGraphicsContext3D_Init_CanLoseContext", 106 "GPU.WebGraphicsContext3D_Init_CanLoseContext",
95 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, 107 attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context,
96 4); 108 4);
97 if (attributes.canRecoverFromContextLoss == false) { 109 if (attributes.canRecoverFromContextLoss == false) {
98 if (gpu_info.can_lose_context) 110 if (gpu_info.can_lose_context)
99 return false; 111 return false;
100 } 112 }
101 113
114 GURL active_url;
102 if (web_view && web_view->mainFrame()) 115 if (web_view && web_view->mainFrame())
103 active_url_ = GURL(web_view->mainFrame()->document().url()); 116 active_url = GURL(web_view->mainFrame()->document().url());
104
105 attributes_ = attributes;
106 render_directly_to_web_view_ = render_directly_to_web_view;
107 if (render_directly_to_web_view_) {
108 RenderView* renderview = RenderView::FromWebView(web_view);
109 if (!renderview)
110 return false;
111 render_view_routing_id_ = renderview->routing_id(),
112 #ifndef WTF_USE_THREADED_COMPOSITING
113 web_view_ = web_view;
114 #endif
115 }
116 return true;
117 }
118
119 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
120 if (context_) {
121 return true;
122 }
123 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL");
124
125 // Convert WebGL context creation attributes into RendererGLContext / EGL size
126 // requests.
127 const int alpha_size = attributes_.alpha ? 8 : 0;
128 const int depth_size = attributes_.depth ? 24 : 0;
129 const int stencil_size = attributes_.stencil ? 8 : 0;
130 const int samples = attributes_.antialias ? 4 : 0;
131 const int sample_buffers = attributes_.antialias ? 1 : 0;
132 const int32 attribs[] = {
133 RendererGLContext::ALPHA_SIZE, alpha_size,
134 RendererGLContext::DEPTH_SIZE, depth_size,
135 RendererGLContext::STENCIL_SIZE, stencil_size,
136 RendererGLContext::SAMPLES, samples,
137 RendererGLContext::SAMPLE_BUFFERS, sample_buffers,
138 RendererGLContext::NONE,
139 };
140 117
141 // 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
142 // 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
143 // 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
144 // them in a share group would prevent this from happening. 121 // them in a share group would prevent this from happening.
145 { 122 RendererGLContext* share_group = NULL;
146 // Need to hold this lock until after RendererGLContext::Create, to ensure 123 if (!attributes.noExtensions) {
147 // the context we picked for our share group isn't deleted (there's also 124 share_group = g_all_contexts.Pointer()->empty() ?
148 // a lock in the destructor). 125 NULL : (*g_all_contexts.Pointer()->begin())->context_;
149 base::AutoLock lock(g_all_contexts_lock.Get()); 126 }
150 RendererGLContext* share_group = NULL;
151 if (!attributes_.noExtensions) {
152 share_group = g_all_contexts.Pointer()->empty() ?
153 NULL : (*g_all_contexts.Pointer()->begin())->context_;
154 }
155 127
156 const char* preferred_extensions = attributes_.noExtensions ? 128 render_directly_to_web_view_ = render_directly_to_web_view;
157 kWebGLPreferredGLExtensions : "*"; 129 if (render_directly_to_web_view) {
158 130 #ifndef WTF_USE_THREADED_COMPOSITING
159 if (render_directly_to_web_view_) { 131 RenderView* renderview = RenderView::FromWebView(web_view);
160 context_ = RendererGLContext::CreateViewContext( 132 if (!renderview)
161 host_, 133 return false;
162 render_view_routing_id_, 134 web_view_ = web_view;
163 !attributes_.noExtensions, 135 #endif
164 share_group, 136 context_ = RendererGLContext::CreateViewContext(
165 preferred_extensions, 137 host,
166 attribs, 138 renderview->routing_id(),
167 active_url_); 139 !attributes.noExtensions,
168 if (context_) { 140 share_group,
169 context_->SetSwapBuffersCallback(NewCallback(this, 141 preferred_extensions,
142 attribs,
143 active_url);
144 if (context_) {
145 context_->SetSwapBuffersCallback(
146 NewCallback(this,
170 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); 147 &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
171 } 148 }
172 } else { 149 } else {
173 context_ = RendererGLContext::CreateOffscreenContext( 150 context_ = RendererGLContext::CreateOffscreenContext(
174 host_, 151 host,
175 gfx::Size(1, 1), 152 gfx::Size(1, 1),
176 !attributes_.noExtensions, 153 !attributes.noExtensions,
177 share_group, 154 share_group,
178 preferred_extensions, 155 preferred_extensions,
179 attribs, 156 attribs,
180 active_url_); 157 active_url);
181 } 158 #ifndef WTF_USE_THREADED_COMPOSITING
159 web_view_ = NULL;
160 #endif
182 } 161 }
183 if (!context_) 162 if (!context_)
184 return false; 163 return false;
185 164
186 gl_ = context_->GetImplementation(); 165 gl_ = context_->GetImplementation();
187 context_->SetContextLostCallback( 166 context_->SetContextLostCallback(
188 NewCallback(this, 167 NewCallback(this,
189 &WebGraphicsContext3DCommandBufferImpl::OnContextLost)); 168 &WebGraphicsContext3DCommandBufferImpl::OnContextLost));
190 169
191 // TODO(gman): Remove this. 170 // TODO(gman): Remove this.
192 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 171 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
193 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) { 172 if (command_line.HasSwitch(switches::kDisableGLSLTranslator)) {
194 context_->DisableShaderTranslation(); 173 context_->DisableShaderTranslation();
195 } 174 }
196 175
197 // Set attributes_ from created offscreen context. 176 // Set attributes_ from created offscreen context.
198 { 177 {
178 attributes_ = attributes;
199 GLint alpha_bits = 0; 179 GLint alpha_bits = 0;
200 getIntegerv(GL_ALPHA_BITS, &alpha_bits); 180 getIntegerv(GL_ALPHA_BITS, &alpha_bits);
201 attributes_.alpha = alpha_bits > 0; 181 attributes_.alpha = alpha_bits > 0;
202 GLint depth_bits = 0; 182 GLint depth_bits = 0;
203 getIntegerv(GL_DEPTH_BITS, &depth_bits); 183 getIntegerv(GL_DEPTH_BITS, &depth_bits);
204 attributes_.depth = depth_bits > 0; 184 attributes_.depth = depth_bits > 0;
205 GLint stencil_bits = 0; 185 GLint stencil_bits = 0;
206 getIntegerv(GL_STENCIL_BITS, &stencil_bits); 186 getIntegerv(GL_STENCIL_BITS, &stencil_bits);
207 attributes_.stencil = stencil_bits > 0; 187 attributes_.stencil = stencil_bits > 0;
208 GLint samples = 0; 188 GLint samples = 0;
209 getIntegerv(GL_SAMPLES, &samples); 189 getIntegerv(GL_SAMPLES, &samples);
210 attributes_.antialias = samples > 0; 190 attributes_.antialias = samples > 0;
211 } 191 }
212 192
213 if (!attributes_.noExtensions) { 193 if (!attributes.noExtensions)
214 base::AutoLock lock(g_all_contexts_lock.Get());
215 g_all_contexts.Pointer()->insert(this); 194 g_all_contexts.Pointer()->insert(this);
216 }
217 195
218 return true; 196 return true;
219 } 197 }
220 198
221 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { 199 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
222 if (!MaybeInitializeGL())
223 return false;
224 return RendererGLContext::MakeCurrent(context_); 200 return RendererGLContext::MakeCurrent(context_);
225 } 201 }
226 202
227 int WebGraphicsContext3DCommandBufferImpl::width() { 203 int WebGraphicsContext3DCommandBufferImpl::width() {
228 return cached_width_; 204 return cached_width_;
229 } 205 }
230 206
231 int WebGraphicsContext3DCommandBufferImpl::height() { 207 int WebGraphicsContext3DCommandBufferImpl::height() {
232 return cached_height_; 208 return cached_height_;
233 } 209 }
234 210
235 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() { 211 bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() {
236 return true; 212 return true;
237 } 213 }
238 214
239 bool WebGraphicsContext3DCommandBufferImpl::setParentContext( 215 bool WebGraphicsContext3DCommandBufferImpl::setParentContext(
240 WebGraphicsContext3D* parent_context) { 216 WebGraphicsContext3D* parent_context) {
241 WebGraphicsContext3DCommandBufferImpl* parent_context_impl = 217 WebGraphicsContext3DCommandBufferImpl* parent_context_impl =
242 static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context); 218 static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context);
243 return context_->SetParent( 219 return context_->SetParent(
244 parent_context_impl ? parent_context_impl->context() : NULL); 220 parent_context_impl ? parent_context_impl->context() : NULL);
245 } 221 }
246 222
247 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { 223 WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() {
224 DCHECK(context_);
248 return context_->GetParentTextureId(); 225 return context_->GetParentTextureId();
249 } 226 }
250 227
251 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { 228 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
252 // 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
253 // used by the compositor. 230 // used by the compositor.
254 #ifndef WTF_USE_THREADED_COMPOSITING 231 #ifndef WTF_USE_THREADED_COMPOSITING
255 RenderView* renderview = 232 RenderView* renderview =
256 web_view_ ? RenderView::FromWebView(web_view_) : NULL; 233 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
257 if (renderview) 234 if (renderview)
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 } 1065 }
1089 #ifndef WTF_USE_THREADED_COMPOSITING 1066 #ifndef WTF_USE_THREADED_COMPOSITING
1090 RenderView* renderview = 1067 RenderView* renderview =
1091 web_view_ ? RenderView::FromWebView(web_view_) : NULL; 1068 web_view_ ? RenderView::FromWebView(web_view_) : NULL;
1092 if (renderview) 1069 if (renderview)
1093 renderview->OnViewContextSwapBuffersAborted(); 1070 renderview->OnViewContextSwapBuffersAborted();
1094 #endif 1071 #endif
1095 } 1072 }
1096 1073
1097 #endif // defined(ENABLE_GPU) 1074 #endif // defined(ENABLE_GPU)
OLDNEW
« no previous file with comments | « content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698