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

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
« no previous file with comments | « ppapi/c/ppb_core.h ('k') | ppapi/c/ppb_image_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17:25:38 Nice catch below, but it's still missing on line 1
jond 2011/07/05 17:30:32 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 a larger
94 * representing your entire plugin. In this case, you would set the location 117 * bitmap representing your entire module. In this case, you would set the
dmichael (off chromium) 2011/07/05 17:25:38 module->instance
jond 2011/07/05 17:30:32 Done.
95 * of your image to (0,0) and then set src_rect to the pixels you changed. 118 * location of your image to (0,0) and then set <code>src_rect</code> to the
119 * pixels you changed.
120 *
121 * @param[in] resource The 2D Graphics resource.
122 * @param[in] image The <code>ImageData</code> to be painted.
123 * @param[in] top_left A <code>Point</code> representing the
124 * <code>top_left</code> location where the <code>ImageData</code> will be
125 * painted.
126 * @param[in] src_rect The rectangular area where the <code>ImageData</code>
127 * will be painted.
96 */ 128 */
97 void (*PaintImageData)(PP_Resource graphics_2d, 129 void (*PaintImageData)(PP_Resource graphics_2d,
98 PP_Resource image_data, 130 PP_Resource image_data,
99 const struct PP_Point* top_left, 131 const struct PP_Point* top_left,
100 const struct PP_Rect* src_rect); 132 const struct PP_Rect* src_rect);
101 133
102 /** 134 /**
103 * Enqueues a scroll of the context's backing store. THIS HAS NO EFFECT UNTIL 135 * 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 136 * 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. 137 * provided clipping rectangle will be shifted by (dx, dy) pixels.
106 * 138 *
107 * This will result in some exposed region which will have undefined 139 * This function will result in some exposed region which will have undefined
108 * contents. The plugin should call PaintImageData on these exposed regions 140 * contents. The module should call PaintImageData() on these exposed regions
109 * to give the correct contents. 141 * to give the correct contents.
110 * 142 *
111 * The scroll can be larger than the area of the clip rect, which means the 143 * 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 144 * means the current image will be scrolled out of the rectangle. This
113 * will be a no-op. 145 * scenario is not an error but will result in a no-op.
146 *
147 * @param[in] graphics_2d The 2D Graphics resource.
148 * @param[in] clip The clipping rectangle.
149 * @param[in] amount The amount the area in the clipping rectangle will
150 * shifted.
114 */ 151 */
115 void (*Scroll)(PP_Resource graphics_2d, 152 void (*Scroll)(PP_Resource graphics_2d,
116 const struct PP_Rect* clip_rect, 153 const struct PP_Rect* clip_rect,
117 const struct PP_Point* amount); 154 const struct PP_Point* amount);
118 155
119 /** 156 /**
120 * This function provides a slightly more efficient way to paint the entire 157 * ReplaceContents() provides a slightly more efficient way to paint the
121 * plugin's image. Normally, calling PaintImageData requires that the browser 158 * entire module's image. Normally, calling PaintImageData() requires that
122 * copy the pixels out of the image and into the graphics context's backing 159 * 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 160 * context's backing store. This function replaces the graphics context's
124 * given image, avoiding the copy. 161 * backing store with the given image, avoiding the copy.
125 * 162 *
126 * The new image must be the exact same size as this graphics context. If the 163 * 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 164 * new image uses a different image format than the browser's native bitmap
128 * format (use PPB_ImageData.GetNativeImageDataFormat to retrieve this), then 165 * format (use <code>PPB_ImageData.GetNativeImageDataFormat()</code> to
129 * a conversion will be done inside the browser which may slow the performance 166 * retrieve the format), then a conversion will be done inside the browser
130 * a little bit. 167 * which may slow the performance a little bit.
131 * 168 *
132 * THE NEW IMAGE WILL NOT BE PAINTED UNTIL YOU CALL FLUSH. 169 * <strong>Note:</strong> The new image will not be painted until you call
170 * Flush().
133 * 171 *
134 * After this call, you should take care to release your references to the 172 * 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 173 * image. If you paint to the image after ReplaceContents(), there is the
136 * possibility of significant painting artifacts because the page might use 174 * possibility of significant painting artifacts because the page might use
137 * partially-rendered data when copying out of the backing store. 175 * partially-rendered data when copying out of the backing store.
138 * 176 *
139 * In the case of an animation, you will want to allocate a new image for the 177 * 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 178 * 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 179 * before allocating this bitmap. This gives the browser the option of
142 * caching the previous backing store and handing it back to you (assuming 180 * 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 181 * 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 182 * during the animation, and the backing store and "front buffer" (which the
145 * plugin is painting into) are just being swapped back and forth. 183 * plugin is painting into) are just being swapped back and forth.
184 *
185 * @param[in] graphics_2d The 2D Graphics resource.
186 * @param[in] image The <code>ImageData</code> to be painted.
146 */ 187 */
147 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data); 188 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data);
148 189
149 /** 190 /**
150 * Flushes any enqueued paint, scroll, and replace commands for the backing 191 * Flush() flushes any enqueued paint, scroll, and replace commands to the
151 * store. This actually executes the updates, and causes a repaint of the 192 * backing store. This function actually executes the updates, and causes a
152 * webpage, assuming this graphics context is bound to a plugin instance. This 193 * repaint of the webpage, assuming this graphics context is bound to a module
153 * can run in two modes: 194 * instance.
154 * 195 *
155 * - In synchronous mode, you specify NULL for the callback and the callback 196 * Flush() runs in asynchronous mode. Specify a callback function and the
156 * data. This function will block the calling thread until the image has 197 * 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 198 * 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. 199 * screen. While you are waiting for a flush callback, additional calls to
159 * 200 * 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 * 201 *
166 * Because the callback is executed (or thread unblocked) only when the 202 * 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 203 * instance's image is actually on the screen, this function provides
168 * way to rate limit animations. By waiting until the image is on the screen 204 * 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 205 * screen before painting the next frame, you can ensure you're not
170 * updates faster than the screen can be updated. 206 * flushing 2D graphics faster than the screen can be updated.
171 * 207 *
172 * <dl> 208 * <strong>Unbound contexts</strong>
173 * <dt>Unbound contexts</dt> 209 * If the context is not bound to a module instance, you will
174 * <dd> 210 * still get a callback. The callback will execute after Flush() returns
175 * If the context is not bound to a plugin instance, you will 211 * to avoid reentrancy. The callback will not wait until anything is
176 * still get a callback. It will execute after the Flush function returns 212 * 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 213 * 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 214 * 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 * 215 *
183 * <dt>Off-screen instances</dt> 216 * <strong>Off-screen instances</strong>
184 * <dd> 217 * 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 218 * 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 219 * case.
187 * like the "unbound context" case.
188 * </dd>
189 * 220 *
190 * <dt>Detaching a context</dt> 221 * <strong>Detaching a context</strong>
191 * <dd> 222 * If you detach a context from a module instance, any pending flush
192 * If you detach a context from a plugin instance, any 223 * 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 * 224 *
197 * <dt>Released contexts</dt> 225 * <strong>Released contexts</strong>
198 * <dd> 226 * 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 227 * 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 228 * internal references to the context suggesting it has not been internally
201 * references to the context that means it has not been internally 229 * 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 230 * other implementation details. As a result, you should be careful to
203 * other implementation details. As a result, you should be careful to 231 * 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 232 * 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 * 233 *
209 * <dt>Shutdown</dt> 234 * <strong>Shutdown</strong>
210 * <dd> 235 * 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 236 * callback will not be executed.
212 * callback will not be executed.
213 * </dd>
214 * </dl>
215 * 237 *
216 * Returns PP_OK on success, PP_Error_BadResource if the graphics context is 238 * @param[in] graphics_2d The 2D Graphics resource.
217 * invalid, PP_Error_BadArgument if the callback is null and Flush is being 239 * @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 240 * the image has been painted on the screen.
219 * Flush is already pending that has not issued its callback yet. In the 241 *
220 * failure case, nothing will be updated and no callback will be scheduled. 242 * @return Returns <code>PP_OK</code> on success or
243 * <code>PP_Error_BadResource</code> if the graphics context is invalid,
244 * <code>PP_Error_BadArgument</code> if the callback is null and flush is
245 * being called from the main thread of the module, or
246 * <code>PP_Error_InProgress</code> if a flush is already pending that has
247 * not issued its callback yet. In the failure case, nothing will be updated
248 * and no callback will be scheduled.
221 */ 249 */
222 /* TODO(darin): We should ensure that the completion callback always runs, so 250
251 /*
252 * 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. 253 * that it is easier for consumers to manage memory referenced by a callback.
224 */ 254 */
255
256 /*
257 * TODO(): Add back in the synchronous mode description once we have support
258 * for it.
259 */
225 int32_t (*Flush)(PP_Resource graphics_2d, 260 int32_t (*Flush)(PP_Resource graphics_2d,
226 struct PP_CompletionCallback callback); 261 struct PP_CompletionCallback callback);
227 262
228 }; 263 };
229 264
230 /** 265 /**
231 * @} 266 * @}
232 */ 267 */
233 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */ 268 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */
OLDNEW
« no previous file with comments | « 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