| OLD | NEW |
| 1 /* Copyright (c) 2010 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_3 "PPB_Graphics2D;0.3" | 19 #define PPB_GRAPHICS_2D_INTERFACE_0_3 "PPB_Graphics2D;0.3" |
| 20 #define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_0_3 | 20 #define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_0_3 |
| 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 * The <code>PPB_Graphics2D</code> structure represents 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 |
| 34 * creation (call BindGraphics on the plugin instance to do that). | 37 * returned graphics context will not be bound to the module instance on |
| 38 * creation (call BindGraphics() on the module instance bind the returned |
| 39 * graphics context to the module 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 * true you know that you will be painting only opaque data to this context. |
| 45 * This option will disable blending when compositing the module with the web |
| 46 * page, which will give slightly higher performance. |
| 39 * | 47 * |
| 40 * If you set is_always_opaque, your alpha channel should always be set to | 48 * 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 | 49 * be set to 0xFF or there may be painting artifacts. Setting this option to |
| 42 * browser to do a memcpy rather than a blend to paint the plugin, and this | 50 * true will allow the browser to do a memcpy rather than a blend to paint |
| 43 * means your alpha values will get set on the page backing store. If these | 51 * the module, and this means your alpha values will get set on the page |
| 44 * values are incorrect, it could mess up future blending. | 52 * backing store. Incorrect values could negitively affect future |
| 53 * blending. |
| 45 * | 54 * |
| 46 * If you aren't sure, it is always correct to specify that it it not opaque. | 55 * If you are not sure if the data is opaque, set this flag to false (not |
| 56 * opaque). |
| 57 * |
| 58 * @return A <code>PP_Resource</code> containing the 2D graphics context if |
| 59 * successful or 0 if unsuccessful. |
| 47 */ | 60 */ |
| 48 PP_Resource (*Create)(PP_Instance instance, | 61 PP_Resource (*Create)(PP_Instance instance, |
| 49 const struct PP_Size* size, | 62 const struct PP_Size* size, |
| 50 PP_Bool is_always_opaque); | 63 PP_Bool is_always_opaque); |
| 51 | 64 |
| 52 /** | 65 /** |
| 53 * Returns PP_TRUE if the given resource is a valid Graphics2D, PP_FALSE if it | 66 * IsGraphics2D() determines if the given resource is a valid |
| 54 * is an invalid resource or is a resource of another type. | 67 * <code>Graphics2D</code>. |
| 68 * |
| 69 * @param[in] resource A <code>Graphics2D</code> context resource. |
| 70 * |
| 71 * @return PP_TRUE if the given resource is a valid <code>Graphics2D</code>, |
| 72 * <code>PP_FALSE</code> if it is an invalid resource or is a resource of |
| 73 * another type. |
| 55 */ | 74 */ |
| 56 PP_Bool (*IsGraphics2D)(PP_Resource resource); | 75 PP_Bool (*IsGraphics2D)(PP_Resource resource); |
| 57 | 76 |
| 58 /** | 77 /** |
| 59 * Retrieves the configuration for the given graphics context, filling the | 78 * Describe() retrieves the configuration for the given graphics context, |
| 60 * given values (which must not be NULL). On success, returns PP_TRUE. If the | 79 * 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 | 80 * |
| 62 * return PP_FALSE. | 81 * @param[in,out] resource The 2D Graphics resource. |
| 82 * @param[in,out] size The size of the 2D graphics context in the browser. |
| 83 * @param[in,out] is_always_opaque Identifies whether only opaque data |
| 84 * will be painted. |
| 85 * |
| 86 * @return Returns <code>PP_TRUE</code> on succes or <code>PP_FALSE</code> if |
| 87 * the resource is invalid. The output parameters will be set to 0 on a |
| 88 * <code>PP_FALSE</code>. |
| 63 */ | 89 */ |
| 64 PP_Bool (*Describe)(PP_Resource graphics_2d, | 90 PP_Bool (*Describe)(PP_Resource graphics_2d, |
| 65 struct PP_Size* size, | 91 struct PP_Size* size, |
| 66 PP_Bool* is_always_opqaue); | 92 PP_Bool* is_always_opqaue); |
| 67 | 93 |
| 68 /** | 94 /** |
| 69 * Enqueues a paint of the given image into the context. THIS HAS NO EFFECT | 95 * PaintImageData() is a pointer to a function that enqueues a paint of the |
| 70 * UNTIL YOU CALL Flush(). As a result, what counts is the contents of the | 96 * given image into the context. This function has |
| 71 * bitmap when you call Flush, not when you call this function. | 97 * no effect until you call Flush() As a result, what counts is the contents |
| 98 * of the bitmap when you call Flush(), not when you call this function. |
| 72 * | 99 * |
| 73 * The given image will be placed at |top_left| from the top left of the | 100 * The given image will be placed at <code>top_left</code> from the top left |
| 74 * context's internal backing store. Then the src_rect will be copied into the | 101 * of the context's internal backing store. Then the <code>src_rect</code> |
| 75 * backing store. This parameter may not be NULL. This means that the | 102 * will be copied into the backing store. This parameter may not be |
| 76 * rectangle being painted will be at src_rect offset by top_left. | 103 * <code>NULL</code>. This means that the rectangle being painted will be at |
| 104 * <code>src_rect</code> offset by <code>top_left</code>. |
| 77 * | 105 * |
| 78 * The src_rect is specified in the coordinate system of the image being | 106 * 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, | 107 * 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 | 108 * entire image, you may specify a <code>NULL</code> <code>src_rect</code> |
| 81 * the entire image, consider using ReplaceContents which will give slightly | 109 * pointer. If you are frequently updating the entire image, consider using |
| 82 * higher performance. | 110 * <code>ReplaceContents</code> which will give slightly higher performance. |
| 83 * | 111 * |
| 84 * The painted area of the source bitmap must fall entirely within the | 112 * 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 | 113 * 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 | 114 * 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. | 115 * as the <code>src_rect</code> subset of it falls entirely within the |
| 116 * context. |
| 88 * | 117 * |
| 89 * There are two modes most plugins may use for painting. The first is | 118 * There are two modes most plugins may use for painting. The first is |
| 90 * that you will generate a new ImageData (possibly representing a subset of | 119 * that you will generate a new <code>ImageData</code> (possibly representing |
| 91 * your plugin) and then paint it. In this case, you'll set the location of | 120 * a subset of your module) and then paint it. In this case, you'll set the |
| 92 * your painting to top_left and set src_rect to NULL. The second is that | 121 * location of your painting to <code>top_left</code> and set |
| 93 * you're generating small invalid regions out of a larger bitmap | 122 * <code>src_rect</code> to <code>NULL</code>. The second is that you're |
| 94 * representing your entire plugin. In this case, you would set the location | 123 * generating small invalid regions out of a larger bitmap representing your |
| 95 * of your image to (0,0) and then set src_rect to the pixels you changed. | 124 * entire module. In this case, you would set the location of your image to |
| 125 * (0,0) and then set <code>src_rect</code> to the pixels you changed. |
| 126 * |
| 127 * @param[in] resource The 2D Graphics resource. |
| 128 * @param[in] image The <code>ImageData</code> to be painted. |
| 129 * @param[in] top_left A <code>Point</code> representing the |
| 130 * <code>top_left</code> location where the <code>ImageData</code> will be |
| 131 * painted. |
| 132 * @param[in] src_rect The rectangular area where the <code>ImageData</code> |
| 133 * will be painted. |
| 96 */ | 134 */ |
| 97 void (*PaintImageData)(PP_Resource graphics_2d, | 135 void (*PaintImageData)(PP_Resource graphics_2d, |
| 98 PP_Resource image_data, | 136 PP_Resource image_data, |
| 99 const struct PP_Point* top_left, | 137 const struct PP_Point* top_left, |
| 100 const struct PP_Rect* src_rect); | 138 const struct PP_Rect* src_rect); |
| 101 | 139 |
| 102 /** | 140 /** |
| 103 * Enqueues a scroll of the context's backing store. THIS HAS NO EFFECT UNTIL | 141 * Scroll() enqueues a scroll of the context's backing store. This function |
| 104 * YOU CALL Flush(). The data within the given clip rect (you may specify | 142 * has no effect until you call Flush(). The data within the provided |
| 105 * NULL to scroll the entire region) will be shifted by (dx, dy) pixels. | 143 * clipping rectangle (you may specify <code>NULL</code> to scroll the entire |
| 144 * region) will be shifted by (dx, dy) pixels. |
| 106 * | 145 * |
| 107 * This will result in some exposed region which will have undefined | 146 * This function will result in some exposed region which will have undefined |
| 108 * contents. The plugin should call PaintImageData on these exposed regions | 147 * contents. The module should call PaintImageData() on these exposed regions |
| 109 * to give the correct contents. | 148 * to give the correct contents. |
| 110 * | 149 * |
| 111 * The scroll can be larger than the area of the clip rect, which means the | 150 * 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 | 151 * means the current image will be scrolled out of the rectangle. This |
| 113 * will be a no-op. | 152 * scenario is not an error but will result in a no-op. |
| 153 * |
| 154 * @param[in] graphics_2d The 2D Graphics resource. |
| 155 * @param[in] clip The clipping rectangle. |
| 156 * @param[in] amount The amount the area in the clipping rectangle will |
| 157 * shifted. |
| 114 */ | 158 */ |
| 115 void (*Scroll)(PP_Resource graphics_2d, | 159 void (*Scroll)(PP_Resource graphics_2d, |
| 116 const struct PP_Rect* clip_rect, | 160 const struct PP_Rect* clip_rect, |
| 117 const struct PP_Point* amount); | 161 const struct PP_Point* amount); |
| 118 | 162 |
| 119 /** | 163 /** |
| 120 * This function provides a slightly more efficient way to paint the entire | 164 * ReplaceContents() provides a slightly more efficient way to paint the |
| 121 * plugin's image. Normally, calling PaintImageData requires that the browser | 165 * entire module's image. Normally, calling PaintImageData() requires that |
| 122 * copy the pixels out of the image and into the graphics context's backing | 166 * 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 | 167 * context's backing store. This function replaces the graphics context's |
| 124 * given image, avoiding the copy. | 168 * backing store with the given image, avoiding the copy. |
| 125 * | 169 * |
| 126 * The new image must be the exact same size as this graphics context. If the | 170 * 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 | 171 * new image uses a different image format than the browser's native bitmap |
| 128 * format (use PPB_ImageData.GetNativeImageDataFormat to retrieve this), then | 172 * format (use <code>PPB_ImageData.GetNativeImageDataFormat()</code> to |
| 129 * a conversion will be done inside the browser which may slow the performance | 173 * retrieve the format), then a conversion will be done inside the browser |
| 130 * a little bit. | 174 * which may slow the performance a little bit. |
| 131 * | 175 * |
| 132 * THE NEW IMAGE WILL NOT BE PAINTED UNTIL YOU CALL FLUSH. | 176 * The new image will not be painted until you call Flush(). |
| 133 * | 177 * |
| 134 * After this call, you should take care to release your references to the | 178 * Release your references to the image after a call to this function. |
| 135 * image. If you paint to the image after ReplaceContents, there is the | 179 * image. If you paint to the image after ReplaceContents(), there is the |
| 136 * possibility of significant painting artifacts because the page might use | 180 * possibility of significant painting artifacts because the page might use |
| 137 * partially-rendered data when copying out of the backing store. | 181 * partially-rendered data when copying out of the backing store. |
| 138 * | 182 * |
| 139 * In the case of an animation, you will want to allocate a new image for the | 183 * 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 | 184 * 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 | 185 * before allocating this bitmap. This gives the browser the option of |
| 142 * caching the previous backing store and handing it back to you (assuming | 186 * 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 | 187 * 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 | 188 * during the animation, and the backing store and "front buffer" (which the |
| 145 * plugin is painting into) are just being swapped back and forth. | 189 * plugin is painting into) are just being swapped back and forth. |
| 190 * |
| 191 * @param[in] graphics_2d The 2D Graphics resource. |
| 192 * @param[in] image The <code>ImageData</code> to be painted. |
| 146 */ | 193 */ |
| 147 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data); | 194 void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data); |
| 148 | 195 |
| 149 /** | 196 /** |
| 150 * Flushes any enqueued paint, scroll, and replace commands for the backing | 197 * Flush() flushes any enqueued paint, scroll, and replace commands for the |
| 151 * store. This actually executes the updates, and causes a repaint of the | 198 * backing store. This function actually executes the updates, and causes a |
| 152 * webpage, assuming this graphics context is bound to a plugin instance. This | 199 * repaint of the webpage, assuming this graphics context is bound to a module |
| 153 * can run in two modes: | 200 * instance. |
| 154 * | 201 * |
| 155 * - In synchronous mode, you specify NULL for the callback and the callback | 202 * Flush() runs in asynchronous mode. Specify a callback function and the |
| 156 * data. This function will block the calling thread until the image has | 203 * 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 | 204 * 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. | 205 * screen. While you are waiting for a flush callback, additional calls to |
| 159 * | 206 * 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 * | 207 * |
| 166 * Because the callback is executed (or thread unblocked) only when the | 208 * 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 | 209 * module's current state is actually on the screen, this function provides a |
| 168 * way to rate limit animations. By waiting until the image is on the screen | 210 * way to rate limit animations. By waiting until the image is on the screen |
| 169 * before painting the next frame, you can ensure you're not generating | 211 * before painting the next frame, you can ensure you're not generating |
| 170 * updates faster than the screen can be updated. | 212 * updates faster than the screen can be updated. |
| 171 * | 213 * |
| 172 * <dl> | 214 * <strong>Unbound contexts</strong> |
| 173 * <dt>Unbound contexts</dt> | 215 * If the context is not bound to a module instance, you will |
| 174 * <dd> | 216 * still get a callback. The callback will execute after Flush() returns |
| 175 * If the context is not bound to a plugin instance, you will | 217 * to avoid reentrancy. The callback will not wait until anything is |
| 176 * still get a callback. It will execute after the Flush function returns | 218 * 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 | 219 * 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 | 220 * 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 * | 221 * |
| 183 * <dt>Off-screen instances</dt> | 222 * <strong>Off-screen instances</strong> |
| 184 * <dd> | 223 * 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 | 224 * 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 | 225 * case. |
| 187 * like the "unbound context" case. | |
| 188 * </dd> | |
| 189 * | 226 * |
| 190 * <dt>Detaching a context</dt> | 227 * <strong>Detaching a context</strong> |
| 191 * <dd> | 228 * If you detach a context from a module instance, any pending flush |
| 192 * If you detach a context from a plugin instance, any | 229 * 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 * | 230 * |
| 197 * <dt>Released contexts</dt> | 231 * <strong>Released contexts</strong> |
| 198 * <dd> | 232 * 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 | 233 * 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 | 234 * internal references to the context suggesting it has not been internally |
| 201 * references to the context that means it has not been internally | 235 * 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 | 236 * other implementation details. As a result, you should be careful to |
| 203 * other implementation details. As a result, you should be careful to | 237 * 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 | 238 * 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 * | 239 * |
| 209 * <dt>Shutdown</dt> | 240 * <strong>Shutdown</strong> |
| 210 * <dd> | 241 * 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 | 242 * callback will not be executed. |
| 212 * callback will not be executed. | |
| 213 * </dd> | |
| 214 * </dl> | |
| 215 * | 243 * |
| 216 * Returns PP_OK on success, PP_Error_BadResource if the graphics context is | 244 * @param[in] graphics_2d The 2D Graphics resource. |
| 217 * invalid, PP_Error_BadArgument if the callback is null and Flush is being | 245 * @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 | 246 * the image has been painted on the screen. |
| 219 * Flush is already pending that has not issued its callback yet. In the | 247 * |
| 220 * failure case, nothing will be updated and no callback will be scheduled. | 248 * @return Returns <code>PP_OK</code> on succes or |
| 249 * <code>PP_Error_BadResource</code> the graphics context is invalid, |
| 250 * <code>PP_Error_BadArgument</code> if the callback is null and flush is |
| 251 * being called from the main thread of the module, or |
| 252 * <code>PP_Error_InProgress</code> if a flush is already pending that has |
| 253 * not issued its callback yet. In the failure case, nothing will be updated |
| 254 * and no callback will be scheduled. |
| 221 */ | 255 */ |
| 222 /* TODO(darin): We should ensure that the completion callback always runs, so | 256 |
| 257 /* |
| 258 * 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. | 259 * that it is easier for consumers to manage memory referenced by a callback. |
| 224 */ | 260 */ |
| 225 int32_t (*Flush)(PP_Resource graphics_2d, | 261 int32_t (*Flush)(PP_Resource graphics_2d, |
| 226 struct PP_CompletionCallback callback); | 262 struct PP_CompletionCallback callback); |
| 227 | 263 |
| 228 }; | 264 }; |
| 229 | 265 |
| 230 /** | 266 /** |
| 231 * @} | 267 * @} |
| 232 */ | 268 */ |
| 233 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */ | 269 #endif /* PPAPI_C_PPB_GRAPHICS_2D_H_ */ |
| 234 | 270 |
| OLD | NEW |