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_H_
6#define PPAPI_CPP_COMPOSITOR_H_
7
8#include "ppapi/c/ppb_compositor.h"
9#include "ppapi/cpp/completion_callback.h"
10#include "ppapi/cpp/compositor_layer.h"
11#include "ppapi/cpp/resource.h"
12
13/// @file
14/// This file defines the API to create a compositor in the browser.
15namespace pp {
16
17/// The <code>Compositor</code> interface is used for setting
18/// <code>CompositorLayer</code> layers to the Chromium compositor for
19/// compositing. This allows a plugin to combine different sources of visual
20/// data efficiently, such as <code>ImageData</code> images and OpenGL textures.
21/// See also <code>CompositorLayer</code> for more information.
22class Compositor : public Resource {
23 public:
24  /// Default constructor for creating an is_null()
25  /// <code>Compositor</code> object.
26  Compositor();
27
28  /// A constructor for creating and initializing a compositor.
29  ///
30  /// On failure, the object will be is_null().
31  explicit Compositor(const InstanceHandle& instance);
32
33  /// The copy constructor for <code>Compositor</code>.
34  ///
35  /// @param[in] other A reference to a <code>Compositor</code>.
36  Compositor(const Compositor& other);
37
38  /// Constructs a <code>Compositor</code> from a <code>Resource</code>.
39  ///
40  /// @param[in] resource A <code>PPB_Compositor</code> resource.
41  explicit Compositor(const Resource& resource);
42
43  /// A constructor used when you have received a <code>PP_Resource</code> as a
44  /// return value that has had 1 ref added on behalf of the caller.
45  ///
46  /// @param[in] resource A <code>PPB_Compositor</code> resource.
47  Compositor(PassRef, PP_Resource resource);
48
49  /// Destructor.
50  ~Compositor();
51
52  /// Creates a new <code>CompositorLayer</code> and adds it to the end of the
53  /// layer stack. A <code>CompositorLayer</code> containing the layer is
54  /// returned. It is uninitialized, <code>SetColor()</code>,
55  /// <code>SetTexture</code> or <code>SetImage</code> should be used to
56  /// initialize it. The layer will appear above other pre-existing layers.
57  /// If <code>ResetLayers</code> is called or the <code>PPB_Compositor</code>
58  /// is released, the returned layer will be invalidated, and any further calls
59  /// on the layer will return <code>PP_ERROR_BADRESOURCE</code>.
60  ///
61  /// @return A <code>CompositorLayer</code> containing the compositor layer
62  /// resource.
63  CompositorLayer AddLayer();
64
65  /// Commits layers added by <code>AddLayer()</code> to the chromium
66  /// compositor.
67  ///
68  /// @param[in] cc A <code>CompletionCallback</code> to be called when
69  /// layers have been represented on screen.
70  ///
71  /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
72  int32_t CommitLayers(const CompletionCallback& cc);
73
74  /// Resets layers added by <code>AddLayer()</code>
75  ///
76  /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
77  int32_t ResetLayers();
78
79  /// Checks whether a <code>Resource</code> is a compositor, to test whether
80  /// it is appropriate for use with the <code>Compositor</code> constructor.
81  ///
82  /// @param[in] resource A <code>Resource</code> to test.
83  ///
84  /// @return True if <code>resource</code> is a compositor.
85  static bool IsCompositor(const Resource& resource);
86};
87
88}  // namespace pp
89
90#endif  // PPAPI_CPP_COMPOSITOR_H_
91