OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_PPB_GRAPHICS_2D_PROXY_H_ | 5 #ifndef PPAPI_PPB_GRAPHICS_2D_PROXY_H_ |
6 #define PPAPI_PPB_GRAPHICS_2D_PROXY_H_ | 6 #define PPAPI_PPB_GRAPHICS_2D_PROXY_H_ |
7 | 7 |
8 #include "ppapi/c/pp_bool.h" | 8 #include "ppapi/c/pp_bool.h" |
9 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
10 #include "ppapi/c/pp_module.h" | 10 #include "ppapi/c/pp_module.h" |
11 #include "ppapi/c/pp_module.h" | 11 #include "ppapi/c/pp_module.h" |
12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/pp_size.h" | 13 #include "ppapi/c/pp_size.h" |
14 #include "ppapi/c/pp_var.h" | 14 #include "ppapi/c/pp_var.h" |
15 #include "ppapi/cpp/completion_callback.h" | 15 #include "ppapi/cpp/completion_callback.h" |
16 #include "ppapi/proxy/host_resource.h" | 16 #include "ppapi/proxy/host_resource.h" |
17 #include "ppapi/proxy/interface_proxy.h" | 17 #include "ppapi/proxy/interface_proxy.h" |
18 #include "ppapi/proxy/plugin_resource.h" | 18 #include "ppapi/proxy/plugin_resource.h" |
19 #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" | 19 #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" |
20 #include "ppapi/thunk/ppb_graphics_2d_api.h" | |
21 | 20 |
22 struct PPB_Graphics2D; | 21 struct PPB_Graphics2D; |
23 struct PP_Point; | 22 struct PP_Point; |
24 struct PP_Rect; | 23 struct PP_Rect; |
25 | 24 |
26 namespace pp { | 25 namespace pp { |
27 namespace proxy { | 26 namespace proxy { |
28 | 27 |
29 class PPB_Graphics2D_Proxy : public InterfaceProxy { | 28 class PPB_Graphics2D_Proxy : public InterfaceProxy { |
30 public: | 29 public: |
31 PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface); | 30 PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface); |
32 virtual ~PPB_Graphics2D_Proxy(); | 31 virtual ~PPB_Graphics2D_Proxy(); |
33 | 32 |
34 static const Info* GetInfo(); | 33 static const Info* GetInfo(); |
35 | 34 |
| 35 static PP_Resource CreateProxyResource(PP_Instance instance, |
| 36 const PP_Size& size, |
| 37 PP_Bool is_always_opaque); |
| 38 |
36 const PPB_Graphics2D* ppb_graphics_2d_target() const { | 39 const PPB_Graphics2D* ppb_graphics_2d_target() const { |
37 return static_cast<const PPB_Graphics2D*>(target_interface()); | 40 return static_cast<const PPB_Graphics2D*>(target_interface()); |
38 } | 41 } |
39 | 42 |
40 // InterfaceProxy implementation. | 43 // InterfaceProxy implementation. |
41 virtual bool OnMessageReceived(const IPC::Message& msg); | 44 virtual bool OnMessageReceived(const IPC::Message& msg); |
42 | 45 |
43 private: | 46 private: |
44 // Plugin->renderer message handlers. | 47 // Plugin->renderer message handlers. |
45 void OnMsgPaintImageData(const HostResource& graphics_2d, | 48 void OnMsgPaintImageData(const HostResource& graphics_2d, |
(...skipping 14 matching lines...) Expand all Loading... |
60 int32_t pp_error); | 63 int32_t pp_error); |
61 | 64 |
62 // Called in the renderer to send the given flush ACK to the plugin. | 65 // Called in the renderer to send the given flush ACK to the plugin. |
63 void SendFlushACKToPlugin(int32_t result, | 66 void SendFlushACKToPlugin(int32_t result, |
64 const HostResource& graphics_2d); | 67 const HostResource& graphics_2d); |
65 | 68 |
66 CompletionCallbackFactory<PPB_Graphics2D_Proxy, | 69 CompletionCallbackFactory<PPB_Graphics2D_Proxy, |
67 ProxyNonThreadSafeRefCount> callback_factory_; | 70 ProxyNonThreadSafeRefCount> callback_factory_; |
68 }; | 71 }; |
69 | 72 |
70 class Graphics2D : public PluginResource, | |
71 public ::ppapi::thunk::PPB_Graphics2D_API { | |
72 public: | |
73 Graphics2D(const HostResource& host_resource, | |
74 const PP_Size& size, | |
75 PP_Bool is_always_opaque) | |
76 : PluginResource(host_resource), | |
77 size_(size), | |
78 is_always_opaque_(is_always_opaque), | |
79 current_flush_callback_(PP_BlockUntilComplete()) { | |
80 } | |
81 virtual ~Graphics2D() { | |
82 } | |
83 | |
84 // Resource overrides. | |
85 virtual Graphics2D* AsGraphics2D() { return this; } | |
86 | |
87 const PP_Size& size() const { return size_; } | |
88 PP_Bool is_always_opaque() const { return is_always_opaque_; } | |
89 | |
90 bool is_flush_pending() const { return !!current_flush_callback_.func; } | |
91 | |
92 PP_CompletionCallback current_flush_callback() const { | |
93 return current_flush_callback_; | |
94 } | |
95 void set_current_flush_callback(PP_CompletionCallback cb) { | |
96 current_flush_callback_ = cb; | |
97 } | |
98 | |
99 // ResourceObjectBase. | |
100 virtual PPB_Graphics2D_API* AsGraphics2D_API(); | |
101 | |
102 // PPB_Graphics_2D_API. | |
103 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); | |
104 void PaintImageData(PP_Resource image_data, | |
105 const PP_Point* top_left, | |
106 const PP_Rect* src_rect); | |
107 void Scroll(const PP_Rect* clip_rect, | |
108 const PP_Point* amount); | |
109 void ReplaceContents(PP_Resource image_data); | |
110 int32_t Flush(PP_CompletionCallback callback); | |
111 | |
112 private: | |
113 PP_Size size_; | |
114 PP_Bool is_always_opaque_; | |
115 | |
116 // In the plugin, this is the current callback set for Flushes. When the | |
117 // callback function pointer is non-NULL, we're waiting for a flush ACK. | |
118 PP_CompletionCallback current_flush_callback_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | |
121 }; | |
122 | |
123 | |
124 } // namespace proxy | 73 } // namespace proxy |
125 } // namespace pp | 74 } // namespace pp |
126 | 75 |
127 #endif // PPAPI_PPB_GRAPHICS_2D_PROXY_H_ | 76 #endif // PPAPI_PPB_GRAPHICS_2D_PROXY_H_ |
OLD | NEW |