Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: webkit/glue/plugins/pepper_graphics_2d.h

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "ppapi/c/pp_completion_callback.h"
12 #include "ppapi/c/ppb_graphics_2d.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h"
14 #include "webkit/glue/plugins/pepper_resource.h"
15
16 struct PPB_Graphics2D;
17
18 namespace gfx {
19 class Rect;
20 }
21
22 namespace pepper {
23
24 class ImageData;
25 class PluginInstance;
26 class PluginModule;
27
28 class Graphics2D : public Resource {
29 public:
30 Graphics2D(PluginModule* module);
31 virtual ~Graphics2D();
32
33 // Returns a pointer to the interface implementing PPB_ImageData that is
34 // exposed to the plugin.
35 static const PPB_Graphics2D* GetInterface();
36
37 bool Init(int width, int height, bool is_always_opaque);
38
39 bool is_always_opaque() const { return is_always_opaque_; }
40
41 // Resource override.
42 virtual Graphics2D* AsGraphics2D();
43
44 // PPB_Graphics2D functions.
45 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque);
46 void PaintImageData(PP_Resource image_data,
47 const PP_Point* top_left,
48 const PP_Rect* src_rect);
49 void Scroll(const PP_Rect* clip_rect, const PP_Point* amount);
50 void ReplaceContents(PP_Resource image_data);
51 int32_t Flush(const PP_CompletionCallback& callback);
52
53 bool ReadImageData(PP_Resource image, const PP_Point* top_left);
54
55 // 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
57 // 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.
59 bool BindToInstance(PluginInstance* new_instance);
60
61 // Paints the current backing store to the web page.
62 void Paint(WebKit::WebCanvas* canvas,
63 const gfx::Rect& plugin_rect,
64 const gfx::Rect& paint_rect);
65
66 // 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
68 // the plugin. See
69 void ViewInitiatedPaint();
70 void ViewFlushedPaint();
71
72 ImageData* image_data() { return image_data_.get(); }
73
74 private:
75 // Tracks a call to flush that requires a callback.
76 class FlushCallbackData {
77 public:
78 FlushCallbackData() {
79 Clear();
80 }
81
82 FlushCallbackData(const PP_CompletionCallback& callback) {
83 Set(callback);
84 }
85
86 bool is_null() const { return !callback_.func; }
87
88 void Set(const PP_CompletionCallback& callback) {
89 callback_ = callback;
90 }
91
92 void Clear() {
93 callback_ = PP_MakeCompletionCallback(NULL, 0);
94 }
95
96 void Execute(int32_t result) {
97 PP_RunCompletionCallback(&callback_, result);
98 }
99
100 private:
101 PP_CompletionCallback callback_;
102 };
103
104 // Called internally to execute the different queued commands. The
105 // 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
107 // the update that requires invalidation. If there were no pixels changed,
108 // this rect can be untouched.
109 void ExecutePaintImageData(ImageData* image,
110 int x, int y,
111 const gfx::Rect& src_rect,
112 gfx::Rect* invalidated_rect);
113 void ExecuteScroll(const gfx::Rect& clip, int dx, int dy,
114 gfx::Rect* invalidated_rect);
115 void ExecuteReplaceContents(ImageData* image,
116 gfx::Rect* invalidated_rect);
117
118 // Schedules the offscreen callback to be fired at a future time. This
119 // will add the given item to the offscreen_flush_callbacks_ vector.
120 void ScheduleOffscreenCallback(const FlushCallbackData& callback);
121
122 // Function scheduled to execute by ScheduleOffscreenCallback that actually
123 // issues the offscreen callbacks.
124 void ExecuteOffscreenCallback(FlushCallbackData data);
125
126 // Returns true if there is any type of flush callback pending.
127 bool HasPendingFlush() const;
128
129 scoped_refptr<ImageData> image_data_;
130
131 // 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.
133 PluginInstance* bound_instance_;
134
135 // Keeps track of all drawing commands queued before a Flush call.
136 struct QueuedOperation;
137 typedef std::vector<QueuedOperation> OperationQueue;
138 OperationQueue queued_operations_;
139
140 // Indicates whether any changes have been flushed to the backing store.
141 // This is initially false and is set to true at the first Flush() call.
142 bool flushed_any_data_;
143
144 // The plugin can give us one "Flush" at a time. This flush will either be in
145 // the "unpainted" state (in which case unpainted_flush_callback_ will be
146 // non-NULL) or painted, in which case painted_flush_callback_ will be
147 // non-NULL). There can also be an offscreen callback which is handled
148 // separately (see offscreen_callback_pending_). Only one of these three
149 // things may be set at a time to enforce the "only one pending flush at a
150 // time" constraint.
151 //
152 // "Unpainted" ones are flush requests which have never been painted. These
153 // could have been done while the RenderView was already waiting for an ACK
154 // from a previous paint, so won't generate a new one yet.
155 //
156 // "Painted" ones are those flushes that have been painted by RenderView, but
157 // for which the ACK from the browser has not yet been received.
158 //
159 // When we get updates from a plugin with a callback, it is first added to
160 // the unpainted callbacks. When the renderer has initiated a paint, we'll
161 // move it to the painted callbacks list. When the renderer receives a flush,
162 // we'll execute the callback and remove it from the list.
163 FlushCallbackData unpainted_flush_callback_;
164 FlushCallbackData painted_flush_callback_;
165
166 // 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
168 // enforce the "only one pending flush at a time" constraint in the API.
169 bool offscreen_flush_pending_;
170
171 // 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.
173 bool is_always_opaque_;
174
175 DISALLOW_COPY_AND_ASSIGN(Graphics2D);
176 };
177
178 } // namespace pepper
179
180 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_GRAPHICS_2D_H_
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_fullscreen_container.h ('k') | webkit/glue/plugins/pepper_graphics_2d.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698