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.
5 #ifndef PPAPI_CPP_COMPOSITOR_LAYER_H_
6 #define PPAPI_CPP_COMPOSITOR_LAYER_H_
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"
17 class CompositorLayer
: public Resource
{
19 /// Default constructor for creating an is_null()
20 /// <code>CompositorLayer</code> object.
23 /// The copy constructor for <code>CompositorLayer</code>.
25 /// @param[in] other A reference to a <code>CompositorLayer</code>.
26 CompositorLayer(const CompositorLayer
& other
);
28 /// Constructs a <code>CompositorLayer</code> from a <code>Resource</code>.
30 /// @param[in] resource A <code>PPB_CompositorLayer</code> resource.
31 explicit CompositorLayer(const Resource
& resource
);
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.
36 /// @param[in] resource A <code>PPB_CompositorLayer</code> resource.
37 CompositorLayer(PassRef
, PP_Resource resource
);
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.
47 /// param[in] red A <code>float</code> for the red color component. It will be
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
58 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
59 int32_t SetColor(float red
,
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.
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
76 /// param[in] cc A <code>CompletionCallback</code> to be called when
77 /// the texture is released by Chromium compositor.
79 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
80 int32_t SetTexture(const Graphics3D
& context
,
83 const CompletionCallback
& cc
);
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.
90 /// param[in] image_data A <code>PP_Resource</code> corresponding to an image
92 /// param[in] cc A <code>CompletionCallback</code> to be called when
93 /// the image data is released by Chromium compositor.
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
);
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.
105 /// param[in] image_data A <code>ImageData</code> corresponding to an image
107 /// param[in] size A <code>Size</code> for the size of the layer before
109 /// param[in] cc A <code>CompletionCallback</code> to be called when the image
110 /// data is released by Chromium compositor.
112 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
113 int32_t SetImage(const ImageData
& image
,
115 const CompletionCallback
& callback
);
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.
121 /// param[in] rect The clip rectangle. The origin is top-left corner of
124 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
125 int32_t SetClipRect(const Rect
& rect
);
127 /// Sets a transform matrix which is used to composite the layer.
129 /// param[in] matrix A float array with 16 elements. The matrix is coloum
130 /// major. The default transform matrix is an identity matrix.
132 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
133 int32_t SetTransform(const float matrix
[16]);
135 /// Sets the opacity value which will be applied to the layer. The effective
136 /// value of each pixel is computed as:
138 /// if (premult_alpha)
139 /// pixel.rgb = pixel.rgb * opacity;
140 /// pixel.a = pixel.a * opactiy;
142 /// param[in] opacity A <code>float</code> for the opacity value.
143 /// The default value is 1.0f.
145 ///@return An int32_t containing a result code from <code>pp_errors.h</code>.
146 int32_t SetOpacity(float opacity
);
148 /// Sets the blend mode which is used to composite the layer.
150 /// param[in] mode A <code>PP_BlendMode</code>. The default value is
151 /// <code>PP_BLENDMODE_SRC_OVER</code>.
153 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
154 int32_t SetBlendMode(PP_BlendMode mode
);
156 /// Sets a source rectangle for a texture layer or an image layer.
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
165 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
166 int32_t SetSourceRect(const FloatRect
& rect
);
168 /// Sets the premultiplied alpha for an texture layer.
170 /// param[in] premult A <code>bool</code> with <code>true</code> if
171 /// pre-multiplied alpha is used.
173 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
174 int32_t SetPremultipliedAlpha(bool premult
);
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>
180 /// @param[in] resource A <code>Resource</code> to test.
182 /// @return True if <code>resource</code> is a compositor layer.
183 static bool IsCompositorLayer(const Resource
& resource
);
188 #endif // PPAPI_CPP_COMPOSITOR_LAYER_H_