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_DEVICE_CONTEXT_2D_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" |
11 #include "third_party/ppapi/c/ppb_device_context_2d.h" | 12 #include "third_party/ppapi/c/ppb_device_context_2d.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" |
13 #include "webkit/glue/plugins/pepper_resource.h" | 14 #include "webkit/glue/plugins/pepper_resource.h" |
14 | 15 |
15 typedef struct _ppb_DeviceContext2D PPB_DeviceContext2D; | 16 typedef struct _ppb_DeviceContext2D PPB_DeviceContext2D; |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
18 class Rect; | 19 class Rect; |
19 } | 20 } |
20 | 21 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 class FlushCallbackData { | 73 class FlushCallbackData { |
73 public: | 74 public: |
74 FlushCallbackData(PPB_DeviceContext2D_FlushCallback c, void* d); | 75 FlushCallbackData(PPB_DeviceContext2D_FlushCallback c, void* d); |
75 | 76 |
76 void Execute(PP_Resource device_context); | 77 void Execute(PP_Resource device_context); |
77 | 78 |
78 private: | 79 private: |
79 PPB_DeviceContext2D_FlushCallback callback_; | 80 PPB_DeviceContext2D_FlushCallback callback_; |
80 void* callback_data_; | 81 void* callback_data_; |
81 }; | 82 }; |
82 typedef std::vector<FlushCallbackData> FlushCallbackVector; | |
83 | 83 |
84 // Called internally to execute the different queued commands. The | 84 // Called internally to execute the different queued commands. The |
85 // parameters to these functions will have already been validated. The last | 85 // parameters to these functions will have already been validated. The last |
86 // rect argument will be filled by each function with the area affected by | 86 // rect argument will be filled by each function with the area affected by |
87 // the update that requires invalidation. If there were no pixels changed, | 87 // the update that requires invalidation. If there were no pixels changed, |
88 // this rect can be untouched. | 88 // this rect can be untouched. |
89 void ExecutePaintImageData(ImageData* image, | 89 void ExecutePaintImageData(ImageData* image, |
90 int x, int y, | 90 int x, int y, |
91 const gfx::Rect& src_rect, | 91 const gfx::Rect& src_rect, |
92 gfx::Rect* invalidated_rect); | 92 gfx::Rect* invalidated_rect); |
93 void ExecuteScroll(const gfx::Rect& clip, int dx, int dy, | 93 void ExecuteScroll(const gfx::Rect& clip, int dx, int dy, |
94 gfx::Rect* invalidated_rect); | 94 gfx::Rect* invalidated_rect); |
95 void ExecuteReplaceContents(ImageData* image, | 95 void ExecuteReplaceContents(ImageData* image, |
96 gfx::Rect* invalidated_rect); | 96 gfx::Rect* invalidated_rect); |
97 | 97 |
98 // Schedules the offscreen callback to be fired at a future time. This | 98 // Schedules the offscreen callback to be fired at a future time. This |
99 // will add the given item to the offscreen_flush_callbacks_ vector. | 99 // will add the given item to the offscreen_flush_callbacks_ vector. |
100 void ScheduleOffscreenCallback(const FlushCallbackData& callback); | 100 void ScheduleOffscreenCallback(const FlushCallbackData& callback); |
101 | 101 |
102 // Function scheduled to execute by ScheduleOffscreenCallback that actually | 102 // Function scheduled to execute by ScheduleOffscreenCallback that actually |
103 // issues the offscreen callbacks. | 103 // issues the offscreen callbacks. |
104 void ExecuteOffscreenCallback(FlushCallbackData data); | 104 void ExecuteOffscreenCallback(FlushCallbackData data); |
105 | 105 |
| 106 // Returns true if there is any type of flush callback pending. |
| 107 bool HasPendingFlush() const; |
| 108 |
106 scoped_refptr<ImageData> image_data_; | 109 scoped_refptr<ImageData> image_data_; |
107 | 110 |
108 // Non-owning pointer to the plugin instance this device context is currently | 111 // Non-owning pointer to the plugin instance this device context is currently |
109 // bound to, if any. If the device context is currently unbound, this will | 112 // bound to, if any. If the device context is currently unbound, this will |
110 // be NULL. | 113 // be NULL. |
111 PluginInstance* bound_instance_; | 114 PluginInstance* bound_instance_; |
112 | 115 |
113 // Keeps track of all drawing commands queued before a Flush call. | 116 // Keeps track of all drawing commands queued before a Flush call. |
114 struct QueuedOperation; | 117 struct QueuedOperation; |
115 typedef std::vector<QueuedOperation> OperationQueue; | 118 typedef std::vector<QueuedOperation> OperationQueue; |
116 OperationQueue queued_operations_; | 119 OperationQueue queued_operations_; |
117 | 120 |
118 // Indicates whether any changes have been flushed to the backing store. | 121 // Indicates whether any changes have been flushed to the backing store. |
119 // This is initially false and is set to true at the first Flush() call. | 122 // This is initially false and is set to true at the first Flush() call. |
120 bool flushed_any_data_; | 123 bool flushed_any_data_; |
121 | 124 |
122 // The plugin may be constantly giving us paint messages. "Unpainted" ones | 125 // The plugin can give us one "Flush" at a time. This flush will either be in |
123 // are paint requests which have never been painted. These could have been | 126 // the "unpainted" state (in which case unpainted_flush_callback_ will be |
124 // done while the RenderView was already waiting for an ACK from a previous | 127 // non-NULL) or painted, in which case painted_flush_callback_ will be |
125 // paint, so won't generate a new one yet. | 128 // non-NULL). There can also be an offscreen callback which is handled |
| 129 // separately (see offscreen_callback_pending_). Only one of these three |
| 130 // things may be set at a time to enforce the "only one pending flush at a |
| 131 // time" constraint. |
126 // | 132 // |
127 // "Painted" ones are those paints that have been painted by RenderView, but | 133 // "Unpainted" ones are flush requests which have never been painted. These |
| 134 // could have been done while the RenderView was already waiting for an ACK |
| 135 // from a previous paint, so won't generate a new one yet. |
| 136 // |
| 137 // "Painted" ones are those flushes that have been painted by RenderView, but |
128 // for which the ACK from the browser has not yet been received. | 138 // for which the ACK from the browser has not yet been received. |
129 // | 139 // |
130 // When we get updates from a plugin with a callback, it is first added to | 140 // When we get updates from a plugin with a callback, it is first added to |
131 // the unpainted callbacks. When the renderer has initiated a paint, we'll | 141 // the unpainted callbacks. When the renderer has initiated a paint, we'll |
132 // move it to the painted callbacks list. When the renderer receives a flush, | 142 // move it to the painted callbacks list. When the renderer receives a flush, |
133 // we'll execute the callback and remove it from the list. | 143 // we'll execute the callback and remove it from the list. |
134 FlushCallbackVector unpainted_flush_callbacks_; | 144 scoped_ptr<FlushCallbackData> unpainted_flush_callback_; |
135 FlushCallbackVector painted_flush_callbacks_; | 145 scoped_ptr<FlushCallbackData> painted_flush_callback_; |
| 146 |
| 147 // When doing offscreen flushes, we issue a task that issues the callback |
| 148 // later. This is set when one of those tasks is pending so that we can |
| 149 // enforce the "only one pending flush at a time" constraint in the API. |
| 150 bool offscreen_flush_pending_; |
136 | 151 |
137 DISALLOW_COPY_AND_ASSIGN(DeviceContext2D); | 152 DISALLOW_COPY_AND_ASSIGN(DeviceContext2D); |
138 }; | 153 }; |
139 | 154 |
140 } // namespace pepper | 155 } // namespace pepper |
141 | 156 |
142 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ | 157 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ |
OLD | NEW |