[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 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 |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 6 | /** |
| 7 | * This file defines the <code>PPB_ImageData</code> struct for determining how |
| 8 | * a browser handles image data. |
| 9 | */ |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 10 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 11 | label Chrome { |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 12 | M14 = 1.0 |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * <code>PP_ImageDataFormat</code> is an enumeration of the different types of |
| 17 | * image data formats. |
| 18 | * |
| 19 | * The third part of each enumeration value describes the memory layout from |
| 20 | * the lowest address to the highest. For example, BGRA means the B component |
| 21 | * is stored in the lowest address, no matter what endianness the platform is |
| 22 | * using. |
| 23 | * |
| 24 | * The PREMUL suffix implies pre-multiplied alpha is used. In this mode, the |
| 25 | * red, green and blue color components of the pixel data supplied to an image |
| 26 | * data should be pre-multiplied by their alpha value. For example: starting |
| 27 | * with floating point color components, here is how to convert them to 8-bit |
| 28 | * premultiplied components for image data: |
| 29 | * |
| 30 | * ...components of a pixel, floats ranging from 0 to 1... |
| 31 | * <code>float red = 1.0f;</code> |
[email protected] | e6ce5e42 | 2011-08-15 17:23:14 | [diff] [blame] | 32 | * <code>float green = 0.50f;</code> |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 33 | * <code>float blue = 0.0f;</code> |
| 34 | * <code>float alpha = 0.75f;</code> |
| 35 | * ...components for image data are 8-bit values ranging from 0 to 255... |
| 36 | * <code>uint8_t image_data_red_premul = (uint8_t)(red * alpha * 255.0f); |
| 37 | * </code> |
| 38 | * <code>uint8_t image_data_green_premul = (uint8_t)(green * alpha * 255.0f); |
| 39 | * </code> |
| 40 | * <code>uint8_t image_data_blue_premul = (uint8_t)(blue * alpha * 255.0f); |
| 41 | * </code> |
| 42 | * <code>uint8_t image_data_alpha_premul = (uint8_t)(alpha * 255.0f);</code> |
| 43 | * |
| 44 | * <strong>Note:</strong> The resulting pre-multiplied red, green and blue |
| 45 | * components should not be greater than the alpha value. |
| 46 | */ |
| 47 | [assert_size(4)] |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 48 | enum PP_ImageDataFormat { |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 49 | PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 50 | PP_IMAGEDATAFORMAT_RGBA_PREMUL |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 53 | /** |
| 54 | * The <code>PP_ImageDataDesc</code> structure represents a description of |
| 55 | * image data. |
| 56 | */ |
| 57 | [assert_size(16)] |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 58 | struct PP_ImageDataDesc { |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 59 | /** |
| 60 | * This value represents one of the image data types in the |
| 61 | * <code>PP_ImageDataFormat</code> enum. |
| 62 | */ |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 63 | PP_ImageDataFormat format; |
| 64 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 65 | /** This value represents the size of the bitmap in pixels. */ |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 66 | PP_Size size; |
| 67 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 68 | /** |
| 69 | * This value represents the row width in bytes. This may be different than |
| 70 | * width * 4 since there may be padding at the end of the lines. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 71 | */ |
| 72 | int32_t stride; |
| 73 | }; |
| 74 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 75 | /** |
| 76 | * The <code>PPB_ImageData</code> interface contains pointers to several |
| 77 | * functions for determining the browser's treatment of image data. |
| 78 | */ |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 79 | interface PPB_ImageData { |
| 80 | /** |
| 81 | * GetNativeImageDataFormat() returns the browser's preferred format for |
| 82 | * image data. The browser uses this format internally for painting. Other |
| 83 | * formats may require internal conversions to paint or may have additional |
| 84 | * restrictions depending on the function. |
| 85 | * |
| 86 | * @return A <code>PP_ImageDataFormat</code> containing the preferred format. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 87 | */ |
| 88 | PP_ImageDataFormat GetNativeImageDataFormat(); |
| 89 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 90 | /** |
| 91 | * IsImageDataFormatSupported() determines if the given image data format is |
| 92 | * supported by the browser. |
| 93 | * |
| 94 | * @param[in] format The image data format. |
| 95 | * |
| 96 | * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given |
| 97 | * image data format is supported by the browser. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 98 | */ |
| 99 | PP_Bool IsImageDataFormatSupported( |
| 100 | [in] PP_ImageDataFormat format); |
| 101 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 102 | /** |
| 103 | * Create() allocates an image data resource with the given format and size. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 104 | * |
| 105 | * For security reasons, if uninitialized, the bitmap will not contain random |
| 106 | * memory, but may contain data from a previous image produced by the same |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 107 | * module if the bitmap was cached and re-used. |
| 108 | * |
[email protected] | e12a6a1 | 2011-08-31 16:07:59 | [diff] [blame] | 109 | * @param[in] instance A <code>PP_Instance</code> identifying one instance |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 110 | * of a module. |
| 111 | * @param[in] format The desired image data format. |
| 112 | * @param[in] size A pointer to a <code>PP_Size</code> containing the image |
| 113 | * size. |
| 114 | * @param[in] init_to_zero A <code>PP_Bool</code> to determine transparency |
| 115 | * at creation. |
| 116 | * Set the <code>init_to_zero</code> flag if you want the bitmap initialized |
| 117 | * to transparent during the creation process. If this flag is not set, the |
| 118 | * current contents of the bitmap will be undefined, and the module should |
| 119 | * be sure to set all the pixels. |
| 120 | * |
[email protected] | e12a6a1 | 2011-08-31 16:07:59 | [diff] [blame] | 121 | * @return A <code>PP_Resource</code> with a nonzero ID on success or zero on |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 122 | * failure. Failure means the instance, image size, or format was invalid. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 123 | */ |
| 124 | PP_Resource Create( |
| 125 | [in] PP_Instance instance, |
| 126 | [in] PP_ImageDataFormat format, |
| 127 | [in] PP_Size size, |
| 128 | [in] PP_Bool init_to_zero); |
| 129 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 130 | /** |
[email protected] | c896ec11 | 2011-12-21 22:00:48 | [diff] [blame^] | 131 | * IsImageData() determines if a given resource is image data. |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 132 | * |
| 133 | * @param[in] image_data A <code>PP_Resource</code> corresponding to image |
| 134 | * data. |
| 135 | * |
| 136 | * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given |
[email protected] | c896ec11 | 2011-12-21 22:00:48 | [diff] [blame^] | 137 | * resource is an image data or <code>PP_FALSE</code> if the resource is |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 138 | * invalid or some type other than image data. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 139 | */ |
| 140 | PP_Bool IsImageData( |
| 141 | [in] PP_Resource image_data); |
| 142 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 143 | /** |
| 144 | * Describe() computes the description of the |
| 145 | * image data. |
| 146 | * |
| 147 | * @param[in] image_data A <code>PP_Resource</code> corresponding to image |
| 148 | * data. |
| 149 | * @param[in,out] desc A pointer to a <code>PP_ImageDataDesc</code> |
| 150 | * containing the description. |
| 151 | * |
| 152 | * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> on success or |
| 153 | * <code>PP_FALSE</code> if the resource is not an image data. On |
| 154 | * <code>PP_FALSE</code>, the <code>desc</code> structure will be filled |
| 155 | * with 0. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 156 | */ |
| 157 | PP_Bool Describe( |
| 158 | [in] PP_Resource image_data, |
| 159 | [out] PP_ImageDataDesc desc); |
| 160 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 161 | /** |
| 162 | * Map() maps an image data into the module address space. |
| 163 | * |
| 164 | * @param[in] image_data A <code>PP_Resource</code> corresponding to image |
| 165 | * data. |
| 166 | * |
| 167 | * @return A pointer to the beginning of the data. |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 168 | */ |
| 169 | mem_t Map( |
| 170 | [in] PP_Resource image_data); |
| 171 | |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 172 | /** |
| 173 | * Unmap is a pointer to a function that unmaps an image data from the module |
| 174 | * address space. |
| 175 | * |
| 176 | * @param[in] image_data A <code>PP_Resource</code> corresponding to image |
| 177 | * data. |
| 178 | */ |
[email protected] | 2272ed3 | 2011-03-30 17:37:54 | [diff] [blame] | 179 | void Unmap( |
| 180 | [in] PP_Resource image_data); |
| 181 | }; |
[email protected] | 745b0d4 | 2011-07-16 23:53:22 | [diff] [blame] | 182 | |