• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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.
4 
5 #ifndef PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
6 #define PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
7 
8 #include "base/callback.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "gpu/command_buffer/client/gpu_control.h"
12 #include "gpu/command_buffer/common/command_buffer.h"
13 #include "gpu/command_buffer/common/command_buffer_shared.h"
14 #include "ppapi/proxy/ppapi_proxy_export.h"
15 #include "ppapi/shared_impl/host_resource.h"
16 
17 namespace IPC {
18 class Message;
19 }
20 
21 namespace ppapi {
22 namespace proxy {
23 
24 class ProxyChannel;
25 class SerializedHandle;
26 
27 class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer,
28                                                    public gpu::GpuControl {
29  public:
30   PpapiCommandBufferProxy(const HostResource& resource,
31                           ProxyChannel* channel,
32                           const SerializedHandle& shared_state);
33   virtual ~PpapiCommandBufferProxy();
34 
35   // gpu::CommandBuffer implementation:
36   virtual bool Initialize() OVERRIDE;
37   virtual State GetLastState() OVERRIDE;
38   virtual int32 GetLastToken() OVERRIDE;
39   virtual void Flush(int32 put_offset) OVERRIDE;
40   virtual void WaitForTokenInRange(int32 start, int32 end) OVERRIDE;
41   virtual void WaitForGetOffsetInRange(int32 start, int32 end) OVERRIDE;
42   virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE;
43   virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
44                                                           int32* id) OVERRIDE;
45   virtual void DestroyTransferBuffer(int32 id) OVERRIDE;
46 
47   // gpu::GpuControl implementation:
48   virtual gpu::Capabilities GetCapabilities() OVERRIDE;
49   virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
50                                                       size_t height,
51                                                       unsigned internalformat,
52                                                       unsigned usage,
53                                                       int32* id) OVERRIDE;
54   virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
55   virtual uint32 InsertSyncPoint() OVERRIDE;
56   virtual uint32 InsertFutureSyncPoint() OVERRIDE;
57   virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE;
58   virtual void SignalSyncPoint(uint32 sync_point,
59                                const base::Closure& callback) OVERRIDE;
60   virtual void SignalQuery(uint32 query,
61                            const base::Closure& callback) OVERRIDE;
62   virtual void SetSurfaceVisible(bool visible) OVERRIDE;
63   virtual void Echo(const base::Closure& callback) OVERRIDE;
64   virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
65 
66  private:
67   bool Send(IPC::Message* msg);
68   void UpdateState(const gpu::CommandBuffer::State& state, bool success);
69 
70   // Try to read an updated copy of the state from shared memory.
71   void TryUpdateState();
72 
73   // The shared memory area used to update state.
74   gpu::CommandBufferSharedState* shared_state() const;
75 
76   State last_state_;
77   scoped_ptr<base::SharedMemory> shared_state_shm_;
78 
79   HostResource resource_;
80   ProxyChannel* channel_;
81 
82   base::Closure channel_error_callback_;
83 
84   DISALLOW_COPY_AND_ASSIGN(PpapiCommandBufferProxy);
85 };
86 
87 }  // namespace proxy
88 }  // namespace ppapi
89 
90 #endif // PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_
91