OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 SERVICES_UI_GLES2_COMMAND_BUFFER_LOCAL_H_ |
| 6 #define SERVICES_UI_GLES2_COMMAND_BUFFER_LOCAL_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include <map> |
| 12 |
| 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "gpu/command_buffer/client/gpu_control.h" |
| 19 #include "gpu/command_buffer/common/command_buffer.h" |
| 20 #include "gpu/command_buffer/common/command_buffer_id.h" |
| 21 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 22 #include "services/ui/gles2/command_buffer_driver.h" |
| 23 #include "services/ui/public/interfaces/command_buffer.mojom.h" |
| 24 #include "ui/gfx/geometry/size.h" |
| 25 #include "ui/gfx/gpu_memory_buffer.h" |
| 26 #include "ui/gfx/native_widget_types.h" |
| 27 |
| 28 namespace { |
| 29 class WaitableEvent; |
| 30 } |
| 31 |
| 32 namespace gl { |
| 33 class GLContext; |
| 34 class GLSurface; |
| 35 } |
| 36 |
| 37 namespace gpu { |
| 38 class GpuControlClient; |
| 39 class SyncPointClient; |
| 40 } |
| 41 |
| 42 namespace ui { |
| 43 |
| 44 class CommandBufferDriver; |
| 45 class CommandBufferLocalClient; |
| 46 class GpuState; |
| 47 |
| 48 // This class provides a wrapper around a CommandBufferDriver and a GpuControl |
| 49 // implementation to allow cc::Display to generate GL directly on the main |
| 50 // thread. |
| 51 class CommandBufferLocal : public gpu::CommandBuffer, |
| 52 public gpu::GpuControl, |
| 53 public CommandBufferDriver::Client, |
| 54 base::NonThreadSafe { |
| 55 public: |
| 56 CommandBufferLocal(CommandBufferLocalClient* client, |
| 57 gfx::AcceleratedWidget widget, |
| 58 const scoped_refptr<GpuState>& gpu_state); |
| 59 |
| 60 bool Initialize(); |
| 61 // Destroy the CommandBufferLocal. The client should not use this class |
| 62 // after calling it. |
| 63 void Destroy(); |
| 64 |
| 65 // gpu::CommandBuffer implementation: |
| 66 gpu::CommandBuffer::State GetLastState() override; |
| 67 int32_t GetLastToken() override; |
| 68 void Flush(int32_t put_offset) override; |
| 69 void OrderingBarrier(int32_t put_offset) override; |
| 70 void WaitForTokenInRange(int32_t start, int32_t end) override; |
| 71 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; |
| 72 void SetGetBuffer(int32_t buffer) override; |
| 73 scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size, |
| 74 int32_t* id) override; |
| 75 void DestroyTransferBuffer(int32_t id) override; |
| 76 |
| 77 // gpu::GpuControl implementation: |
| 78 void SetGpuControlClient(gpu::GpuControlClient*) override; |
| 79 gpu::Capabilities GetCapabilities() override; |
| 80 int32_t CreateImage(ClientBuffer buffer, |
| 81 size_t width, |
| 82 size_t height, |
| 83 unsigned internalformat) override; |
| 84 void DestroyImage(int32_t id) override; |
| 85 int32_t CreateGpuMemoryBufferImage(size_t width, |
| 86 size_t height, |
| 87 unsigned internal_format, |
| 88 unsigned usage) override; |
| 89 void SignalQuery(uint32_t query_id, const base::Closure& callback) override; |
| 90 void SetLock(base::Lock*) override; |
| 91 void EnsureWorkVisible() override; |
| 92 gpu::CommandBufferNamespace GetNamespaceID() const override; |
| 93 gpu::CommandBufferId GetCommandBufferID() const override; |
| 94 int32_t GetExtraCommandBufferData() const override; |
| 95 uint64_t GenerateFenceSyncRelease() override; |
| 96 bool IsFenceSyncRelease(uint64_t release) override; |
| 97 bool IsFenceSyncFlushed(uint64_t release) override; |
| 98 bool IsFenceSyncFlushReceived(uint64_t release) override; |
| 99 void SignalSyncToken(const gpu::SyncToken& sync_token, |
| 100 const base::Closure& callback) override; |
| 101 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; |
| 102 |
| 103 private: |
| 104 // CommandBufferDriver::Client implementation. All called on GPU thread. |
| 105 void DidLoseContext(uint32_t reason) override; |
| 106 void UpdateVSyncParameters(const base::TimeTicks& timebase, |
| 107 const base::TimeDelta& interval) override; |
| 108 void OnGpuCompletedSwapBuffers(gfx::SwapResult result) override; |
| 109 |
| 110 ~CommandBufferLocal() override; |
| 111 |
| 112 gpu::CommandBufferSharedState* shared_state() const { |
| 113 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
| 114 shared_state_.get()); |
| 115 } |
| 116 void TryUpdateState(); |
| 117 void MakeProgressAndUpdateState(); |
| 118 |
| 119 // Helper functions are called in the GPU thread. |
| 120 void InitializeOnGpuThread(base::WaitableEvent* event, bool* result); |
| 121 bool FlushOnGpuThread(int32_t put_offset, uint32_t order_num); |
| 122 bool SetGetBufferOnGpuThread(int32_t buffer); |
| 123 bool RegisterTransferBufferOnGpuThread( |
| 124 int32_t id, |
| 125 mojo::ScopedSharedBufferHandle transfer_buffer, |
| 126 uint32_t size); |
| 127 bool DestroyTransferBufferOnGpuThread(int32_t id); |
| 128 bool CreateImageOnGpuThread(int32_t id, |
| 129 mojo::ScopedHandle memory_handle, |
| 130 int32_t type, |
| 131 const gfx::Size& size, |
| 132 int32_t format, |
| 133 int32_t internal_format); |
| 134 bool CreateImageNativeOzoneOnGpuThread(int32_t id, |
| 135 int32_t type, |
| 136 gfx::Size size, |
| 137 gfx::BufferFormat format, |
| 138 uint32_t internal_format, |
| 139 ui::NativePixmap* pixmap); |
| 140 bool DestroyImageOnGpuThread(int32_t id); |
| 141 bool MakeProgressOnGpuThread(base::WaitableEvent* event, |
| 142 gpu::CommandBuffer::State* state); |
| 143 bool DeleteOnGpuThread(base::WaitableEvent* event); |
| 144 bool SignalQueryOnGpuThread(uint32_t query_id, const base::Closure& callback); |
| 145 |
| 146 // Helper functions are called in the client thread. |
| 147 void DidLoseContextOnClientThread(uint32_t reason); |
| 148 void UpdateVSyncParametersOnClientThread(const base::TimeTicks& timebase, |
| 149 const base::TimeDelta& interval); |
| 150 void OnGpuCompletedSwapBuffersOnClientThread(gfx::SwapResult result); |
| 151 |
| 152 gfx::AcceleratedWidget widget_; |
| 153 scoped_refptr<GpuState> gpu_state_; |
| 154 std::unique_ptr<CommandBufferDriver> driver_; |
| 155 CommandBufferLocalClient* client_; |
| 156 scoped_refptr<base::SingleThreadTaskRunner> client_thread_task_runner_; |
| 157 |
| 158 // Members accessed on the client thread: |
| 159 gpu::GpuControlClient* gpu_control_client_; |
| 160 gpu::CommandBuffer::State last_state_; |
| 161 mojo::ScopedSharedBufferMapping shared_state_; |
| 162 int32_t last_put_offset_; |
| 163 gpu::Capabilities capabilities_; |
| 164 int32_t next_transfer_buffer_id_; |
| 165 int32_t next_image_id_; |
| 166 uint64_t next_fence_sync_release_; |
| 167 uint64_t flushed_fence_sync_release_; |
| 168 bool lost_context_; |
| 169 |
| 170 // This sync point client is only for out of order Wait on client thread. |
| 171 std::unique_ptr<gpu::SyncPointClient> sync_point_client_waiter_; |
| 172 |
| 173 base::WeakPtr<CommandBufferLocal> weak_ptr_; |
| 174 |
| 175 // This weak factory will be invalidated in the client thread, so all weak |
| 176 // pointers have to be dereferenced in the client thread too. |
| 177 base::WeakPtrFactory<CommandBufferLocal> weak_factory_; |
| 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(CommandBufferLocal); |
| 180 }; |
| 181 |
| 182 } // namespace mus |
| 183 |
| 184 #endif // SERVICES_UI_GLES2_COMMAND_BUFFER_LOCAL_H_ |
OLD | NEW |