| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/common/gpu/client/command_buffer_metrics.h" | 20 #include "content/common/gpu/client/command_buffer_metrics.h" |
| 21 #include "gpu/blink/webgraphicscontext3d_impl.h" | |
| 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 23 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 22 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 24 #include "gpu/ipc/common/surface_handle.h" | 23 #include "gpu/ipc/common/surface_handle.h" |
| 25 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 24 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 26 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 27 #include "ui/gl/gpu_preference.h" | 26 #include "ui/gl/gpu_preference.h" |
| 28 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 29 | 28 |
| 30 namespace gpu { | 29 namespace gpu { |
| 31 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 } | 41 } |
| 43 | 42 |
| 44 namespace content { | 43 namespace content { |
| 45 | 44 |
| 46 const size_t kDefaultCommandBufferSize = 1024 * 1024; | 45 const size_t kDefaultCommandBufferSize = 1024 * 1024; |
| 47 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024; | 46 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024; |
| 48 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024; | 47 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024; |
| 49 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; | 48 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; |
| 50 | 49 |
| 51 class WebGraphicsContext3DCommandBufferImpl | 50 class WebGraphicsContext3DCommandBufferImpl |
| 52 : public gpu_blink::WebGraphicsContext3DImpl { | 51 : public NON_EXPORTED_BASE(blink::WebGraphicsContext3D) { |
| 53 public: | 52 public: |
| 54 enum MappedMemoryReclaimLimit { | 53 enum MappedMemoryReclaimLimit { |
| 55 kNoLimit = 0, | 54 kNoLimit = 0, |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 class ShareGroup : public base::RefCountedThreadSafe<ShareGroup> { | 57 class ShareGroup : public base::RefCountedThreadSafe<ShareGroup> { |
| 59 public: | 58 public: |
| 60 ShareGroup(); | 59 ShareGroup(); |
| 61 | 60 |
| 62 WebGraphicsContext3DCommandBufferImpl* GetAnyContextLocked() { | 61 WebGraphicsContext3DCommandBufferImpl* GetAnyContextLocked() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 private: | 91 private: |
| 93 friend class base::RefCountedThreadSafe<ShareGroup>; | 92 friend class base::RefCountedThreadSafe<ShareGroup>; |
| 94 virtual ~ShareGroup(); | 93 virtual ~ShareGroup(); |
| 95 | 94 |
| 96 std::vector<WebGraphicsContext3DCommandBufferImpl*> contexts_; | 95 std::vector<WebGraphicsContext3DCommandBufferImpl*> contexts_; |
| 97 base::Lock lock_; | 96 base::Lock lock_; |
| 98 | 97 |
| 99 DISALLOW_COPY_AND_ASSIGN(ShareGroup); | 98 DISALLOW_COPY_AND_ASSIGN(ShareGroup); |
| 100 }; | 99 }; |
| 101 | 100 |
| 101 class WebGraphicsContextLostCallback { |
| 102 public: |
| 103 virtual void onContextLost() = 0; |
| 104 |
| 105 protected: |
| 106 virtual ~WebGraphicsContextLostCallback() {} |
| 107 }; |
| 108 |
| 102 CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl( | 109 CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl( |
| 103 gpu::SurfaceHandle surface_handle, | 110 gpu::SurfaceHandle surface_handle, |
| 104 const GURL& active_url, | 111 const GURL& active_url, |
| 105 gpu::GpuChannelHost* host, | 112 gpu::GpuChannelHost* host, |
| 106 const gpu::gles2::ContextCreationAttribHelper& attributes, | 113 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 107 gfx::GpuPreference gpu_preference, | 114 gfx::GpuPreference gpu_preference, |
| 108 bool share_resources, | 115 bool share_resources, |
| 109 bool automatic_flushes, | 116 bool automatic_flushes, |
| 110 WebGraphicsContext3DCommandBufferImpl* share_context); | 117 WebGraphicsContext3DCommandBufferImpl* share_context); |
| 111 | 118 |
| 112 ~WebGraphicsContext3DCommandBufferImpl() override; | 119 ~WebGraphicsContext3DCommandBufferImpl() override; |
| 113 | 120 |
| 114 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { | 121 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { |
| 115 return command_buffer_.get(); | 122 return command_buffer_.get(); |
| 116 } | 123 } |
| 117 | 124 |
| 118 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); | 125 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); |
| 119 | 126 |
| 120 gpu::gles2::GLES2Implementation* GetImplementation() { | 127 gpu::gles2::GLES2Implementation* GetImplementation() { |
| 121 return real_gl_.get(); | 128 return real_gl_.get(); |
| 122 } | 129 } |
| 123 | 130 |
| 131 void SetContextLostCallback(WebGraphicsContextLostCallback* callback) { |
| 132 context_lost_callback_ = callback; |
| 133 } |
| 134 |
| 124 CONTENT_EXPORT bool InitializeOnCurrentThread( | 135 CONTENT_EXPORT bool InitializeOnCurrentThread( |
| 125 const gpu::SharedMemoryLimits& memory_limits); | 136 const gpu::SharedMemoryLimits& memory_limits); |
| 126 | 137 |
| 127 void SetContextType(CommandBufferContextType type) { | 138 void SetContextType(CommandBufferContextType type) { |
| 128 context_type_ = type; | 139 context_type_ = type; |
| 129 } | 140 } |
| 130 private: | 141 private: |
| 131 // These are the same error codes as used by EGL. | 142 // These are the same error codes as used by EGL. |
| 132 enum Error { | 143 enum Error { |
| 133 SUCCESS = 0x3000, | 144 SUCCESS = 0x3000, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 156 // a gpu::SurfaceHandle in place of the gfx::NativeViewId, | 167 // a gpu::SurfaceHandle in place of the gfx::NativeViewId, |
| 157 // because the facility to allocate a fake PluginWindowHandle is | 168 // because the facility to allocate a fake PluginWindowHandle is |
| 158 // already in place. We could add more entry points and messages to | 169 // already in place. We could add more entry points and messages to |
| 159 // allocate both fake PluginWindowHandles and NativeViewIds and map | 170 // allocate both fake PluginWindowHandles and NativeViewIds and map |
| 160 // from fake NativeViewIds to PluginWindowHandles, but this seems like | 171 // from fake NativeViewIds to PluginWindowHandles, but this seems like |
| 161 // unnecessary complexity at the moment. | 172 // unnecessary complexity at the moment. |
| 162 bool CreateContext(const gpu::SharedMemoryLimits& memory_limits); | 173 bool CreateContext(const gpu::SharedMemoryLimits& memory_limits); |
| 163 | 174 |
| 164 void OnContextLost(); | 175 void OnContextLost(); |
| 165 | 176 |
| 177 bool initialized_ = false; |
| 178 bool initialize_failed_ = false; |
| 179 WebGraphicsContextLostCallback* context_lost_callback_ = nullptr; |
| 180 |
| 166 bool automatic_flushes_; | 181 bool automatic_flushes_; |
| 167 gpu::gles2::ContextCreationAttribHelper attributes_; | 182 gpu::gles2::ContextCreationAttribHelper attributes_; |
| 168 | 183 |
| 169 // State needed by MaybeInitializeGL. | 184 // State needed by MaybeInitializeGL. |
| 170 scoped_refptr<gpu::GpuChannelHost> host_; | 185 scoped_refptr<gpu::GpuChannelHost> host_; |
| 171 gpu::SurfaceHandle surface_handle_; | 186 gpu::SurfaceHandle surface_handle_; |
| 172 GURL active_url_; | 187 GURL active_url_; |
| 173 CommandBufferContextType context_type_; | 188 CommandBufferContextType context_type_; |
| 174 | 189 |
| 175 gfx::GpuPreference gpu_preference_; | 190 gfx::GpuPreference gpu_preference_; |
| 176 | 191 |
| 177 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_; | 192 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_; |
| 178 std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; | 193 std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
| 179 std::unique_ptr<gpu::TransferBuffer> transfer_buffer_; | 194 std::unique_ptr<gpu::TransferBuffer> transfer_buffer_; |
| 180 std::unique_ptr<gpu::gles2::GLES2Implementation> real_gl_; | 195 std::unique_ptr<gpu::gles2::GLES2Implementation> real_gl_; |
| 181 std::unique_ptr<gpu::gles2::GLES2Interface> trace_gl_; | 196 std::unique_ptr<gpu::gles2::GLES2Interface> trace_gl_; |
| 182 scoped_refptr<ShareGroup> share_group_; | 197 scoped_refptr<ShareGroup> share_group_; |
| 183 | 198 |
| 184 // Member variables should appear before the WeakPtrFactory, to ensure | 199 // Member variables should appear before the WeakPtrFactory, to ensure |
| 185 // that any WeakPtrs to Controller are invalidated before its members | 200 // that any WeakPtrs to Controller are invalidated before its members |
| 186 // variable's destructors are executed, rendering them invalid. | 201 // variable's destructors are executed, rendering them invalid. |
| 187 base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_; | 202 base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_; |
| 188 }; | 203 }; |
| 189 | 204 |
| 190 } // namespace content | 205 } // namespace content |
| 191 | 206 |
| 192 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 207 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
| OLD | NEW |