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)};
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CommandBufferClientImpl : public CommandBufferClient,
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public ErrorHandler,
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public gpu::CommandBuffer,
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                public gpu::GpuControl {
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit CommandBufferClientImpl(
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CommandBufferDelegate* delegate,
39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const MojoAsyncWaiter* async_waiter,
400de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)      ScopedMessagePipeHandle command_buffer_handle);
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~CommandBufferClientImpl();
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // CommandBuffer implementation:
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Initialize() OVERRIDE;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual State GetLastState() OVERRIDE;
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int32 GetLastToken() OVERRIDE;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Flush(int32 put_offset) OVERRIDE;
4823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
4923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetGetBuffer(int32 shm_id) OVERRIDE;
51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                                          int32* id) OVERRIDE;
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // gpu::GpuControl implementation:
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gpu::Capabilities GetCapabilities() OVERRIDE;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      size_t height,
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      unsigned internalformat,
60010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                                      unsigned usage,
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                                      int32* id) OVERRIDE;
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32 InsertSyncPoint() OVERRIDE;
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual uint32 InsertFutureSyncPoint() OVERRIDE;
65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE;
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SignalSyncPoint(uint32 sync_point,
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const base::Closure& callback) OVERRIDE;
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SignalQuery(uint32 query,
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           const base::Closure& callback) OVERRIDE;
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetSurfaceVisible(bool visible) OVERRIDE;
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Echo(const base::Closure& callback) OVERRIDE;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  class SyncClientImpl;
76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // CommandBufferClient implementation:
7823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void DidDestroy() OVERRIDE;
7923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual void LostContext(int32_t lost_reason) OVERRIDE;
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // ErrorHandler implementation:
820de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  virtual void OnConnectionError() OVERRIDE;
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void TryUpdateState();
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void MakeProgressAndUpdateState();
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
87c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  gpu::CommandBufferSharedState* shared_state() const { return shared_state_; }
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CommandBufferDelegate* delegate_;
900de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)  CommandBufferPtr command_buffer_;
91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<SyncClientImpl> sync_client_impl_;
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  State last_state_;
94c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  mojo::ScopedSharedBufferHandle shared_state_handle_;
95c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  gpu::CommandBufferSharedState* shared_state_;
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int32 last_put_offset_;
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int32 next_transfer_buffer_id_;
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
99f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const MojoAsyncWaiter* async_waiter_;
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // gles2
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // mojo
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // MOJO_GLES2_COMMAND_BUFFER_CLIENT_IMPL_H_
106