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_PPB_GRAPHICS_3D_PROXY_H_
6#define PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_
7
8#include <vector>
9
10#include "base/memory/shared_memory.h"
11#include "gpu/command_buffer/common/command_buffer.h"
12#include "ppapi/c/pp_graphics_3d.h"
13#include "ppapi/c/pp_instance.h"
14#include "ppapi/proxy/interface_proxy.h"
15#include "ppapi/proxy/ppapi_proxy_export.h"
16#include "ppapi/proxy/proxy_completion_callback_factory.h"
17#include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
18#include "ppapi/shared_impl/resource.h"
19#include "ppapi/utility/completion_callback_factory.h"
20
21namespace ppapi {
22
23class HostResource;
24
25namespace proxy {
26
27class SerializedHandle;
28class PpapiCommandBufferProxy;
29
30class PPAPI_PROXY_EXPORT Graphics3D : public PPB_Graphics3D_Shared {
31 public:
32  explicit Graphics3D(const HostResource& resource);
33  virtual ~Graphics3D();
34
35  bool Init(gpu::gles2::GLES2Implementation* share_gles2,
36            const SerializedHandle& shared_state);
37
38  // Graphics3DTrusted API. These are not implemented in the proxy.
39  virtual PP_Bool SetGetBuffer(int32_t shm_id) OVERRIDE;
40  virtual PP_Bool Flush(int32_t put_offset) OVERRIDE;
41  virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
42                                                          int32* id) OVERRIDE;
43  virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE;
44  virtual gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
45                                                        int32_t end) OVERRIDE;
46  virtual gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start,
47                                                            int32_t end)
48      OVERRIDE;
49  virtual uint32_t InsertSyncPoint() OVERRIDE;
50  virtual uint32_t InsertFutureSyncPoint() OVERRIDE;
51  virtual void RetireSyncPoint(uint32_t sync_point) OVERRIDE;
52
53 private:
54  // PPB_Graphics3D_Shared overrides.
55  virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
56  virtual gpu::GpuControl* GetGpuControl() OVERRIDE;
57  virtual int32 DoSwapBuffers() OVERRIDE;
58
59  scoped_ptr<PpapiCommandBufferProxy> command_buffer_;
60
61  DISALLOW_COPY_AND_ASSIGN(Graphics3D);
62};
63
64class PPB_Graphics3D_Proxy : public InterfaceProxy {
65 public:
66  PPB_Graphics3D_Proxy(Dispatcher* dispatcher);
67  virtual ~PPB_Graphics3D_Proxy();
68
69  static PP_Resource CreateProxyResource(
70      PP_Instance instance,
71      PP_Resource share_context,
72      const int32_t* attrib_list);
73
74  // InterfaceProxy implementation.
75  virtual bool OnMessageReceived(const IPC::Message& msg);
76
77  static const ApiID kApiID = API_ID_PPB_GRAPHICS_3D;
78
79 private:
80  void OnMsgCreate(PP_Instance instance,
81                   HostResource share_context,
82                   const std::vector<int32_t>& attribs,
83                   HostResource* result,
84                   SerializedHandle* handle);
85  void OnMsgSetGetBuffer(const HostResource& context,
86                         int32 id);
87  void OnMsgWaitForTokenInRange(const HostResource& context,
88                                int32 start,
89                                int32 end,
90                                gpu::CommandBuffer::State* state,
91                                bool* success);
92  void OnMsgWaitForGetOffsetInRange(const HostResource& context,
93                                    int32 start,
94                                    int32 end,
95                                    gpu::CommandBuffer::State* state,
96                                    bool* success);
97  void OnMsgAsyncFlush(const HostResource& context, int32 put_offset);
98  void OnMsgCreateTransferBuffer(
99      const HostResource& context,
100      uint32 size,
101      int32* id,
102      ppapi::proxy::SerializedHandle* transfer_buffer);
103  void OnMsgDestroyTransferBuffer(const HostResource& context,
104                                  int32 id);
105  void OnMsgSwapBuffers(const HostResource& context);
106  void OnMsgInsertSyncPoint(const HostResource& context, uint32* sync_point);
107  void OnMsgInsertFutureSyncPoint(const HostResource& context,
108                                  uint32* sync_point);
109  void OnMsgRetireSyncPoint(const HostResource& context, uint32 sync_point);
110  // Renderer->plugin message handlers.
111  void OnMsgSwapBuffersACK(const HostResource& context,
112                           int32_t pp_error);
113
114  void SendSwapBuffersACKToPlugin(int32_t result,
115                                  const HostResource& context);
116
117  ProxyCompletionCallbackFactory<PPB_Graphics3D_Proxy> callback_factory_;
118
119  DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Proxy);
120};
121
122}  // namespace proxy
123}  // namespace ppapi
124
125#endif  // PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_
126
127