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

Side by Side Diff: ppapi/c/ppb_graphics_2d.h

Issue 7282015: Misc. changes. Mostly formatting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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
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_C_PPB_GRAPHICS_2D_H_ 5 #ifndef PPAPI_C_PPB_GRAPHICS_2D_H_
6 #define PPAPI_C_PPB_GRAPHICS_2D_H_ 6 #define PPAPI_C_PPB_GRAPHICS_2D_H_
7 7
8 #include "ppapi/c/pp_bool.h" 8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_module.h" 10 #include "ppapi/c/pp_module.h"
11 #include "ppapi/c/pp_resource.h" 11 #include "ppapi/c/pp_resource.h"
12 #include "ppapi/c/pp_stdint.h" 12 #include "ppapi/c/pp_stdint.h"
13 13
14 struct PP_CompletionCallback; 14 struct PP_CompletionCallback;
15 struct PP_Point; 15 struct PP_Point;
16 struct PP_Rect; 16 struct PP_Rect;
17 struct PP_Size; 17 struct PP_Size;
18 18
19 #define PPB_GRAPHICS_2D_INTERFACE_0_4 "PPB_Graphics2D;0.4" 19 #define PPB_GRAPHICS_2D_INTERFACE_0_4 "PPB_Graphics2D;0.4"
20 #define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_0_4 20 #define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_0_4
21 21
22 /** 22 /**
23 * @file 23 * @file
24 * Defines the PPB_Graphics2D struct. 24 * Defines the <code>PPB_Graphics2D</code> struct representing a 2D graphics
25 * context within the browser.
25 * 26 *
26 * @addtogroup Interfaces 27 * @addtogroup Interfaces
27 * @{ 28 * @{
28 */ 29 */
29 30
30 /** {PENDING: describe PPB_Graphics2D. */ 31 /**
32 * <code>PPB_Graphics2D</code> defines the interface for a 2D graphics context.
33 */
31 struct PPB_Graphics2D { 34 struct PPB_Graphics2D {
32 /** 35 /**
33 * The returned graphics context will not be bound to the plugin instance on 36 * Create() creates a 2D graphics context. The returned graphics context will
34 * creation (call BindGraphics on the plugin instance to do that). 37 * not be bound to the module instance on creation (call BindGraphics() on
38 * the module instance to bind the returned graphics context to the module
39 * instance).
35 * 40 *
36 * Set the is_always_opaque flag if you know that you will be painting only 41 * @param[in] instance The module instance.
37 * opaque data to this context. This will disable blending when compositing 42 * @param[in] size The size of the graphic context.
38 * the plugin with the web page, which will give slightly higher performance. 43 * @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag to
44 * <code>PP_TRUE</code> if you know that you will be painting only opaque
45 * data to this context. This option will disable blending when compositing
46 * the module with the web page, which might give higher performance on some
47 * computers.
39 * 48 *
40 * If you set is_always_opaque, your alpha channel should always be set to 49 * If you set <code>is_always_opaque</code>, your alpha channel should always
41 * 0xFF or there may be painting artifacts. Being opaque will allow the 50 * be set to 0xFF or there may be painting artifacts. The alpha values
42 * browser to do a memcpy rather than a blend to paint the plugin, and this 51 * overwrite the destination alpha values without blending when
43 * means your alpha values will get set on the page backing store. If these 52 * <code>is_always_opaque</code> is true.
44 * values are incorrect, it could mess up future blending.
45 * 53 *
46 * If you aren't sure, it is always correct to specify that it it not opaque. 54 * @return A <code>PP_Resource</code> containing the 2D graphics context if
55 * successful or 0 if unsuccessful.
47 */ 56 */
48 PP_Resource (*Create)(PP_Instance instance, 57 PP_Resource (*Create)(PP_Instance instance,
49 const struct PP_Size* size, 58 const struct PP_Size* size,
50 PP_Bool is_always_opaque); 59 PP_Bool is_always_opaque);
51 60
52 /** 61 /**
53 * Returns PP_TRUE if the given resource is a valid Graphics2D, PP_FALSE if it 62 * IsGraphics2D() determines if the given resource is a valid
54 * is an invalid resource or is a resource of another type. 63 * <code>Graphics2D</code>.
64 *
65 * @param[in] resource A <code>Graphics2D</code> context resource.
66 *
67 * @return PP_TRUE if the given resource is a valid <code>Graphics2D</code>,
68 * <code>PP_FALSE</code> if it is an invalid resource or is a resource of
69 * another type.
55 */ 70 */
56 PP_Bool (*IsGraphics2D)(PP_Resource resource); 71 PP_Bool (*IsGraphics2D)(PP_Resource resource);
57 72
58 /** 73 /**
59 * Retrieves the configuration for the given graphics context, filling the 74 * Describe() retrieves the configuration for the given graphics context,
60 * given values (which must not be NULL). On success, returns PP_TRUE. If the 75 * filling the given values (which must not be <code>NULL</code>).
61 * resource is invalid, the output parameters will be set to 0 and it will 76 *
62 * return PP_FALSE. 77 * @param[in] resource The 2D Graphics resource.
78 * @param[in,out] size The size of the 2D graphics context in the browser.
79 * @param[in,out] is_always_opaque Identifies whether only opaque data
80 * will be painted.
81 *
82 * @return Returns <code>PP_TRUE</code> on succes or <code>PP_FALSE</code> if
83 * the resource is invalid. The output parameters will be set to 0 on a
84 * <code>PP_FALSE</code>.
63 */ 85 */
64 PP_Bool (*Describe)(PP_Resource graphics_2d, 86 PP_Bool (*Describe)(PP_Resource graphics_2d,
65 struct PP_Size* size, 87 struct PP_Size* size,
66 PP_Bool* is_always_opqaue); 88 PP_Bool* is_always_opqaue);
67 89
68 /** 90 /**
69 * Enqueues a paint of the given image into the context. THIS HAS NO EFFECT 91 * PaintImageData() enqueues a paint of the given image into the context.
70 * UNTIL YOU CALL Flush(). As a result, what counts is the contents of the 92 * This function has no effect until you call Flush() As a result, what
71 * bitmap when you call Flush, not when you call this function. 93 * counts is the contents of the bitmap when you call Flush(), not when
94 * you call this function.
72 * 95 *
73 * The given image will be placed at |top_left| from the top left of the 96 * The provided image will be placed at <code>top_left</code> from the top
74 * context's internal backing store. Then the src_rect will be copied into the 97 * left of the context's internal backing store. Then the pixels contained
75 * backing store. This parameter may not be NULL. This means that the 98 * in <code>src_rect</code> will be copied into the backing store. This
76 * rectangle being painted will be at src_rect offset by top_left. 99 * means that the rectangle being painted will be at <code>src_rect</code>
100 * offset by <code>top_left/code>.
dmichael (off chromium) 2011/07/05 15:58:19 lost the '<' for your closing </code> tag
jond 2011/07/05 17:09:23 Done.
77 * 101 *
78 * The src_rect is specified in the coordinate system of the image being 102 * The <code>src_rect/code> is specified in the coordinate system of the
79 * painted, not the context. For the common case of copying the entire image, 103 * image being painted, not the context. For the common case of copying the
80 * you may specify a NULL |src_rect| pointer. If you are frequently updating 104 * entire image, you may specify an empty <code>src_rect</code>.
81 * the entire image, consider using ReplaceContents which will give slightly
82 * higher performance.
83 * 105 *
84 * The painted area of the source bitmap must fall entirely within the 106 * The painted area of the source bitmap must fall entirely within the
85 * context. Attempting to paint outside of the context will result in an 107 * context. Attempting to paint outside of the context will result in an
86 * error. However, the source bitmap may fall outside the context, as long 108 * error. However, the source bitmap may fall outside the context, as long
87 * as the src_rect subset of it falls entirely within the context. 109 * as the <code>src_rect</code> subset of it falls entirely within the
110 * context.
88 * 111 *
89 * There are two modes most plugins may use for painting. The first is 112 * There are two methods most modules will use for painting. The first
90 * that you will generate a new ImageData (possibly representing a subset of 113 * method is to generate a new <code>ImageData</code> and then paint it. In
91 * your plugin) and then paint it. In this case, you'll set the location of 114 * this case, you'll set the location of your painting to
92 * your painting to top_left and set src_rect to NULL. The second is that 115 * <code>top_left</code> and set <code>src_rect</code> to <code>NULL</code>.
93 * you're generating small invalid regions out of a larger bitmap 116 * The second is that you're generating small invalid regions out of
94 * representing your entire plugin. In this case, you would set the location 117 * a larger bitmap representing your entire module's image. The
95 * of your image to (0,0) and then set src_rect to the pixels you changed. 118 * second is that you're generating small invalid regions out of a larger
119 * bitmap representing your entire module. In this case, you would set the
dmichael (off chromium) 2011/07/05 15:58:19 Bad merge? The documentation seems to repeat itse
jond 2011/07/05 17:09:23 Done.
jond 2011/07/05 17:09:23 Done.
120 * location of your image to (0,0) and then set <code>src_rect</code> to the
121 * pixels you changed.
122 *
123 * @param[in] resource The 2D Graphics resource.
124 * @param[in] image The <code>ImageData</code> to be painted.
125 * @param[in] top_left A <code>Point</code> representing the
126 * <code>top_left</code> location where the <code>ImageData</code> will be
127 * painted.
128 * @param[in] src_rect The rectangular area where the <code>ImageData</code>
129 * will be painted.
96 */ 130 */
97 void (*PaintImageData)(PP_Resource graphics_2d, 131 void (*PaintImageData)(PP_Resource graphics_2d,
98 PP_Resource image_data, 132 PP_Resource image_data,
99 const struct PP_Point* top_left, 133 const struct PP_Point* top_left,
100 const struct PP_Rect* src_rect); 134 const struct PP_Rect* src_rect);
101 135
102 /** 136 /**
103 * Enqueues a scroll of the context's backing store. THIS HAS NO EFFECT UNTIL 137 * Scroll() enqueues a scroll of the context's backing store. This
104 * YOU CALL Flush(). The data within the given clip rect (you may specify 138 * function has no effect until you call Flush(). The data within the
105 * NULL to scroll the entire region) will be shifted by (dx, dy) pixels. 139 * provided clipping rectangle will be shifted by (dx, dy) pixels.
106 * 140 *
107 * This will result in some exposed region which will have undefined 141 * This function will result in some exposed region which will have undefined
108 * contents. The plugin should call PaintImageData on these exposed regions 142 * contents. The module should call PaintImageData() on these exposed regions
109 * to give the correct contents. 143 * to give the correct contents.
110 * 144 *
111 * The scroll can be larger than the area of the clip rect, which means the 145 * The scroll can be larger than the area of the clipping rectangle, which
112 * current image will be scrolled out of the rect. This is not an error but 146 * means the current image will be scrolled out of the rectangle. This
113 * will be a no-op. 147 * scenario is not an error but will result in a no-op.
148 *
149 * @param[in] graphics_2d The 2D Graphics resource.
150 * @param[in] clip The clipping rectangle.
151 * @param[in] amount The amount the area in the clipping rectangle will
152 * shifted.
114 */ 153 */
115 void (*Scroll)(PP_Resource graphics_2d, 154 void (*Scroll)(PP_Resource graphics_2d,
116 const struct PP_Rect* clip_rect, 155 const struct PP_Rect* clip_rect,
117 const struct PP_Point* amount); 156 const struct PP_Point* amount);
118 157
119 /** 158 /**
120 * This function provides a slightly more efficient way to paint the entire 159 * ReplaceContents() provides a slightly more efficient way to paint the
121 * plugin's image. Normally, calling PaintImageData requires that the browser 160 * entire module's image. Normally, calling PaintImageData() requires that
122 * copy the pixels out of the image and into the graphics context's backing 161 * the browser copy the pixels out of the image and into the graphics
123 * store. This function replaces the graphics context's backing store with the 162 * context's backing store. This function replaces the graphics context's
124 * given image, avoiding the copy. 163 * backing store with the given image, avoiding the copy.
125 * 164 *
126 * The new image must be the exact same size as this graphics context. If the 165 * The new image must be the exact same size as this graphics context. If the
127 * new image uses a different image format than the browser's native bitmap 166 * new image uses a different image format than the browser's native bitmap
128 * format (use PPB_ImageData.GetNativeImageDataFormat to retrieve this), then 167 * format (use <code>PPB_ImageData.GetNativeImageDataFormat()</code> to
129 * a conversion will be done inside the browser which may slow the performance 168 * retrieve the format), then a conversion will be done inside the browser
130 * a little bit. 169 * which may slow the performance a little bit.
131 * 170 *
132 * THE NEW IMAGE WILL NOT BE PAINTED UNTIL YOU CALL FLUSH. 171 * <strong>Note:</strong> The new image will not be painted until you call
172 * Flush().
133 * 173 *
134 * After this call, you should take care to release your references to the 174 * After this call, you should take care to release your references to the
135 * image. If you paint to the image after ReplaceContents, there is the 175 * image. If you paint to the image after ReplaceContents(), there is the
136 * possibility of significant painting artifacts because the page might use 176 * possibility of significant painting artifacts because the page might use
137 * partially-rendered data when copying out of the backing store. 177 * partially-rendered data when copying out of the backing store.
138 * 178 *
139 * In the case of an animation, you will want to allocate a new image for the 179 * In the case of an animation, you will want to allocate a new image for the
140 * next frame. It is best if you wait until the flush callback has executed 180 * next frame. It is best if you wait until the flush callback has executed
141 * before allocating this bitmap. This gives the browser the option of 181 * before allocating this bitmap. This gives the browser the option of
142 * caching the previous backing store and handing it back to you (assuming 182 * caching the previous backing store and handing it back to you (assuming
143 * the sizes match). In the optimal case, this means no bitmaps are allocated 183 * the sizes match). In the optimal case, this means no bitmaps are allocated
144 * during the animation, and the backing store and "front buffer" (which the 184 * during the animation, and the backing store and "front buffer" (which the
145 * plugin is painting into) are just being swapped back and forth. 185 * plugin is painting into) are just being swapped back and forth.
186 *
187 * @param[in] graphics_2d The 2D Graphics resource.
188 * @param[in] image The <code>ImageData</code> to be painted.
146 */ 189 */
147 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data); 190 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data);
148 191
149 /** 192 /**
150 * Flushes any enqueued paint, scroll, and replace commands for the backing 193 * Flush() flushes any enqueued paint, scroll, and replace commands to the
151 * store. This actually executes the updates, and causes a repaint of the 194 * backing store. This function actually executes the updates, and causes a
152 * webpage, assuming this graphics context is bound to a plugin instance. This 195 * repaint of the webpage, assuming this graphics context is bound to a module
153 * can run in two modes: 196 * instance.
154 * 197 *
155 * - In synchronous mode, you specify NULL for the callback and the callback 198 * Flush() runs in asynchronous mode. Specify a callback function and the
156 * data. This function will block the calling thread until the image has 199 * argument for that callback function. The callback function will be
157 * been painted to the screen. It is not legal to block the main thread of 200 * executed on the calling thread when the image has been painted to the
158 * the plugin, you can use synchronous mode only from background threads. 201 * screen. While you are waiting for a flush callback, additional calls to
159 * 202 * Flush() will fail.
160 * - In asynchronous mode, you specify a callback function and the argument
161 * for that callback function. The callback function will be executed on
162 * the calling thread when the image has been painted to the screen. While
163 * you are waiting for a Flush callback, additional calls to Flush will
164 * fail.
165 * 203 *
166 * Because the callback is executed (or thread unblocked) only when the 204 * Because the callback is executed (or thread unblocked) only when the
167 * plugin's current state is actually on the screen, this function provides a 205 * module's image is actually on the screen, this function provides
dmichael (off chromium) 2011/07/05 15:58:19 module->instance
jond 2011/07/05 17:09:23 Done.
jond 2011/07/05 17:09:23 Done.
168 * way to rate limit animations. By waiting until the image is on the screen 206 * a way to rate limit animations. By waiting until the image is on the
169 * before painting the next frame, you can ensure you're not generating 207 * screen before painting the next frame, you can ensure you're not
170 * updates faster than the screen can be updated. 208 * flushing 2D graphics faster than the screen can be updated.
171 * 209 *
172 * <dl> 210 * <strong>Unbound contexts</strong>
173 * <dt>Unbound contexts</dt> 211 * If the context is not bound to a module instance, you will
174 * <dd> 212 * still get a callback. The callback will execute after Flush() returns
175 * If the context is not bound to a plugin instance, you will 213 * to avoid reentrancy. The callback will not wait until anything is
176 * still get a callback. It will execute after the Flush function returns 214 * painted to the screen because there will be nothing on the screen. The
177 * to avoid reentrancy. Of course, it will not wait until anything is 215 * timing of this callback is not guaranteed and may be deprioritized by
178 * painted to the screen because there will be nothing on the screen. The 216 * the browser because it is not affecting the user experience.
179 * timing of this callback is not guaranteed and may be deprioritized by
180 * the browser because it is not affecting the user experience.
181 * </dd>
182 * 217 *
183 * <dt>Off-screen instances</dt> 218 * <strong>Off-screen instances</strong>
184 * <dd> 219 * If the context is bound to an instance that is currently not visible (for
185 * If the context is bound to an instance that is 220 * example, scrolled out of view) it will behave like the "unbound context"
186 * currently not visible (for example, scrolled out of view) it will behave 221 * case.
187 * like the "unbound context" case.
188 * </dd>
189 * 222 *
190 * <dt>Detaching a context</dt> 223 * <strong>Detaching a context</strong>
191 * <dd> 224 * If you detach a context from a module instance, any pending flush
192 * If you detach a context from a plugin instance, any 225 * callbacks will be converted into the "unbound context" case.
193 * pending flush callbacks will be converted into the "unbound context"
194 * case.
195 * </dd>
196 * 226 *
197 * <dt>Released contexts</dt> 227 * <strong>Released contexts</strong>
198 * <dd> 228 * A callback may or may not get called even if you have released all
199 * A callback may or may not still get called even if you have released all 229 * of your references to the context. This scenario can occur if there are
200 * of your references to the context. This can occur if there are internal 230 * internal references to the context suggesting it has not been internally
201 * references to the context that means it has not been internally 231 * destroyed (for example, if it is still bound to an instance) or due to
202 * destroyed (for example, if it is still bound to an instance) or due to 232 * other implementation details. As a result, you should be careful to
203 * other implementation details. As a result, you should be careful to 233 * check that flush callbacks are for the context you expect and that
204 * check that flush callbacks are for the context you expect and that 234 * you're capable of handling callbacks for unreferenced contexts.
205 * you're capable of handling callbacks for context that you may have
206 * released your reference to.
207 * </dd>
208 * 235 *
209 * <dt>Shutdown</dt> 236 * <strong>Shutdown</strong>
210 * <dd> 237 * If a module instance is removed when a flush is pending, the
211 * If a plugin instance is removed when a Flush is pending, the 238 * callback will not be executed.
212 * callback will not be executed.
213 * </dd>
214 * </dl>
215 * 239 *
216 * Returns PP_OK on success, PP_Error_BadResource if the graphics context is 240 * @param[in] graphics_2d The 2D Graphics resource.
217 * invalid, PP_Error_BadArgument if the callback is null and Flush is being 241 * @param[in] callback A <code>CompletionCallback</code> to be called when
218 * called from the main thread of the plugin, or PP_Error_InProgress if a 242 * the image has been painted on the screen.
219 * Flush is already pending that has not issued its callback yet. In the 243 *
220 * failure case, nothing will be updated and no callback will be scheduled. 244 * @return Returns <code>PP_OK</code> on success or
245 * <code>PP_Error_BadResource</code> if the graphics context is invalid,
246 * <code>PP_Error_BadArgument</code> if the callback is null and flush is
247 * being called from the main thread of the module, or
248 * <code>PP_Error_InProgress</code> if a flush is already pending that has
249 * not issued its callback yet. In the failure case, nothing will be updated
250 * and no callback will be scheduled.
221 */ 251 */
222 /* TODO(darin): We should ensure that the completion callback always runs, so 252
253 /*
254 * TODO(darin): We should ensure that the completion callback always runs, so
223 * that it is easier for consumers to manage memory referenced by a callback. 255 * that it is easier for consumers to manage memory referenced by a callback.
224 */ 256 */
257
258 /*
259 * TODO(): Add back in the synchronous mode description once we have support
260 * for it.
261 */
225 int32_t (*Flush)(PP_Resource graphics_2d, 262 int32_t (*Flush)(PP_Resource graphics_2d,
226 struct PP_CompletionCallback callback); 263 struct PP_CompletionCallback callback);
227 264
228 }; 265 };
229 266
230 /** 267 /**
231 * @} 268 * @}
232 */ 269 */
233 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */ 270 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */
OLDNEW
« ppapi/c/ppb_core.h ('K') | « ppapi/c/ppb_core.h ('k') | ppapi/c/ppb_image_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698