Data Fields

PP_Resource(* Create )(PP_Instance instance, const struct PP_Size *size, PP_Bool is_always_opaque)
PP_Bool(* IsGraphics2D )(PP_Resource resource)
PP_Bool(* Describe )(PP_Resource graphics_2d, struct PP_Size *size, PP_Bool *is_always_opaque)
void(* PaintImageData )(PP_Resource graphics_2d, PP_Resource image_data, const struct PP_Point *top_left, const struct PP_Rect *src_rect)
void(* Scroll )(PP_Resource graphics_2d, const struct PP_Rect *clip_rect, const struct PP_Point *amount)
void(* ReplaceContents )(PP_Resource graphics_2d, PP_Resource image_data)
int32_t(* Flush )(PP_Resource graphics_2d, struct PP_CompletionCallback callback)
PP_Bool(* SetScale )(PP_Resource resource, float scale)
float(* GetScale )(PP_Resource resource)
PP_Bool(* SetLayerTransform )(PP_Resource resource, float scale, const struct PP_Point *origin, const struct PP_Point *translate)

Detailed Description

PPB_Graphics2D defines the interface for a 2D graphics context.


Field Documentation

PP_Resource(* PPB_Graphics2D::Create)(PP_Instance instance, const struct PP_Size *size, PP_Bool is_always_opaque)

Create() creates a 2D graphics context.

The returned graphics context will not be bound to the module instance on creation (call BindGraphics() on the module instance to bind the returned graphics context to the module instance).

Parameters:
[in]instanceThe module instance.
[in]sizeThe size of the graphic context.
[in]is_always_opaqueSet the is_always_opaque flag to PP_TRUE if you know that you will be painting only opaque data to this context. This option will disable blending when compositing the module with the web page, which might give higher performance on some computers.

If you set is_always_opaque, your alpha channel should always be set to 0xFF or there may be painting artifacts. The alpha values overwrite the destination alpha values without blending when is_always_opaque is true.

Returns:
A PP_Resource containing the 2D graphics context if successful or 0 if unsuccessful.
PP_Bool(* PPB_Graphics2D::Describe)(PP_Resource graphics_2d, struct PP_Size *size, PP_Bool *is_always_opaque)

Describe() retrieves the configuration for the given graphics context, filling the given values (which must not be NULL).

Parameters:
[in]resourceThe 2D Graphics resource.
[in,out]sizeThe size of the 2D graphics context in the browser.
[in,out]is_always_opaqueIdentifies whether only opaque data will be painted.
Returns:
Returns PP_TRUE on success or PP_FALSE if the resource is invalid. The output parameters will be set to 0 on a PP_FALSE.
int32_t(* PPB_Graphics2D::Flush)(PP_Resource graphics_2d, struct PP_CompletionCallback callback)

Flush() flushes any enqueued paint, scroll, and replace commands to the backing store.

This function actually executes the updates, and causes a repaint of the webpage, assuming this graphics context is bound to a module instance.

Flush() runs in asynchronous mode. Specify a callback function and the argument for that callback function. The callback function will be executed on the calling thread when the image has been painted to the screen. While you are waiting for a flush callback, additional calls to Flush() will fail.

Because the callback is executed (or thread unblocked) only when the instance's image is actually on the screen, this function provides a way to rate limit animations. By waiting until the image is on the screen before painting the next frame, you can ensure you're not flushing 2D graphics faster than the screen can be updated.

Unbound contexts If the context is not bound to a module instance, you will still get a callback. The callback will execute after Flush() returns to avoid reentrancy. The callback will not wait until anything is painted to the screen because there will be nothing on the screen. The timing of this callback is not guaranteed and may be deprioritized by the browser because it is not affecting the user experience.

Off-screen instances If the context is bound to an instance that is currently not visible (for example, scrolled out of view) it will behave like the "unbound context" case.

Detaching a context If you detach a context from a module instance, any pending flush callbacks will be converted into the "unbound context" case.

Released contexts A callback may or may not get called even if you have released all of your references to the context. This scenario can occur if there are internal references to the context suggesting it has not been internally destroyed (for example, if it is still bound to an instance) or due to other implementation details. As a result, you should be careful to check that flush callbacks are for the context you expect and that you're capable of handling callbacks for unreferenced contexts.

Shutdown If a module instance is removed when a flush is pending, the callback will not be executed.

Parameters:
[in]graphics_2dThe 2D Graphics resource.
[in]callbackA CompletionCallback to be called when the image has been painted on the screen.
Returns:
Returns PP_OK on success or PP_ERROR_BADRESOURCE if the graphics context is invalid, PP_ERROR_BADARGUMENT if the callback is null and flush is being called from the main thread of the module, or PP_ERROR_INPROGRESS if a flush is already pending that has not issued its callback yet. In the failure case, nothing will be updated and no callback will be scheduled.

IsGraphics2D() determines if the given resource is a valid Graphics2D.

