| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_IMPL_H_ | |
| 6 #define SERVICES_UI_GLES2_COMMAND_BUFFER_IMPL_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/single_thread_task_runner.h" | |
| 15 #include "gpu/command_buffer/common/command_buffer.h" | |
| 16 #include "mojo/public/cpp/bindings/binding.h" | |
| 17 #include "services/ui/gles2/command_buffer_driver.h" | |
| 18 #include "services/ui/public/interfaces/command_buffer.mojom.h" | |
| 19 | |
| 20 namespace ui { | |
| 21 | |
| 22 class CommandBufferDriver; | |
| 23 class GpuState; | |
| 24 | |
| 25 // This class listens to the CommandBuffer message pipe on a low-latency thread | |
| 26 // so that we can insert sync points without blocking on the GL driver. It | |
| 27 // forwards most method calls to the CommandBufferDriver, which runs on the | |
| 28 // same thread as the native viewport. | |
| 29 class CommandBufferImpl : public mojom::CommandBuffer, | |
| 30 public CommandBufferDriver::Client { | |
| 31 public: | |
| 32 CommandBufferImpl(mojo::InterfaceRequest<CommandBuffer> request, | |
| 33 scoped_refptr<GpuState> gpu_state); | |
| 34 | |
| 35 private: | |
| 36 class CommandBufferDriverClientImpl; | |
| 37 ~CommandBufferImpl() override; | |
| 38 | |
| 39 // CommandBufferDriver::Client. All called on the GPU thread. | |
| 40 void DidLoseContext(uint32_t reason) override; | |
| 41 void UpdateVSyncParameters(const base::TimeTicks& timebase, | |
| 42 const base::TimeDelta& interval) override; | |
| 43 void OnGpuCompletedSwapBuffers(gfx::SwapResult result) override; | |
| 44 | |
| 45 // mojom::CommandBuffer: | |
| 46 void Initialize( | |
| 47 mojom::CommandBufferClientPtr client, | |
| 48 mojo::ScopedSharedBufferHandle shared_state, | |
| 49 mojo::Array<int32_t> attribs, | |
| 50 const mojom::CommandBuffer::InitializeCallback& callback) override; | |
| 51 void SetGetBuffer(int32_t buffer) override; | |
| 52 void Flush(int32_t put_offset) override; | |
| 53 void MakeProgress( | |
| 54 int32_t last_get_offset, | |
| 55 const mojom::CommandBuffer::MakeProgressCallback& callback) override; | |
| 56 void RegisterTransferBuffer(int32_t id, | |
| 57 mojo::ScopedSharedBufferHandle transfer_buffer, | |
| 58 uint32_t size) override; | |
| 59 void DestroyTransferBuffer(int32_t id) override; | |
| 60 void CreateImage(int32_t id, | |
| 61 mojo::ScopedHandle memory_handle, | |
| 62 int32_t type, | |
| 63 const gfx::Size& size, | |
| 64 int32_t format, | |
| 65 int32_t internal_format) override; | |
| 66 void DestroyImage(int32_t id) override; | |
| 67 void CreateStreamTexture( | |
| 68 uint32_t client_texture_id, | |
| 69 const mojom::CommandBuffer::CreateStreamTextureCallback& callback | |
| 70 ) override; | |
| 71 void TakeFrontBuffer(const gpu::Mailbox& mailbox) override; | |
| 72 void ReturnFrontBuffer(const gpu::Mailbox& mailbox, bool is_lost) override; | |
| 73 void SignalQuery(uint32_t query, uint32_t signal_id) override; | |
| 74 void SignalSyncToken(const gpu::SyncToken& sync_token, | |
| 75 uint32_t signal_id) override; | |
| 76 void WaitForGetOffsetInRange( | |
| 77 int32_t start, int32_t end, | |
| 78 const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback | |
| 79 ) override; | |
| 80 void WaitForTokenInRange( | |
| 81 int32_t start, int32_t end, | |
| 82 const mojom::CommandBuffer::WaitForGetOffsetInRangeCallback& callback | |
| 83 ) override; | |
| 84 | |
| 85 // All helper functions are called in the GPU therad. | |
| 86 void InitializeOnGpuThread( | |
| 87 mojom::CommandBufferClientPtr client, | |
| 88 mojo::ScopedSharedBufferHandle shared_state, | |
| 89 mojo::Array<int32_t> attribs, | |
| 90 const base::Callback< | |
| 91 void(mojom::CommandBufferInitializeResultPtr)>& callback); | |
| 92 bool SetGetBufferOnGpuThread(int32_t buffer); | |
| 93 bool FlushOnGpuThread(int32_t put_offset, uint32_t order_num); | |
| 94 bool MakeProgressOnGpuThread( | |
| 95 int32_t last_get_offset, | |
| 96 const base::Callback<void(const gpu::CommandBuffer::State&)>& callback); | |
| 97 bool RegisterTransferBufferOnGpuThread( | |
| 98 int32_t id, | |
| 99 mojo::ScopedSharedBufferHandle transfer_buffer, | |
| 100 uint32_t size); | |
| 101 bool DestroyTransferBufferOnGpuThread(int32_t id); | |
| 102 bool CreateImageOnGpuThread(int32_t id, | |
| 103 mojo::ScopedHandle memory_handle, | |
| 104 int32_t type, | |
| 105 const gfx::Size& size, | |
| 106 int32_t format, | |
| 107 int32_t internal_format); | |
| 108 bool DestroyImageOnGpuThread(int32_t id); | |
| 109 | |
| 110 void BindToRequest(mojo::InterfaceRequest<CommandBuffer> request); | |
| 111 | |
| 112 void OnConnectionError(); | |
| 113 bool DeleteOnGpuThread(); | |
| 114 void DeleteOnGpuThread2(); | |
| 115 | |
| 116 scoped_refptr<GpuState> gpu_state_; | |
| 117 std::unique_ptr<CommandBufferDriver> driver_; | |
| 118 std::unique_ptr<mojo::Binding<CommandBuffer>> binding_; | |
| 119 mojom::CommandBufferClientPtr client_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl); | |
| 122 }; | |
| 123 | |
| 124 } // namespace ui | |
| 125 | |
| 126 #endif // SERVICES_UI_GLES2_COMMAND_BUFFER_IMPL_H_ | |
| OLD | NEW |