blob: d94ea820b53e6b8f552732bc1bc67670fce92a19 [file] [log] [blame]
[email protected]b15cce52011-07-06 20:44:311// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1758e882010-11-01 16:16:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_CPP_IMAGE_DATA_H_
6#define PPAPI_CPP_IMAGE_DATA_H_
7
8#include "ppapi/c/ppb_image_data.h"
9#include "ppapi/cpp/point.h"
10#include "ppapi/cpp/size.h"
11#include "ppapi/cpp/resource.h"
12
[email protected]d0270d12011-06-23 22:01:5813/// @file
14/// This file defines the APIs for determining how a browser
15/// handles image data.
[email protected]1758e882010-11-01 16:16:5016namespace pp {
17
[email protected]09af0f72012-02-27 20:23:1918class InstanceHandle;
[email protected]1758e882010-11-01 16:16:5019
20class ImageData : public Resource {
21 public:
[email protected]b15cce52011-07-06 20:44:3122 /// Default constructor for creating an is_null() <code>ImageData</code>
23 /// object.
[email protected]1758e882010-11-01 16:16:5024 ImageData();
25
[email protected]e12a6a12011-08-31 16:07:5926 /// A constructor used when you have received a <code>PP_Resource</code> as a
27 /// return value that has already been reference counted.
[email protected]d0270d12011-06-23 22:01:5828 ///
29 /// @param[in] resource A PP_Resource corresponding to image data.
[email protected]1758e882010-11-01 16:16:5030 ImageData(PassRef, PP_Resource resource);
31
[email protected]b15cce52011-07-06 20:44:3132 /// The copy constructor for <code>ImageData</code>. This constructor
33 /// produces an <code>ImageData</code> object that shares the underlying
34 /// <code>Image</code> resource with <code>other</code>.
[email protected]d0270d12011-06-23 22:01:5835 ///
36 /// @param[in] other A pointer to an image data.
[email protected]1758e882010-11-01 16:16:5037 ImageData(const ImageData& other);
38
[email protected]b15cce52011-07-06 20:44:3139 /// A constructor that allocates a new <code>ImageData</code> in the browser
40 /// with the provided parameters. The resulting object will be is_null() if
41 /// the allocation failed.
[email protected]d0270d12011-06-23 22:01:5842 ///
[email protected]09af0f72012-02-27 20:23:1943 /// @param[in] instance The instance with which this resource will be
44 /// associated.
[email protected]b15cce52011-07-06 20:44:3145 ///
46 /// @param[in] format A PP_ImageDataFormat containing desired image format.
[email protected]d0270d12011-06-23 22:01:5847 /// PP_ImageDataFormat is an enumeration of the different types of
[email protected]63e627d2011-08-16 19:15:3148 /// image data formats. Refer to
49 /// <a href="../pepperc/ppb__image__data_8h.html">
50 /// <code>ppb_image_data.h</code></a> for further information.
[email protected]d0270d12011-06-23 22:01:5851 ///
[email protected]b15cce52011-07-06 20:44:3152 /// @param[in] size A pointer to a <code>Size</code> containing the image
53 /// size.
[email protected]d0270d12011-06-23 22:01:5854 ///
[email protected]b15cce52011-07-06 20:44:3155 /// @param[in] init_to_zero A bool used to determine transparency at
56 /// creation. Set the <code>init_to_zero</code> flag if you want the bitmap
57 /// initialized to transparent during the creation process. If this flag is
58 /// not set, the current contents of the bitmap will be undefined, and the
59 /// module should be sure to set all the pixels.
[email protected]09af0f72012-02-27 20:23:1960 ImageData(const InstanceHandle& instance,
[email protected]7ca87c22011-01-07 05:33:2061 PP_ImageDataFormat format,
[email protected]1758e882010-11-01 16:16:5062 const Size& size,
63 bool init_to_zero);
64
[email protected]b15cce52011-07-06 20:44:3165 /// This function decrements the reference count of this
66 /// <code>ImageData</code> and increments the reference count of the
67 /// <code>other</code> <code>ImageData</code>. This <code>ImageData</code>
68 /// shares the underlying image resource with <code>other</code>.
[email protected]d0270d12011-06-23 22:01:5869 ///
70 /// @param[in] other An other image data.
[email protected]b15cce52011-07-06 20:44:3171 ///
[email protected]d0270d12011-06-23 22:01:5872 /// @return A new image data context.
[email protected]1758e882010-11-01 16:16:5073 ImageData& operator=(const ImageData& other);
[email protected]1758e882010-11-01 16:16:5074
[email protected]dc893002012-11-01 23:54:2475 /// IsImageDataFormatSupported() returns <code>true</code> if the supplied
76 /// format is supported by the browser. Note:
77 /// <code>PP_IMAGEDATAFORMAT_BGRA_PREMUL</code> and
78 /// <code>PP_IMAGEDATAFORMAT_RGBA_PREMUL</code> formats are always supported.
79 /// Other image formats do not make this guarantee, and should be checked
80 /// first with IsImageDataFormatSupported() before using.
81 ///
82 /// @param[in] format Image data format.
83 ///
84 /// @return <code>true</code> if the format is supported by the browser.
85 static bool IsImageDataFormatSupported(PP_ImageDataFormat format);
86
[email protected]b15cce52011-07-06 20:44:3187 /// GetNativeImageDataFormat() determines the browser's preferred format for
88 /// images. Using this format guarantees no extra conversions will occur when
[email protected]d0270d12011-06-23 22:01:5889 /// painting.
90 ///
[email protected]b15cce52011-07-06 20:44:3191 /// @return <code>PP_ImageDataFormat</code> containing the preferred format.
[email protected]1758e882010-11-01 16:16:5092 static PP_ImageDataFormat GetNativeImageDataFormat();
93
[email protected]d0270d12011-06-23 22:01:5894 /// A getter function for returning the current format for images.
95 ///
[email protected]b15cce52011-07-06 20:44:3196 /// @return <code>PP_ImageDataFormat</code> containing the preferred format.
[email protected]1758e882010-11-01 16:16:5097 PP_ImageDataFormat format() const { return desc_.format; }
98
[email protected]d0270d12011-06-23 22:01:5899 /// A getter function for returning the image size.
100 ///
101 /// @return The image size in pixels.
[email protected]1758e882010-11-01 16:16:50102 pp::Size size() const { return desc_.size; }
[email protected]d0270d12011-06-23 22:01:58103
104 /// A getter function for returning the row width in bytes.
105 ///
106 /// @return The row width in bytes.
[email protected]1758e882010-11-01 16:16:50107 int32_t stride() const { return desc_.stride; }
108
[email protected]d0270d12011-06-23 22:01:58109 /// A getter function for returning a raw pointer to the image pixels.
110 ///
111 /// @return A raw pointer to the image pixels.
[email protected]1758e882010-11-01 16:16:50112 void* data() const { return data_; }
113
[email protected]d0270d12011-06-23 22:01:58114 /// This function is used retrieve the address of the given pixel for 32-bit
115 /// pixel formats.
116 ///
[email protected]b15cce52011-07-06 20:44:31117 /// @param[in] coord A <code>Point</code> representing the x and y
118 /// coordinates for a specific pixel.
119 ///
[email protected]d0270d12011-06-23 22:01:58120 /// @return The address for the pixel.
[email protected]1758e882010-11-01 16:16:50121 const uint32_t* GetAddr32(const Point& coord) const;
[email protected]d0270d12011-06-23 22:01:58122
123 /// This function is used retrieve the address of the given pixel for 32-bit
124 /// pixel formats.
125 ///
[email protected]b15cce52011-07-06 20:44:31126 /// @param[in] coord A <code>Point</code> representing the x and y
127 /// coordinates for a specific pixel.
128 ///
[email protected]d0270d12011-06-23 22:01:58129 /// @return The address for the pixel.
[email protected]1758e882010-11-01 16:16:50130 uint32_t* GetAddr32(const Point& coord);
131
132 private:
[email protected]09af0f72012-02-27 20:23:19133 void InitData();
[email protected]1758e882010-11-01 16:16:50134
135 PP_ImageDataDesc desc_;
136 void* data_;
137};
138
139} // namespace pp
140
141#endif // PPAPI_CPP_IMAGE_DATA_H_