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 #ifndef PPAPI_CPP_COMPOSITOR_LAYER_H_ 6 #define PPAPI_CPP_COMPOSITOR_LAYER_H_ 7 8 #include "ppapi/c/ppb_compositor_layer.h" 9 #include "ppapi/cpp/graphics_3d.h" 10 #include "ppapi/cpp/image_data.h" 11 #include "ppapi/cpp/rect.h" 12 #include "ppapi/cpp/resource.h" 13 #include "ppapi/cpp/size.h" 14 15 namespace pp { 16 17 class CompositorLayer : public Resource { 18 public: 19 /// Default constructor for creating an is_null() 20 /// <code>CompositorLayer</code> object. 21 CompositorLayer(); 22 23 /// The copy constructor for <code>CompositorLayer</code>. 24 /// 25 /// @param[in] other A reference to a <code>CompositorLayer</code>. 26 CompositorLayer(const CompositorLayer& other); 27 28 /// Constructs a <code>CompositorLayer</code> from a <code>Resource</code>. 29 /// 30 /// @param[in] resource A <code>PPB_CompositorLayer</code> resource. 31 explicit CompositorLayer(const Resource& resource); 32 33 /// A constructor used when you have received a <code>PP_Resource</code> as a 34 /// return value that has had 1 ref added for you. 35 /// 36 /// @param[in] resource A <code>PPB_CompositorLayer</code> resource. 37 CompositorLayer(PassRef, PP_Resource resource); 38 39 /// Destructor. 40 ~CompositorLayer(); 41 42 /// Sets the color of a solid color layer. If the layer is uninitialized, it 43 /// will initialize the layer first, and then set its color. If the layer has 44 /// been initialized to another kind of layer, the layer will not be changed, 45 /// and <code>PP_ERROR_BADARGUMENT</code> will be returned. 46 /// 47 /// param[in] red A <code>float</code> for the red color component. It will be 48 /// clamped to [0, 1] 49 /// param[in] green A <code>float</code> for the green color component. 50 /// It will be clamped to [0, 1]. 51 /// param[in] blue A <code>float</code> for the blue color component. It will 52 /// be clamped to [0, 1]. 53 /// param[in] alpha A <code>float</code> for the alpha color component. 54 /// It will be clamped to [0, 1]. 55 /// param[in] size A <code>Size</code> for the size of the layer before 56 /// transform. 57 /// 58 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 59 int32_t SetColor(float red, 60 float green, 61 float blue, 62 float alpha, 63 const Size& size); 64 65 /// Sets the texture of a texture layer. If the layer is uninitialized, it 66 /// will initialize the layer first, and then set its texture. The source rect 67 /// will be set to ((0, 0), (1, 1)). If the layer has been initialized to 68 /// another kind of layer, the layer will not be changed, and 69 /// <code>PP_ERROR_BADARGUMENT</code> will be returned. 70 /// 71 /// param[in] context A <code>Graphics3D</code> corresponding to a graphics 3d 72 /// resource which owns the GL texture. 73 /// param[in] texture A GL texture object id. 74 /// param[in] size A <code>Size</code> for the size of the layer before 75 /// transform. 76 /// param[in] cc A <code>CompletionCallback</code> to be called when 77 /// the texture is released by Chromium compositor. 78 /// 79 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 80 int32_t SetTexture(const Graphics3D& context, 81 uint32_t texture, 82 const Size& size, 83 const CompletionCallback& cc); 84 85 /// Sets the image of an image layer. If the layer is uninitialized, it will 86 /// initiliaze the layer first, and then set the image of it. If the layer has 87 /// been initialized to another kind of layer, the layer will not be changed, 88 /// and <code>PP_ERROR_BADARGUMENT</code> will be returned. 89 /// 90 /// param[in] image_data A <code>PP_Resource</code> corresponding to an image 91 /// data resource. 92 /// param[in] cc A <code>CompletionCallback</code> to be called when 93 /// the image data is released by Chromium compositor. 94 /// 95 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 96 int32_t SetImage(const ImageData& image, 97 const CompletionCallback& callback); 98 99 /// Sets the image of an image layer. If the layer is uninitialized, it will 100 /// initialize the layer first, and then set its image. The layer size will 101 /// be set to the image's size. The source rect will be set to the full image. 102 /// If the layer has been initialized to another kind of layer, the layer will 103 /// not be changed, and <code>PP_ERROR_BADARGUMENT</code> will be returned. 104 /// 105 /// param[in] image_data A <code>ImageData</code> corresponding to an image 106 /// data resource. 107 /// param[in] size A <code>Size</code> for the size of the layer before 108 /// transform. 109 /// param[in] cc A <code>CompletionCallback</code> to be called when the image 110 /// data is released by Chromium compositor. 111 /// 112 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 113 int32_t SetImage(const ImageData& image, 114 const Size& size, 115 const CompletionCallback& callback); 116 117 /// Sets a clip rectangle for a compositor layer. The Chromium compositor 118 /// applies a transform matrix on the layer first, and then clips the layer 119 /// with the rectangle. 120 /// 121 /// param[in] rect The clip rectangle. The origin is top-left corner of 122 /// the plugin. 123 /// 124 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 125 int32_t SetClipRect(const Rect& rect); 126 127 /// Sets a transform matrix which is used to composite the layer. 128 /// 129 /// param[in] matrix A float array with 16 elements. The matrix is coloum 130 /// major. The default transform matrix is an identity matrix. 131 /// 132 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 133 int32_t SetTransform(const float matrix[16]); 134 135 /// Sets the opacity value which will be applied to the layer. The effective 136 /// value of each pixel is computed as: 137 /// 138 /// if (premult_alpha) 139 /// pixel.rgb = pixel.rgb * opacity; 140 /// pixel.a = pixel.a * opactiy; 141 /// 142 /// param[in] opacity A <code>float</code> for the opacity value. 143 /// The default value is 1.0f. 144 /// 145 ///@return An int32_t containing a result code from <code>pp_errors.h</code>. 146 int32_t SetOpacity(float opacity); 147 148 /// Sets the blend mode which is used to composite the layer. 149 /// 150 /// param[in] mode A <code>PP_BlendMode</code>. The default value is 151 /// <code>PP_BLENDMODE_SRC_OVER</code>. 152 /// 153 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 154 int32_t SetBlendMode(PP_BlendMode mode); 155 156 /// Sets a source rectangle for a texture layer or an image layer. 157 /// 158 /// param[in] rect A <code>FloatRect</code> for an area of the source to 159 /// consider. For a texture layer, rect is in uv coordinates. For an image 160 /// layer, rect is in pixels. If the rect is beyond the dimensions of the 161 /// texture or image, <code>PP_ERROR_BADARGUMENT</code> will be returned. 162 /// If the layer size does not match the source rect size, bilinear scaling 163 /// will be used. 164 /// 165 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 166 int32_t SetSourceRect(const FloatRect& rect); 167 168 /// Sets the premultiplied alpha for an texture layer. 169 /// 170 /// param[in] premult A <code>bool</code> with <code>true</code> if 171 /// pre-multiplied alpha is used. 172 /// 173 /// @return An int32_t containing a result code from <code>pp_errors.h</code>. 174 int32_t SetPremultipliedAlpha(bool premult); 175 176 /// Checks whether a <code>Resource</code> is a compositor layer, to test 177 /// whether it is appropriate for use with the <code>CompositorLayer</code> 178 /// constructor. 179 /// 180 /// @param[in] resource A <code>Resource</code> to test. 181 /// 182 /// @return True if <code>resource</code> is a compositor layer. 183 static bool IsCompositorLayer(const Resource& resource); 184 }; 185 186 } // namespace pp 187 188 #endif // PPAPI_CPP_COMPOSITOR_LAYER_H_ 189