blob: b4956b65de3f85dd28b1f1f0021f85c1b8bee121 [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
Sean Paul117e1692015-06-03 15:50:21 -040020#include "importer.h"
21
Zach Reiznerc10555d2015-04-01 16:11:14 -070022struct hwc_layer_1;
23struct hwc_drm_bo;
24
25namespace android {
26
27class GraphicBuffer;
28template <typename T>
29class sp;
30
31class Targeting {
32 public:
33 // Prepares the given framebuffer for use as output of this compositor. On
34 // success, takes a reference to the given buffer and returns a non- negative
35 // integer that is used as a handle to the prepared target. On failure,
36 // returns a negative integer.
37 virtual int CreateTarget(sp<android::GraphicBuffer> &buffer) = 0;
38
39 // Sets the target framebuffer of all subsequent composite calls. The target
40 // must be an integer previously returned by a successful call to createTarget
41 // of this compositor or the target can be -1 to indicate that no custom
42 // buffer should be used for subsequent calls.
43 virtual void SetTarget(int target) = 0;
44
45 // Releases the reference to the buffer underlying the given target. The given
46 // target will no longer be valid for use for setTarget. Calling this on a
47 // target that was used in the last setTarget call or that is the target of a
48 // composition that has not yet signaled its fence is undefined behavior.
49 virtual void ForgetTarget(int target) = 0;
50
51 protected:
52 ~Targeting();
53};
54
55class Composition {
56 public:
57 // Releases and invalidates the composition.
58 virtual ~Composition();
59
60 // Adds the given layer, whose handle has been imported into the given buffer
61 // object, to the given display of the composition. The layer may be modified
Sean Paul117e1692015-06-03 15:50:21 -040062 // to include a releaseFenceFd.
63 //
64 // Upon success, the compositor takes ownership of bo and is responsible
65 // for calling importer->ReleaseBuffer(bo), where importer is the importer
66 // provided on CreateComposition(). Returns 0 on success.
Zach Reiznerc10555d2015-04-01 16:11:14 -070067 virtual int AddLayer(int display, hwc_layer_1 *layer, hwc_drm_bo *bo) = 0;
68
69 // Gets the number of successful AddLayer calls that can be made on the
70 // composition and display, up to num_needed.
71 virtual unsigned GetRemainingLayers(int display,
72 unsigned num_needed) const = 0;
73};
74
75class Compositor {
76 public:
77 virtual ~Compositor();
78
79 // This must be called once before any other methods called. It must be called
80 // on the thread the Compositor is meant to operate on to initialize thread
81 // local variables. Returns 0 on success.
82 virtual int Init() = 0;
83
84 // If this compositor supports targeting to output buffers, this returns a
85 // non-null pointer. Otherwise, returns null.
86 virtual Targeting *targeting() = 0;
87
88 // Starts a fresh composition.
Sean Paul117e1692015-06-03 15:50:21 -040089 virtual Composition *CreateComposition(Importer *importer) = 0;
Zach Reiznerc10555d2015-04-01 16:11:14 -070090
91 // On success returns a syncpoint fd that will be signaled when composition is
92 // complete or -1 if compositing was completed by this method's return. On
93 // error returns an integer less than -1. The composition is invalid after
94 // this call.
95 virtual int QueueComposition(Composition *composition) = 0;
96
97 // compositors require that every QueueComposition be paired with a Composite
98 // on a worker thread. Each Composite call handles one composition that was
99 // submitted via QueueComposition in FIFO order. Returns 0 on success.
100 virtual int Composite() = 0;
101};
102
103} // namespace android
104
105#endif