system/core/libsync/include \
LOCAL_SRC_FILES := \
+ compositor.cpp \
drmresources.cpp \
drmcomposition.cpp \
drmcompositor.cpp \
--- /dev/null
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "compositor.h"
+
+#include <sstream>
+
+namespace android {
+
+Targeting::~Targeting() {
+}
+
+Composition::~Composition() {
+}
+
+Compositor::~Compositor() {
+}
+
+void Compositor::Dump(std::ostringstream */* out */) const {
+}
+
+} // namespace android
--- /dev/null
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DRM_HWCOMPOSER_COMPOSITOR_H_
+#define DRM_HWCOMPOSER_COMPOSITOR_H_
+
+#include "importer.h"
+
+#include <sstream>
+
+struct hwc_layer_1;
+struct hwc_drm_bo;
+
+namespace android {
+
+class GraphicBuffer;
+template <typename T>
+class sp;
+
+class Targeting {
+ public:
+ // Prepares the given framebuffer for use as output of this compositor. On
+ // success, takes a reference to the given buffer and returns a non- negative
+ // integer that is used as a handle to the prepared target. On failure,
+ // returns a negative integer.
+ virtual int CreateTarget(sp<android::GraphicBuffer> &buffer) = 0;
+
+ // Sets the target framebuffer of all subsequent composite calls. The target
+ // must be an integer previously returned by a successful call to createTarget
+ // of this compositor or the target can be -1 to indicate that no custom
+ // buffer should be used for subsequent calls.
+ virtual void SetTarget(int target) = 0;
+
+ // Releases the reference to the buffer underlying the given target. The given
+ // target will no longer be valid for use for setTarget. Calling this on a
+ // target that was used in the last setTarget call or that is the target of a
+ // composition that has not yet signaled its fence is undefined behavior.
+ virtual void ForgetTarget(int target) = 0;
+
+ protected:
+ ~Targeting();
+};
+
+class Composition {
+ public:
+ // Releases and invalidates the composition.
+ virtual ~Composition();
+
+ // Adds the given layer, whose handle has been imported into the given buffer
+ // object, to the given display of the composition. The layer may be modified
+ // to include a releaseFenceFd.
+ //
+ // Upon success, the compositor takes ownership of bo and is responsible
+ // for calling importer->ReleaseBuffer(bo), where importer is the importer
+ // provided on CreateComposition(). Returns 0 on success.
+ virtual int AddLayer(int display, hwc_layer_1 *layer, hwc_drm_bo *bo) = 0;
+
+ // Gets the number of successful AddLayer calls that can be made on the
+ // composition and display, up to num_needed.
+ virtual unsigned GetRemainingLayers(int display,
+ unsigned num_needed) const = 0;
+};
+
+class Compositor {
+ public:
+ virtual ~Compositor();
+
+ // This must be called once before any other methods called. It must be called
+ // on the thread the Compositor is meant to operate on to initialize thread
+ // local variables. Returns 0 on success.
+ virtual int Init() = 0;
+
+ // If this compositor supports targeting to output buffers, this returns a
+ // non-null pointer. Otherwise, returns null.
+ virtual Targeting *targeting() = 0;
+
+ // Starts a fresh composition.
+ virtual Composition *CreateComposition(Importer *importer) = 0;
+
+ // Transfers ownership of composition to the Compositor (whether or not this
+ // call returns success) for compositing.
+ // On success returns a syncpoint fd that will be signaled when composition is
+ // complete or -1 if compositing was completed by this method's return. On
+ // error returns an integer less than -1. The composition is invalid after
+ // this call.
+ virtual int QueueComposition(Composition *composition) = 0;
+
+ // compositors require that every QueueComposition be paired with a Composite
+ // on a worker thread. Each Composite call handles one composition that was
+ // submitted via QueueComposition in FIFO order. Returns 0 on success.
+ virtual int Composite() = 0;
+
+ // Dumps state from the Compositor to the out stream
+ virtual void Dump(std::ostringstream *out) const;
+};
+
+} // namespace android
+
+#endif
#ifndef ANDROID_DRM_COMPOSITION_H_
#define ANDROID_DRM_COMPOSITION_H_
+#include "compositor.h"
#include "drm_hwcomposer.h"
#include "drmdisplaycomposition.h"
#include "drmplane.h"
namespace android {
-class DrmComposition {
+class DrmComposition : public Composition {
public:
DrmComposition(DrmResources *drm, Importer *importer);
~DrmComposition();
- int Init();
+ virtual int Init();
- unsigned GetRemainingLayers(int display, unsigned num_needed) const;
- int AddLayer(int display, hwc_layer_1_t *layer, hwc_drm_bo_t *bo);
+ virtual unsigned GetRemainingLayers(int display, unsigned num_needed) const;
+ virtual int AddLayer(int display, hwc_layer_1_t *layer, hwc_drm_bo_t *bo);
int AddDpmsMode(int display, uint32_t dpms_mode);
int DisableUnusedPlanes();
return 0;
}
-DrmComposition *DrmCompositor::CreateComposition(Importer *importer) {
+Composition *DrmCompositor::CreateComposition(Importer *importer) {
DrmComposition *composition = new DrmComposition(drm_, importer);
if (!composition) {
ALOGE("Failed to allocate drm composition");
return composition;
}
-int DrmCompositor::QueueComposition(DrmComposition *composition) {
- int ret = composition->DisableUnusedPlanes();
+int DrmCompositor::QueueComposition(Composition *composition) {
+ DrmComposition *drm_composition = (DrmComposition *)composition;
+
+ int ret = drm_composition->DisableUnusedPlanes();
if (ret) {
ALOGE("Failed to disable unused planes %d", ret);
return ret;
iter != drm_->end_connectors(); ++iter) {
int display = (*iter)->display();
int ret = compositor_map_[display].QueueComposition(
- composition->TakeDisplayComposition(display));
+ drm_composition->TakeDisplayComposition(display));
if (ret) {
ALOGE("Failed to queue composition for display %d", display);
delete composition;
#ifndef ANDROID_DRM_COMPOSITOR_H_
#define ANDROID_DRM_COMPOSITOR_H_
-#include "drmcomposition.h"
+#include "compositor.h"
#include "drmdisplaycompositor.h"
#include "importer.h"
namespace android {
-class DrmCompositor {
+class DrmCompositor : public Compositor {
public:
DrmCompositor(DrmResources *drm);
~DrmCompositor();
- int Init();
+ virtual int Init();
- DrmComposition *CreateComposition(Importer *importer);
+ virtual Targeting *targeting() {
+ return NULL;
+ }
- int QueueComposition(DrmComposition *composition);
- int Composite();
- void Dump(std::ostringstream *out) const;
+ virtual Composition *CreateComposition(Importer *importer);
+
+ virtual int QueueComposition(Composition *composition);
+ virtual int Composite();
+ virtual void Dump(std::ostringstream *out) const;
private:
DrmCompositor(const DrmCompositor &) = delete;
return -EINVAL;
}
- DrmComposition *comp = compositor_.CreateComposition(NULL);
+ DrmComposition *comp = (DrmComposition *)compositor_.CreateComposition(NULL);
if (!comp) {
ALOGE("Failed to create composition for dpms on %d", display);
return -ENOMEM;
delete comp;
return ret;
}
- ret = compositor_.QueueComposition(comp);
+ ret = compositor_.QueueComposition((Composition *)comp);
if (ret) {
ALOGE("Failed to queue dpms composition on %d %d", display, ret);
return ret;
static void hwc_set_cleanup(size_t num_displays,
hwc_display_contents_1_t **display_contents,
- DrmComposition *composition) {
+ Composition *composition) {
for (int i = 0; i < (int)num_displays; ++i) {
if (!display_contents[i])
continue;
}
static int hwc_add_layer(int display, hwc_context_t *ctx, hwc_layer_1_t *layer,
- DrmComposition *composition) {
+ Composition *composition) {
hwc_drm_bo_t bo;
int ret = ctx->importer->ImportBuffer(layer->handle, &bo);
if (ret) {
hwc_display_contents_1_t **display_contents) {
ATRACE_CALL();
struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common;
- DrmComposition *composition =
+ Composition *composition =
ctx->drm.compositor()->CreateComposition(ctx->importer);
if (!composition) {
ALOGE("Drm composition init failed");