OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_2D_IMPL_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_2D_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "ppapi/c/pp_completion_callback.h" | 11 #include "ppapi/c/pp_completion_callback.h" |
12 #include "ppapi/c/ppb_graphics_2d.h" | 12 #include "ppapi/c/ppb_graphics_2d.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" |
14 #include "webkit/glue/plugins/pepper_resource.h" | 14 #include "webkit/plugins/ppapi/resource.h" |
15 | 15 |
16 struct PPB_Graphics2D; | 16 struct PPB_Graphics2D; |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 class Rect; | 19 class Rect; |
20 } | 20 } |
21 | 21 |
22 namespace pepper { | 22 namespace webkit { |
| 23 namespace plugins { |
| 24 namespace ppapi { |
23 | 25 |
24 class ImageData; | 26 class PPB_ImageData_Impl; |
25 class PluginInstance; | 27 class PluginInstance; |
26 class PluginModule; | 28 class PluginModule; |
27 | 29 |
28 class Graphics2D : public Resource { | 30 class PPB_Graphics2D_Impl : public Resource { |
29 public: | 31 public: |
30 Graphics2D(PluginModule* module); | 32 PPB_Graphics2D_Impl(PluginModule* module); |
31 virtual ~Graphics2D(); | 33 virtual ~PPB_Graphics2D_Impl(); |
32 | 34 |
33 // Returns a pointer to the interface implementing PPB_ImageData that is | 35 // Returns a pointer to the interface implementing PPB_ImageData that is |
34 // exposed to the plugin. | 36 // exposed to the plugin. |
35 static const PPB_Graphics2D* GetInterface(); | 37 static const PPB_Graphics2D* GetInterface(); |
36 | 38 |
37 bool Init(int width, int height, bool is_always_opaque); | 39 bool Init(int width, int height, bool is_always_opaque); |
38 | 40 |
39 bool is_always_opaque() const { return is_always_opaque_; } | 41 bool is_always_opaque() const { return is_always_opaque_; } |
40 | 42 |
41 // Resource override. | 43 // Resource override. |
42 virtual Graphics2D* AsGraphics2D() { return this; } | 44 virtual PPB_Graphics2D_Impl* AsGraphics2D(); |
43 | 45 |
44 // PPB_Graphics2D functions. | 46 // PPB_Graphics2D functions. |
45 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); | 47 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); |
46 void PaintImageData(PP_Resource image_data, | 48 void PaintImageData(PP_Resource image_data, |
47 const PP_Point* top_left, | 49 const PP_Point* top_left, |
48 const PP_Rect* src_rect); | 50 const PP_Rect* src_rect); |
49 void Scroll(const PP_Rect* clip_rect, const PP_Point* amount); | 51 void Scroll(const PP_Rect* clip_rect, const PP_Point* amount); |
50 void ReplaceContents(PP_Resource image_data); | 52 void ReplaceContents(PP_Resource image_data); |
51 int32_t Flush(const PP_CompletionCallback& callback); | 53 int32_t Flush(const PP_CompletionCallback& callback); |
52 | 54 |
53 bool ReadImageData(PP_Resource image, const PP_Point* top_left); | 55 bool ReadImageData(PP_Resource image, const PP_Point* top_left); |
54 | 56 |
55 // Assciates this device with the given plugin instance. You can pass NULL to | 57 // Assciates this device with the given plugin instance. You can pass NULL to |
56 // clear the existing device. Returns true on success. In this case, a | 58 // clear the existing device. Returns true on success. In this case, a |
57 // repaint of the page will also be scheduled. Failure means that the device | 59 // repaint of the page will also be scheduled. Failure means that the device |
58 // is already bound to a different instance, and nothing will happen. | 60 // is already bound to a different instance, and nothing will happen. |
59 bool BindToInstance(PluginInstance* new_instance); | 61 bool BindToInstance(PluginInstance* new_instance); |
60 | 62 |
61 // Paints the current backing store to the web page. | 63 // Paints the current backing store to the web page. |
62 void Paint(WebKit::WebCanvas* canvas, | 64 void Paint(WebKit::WebCanvas* canvas, |
63 const gfx::Rect& plugin_rect, | 65 const gfx::Rect& plugin_rect, |
64 const gfx::Rect& paint_rect); | 66 const gfx::Rect& paint_rect); |
65 | 67 |
66 // Notifications that the view has rendered the page and that it has been | 68 // Notifications that the view has rendered the page and that it has been |
67 // flushed to the screen. These messages are used to send Flush callbacks to | 69 // flushed to the screen. These messages are used to send Flush callbacks to |
68 // the plugin. See | 70 // the plugin. See |
69 void ViewInitiatedPaint(); | 71 void ViewInitiatedPaint(); |
70 void ViewFlushedPaint(); | 72 void ViewFlushedPaint(); |
71 | 73 |
72 ImageData* image_data() { return image_data_.get(); } | 74 PPB_ImageData_Impl* image_data() { return image_data_.get(); } |
73 | 75 |
74 private: | 76 private: |
75 // Tracks a call to flush that requires a callback. | 77 // Tracks a call to flush that requires a callback. |
76 class FlushCallbackData { | 78 class FlushCallbackData { |
77 public: | 79 public: |
78 FlushCallbackData() { | 80 FlushCallbackData() { |
79 Clear(); | 81 Clear(); |
80 } | 82 } |
81 | 83 |
82 FlushCallbackData(const PP_CompletionCallback& callback) { | 84 FlushCallbackData(const PP_CompletionCallback& callback) { |
(...skipping 16 matching lines...) Expand all Loading... |
99 | 101 |
100 private: | 102 private: |
101 PP_CompletionCallback callback_; | 103 PP_CompletionCallback callback_; |
102 }; | 104 }; |
103 | 105 |
104 // Called internally to execute the different queued commands. The | 106 // Called internally to execute the different queued commands. The |
105 // parameters to these functions will have already been validated. The last | 107 // parameters to these functions will have already been validated. The last |
106 // rect argument will be filled by each function with the area affected by | 108 // rect argument will be filled by each function with the area affected by |
107 // the update that requires invalidation. If there were no pixels changed, | 109 // the update that requires invalidation. If there were no pixels changed, |
108 // this rect can be untouched. | 110 // this rect can be untouched. |
109 void ExecutePaintImageData(ImageData* image, | 111 void ExecutePaintImageData(PPB_ImageData_Impl* image, |
110 int x, int y, | 112 int x, int y, |
111 const gfx::Rect& src_rect, | 113 const gfx::Rect& src_rect, |
112 gfx::Rect* invalidated_rect); | 114 gfx::Rect* invalidated_rect); |
113 void ExecuteScroll(const gfx::Rect& clip, int dx, int dy, | 115 void ExecuteScroll(const gfx::Rect& clip, int dx, int dy, |
114 gfx::Rect* invalidated_rect); | 116 gfx::Rect* invalidated_rect); |
115 void ExecuteReplaceContents(ImageData* image, | 117 void ExecuteReplaceContents(PPB_ImageData_Impl* image, |
116 gfx::Rect* invalidated_rect); | 118 gfx::Rect* invalidated_rect); |
117 | 119 |
118 // Schedules the offscreen callback to be fired at a future time. This | 120 // Schedules the offscreen callback to be fired at a future time. This |
119 // will add the given item to the offscreen_flush_callbacks_ vector. | 121 // will add the given item to the offscreen_flush_callbacks_ vector. |
120 void ScheduleOffscreenCallback(const FlushCallbackData& callback); | 122 void ScheduleOffscreenCallback(const FlushCallbackData& callback); |
121 | 123 |
122 // Function scheduled to execute by ScheduleOffscreenCallback that actually | 124 // Function scheduled to execute by ScheduleOffscreenCallback that actually |
123 // issues the offscreen callbacks. | 125 // issues the offscreen callbacks. |
124 void ExecuteOffscreenCallback(FlushCallbackData data); | 126 void ExecuteOffscreenCallback(FlushCallbackData data); |
125 | 127 |
126 // Returns true if there is any type of flush callback pending. | 128 // Returns true if there is any type of flush callback pending. |
127 bool HasPendingFlush() const; | 129 bool HasPendingFlush() const; |
128 | 130 |
129 scoped_refptr<ImageData> image_data_; | 131 scoped_refptr<PPB_ImageData_Impl> image_data_; |
130 | 132 |
131 // Non-owning pointer to the plugin instance this context is currently bound | 133 // Non-owning pointer to the plugin instance this context is currently bound |
132 // to, if any. If the context is currently unbound, this will be NULL. | 134 // to, if any. If the context is currently unbound, this will be NULL. |
133 PluginInstance* bound_instance_; | 135 PluginInstance* bound_instance_; |
134 | 136 |
135 // Keeps track of all drawing commands queued before a Flush call. | 137 // Keeps track of all drawing commands queued before a Flush call. |
136 struct QueuedOperation; | 138 struct QueuedOperation; |
137 typedef std::vector<QueuedOperation> OperationQueue; | 139 typedef std::vector<QueuedOperation> OperationQueue; |
138 OperationQueue queued_operations_; | 140 OperationQueue queued_operations_; |
139 | 141 |
(...skipping 25 matching lines...) Expand all Loading... |
165 | 167 |
166 // When doing offscreen flushes, we issue a task that issues the callback | 168 // When doing offscreen flushes, we issue a task that issues the callback |
167 // later. This is set when one of those tasks is pending so that we can | 169 // later. This is set when one of those tasks is pending so that we can |
168 // enforce the "only one pending flush at a time" constraint in the API. | 170 // enforce the "only one pending flush at a time" constraint in the API. |
169 bool offscreen_flush_pending_; | 171 bool offscreen_flush_pending_; |
170 | 172 |
171 // Set to true if the plugin declares that this device will always be opaque. | 173 // Set to true if the plugin declares that this device will always be opaque. |
172 // This allows us to do more optimized painting in some cases. | 174 // This allows us to do more optimized painting in some cases. |
173 bool is_always_opaque_; | 175 bool is_always_opaque_; |
174 | 176 |
175 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | 177 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics2D_Impl); |
176 }; | 178 }; |
177 | 179 |
178 } // namespace pepper | 180 } // namespace ppapi |
| 181 } // namespace plugins |
| 182 } // namespace webkit |
179 | 183 |
180 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_ | 184 #endif // WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_2D_IMPL_H_ |
OLD | NEW |