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