Native Client

pp::PaintManager Class Reference

This class converts the "instance push" model of painting in PPAPI to a paint request at a later time. More...

List of all members.

Classes

class  Client

Public Functions

 PaintManager ()
 PaintManager (Instance *instance, Client *client, bool is_always_opaque)
 ~PaintManager ()
void Initialize (Instance *instance, Client *client, bool is_always_opaque)
void set_max_redundant_paint_to_scroll_area (float area)
void set_max_paint_rects (size_t max_rects)
void SetSize (const Size &new_size)
const Graphics2Dgraphics () const
Graphics2Dgraphics ()
void Invalidate ()
void InvalidateRect (const Rect &rect)
void ScrollRect (const Rect &clip_rect, const Point &amount)
Size GetEffectiveSize () const

Detailed Description

This class converts the "instance push" model of painting in PPAPI to a paint request at a later time.

Usage is that you call Invalidate and Scroll, and implement the Client interface. Your OnPaint handler will then get called with coalesced paint events.

This class is basically a PaintAggregator that groups updates, plus management of callbacks for scheduling paints.

Example:

class MyClass : public pp::Instance, public PaintManager::Client { public: MyClass() { paint_manager_.Initialize(this, this, false); }

void ViewChanged(const pp::Rect& position, const pp::Rect& clip) { paint_manager_.SetSize(position.size()); }

void DoSomething() { This function does something like respond to an event that causes the screen to need updating. paint_manager_.InvalidateRect(some_rect); }

Implementation of PaintManager::Client virtual bool OnPaint(pp::Graphics2D& device, const pp::PaintUpdate& update) { If our app needed scrolling, we would apply that first here.

Then we would either repaint the area returned by GetPaintBounds or iterate through all the paint_rects.

The caller will call Flush() for us, so don't do that here. return true; }

private: pp::PaintManager paint_manager_; };


Constructor and Destructor Details

pp::PaintManager::PaintManager ( )

Default constructor for creating an is_null() PaintManager object.

If you use this version of the constructor, you must call Initialize() below.

pp::PaintManager::PaintManager ( Instance instance,
Client client,
bool  is_always_opaque 
)

A constructor to create a new PaintManager with an instance and client.

Note: You will need to call SetSize() before this class will do anything. Normally you do this from the ViewChanged method of your instance.

Parameters:
instanceThe instance using this paint manager to do its painting. Painting will automatically go to this instance and you don't have to manually bind any device context (this is all handled by the paint manager).
clientA non-owning pointer and must remain valid (normally the object implementing the Client interface will own the paint manager).
is_always_opaqueA flag passed to the device contexts that this class creates. Set this to true if your instance always draws an opaque image to the device. This is used as a hint to the browser that it does not need to do alpha blending, which speeds up painting. If you generate non-opqaue pixels or aren't sure, set this to false for more general blending.

If you set is_always_opaque, your alpha channel should always be set to 0xFF or there may be painting artifacts. Being opaque will allow the browser to do a memcpy rather than a blend to paint the plugin, and this means your alpha values will get set on the page backing store. If these values are incorrect, it could mess up future blending. If you aren't sure, it is always correct to specify that it it not opaque.

pp::PaintManager::~PaintManager ( )

Destructor.


Function Details

Size pp::PaintManager::GetEffectiveSize ( ) const

GetEffectiveSize() returns the size of the graphics context for the next paint operation.

This is the pending size if a resize is pending (the instance has called SetSize() but we haven't actually painted it yet), or the current size of no resize is pending.

Returns:
The effective size.
const Graphics2D& pp::PaintManager::graphics ( ) const [inline]

This function provides access to the underlying device in case you need it.

If you have done a SetSize(), note that the graphics context won't be updated until right before the next call to OnPaint().

Note: If you call Flush on this device the paint manager will get very confused, don't do this!

Graphics2D& pp::PaintManager::graphics ( ) [inline]

This function provides access to the underlying device in case you need it.

If you have done a SetSize(), note that the graphics context won't be updated until right before the next call to OnPaint().

Note: If you call Flush on this device the paint manager will get very confused, don't do this!

void pp::PaintManager::Initialize ( Instance instance,
Client client,
bool  is_always_opaque 
)

Initialize() must be called if you are using the 0-arg constructor.

Parameters:
instanceThe instance using this paint manager to do its painting. Painting will automatically go to this instance and you don't have to manually bind any device context (this is all handled by the paint manager).
clientA non-owning pointer and must remain valid (normally the object implementing the Client interface will own the paint manager).
is_always_opaqueA flag passed to the device contexts that this class creates. Set this to true if your instance always draws an opaque image to the device. This is used as a hint to the browser that it does not need to do alpha blending, which speeds up painting. If you generate non-opqaue pixels or aren't sure, set this to false for more general blending.

If you set is_always_opaque, your alpha channel should always be set to 0xFF or there may be painting artifacts. Being opaque will allow the browser to do a memcpy rather than a blend to paint the plugin, and this means your alpha values will get set on the page backing store. If these values are incorrect, it could mess up future blending. If you aren't sure, it is always correct to specify that it it not opaque.

void pp::PaintManager::Invalidate ( )

Invalidate() invalidate the entire instance.

void pp::PaintManager::InvalidateRect ( const Rect rect)

InvalidateRect() Invalidate the provided rect.

Parameters:
[in]rectThe Rect to be invalidated.
void pp::PaintManager::ScrollRect ( const Rect clip_rect,
const Point amount 
)

ScrollRect() scrolls the provided clip_rect by the amount argument.

Parameters:
clip_rectThe clip rectangle to scroll.
amountThe amount to scroll clip_rect.
void pp::PaintManager::set_max_paint_rects ( size_t  max_rects) [inline]

Setter function for setting the maximum number of paint rects.

If we exceed this limit, then we'll start combining paint rects (refer to CombinePaintRects() for further information). This limiting can be important since there is typically some overhead in deciding what to paint. If your module is fast at doing these computations, raise this threshold, if your module is slow, lower it (probably requires some tuning to find the right value).

Parameters:
[in]max_rectsThe maximum number of paint rects.
void pp::PaintManager::set_max_redundant_paint_to_scroll_area ( float  area) [inline]

Setter function setting the max ratio of paint rect area to scroll rect area that we will tolerate before downgrading the scroll into a repaint.

If the combined area of paint rects contained within the scroll rect grows too large, then we might as well just treat the scroll rect as a paint rect.

Parameters:
[in]areaThe max ratio of paint rect area to scroll rect area that we will tolerate before downgrading the scroll into a repaint.
void pp::PaintManager::SetSize ( const Size new_size)

SetSize() sets the size of the instance.

If the size is the same as the previous call, this will be a NOP. If the size has changed, a new device will be allocated to the given size and a paint to that device will be scheduled.

This function is intended to be called from ViewChanged with the size of the instance. Since it tracks the old size and only allocates when the size changes, you can always call this function without worrying about whether the size changed or ViewChanged() is called for another reason (like the position changed).

Parameters:
new_sizeThe new size for the instance.

The documentation for this class was generated from the following file:

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.