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.
5 #ifndef MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
6 #define MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/view_manager/public/interfaces/command_buffer.mojom.h"
13 #include "gpu/command_buffer/client/gpu_control.h"
14 #include "gpu/command_buffer/common/command_buffer.h"
15 #include "gpu/command_buffer/common/command_buffer_shared.h"
22 class CommandBufferClientImpl
;
24 class CommandBufferDelegate
{
26 virtual ~CommandBufferDelegate();
27 virtual void ContextLost();
30 class CommandBufferClientImpl
: public mojo::CommandBufferLostContextObserver
,
31 public gpu::CommandBuffer
,
32 public gpu::GpuControl
{
34 explicit CommandBufferClientImpl(
35 CommandBufferDelegate
* delegate
,
36 const MojoAsyncWaiter
* async_waiter
,
37 mojo::ScopedMessagePipeHandle command_buffer_handle
);
38 ~CommandBufferClientImpl() override
;
40 // CommandBuffer implementation:
41 bool Initialize() override
;
42 State
GetLastState() override
;
43 int32_t GetLastToken() override
;
44 void Flush(int32_t put_offset
) override
;
45 void OrderingBarrier(int32_t put_offset
) override
;
46 void WaitForTokenInRange(int32_t start
, int32_t end
) override
;
47 void WaitForGetOffsetInRange(int32_t start
, int32_t end
) override
;
48 void SetGetBuffer(int32_t shm_id
) override
;
49 scoped_refptr
<gpu::Buffer
> CreateTransferBuffer(size_t size
,
50 int32_t* id
) override
;
51 void DestroyTransferBuffer(int32_t id
) override
;
53 // gpu::GpuControl implementation:
54 gpu::Capabilities
GetCapabilities() override
;
55 int32_t CreateImage(ClientBuffer buffer
,
58 unsigned internalformat
) override
;
59 void DestroyImage(int32_t id
) override
;
60 int32_t CreateGpuMemoryBufferImage(size_t width
,
62 unsigned internalformat
,
63 unsigned usage
) override
;
64 uint32
InsertSyncPoint() override
;
65 uint32
InsertFutureSyncPoint() override
;
66 void RetireSyncPoint(uint32 sync_point
) override
;
67 void SignalSyncPoint(uint32 sync_point
,
68 const base::Closure
& callback
) override
;
69 void SignalQuery(uint32 query
, const base::Closure
& callback
) override
;
70 void SetSurfaceVisible(bool visible
) override
;
71 uint32
CreateStreamTexture(uint32 texture_id
) override
;
72 void SetLock(base::Lock
*) override
;
73 bool IsGpuChannelLost() override
;
77 class SyncPointClientImpl
;
79 // mojo::CommandBufferLostContextObserver implementation:
80 void DidLoseContext(int32_t lost_reason
) override
;
82 void TryUpdateState();
83 void MakeProgressAndUpdateState();
85 gpu::CommandBufferSharedState
* shared_state() const { return shared_state_
; }
87 CommandBufferDelegate
* delegate_
;
88 mojo::Binding
<mojo::CommandBufferLostContextObserver
> observer_binding_
;
89 mojo::CommandBufferPtr command_buffer_
;
90 scoped_ptr
<SyncClientImpl
> sync_client_impl_
;
91 scoped_ptr
<SyncPointClientImpl
> sync_point_client_impl_
;
93 gpu::Capabilities capabilities_
;
95 mojo::ScopedSharedBufferHandle shared_state_handle_
;
96 gpu::CommandBufferSharedState
* shared_state_
;
97 int32_t last_put_offset_
;
98 int32_t next_transfer_buffer_id_
;
100 // Image IDs are allocated in sequence.
103 const MojoAsyncWaiter
* async_waiter_
;
108 #endif // MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_