| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ | |
| 6 #define CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <map> | |
| 12 #include <queue> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/callback.h" | |
| 16 #include "base/compiler_specific.h" | |
| 17 #include "base/containers/hash_tables.h" | |
| 18 #include "base/containers/scoped_ptr_hash_map.h" | |
| 19 #include "base/macros.h" | |
| 20 #include "base/memory/ref_counted.h" | |
| 21 #include "base/memory/weak_ptr.h" | |
| 22 #include "base/observer_list.h" | |
| 23 #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_id.h" | |
| 26 #include "gpu/command_buffer/common/command_buffer_shared.h" | |
| 27 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | |
| 28 #include "ipc/ipc_listener.h" | |
| 29 #include "ui/events/latency_info.h" | |
| 30 #include "ui/gfx/swap_result.h" | |
| 31 | |
| 32 struct GPUCommandBufferConsoleMessage; | |
| 33 | |
| 34 namespace base { | |
| 35 class SharedMemory; | |
| 36 } | |
| 37 | |
| 38 namespace gpu { | |
| 39 struct Mailbox; | |
| 40 struct SyncToken; | |
| 41 } | |
| 42 | |
| 43 namespace content { | |
| 44 class GpuChannelHost; | |
| 45 | |
| 46 // Client side proxy that forwards messages synchronously to a | |
| 47 // CommandBufferStub. | |
| 48 class CommandBufferProxyImpl | |
| 49 : public gpu::CommandBuffer, | |
| 50 public gpu::GpuControl, | |
| 51 public IPC::Listener, | |
| 52 public base::SupportsWeakPtr<CommandBufferProxyImpl> { | |
| 53 public: | |
| 54 class DeletionObserver { | |
| 55 public: | |
| 56 // Called during the destruction of the CommandBufferProxyImpl. | |
| 57 virtual void OnWillDeleteImpl() = 0; | |
| 58 | |
| 59 protected: | |
| 60 virtual ~DeletionObserver() {} | |
| 61 }; | |
| 62 | |
| 63 typedef base::Callback<void( | |
| 64 const std::string& msg, int id)> GpuConsoleMessageCallback; | |
| 65 | |
| 66 CommandBufferProxyImpl(GpuChannelHost* channel, | |
| 67 int32_t route_id, | |
| 68 int32_t stream_id); | |
| 69 ~CommandBufferProxyImpl() override; | |
| 70 | |
| 71 // IPC::Listener implementation: | |
| 72 bool OnMessageReceived(const IPC::Message& message) override; | |
| 73 void OnChannelError() override; | |
| 74 | |
| 75 // CommandBuffer implementation: | |
| 76 bool Initialize() override; | |
| 77 State GetLastState() override; | |
| 78 int32_t GetLastToken() override; | |
| 79 void Flush(int32_t put_offset) override; | |
| 80 void OrderingBarrier(int32_t put_offset) override; | |
| 81 void WaitForTokenInRange(int32_t start, int32_t end) override; | |
| 82 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; | |
| 83 void SetGetBuffer(int32_t shm_id) override; | |
| 84 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, | |
| 85 int32_t* id) override; | |
| 86 void DestroyTransferBuffer(int32_t id) override; | |
| 87 | |
| 88 // gpu::GpuControl implementation: | |
| 89 gpu::Capabilities GetCapabilities() override; | |
| 90 int32_t CreateImage(ClientBuffer buffer, | |
| 91 size_t width, | |
| 92 size_t height, | |
| 93 unsigned internal_format) override; | |
| 94 void DestroyImage(int32_t id) override; | |
| 95 int32_t CreateGpuMemoryBufferImage(size_t width, | |
| 96 size_t height, | |
| 97 unsigned internal_format, | |
| 98 unsigned usage) override; | |
| 99 void SignalQuery(uint32_t query, const base::Closure& callback) override; | |
| 100 void SetLock(base::Lock* lock) override; | |
| 101 bool IsGpuChannelLost() override; | |
| 102 void EnsureWorkVisible() override; | |
| 103 gpu::CommandBufferNamespace GetNamespaceID() const override; | |
| 104 gpu::CommandBufferId GetCommandBufferID() const override; | |
| 105 int32_t GetExtraCommandBufferData() const override; | |
| 106 uint64_t GenerateFenceSyncRelease() override; | |
| 107 bool IsFenceSyncRelease(uint64_t release) override; | |
| 108 bool IsFenceSyncFlushed(uint64_t release) override; | |
| 109 bool IsFenceSyncFlushReceived(uint64_t release) override; | |
| 110 void SignalSyncToken(const gpu::SyncToken& sync_token, | |
| 111 const base::Closure& callback) override; | |
| 112 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; | |
| 113 | |
| 114 bool ProduceFrontBuffer(const gpu::Mailbox& mailbox); | |
| 115 void SetContextLostCallback(const base::Closure& callback); | |
| 116 | |
| 117 void AddDeletionObserver(DeletionObserver* observer); | |
| 118 void RemoveDeletionObserver(DeletionObserver* observer); | |
| 119 | |
| 120 bool EnsureBackbuffer(); | |
| 121 | |
| 122 void SetOnConsoleMessageCallback( | |
| 123 const GpuConsoleMessageCallback& callback); | |
| 124 | |
| 125 void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info); | |
| 126 using SwapBuffersCompletionCallback = | |
| 127 base::Callback<void(const std::vector<ui::LatencyInfo>& latency_info, | |
| 128 gfx::SwapResult result)>; | |
| 129 void SetSwapBuffersCompletionCallback( | |
| 130 const SwapBuffersCompletionCallback& callback); | |
| 131 | |
| 132 using UpdateVSyncParametersCallback = | |
| 133 base::Callback<void(base::TimeTicks timebase, base::TimeDelta interval)>; | |
| 134 void SetUpdateVSyncParametersCallback( | |
| 135 const UpdateVSyncParametersCallback& callback); | |
| 136 | |
| 137 // TODO(apatrick): this is a temporary optimization while skia is calling | |
| 138 // ContentGLContext::MakeCurrent prior to every GL call. It saves returning 6 | |
| 139 // ints redundantly when only the error is needed for the | |
| 140 // CommandBufferProxyImpl implementation. | |
| 141 gpu::error::Error GetLastError() override; | |
| 142 | |
| 143 int32_t route_id() const { return route_id_; } | |
| 144 | |
| 145 int32_t stream_id() const { return stream_id_; } | |
| 146 | |
| 147 GpuChannelHost* channel() const { return channel_; } | |
| 148 | |
| 149 base::SharedMemoryHandle GetSharedStateHandle() const { | |
| 150 return shared_state_shm_->handle(); | |
| 151 } | |
| 152 uint32_t CreateStreamTexture(uint32_t texture_id); | |
| 153 | |
| 154 private: | |
| 155 typedef std::map<int32_t, scoped_refptr<gpu::Buffer>> TransferBufferMap; | |
| 156 typedef base::hash_map<uint32_t, base::Closure> SignalTaskMap; | |
| 157 | |
| 158 void CheckLock() { | |
| 159 if (lock_) | |
| 160 lock_->AssertAcquired(); | |
| 161 } | |
| 162 | |
| 163 // Send an IPC message over the GPU channel. This is private to fully | |
| 164 // encapsulate the channel; all callers of this function must explicitly | |
| 165 // verify that the context has not been lost. | |
| 166 bool Send(IPC::Message* msg); | |
| 167 | |
| 168 // Message handlers: | |
| 169 void OnUpdateState(const gpu::CommandBuffer::State& state); | |
| 170 void OnDestroyed(gpu::error::ContextLostReason reason, | |
| 171 gpu::error::Error error); | |
| 172 void OnConsoleMessage(const GPUCommandBufferConsoleMessage& message); | |
| 173 void OnSignalAck(uint32_t id); | |
| 174 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | |
| 175 gfx::SwapResult result); | |
| 176 void OnUpdateVSyncParameters(base::TimeTicks timebase, | |
| 177 base::TimeDelta interval); | |
| 178 | |
| 179 // Try to read an updated copy of the state from shared memory. | |
| 180 void TryUpdateState(); | |
| 181 | |
| 182 // Updates the highest verified release fence sync. | |
| 183 void UpdateVerifiedReleases(uint32_t verified_flush); | |
| 184 | |
| 185 // Loses the context after we received an invalid message from the GPU | |
| 186 // process. Will call the lost context callback reentrantly if any. | |
| 187 void InvalidGpuMessage(); | |
| 188 | |
| 189 // Loses the context after we received an invalid reply from the GPU | |
| 190 // process. Will post a task to call the lost context callback if any. | |
| 191 void InvalidGpuReply(); | |
| 192 | |
| 193 void InvalidGpuReplyOnClientThread(); | |
| 194 | |
| 195 // The shared memory area used to update state. | |
| 196 gpu::CommandBufferSharedState* shared_state() const; | |
| 197 | |
| 198 base::Lock* lock_; | |
| 199 | |
| 200 // Unowned list of DeletionObservers. | |
| 201 base::ObserverList<DeletionObserver> deletion_observers_; | |
| 202 | |
| 203 // The last cached state received from the service. | |
| 204 State last_state_; | |
| 205 | |
| 206 // The shared memory area used to update state. | |
| 207 scoped_ptr<base::SharedMemory> shared_state_shm_; | |
| 208 | |
| 209 // |*this| is owned by |*channel_| and so is always outlived by it, so using a | |
| 210 // raw pointer is ok. | |
| 211 GpuChannelHost* channel_; | |
| 212 const gpu::CommandBufferId command_buffer_id_; | |
| 213 const int32_t route_id_; | |
| 214 const int32_t stream_id_; | |
| 215 uint32_t flush_count_; | |
| 216 int32_t last_put_offset_; | |
| 217 int32_t last_barrier_put_offset_; | |
| 218 | |
| 219 // Next generated fence sync. | |
| 220 uint64_t next_fence_sync_release_; | |
| 221 | |
| 222 // Unverified flushed fence syncs with their corresponding flush id. | |
| 223 std::queue<std::pair<uint64_t, uint32_t>> flushed_release_flush_id_; | |
| 224 | |
| 225 // Last flushed fence sync release, same as last item in queue if not empty. | |
| 226 uint64_t flushed_fence_sync_release_; | |
| 227 | |
| 228 // Last verified fence sync. | |
| 229 uint64_t verified_fence_sync_release_; | |
| 230 | |
| 231 base::Closure context_lost_callback_; | |
| 232 | |
| 233 GpuConsoleMessageCallback console_message_callback_; | |
| 234 | |
| 235 // Tasks to be invoked in SignalSyncPoint responses. | |
| 236 uint32_t next_signal_id_; | |
| 237 SignalTaskMap signal_tasks_; | |
| 238 | |
| 239 gpu::Capabilities capabilities_; | |
| 240 | |
| 241 std::vector<ui::LatencyInfo> latency_info_; | |
| 242 | |
| 243 SwapBuffersCompletionCallback swap_buffers_completion_callback_; | |
| 244 UpdateVSyncParametersCallback update_vsync_parameters_completion_callback_; | |
| 245 | |
| 246 base::WeakPtr<CommandBufferProxyImpl> weak_this_; | |
| 247 scoped_refptr<base::SequencedTaskRunner> callback_thread_; | |
| 248 | |
| 249 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxyImpl); | |
| 250 }; | |
| 251 | |
| 252 } // namespace content | |
| 253 | |
| 254 #endif // CONTENT_COMMON_GPU_CLIENT_COMMAND_BUFFER_PROXY_IMPL_H_ | |
| OLD | NEW |