blob: a805af0b131ba6bab6747d0b660db3f9d2ab13e2 [file] [log] [blame]
[email protected]12dbac942011-04-01 18:20:421// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f56279c2011-02-02 18:12:312// 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_PPB_SURFACE_3D_PROXY_H_
6#define PPAPI_PPB_SURFACE_3D_PROXY_H_
7
8#include <vector>
9
10#include "ppapi/c/dev/pp_graphics_3d_dev.h"
11#include "ppapi/c/pp_completion_callback.h"
12#include "ppapi/c/pp_instance.h"
13#include "ppapi/cpp/completion_callback.h"
14#include "ppapi/proxy/interface_proxy.h"
15#include "ppapi/proxy/plugin_resource.h"
16#include "ppapi/proxy/proxy_non_thread_safe_ref_count.h"
17
18struct PPB_Surface3D_Dev;
19
20namespace pp {
21namespace proxy {
22
23class Context3D;
24
25class Surface3D : public PluginResource {
26 public:
27 explicit Surface3D(const HostResource& host_resource)
28 : PluginResource(host_resource),
29 resource_(0),
30 context_(NULL),
31 current_flush_callback_(PP_BlockUntilComplete()) {
32 }
[email protected]12dbac942011-04-01 18:20:4233 virtual ~Surface3D();
[email protected]f56279c2011-02-02 18:12:3134
35 // Resource overrides.
36 virtual Surface3D* AsSurface3D() { return this; }
37
38 bool is_flush_pending() const { return !!current_flush_callback_.func; }
39
40 PP_CompletionCallback current_flush_callback() const {
41 return current_flush_callback_;
42 }
43
44 void set_current_flush_callback(PP_CompletionCallback cb) {
45 current_flush_callback_ = cb;
46 }
47
48 void set_context(Context3D* context) {
49 context_ = context;
50 }
51
52 Context3D* context() const { return context_; }
53
54 void set_resource(PP_Resource resource) { resource_ = resource; }
55 PP_Resource resource() const { return resource_; }
56
57 private:
58 PP_Resource resource_;
59 Context3D* context_;
60 // In the plugin, this is the current callback set for Flushes. When the
61 // callback function pointer is non-NULL, we're waiting for a flush ACK.
62 PP_CompletionCallback current_flush_callback_;
63
64 DISALLOW_COPY_AND_ASSIGN(Surface3D);
65};
66
67class PPB_Surface3D_Proxy : public InterfaceProxy {
68 public:
69 PPB_Surface3D_Proxy(Dispatcher* dispatcher, const void* target_interface);
70 virtual ~PPB_Surface3D_Proxy();
71
[email protected]465faa22011-02-08 16:31:4672 static const Info* GetInfo();
73
[email protected]f56279c2011-02-02 18:12:3174 const PPB_Surface3D_Dev* ppb_surface_3d_target() const {
75 return reinterpret_cast<const PPB_Surface3D_Dev*>(target_interface());
76 }
77
78 // InterfaceProxy implementation.
[email protected]f56279c2011-02-02 18:12:3179 virtual bool OnMessageReceived(const IPC::Message& msg);
80
81 private:
82 // Message handlers.
83 void OnMsgCreate(PP_Instance instance,
84 PP_Config3D_Dev config,
85 std::vector<int32_t> attribs,
86 HostResource* result);
87 void OnMsgSwapBuffers(const HostResource& surface);
88 // Renderer->plugin message handlers.
89 void OnMsgSwapBuffersACK(const HostResource& surface, int32_t pp_error);
90
91 void SendSwapBuffersACKToPlugin(int32_t result,
92 const HostResource& surface_3d);
93
94 CompletionCallbackFactory<PPB_Surface3D_Proxy,
95 ProxyNonThreadSafeRefCount> callback_factory_;
96};
97
98} // namespace proxy
99} // namespace pp
100
101#endif // PPAPI_PPB_SURFACE_3D_PROXY_H_