| 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 COMPONENTS_MUS_GLES2_COMMAND_BUFFER_LOCAL_H_ | |
| 6 #define COMPONENTS_MUS_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 "components/mus/gles2/command_buffer_driver.h" | |
| 19 #include "components/mus/public/interfaces/command_buffer.mojom.h" | |
| 20 #include "gpu/command_buffer/client/gpu_control.h" | |
| 21 #include "gpu/command_buffer/common/command_buffer.h" | |
| 22 #include "gpu/command_buffer/common/command_buffer_id.h" | |
| 23 #include "gpu/command_buffer/common/command_buffer_shared.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 mus { | |
| 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 int32_t GetImageGpuMemoryBufferId(unsigned image_id) override; | |
| 90 void SignalQuery(uint32_t query_id, const base::Closure& callback) override; | |
| 91 void SetLock(base::Lock*) override; | |
| 92 void EnsureWorkVisible() override; | |
| 93 gpu::CommandBufferNamespace GetNamespaceID() const override; | |
| 94 gpu::CommandBufferId GetCommandBufferID() const override; | |
| 95 int32_t GetExtraCommandBufferData() const override; | |
| 96 uint64_t GenerateFenceSyncRelease() override; | |
| 97 bool IsFenceSyncRelease(uint64_t release) override; | |
| 98 bool IsFenceSyncFlushed(uint64_t release) override; | |
| 99 bool IsFenceSyncFlushReceived(uint64_t release) override; | |
| 100 void SignalSyncToken(const gpu::SyncToken& sync_token, | |
| 101 const base::Closure& callback) override; | |
| 102 bool CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) override; | |
| 103 | |
| 104 private: | |
| 105 // CommandBufferDriver::Client implementation. All called on GPU thread. | |
| 106 void DidLoseContext(uint32_t reason) override; | |
| 107 void UpdateVSyncParameters(const base::TimeTicks& timebase, | |
| 108 const base::TimeDelta& interval) override; | |
| 109 void OnGpuCompletedSwapBuffers(gfx::SwapResult result) override; | |
| 110 | |
| 111 ~CommandBufferLocal() override; | |
| 112 | |
| 113 gpu::CommandBufferSharedState* shared_state() const { | |
| 114 return reinterpret_cast<gpu::CommandBufferSharedState*>( | |
| 115 shared_state_.get()); | |
| 116 } | |
| 117 void TryUpdateState(); | |
| 118 void MakeProgressAndUpdateState(); | |
| 119 | |
| 120 // Helper functions are called in the GPU thread. | |
| 121 void InitializeOnGpuThread(base::WaitableEvent* event, bool* result); | |
| 122 bool FlushOnGpuThread(int32_t put_offset, uint32_t order_num); | |
| 123 bool SetGetBufferOnGpuThread(int32_t buffer); | |
| 124 bool RegisterTransferBufferOnGpuThread( | |
| 125 int32_t id, | |
| 126 mojo::ScopedSharedBufferHandle transfer_buffer, | |
| 127 uint32_t size); | |
| 128 bool DestroyTransferBufferOnGpuThread(int32_t id); | |
| 129 bool CreateImageOnGpuThread(int32_t id, | |
| 130 mojo::ScopedHandle memory_handle, | |
| 131 int32_t type, | |
| 132 const gfx::Size& size, | |
| 133 int32_t format, | |
| 134 int32_t internal_format); | |
| 135 bool CreateImageNativeOzoneOnGpuThread(int32_t id, | |
| 136 int32_t type, | |
| 137 gfx::Size size, | |
| 138 gfx::BufferFormat format, | |
| 139 uint32_t internal_format, | |
| 140 ui::NativePixmap* pixmap); | |
| 141 bool DestroyImageOnGpuThread(int32_t id); | |
| 142 bool MakeProgressOnGpuThread(base::WaitableEvent* event, | |
| 143 gpu::CommandBuffer::State* state); | |
| 144 bool DeleteOnGpuThread(base::WaitableEvent* event); | |
| 145 bool SignalQueryOnGpuThread(uint32_t query_id, const base::Closure& callback); | |
| 146 | |
| 147 // Helper functions are called in the client thread. | |
| 148 void DidLoseContextOnClientThread(uint32_t reason); | |
| 149 void UpdateVSyncParametersOnClientThread(const base::TimeTicks& timebase, | |
| 150 const base::TimeDelta& interval); | |
| 151 void OnGpuCompletedSwapBuffersOnClientThread(gfx::SwapResult result); | |
| 152 | |
| 153 gfx::AcceleratedWidget widget_; | |
| 154 scoped_refptr<GpuState> gpu_state_; | |
| 155 std::unique_ptr<CommandBufferDriver> driver_; | |
| 156 CommandBufferLocalClient* client_; | |
| 157 scoped_refptr<base::SingleThreadTaskRunner> client_thread_task_runner_; | |
| 158 | |
| 159 // Members accessed on the client thread: | |
| 160 gpu::GpuControlClient* gpu_control_client_; | |
| 161 gpu::CommandBuffer::State last_state_; | |
| 162 mojo::ScopedSharedBufferMapping shared_state_; | |
| 163 int32_t last_put_offset_; | |
| 164 gpu::Capabilities capabilities_; | |
| 165 int32_t next_transfer_buffer_id_; | |
| 166 int32_t next_image_id_; | |
| 167 uint64_t next_fence_sync_release_; | |
| 168 uint64_t flushed_fence_sync_release_; | |
| 169 bool lost_context_; | |
| 170 | |
| 171 // This sync point client is only for out of order Wait on client thread. | |
| 172 std::unique_ptr<gpu::SyncPointClient> sync_point_client_waiter_; | |
| 173 | |
| 174 base::WeakPtr<CommandBufferLocal> weak_ptr_; | |
| 175 | |
| 176 // This weak factory will be invalidated in the client thread, so all weak | |
| 177 // pointers have to be dereferenced in the client thread too. | |
| 178 base::WeakPtrFactory<CommandBufferLocal> weak_factory_; | |
| 179 | |
| 180 DISALLOW_COPY_AND_ASSIGN(CommandBufferLocal); | |
| 181 }; | |
| 182 | |
| 183 } // namespace mus | |
| 184 | |
| 185 #endif // COMPONENTS_MUS_GLES2_COMMAND_BUFFER_LOCAL_H_ | |
| OLD | NEW |