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 #ifndef CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| 6 #define CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/synchronization/lock.h" | |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 16 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 17 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 19 #include "ui/gl/gpu_preference.h" | 20 #include "ui/gl/gpu_preference.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace gpu { | 23 namespace gpu { |
| 23 | 24 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 size_t max_transfer_buffer_size; | 73 size_t max_transfer_buffer_size; |
| 73 size_t mapped_memory_reclaim_limit; | 74 size_t mapped_memory_reclaim_limit; |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 WebGraphicsContext3DCommandBufferImpl( | 77 WebGraphicsContext3DCommandBufferImpl( |
| 77 int surface_id, | 78 int surface_id, |
| 78 const GURL& active_url, | 79 const GURL& active_url, |
| 79 GpuChannelHost* host, | 80 GpuChannelHost* host, |
| 80 const Attributes& attributes, | 81 const Attributes& attributes, |
| 81 bool bind_generates_resources, | 82 bool bind_generates_resources, |
| 82 const SharedMemoryLimits& limits); | 83 const SharedMemoryLimits& limits, |
| 84 WebGraphicsContext3DCommandBufferImpl* share_context); | |
| 83 | 85 |
| 84 virtual ~WebGraphicsContext3DCommandBufferImpl(); | 86 virtual ~WebGraphicsContext3DCommandBufferImpl(); |
| 85 | 87 |
| 86 // The following 3 IDs let one uniquely identify this context. | 88 // The following 3 IDs let one uniquely identify this context. |
| 87 // Gets the GPU process ID for this context. | 89 // Gets the GPU process ID for this context. |
| 88 int GetGPUProcessID(); | 90 int GetGPUProcessID(); |
| 89 | 91 |
| 90 CommandBufferProxyImpl* GetCommandBufferProxy() { | 92 CommandBufferProxyImpl* GetCommandBufferProxy() { |
| 91 return command_buffer_.get(); | 93 return command_buffer_.get(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); | 96 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); |
| 95 | 97 |
| 96 gpu::gles2::GLES2Implementation* GetImplementation() { | 98 gpu::gles2::GLES2Implementation* GetImplementation() { |
| 97 return real_gl_.get(); | 99 return real_gl_.get(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 // Return true if GPU process reported context lost or there was a | 102 // Return true if GPU process reported context lost or there was a |
| 101 // problem communicating with the GPU process. | 103 // problem communicating with the GPU process. |
| 102 bool IsCommandBufferContextLost(); | 104 bool IsCommandBufferContextLost(); |
| 103 | 105 |
| 104 // Create & initialize a WebGraphicsContext3DCommandBufferImpl. Return NULL | 106 // Create & initialize a WebGraphicsContext3DCommandBufferImpl. Return NULL |
| 105 // on any failure. | 107 // on any failure. |
| 106 static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl* | 108 static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl* |
| 107 CreateOffscreenContext( | 109 CreateOffscreenContext( |
| 108 GpuChannelHost* host, | 110 GpuChannelHost* host, |
| 109 const WebGraphicsContext3D::Attributes& attributes, | 111 const WebGraphicsContext3D::Attributes& attributes, |
| 110 const GURL& active_url, | 112 const GURL& active_url, |
| 111 const SharedMemoryLimits& limits); | 113 const SharedMemoryLimits& limits, |
| 114 WebGraphicsContext3D* share_context); | |
| 112 | 115 |
| 113 size_t GetMappedMemoryLimit() { | 116 size_t GetMappedMemoryLimit() { |
| 114 return mem_limits_.mapped_memory_reclaim_limit; | 117 return mem_limits_.mapped_memory_reclaim_limit; |
| 115 } | 118 } |
| 116 | 119 |
| 117 //---------------------------------------------------------------------- | 120 //---------------------------------------------------------------------- |
| 118 // WebGraphicsContext3D methods | 121 // WebGraphicsContext3D methods |
| 119 | 122 |
| 120 // Must be called after initialize() and before any of the following methods. | 123 // Must be called after initialize() and before any of the following methods. |
| 121 // Permanently binds to the first calling thread. Returns false if the | 124 // Permanently binds to the first calling thread. Returns false if the |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 SAMPLE_BUFFERS = 0x3032, | 654 SAMPLE_BUFFERS = 0x3032, |
| 652 HEIGHT = 0x3056, | 655 HEIGHT = 0x3056, |
| 653 WIDTH = 0x3057, | 656 WIDTH = 0x3057, |
| 654 NONE = 0x3038, // Attrib list = terminator | 657 NONE = 0x3038, // Attrib list = terminator |
| 655 SHARE_RESOURCES = 0x10000, | 658 SHARE_RESOURCES = 0x10000, |
| 656 BIND_GENERATES_RESOURCES = 0x10001, | 659 BIND_GENERATES_RESOURCES = 0x10001, |
| 657 FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002 | 660 FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002 |
| 658 }; | 661 }; |
| 659 friend class WebGraphicsContext3DErrorMessageCallback; | 662 friend class WebGraphicsContext3DErrorMessageCallback; |
| 660 | 663 |
| 664 class ShareGroup : public base::RefCountedThreadSafe<ShareGroup> { | |
| 665 public: | |
| 666 ShareGroup(); | |
| 667 | |
| 668 WebGraphicsContext3DCommandBufferImpl* GetAnyContext() { | |
|
piman
2013/12/12 23:56:39
nit: maybe append "Locked" to these functions to m
| |
| 669 // In order to ensure that the context returned is not removed while | |
| 670 // in use the share group's lock should be aquired before calling this | |
| 671 // function. | |
| 672 lock_.AssertAcquired(); | |
| 673 if (contexts_.empty()) | |
| 674 return NULL; | |
| 675 return contexts_.front(); | |
| 676 } | |
| 677 | |
| 678 void AddContext(WebGraphicsContext3DCommandBufferImpl* context) { | |
| 679 lock_.AssertAcquired(); | |
| 680 contexts_.push_back(context); | |
| 681 } | |
| 682 | |
| 683 void RemoveContext(WebGraphicsContext3DCommandBufferImpl* context) { | |
| 684 base::AutoLock auto_lock(lock_); | |
| 685 contexts_.erase(std::remove(contexts_.begin(), contexts_.end(), context), | |
| 686 contexts_.end()); | |
| 687 } | |
| 688 | |
| 689 void RemoveAllContexts() { | |
| 690 base::AutoLock auto_lock(lock_); | |
| 691 contexts_.clear(); | |
| 692 } | |
| 693 | |
| 694 base::Lock& lock() { | |
| 695 return lock_; | |
| 696 } | |
| 697 | |
| 698 private: | |
| 699 friend class base::RefCountedThreadSafe<ShareGroup>; | |
| 700 ~ShareGroup(); | |
| 701 | |
| 702 std::vector<WebGraphicsContext3DCommandBufferImpl*> contexts_; | |
| 703 base::Lock lock_; | |
| 704 | |
| 705 DISALLOW_COPY_AND_ASSIGN(ShareGroup); | |
| 706 }; | |
| 707 | |
| 661 // Initialize the underlying GL context. May be called multiple times; second | 708 // Initialize the underlying GL context. May be called multiple times; second |
| 662 // and subsequent calls are ignored. Must be called from the thread that is | 709 // and subsequent calls are ignored. Must be called from the thread that is |
| 663 // going to use this object to issue GL commands (which might not be the main | 710 // going to use this object to issue GL commands (which might not be the main |
| 664 // thread). | 711 // thread). |
| 665 bool MaybeInitializeGL(); | 712 bool MaybeInitializeGL(); |
| 666 | 713 |
| 667 bool InitializeCommandBuffer(bool onscreen); | 714 bool InitializeCommandBuffer(bool onscreen, |
| 715 WebGraphicsContext3DCommandBufferImpl* share_context); | |
| 668 | 716 |
| 669 void Destroy(); | 717 void Destroy(); |
| 670 | 718 |
| 671 // Create a CommandBufferProxy that renders directly to a view. The view and | 719 // Create a CommandBufferProxy that renders directly to a view. The view and |
| 672 // the associated window must not be destroyed until the returned | 720 // the associated window must not be destroyed until the returned |
| 673 // CommandBufferProxy has been destroyed, otherwise the GPU process might | 721 // CommandBufferProxy has been destroyed, otherwise the GPU process might |
| 674 // attempt to render to an invalid window handle. | 722 // attempt to render to an invalid window handle. |
| 675 // | 723 // |
| 676 // NOTE: on Mac OS X, this entry point is only used to set up the | 724 // NOTE: on Mac OS X, this entry point is only used to set up the |
| 677 // accelerated compositor's output. On this platform, we actually pass | 725 // accelerated compositor's output. On this platform, we actually pass |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; | 764 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
| 717 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; | 765 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; |
| 718 gpu::gles2::GLES2Interface* gl_; | 766 gpu::gles2::GLES2Interface* gl_; |
| 719 scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_; | 767 scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_; |
| 720 scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_; | 768 scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_; |
| 721 Error last_error_; | 769 Error last_error_; |
| 722 bool bind_generates_resources_; | 770 bool bind_generates_resources_; |
| 723 SharedMemoryLimits mem_limits_; | 771 SharedMemoryLimits mem_limits_; |
| 724 | 772 |
| 725 uint32_t flush_id_; | 773 uint32_t flush_id_; |
| 774 scoped_refptr<ShareGroup> share_group_; | |
| 726 }; | 775 }; |
| 727 | 776 |
| 728 } // namespace content | 777 } // namespace content |
| 729 | 778 |
| 730 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 779 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| OLD | NEW |