[email protected] | 6ea6954 | 2010-12-20 18:15:59 | [diff] [blame] | 1 | /* Copyright (c) 2010 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 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 5 | #ifndef PPAPI_C_PPB_IMAGE_DATA_H_ |
| 6 | #define PPAPI_C_PPB_IMAGE_DATA_H_ |
| 7 | |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 8 | #include "ppapi/c/pp_bool.h" |
[email protected] | 7ca87c2 | 2011-01-07 05:33:20 | [diff] [blame] | 9 | #include "ppapi/c/pp_instance.h" |
[email protected] | 1ad2a1db | 2010-12-13 20:04:31 | [diff] [blame] | 10 | #include "ppapi/c/pp_macros.h" |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 11 | #include "ppapi/c/pp_module.h" |
| 12 | #include "ppapi/c/pp_resource.h" |
| 13 | #include "ppapi/c/pp_size.h" |
| 14 | #include "ppapi/c/pp_stdint.h" |
| 15 | |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 16 | /** |
| 17 | * @file |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 18 | * This file defines the PPB_ImageData struct for determining how a browser |
| 19 | * handles image data. |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @addtogroup Enums |
| 24 | * @{ |
| 25 | */ |
| 26 | |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 27 | /** |
| 28 | * PP_ImageDataFormat is an enumeration of the different types of |
| 29 | * image data formats. |
[email protected] | 7af3e12 | 2011-03-23 18:23:57 | [diff] [blame] | 30 | * |
| 31 | * The third part of each enumeration value describes the memory layout from |
| 32 | * the lowest address to the highest. For example, BGRA means the B component |
| 33 | * is stored in the lowest address, no matter what endianness the platform is |
| 34 | * using. |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 35 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 36 | typedef enum { |
| 37 | PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 38 | PP_IMAGEDATAFORMAT_RGBA_PREMUL |
| 39 | } PP_ImageDataFormat; |
[email protected] | 1ad2a1db | 2010-12-13 20:04:31 | [diff] [blame] | 40 | PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_ImageDataFormat, 4); |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 41 | /** |
| 42 | * @} |
| 43 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 44 | |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 45 | /** |
| 46 | * @addtogroup Structs |
| 47 | * @{ |
| 48 | */ |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * The PP_ImageDataDesc structure represents a description of image data. |
| 52 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 53 | struct PP_ImageDataDesc { |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * This value represents one of the image data types in the |
| 57 | * PP_ImageDataFormat enum. |
| 58 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 59 | PP_ImageDataFormat format; |
| 60 | |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 61 | /** This value represents the size of the bitmap in pixels. */ |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 62 | struct PP_Size size; |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 63 | |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 64 | /** |
| 65 | * This value represents the row width in bytes. This may be different than |
| 66 | * width * 4 since there may be padding at the end of the lines. |
[email protected] | 6ea6954 | 2010-12-20 18:15:59 | [diff] [blame] | 67 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 68 | int32_t stride; |
| 69 | }; |
[email protected] | 1ad2a1db | 2010-12-13 20:04:31 | [diff] [blame] | 70 | PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_ImageDataDesc, 16); |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 71 | /** |
| 72 | * @} |
| 73 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 74 | |
[email protected] | 7ca87c2 | 2011-01-07 05:33:20 | [diff] [blame] | 75 | #define PPB_IMAGEDATA_INTERFACE "PPB_ImageData;0.3" |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 76 | |
| 77 | /** |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 78 | * @addtogroup Interfaces |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 79 | * @{ |
| 80 | */ |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * The PPB_ImageData interface contains pointers to several functions for |
| 84 | * determining the browser's treatment of image data. |
| 85 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 86 | struct PPB_ImageData { |
| 87 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 88 | * GetNativeImageDataFormat is a pointer to a function that returns the |
| 89 | * browser's preferred format for image data. The browser uses this format |
| 90 | * internally for painting. Other formats may require internal conversions |
| 91 | * to paint or may have additional restrictions depending on the function. |
| 92 | * |
| 93 | * @return PP_ImageDataFormat containing the preferred format. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 94 | */ |
| 95 | PP_ImageDataFormat (*GetNativeImageDataFormat)(); |
| 96 | |
| 97 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 98 | * IsImageDataFormatSupported is a pointer to a function that determines if |
| 99 | * the given image data format is supported by the browser. |
| 100 | * |
| 101 | * @param[in] format The image data format. |
| 102 | * @return PP_Bool with PP_TRUE if the given image data format is supported |
| 103 | * by the browser. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 104 | */ |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 105 | PP_Bool (*IsImageDataFormatSupported)(PP_ImageDataFormat format); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 106 | |
| 107 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 108 | * Create is a pointer to a function that allocates an image data resource |
| 109 | * with the given format and size. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 110 | * |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 111 | * For security reasons, if uninitialized, the bitmap will not contain random |
| 112 | * memory, but may contain data from a previous image produced by the same |
| 113 | * plugin if the bitmap was cached and re-used. |
| 114 | * |
| 115 | * @param[in] instance A PP_Instance indentifying one instance of a module. |
| 116 | * @param[in] format The desired image data format. |
| 117 | * @param[in] size A pointer to a PP_Size containing the image size. |
| 118 | * @param[in] init_to_zero A PP_Bool to determine transparency at creation. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 119 | * Set the init_to_zero flag if you want the bitmap initialized to |
| 120 | * transparent during the creation process. If this flag is not set, the |
| 121 | * current contents of the bitmap will be undefined, and the plugin should |
| 122 | * be sure to set all the pixels. |
| 123 | * |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 124 | * @return A PP_Resource with a nonzero ID on succes or zero on failure. |
| 125 | * Failure means the instance, image size, or format was invalid. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 126 | */ |
[email protected] | 7ca87c2 | 2011-01-07 05:33:20 | [diff] [blame] | 127 | PP_Resource (*Create)(PP_Instance instance, |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 128 | PP_ImageDataFormat format, |
| 129 | const struct PP_Size* size, |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 130 | PP_Bool init_to_zero); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 131 | |
| 132 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 133 | * IsImageData is a pointer to a function that determiens if a given resource |
| 134 | * is image data. |
| 135 | * |
| 136 | * @param[in] image_data A PP_Resource corresponding to image data. |
| 137 | * @return A PP_Bool with PP_TRUE if the given resrouce is an image data |
| 138 | * or PP_FALSE if the resource is invalid or some type other than image data. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 139 | */ |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 140 | PP_Bool (*IsImageData)(PP_Resource image_data); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 141 | |
| 142 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 143 | * Describe is a pointer to a function that computes the description of the |
| 144 | * image data. |
| 145 | * |
| 146 | * @param[in] image_data A PP_Resource corresponding to image data. |
| 147 | * @param[in/out] desc A pointer to a PP_ImageDataDesc containing the |
| 148 | * description. |
| 149 | * @return A PP_Bool with PP_TRUE on success or PP_FALSE |
| 150 | * if the resource is not an image data. On PP_FALSE, the |desc| |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 151 | * structure will be filled with 0. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 152 | */ |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 153 | PP_Bool (*Describe)(PP_Resource image_data, |
| 154 | struct PP_ImageDataDesc* desc); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 155 | |
| 156 | /** |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 157 | * Map is a pointer to a function that maps an image data into the plugin |
| 158 | * address space. |
| 159 | * |
| 160 | * @param[in] image_data A PP_Resource corresponding to image data. |
| 161 | * @return A pointer to the beginning of the data. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 162 | */ |
| 163 | void* (*Map)(PP_Resource image_data); |
| 164 | |
[email protected] | 5651386f | 2011-03-09 23:25:53 | [diff] [blame] | 165 | /** |
| 166 | * Unmap is a pointer to a function that unmaps an image data from the plugin |
| 167 | * address space. |
| 168 | * |
| 169 | * @param[in] image_data A PP_Resource corresponding to image data. |
| 170 | */ |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 171 | void (*Unmap)(PP_Resource image_data); |
| 172 | }; |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 173 | /** |
| 174 | * @} |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 175 | */ |
[email protected] | 040d5e8 | 2011-01-28 15:38:38 | [diff] [blame] | 176 | |
[email protected] | 6ea6954 | 2010-12-20 18:15:59 | [diff] [blame] | 177 | #endif /* PPAPI_C_PPB_IMAGE_DATA_H_ */ |