OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_GRAPHICS_2D_H_ | 5 #ifndef PPAPI_CPP_GRAPHICS_2D_H_ |
6 #define PPAPI_CPP_GRAPHICS_2D_H_ | 6 #define PPAPI_CPP_GRAPHICS_2D_H_ |
7 | 7 |
8 #include "ppapi/c/pp_stdint.h" | 8 #include "ppapi/c/pp_stdint.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 #include "ppapi/cpp/size.h" | 10 #include "ppapi/cpp/size.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 Graphics2D(const Graphics2D& other); | 34 Graphics2D(const Graphics2D& other); |
35 | 35 |
36 /// A constructor allocating a new 2D graphics context with the given size | 36 /// A constructor allocating a new 2D graphics context with the given size |
37 /// in the browser, resulting object will be is_null() if the allocation | 37 /// in the browser, resulting object will be is_null() if the allocation |
38 /// failed. | 38 /// failed. |
39 /// | 39 /// |
40 /// @param[in] instance The instance with which this resource will be | 40 /// @param[in] instance The instance with which this resource will be |
41 /// associated. | 41 /// associated. |
42 /// | 42 /// |
43 /// @param[in] size The size of the 2D graphics context in the browser, | 43 /// @param[in] size The size of the 2D graphics context in the browser, |
44 /// measured in device pixels. | 44 /// measured in pixels. See <code>SetScale()</code> for more information. |
45 /// | 45 /// |
46 /// @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag | 46 /// @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag |
47 /// to true if you know that you will be painting only opaque data to this | 47 /// to true if you know that you will be painting only opaque data to this |
48 /// context. This option will disable blending when compositing the module | 48 /// context. This option will disable blending when compositing the module |
49 /// with the web page, which might give higher performance on some computers. | 49 /// with the web page, which might give higher performance on some computers. |
50 /// | 50 /// |
51 /// If you set <code>is_always_opaque</code>, your alpha channel should | 51 /// If you set <code>is_always_opaque</code>, your alpha channel should |
52 /// always be set to 0xFF or there may be painting artifacts. The alpha values | 52 /// always be set to 0xFF or there may be painting artifacts. The alpha values |
53 /// overwrite the destination alpha values without blending when | 53 /// overwrite the destination alpha values without blending when |
54 /// <code>is_always_opaque</code> is true. | 54 /// <code>is_always_opaque</code> is true. |
(...skipping 12 matching lines...) Expand all Loading... |
67 /// of the other 2D graphics context while decrementing the reference counter | 67 /// of the other 2D graphics context while decrementing the reference counter |
68 /// of this 2D graphics context. | 68 /// of this 2D graphics context. |
69 /// | 69 /// |
70 /// @param[in] other An other 2D graphics context. | 70 /// @param[in] other An other 2D graphics context. |
71 /// | 71 /// |
72 /// @return A new Graphics2D context. | 72 /// @return A new Graphics2D context. |
73 Graphics2D& operator=(const Graphics2D& other); | 73 Graphics2D& operator=(const Graphics2D& other); |
74 | 74 |
75 /// Getter function for returning size of the 2D graphics context. | 75 /// Getter function for returning size of the 2D graphics context. |
76 /// | 76 /// |
77 /// @return The size of the 2D graphics context measured in device pixels. | 77 /// @return The size of the 2D graphics context measured in pixels. |
78 const Size& size() const { return size_; } | 78 const Size& size() const { return size_; } |
79 | 79 |
80 /// PaintImageData() enqueues a paint command of the given image into | 80 /// PaintImageData() enqueues a paint command of the given image into |
81 /// the context. This command has no effect until you call Flush(). As a | 81 /// the context. This command has no effect until you call Flush(). As a |
82 /// result, what counts is the contents of the bitmap when you call Flush, | 82 /// result, what counts is the contents of the bitmap when you call Flush, |
83 /// not when you call this function. | 83 /// not when you call this function. |
84 /// | 84 /// |
85 /// The provided image will be placed at <code>top_left</code> from the top | 85 /// The provided image will be placed at <code>top_left</code> from the top |
86 /// left of the context's internal backing store. This version of | 86 /// left of the context's internal backing store. This version of |
87 /// PaintImageData paints the entire image. Refer to the other version of | 87 /// PaintImageData paints the entire image. Refer to the other version of |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 /// not issued its callback yet. In the failure case, nothing will be | 253 /// not issued its callback yet. In the failure case, nothing will be |
254 /// updated and no callback will be scheduled. | 254 /// updated and no callback will be scheduled. |
255 | 255 |
256 // TODO(darin): We should ensure that the completion callback always runs, so | 256 // TODO(darin): We should ensure that the completion callback always runs, so |
257 // that it is easier for consumers to manage memory referenced by a callback. | 257 // that it is easier for consumers to manage memory referenced by a callback. |
258 | 258 |
259 // TODO(): Add back in the synchronous mode description once we have support | 259 // TODO(): Add back in the synchronous mode description once we have support |
260 // for it. | 260 // for it. |
261 int32_t Flush(const CompletionCallback& cc); | 261 int32_t Flush(const CompletionCallback& cc); |
262 | 262 |
| 263 /// SetScale() sets the scale factor that will be applied when painting the |
| 264 /// graphics context onto the output device. Typically, if rendering at device |
| 265 /// resolution is desired, the context would be created with the width and |
| 266 /// height scaled up by the view's GetDeviceScale and SetScale called with a |
| 267 /// scale of 1.0 / GetDeviceScale(). For example, if the view resource passed |
| 268 /// to DidChangeView has a rectangle of (w=200, h=100) and a device scale of |
| 269 /// 2.0, one would call Create with a size of (w=400, h=200) and then call |
| 270 /// SetScale with 0.5. One would then treat each pixel in the context as a |
| 271 /// single device pixel. |
| 272 /// |
| 273 /// @param[in] scale The scale to apply when painting. |
| 274 /// |
| 275 /// @return Returns <code>true</code> on success or <code>false</code> |
| 276 /// if the resource is invalid or the scale factor is 0 or less. |
| 277 bool SetScale(float scale); |
| 278 |
| 279 /// GetScale() gets the scale factor that will be applied when painting the |
| 280 /// graphics context onto the output device. |
| 281 /// |
| 282 /// @return Returns the scale factor for the graphics context. If the resource |
| 283 /// is invalid, 0.0 will be returned. The default scale for a graphics context |
| 284 /// is 1.0. |
| 285 float GetScale(); |
| 286 |
263 private: | 287 private: |
264 Size size_; | 288 Size size_; |
265 }; | 289 }; |
266 | 290 |
267 } // namespace pp | 291 } // namespace pp |
268 | 292 |
269 #endif // PPAPI_CPP_GRAPHICS_2D_H_ | 293 #endif // PPAPI_CPP_GRAPHICS_2D_H_ |
OLD | NEW |