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_COMMAND_BUFFER_PROXY_IMPL_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ |
6 #define CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <queue> | 12 #include <queue> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
18 #include "base/containers/scoped_ptr_hash_map.h" | 18 #include "base/containers/scoped_ptr_hash_map.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
| 23 #include "content/common/gpu/client/ipc/command_buffer_ipc_transport.h" |
23 #include "gpu/command_buffer/client/gpu_control.h" | 24 #include "gpu/command_buffer/client/gpu_control.h" |
24 #include "gpu/command_buffer/common/command_buffer.h" | 25 #include "gpu/command_buffer/common/command_buffer.h" |
25 #include "gpu/command_buffer/common/command_buffer_shared.h" | 26 #include "gpu/command_buffer/common/command_buffer_shared.h" |
26 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 27 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
27 #include "ipc/ipc_listener.h" | |
28 #include "ui/events/latency_info.h" | 28 #include "ui/events/latency_info.h" |
29 #include "ui/gfx/swap_result.h" | 29 #include "ui/gfx/swap_result.h" |
30 | 30 |
31 struct GPUCommandBufferConsoleMessage; | |
32 | |
33 namespace base { | 31 namespace base { |
34 class SharedMemory; | 32 class SharedMemory; |
35 } | 33 } |
36 | 34 |
37 namespace gpu { | 35 namespace gpu { |
38 struct Mailbox; | 36 struct Mailbox; |
39 struct SyncToken; | 37 struct SyncToken; |
40 } | 38 } |
41 | 39 |
42 namespace media { | 40 namespace media { |
43 class VideoDecodeAccelerator; | 41 class VideoDecodeAccelerator; |
44 class VideoEncodeAccelerator; | 42 class VideoEncodeAccelerator; |
45 } | 43 } |
46 | 44 |
47 namespace content { | 45 namespace content { |
| 46 |
48 class GpuChannelHost; | 47 class GpuChannelHost; |
| 48 struct CommandBufferConsoleMessage; |
49 | 49 |
50 // Client side proxy that forwards messages synchronously to a | 50 // Client side proxy that forwards messages synchronously to a |
51 // CommandBufferStub. | 51 // CommandBufferStub. |
52 class CommandBufferProxyImpl | 52 class CommandBufferProxyImpl |
53 : public gpu::CommandBuffer, | 53 : public gpu::CommandBuffer, |
54 public gpu::GpuControl, | 54 public gpu::GpuControl, |
55 public IPC::Listener, | 55 public CommandBufferIPCTransport::Client, |
56 public base::SupportsWeakPtr<CommandBufferProxyImpl> { | 56 public base::SupportsWeakPtr<CommandBufferProxyImpl> { |
57 public: | 57 public: |
58 class DeletionObserver { | 58 class DeletionObserver { |
59 public: | 59 public: |
60 // Called during the destruction of the CommandBufferProxyImpl. | 60 // Called during the destruction of the CommandBufferProxyImpl. |
61 virtual void OnWillDeleteImpl() = 0; | 61 virtual void OnWillDeleteImpl() = 0; |
62 | 62 |
63 protected: | 63 protected: |
64 virtual ~DeletionObserver() {} | 64 virtual ~DeletionObserver() {} |
65 }; | 65 }; |
66 | 66 |
67 typedef base::Callback<void( | 67 typedef base::Callback<void( |
68 const std::string& msg, int id)> GpuConsoleMessageCallback; | 68 const std::string& msg, int id)> GpuConsoleMessageCallback; |
69 | 69 |
70 CommandBufferProxyImpl(GpuChannelHost* channel, | 70 CommandBufferProxyImpl(GpuChannelHost* channel, |
71 int32_t route_id, | 71 scoped_ptr<CommandBufferIPCTransport> transport, |
72 int32_t stream_id); | 72 int32_t stream_id); |
73 ~CommandBufferProxyImpl() override; | 73 ~CommandBufferProxyImpl() override; |
74 | 74 |
| 75 // TODO(fsamuel): It's a little unfortunate that we have to expose this. Let's |
| 76 // see if there's a way to hide this. |
| 77 const CommandBufferIPCTransport* transport() const { |
| 78 return transport_.get(); |
| 79 } |
| 80 |
| 81 CommandBufferIPCTransport* transport() { return transport_.get(); } |
| 82 |
75 // Sends an IPC message to create a GpuVideoDecodeAccelerator. Creates and | 83 // Sends an IPC message to create a GpuVideoDecodeAccelerator. Creates and |
76 // returns it as an owned pointer to a media::VideoDecodeAccelerator. Returns | 84 // returns it as an owned pointer to a media::VideoDecodeAccelerator. Returns |
77 // NULL on failure to create the GpuVideoDecodeAcceleratorHost. | 85 // NULL on failure to create the GpuVideoDecodeAcceleratorHost. |
78 // Note that the GpuVideoDecodeAccelerator may still fail to be created in | 86 // Note that the GpuVideoDecodeAccelerator may still fail to be created in |
79 // the GPU process, even if this returns non-NULL. In this case the VDA client | 87 // the GPU process, even if this returns non-NULL. In this case the VDA client |
80 // is notified of an error later, after Initialize(). | 88 // is notified of an error later, after Initialize(). |
81 scoped_ptr<media::VideoDecodeAccelerator> CreateVideoDecoder(); | 89 scoped_ptr<media::VideoDecodeAccelerator> CreateVideoDecoder(); |
82 | 90 |
83 // Sends an IPC message to create a GpuVideoEncodeAccelerator. Creates and | 91 // Sends an IPC message to create a GpuVideoEncodeAccelerator. Creates and |
84 // returns it as an owned pointer to a media::VideoEncodeAccelerator. Returns | 92 // returns it as an owned pointer to a media::VideoEncodeAccelerator. Returns |
85 // NULL on failure to create the GpuVideoEncodeAcceleratorHost. | 93 // NULL on failure to create the GpuVideoEncodeAcceleratorHost. |
86 // Note that the GpuVideoEncodeAccelerator may still fail to be created in | 94 // Note that the GpuVideoEncodeAccelerator may still fail to be created in |
87 // the GPU process, even if this returns non-NULL. In this case the VEA client | 95 // the GPU process, even if this returns non-NULL. In this case the VEA client |
88 // is notified of an error later, after Initialize(); | 96 // is notified of an error later, after Initialize(); |
89 scoped_ptr<media::VideoEncodeAccelerator> CreateVideoEncoder(); | 97 scoped_ptr<media::VideoEncodeAccelerator> CreateVideoEncoder(); |
90 | 98 |
91 // IPC::Listener implementation: | |
92 bool OnMessageReceived(const IPC::Message& message) override; | |
93 void OnChannelError() override; | |
94 | |
95 // CommandBuffer implementation: | 99 // CommandBuffer implementation: |
96 bool Initialize() override; | 100 bool Initialize() override; |
97 State GetLastState() override; | 101 State GetLastState() override; |
98 int32_t GetLastToken() override; | 102 int32_t GetLastToken() override; |
99 void Flush(int32_t put_offset) override; | 103 void Flush(int32_t put_offset) override; |
100 void OrderingBarrier(int32_t put_offset) override; | 104 void OrderingBarrier(int32_t put_offset) override; |
101 void WaitForTokenInRange(int32_t start, int32_t end) override; | 105 void WaitForTokenInRange(int32_t start, int32_t end) override; |
102 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; | 106 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; |
103 void SetGetBuffer(int32_t shm_id) override; | 107 void SetGetBuffer(int32_t shm_id) override; |
104 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | 108 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 base::Callback<void(base::TimeTicks timebase, base::TimeDelta interval)>; | 157 base::Callback<void(base::TimeTicks timebase, base::TimeDelta interval)>; |
154 void SetUpdateVSyncParametersCallback( | 158 void SetUpdateVSyncParametersCallback( |
155 const UpdateVSyncParametersCallback& callback); | 159 const UpdateVSyncParametersCallback& callback); |
156 | 160 |
157 // TODO(apatrick): this is a temporary optimization while skia is calling | 161 // TODO(apatrick): this is a temporary optimization while skia is calling |
158 // ContentGLContext::MakeCurrent prior to every GL call. It saves returning 6 | 162 // ContentGLContext::MakeCurrent prior to every GL call. It saves returning 6 |
159 // ints redundantly when only the error is needed for the | 163 // ints redundantly when only the error is needed for the |
160 // CommandBufferProxyImpl implementation. | 164 // CommandBufferProxyImpl implementation. |
161 gpu::error::Error GetLastError() override; | 165 gpu::error::Error GetLastError() override; |
162 | 166 |
163 int32_t route_id() const { return route_id_; } | |
164 | |
165 int32_t stream_id() const { return stream_id_; } | 167 int32_t stream_id() const { return stream_id_; } |
166 | 168 |
167 GpuChannelHost* channel() const { return channel_; } | 169 GpuChannelHost* channel() const { return channel_; } |
168 | 170 |
169 base::SharedMemoryHandle GetSharedStateHandle() const { | 171 base::SharedMemoryHandle GetSharedStateHandle() const { |
170 return shared_state_shm_->handle(); | 172 return shared_state_shm_->handle(); |
171 } | 173 } |
172 uint32_t CreateStreamTexture(uint32_t texture_id); | 174 uint32_t CreateStreamTexture(uint32_t texture_id); |
173 | 175 |
174 private: | 176 private: |
175 typedef std::map<int32_t, scoped_refptr<gpu::Buffer>> TransferBufferMap; | 177 typedef std::map<int32_t, scoped_refptr<gpu::Buffer>> TransferBufferMap; |
176 typedef base::hash_map<uint32_t, base::Closure> SignalTaskMap; | 178 typedef base::hash_map<uint32_t, base::Closure> SignalTaskMap; |
177 | 179 |
178 void CheckLock() { | 180 void CheckLock() { |
179 if (lock_) | 181 if (lock_) |
180 lock_->AssertAcquired(); | 182 lock_->AssertAcquired(); |
181 } | 183 } |
182 | 184 |
183 // Send an IPC message over the GPU channel. This is private to fully | 185 // CommandBufferIPCTransport::Client implementation. |
184 // encapsulate the channel; all callers of this function must explicitly | 186 void OnChannelError() override; |
185 // verify that the context has not been lost. | 187 void OnConsoleMessage(const CommandBufferConsoleMessage& message) override; |
186 bool Send(IPC::Message* msg); | |
187 | |
188 // Message handlers: | |
189 void OnUpdateState(const gpu::CommandBuffer::State& state); | |
190 void OnDestroyed(gpu::error::ContextLostReason reason, | 188 void OnDestroyed(gpu::error::ContextLostReason reason, |
191 gpu::error::Error error); | 189 gpu::error::Error error) override; |
192 void OnConsoleMessage(const GPUCommandBufferConsoleMessage& message); | 190 void OnDidHandleMessage() override; |
193 void OnSignalAck(uint32_t id); | 191 void OnSignalAck(uint32_t id) override; |
194 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 192 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, |
195 gfx::SwapResult result); | 193 gfx::SwapResult result) override; |
| 194 void OnUpdateState(const gpu::CommandBuffer::State& state) override; |
196 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 195 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
197 base::TimeDelta interval); | 196 base::TimeDelta interval) override; |
| 197 void OnWillHandleMessage() override; |
198 | 198 |
199 // Try to read an updated copy of the state from shared memory. | 199 // Try to read an updated copy of the state from shared memory. |
200 void TryUpdateState(); | 200 void TryUpdateState(); |
201 | 201 |
202 // Updates the highest verified release fence sync. | 202 // Updates the highest verified release fence sync. |
203 void UpdateVerifiedReleases(uint32_t verified_flush); | 203 void UpdateVerifiedReleases(uint32_t verified_flush); |
204 | 204 |
205 // Loses the context after we received an invalid message from the GPU | 205 // Loses the context after we received an invalid message from the GPU |
206 // process. Will call the lost context callback reentrantly if any. | 206 // process. Will call the lost context callback reentrantly if any. |
207 void InvalidGpuMessage(); | 207 void InvalidGpuMessage(); |
(...skipping 14 matching lines...) Expand all Loading... |
222 | 222 |
223 // The last cached state received from the service. | 223 // The last cached state received from the service. |
224 State last_state_; | 224 State last_state_; |
225 | 225 |
226 // The shared memory area used to update state. | 226 // The shared memory area used to update state. |
227 scoped_ptr<base::SharedMemory> shared_state_shm_; | 227 scoped_ptr<base::SharedMemory> shared_state_shm_; |
228 | 228 |
229 // |*this| is owned by |*channel_| and so is always outlived by it, so using a | 229 // |*this| is owned by |*channel_| and so is always outlived by it, so using a |
230 // raw pointer is ok. | 230 // raw pointer is ok. |
231 GpuChannelHost* channel_; | 231 GpuChannelHost* channel_; |
232 const uint64_t command_buffer_id_; | 232 scoped_ptr<CommandBufferIPCTransport> transport_; |
233 const int32_t route_id_; | |
234 const int32_t stream_id_; | 233 const int32_t stream_id_; |
235 uint32_t flush_count_; | 234 uint32_t flush_count_; |
236 int32_t last_put_offset_; | 235 int32_t last_put_offset_; |
237 int32_t last_barrier_put_offset_; | 236 int32_t last_barrier_put_offset_; |
238 | 237 |
239 // Next generated fence sync. | 238 // Next generated fence sync. |
240 uint64_t next_fence_sync_release_; | 239 uint64_t next_fence_sync_release_; |
241 | 240 |
242 // Unverified flushed fence syncs with their corresponding flush id. | 241 // Unverified flushed fence syncs with their corresponding flush id. |
243 std::queue<std::pair<uint64_t, uint32_t>> flushed_release_flush_id_; | 242 std::queue<std::pair<uint64_t, uint32_t>> flushed_release_flush_id_; |
(...skipping 21 matching lines...) Expand all Loading... |
265 | 264 |
266 base::WeakPtr<CommandBufferProxyImpl> weak_this_; | 265 base::WeakPtr<CommandBufferProxyImpl> weak_this_; |
267 scoped_refptr<base::SequencedTaskRunner> callback_thread_; | 266 scoped_refptr<base::SequencedTaskRunner> callback_thread_; |
268 | 267 |
269 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxyImpl); | 268 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxyImpl); |
270 }; | 269 }; |
271 | 270 |
272 } // namespace content | 271 } // namespace content |
273 | 272 |
274 #endif // CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ | 273 #endif // CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ |
OLD | NEW |