2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DRM_HWCOMPOSER_COMPOSITOR_H_
18 #define DRM_HWCOMPOSER_COMPOSITOR_H_
35 // Prepares the given framebuffer for use as output of this compositor. On
36 // success, takes a reference to the given buffer and returns a non- negative
37 // integer that is used as a handle to the prepared target. On failure,
38 // returns a negative integer.
39 virtual int CreateTarget(sp<android::GraphicBuffer> &buffer) = 0;
41 // Sets the target framebuffer of all subsequent composite calls. The target
42 // must be an integer previously returned by a successful call to createTarget
43 // of this compositor or the target can be -1 to indicate that no custom
44 // buffer should be used for subsequent calls.
45 virtual void SetTarget(int target) = 0;
47 // Releases the reference to the buffer underlying the given target. The given
48 // target will no longer be valid for use for setTarget. Calling this on a
49 // target that was used in the last setTarget call or that is the target of a
50 // composition that has not yet signaled its fence is undefined behavior.
51 virtual void ForgetTarget(int target) = 0;
59 // Releases and invalidates the composition.
60 virtual ~Composition();
62 // Adds the given layer, whose handle has been imported into the given buffer
63 // object, to the given display of the composition. The layer may be modified
64 // to include a releaseFenceFd.
66 // Upon success, the compositor takes ownership of bo and is responsible
67 // for calling importer->ReleaseBuffer(bo), where importer is the importer
68 // provided on CreateComposition(). Returns 0 on success.
69 virtual int AddLayer(int display, hwc_layer_1 *layer, hwc_drm_bo *bo) = 0;
71 // Gets the number of successful AddLayer calls that can be made on the
72 // composition and display, up to num_needed.
73 virtual unsigned GetRemainingLayers(int display,
74 unsigned num_needed) const = 0;
79 virtual ~Compositor();
81 // This must be called once before any other methods called. It must be called
82 // on the thread the Compositor is meant to operate on to initialize thread
83 // local variables. Returns 0 on success.
84 virtual int Init() = 0;
86 // If this compositor supports targeting to output buffers, this returns a
87 // non-null pointer. Otherwise, returns null.
88 virtual Targeting *targeting() = 0;
90 // Starts a fresh composition.
91 virtual Composition *CreateComposition(Importer *importer) = 0;
93 // Transfers ownership of composition to the Compositor (whether or not this
94 // call returns success) for compositing.
95 // On success returns a syncpoint fd that will be signaled when composition is
96 // complete or -1 if compositing was completed by this method's return. On
97 // error returns an integer less than -1. The composition is invalid after
99 virtual int QueueComposition(Composition *composition) = 0;
101 // compositors require that every QueueComposition be paired with a Composite
102 // on a worker thread. Each Composite call handles one composition that was
103 // submitted via QueueComposition in FIFO order. Returns 0 on success.
104 virtual int Composite() = 0;
106 // Dumps state from the Compositor to the out stream
107 virtual void Dump(std::ostringstream *out) const;
110 } // namespace android