Advertisement
Guest User

Untitled

a guest
May 17th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.87 KB | None | 0 0
  1. /* Copyright (c) 2012 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.  
  6. /* From ppb_graphics_2d.idl modified Mon Mar 19 11:35:04 2012. */
  7.  
  8. #ifndef PPAPI_C_PPB_GRAPHICS_2D_H_
  9. #define PPAPI_C_PPB_GRAPHICS_2D_H_
  10.  
  11. #include "ppapi/c/pp_bool.h"
  12. #include "ppapi/c/pp_completion_callback.h"
  13. #include "ppapi/c/pp_instance.h"
  14. #include "ppapi/c/pp_macros.h"
  15. #include "ppapi/c/pp_point.h"
  16. #include "ppapi/c/pp_rect.h"
  17. #include "ppapi/c/pp_resource.h"
  18. #include "ppapi/c/pp_size.h"
  19. #include "ppapi/c/pp_stdint.h"
  20.  
  21. #define PPB_GRAPHICS_2D_INTERFACE_1_0 "PPB_Graphics2D;1.0"
  22. #define PPB_GRAPHICS_2D_INTERFACE PPB_GRAPHICS_2D_INTERFACE_1_0
  23.  
  24. /**
  25.  * @file
  26.  * Defines the <code>PPB_Graphics2D</code> struct representing a 2D graphics
  27.  * context within the browser.
  28.  */
  29.  
  30.  
  31. /**
  32.  * @addtogroup Interfaces
  33.  * @{
  34.  */
  35. /**
  36.  * <code>PPB_Graphics2D</code> defines the interface for a 2D graphics context.
  37.  */
  38. struct PPB_Graphics2D_1_0 {
  39.   /**
  40.    * Create() creates a 2D graphics context. The returned graphics context will
  41.    * not be bound to the module instance on creation (call BindGraphics() on
  42.    * the module instance to bind the returned graphics context to the module
  43.    * instance).
  44.    *
  45.    * @param[in] instance The module instance.
  46.    * @param[in] size The size of the graphic context.
  47.    * @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag to
  48.    * <code>PP_TRUE</code> if you know that you will be painting only opaque
  49.    * data to this context. This option will disable blending when compositing
  50.    * the module with the web page, which might give higher performance on some
  51.    * computers.
  52.    *
  53.    * If you set <code>is_always_opaque</code>, your alpha channel should always
  54.    * be set to 0xFF or there may be painting artifacts. The alpha values
  55.    * overwrite the destination alpha values without blending when
  56.    * <code>is_always_opaque</code> is true.
  57.    *
  58.    * @return A <code>PP_Resource</code> containing the 2D graphics context if
  59.    * successful or 0 if unsuccessful.
  60.    */
  61.   PP_Resource (*Create)(PP_Instance instance,
  62.                         const struct PP_Size* size,
  63.                         PP_Bool is_always_opaque);
  64.   /**
  65.    * IsGraphics2D() determines if the given resource is a valid
  66.    * <code>Graphics2D</code>.
  67.    *
  68.    * @param[in] resource A <code>Graphics2D</code> context resource.
  69.    *
  70.    * @return PP_TRUE if the given resource is a valid <code>Graphics2D</code>,
  71.    * <code>PP_FALSE</code> if it is an invalid resource or is a resource of
  72.    * another type.
  73.    */
  74.   PP_Bool (*IsGraphics2D)(PP_Resource resource);
  75.   /**
  76.    * Describe() retrieves the configuration for the given graphics context,
  77.    * filling the given values (which must not be <code>NULL</code>).
  78.    *
  79.    * @param[in] resource The 2D Graphics resource.
  80.    * @param[in,out] size The size of the 2D graphics context in the browser.
  81.    * @param[in,out] is_always_opaque Identifies whether only opaque data
  82.    * will be painted.
  83.    *
  84.    * @return Returns <code>PP_TRUE</code> on succes or <code>PP_FALSE</code> if
  85.    * the resource is invalid. The output parameters will be set to 0 on a
  86.    * <code>PP_FALSE</code>.
  87.    */
  88.   PP_Bool (*Describe)(PP_Resource graphics_2d,
  89.                       struct PP_Size* size,
  90.                       PP_Bool* is_always_opqaue);
  91.   /**
  92.    * PaintImageData() enqueues a paint of the given image into the context.
  93.    * This function has no effect until you call Flush() As a result, what
  94.    * counts is the contents of the bitmap when you call Flush(), not when
  95.    * you call this function.
  96.    *
  97.    * The provided image will be placed at <code>top_left</code> from the top
  98.    *  left of the context's internal backing store. Then the pixels contained
  99.    * in <code>src_rect</code> will be copied into the backing store. This
  100.    * means that the rectangle being painted will be at <code>src_rect</code>
  101.    * offset by <code>top_left</code>.
  102.    *
  103.    * The <code>src_rect</code> is specified in the coordinate system of the
  104.    * image being painted, not the context. For the common case of copying the
  105.    * entire image, you may specify an empty <code>src_rect</code>.
  106.    *
  107.    * The painted area of the source bitmap must fall entirely within the
  108.    * context. Attempting to paint outside of the context will result in an
  109.    * error. However, the source bitmap may fall outside the context, as long
  110.    * as the <code>src_rect</code> subset of it falls entirely within the
  111.    * context.
  112.    *
  113.    * There are two methods most modules will use for painting. The first
  114.    * method is to generate a new <code>ImageData</code> and then paint it. In
  115.    * this case, you'll set the location of your painting to
  116.    * <code>top_left</code> and set <code>src_rect</code> to <code>NULL</code>.
  117.    * The second is that you're generating small invalid regions out of a larger
  118.    * bitmap representing your entire instance. In this case, you would set the
  119.    * location of your image to (0,0) and then set <code>src_rect</code> to the
  120.    * pixels you changed.
  121.    *
  122.    * @param[in] resource The 2D Graphics resource.
  123.    * @param[in] image The <code>ImageData</code> to be painted.
  124.    * @param[in] top_left A <code>Point</code> representing the
  125.    * <code>top_left</code> location where the <code>ImageData</code> will be
  126.    * painted.
  127.    * @param[in] src_rect The rectangular area where the <code>ImageData</code>
  128.    * will be painted.
  129.    */
  130.   void (*PaintImageData)(PP_Resource graphics_2d,
  131.                          PP_Resource image_data,
  132.                          const struct PP_Point* top_left,
  133.                          const struct PP_Rect* src_rect);
  134.   /**
  135.    * Scroll() enqueues a scroll of the context's backing store. This
  136.    * function has no effect until you call Flush(). The data within the
  137.    * provided clipping rectangle will be shifted by (dx, dy) pixels.
  138.    *
  139.    * This function will result in some exposed region which will have undefined
  140.    * contents. The module should call PaintImageData() on these exposed regions
  141.    * to give the correct contents.
  142.    *
  143.    * The scroll can be larger than the area of the clipping rectangle, which
  144.    * means the current image will be scrolled out of the rectangle. This
  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.
  151.    */
  152.   void (*Scroll)(PP_Resource graphics_2d,
  153.                  const struct PP_Rect* clip_rect,
  154.                  const struct PP_Point* amount);
  155.   /**
  156.    * ReplaceContents() provides a slightly more efficient way to paint the
  157.    * entire module's image. Normally, calling PaintImageData() requires that
  158.    * the browser copy the pixels out of the image and into the graphics
  159.    * context's backing store. This function replaces the graphics context's
  160.    * backing store with the given image, avoiding the copy.
  161.    *
  162.    * The new image must be the exact same size as this graphics context. If the
  163.    * new image uses a different image format than the browser's native bitmap
  164.    * format (use <code>PPB_ImageData.GetNativeImageDataFormat()</code> to
  165.    * retrieve the format), then a conversion will be done inside the browser
  166.    * which may slow the performance a little bit.
  167.    *
  168.    * <strong>Note:</strong> The new image will not be painted until you call
  169.    * Flush().
  170.    *
  171.    * After this call, you should take care to release your references to the
  172.    * image. If you paint to the image after ReplaceContents(), there is the
  173.    * possibility of significant painting artifacts because the page might use
  174.    * partially-rendered data when copying out of the backing store.
  175.    *
  176.    * In the case of an animation, you will want to allocate a new image for the
  177.    * next frame. It is best if you wait until the flush callback has executed
  178.    * before allocating this bitmap. This gives the browser the option of
  179.    * caching the previous backing store and handing it back to you (assuming
  180.    * the sizes match). In the optimal case, this means no bitmaps are allocated
  181.    * during the animation, and the backing store and "front buffer" (which the
  182.    * plugin is painting into) are just being swapped back and forth.
  183.    *
  184.    * @param[in] graphics_2d The 2D Graphics resource.
  185.    * @param[in] image The <code>ImageData</code> to be painted.
  186.    */
  187.   void (*ReplaceContents)(PP_Resource graphics_2d, PP_Resource image_data);
  188.   /**
  189.    * Flush() flushes any enqueued paint, scroll, and replace commands to the
  190.    * backing store. This function actually executes the updates, and causes a
  191.    * repaint of the webpage, assuming this graphics context is bound to a module
  192.    * instance.
  193.    *
  194.    * Flush() runs in asynchronous mode. Specify a callback function and the
  195.    * argument for that callback function. The callback function will be
  196.    * executed on the calling thread when the image has been painted to the
  197.    * screen. While you are waiting for a flush callback, additional calls to
  198.    * Flush() will fail.
  199.    *
  200.    * Because the callback is executed (or thread unblocked) only when the
  201.    * instance's image is actually on the screen, this function provides
  202.    * a way to rate limit animations. By waiting until the image is on the
  203.    * screen before painting the next frame, you can ensure you're not
  204.    * flushing 2D graphics faster than the screen can be updated.
  205.    *
  206.    * <strong>Unbound contexts</strong>
  207.    * If the context is not bound to a module instance, you will
  208.    * still get a callback. The callback will execute after Flush() returns
  209.    * to avoid reentrancy. The callback will not wait until anything is
  210.    * painted to the screen because there will be nothing on the screen. The
  211.    * timing of this callback is not guaranteed and may be deprioritized by
  212.    * the browser because it is not affecting the user experience.
  213.    *
  214.    * <strong>Off-screen instances</strong>
  215.    * If the context is bound to an instance that is currently not visible (for
  216.    * example, scrolled out of view) it will behave like the "unbound context"
  217.    * case.
  218.    *
  219.    * <strong>Detaching a context</strong>
  220.    * If you detach a context from a module instance, any pending flush
  221.    * callbacks will be converted into the "unbound context" case.
  222.    *
  223.    * <strong>Released contexts</strong>
  224.    * A callback may or may not get called even if you have released all
  225.    * of your references to the context. This scenario can occur if there are
  226.    * internal references to the context suggesting it has not been internally
  227.    * destroyed (for example, if it is still bound to an instance) or due to
  228.    * other implementation details. As a result, you should be careful to
  229.    * check that flush callbacks are for the context you expect and that
  230.    * you're capable of handling callbacks for unreferenced contexts.
  231.    *
  232.    * <strong>Shutdown</strong>
  233.    * If a module instance is removed when a flush is pending, the
  234.    * callback will not be executed.
  235.    *
  236.    * @param[in] graphics_2d The 2D Graphics resource.
  237.    * @param[in] callback A <code>CompletionCallback</code> to be called when
  238.    * the image has been painted on the screen.
  239.    *
  240.    * @return Returns <code>PP_OK</code> on success or
  241.    * <code>PP_ERROR_BADRESOURCE</code> if the graphics context is invalid,
  242.    * <code>PP_ERROR_BADARGUMENT</code> if the callback is null and flush is
  243.    * being called from the main thread of the module, or
  244.    * <code>PP_ERROR_INPROGRESS</code> if a flush is already pending that has
  245.    * not issued its callback yet.  In the failure case, nothing will be updated
  246.    * and no callback will be scheduled.
  247.    */
  248.   int32_t (*Flush)(PP_Resource graphics_2d,
  249.                    struct PP_CompletionCallback callback);
  250. };
  251.  
  252. typedef struct PPB_Graphics2D_1_0 PPB_Graphics2D;
  253. /**
  254.  * @}
  255.  */
  256.  
  257. #endif  /* PPAPI_C_PPB_GRAPHICS_2D_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement