command_buffer_client_impl.h revision 116680a4aac90f2aa7413d9095a592090648e557
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <map>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "base/macros.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "gpu/command_buffer/client/gpu_control.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gpu/command_buffer/common/command_buffer.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gpu/command_buffer/common/command_buffer_shared.h"
15e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "mojo/public/cpp/bindings/error_handler.h"
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "mojo/services/gles2/command_buffer.mojom.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class RunLoop;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace mojo {
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gles2 {
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CommandBufferClientImpl;
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CommandBufferDelegate {
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~CommandBufferDelegate();
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void ContextLost();
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DrawAnimationFrame();
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CommandBufferClientImpl : public CommandBufferClient,
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public ErrorHandler,
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public gpu::CommandBuffer,
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public gpu::GpuControl {
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit CommandBufferClientImpl(
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CommandBufferDelegate* delegate,
40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const MojoAsyncWaiter* async_waiter,
410de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      ScopedMessagePipeHandle command_buffer_handle);
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~CommandBufferClientImpl();
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // CommandBuffer implementation:
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Initialize() OVERRIDE;
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual State GetLastState() OVERRIDE;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int32 GetLastToken() OVERRIDE;
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Flush(int32 put_offset) OVERRIDE;
4923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
5023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetGetBuffer(int32 shm_id) OVERRIDE;
52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                                          int32* id) OVERRIDE;
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // gpu::GpuControl implementation:
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gpu::Capabilities GetCapabilities() OVERRIDE;
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      size_t height,
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      unsigned internalformat,
61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                                      unsigned usage,
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      int32* id) OVERRIDE;
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32 InsertSyncPoint() OVERRIDE;
65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual uint32 InsertFutureSyncPoint() OVERRIDE;
66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE;
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SignalSyncPoint(uint32 sync_point,
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const base::Closure& callback) OVERRIDE;
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SignalQuery(uint32 query,
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           const base::Closure& callback) OVERRIDE;
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetSurfaceVisible(bool visible) OVERRIDE;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Echo(const base::Closure& callback) OVERRIDE;
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void RequestAnimationFrames();
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CancelAnimationFrames();
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
79116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  class SyncClientImpl;
80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // CommandBufferClient implementation:
8223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void DidDestroy() OVERRIDE;
8323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void LostContext(int32_t lost_reason) OVERRIDE;
84116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void DrawAnimationFrame() OVERRIDE;
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ErrorHandler implementation:
870de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  virtual void OnConnectionError() OVERRIDE;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void TryUpdateState();
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void MakeProgressAndUpdateState();
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
92c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  gpu::CommandBufferSharedState* shared_state() const { return shared_state_; }
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CommandBufferDelegate* delegate_;
950de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  CommandBufferPtr command_buffer_;
96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<SyncClientImpl> sync_client_impl_;
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  State last_state_;
99c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  mojo::ScopedSharedBufferHandle shared_state_handle_;
100c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  gpu::CommandBufferSharedState* shared_state_;
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int32 last_put_offset_;
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int32 next_transfer_buffer_id_;
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const MojoAsyncWaiter* async_waiter_;
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // gles2
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // mojo
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
111