• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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] target GL texture target (GL_TEXTURE_2D, etc).
74   /// param[in] texture A GL texture object id.
75   /// param[in] size A <code>Size</code> for the size of the layer before
76   /// transform.
77   /// param[in] cc A <code>CompletionCallback</code> to be called when
78   /// the texture is released by Chromium compositor.
79   ///
80   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
81   int32_t SetTexture(const Graphics3D& context,
82                      uint32_t target,
83                      uint32_t texture,
84                      const Size& size,
85                      const CompletionCallback& cc);
86 
87   /// Sets the image of an image layer. If the layer is uninitialized, it will
88   /// initiliaze the layer first, and then set the image of it. If the layer has
89   /// been initialized to another kind of layer, the layer will not be changed,
90   /// and <code>PP_ERROR_BADARGUMENT</code> will be returned.
91   ///
92   /// param[in] image_data A <code>PP_Resource</code> corresponding to an image
93   /// data resource.
94   /// param[in] cc A <code>CompletionCallback</code> to be called when
95   /// the image data is released by Chromium compositor.
96   ///
97   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
98   int32_t SetImage(const ImageData& image,
99                    const CompletionCallback& callback);
100 
101   /// Sets the image of an image layer. If the layer is uninitialized, it will
102   /// initialize the layer first, and then set its image. The layer size will
103   /// be set to the image's size. The source rect will be set to the full image.
104   /// If the layer has been initialized to another kind of layer, the layer will
105   /// not be changed, and <code>PP_ERROR_BADARGUMENT</code> will be returned.
106   ///
107   /// param[in] image_data A <code>ImageData</code> corresponding to an image
108   /// data resource.
109   /// param[in] size A <code>Size</code> for the size of the layer before
110   /// transform.
111   /// param[in] cc A <code>CompletionCallback</code> to be called when the image
112   /// data is released by Chromium compositor.
113   ///
114   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
115   int32_t SetImage(const ImageData& image,
116                    const Size& size,
117                    const CompletionCallback& callback);
118 
119   /// Sets a clip rectangle for a compositor layer. The Chromium compositor
120   /// applies a transform matrix on the layer first, and then clips the layer
121   /// with the rectangle.
122   ///
123   /// param[in] rect The clip rectangle. The origin is top-left corner of
124   /// the plugin.
125   ///
126   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
127   int32_t SetClipRect(const Rect& rect);
128 
129   /// Sets a transform matrix which is used to composite the layer.
130   ///
131   /// param[in] matrix A float array with 16 elements. The matrix is coloum
132   /// major. The default transform matrix is an identity matrix.
133   ///
134   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
135   int32_t SetTransform(const float matrix[16]);
136 
137   /// Sets the opacity value which will be applied to the layer. The effective
138   /// value of each pixel is computed as:
139   ///
140   ///   if (premult_alpha)
141   ///     pixel.rgb = pixel.rgb * opacity;
142   ///   pixel.a = pixel.a * opactiy;
143   ///
144   /// param[in] opacity A <code>float</code> for the opacity value.
145   /// The default value is 1.0f.
146   ///
147   ///@return An int32_t containing a result code from <code>pp_errors.h</code>.
148   int32_t SetOpacity(float opacity);
149 
150   /// Sets the blend mode which is used to composite the layer.
151   ///
152   /// param[in] mode A <code>PP_BlendMode</code>. The default value is
153   /// <code>PP_BLENDMODE_SRC_OVER</code>.
154   ///
155   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
156   int32_t SetBlendMode(PP_BlendMode mode);
157 
158   /// Sets a source rectangle for a texture layer or an image layer.
159   ///
160   /// param[in] rect A <code>FloatRect</code> for an area of the source to
161   /// consider. For a texture layer, rect is in uv coordinates. For an image
162   /// layer, rect is in pixels. If the rect is beyond the dimensions of the
163   /// texture or image, <code>PP_ERROR_BADARGUMENT</code> will be returned.
164   /// If the layer size does not match the source rect size, bilinear scaling
165   /// will be used.
166   ///
167   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
168   int32_t SetSourceRect(const FloatRect& rect);
169 
170   /// Sets the premultiplied alpha for an texture layer.
171   ///
172   /// param[in] premult A <code>bool</code> with <code>true</code> if
173   /// pre-multiplied alpha is used.
174   ///
175   /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
176   int32_t SetPremultipliedAlpha(bool premult);
177 
178   /// Checks whether a <code>Resource</code> is a compositor layer, to test
179   /// whether it is appropriate for use with the <code>CompositorLayer</code>
180   /// constructor.
181   ///
182   /// @param[in] resource A <code>Resource</code> to test.
183   ///
184   /// @return True if <code>resource</code> is a compositor layer.
185   static bool IsCompositorLayer(const Resource& resource);
186 };
187 
188 }  // namespace pp
189 
190 #endif  // PPAPI_CPP_COMPOSITOR_LAYER_H_
191