blob: b162f4a2d619c45bec2590446431f677a5bc0a76 [file] [log] [blame]
Zach Reiznerc10555d2015-04-01 16:11:14 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef DRM_HWCOMPOSER_COMPOSITOR_H_
18#define DRM_HWCOMPOSER_COMPOSITOR_H_
19
20struct hwc_layer_1;
21struct hwc_drm_bo;
22
23namespace android {
24
25class GraphicBuffer;
26template <typename T>
27class sp;
28
29class Targeting {
30 public:
31 // Prepares the given framebuffer for use as output of this compositor. On
32 // success, takes a reference to the given buffer and returns a non- negative
33 // integer that is used as a handle to the prepared target. On failure,
34 // returns a negative integer.
35 virtual int CreateTarget(sp<android::GraphicBuffer> &buffer) = 0;
36
37 // Sets the target framebuffer of all subsequent composite calls. The target
38 // must be an integer previously returned by a successful call to createTarget
39 // of this compositor or the target can be -1 to indicate that no custom
40 // buffer should be used for subsequent calls.
41 virtual void SetTarget(int target) = 0;
42
43 // Releases the reference to the buffer underlying the given target. The given
44 // target will no longer be valid for use for setTarget. Calling this on a
45 // target that was used in the last setTarget call or that is the target of a
46 // composition that has not yet signaled its fence is undefined behavior.
47 virtual void ForgetTarget(int target) = 0;
48
49 protected:
50 ~Targeting();
51};
52
53class Composition {
54 public:
55 // Releases and invalidates the composition.
56 virtual ~Composition();
57
58 // Adds the given layer, whose handle has been imported into the given buffer
59 // object, to the given display of the composition. The layer may be modified
60 // to include a releaseFenceFd. Returns 0 on success.
61 virtual int AddLayer(int display, hwc_layer_1 *layer, hwc_drm_bo *bo) = 0;
62
63 // Gets the number of successful AddLayer calls that can be made on the
64 // composition and display, up to num_needed.
65 virtual unsigned GetRemainingLayers(int display,
66 unsigned num_needed) const = 0;
67};
68
69class Compositor {
70 public:
71 virtual ~Compositor();
72
73 // This must be called once before any other methods called. It must be called
74 // on the thread the Compositor is meant to operate on to initialize thread
75 // local variables. Returns 0 on success.
76 virtual int Init() = 0;
77
78 // If this compositor supports targeting to output buffers, this returns a
79 // non-null pointer. Otherwise, returns null.
80 virtual Targeting *targeting() = 0;
81
82 // Starts a fresh composition.
83 virtual Composition *CreateComposition() = 0;
84
85 // On success returns a syncpoint fd that will be signaled when composition is
86 // complete or -1 if compositing was completed by this method's return. On
87 // error returns an integer less than -1. The composition is invalid after
88 // this call.
89 virtual int QueueComposition(Composition *composition) = 0;
90
91 // compositors require that every QueueComposition be paired with a Composite
92 // on a worker thread. Each Composite call handles one composition that was
93 // submitted via QueueComposition in FIFO order. Returns 0 on success.
94 virtual int Composite() = 0;
95};
96
97} // namespace android
98
99#endif