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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 struct CONTENT_EXPORT SharedMemoryLimits { | 67 struct CONTENT_EXPORT SharedMemoryLimits { |
67 SharedMemoryLimits(); | 68 SharedMemoryLimits(); |
68 | 69 |
69 size_t command_buffer_size; | 70 size_t command_buffer_size; |
70 size_t start_transfer_buffer_size; | 71 size_t start_transfer_buffer_size; |
71 size_t min_transfer_buffer_size; | 72 size_t min_transfer_buffer_size; |
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 |
| 77 class ShareGroup : public base::RefCountedThreadSafe<ShareGroup> { |
| 78 public: |
| 79 ShareGroup(); |
| 80 |
| 81 WebGraphicsContext3DCommandBufferImpl* GetAnyContextLocked() { |
| 82 // In order to ensure that the context returned is not removed while |
| 83 // in use the share group's lock should be aquired before calling this |
| 84 // function. |
| 85 lock_.AssertAcquired(); |
| 86 if (contexts_.empty()) |
| 87 return NULL; |
| 88 return contexts_.front(); |
| 89 } |
| 90 |
| 91 void AddContextLocked(WebGraphicsContext3DCommandBufferImpl* context) { |
| 92 lock_.AssertAcquired(); |
| 93 contexts_.push_back(context); |
| 94 } |
| 95 |
| 96 void RemoveContext(WebGraphicsContext3DCommandBufferImpl* context) { |
| 97 base::AutoLock auto_lock(lock_); |
| 98 contexts_.erase(std::remove(contexts_.begin(), contexts_.end(), context), |
| 99 contexts_.end()); |
| 100 } |
| 101 |
| 102 void RemoveAllContexts() { |
| 103 base::AutoLock auto_lock(lock_); |
| 104 contexts_.clear(); |
| 105 } |
| 106 |
| 107 base::Lock& lock() { |
| 108 return lock_; |
| 109 } |
| 110 |
| 111 private: |
| 112 friend class base::RefCountedThreadSafe<ShareGroup>; |
| 113 ~ShareGroup(); |
| 114 |
| 115 std::vector<WebGraphicsContext3DCommandBufferImpl*> contexts_; |
| 116 base::Lock lock_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(ShareGroup); |
| 119 }; |
| 120 |
76 WebGraphicsContext3DCommandBufferImpl( | 121 WebGraphicsContext3DCommandBufferImpl( |
77 int surface_id, | 122 int surface_id, |
78 const GURL& active_url, | 123 const GURL& active_url, |
79 GpuChannelHost* host, | 124 GpuChannelHost* host, |
80 const Attributes& attributes, | 125 const Attributes& attributes, |
81 bool bind_generates_resources, | 126 bool bind_generates_resources, |
82 const SharedMemoryLimits& limits); | 127 const SharedMemoryLimits& limits, |
| 128 WebGraphicsContext3DCommandBufferImpl* share_context); |
83 | 129 |
84 virtual ~WebGraphicsContext3DCommandBufferImpl(); | 130 virtual ~WebGraphicsContext3DCommandBufferImpl(); |
85 | 131 |
86 // The following 3 IDs let one uniquely identify this context. | 132 // The following 3 IDs let one uniquely identify this context. |
87 // Gets the GPU process ID for this context. | 133 // Gets the GPU process ID for this context. |
88 int GetGPUProcessID(); | 134 int GetGPUProcessID(); |
89 | 135 |
90 CommandBufferProxyImpl* GetCommandBufferProxy() { | 136 CommandBufferProxyImpl* GetCommandBufferProxy() { |
91 return command_buffer_.get(); | 137 return command_buffer_.get(); |
92 } | 138 } |
93 | 139 |
94 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); | 140 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); |
95 | 141 |
96 gpu::gles2::GLES2Implementation* GetImplementation() { | 142 gpu::gles2::GLES2Implementation* GetImplementation() { |
97 return real_gl_.get(); | 143 return real_gl_.get(); |
98 } | 144 } |
99 | 145 |
100 // Return true if GPU process reported context lost or there was a | 146 // Return true if GPU process reported context lost or there was a |
101 // problem communicating with the GPU process. | 147 // problem communicating with the GPU process. |
102 bool IsCommandBufferContextLost(); | 148 bool IsCommandBufferContextLost(); |
103 | 149 |
104 // Create & initialize a WebGraphicsContext3DCommandBufferImpl. Return NULL | 150 // Create & initialize a WebGraphicsContext3DCommandBufferImpl. Return NULL |
105 // on any failure. | 151 // on any failure. |
106 static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl* | 152 static CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl* |
107 CreateOffscreenContext( | 153 CreateOffscreenContext( |
108 GpuChannelHost* host, | 154 GpuChannelHost* host, |
109 const WebGraphicsContext3D::Attributes& attributes, | 155 const WebGraphicsContext3D::Attributes& attributes, |
110 const GURL& active_url, | 156 const GURL& active_url, |
111 const SharedMemoryLimits& limits); | 157 const SharedMemoryLimits& limits, |
| 158 WebGraphicsContext3DCommandBufferImpl* share_context); |
112 | 159 |
113 size_t GetMappedMemoryLimit() { | 160 size_t GetMappedMemoryLimit() { |
114 return mem_limits_.mapped_memory_reclaim_limit; | 161 return mem_limits_.mapped_memory_reclaim_limit; |
115 } | 162 } |
116 | 163 |
117 //---------------------------------------------------------------------- | 164 //---------------------------------------------------------------------- |
118 // WebGraphicsContext3D methods | 165 // WebGraphicsContext3D methods |
119 | 166 |
120 // Must be called after initialize() and before any of the following methods. | 167 // Must be called after initialize() and before any of the following methods. |
121 // Permanently binds to the first calling thread. Returns false if the | 168 // Permanently binds to the first calling thread. Returns false if the |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002 | 712 FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002 |
666 }; | 713 }; |
667 friend class WebGraphicsContext3DErrorMessageCallback; | 714 friend class WebGraphicsContext3DErrorMessageCallback; |
668 | 715 |
669 // Initialize the underlying GL context. May be called multiple times; second | 716 // Initialize the underlying GL context. May be called multiple times; second |
670 // and subsequent calls are ignored. Must be called from the thread that is | 717 // and subsequent calls are ignored. Must be called from the thread that is |
671 // going to use this object to issue GL commands (which might not be the main | 718 // going to use this object to issue GL commands (which might not be the main |
672 // thread). | 719 // thread). |
673 bool MaybeInitializeGL(); | 720 bool MaybeInitializeGL(); |
674 | 721 |
675 bool InitializeCommandBuffer(bool onscreen); | 722 bool InitializeCommandBuffer(bool onscreen, |
| 723 WebGraphicsContext3DCommandBufferImpl* share_context); |
676 | 724 |
677 void Destroy(); | 725 void Destroy(); |
678 | 726 |
679 // Create a CommandBufferProxy that renders directly to a view. The view and | 727 // Create a CommandBufferProxy that renders directly to a view. The view and |
680 // the associated window must not be destroyed until the returned | 728 // the associated window must not be destroyed until the returned |
681 // CommandBufferProxy has been destroyed, otherwise the GPU process might | 729 // CommandBufferProxy has been destroyed, otherwise the GPU process might |
682 // attempt to render to an invalid window handle. | 730 // attempt to render to an invalid window handle. |
683 // | 731 // |
684 // NOTE: on Mac OS X, this entry point is only used to set up the | 732 // NOTE: on Mac OS X, this entry point is only used to set up the |
685 // accelerated compositor's output. On this platform, we actually pass | 733 // accelerated compositor's output. On this platform, we actually pass |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; | 772 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
725 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; | 773 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; |
726 gpu::gles2::GLES2Interface* gl_; | 774 gpu::gles2::GLES2Interface* gl_; |
727 scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_; | 775 scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_; |
728 scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_; | 776 scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_; |
729 Error last_error_; | 777 Error last_error_; |
730 bool bind_generates_resources_; | 778 bool bind_generates_resources_; |
731 SharedMemoryLimits mem_limits_; | 779 SharedMemoryLimits mem_limits_; |
732 | 780 |
733 uint32_t flush_id_; | 781 uint32_t flush_id_; |
| 782 scoped_refptr<ShareGroup> share_group_; |
734 }; | 783 }; |
735 | 784 |
736 } // namespace content | 785 } // namespace content |
737 | 786 |
738 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 787 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
OLD | NEW |