Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an | 93 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an |
| 93 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list | 94 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list |
| 94 // of attribute/value pairs. | 95 // of attribute/value pairs. |
| 95 static GLInProcessContext* CreateContext( | 96 static GLInProcessContext* CreateContext( |
| 96 bool is_offscreen, | 97 bool is_offscreen, |
| 97 gfx::AcceleratedWidget window, | 98 gfx::AcceleratedWidget window, |
| 98 const gfx::Size& size, | 99 const gfx::Size& size, |
| 99 bool share_resources, | 100 bool share_resources, |
| 100 const char* allowed_extensions, | 101 const char* allowed_extensions, |
| 101 const int32* attrib_list, | 102 const int32* attrib_list, |
| 102 gfx::GpuPreference gpu_preference); | 103 gfx::GpuPreference gpu_preference, |
| 104 bool use_virtualized_gl_context_if_possible); | |
| 103 | 105 |
| 104 // For an offscreen frame buffer GLInProcessContext, return the texture ID | 106 // For an offscreen frame buffer GLInProcessContext, return the texture ID |
| 105 // with respect to the parent GLInProcessContext. Returns zero if | 107 // with respect to the parent GLInProcessContext. Returns zero if |
| 106 // GLInProcessContext does not have a parent. | 108 // GLInProcessContext does not have a parent. |
| 107 uint32 GetParentTextureId(); | 109 uint32 GetParentTextureId(); |
| 108 | 110 |
| 109 // Create a new texture in the parent's GLInProcessContext. Returns zero if | 111 // Create a new texture in the parent's GLInProcessContext. Returns zero if |
| 110 // GLInProcessContext does not have a parent. | 112 // GLInProcessContext does not have a parent. |
| 111 uint32 CreateParentTexture(const gfx::Size& size); | 113 uint32 CreateParentTexture(const gfx::Size& size); |
| 112 | 114 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 143 ::gpu::gles2::GLES2Decoder* GetDecoder(); | 145 ::gpu::gles2::GLES2Decoder* GetDecoder(); |
| 144 | 146 |
| 145 private: | 147 private: |
| 146 explicit GLInProcessContext(bool share_resources); | 148 explicit GLInProcessContext(bool share_resources); |
| 147 | 149 |
| 148 bool Initialize(bool is_offscreen, | 150 bool Initialize(bool is_offscreen, |
| 149 gfx::AcceleratedWidget window, | 151 gfx::AcceleratedWidget window, |
| 150 const gfx::Size& size, | 152 const gfx::Size& size, |
| 151 const char* allowed_extensions, | 153 const char* allowed_extensions, |
| 152 const int32* attrib_list, | 154 const int32* attrib_list, |
| 153 gfx::GpuPreference gpu_preference); | 155 gfx::GpuPreference gpu_preference, |
| 156 bool use_virtualized_gl_context_if_possible); | |
| 154 void Destroy(); | 157 void Destroy(); |
| 155 | 158 |
| 156 void OnContextLost(); | 159 void OnContextLost(); |
| 157 | 160 |
| 158 base::Closure context_lost_callback_; | 161 base::Closure context_lost_callback_; |
| 159 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 162 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 160 scoped_ptr<CommandBufferService> command_buffer_; | 163 scoped_ptr<CommandBufferService> command_buffer_; |
| 161 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 164 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 162 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 165 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 163 scoped_refptr<gfx::GLContext> context_; | 166 scoped_refptr<gfx::GLContext> context_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 Destroy(); | 210 Destroy(); |
| 208 } | 211 } |
| 209 | 212 |
| 210 GLInProcessContext* GLInProcessContext::CreateContext( | 213 GLInProcessContext* GLInProcessContext::CreateContext( |
| 211 bool is_offscreen, | 214 bool is_offscreen, |
| 212 gfx::AcceleratedWidget window, | 215 gfx::AcceleratedWidget window, |
| 213 const gfx::Size& size, | 216 const gfx::Size& size, |
| 214 bool share_resources, | 217 bool share_resources, |
| 215 const char* allowed_extensions, | 218 const char* allowed_extensions, |
| 216 const int32* attrib_list, | 219 const int32* attrib_list, |
| 217 gfx::GpuPreference gpu_preference) { | 220 gfx::GpuPreference gpu_preference, |
| 221 bool use_virtualized_gl_context_if_possible) { | |
| 218 scoped_ptr<GLInProcessContext> context( | 222 scoped_ptr<GLInProcessContext> context( |
| 219 new GLInProcessContext(share_resources)); | 223 new GLInProcessContext(share_resources)); |
| 220 if (!context->Initialize( | 224 if (!context->Initialize( |
| 221 is_offscreen, | 225 is_offscreen, |
| 222 window, | 226 window, |
| 223 size, | 227 size, |
| 224 allowed_extensions, | 228 allowed_extensions, |
| 225 attrib_list, | 229 attrib_list, |
| 226 gpu_preference)) | 230 gpu_preference, |
| 231 use_virtualized_gl_context_if_possible)) | |
| 227 return NULL; | 232 return NULL; |
| 228 | 233 |
| 229 return context.release(); | 234 return context.release(); |
| 230 } | 235 } |
| 231 | 236 |
| 232 // In the normal command buffer implementation, all commands are passed over IPC | 237 // In the normal command buffer implementation, all commands are passed over IPC |
| 233 // to the gpu process where they are fed to the GLES2Decoder from a single | 238 // to the gpu process where they are fed to the GLES2Decoder from a single |
| 234 // thread. In layout tests, any thread could call this function. GLES2Decoder, | 239 // thread. In layout tests, any thread could call this function. GLES2Decoder, |
| 235 // and in particular the GL implementations behind it, are not generally | 240 // and in particular the GL implementations behind it, are not generally |
| 236 // threadsafe, so we guard entry points with a mutex. | 241 // threadsafe, so we guard entry points with a mutex. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 share_resources_(share_resources), | 392 share_resources_(share_resources), |
| 388 context_lost_(false) { | 393 context_lost_(false) { |
| 389 } | 394 } |
| 390 | 395 |
| 391 bool GLInProcessContext::Initialize( | 396 bool GLInProcessContext::Initialize( |
| 392 bool is_offscreen, | 397 bool is_offscreen, |
| 393 gfx::AcceleratedWidget window, | 398 gfx::AcceleratedWidget window, |
| 394 const gfx::Size& size, | 399 const gfx::Size& size, |
| 395 const char* allowed_extensions, | 400 const char* allowed_extensions, |
| 396 const int32* attrib_list, | 401 const int32* attrib_list, |
| 397 gfx::GpuPreference gpu_preference) { | 402 gfx::GpuPreference gpu_preference, |
| 403 bool use_virtualized_gl_context_if_possible) { | |
| 398 // Use one share group for all contexts. | 404 // Use one share group for all contexts. |
| 399 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, | 405 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, |
| 400 (new gfx::GLShareGroup)); | 406 (new gfx::GLShareGroup)); |
| 401 | 407 |
| 402 DCHECK(size.width() >= 0 && size.height() >= 0); | 408 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 403 | 409 |
| 404 // Ensure the gles2 library is initialized first in a thread safe way. | 410 // Ensure the gles2 library is initialized first in a thread safe way. |
| 405 g_gles2_initializer.Get(); | 411 g_gles2_initializer.Get(); |
| 406 | 412 |
| 407 std::vector<int32> attribs; | 413 std::vector<int32> attribs; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); | 477 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); |
| 472 else | 478 else |
| 473 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); | 479 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); |
| 474 | 480 |
| 475 if (!surface_.get()) { | 481 if (!surface_.get()) { |
| 476 LOG(ERROR) << "Could not create GLSurface."; | 482 LOG(ERROR) << "Could not create GLSurface."; |
| 477 Destroy(); | 483 Destroy(); |
| 478 return false; | 484 return false; |
| 479 } | 485 } |
| 480 | 486 |
| 481 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | 487 if (use_virtualized_gl_context_if_possible) { |
| 482 surface_.get(), | 488 context_ = share_group->GetSharedContext(); |
| 483 gpu_preference); | 489 if (!context_) { |
| 490 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | |
| 491 surface_.get(), | |
| 492 gpu_preference); | |
| 493 share_group->SetSharedContext(context_); | |
| 494 } | |
| 495 | |
| 496 context_ = new ::gpu::GLContextVirtual(share_group.get(), | |
| 497 context_, | |
| 498 decoder_->AsWeakPtr()); | |
| 499 if (context_->Initialize(surface_, gpu_preference)) { | |
| 500 VLOG(1) << "Created virtual GL context."; | |
| 501 } else { | |
| 502 context_ = NULL; | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 if (!context_) { | |
| 507 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | |
| 508 surface_.get(), | |
| 509 gpu_preference); | |
| 510 } | |
| 511 | |
| 484 if (!context_.get()) { | 512 if (!context_.get()) { |
| 485 LOG(ERROR) << "Could not create GLContext."; | 513 LOG(ERROR) << "Could not create GLContext."; |
| 486 Destroy(); | 514 Destroy(); |
| 487 return false; | 515 return false; |
| 488 } | 516 } |
| 489 | 517 |
| 490 if (!context_->MakeCurrent(surface_.get())) { | 518 if (!context_->MakeCurrent(surface_.get())) { |
| 491 LOG(ERROR) << "Could not make context current."; | 519 LOG(ERROR) << "Could not make context current."; |
| 492 Destroy(); | 520 Destroy(); |
| 493 return false; | 521 return false; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 void GLInProcessContext::OnContextLost() { | 609 void GLInProcessContext::OnContextLost() { |
| 582 if (!context_lost_callback_.is_null()) | 610 if (!context_lost_callback_.is_null()) |
| 583 context_lost_callback_.Run(); | 611 context_lost_callback_.Run(); |
| 584 } | 612 } |
| 585 | 613 |
| 586 | 614 |
| 587 // static | 615 // static |
| 588 WebGraphicsContext3DInProcessCommandBufferImpl* | 616 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 589 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | 617 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
| 590 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 618 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 591 gfx::AcceleratedWidget window) { | 619 gfx::AcceleratedWidget window, |
| 620 bool use_virtualized_gl_context_if_possible) { | |
| 592 return new WebGraphicsContext3DInProcessCommandBufferImpl( | 621 return new WebGraphicsContext3DInProcessCommandBufferImpl( |
| 593 attributes, false, window); | 622 attributes, false, window, use_virtualized_gl_context_if_possible); |
| 594 } | 623 } |
| 595 | 624 |
| 596 // static | 625 // static |
| 597 WebGraphicsContext3DInProcessCommandBufferImpl* | 626 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 598 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | 627 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( |
| 599 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | 628 const WebKit::WebGraphicsContext3D::Attributes& attributes) { |
| 600 return new WebGraphicsContext3DInProcessCommandBufferImpl( | 629 return new WebGraphicsContext3DInProcessCommandBufferImpl( |
| 601 attributes, true, gfx::kNullAcceleratedWidget); | 630 attributes, true, gfx::kNullAcceleratedWidget, false); |
|
piman
2013/04/19 22:51:00
Why false here?
boliu
2013/04/19 22:53:22
Retaining old behavior to not use GLVirtualContext
| |
| 602 } | 631 } |
| 603 | 632 |
| 604 WebGraphicsContext3DInProcessCommandBufferImpl:: | 633 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 605 WebGraphicsContext3DInProcessCommandBufferImpl( | 634 WebGraphicsContext3DInProcessCommandBufferImpl( |
| 606 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 635 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 607 bool is_offscreen, | 636 bool is_offscreen, |
| 608 gfx::AcceleratedWidget window) | 637 gfx::AcceleratedWidget window, |
| 638 bool use_virtualized_gl_context_if_possible) | |
| 609 : is_offscreen_(is_offscreen), | 639 : is_offscreen_(is_offscreen), |
| 610 window_(window), | 640 window_(window), |
| 641 use_virtualized_gl_context_if_possible_( | |
| 642 use_virtualized_gl_context_if_possible), | |
| 611 initialized_(false), | 643 initialized_(false), |
| 612 initialize_failed_(false), | 644 initialize_failed_(false), |
| 613 context_(NULL), | 645 context_(NULL), |
| 614 gl_(NULL), | 646 gl_(NULL), |
| 615 context_lost_callback_(NULL), | 647 context_lost_callback_(NULL), |
| 616 context_lost_reason_(GL_NO_ERROR), | 648 context_lost_reason_(GL_NO_ERROR), |
| 617 attributes_(attributes), | 649 attributes_(attributes), |
| 618 cached_width_(0), | 650 cached_width_(0), |
| 619 cached_height_(0), | 651 cached_height_(0), |
| 620 bound_fbo_(0) { | 652 bound_fbo_(0) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 // discrete GPU is created, or the last one is destroyed. | 688 // discrete GPU is created, or the last one is destroyed. |
| 657 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 689 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 658 | 690 |
| 659 context_ = GLInProcessContext::CreateContext( | 691 context_ = GLInProcessContext::CreateContext( |
| 660 is_offscreen_, | 692 is_offscreen_, |
| 661 window_, | 693 window_, |
| 662 gfx::Size(1, 1), | 694 gfx::Size(1, 1), |
| 663 attributes_.shareResources, | 695 attributes_.shareResources, |
| 664 preferred_extensions, | 696 preferred_extensions, |
| 665 attribs, | 697 attribs, |
| 666 gpu_preference); | 698 gpu_preference, |
| 699 use_virtualized_gl_context_if_possible_); | |
| 667 | 700 |
| 668 if (!context_) { | 701 if (!context_) { |
| 669 initialize_failed_ = true; | 702 initialize_failed_ = true; |
| 670 return false; | 703 return false; |
| 671 } | 704 } |
| 672 | 705 |
| 673 gl_ = context_->GetImplementation(); | 706 gl_ = context_->GetImplementation(); |
| 674 | 707 |
| 675 if (gl_ && attributes_.noExtensions) | 708 if (gl_ && attributes_.noExtensions) |
| 676 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 709 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1762 | 1795 |
| 1763 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1796 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1764 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1797 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1765 WGC3Denum, WGC3Denum, const void*) | 1798 WGC3Denum, WGC3Denum, const void*) |
| 1766 | 1799 |
| 1767 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1800 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1768 WGC3Denum) | 1801 WGC3Denum) |
| 1769 | 1802 |
| 1770 } // namespace gpu | 1803 } // namespace gpu |
| 1771 } // namespace webkit | 1804 } // namespace webkit |
| OLD | NEW |