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.
5 #ifndef PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_
6 #define PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_
10 #include "base/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/proxy/serialized_structs.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"
27 class Graphics3D
: public PPB_Graphics3D_Shared
{
29 explicit Graphics3D(const HostResource
& resource
);
30 virtual ~Graphics3D();
32 bool Init(gpu::gles2::GLES2Implementation
* share_gles2
);
34 // Graphics3DTrusted API. These are not implemented in the proxy.
35 virtual PP_Bool
InitCommandBuffer() OVERRIDE
;
36 virtual PP_Bool
SetGetBuffer(int32_t shm_id
) OVERRIDE
;
37 virtual PP_Graphics3DTrustedState
GetState() OVERRIDE
;
38 virtual PP_Bool
Flush(int32_t put_offset
) OVERRIDE
;
39 virtual PP_Graphics3DTrustedState
FlushSync(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
,
44 uint32_t* shm_size
) OVERRIDE
;
45 virtual PP_Graphics3DTrustedState
FlushSyncFast(
47 int32_t last_known_get
) OVERRIDE
;
50 class LockingCommandBuffer
;
52 // PPB_Graphics3D_Shared overrides.
53 virtual gpu::CommandBuffer
* GetCommandBuffer() OVERRIDE
;
54 virtual int32
DoSwapBuffers() OVERRIDE
;
55 virtual void PushAlreadyLocked() OVERRIDE
;
56 virtual void PopAlreadyLocked() OVERRIDE
;
58 int num_already_locked_calls_
;
59 scoped_ptr
<gpu::CommandBuffer
> command_buffer_
;
60 scoped_ptr
<LockingCommandBuffer
> locking_command_buffer_
;
62 DISALLOW_COPY_AND_ASSIGN(Graphics3D
);
65 class PPB_Graphics3D_Proxy
: public InterfaceProxy
{
67 PPB_Graphics3D_Proxy(Dispatcher
* dispatcher
);
68 virtual ~PPB_Graphics3D_Proxy();
70 static PP_Resource
CreateProxyResource(
72 PP_Resource share_context
,
73 const int32_t* attrib_list
);
75 // InterfaceProxy implementation.
76 virtual bool OnMessageReceived(const IPC::Message
& msg
);
78 static const ApiID kApiID
= API_ID_PPB_GRAPHICS_3D
;
81 void OnMsgCreate(PP_Instance instance
,
82 HostResource share_context
,
83 const std::vector
<int32_t>& attribs
,
84 HostResource
* result
);
85 void OnMsgInitCommandBuffer(const HostResource
& context
);
86 void OnMsgSetGetBuffer(const HostResource
& context
,
88 void OnMsgGetState(const HostResource
& context
,
89 gpu::CommandBuffer::State
* state
,
91 void OnMsgFlush(const HostResource
& context
,
94 gpu::CommandBuffer::State
* state
,
96 void OnMsgAsyncFlush(const HostResource
& context
,
98 void OnMsgCreateTransferBuffer(const HostResource
& context
,
101 void OnMsgDestroyTransferBuffer(const HostResource
& context
,
103 void OnMsgGetTransferBuffer(const HostResource
& context
,
105 ppapi::proxy::SerializedHandle
* transfer_buffer
);
106 void OnMsgSwapBuffers(const HostResource
& context
);
107 // Renderer->plugin message handlers.
108 void OnMsgSwapBuffersACK(const HostResource
& context
,
111 void SendSwapBuffersACKToPlugin(int32_t result
,
112 const HostResource
& context
);
114 ProxyCompletionCallbackFactory
<PPB_Graphics3D_Proxy
> callback_factory_
;
116 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Proxy
);
122 #endif // PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_