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