Revert "Non-SFI NaCl: Allow CLOCK_SYSTEM_TRACE on Chrome OS"
[chromium-blink-merge.git] / mojo / gles2 / command_buffer_client_impl.h
blobe4c78935447ce084bbec284fc9d49501d23e9546
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>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/client/gpu_control.h"
13 #include "gpu/command_buffer/common/command_buffer.h"
14 #include "gpu/command_buffer/common/command_buffer_shared.h"
15 #include "mojo/public/cpp/bindings/error_handler.h"
16 #include "mojo/services/gles2/command_buffer.mojom.h"
18 namespace base {
19 class RunLoop;
22 namespace mojo {
23 template <typename S>
24 class SyncDispatcher;
26 namespace gles2 {
27 class CommandBufferClientImpl;
29 class CommandBufferDelegate {
30 public:
31 virtual ~CommandBufferDelegate();
32 virtual void ContextLost();
33 virtual void DrawAnimationFrame();
36 class CommandBufferClientImpl : public CommandBufferClient,
37 public CommandBufferSyncClient,
38 public ErrorHandler,
39 public gpu::CommandBuffer,
40 public gpu::GpuControl {
41 public:
42 explicit CommandBufferClientImpl(
43 CommandBufferDelegate* delegate,
44 MojoAsyncWaiter* async_waiter,
45 ScopedMessagePipeHandle command_buffer_handle);
46 virtual ~CommandBufferClientImpl();
48 // CommandBuffer implementation:
49 virtual bool Initialize() OVERRIDE;
50 virtual State GetLastState() OVERRIDE;
51 virtual int32 GetLastToken() OVERRIDE;
52 virtual void Flush(int32 put_offset) OVERRIDE;
53 virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
54 virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
55 virtual void SetGetBuffer(int32 shm_id) OVERRIDE;
56 virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
57 int32* id) OVERRIDE;
58 virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
60 // gpu::GpuControl implementation:
61 virtual gpu::Capabilities GetCapabilities() OVERRIDE;
62 virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
63 size_t height,
64 unsigned internalformat,
65 unsigned usage,
66 int32* id) OVERRIDE;
67 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
68 virtual uint32 InsertSyncPoint() OVERRIDE;
69 virtual void SignalSyncPoint(uint32 sync_point,
70 const base::Closure& callback) OVERRIDE;
71 virtual void SignalQuery(uint32 query,
72 const base::Closure& callback) OVERRIDE;
73 virtual void SetSurfaceVisible(bool visible) OVERRIDE;
74 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats)
75 OVERRIDE;
76 virtual void Echo(const base::Closure& callback) OVERRIDE;
77 virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
79 void RequestAnimationFrames();
80 void CancelAnimationFrames();
82 private:
83 // CommandBufferClient implementation:
84 virtual void DidInitialize(bool success) OVERRIDE;
85 virtual void DidMakeProgress(CommandBufferStatePtr state) OVERRIDE;
86 virtual void DidDestroy() OVERRIDE;
87 virtual void LostContext(int32_t lost_reason) OVERRIDE;
89 // ErrorHandler implementation:
90 virtual void OnConnectionError() OVERRIDE;
92 virtual void DrawAnimationFrame() OVERRIDE;
94 void TryUpdateState();
95 void MakeProgressAndUpdateState();
97 gpu::CommandBufferSharedState* shared_state() const { return shared_state_; }
99 CommandBufferDelegate* delegate_;
100 CommandBufferPtr command_buffer_;
101 scoped_ptr<SyncDispatcher<CommandBufferSyncClient> > sync_dispatcher_;
103 State last_state_;
104 mojo::ScopedSharedBufferHandle shared_state_handle_;
105 gpu::CommandBufferSharedState* shared_state_;
106 int32 last_put_offset_;
107 int32 next_transfer_buffer_id_;
109 bool initialize_result_;
110 MojoAsyncWaiter* async_waiter_;
113 } // gles2
114 } // mojo
116 #endif // MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_