| 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/pp_completion_callback.h" |
| 12 #include "third_party/ppapi/c/ppb_device_context_2d.h" | 12 #include "third_party/ppapi/c/ppb_device_context_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/glue/plugins/pepper_resource.h" |
| 15 | 15 |
| 16 typedef struct _ppb_DeviceContext2D PPB_DeviceContext2D; | 16 typedef struct _ppb_DeviceContext2D PPB_DeviceContext2D; |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 class Rect; | 19 class Rect; |
| 20 } | 20 } |
| 21 | 21 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 // Resource override. | 39 // Resource override. |
| 40 virtual DeviceContext2D* AsDeviceContext2D() { return this; } | 40 virtual DeviceContext2D* AsDeviceContext2D() { return this; } |
| 41 | 41 |
| 42 // PPB_DeviceContext2D functions. | 42 // PPB_DeviceContext2D functions. |
| 43 bool Describe(int32_t* width, int32_t* height, bool* is_always_opaque); | 43 bool Describe(int32_t* width, int32_t* height, bool* is_always_opaque); |
| 44 bool PaintImageData(PP_Resource image, | 44 bool PaintImageData(PP_Resource image, |
| 45 int32_t x, int32_t y, | 45 int32_t x, int32_t y, |
| 46 const PP_Rect* src_rect); | 46 const PP_Rect* src_rect); |
| 47 bool Scroll(const PP_Rect* clip_rect, int32_t dx, int32_t dy); | 47 bool Scroll(const PP_Rect* clip_rect, int32_t dx, int32_t dy); |
| 48 bool ReplaceContents(PP_Resource image); | 48 bool ReplaceContents(PP_Resource image); |
| 49 bool Flush(PPB_DeviceContext2D_FlushCallback callback, | 49 int32_t Flush(const PP_CompletionCallback& callback); |
| 50 void* callback_data); | 50 |
| 51 bool ReadImageData(PP_Resource image, int32_t x, int32_t y); | 51 bool ReadImageData(PP_Resource image, int32_t x, int32_t y); |
| 52 | 52 |
| 53 // Assciates this device with the given plugin instance. You can pass NULL to | 53 // Assciates this device with the given plugin instance. You can pass NULL to |
| 54 // clear the existing device. Returns true on success. In this case, a | 54 // clear the existing device. Returns true on success. In this case, a |
| 55 // repaint of the page will also be scheduled. Failure means that the device | 55 // repaint of the page will also be scheduled. Failure means that the device |
| 56 // is already bound to a different instance, and nothing will happen. | 56 // is already bound to a different instance, and nothing will happen. |
| 57 bool BindToInstance(PluginInstance* new_instance); | 57 bool BindToInstance(PluginInstance* new_instance); |
| 58 | 58 |
| 59 // Paints the current backing store to the web page. | 59 // Paints the current backing store to the web page. |
| 60 void Paint(WebKit::WebCanvas* canvas, | 60 void Paint(WebKit::WebCanvas* canvas, |
| 61 const gfx::Rect& plugin_rect, | 61 const gfx::Rect& plugin_rect, |
| 62 const gfx::Rect& paint_rect); | 62 const gfx::Rect& paint_rect); |
| 63 | 63 |
| 64 // Notifications that the view has rendered the page and that it has been | 64 // Notifications that the view has rendered the page and that it has been |
| 65 // flushed to the screen. These messages are used to send Flush callbacks to | 65 // flushed to the screen. These messages are used to send Flush callbacks to |
| 66 // the plugin. See | 66 // the plugin. See |
| 67 void ViewInitiatedPaint(); | 67 void ViewInitiatedPaint(); |
| 68 void ViewFlushedPaint(); | 68 void ViewFlushedPaint(); |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 // Tracks a call to flush that requires a callback. | 71 // Tracks a call to flush that requires a callback. |
| 72 // See unpainted_flush_callbacks_ below. | |
| 73 class FlushCallbackData { | 72 class FlushCallbackData { |
| 74 public: | 73 public: |
| 75 FlushCallbackData(PPB_DeviceContext2D_FlushCallback c, void* d); | 74 FlushCallbackData() { |
| 75 Clear(); |
| 76 } |
| 76 | 77 |
| 77 void Execute(PP_Resource device_context); | 78 FlushCallbackData(const PP_CompletionCallback& callback) { |
| 79 Set(callback); |
| 80 } |
| 81 |
| 82 bool is_null() const { return !callback_.func; } |
| 83 |
| 84 void Set(const PP_CompletionCallback& callback) { |
| 85 callback_ = callback; |
| 86 } |
| 87 |
| 88 void Clear() { |
| 89 callback_ = PP_MakeCompletionCallback(NULL, 0); |
| 90 } |
| 91 |
| 92 void Execute(int32_t result) { |
| 93 PP_RunCompletionCallback(&callback_, result); |
| 94 } |
| 78 | 95 |
| 79 private: | 96 private: |
| 80 PPB_DeviceContext2D_FlushCallback callback_; | 97 PP_CompletionCallback callback_; |
| 81 void* callback_data_; | |
| 82 }; | 98 }; |
| 83 | 99 |
| 84 // Called internally to execute the different queued commands. The | 100 // Called internally to execute the different queued commands. The |
| 85 // parameters to these functions will have already been validated. The last | 101 // 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 | 102 // 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, | 103 // the update that requires invalidation. If there were no pixels changed, |
| 88 // this rect can be untouched. | 104 // this rect can be untouched. |
| 89 void ExecutePaintImageData(ImageData* image, | 105 void ExecutePaintImageData(ImageData* image, |
| 90 int x, int y, | 106 int x, int y, |
| 91 const gfx::Rect& src_rect, | 107 const gfx::Rect& src_rect, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // could have been done while the RenderView was already waiting for an ACK | 150 // 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. | 151 // from a previous paint, so won't generate a new one yet. |
| 136 // | 152 // |
| 137 // "Painted" ones are those flushes that have been painted by RenderView, but | 153 // "Painted" ones are those flushes that have been painted by RenderView, but |
| 138 // for which the ACK from the browser has not yet been received. | 154 // for which the ACK from the browser has not yet been received. |
| 139 // | 155 // |
| 140 // When we get updates from a plugin with a callback, it is first added to | 156 // When we get updates from a plugin with a callback, it is first added to |
| 141 // the unpainted callbacks. When the renderer has initiated a paint, we'll | 157 // the unpainted callbacks. When the renderer has initiated a paint, we'll |
| 142 // move it to the painted callbacks list. When the renderer receives a flush, | 158 // move it to the painted callbacks list. When the renderer receives a flush, |
| 143 // we'll execute the callback and remove it from the list. | 159 // we'll execute the callback and remove it from the list. |
| 144 scoped_ptr<FlushCallbackData> unpainted_flush_callback_; | 160 FlushCallbackData unpainted_flush_callback_; |
| 145 scoped_ptr<FlushCallbackData> painted_flush_callback_; | 161 FlushCallbackData painted_flush_callback_; |
| 146 | 162 |
| 147 // When doing offscreen flushes, we issue a task that issues the callback | 163 // 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 | 164 // 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. | 165 // enforce the "only one pending flush at a time" constraint in the API. |
| 150 bool offscreen_flush_pending_; | 166 bool offscreen_flush_pending_; |
| 151 | 167 |
| 152 DISALLOW_COPY_AND_ASSIGN(DeviceContext2D); | 168 DISALLOW_COPY_AND_ASSIGN(DeviceContext2D); |
| 153 }; | 169 }; |
| 154 | 170 |
| 155 } // namespace pepper | 171 } // namespace pepper |
| 156 | 172 |
| 157 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ | 173 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_2D_H_ |
| OLD | NEW |