Parameters:
[in]resourceA Graphics2D context resource.
Returns:
PP_TRUE if the given resource is a valid Graphics2D, PP_FALSE if it is an invalid resource or is a resource of another type.
void(* PPB_Graphics2D::PaintImageData)(PP_Resource graphics_2d, PP_Resource image_data, const struct PP_Point *top_left, const struct PP_Rect *src_rect)

PaintImageData() enqueues a paint of the given image into the context.

This function has no effect until you call Flush() As a result, what counts is the contents of the bitmap when you call Flush(), not when you call this function.

The provided image will be placed at top_left from the top left of the context's internal backing store. Then the pixels contained in src_rect will be copied into the backing store. This means that the rectangle being painted will be at src_rect offset by top_left.

The src_rect is specified in the coordinate system of the image being painted, not the context. For the common case of copying the entire image, you may specify an empty src_rect.

The painted area of the source bitmap must fall entirely within the context. Attempting to paint outside of the context will result in an error. However, the source bitmap may fall outside the context, as long as the src_rect subset of it falls entirely within the context.

There are two methods most modules will use for painting. The first method is to generate a new ImageData and then paint it. In this case, you'll set the location of your painting to top_left and set src_rect to NULL. The second is that you're generating small invalid regions out of a larger bitmap representing your entire instance. In this case, you would set the location of your image to (0,0) and then set src_rect to the pixels you changed.

Parameters:
[in]resourceThe 2D Graphics resource.
[in]imageThe ImageData to be painted.
[in]top_leftA Point representing the top_left location where the ImageData will be painted.
[in]src_rectThe rectangular area where the ImageData will be painted.

ReplaceContents() provides a slightly more efficient way to paint the entire module's image.

Normally, calling PaintImageData() requires that the browser copy the pixels out of the image and into the graphics context's backing store. This function replaces the graphics context's backing store with the given image, avoiding the copy.

The new image must be the exact same size as this graphics context. If the new image uses a different image format than the browser's native bitmap format (use PPB_ImageData.GetNativeImageDataFormat() to retrieve the format), then a conversion will be done inside the browser which may slow the performance a little bit.

Note: The new image will not be painted until you call Flush().

After this call, you should take care to release your references to the image. If you paint to the image after ReplaceContents(), there is the possibility of significant painting artifacts because the page might use partially-rendered data when copying out of the backing store.

In the case of an animation, you will want to allocate a new image for the next frame. It is best if you wait until the flush callback has executed before allocating this bitmap. This gives the browser the option of caching the previous backing store and handing it back to you (assuming the sizes match). In the optimal case, this means no bitmaps are allocated during the animation, and the backing store and "front buffer" (which the plugin is painting into) are just being swapped back and forth.

Parameters:
[in]graphics_2dThe 2D Graphics resource.
[in]imageThe ImageData to be painted.
void(* PPB_Graphics2D::Scroll)(PP_Resource graphics_2d, const struct PP_Rect *clip_rect, const struct PP_Point *amount)

Scroll() enqueues a scroll of the context's backing store.

This function has no effect until you call Flush(). The data within the provided clipping rectangle will be shifted by (dx, dy) pixels.

This function will result in some exposed region which will have undefined contents. The module should call PaintImageData() on these exposed regions to give the correct contents.

The scroll can be larger than the area of the clipping rectangle, which means the current image will be scrolled out of the rectangle. This scenario is not an error but will result in a no-op.

Parameters:
[in]graphics_2dThe 2D Graphics resource.
[in]clipThe clipping rectangle.
[in]amountThe amount the area in the clipping rectangle will shifted.
PP_Bool(* PPB_Graphics2D::SetLayerTransform)(PP_Resource resource, float scale, const struct PP_Point *origin, const struct PP_Point *translate)

SetLayerTransform() sets a transformation factor that will be applied for the current graphics context displayed on the output device.

If both SetScale and SetLayerTransform will be used, they are going to get combined for the final result.

This function has no effect until you call Flush().

Parameters:
[in]scaleThe scale to be applied.
[in]originThe origin of the scale.
[in]translateThe translation to be applied.
Returns:
Returns PP_TRUE on success or PP_FALSE if the resource is invalid or the scale factor is 0 or less.
PP_Bool(* PPB_Graphics2D::SetScale)(PP_Resource resource, float scale)

SetScale() sets the scale factor that will be applied when painting the graphics context onto the output device.

Typically, if rendering at device resolution is desired, the context would be created with the width and height scaled up by the view's GetDeviceScale and SetScale called with a scale of 1.0 / GetDeviceScale(). For example, if the view resource passed to DidChangeView has a rectangle of (w=200, h=100) and a device scale of 2.0, one would call Create with a size of (w=400, h=200) and then call SetScale with 0.5. One would then treat each pixel in the context as a single device pixel.

Parameters:
[in]resourceA Graphics2D context resource.
[in]scaleThe scale to apply when painting.
Returns:
Returns PP_TRUE on success or PP_FALSE if the resource is invalid or the scale factor is 0 or less.

The documentation for this struct was generated from the following file:
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.