Connect PPAPI IPC channels for non-SFI mode.
[chromium-blink-merge.git] / mojo / gles2 / command_buffer_client_impl.h
blobab5fed3eb2a885f8d75b8cfb415bcee375285cd8
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_
8 #include <map>
9 #include <queue>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h"
13 #include "gpu/command_buffer/common/command_buffer.h"
14 #include "gpu/command_buffer/common/command_buffer_shared.h"
15 #include "gpu/command_buffer/common/gpu_control.h"
17 #include "mojo/public/bindings/error_handler.h"
18 #include "mojo/public/bindings/remote_ptr.h"
19 #include "mojom/command_buffer.h"
21 namespace base {
22 class RunLoop;
25 namespace mojo {
26 template <typename S>
27 class SyncDispatcher;
29 namespace gles2 {
30 class CommandBufferClientImpl;
32 class CommandBufferDelegate {
33 public:
34 virtual ~CommandBufferDelegate();
35 virtual void ContextLost();
36 virtual void DrawAnimationFrame();
39 class CommandBufferClientImpl : public CommandBufferClient,
40 public CommandBufferSyncClient,
41 public ErrorHandler,
42 public gpu::CommandBuffer,
43 public gpu::GpuControl {
44 public:
45 explicit CommandBufferClientImpl(
46 CommandBufferDelegate* delegate,
47 MojoAsyncWaiter* async_waiter,
48 ScopedCommandBufferHandle command_buffer_handle);
49 virtual ~CommandBufferClientImpl();
51 // CommandBuffer implementation:
52 virtual bool Initialize() OVERRIDE;
53 virtual State GetState() OVERRIDE;
54 virtual State GetLastState() OVERRIDE;
55 virtual int32 GetLastToken() OVERRIDE;
56 virtual void Flush(int32 put_offset) OVERRIDE;
57 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE;
58 virtual void SetGetBuffer(int32 shm_id) OVERRIDE;
59 virtual void SetGetOffset(int32 get_offset) OVERRIDE;
60 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE;
61 virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
62 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE;
63 virtual void SetToken(int32 token) OVERRIDE;
64 virtual void SetParseError(gpu::error::Error error) OVERRIDE;
65 virtual void SetContextLostReason(gpu::error::ContextLostReason reason)
66 OVERRIDE;
68 // gpu::GpuControl implementation:
69 virtual gpu::Capabilities GetCapabilities() OVERRIDE;
70 virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
71 size_t height,
72 unsigned internalformat,
73 int32* id) OVERRIDE;
74 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
75 virtual uint32 InsertSyncPoint() OVERRIDE;
76 virtual void SignalSyncPoint(uint32 sync_point,
77 const base::Closure& callback) OVERRIDE;
78 virtual void SignalQuery(uint32 query,
79 const base::Closure& callback) OVERRIDE;
80 virtual void SetSurfaceVisible(bool visible) OVERRIDE;
81 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats)
82 OVERRIDE;
83 virtual void Echo(const base::Closure& callback) OVERRIDE;
84 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
86 void RequestAnimationFrames();
87 void CancelAnimationFrames();
89 private:
90 typedef std::map<int32, gpu::Buffer> TransferBufferMap;
92 // CommandBufferClient implementation:
93 virtual void DidInitialize(bool success) MOJO_OVERRIDE;
94 virtual void DidMakeProgress(const CommandBufferState& state) MOJO_OVERRIDE;
95 virtual void DidDestroy() MOJO_OVERRIDE;
96 virtual void EchoAck() MOJO_OVERRIDE;
97 virtual void LostContext(int32_t lost_reason) MOJO_OVERRIDE;
99 // ErrorHandler implementation:
100 virtual void OnError() MOJO_OVERRIDE;
102 virtual void DrawAnimationFrame() MOJO_OVERRIDE;
104 void TryUpdateState();
105 void MakeProgressAndUpdateState();
107 gpu::CommandBufferSharedState* shared_state() const {
108 return reinterpret_cast<gpu::CommandBufferSharedState*>(
109 shared_state_shm_->memory());
112 CommandBufferDelegate* delegate_;
113 RemotePtr<mojo::CommandBuffer> command_buffer_;
114 scoped_ptr<SyncDispatcher<CommandBufferSyncClient> > sync_dispatcher_;
116 State last_state_;
117 scoped_ptr<base::SharedMemory> shared_state_shm_;
118 TransferBufferMap transfer_buffers_;
119 int32 last_put_offset_;
120 int32 next_transfer_buffer_id_;
121 std::queue<base::Closure> echo_closures_;
123 bool initialize_result_;
126 } // gles2
127 } // mojo
129 #endif // MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_