1 /* Copyright 2014 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 6 /* From ppb_compositor_layer.idl modified Thu Aug 14 18:06:33 2014. */ 7 8 #ifndef PPAPI_C_PPB_COMPOSITOR_LAYER_H_ 9 #define PPAPI_C_PPB_COMPOSITOR_LAYER_H_ 10 11 #include "ppapi/c/pp_bool.h" 12 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_macros.h" 14 #include "ppapi/c/pp_point.h" 15 #include "ppapi/c/pp_rect.h" 16 #include "ppapi/c/pp_resource.h" 17 #include "ppapi/c/pp_size.h" 18 #include "ppapi/c/pp_stdint.h" 19 20 #define PPB_COMPOSITORLAYER_INTERFACE_0_1 "PPB_CompositorLayer;0.1" /* dev */ 21 #define PPB_COMPOSITORLAYER_INTERFACE_0_2 "PPB_CompositorLayer;0.2" /* dev */ 22 /** 23 * @file 24 */ 25 26 27 /** 28 * @addtogroup Enums 29 * @{ 30 */ 31 /** 32 * This enumeration contains blend modes used for computing the result pixels 33 * based on the source RGBA values in layers with the RGBA values that are 34 * already in the destination framebuffer. 35 * alpha_src, color_src: source alpha and color. 36 * alpha_dst, color_dst: destination alpha and color (before compositing). 37 * Below descriptions of the blend modes assume the colors are pre-multiplied. 38 * This interface is still in development (Dev API status) and may change, 39 * so is only supported on Dev channel and Canary currently. 40 */ 41 typedef enum { 42 /** 43 * No blending, copy source to the destination directly. 44 */ 45 PP_BLENDMODE_NONE, 46 /** 47 * Source is placed over the destination. 48 * Resulting alpha = alpha_src + alpha_dst - alpha_src * alpha_dst 49 * Resulting color = color_src + color_dst * (1 - alpha_src) 50 */ 51 PP_BLENDMODE_SRC_OVER, 52 /** 53 * The last blend mode. 54 */ 55 PP_BLENDMODE_LAST = PP_BLENDMODE_SRC_OVER 56 } PP_BlendMode; 57 /** 58 * @} 59 */ 60 61 /** 62 * @addtogroup Interfaces 63 * @{ 64 */ 65 /** 66 * Defines the <code>PPB_CompositorLayer</code> interface. It is used by 67 * <code>PPB_Compositor</code>. 68 */ 69 struct PPB_CompositorLayer_0_2 { /* dev */ 70 /** 71 * Determines if a resource is a compositor layer resource. 72 * 73 * @param[in] resource The <code>PP_Resource</code> to test. 74 * 75 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given 76 * resource is a compositor layer resource or <code>PP_FALSE</code> 77 * otherwise. 78 */ 79 PP_Bool (*IsCompositorLayer)(PP_Resource resource); 80 /** 81 * Sets the color of a solid color layer. If the layer is uninitialized, 82 * it will initialize the layer first, and then set its color. 83 * If the layer has been initialized to another kind of layer, the layer will 84 * not be changed, and <code>PP_ERROR_BADARGUMENT</code> will be returned. 85 * 86 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 87 * layer resource. 88 * param[in] red A <code>float</code> for the red color component. It will be 89 * clamped to [0, 1]. 90 * param[in] green A <code>float</code> for the green color component. It will 91 * be clamped to [0, 1]. 92 * param[in] blue A <code>float</code> for the blue color component. It will 93 * be clamped to [0, 1]. 94 * param[in] alpha A <code>float</code> for the alpha color component. It will 95 * be clamped to [0, 1]. 96 * param[in] size A <code>PP_Size</code> for the size of the layer before 97 * transform. 98 * 99 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 100 */ 101 int32_t (*SetColor)(PP_Resource layer, 102 float red, 103 float green, 104 float blue, 105 float alpha, 106 const struct PP_Size* size); 107 /** 108 * Sets the texture of a texture layer. If the layer is uninitialized, 109 * it will initialize the layer first, and then set its texture. 110 * The source rect will be set to ((0, 0), (1, 1)). If the layer has been 111 * initialized to another kind of layer, the layer will not be changed, 112 * and <code>PP_ERROR_BADARGUMENT</code> will be returned. 113 * 114 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 115 * layer resource. 116 * param[in] context A <code>PP_Resource</code> corresponding to a graphics 117 * 3d resource which owns the GL texture. 118 * param[in] target GL texture target (GL_TEXTURE_2D, etc). 119 * param[in] texture A GL texture object id. 120 * param[in] size A <code>PP_Size</code> for the size of the layer before 121 * transform. 122 * param[in] cc A <code>PP_CompletionCallback</code> to be called when 123 * the texture is released by Chromium compositor. 124 * 125 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 126 */ 127 int32_t (*SetTexture)(PP_Resource layer, 128 PP_Resource context, 129 uint32_t target, 130 uint32_t texture, 131 const struct PP_Size* size, 132 struct PP_CompletionCallback cc); 133 /** 134 * Sets the image of an image layer. If the layer is uninitialized, 135 * it will initialize the layer first, and then set its image. 136 * The layer size will be set to the image's size. The source rect will be set 137 * to the full image. If the layer has been initialized to another kind of 138 * layer, the layer will not be changed, and <code>PP_ERROR_BADARGUMENT</code> 139 * will be returned. 140 * 141 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 142 * layer resource. 143 * param[in] image_data A <code>PP_Resource</code> corresponding to 144 * an image data resource. 145 * param[in] size A <code>PP_Size</code> for the size of the layer before 146 * transform. If NULL, the image's size will be used. 147 * param[in] cc A <code>PP_CompletionCallback</code> to be called when 148 * the image data is released by Chromium compositor. 149 * 150 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 151 */ 152 int32_t (*SetImage)(PP_Resource layer, 153 PP_Resource image_data, 154 const struct PP_Size* size, 155 struct PP_CompletionCallback cc); 156 /** 157 * Sets a clip rectangle for a compositor layer. The Chromium compositor 158 * applies a transform matrix on the layer first, and then clips the layer 159 * with the rectangle. 160 * 161 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 162 * layer resource. 163 * param[in] rect The clip rectangle. The origin is top-left corner of 164 * the plugin. 165 * 166 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 167 */ 168 int32_t (*SetClipRect)(PP_Resource layer, const struct PP_Rect* rect); 169 /** 170 * Sets a transform matrix which is used to composite the layer. 171 * 172 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 173 * layer resource. 174 * param[in] matrix A float array with 16 elements. The matrix is 175 * column major. The default transform matrix is an identity matrix. 176 * 177 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 178 */ 179 int32_t (*SetTransform)(PP_Resource layer, const float matrix[16]); 180 /** 181 * Sets the opacity value which will be applied to the layer. The effective 182 * value of each pixel is computed as: 183 * 184 * if (premult_alpha) 185 * pixel.rgb = pixel.rgb * opacity; 186 * pixel.a = pixel.a * opactiy; 187 * 188 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 189 * layer resource. 190 * param[in] opacity A <code>float</code> for the opacity value, The default 191 * value is 1.0f. 192 * 193 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 194 */ 195 int32_t (*SetOpacity)(PP_Resource layer, float opacity); 196 /** 197 * Sets the blend mode which is used to composite the layer. 198 * 199 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 200 * layer resource. 201 * param[in] mode A <code>PP_BlendMode</code>. The default mode is 202 * <code>PP_BLENDMODE_SRC_OVER</code>. 203 * 204 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 205 */ 206 int32_t (*SetBlendMode)(PP_Resource layer, PP_BlendMode mode); 207 /** 208 * Sets a source rectangle for a texture layer or an image layer. 209 * 210 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 211 * layer resource. 212 * param[in] rect A <code>PP_FloatRect</code> for an area of the source to 213 * consider. For a texture layer, rect is in uv coordinates. For an image 214 * layer, rect is in pixels. If the rect is beyond the dimensions of the 215 * texture or image, <code>PP_ERROR_BADARGUMENT</code> will be returned. 216 * If the layer size does not match the source rect size, bilinear scaling 217 * will be used. 218 * 219 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 220 */ 221 int32_t (*SetSourceRect)(PP_Resource layer, const struct PP_FloatRect* rect); 222 /** 223 * Sets the premultiplied alpha for an texture layer. 224 * 225 * param[in] layer A <code>PP_Resource</code> corresponding to a compositor 226 * layer resource. 227 * param[in] premult A <code>PP_Bool</code> with <code>PP_TRUE</code> if 228 * pre-multiplied alpha is used. 229 * 230 * @return An int32_t containing a result code from <code>pp_errors.h</code>. 231 */ 232 int32_t (*SetPremultipliedAlpha)(PP_Resource layer, PP_Bool premult); 233 }; 234 235 struct PPB_CompositorLayer_0_1 { /* dev */ 236 PP_Bool (*IsCompositorLayer)(PP_Resource resource); 237 int32_t (*SetColor)(PP_Resource layer, 238 float red, 239 float green, 240 float blue, 241 float alpha, 242 const struct PP_Size* size); 243 int32_t (*SetTexture)(PP_Resource layer, 244 PP_Resource context, 245 uint32_t texture, 246 const struct PP_Size* size, 247 struct PP_CompletionCallback cc); 248 int32_t (*SetImage)(PP_Resource layer, 249 PP_Resource image_data, 250 const struct PP_Size* size, 251 struct PP_CompletionCallback cc); 252 int32_t (*SetClipRect)(PP_Resource layer, const struct PP_Rect* rect); 253 int32_t (*SetTransform)(PP_Resource layer, const float matrix[16]); 254 int32_t (*SetOpacity)(PP_Resource layer, float opacity); 255 int32_t (*SetBlendMode)(PP_Resource layer, PP_BlendMode mode); 256 int32_t (*SetSourceRect)(PP_Resource layer, const struct PP_FloatRect* rect); 257 int32_t (*SetPremultipliedAlpha)(PP_Resource layer, PP_Bool premult); 258 }; 259 /** 260 * @} 261 */ 262 263 #endif /* PPAPI_C_PPB_COMPOSITOR_LAYER_H_ */ 264 265