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 "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 7 #include "webkit/gpu/webgraphicscontext3d_in_process_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 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // already in place. We could add more entry points and messages to | 96 // already in place. We could add more entry points and messages to |
97 // allocate both fake PluginWindowHandles and NativeViewIds and map | 97 // allocate both fake PluginWindowHandles and NativeViewIds and map |
98 // from fake NativeViewIds to PluginWindowHandles, but this seems like | 98 // from fake NativeViewIds to PluginWindowHandles, but this seems like |
99 // unnecessary complexity at the moment. | 99 // unnecessary complexity at the moment. |
100 // | 100 // |
101 static GLInProcessContext* CreateViewContext( | 101 static GLInProcessContext* CreateViewContext( |
102 gfx::PluginWindowHandle render_surface, | 102 gfx::PluginWindowHandle render_surface, |
103 GLInProcessContext* context_group, | 103 GLInProcessContext* context_group, |
104 const char* allowed_extensions, | 104 const char* allowed_extensions, |
105 const int32* attrib_list, | 105 const int32* attrib_list, |
106 const GURL& active_arl); | 106 const GURL& active_url, |
| 107 gfx::GpuPreference gpu_preference); |
107 | 108 |
108 // Create a GLInProcessContext that renders to an offscreen frame buffer. If | 109 // Create a GLInProcessContext that renders to an offscreen frame buffer. If |
109 // parent is not NULL, that GLInProcessContext can access a copy of the | 110 // parent is not NULL, that GLInProcessContext can access a copy of the |
110 // created GLInProcessContext's frame buffer that is updated every time | 111 // created GLInProcessContext's frame buffer that is updated every time |
111 // SwapBuffers is called. It is not as general as shared GLInProcessContexts | 112 // SwapBuffers is called. It is not as general as shared GLInProcessContexts |
112 // in other implementations of OpenGL. If parent is not NULL, it must be used | 113 // in other implementations of OpenGL. If parent is not NULL, it must be used |
113 // on the same thread as the parent. A child GLInProcessContext may not | 114 // on the same thread as the parent. A child GLInProcessContext may not |
114 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of | 115 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of |
115 // attribute/value pairs. | 116 // attribute/value pairs. |
116 static GLInProcessContext* CreateOffscreenContext( | 117 static GLInProcessContext* CreateOffscreenContext( |
117 GLInProcessContext* parent, | 118 GLInProcessContext* parent, |
118 const gfx::Size& size, | 119 const gfx::Size& size, |
119 GLInProcessContext* context_group, | 120 GLInProcessContext* context_group, |
120 const char* allowed_extensions, | 121 const char* allowed_extensions, |
121 const int32* attrib_list, | 122 const int32* attrib_list, |
122 const GURL& active_url); | 123 const GURL& active_url, |
| 124 gfx::GpuPreference gpu_preference); |
123 | 125 |
124 // For an offscreen frame buffer GLInProcessContext, return the texture ID | 126 // For an offscreen frame buffer GLInProcessContext, return the texture ID |
125 // with respect to the parent GLInProcessContext. Returns zero if | 127 // with respect to the parent GLInProcessContext. Returns zero if |
126 // GLInProcessContext does not have a parent. | 128 // GLInProcessContext does not have a parent. |
127 uint32 GetParentTextureId(); | 129 uint32 GetParentTextureId(); |
128 | 130 |
129 // Create a new texture in the parent's GLInProcessContext. Returns zero if | 131 // Create a new texture in the parent's GLInProcessContext. Returns zero if |
130 // GLInProcessContext does not have a parent. | 132 // GLInProcessContext does not have a parent. |
131 uint32 CreateParentTexture(const gfx::Size& size); | 133 uint32 CreateParentTexture(const gfx::Size& size); |
132 | 134 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 168 |
167 private: | 169 private: |
168 GLInProcessContext(GLInProcessContext* parent); | 170 GLInProcessContext(GLInProcessContext* parent); |
169 | 171 |
170 bool Initialize(bool onscreen, | 172 bool Initialize(bool onscreen, |
171 gfx::PluginWindowHandle render_surface, | 173 gfx::PluginWindowHandle render_surface, |
172 const gfx::Size& size, | 174 const gfx::Size& size, |
173 GLInProcessContext* context_group, | 175 GLInProcessContext* context_group, |
174 const char* allowed_extensions, | 176 const char* allowed_extensions, |
175 const int32* attrib_list, | 177 const int32* attrib_list, |
176 const GURL& active_url); | 178 const GURL& active_url, |
| 179 gfx::GpuPreference gpu_preference); |
177 void Destroy(); | 180 void Destroy(); |
178 | 181 |
179 void OnSwapBuffers(); | 182 void OnSwapBuffers(); |
180 void OnContextLost(); | 183 void OnContextLost(); |
181 | 184 |
182 base::WeakPtr<GLInProcessContext> parent_; | 185 base::WeakPtr<GLInProcessContext> parent_; |
183 scoped_ptr<Callback0::Type> swap_buffers_callback_; | 186 scoped_ptr<Callback0::Type> swap_buffers_callback_; |
184 scoped_ptr<Callback0::Type> context_lost_callback_; | 187 scoped_ptr<Callback0::Type> context_lost_callback_; |
185 uint32 parent_texture_id_; | 188 uint32 parent_texture_id_; |
186 scoped_ptr<CommandBufferService> command_buffer_; | 189 scoped_ptr<CommandBufferService> command_buffer_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 236 |
234 GLInProcessContext::~GLInProcessContext() { | 237 GLInProcessContext::~GLInProcessContext() { |
235 Destroy(); | 238 Destroy(); |
236 } | 239 } |
237 | 240 |
238 GLInProcessContext* GLInProcessContext::CreateViewContext( | 241 GLInProcessContext* GLInProcessContext::CreateViewContext( |
239 gfx::PluginWindowHandle render_surface, | 242 gfx::PluginWindowHandle render_surface, |
240 GLInProcessContext* context_group, | 243 GLInProcessContext* context_group, |
241 const char* allowed_extensions, | 244 const char* allowed_extensions, |
242 const int32* attrib_list, | 245 const int32* attrib_list, |
243 const GURL& active_url) { | 246 const GURL& active_url, |
| 247 gfx::GpuPreference gpu_preference) { |
244 #if defined(ENABLE_GPU) | 248 #if defined(ENABLE_GPU) |
245 scoped_ptr<GLInProcessContext> context(new GLInProcessContext(NULL)); | 249 scoped_ptr<GLInProcessContext> context(new GLInProcessContext(NULL)); |
246 if (!context->Initialize( | 250 if (!context->Initialize( |
247 true, | 251 true, |
248 render_surface, | 252 render_surface, |
249 gfx::Size(), | 253 gfx::Size(), |
250 context_group, | 254 context_group, |
251 allowed_extensions, | 255 allowed_extensions, |
252 attrib_list, | 256 attrib_list, |
253 active_url)) | 257 active_url, |
| 258 gpu_preference)) |
254 return NULL; | 259 return NULL; |
255 | 260 |
256 return context.release(); | 261 return context.release(); |
257 #else | 262 #else |
258 return NULL; | 263 return NULL; |
259 #endif | 264 #endif |
260 } | 265 } |
261 | 266 |
262 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( | 267 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( |
263 GLInProcessContext* parent, | 268 GLInProcessContext* parent, |
264 const gfx::Size& size, | 269 const gfx::Size& size, |
265 GLInProcessContext* context_group, | 270 GLInProcessContext* context_group, |
266 const char* allowed_extensions, | 271 const char* allowed_extensions, |
267 const int32* attrib_list, | 272 const int32* attrib_list, |
268 const GURL& active_url) { | 273 const GURL& active_url, |
| 274 gfx::GpuPreference gpu_preference) { |
269 #if defined(ENABLE_GPU) | 275 #if defined(ENABLE_GPU) |
270 scoped_ptr<GLInProcessContext> context(new GLInProcessContext(parent)); | 276 scoped_ptr<GLInProcessContext> context(new GLInProcessContext(parent)); |
271 if (!context->Initialize( | 277 if (!context->Initialize( |
272 false, | 278 false, |
273 gfx::kNullPluginWindow, | 279 gfx::kNullPluginWindow, |
274 size, | 280 size, |
275 context_group, | 281 context_group, |
276 allowed_extensions, | 282 allowed_extensions, |
277 attrib_list, | 283 attrib_list, |
278 active_url)) | 284 active_url, |
| 285 gpu_preference)) |
279 return NULL; | 286 return NULL; |
280 | 287 |
281 return context.release(); | 288 return context.release(); |
282 #else | 289 #else |
283 return NULL; | 290 return NULL; |
284 #endif | 291 #endif |
285 } | 292 } |
286 | 293 |
287 // In the normal command buffer implementation, all commands are passed over IPC | 294 // In the normal command buffer implementation, all commands are passed over IPC |
288 // to the gpu process where they are fed to the GLES2Decoder from a single | 295 // to the gpu process where they are fed to the GLES2Decoder from a single |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 transfer_buffer_id_(-1), | 397 transfer_buffer_id_(-1), |
391 last_error_(SUCCESS) { | 398 last_error_(SUCCESS) { |
392 } | 399 } |
393 | 400 |
394 bool GLInProcessContext::Initialize(bool onscreen, | 401 bool GLInProcessContext::Initialize(bool onscreen, |
395 gfx::PluginWindowHandle render_surface, | 402 gfx::PluginWindowHandle render_surface, |
396 const gfx::Size& size, | 403 const gfx::Size& size, |
397 GLInProcessContext* context_group, | 404 GLInProcessContext* context_group, |
398 const char* allowed_extensions, | 405 const char* allowed_extensions, |
399 const int32* attrib_list, | 406 const int32* attrib_list, |
400 const GURL& active_url) { | 407 const GURL& active_url, |
| 408 gfx::GpuPreference gpu_preference) { |
401 // Use one share group for all contexts. | 409 // Use one share group for all contexts. |
402 static scoped_refptr<gfx::GLShareGroup> share_group(new gfx::GLShareGroup); | 410 static scoped_refptr<gfx::GLShareGroup> share_group(new gfx::GLShareGroup); |
403 | 411 |
404 DCHECK(size.width() >= 0 && size.height() >= 0); | 412 DCHECK(size.width() >= 0 && size.height() >= 0); |
405 | 413 |
406 // Ensure the gles2 library is initialized first in a thread safe way. | 414 // Ensure the gles2 library is initialized first in a thread safe way. |
407 g_gles2_initializer.Get(); | 415 g_gles2_initializer.Get(); |
408 | 416 |
409 // Allocate a frame buffer ID with respect to the parent. | 417 // Allocate a frame buffer ID with respect to the parent. |
410 if (parent_.get()) { | 418 if (parent_.get()) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, | 481 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, |
474 gfx::Size(1, 1)); | 482 gfx::Size(1, 1)); |
475 } | 483 } |
476 | 484 |
477 if (!surface_.get()) { | 485 if (!surface_.get()) { |
478 LOG(ERROR) << "Could not create GLSurface."; | 486 LOG(ERROR) << "Could not create GLSurface."; |
479 Destroy(); | 487 Destroy(); |
480 return false; | 488 return false; |
481 } | 489 } |
482 | 490 |
483 context_ = gfx::GLContext::CreateGLContext(share_group.get(), surface_.get()); | 491 context_ = gfx::GLContext::CreateGLContext(share_group.get(), |
| 492 surface_.get(), |
| 493 gpu_preference); |
484 if (!context_.get()) { | 494 if (!context_.get()) { |
485 LOG(ERROR) << "Could not create GLContext."; | 495 LOG(ERROR) << "Could not create GLContext."; |
486 Destroy(); | 496 Destroy(); |
487 return false; | 497 return false; |
488 } | 498 } |
489 | 499 |
490 if (!decoder_->Initialize(surface_.get(), | 500 if (!decoder_->Initialize(surface_.get(), |
491 context_.get(), | 501 context_.get(), |
492 size, | 502 size, |
493 ::gpu::gles2::DisallowedFeatures(), | 503 ::gpu::gles2::DisallowedFeatures(), |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 GLInProcessContext::ALPHA_SIZE, alpha_size, | 628 GLInProcessContext::ALPHA_SIZE, alpha_size, |
619 GLInProcessContext::DEPTH_SIZE, depth_size, | 629 GLInProcessContext::DEPTH_SIZE, depth_size, |
620 GLInProcessContext::STENCIL_SIZE, stencil_size, | 630 GLInProcessContext::STENCIL_SIZE, stencil_size, |
621 GLInProcessContext::SAMPLES, samples, | 631 GLInProcessContext::SAMPLES, samples, |
622 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, | 632 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, |
623 GLInProcessContext::NONE, | 633 GLInProcessContext::NONE, |
624 }; | 634 }; |
625 | 635 |
626 const char* preferred_extensions = "*"; | 636 const char* preferred_extensions = "*"; |
627 | 637 |
| 638 // TODO(kbr): More work will be needed in this implementation to |
| 639 // properly support GPU switching. Like in the out-of-process |
| 640 // command buffer implementation, all previously created contexts |
| 641 // will need to be lost either when the first context requesting the |
| 642 // discrete GPU is created, or the last one is destroyed. |
| 643 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 644 |
628 GURL active_url; | 645 GURL active_url; |
629 if (web_view && web_view->mainFrame()) | 646 if (web_view && web_view->mainFrame()) |
630 active_url = GURL(web_view->mainFrame()->document().url()); | 647 active_url = GURL(web_view->mainFrame()->document().url()); |
631 | 648 |
632 GLInProcessContext* parent_context = NULL; | 649 GLInProcessContext* parent_context = NULL; |
633 if (!render_directly_to_web_view) { | 650 if (!render_directly_to_web_view) { |
634 WebKit::WebGraphicsContext3D* view_context = | 651 WebKit::WebGraphicsContext3D* view_context = |
635 web_view ? web_view->graphicsContext3D() : NULL; | 652 web_view ? web_view->graphicsContext3D() : NULL; |
636 if (view_context) { | 653 if (view_context) { |
637 WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = | 654 WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = |
638 static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( | 655 static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( |
639 view_context); | 656 view_context); |
640 parent_context = context_impl->context_; | 657 parent_context = context_impl->context_; |
641 } | 658 } |
642 } | 659 } |
643 | 660 |
644 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; | 661 WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; |
645 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 662 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
646 if (attributes.shareResources) | 663 if (attributes.shareResources) |
647 context_group = g_all_shared_contexts.Pointer()->empty() ? | 664 context_group = g_all_shared_contexts.Pointer()->empty() ? |
648 NULL : *g_all_shared_contexts.Pointer()->begin(); | 665 NULL : *g_all_shared_contexts.Pointer()->begin(); |
649 | 666 |
650 context_ = GLInProcessContext::CreateOffscreenContext( | 667 context_ = GLInProcessContext::CreateOffscreenContext( |
651 parent_context, | 668 parent_context, |
652 gfx::Size(1, 1), | 669 gfx::Size(1, 1), |
653 context_group ? context_group->context_ : NULL, | 670 context_group ? context_group->context_ : NULL, |
654 preferred_extensions, | 671 preferred_extensions, |
655 attribs, | 672 attribs, |
656 active_url); | 673 active_url, |
| 674 gpu_preference); |
657 web_view_ = NULL; | 675 web_view_ = NULL; |
658 | 676 |
659 if (!context_) | 677 if (!context_) |
660 return false; | 678 return false; |
661 | 679 |
662 gl_ = context_->GetImplementation(); | 680 gl_ = context_->GetImplementation(); |
663 | 681 |
664 if (gl_ && attributes.noExtensions) | 682 if (gl_ && attributes.noExtensions) |
665 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 683 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
666 | 684 |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1627 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
1610 if (context_lost_callback_) { | 1628 if (context_lost_callback_) { |
1611 context_lost_callback_->onContextLost(); | 1629 context_lost_callback_->onContextLost(); |
1612 } | 1630 } |
1613 } | 1631 } |
1614 | 1632 |
1615 } // namespace gpu | 1633 } // namespace gpu |
1616 } // namespace webkit | 1634 } // namespace webkit |
1617 | 1635 |
1618 #endif // defined(ENABLE_GPU) | 1636 #endif // defined(ENABLE_GPU) |
OLD | NEW |