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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 // If surface_handle is not kNullSurfaceHandle, this creates a | 60 // If surface_handle is not kNullSurfaceHandle, this creates a |
61 // CommandBufferProxy that renders directly to a view. The view and | 61 // CommandBufferProxy that renders directly to a view. The view and |
62 // the associated window must not be destroyed until the returned | 62 // the associated window must not be destroyed until the returned |
63 // CommandBufferProxy has been destroyed, otherwise the GPU process might | 63 // CommandBufferProxy has been destroyed, otherwise the GPU process might |
64 // attempt to render to an invalid window handle. | 64 // attempt to render to an invalid window handle. |
65 CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl( | 65 CONTENT_EXPORT WebGraphicsContext3DCommandBufferImpl( |
66 gpu::SurfaceHandle surface_handle, | 66 gpu::SurfaceHandle surface_handle, |
67 const GURL& active_url, | 67 const GURL& active_url, |
68 scoped_refptr<gpu::GpuChannelHost> host, | 68 scoped_refptr<gpu::GpuChannelHost> host, |
69 const gpu::gles2::ContextCreationAttribHelper& attributes, | |
70 gfx::GpuPreference gpu_preference, | 69 gfx::GpuPreference gpu_preference, |
71 bool automatic_flushes); | 70 bool automatic_flushes); |
72 | 71 |
73 CONTENT_EXPORT ~WebGraphicsContext3DCommandBufferImpl(); | 72 CONTENT_EXPORT ~WebGraphicsContext3DCommandBufferImpl(); |
74 | 73 |
75 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { | 74 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { |
76 return command_buffer_.get(); | 75 return command_buffer_.get(); |
77 } | 76 } |
78 | 77 |
79 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); | 78 CONTENT_EXPORT gpu::ContextSupport* GetContextSupport(); |
80 | 79 |
81 gpu::gles2::GLES2Implementation* GetImplementation() { | 80 gpu::gles2::GLES2Implementation* GetImplementation() { |
82 return real_gl_.get(); | 81 return real_gl_.get(); |
83 } | 82 } |
84 | 83 |
85 void SetContextLostCallback(WebGraphicsContextLostCallback* callback) { | 84 void SetContextLostCallback(WebGraphicsContextLostCallback* callback) { |
86 context_lost_callback_ = callback; | 85 context_lost_callback_ = callback; |
87 } | 86 } |
88 | 87 |
89 CONTENT_EXPORT bool InitializeOnCurrentThread( | 88 CONTENT_EXPORT bool InitializeOnCurrentThread( |
90 const gpu::SharedMemoryLimits& memory_limits, | 89 const gpu::SharedMemoryLimits& memory_limits, |
91 gpu::CommandBufferProxyImpl* shared_command_buffer, | 90 gpu::CommandBufferProxyImpl* shared_command_buffer, |
92 scoped_refptr<gpu::gles2::ShareGroup> share_group); | 91 scoped_refptr<gpu::gles2::ShareGroup> share_group, |
| 92 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 93 command_buffer_metrics::ContextType context_type); |
93 | 94 |
94 void SetContextType(CommandBufferContextType type) { | |
95 context_type_ = type; | |
96 } | |
97 private: | 95 private: |
98 // These are the same error codes as used by EGL. | |
99 enum Error { | |
100 SUCCESS = 0x3000, | |
101 BAD_ATTRIBUTE = 0x3004, | |
102 CONTEXT_LOST = 0x300E | |
103 }; | |
104 | |
105 // Initialize the underlying GL context. May be called multiple times; second | 96 // Initialize the underlying GL context. May be called multiple times; second |
106 // and subsequent calls are ignored. Must be called from the thread that is | 97 // and subsequent calls are ignored. Must be called from the thread that is |
107 // going to use this object to issue GL commands (which might not be the main | 98 // going to use this object to issue GL commands (which might not be the main |
108 // thread). | 99 // thread). |
109 bool MaybeInitializeGL(const gpu::SharedMemoryLimits& memory_limits, | 100 bool MaybeInitializeGL( |
110 gpu::CommandBufferProxyImpl* shared_command_buffer, | 101 const gpu::SharedMemoryLimits& memory_limits, |
111 scoped_refptr<gpu::gles2::ShareGroup> share_group); | 102 gpu::CommandBufferProxyImpl* shared_command_buffer, |
| 103 scoped_refptr<gpu::gles2::ShareGroup> share_group, |
| 104 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 105 command_buffer_metrics::ContextType context_type); |
112 | 106 |
113 bool InitializeCommandBuffer( | 107 bool InitializeCommandBuffer( |
114 gpu::CommandBufferProxyImpl* shared_command_buffer); | 108 gpu::CommandBufferProxyImpl* shared_command_buffer, |
| 109 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 110 command_buffer_metrics::ContextType context_type); |
115 | 111 |
116 void Destroy(); | 112 void Destroy(); |
117 | 113 |
118 bool CreateContext(const gpu::SharedMemoryLimits& memory_limits, | 114 bool CreateContext(const gpu::SharedMemoryLimits& memory_limits, |
119 gpu::CommandBufferProxyImpl* shared_command_buffer, | 115 gpu::CommandBufferProxyImpl* shared_command_buffer, |
120 scoped_refptr<gpu::gles2::ShareGroup> share_group); | 116 scoped_refptr<gpu::gles2::ShareGroup> share_group, |
| 117 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 118 command_buffer_metrics::ContextType context_type); |
121 | 119 |
122 void OnContextLost(); | 120 void OnContextLost(); |
123 | 121 |
124 bool initialized_ = false; | 122 bool initialized_ = false; |
125 bool initialize_failed_ = false; | 123 bool initialize_failed_ = false; |
126 WebGraphicsContextLostCallback* context_lost_callback_ = nullptr; | 124 WebGraphicsContextLostCallback* context_lost_callback_ = nullptr; |
127 | 125 |
128 bool automatic_flushes_; | 126 bool automatic_flushes_; |
129 gpu::gles2::ContextCreationAttribHelper attributes_; | |
130 | 127 |
131 // State needed by MaybeInitializeGL. | 128 // State needed by MaybeInitializeGL. |
132 scoped_refptr<gpu::GpuChannelHost> host_; | 129 scoped_refptr<gpu::GpuChannelHost> host_; |
133 gpu::SurfaceHandle surface_handle_; | 130 gpu::SurfaceHandle surface_handle_; |
134 GURL active_url_; | 131 GURL active_url_; |
135 CommandBufferContextType context_type_; | |
136 | 132 |
137 gfx::GpuPreference gpu_preference_; | 133 gfx::GpuPreference gpu_preference_; |
138 | 134 |
139 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_; | 135 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_; |
140 std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; | 136 std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
141 std::unique_ptr<gpu::TransferBuffer> transfer_buffer_; | 137 std::unique_ptr<gpu::TransferBuffer> transfer_buffer_; |
142 std::unique_ptr<gpu::gles2::GLES2Implementation> real_gl_; | 138 std::unique_ptr<gpu::gles2::GLES2Implementation> real_gl_; |
143 std::unique_ptr<gpu::gles2::GLES2Interface> trace_gl_; | 139 std::unique_ptr<gpu::gles2::GLES2Interface> trace_gl_; |
144 | 140 |
145 // Member variables should appear before the WeakPtrFactory, to ensure | 141 // Member variables should appear before the WeakPtrFactory, to ensure |
146 // that any WeakPtrs to Controller are invalidated before its members | 142 // that any WeakPtrs to Controller are invalidated before its members |
147 // variable's destructors are executed, rendering them invalid. | 143 // variable's destructors are executed, rendering them invalid. |
148 base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_; | 144 base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_; |
149 }; | 145 }; |
150 | 146 |
151 } // namespace content | 147 } // namespace content |
152 | 148 |
153 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 149 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ |
OLD | NEW |