Chromium Code Reviews| 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_CPP_PAINT_MANAGER_H_ | 5 #ifndef PPAPI_CPP_PAINT_MANAGER_H_ |
| 6 #define PPAPI_CPP_PAINT_MANAGER_H_ | 6 #define PPAPI_CPP_PAINT_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ppapi/cpp/completion_callback.h" | 10 #include "ppapi/cpp/completion_callback.h" |
| 11 #include "ppapi/cpp/graphics_2d.h" | 11 #include "ppapi/cpp/graphics_2d.h" |
| 12 #include "ppapi/cpp/paint_aggregator.h" | 12 #include "ppapi/cpp/paint_aggregator.h" |
| 13 | 13 |
| 14 /// @file | |
| 15 /// This file defines the API to convert the "plugin push" model of painting | |
| 16 /// in PPAPI to a paint request at a later time. | |
| 17 | |
| 14 namespace pp { | 18 namespace pp { |
| 15 | 19 |
| 16 class Graphics2D; | 20 class Graphics2D; |
| 17 class Instance; | 21 class Instance; |
| 18 class Point; | 22 class Point; |
| 19 class Rect; | 23 class Rect; |
| 20 | 24 |
| 21 // This class converts the "plugin push" model of painting in PPAPI to a paint | 25 /// This class converts the "instance push" model of painting in PPAPI to a |
| 22 // request at a later time. Usage is that you call Invalidate and Scroll, and | 26 /// paint request at a later time. Usage is that you call Invalidate and |
| 23 // implement the Client interface. Your OnPaint handler will then get called | 27 /// Scroll, and implement the Client interface. Your OnPaint handler will |
| 24 // with coalesced paint events. | 28 /// then get called with coalesced paint events. |
| 25 // | 29 /// |
| 26 // This class is basically a PaintAggregator that groups updates, plus | 30 /// This class is basically a <code>PaintAggregator</code> that groups updates, |
| 27 // management of callbacks for scheduling paints. | 31 /// plus management of callbacks for scheduling paints. |
| 28 // | 32 /// |
| 29 // Typical usage: | 33 /// <strong>Example:</strong> |
| 30 // | 34 /// |
| 31 // class MyClass : public pp::Instance, public PaintManager::Client { | 35 /// @code |
|
dmichael (off chromium)
2011/08/03 15:50:49
Why are you using @code here instead of <code> lik
jond
2011/08/03 20:15:08
We're using @code and @endcode for large code bloc
dmichael (off chromium)
2011/08/04 16:33:38
Is the @code tag very widespread? There doesn't se
| |
| 32 // public: | 36 /// |
| 33 // MyClass() { | 37 /// class MyClass : public pp::Instance, public PaintManager::Client { |
| 34 // paint_manager_.Initialize(this, this, false); | 38 /// public: |
| 35 // } | 39 /// MyClass() { |
| 36 // | 40 /// paint_manager_.Initialize(this, this, false); |
| 37 // void ViewChanged(const pp::Rect& position, const pp::Rect& clip) { | 41 /// } |
| 38 // paint_manager_.SetSize(position.size()); | 42 /// |
| 39 // } | 43 /// void ViewChanged(const pp::Rect& position, const pp::Rect& clip) { |
| 40 // | 44 /// paint_manager_.SetSize(position.size()); |
| 41 // void DoSomething() { | 45 /// } |
| 42 // // This function does something like respond to an event that causes | 46 /// |
| 43 // // the screen to need updating. | 47 /// void DoSomething() { |
| 44 // paint_manager_.InvalidateRect(some_rect); | 48 /// // This function does something like respond to an event that causes |
| 45 // } | 49 /// // the screen to need updating. |
| 46 // | 50 /// paint_manager_.InvalidateRect(some_rect); |
| 47 // // Implementation of PaintManager::Client | 51 /// } |
| 48 // virtual bool OnPaint(pp::Graphics2D& device, | 52 /// |
| 49 // const pp::PaintUpdate& update) { | 53 /// // Implementation of PaintManager::Client |
| 50 // // If our app needed scrolling, we would apply that first here. | 54 /// virtual bool OnPaint(pp::Graphics2D& device, |
| 51 // | 55 /// const pp::PaintUpdate& update) { |
| 52 // // Then we would either repaint the area returned by GetPaintBounds or | 56 /// // If our app needed scrolling, we would apply that first here. |
| 53 // // iterate through all the paint_rects. | 57 /// |
| 54 // | 58 /// // Then we would either repaint the area returned by GetPaintBounds or |
| 55 // // The caller will call Flush() for us, so don't do that here. | 59 /// // iterate through all the paint_rects. |
| 56 // return true; | 60 /// |
| 57 // } | 61 /// // The caller will call Flush() for us, so don't do that here. |
| 58 // | 62 /// return true; |
| 59 // private: | 63 /// } |
| 60 // pp::PaintManager paint_manager_; | 64 /// |
| 61 // }; | 65 /// private: |
| 66 /// pp::PaintManager paint_manager_; | |
| 67 /// }; | |
| 68 /// @endcode | |
| 62 class PaintManager { | 69 class PaintManager { |
| 63 public: | 70 public: |
| 64 class Client { | 71 class Client { |
| 65 public: | 72 public: |
| 66 // Paints the given invalid area of the plugin to the given graphics | 73 /// OnPaint() paints the given invalid area of the instance to the given |
|
dmichael (off chromium)
2011/08/03 15:50:49
Do we wrap function names with <code> tags? If so,
jond
2011/08/03 20:15:08
<code></code> is only used for things that exist i
| |
| 67 // device. Returns true if anything was painted. | 74 /// graphics device. Returns true if anything was painted. |
| 68 // | 75 /// |
| 69 // You are given the list of rects to paint in |paint_rects|, and the | 76 /// You are given the list of rects to paint in <code>paint_rects</code>, |
| 70 // union of all of these rects in |paint_bounds|. You only have to paint | 77 /// and the union of all of these rects in <code>paint_bounds</code>. You |
| 71 // the area inside each of the |paint_rects|, but can paint more if you | 78 /// only have to paint the area inside each of the |
| 72 // want (some apps may just want to paint the union). | 79 /// <code>paint_rects</code>, but can paint more if you want (some apps may |
| 73 // | 80 /// just want to paint the union). |
| 74 // Do not call Flush() on the graphics device, this will be done | 81 /// |
| 75 // automatically if you return true from this function since the | 82 /// Do not call Flush() on the graphics device, this will be done |
| 76 // PaintManager needs to handle the callback. | 83 /// automatically if you return true from this function since the |
| 77 // | 84 /// <code>PaintManager</code> needs to handle the callback. |
| 78 // It is legal for you to cause invalidates inside of Paint which will | 85 /// |
| 79 // then get executed as soon as the Flush for this update has completed. | 86 /// It is legal for you to cause invalidates inside of Paint which will |
| 80 // However, this is not very nice to the host system since it will spin the | 87 /// then get executed as soon as the Flush for this update has completed. |
| 81 // CPU, possibly updating much faster than necessary. It is best to have a | 88 /// However, this is not very nice to the host system since it will spin the |
| 82 // 1/60 second timer to do an invalidate instead. This will limit your | 89 /// CPU, possibly updating much faster than necessary. It is best to have a |
| 83 // animation to the slower of 60Hz or "however fast Flush can complete." | 90 /// 1/60 second timer to do an invalidate instead. This will limit your |
| 91 /// animation to the slower of 60Hz or "however fast Flush can complete." | |
| 92 /// | |
| 93 /// @param graphics A <code>Graphics2D</code> to be painted. | |
| 94 /// @param paint_rects A list of rects to paint. | |
| 95 /// @param paint_bounds A union of the rects to paint. | |
| 84 virtual bool OnPaint(Graphics2D& graphics, | 96 virtual bool OnPaint(Graphics2D& graphics, |
| 85 const std::vector<Rect>& paint_rects, | 97 const std::vector<Rect>& paint_rects, |
| 86 const Rect& paint_bounds) = 0; | 98 const Rect& paint_bounds) = 0; |
| 87 | 99 |
| 88 protected: | 100 protected: |
| 89 // You shouldn't be doing deleting through this interface. | 101 // You shouldn't be doing deleting through this interface. |
| 90 virtual ~Client() {} | 102 virtual ~Client() {} |
| 91 }; | 103 }; |
| 92 | 104 |
| 93 // If you use this version of the constructor, you must call Initialize() | 105 /// Default constructor for creating an is_null() <code>PaintManager</code> |
| 94 // below. | 106 /// object. If you use this version of the constructor, you must call |
| 107 /// Initialize() below. | |
| 95 PaintManager(); | 108 PaintManager(); |
| 96 | 109 |
| 97 // The instance is the plugin instance using this paint manager to do its | 110 /// A constructor to create a new <code>PaintManager</code> with an instance |
| 98 // painting. Painting will automatically go to this instance and you don't | 111 /// and client. |
| 99 // have to manually bind any device context (this is all handled by the | 112 /// |
| 100 // paint manager). | 113 /// <strong>Note:</strong> You will need to call SetSize() before this class |
| 101 // | 114 /// will do anything. Normally you do this from the <code>ViewChanged</code> |
| 102 // The Client is a non-owning pointer and must remain valid (normally the | 115 /// method of your instance. |
| 103 // object implementing the Client interface will own the paint manager). | 116 /// |
| 104 // | 117 /// @param instance The instance using this paint manager to do its |
| 105 // The is_always_opaque flag will be passed to the device contexts that this | 118 /// painting. Painting will automatically go to this instance and you don't |
| 106 // class creates. Set this to true if your plugin always draws an opaque | 119 /// have to manually bind any device context (this is all handled by the |
| 107 // image to the device. This is used as a hint to the browser that it does | 120 /// paint manager). |
| 108 // not need to do alpha blending, which speeds up painting. If you generate | 121 /// |
| 109 // non-opqaue pixels or aren't sure, set this to false for more general | 122 /// @param client A non-owning pointer and must remain valid (normally the |
| 110 // blending. | 123 /// object implementing the Client interface will own the paint manager). |
| 111 // | 124 /// |
| 112 // If you set is_always_opaque, your alpha channel should always be set to | 125 /// @param is_always_opaque A flag passed to the device contexts that this |
| 113 // 0xFF or there may be painting artifacts. Being opaque will allow the | 126 /// class creates. Set this to true if your instance always draws an opaque |
| 114 // browser to do a memcpy rather than a blend to paint the plugin, and this | 127 /// image to the device. This is used as a hint to the browser that it does |
| 115 // means your alpha values will get set on the page backing store. If these | 128 /// not need to do alpha blending, which speeds up painting. If you generate |
| 116 // values are incorrect, it could mess up future blending. If you aren't | 129 /// non-opqaue pixels or aren't sure, set this to false for more general |
| 117 // sure, it is always correct to specify that it it not opaque. | 130 /// blending. |
| 118 // | 131 /// |
| 119 // You will need to call SetSize before this class will do anything. Normally | 132 /// If you set is_always_opaque, your alpha channel should always be set to |
| 120 // you do this from the ViewChanged method of your plugin instance. | 133 /// 0xFF or there may be painting artifacts. Being opaque will allow the |
| 134 /// browser to do a memcpy rather than a blend to paint the plugin, and this | |
| 135 /// means your alpha values will get set on the page backing store. If these | |
| 136 /// values are incorrect, it could mess up future blending. If you aren't | |
| 137 /// sure, it is always correct to specify that it it not opaque. | |
| 121 PaintManager(Instance* instance, Client* client, bool is_always_opaque); | 138 PaintManager(Instance* instance, Client* client, bool is_always_opaque); |
| 122 | 139 |
| 140 /// Destructor. | |
| 123 ~PaintManager(); | 141 ~PaintManager(); |
| 124 | 142 |
| 125 // You must call this function before using if you use the 0-arg constructor. | 143 /// Initialize() is called before using if you use the 0-arg constructor. |
|
dmichael (off chromium)
2011/08/03 15:50:49
Reword as a 'You must' kind of thing; the develope
jond
2011/08/03 20:15:08
Done.
jond
2011/08/03 20:15:08
Done.
| |
| 126 // See the constructor for what these arguments mean. | 144 /// |
| 145 /// @param client A non-owning pointer and must remain valid (normally the | |
| 146 /// object implementing the Client interface will own the paint manager). | |
| 147 /// | |
| 148 /// @param is_always_opaque A flag passed to the device contexts that this | |
| 149 /// class creates. Set this to true if your instance always draws an opaque | |
| 150 /// image to the device. This is used as a hint to the browser that it does | |
| 151 /// not need to do alpha blending, which speeds up painting. If you generate | |
| 152 /// non-opqaue pixels or aren't sure, set this to false for more general | |
| 153 /// blending. | |
| 154 /// | |
| 155 /// If you set is_always_opaque, your alpha channel should always be set to | |
| 156 /// 0xFF or there may be painting artifacts. Being opaque will allow the | |
| 157 /// browser to do a memcpy rather than a blend to paint the plugin, and this | |
| 158 /// means your alpha values will get set on the page backing store. If these | |
| 159 /// values are incorrect, it could mess up future blending. If you aren't | |
| 160 /// sure, it is always correct to specify that it it not opaque. | |
| 127 void Initialize(Instance* instance, Client* client, bool is_always_opaque); | 161 void Initialize(Instance* instance, Client* client, bool is_always_opaque); |
| 128 | 162 |
| 129 // Setters for the configuration settings in the paint aggregator. | 163 /// Setter function setting the max ratio of paint rect area to scroll rect |
| 130 // See paint_aggregator.h for what these mean. | 164 /// area that we will tolerate before downgrading the scroll into a repaint. |
| 165 /// | |
| 166 /// If the combined area of paint rects contained within the scroll | |
| 167 /// rect grows too large, then we might as well just treat | |
| 168 /// the scroll rect as a paint rect. | |
| 169 /// | |
| 170 /// @param[in] area The max ratio of paint rect area to scroll rect area that | |
| 171 /// we will tolerate before downgrading the scroll into a repaint. | |
| 131 void set_max_redundant_paint_to_scroll_area(float area) { | 172 void set_max_redundant_paint_to_scroll_area(float area) { |
| 132 aggregator_.set_max_redundant_paint_to_scroll_area(area); | 173 aggregator_.set_max_redundant_paint_to_scroll_area(area); |
| 133 } | 174 } |
| 175 | |
| 176 /// Setter function for setting the maximum number of paint rects. If we | |
| 177 /// exceed this limit, then we'll start combining paint rects (see | |
| 178 /// CombinePaintRects(). This limiting can be important since there is | |
| 179 /// typically some overhead in deciding what to paint. If your module is fast | |
| 180 /// at doing these computations, raise this threshold, if your module is | |
| 181 /// slow, lower it (probably requires some tuning to find the right value). | |
| 182 /// | |
| 183 /// @param[in] max_rects The maximum number of paint rects. | |
| 134 void set_max_paint_rects(size_t max_rects) { | 184 void set_max_paint_rects(size_t max_rects) { |
| 135 aggregator_.set_max_paint_rects(max_rects); | 185 aggregator_.set_max_paint_rects(max_rects); |
| 136 } | 186 } |
| 137 | 187 |
| 138 // Sets the size of the plugin. If the size is the same as the previous call, | 188 /// SetSize() sets the size of the instance. If the size is the same as the |
| 139 // this will be a NOP. If the size has changed, a new device will be | 189 /// previous call, this will be a NOP. If the size has changed, a new device |
| 140 // allocated to the given size and a paint to that device will be scheduled. | 190 /// will be allocated to the given size and a paint to that device will be |
| 141 // | 191 /// scheduled. |
| 142 // This is intended to be called from ViewChanged with the size of the | 192 /// |
| 143 // plugin. Since it tracks the old size and only allocates when the size | 193 /// This function intended to be called from <code>ViewChanged</code> with |
|
dmichael (off chromium)
2011/08/03 15:50:49
you lost the 'is' before intentended
| |
| 144 // changes, you can always call this function without worrying about whether | 194 /// the size of the instance. Since it tracks the old size and only allocates |
| 145 // the size changed or ViewChanged is called for another reason (like the | 195 /// when the size changes, you can always call this function without worrying |
| 146 // position changed). | 196 /// about whether the size changed or ViewChanged() is called for another |
| 197 /// reason (like the position changed). | |
| 198 /// | |
| 199 /// @param new_size The new size for the instance. | |
| 147 void SetSize(const Size& new_size); | 200 void SetSize(const Size& new_size); |
| 148 | 201 |
| 149 // Provides access to the underlying device in case you need it. If you have | 202 /// This function provides access to the underlying device in case you need |
| 150 // done a SetSize, note that the graphics context won't be updated until | 203 /// it. If you have done a SetSize(), note that the graphics context won't be |
| 151 // right before the next OnPaint call. | 204 /// updated until right before the next call to OnPaint(). |
| 152 // | 205 /// |
| 153 // Note: if you call Flush on this device the paint manager will get very | 206 /// <strong>Note:</strong> If you call Flush on this device the paint manager |
| 154 // confused, don't do this! | 207 /// will get very confused, don't do this! |
| 155 const Graphics2D& graphics() const { return graphics_; } | 208 const Graphics2D& graphics() const { return graphics_; } |
| 209 | |
| 210 /// This function provides access to the underlying device in case you need | |
| 211 /// it. If you have done a SetSize(), note that the graphics context won't be | |
| 212 /// updated until right before the next call to OnPaint(). | |
| 213 /// | |
| 214 /// <strong>Note:</strong> If you call Flush on this device the paint manager | |
| 215 /// will get very confused, don't do this! | |
| 156 Graphics2D& graphics() { return graphics_; } | 216 Graphics2D& graphics() { return graphics_; } |
| 157 | 217 |
| 158 // Invalidate the entire plugin. | 218 /// Invalidate() invalidate the entire instance. |
| 159 void Invalidate(); | 219 void Invalidate(); |
| 160 | 220 |
| 161 // Invalidate the given rect. | 221 /// InvalidateRect() Invalidate the provided rect. |
| 222 /// | |
| 223 /// @param rect The <code>Rect</code> to be invalidated. | |
| 162 void InvalidateRect(const Rect& rect); | 224 void InvalidateRect(const Rect& rect); |
| 163 | 225 |
| 164 // The given rect should be scrolled by the given amounts. | 226 /// ScrollRect() scrolls the provided <code>Rect</code> by the provided |
|
dmichael (off chromium)
2011/08/03 15:50:49
'by the provided' -> 'by the given'?
It might read
jond
2011/08/03 20:15:08
Done.
jond
2011/08/03 20:15:08
Done.
| |
| 227 /// amount. | |
| 228 /// | |
| 229 /// @param clip_rect The clip rectangle to scroll. | |
| 230 /// @param amount The amount to scroll <code>clip_rect</code>. | |
| 165 void ScrollRect(const Rect& clip_rect, const Point& amount); | 231 void ScrollRect(const Rect& clip_rect, const Point& amount); |
| 166 | 232 |
| 167 // Returns the size of the graphics context for the next paint operation. | 233 /// GetEffectiveSize() returns the size of the graphics context for the |
| 168 // This is the pending size if a resize is pending (the plugin has called | 234 /// next paint operation. This is the pending size if a resize is pending |
| 169 // SetSize but we haven't actually painted it yet), or the current size of | 235 /// (the instance has called SetSize() but we haven't actually painted it |
| 170 // no resize is pending. | 236 /// yet), or the current size of no resize is pending. |
| 237 /// | |
| 238 /// @return The effetive size. | |
| 171 Size GetEffectiveSize() const; | 239 Size GetEffectiveSize() const; |
| 172 | 240 |
| 173 private: | 241 private: |
| 174 // Disallow copy and assign (these are unimplemented). | 242 // Disallow copy and assign (these are unimplemented). |
| 175 PaintManager(const PaintManager&); | 243 PaintManager(const PaintManager&); |
| 176 PaintManager& operator=(const PaintManager&); | 244 PaintManager& operator=(const PaintManager&); |
| 177 | 245 |
| 178 // Makes sure there is a callback that will trigger a paint at a later time. | 246 // Makes sure there is a callback that will trigger a paint at a later time. |
| 179 // This will be either a Flush callback telling us we're allowed to generate | 247 // This will be either a Flush callback telling us we're allowed to generate |
| 180 // more data, or, if there's no flush callback pending, a manual call back | 248 // more data, or, if there's no flush callback pending, a manual call back |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 // When we get a resize, we don't bind right away (see SetSize). The | 281 // When we get a resize, we don't bind right away (see SetSize). The |
| 214 // has_pending_resize_ tells us that we need to do a resize for the next | 282 // has_pending_resize_ tells us that we need to do a resize for the next |
| 215 // paint operation. When true, the new size is in pending_size_. | 283 // paint operation. When true, the new size is in pending_size_. |
| 216 bool has_pending_resize_; | 284 bool has_pending_resize_; |
| 217 Size pending_size_; | 285 Size pending_size_; |
| 218 }; | 286 }; |
| 219 | 287 |
| 220 } // namespace pp | 288 } // namespace pp |
| 221 | 289 |
| 222 #endif // PPAPI_CPP_PAINT_MANAGER_H_ | 290 #endif // PPAPI_CPP_PAINT_MANAGER_H_ |
| OLD | NEW |