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" |
20 | 21 |
21 struct PPB_Graphics2D; | 22 struct PPB_Graphics2D; |
22 struct PP_Point; | 23 struct PP_Point; |
23 struct PP_Rect; | 24 struct PP_Rect; |
24 | 25 |
25 namespace pp { | 26 namespace pp { |
26 namespace proxy { | 27 namespace proxy { |
27 | 28 |
28 class PPB_Graphics2D_Proxy : public InterfaceProxy { | 29 class PPB_Graphics2D_Proxy : public InterfaceProxy { |
29 public: | 30 public: |
30 PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface); | 31 PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface); |
31 virtual ~PPB_Graphics2D_Proxy(); | 32 virtual ~PPB_Graphics2D_Proxy(); |
32 | 33 |
33 static const Info* GetInfo(); | 34 static const Info* GetInfo(); |
34 | 35 |
35 static PP_Resource CreateProxyResource(PP_Instance instance, | |
36 const PP_Size& size, | |
37 PP_Bool is_always_opaque); | |
38 | |
39 const PPB_Graphics2D* ppb_graphics_2d_target() const { | 36 const PPB_Graphics2D* ppb_graphics_2d_target() const { |
40 return static_cast<const PPB_Graphics2D*>(target_interface()); | 37 return static_cast<const PPB_Graphics2D*>(target_interface()); |
41 } | 38 } |
42 | 39 |
43 // InterfaceProxy implementation. | 40 // InterfaceProxy implementation. |
44 virtual bool OnMessageReceived(const IPC::Message& msg); | 41 virtual bool OnMessageReceived(const IPC::Message& msg); |
45 | 42 |
46 private: | 43 private: |
47 // Plugin->renderer message handlers. | 44 // Plugin->renderer message handlers. |
48 void OnMsgPaintImageData(const HostResource& graphics_2d, | 45 void OnMsgPaintImageData(const HostResource& graphics_2d, |
(...skipping 14 matching lines...) Expand all Loading... |
63 int32_t pp_error); | 60 int32_t pp_error); |
64 | 61 |
65 // Called in the renderer to send the given flush ACK to the plugin. | 62 // Called in the renderer to send the given flush ACK to the plugin. |
66 void SendFlushACKToPlugin(int32_t result, | 63 void SendFlushACKToPlugin(int32_t result, |
67 const HostResource& graphics_2d); | 64 const HostResource& graphics_2d); |
68 | 65 |
69 CompletionCallbackFactory<PPB_Graphics2D_Proxy, | 66 CompletionCallbackFactory<PPB_Graphics2D_Proxy, |
70 ProxyNonThreadSafeRefCount> callback_factory_; | 67 ProxyNonThreadSafeRefCount> callback_factory_; |
71 }; | 68 }; |
72 | 69 |
| 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 |
73 } // namespace proxy | 124 } // namespace proxy |
74 } // namespace pp | 125 } // namespace pp |
75 | 126 |
76 #endif // PPAPI_PPB_GRAPHICS_2D_PROXY_H_ | 127 #endif // PPAPI_PPB_GRAPHICS_2D_PROXY_H_ |
OLD | NEW |