OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
10 #endif | 10 #endif |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/memory/singleton.h" | 24 #include "base/memory/singleton.h" |
25 #include "base/message_loop.h" | 25 #include "base/message_loop.h" |
26 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
27 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
28 #include "gpu/command_buffer/client/gles2_implementation.h" | 28 #include "gpu/command_buffer/client/gles2_implementation.h" |
29 #include "gpu/command_buffer/client/gles2_lib.h" | 29 #include "gpu/command_buffer/client/gles2_lib.h" |
30 #include "gpu/command_buffer/client/transfer_buffer.h" | 30 #include "gpu/command_buffer/client/transfer_buffer.h" |
31 #include "gpu/command_buffer/common/constants.h" | 31 #include "gpu/command_buffer/common/constants.h" |
32 #include "gpu/command_buffer/service/command_buffer_service.h" | 32 #include "gpu/command_buffer/service/command_buffer_service.h" |
33 #include "gpu/command_buffer/service/context_group.h" | 33 #include "gpu/command_buffer/service/context_group.h" |
| 34 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 35 #include "gpu/command_buffer/service/gpu_scheduler.h" |
34 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 36 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
35 #include "gpu/command_buffer/service/gpu_scheduler.h" | |
36 #include "ui/gl/gl_context.h" | 37 #include "ui/gl/gl_context.h" |
37 #include "ui/gl/gl_share_group.h" | 38 #include "ui/gl/gl_share_group.h" |
38 #include "ui/gl/gl_surface.h" | 39 #include "ui/gl/gl_surface.h" |
39 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" | 40 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" |
40 | 41 |
41 using gpu::Buffer; | 42 using gpu::Buffer; |
42 using gpu::CommandBuffer; | 43 using gpu::CommandBuffer; |
43 using gpu::CommandBufferService; | 44 using gpu::CommandBufferService; |
44 using gpu::gles2::GLES2CmdHelper; | 45 using gpu::gles2::GLES2CmdHelper; |
45 using gpu::gles2::GLES2Implementation; | 46 using gpu::gles2::GLES2Implementation; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // thread. In layout tests, any thread could call this function. GLES2Decoder, | 235 // thread. In layout tests, any thread could call this function. GLES2Decoder, |
235 // and in particular the GL implementations behind it, are not generally | 236 // and in particular the GL implementations behind it, are not generally |
236 // threadsafe, so we guard entry points with a mutex. | 237 // threadsafe, so we guard entry points with a mutex. |
237 static base::LazyInstance<base::Lock> g_decoder_lock = | 238 static base::LazyInstance<base::Lock> g_decoder_lock = |
238 LAZY_INSTANCE_INITIALIZER; | 239 LAZY_INSTANCE_INITIALIZER; |
239 | 240 |
240 static base::LazyInstance< | 241 static base::LazyInstance< |
241 std::set<GLInProcessContext*> > | 242 std::set<GLInProcessContext*> > |
242 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 243 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
243 | 244 |
| 245 static bool g_use_virtualized_gl_context = false; |
| 246 |
244 namespace { | 247 namespace { |
245 | 248 |
246 // Also calls DetachFromThread on all GLES2Decoders before the lock is released | 249 // Also calls DetachFromThread on all GLES2Decoders before the lock is released |
247 // to maintain the invariant that all decoders are unbounded while the lock is | 250 // to maintain the invariant that all decoders are unbounded while the lock is |
248 // not held. This is to workaround DumpRenderTree uses WGC3DIPCBI with shared | 251 // not held. This is to workaround DumpRenderTree uses WGC3DIPCBI with shared |
249 // resources on different threads. | 252 // resources on different threads. |
250 class AutoLockAndDecoderDetachThread { | 253 class AutoLockAndDecoderDetachThread { |
251 public: | 254 public: |
252 AutoLockAndDecoderDetachThread(base::Lock& lock, | 255 AutoLockAndDecoderDetachThread(base::Lock& lock, |
253 const std::set<GLInProcessContext*>& contexts); | 256 const std::set<GLInProcessContext*>& contexts); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); | 474 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); |
472 else | 475 else |
473 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); | 476 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); |
474 | 477 |
475 if (!surface_.get()) { | 478 if (!surface_.get()) { |
476 LOG(ERROR) << "Could not create GLSurface."; | 479 LOG(ERROR) << "Could not create GLSurface."; |
477 Destroy(); | 480 Destroy(); |
478 return false; | 481 return false; |
479 } | 482 } |
480 | 483 |
481 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | 484 if (g_use_virtualized_gl_context) { |
482 surface_.get(), | 485 context_ = share_group->GetSharedContext(); |
483 gpu_preference); | 486 if (!context_) { |
| 487 context_ = gfx::GLContext::CreateGLContext(share_group.get(), |
| 488 surface_.get(), |
| 489 gpu_preference); |
| 490 share_group->SetSharedContext(context_); |
| 491 } |
| 492 |
| 493 context_ = new ::gpu::GLContextVirtual(share_group.get(), |
| 494 context_, |
| 495 decoder_->AsWeakPtr()); |
| 496 if (context_->Initialize(surface_, gpu_preference)) { |
| 497 VLOG(1) << "Created virtual GL context."; |
| 498 } else { |
| 499 context_ = NULL; |
| 500 } |
| 501 } else { |
| 502 context_ = gfx::GLContext::CreateGLContext(share_group.get(), |
| 503 surface_.get(), |
| 504 gpu_preference); |
| 505 } |
| 506 |
484 if (!context_.get()) { | 507 if (!context_.get()) { |
485 LOG(ERROR) << "Could not create GLContext."; | 508 LOG(ERROR) << "Could not create GLContext."; |
486 Destroy(); | 509 Destroy(); |
487 return false; | 510 return false; |
488 } | 511 } |
489 | 512 |
490 if (!context_->MakeCurrent(surface_.get())) { | 513 if (!context_->MakeCurrent(surface_.get())) { |
491 LOG(ERROR) << "Could not make context current."; | 514 LOG(ERROR) << "Could not make context current."; |
492 Destroy(); | 515 Destroy(); |
493 return false; | 516 return false; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 599 } |
577 | 600 |
578 g_all_shared_contexts.Pointer()->erase(this); | 601 g_all_shared_contexts.Pointer()->erase(this); |
579 } | 602 } |
580 | 603 |
581 void GLInProcessContext::OnContextLost() { | 604 void GLInProcessContext::OnContextLost() { |
582 if (!context_lost_callback_.is_null()) | 605 if (!context_lost_callback_.is_null()) |
583 context_lost_callback_.Run(); | 606 context_lost_callback_.Run(); |
584 } | 607 } |
585 | 608 |
| 609 // static |
| 610 void |
| 611 WebGraphicsContext3DInProcessCommandBufferImpl::EnableVirtualizedContext() { |
| 612 #if !defined(NDEBUG) |
| 613 { |
| 614 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 615 g_all_shared_contexts.Get()); |
| 616 DCHECK(g_all_shared_contexts.Get().empty()); |
| 617 } |
| 618 #endif // !defined(NDEBUG) |
| 619 g_use_virtualized_gl_context = true; |
| 620 } |
586 | 621 |
587 // static | 622 // static |
588 WebGraphicsContext3DInProcessCommandBufferImpl* | 623 WebGraphicsContext3DInProcessCommandBufferImpl* |
589 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | 624 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
590 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 625 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
591 gfx::AcceleratedWidget window) { | 626 gfx::AcceleratedWidget window) { |
592 return new WebGraphicsContext3DInProcessCommandBufferImpl( | 627 return new WebGraphicsContext3DInProcessCommandBufferImpl( |
593 attributes, false, window); | 628 attributes, false, window); |
594 } | 629 } |
595 | 630 |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 | 1797 |
1763 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1798 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
1764 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1799 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
1765 WGC3Denum, WGC3Denum, const void*) | 1800 WGC3Denum, WGC3Denum, const void*) |
1766 | 1801 |
1767 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1802 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
1768 WGC3Denum) | 1803 WGC3Denum) |
1769 | 1804 |
1770 } // namespace gpu | 1805 } // namespace gpu |
1771 } // namespace webkit | 1806 } // namespace webkit |
OLD | NEW |