// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef PPAPI_CPP_COMPOSITOR_LAYER_H_ #define PPAPI_CPP_COMPOSITOR_LAYER_H_ #include "ppapi/c/ppb_compositor_layer.h" #include "ppapi/cpp/graphics_3d.h" #include "ppapi/cpp/image_data.h" #include "ppapi/cpp/rect.h" #include "ppapi/cpp/resource.h" #include "ppapi/cpp/size.h" namespace pp { class CompositorLayer : public Resource { public: /// Default constructor for creating an is_null() /// CompositorLayer object. CompositorLayer(); /// The copy constructor for CompositorLayer. /// /// @param[in] other A reference to a CompositorLayer. CompositorLayer(const CompositorLayer& other); /// Constructs a CompositorLayer from a Resource. /// /// @param[in] resource A PPB_CompositorLayer resource. explicit CompositorLayer(const Resource& resource); /// A constructor used when you have received a PP_Resource as a /// return value that has had 1 ref added for you. /// /// @param[in] resource A PPB_CompositorLayer resource. CompositorLayer(PassRef, PP_Resource resource); /// Destructor. ~CompositorLayer(); /// Sets the color of a solid color layer. If the layer is uninitialized, it /// will initialize the layer first, and then set its color. If the layer has /// been initialized to another kind of layer, the layer will not be changed, /// and PP_ERROR_BADARGUMENT will be returned. /// /// param[in] red A float for the red color component. It will be /// clamped to [0, 1] /// param[in] green A float for the green color component. /// It will be clamped to [0, 1]. /// param[in] blue A float for the blue color component. It will /// be clamped to [0, 1]. /// param[in] alpha A float for the alpha color component. /// It will be clamped to [0, 1]. /// param[in] size A Size for the size of the layer before /// transform. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetColor(float red, float green, float blue, float alpha, const Size& size); /// Sets the texture of a texture layer. If the layer is uninitialized, it /// will initialize the layer first, and then set its texture. The source rect /// will be set to ((0, 0), (1, 1)). If the layer has been initialized to /// another kind of layer, the layer will not be changed, and /// PP_ERROR_BADARGUMENT will be returned. /// /// param[in] context A Graphics3D corresponding to a graphics 3d /// resource which owns the GL texture. /// param[in] target GL texture target (GL_TEXTURE_2D, etc). /// param[in] texture A GL texture object id. /// param[in] size A Size for the size of the layer before /// transform. /// param[in] cc A CompletionCallback to be called when /// the texture is released by Chromium compositor. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetTexture(const Graphics3D& context, uint32_t target, uint32_t texture, const Size& size, const CompletionCallback& cc); /// Sets the image of an image layer. If the layer is uninitialized, it will /// initiliaze the layer first, and then set the image of it. If the layer has /// been initialized to another kind of layer, the layer will not be changed, /// and PP_ERROR_BADARGUMENT will be returned. /// /// param[in] image_data A PP_Resource corresponding to an image /// data resource. /// param[in] cc A CompletionCallback to be called when /// the image data is released by Chromium compositor. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetImage(const ImageData& image, const CompletionCallback& callback); /// Sets the image of an image layer. If the layer is uninitialized, it will /// initialize the layer first, and then set its image. The layer size will /// be set to the image's size. The source rect will be set to the full image. /// If the layer has been initialized to another kind of layer, the layer will /// not be changed, and PP_ERROR_BADARGUMENT will be returned. /// /// param[in] image_data A ImageData corresponding to an image /// data resource. /// param[in] size A Size for the size of the layer before /// transform. /// param[in] cc A CompletionCallback to be called when the image /// data is released by Chromium compositor. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetImage(const ImageData& image, const Size& size, const CompletionCallback& callback); /// Sets a clip rectangle for a compositor layer. The Chromium compositor /// applies a transform matrix on the layer first, and then clips the layer /// with the rectangle. /// /// param[in] rect The clip rectangle. The origin is top-left corner of /// the plugin. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetClipRect(const Rect& rect); /// Sets a transform matrix which is used to composite the layer. /// /// param[in] matrix A float array with 16 elements. The matrix is coloum /// major. The default transform matrix is an identity matrix. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetTransform(const float matrix[16]); /// Sets the opacity value which will be applied to the layer. The effective /// value of each pixel is computed as: /// /// if (premult_alpha) /// pixel.rgb = pixel.rgb * opacity; /// pixel.a = pixel.a * opactiy; /// /// param[in] opacity A float for the opacity value. /// The default value is 1.0f. /// ///@return An int32_t containing a result code from pp_errors.h. int32_t SetOpacity(float opacity); /// Sets the blend mode which is used to composite the layer. /// /// param[in] mode A PP_BlendMode. The default value is /// PP_BLENDMODE_SRC_OVER. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetBlendMode(PP_BlendMode mode); /// Sets a source rectangle for a texture layer or an image layer. /// /// param[in] rect A FloatRect for an area of the source to /// consider. For a texture layer, rect is in uv coordinates. For an image /// layer, rect is in pixels. If the rect is beyond the dimensions of the /// texture or image, PP_ERROR_BADARGUMENT will be returned. /// If the layer size does not match the source rect size, bilinear scaling /// will be used. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetSourceRect(const FloatRect& rect); /// Sets the premultiplied alpha for an texture layer. /// /// param[in] premult A bool with true if /// pre-multiplied alpha is used. /// /// @return An int32_t containing a result code from pp_errors.h. int32_t SetPremultipliedAlpha(bool premult); /// Checks whether a Resource is a compositor layer, to test /// whether it is appropriate for use with the CompositorLayer /// constructor. /// /// @param[in] resource A Resource to test. /// /// @return True if resource is a compositor layer. static bool IsCompositorLayer(const Resource& resource); }; } // namespace pp #endif // PPAPI_CPP_COMPOSITOR_LAYER_H_