From 1c5e55680d9165d8f9bb2bc6e2c4261574b5d41d Mon Sep 17 00:00:00 2001 From: Puneet Kumar Date: Thu, 30 Jul 2015 03:35:38 +0000 Subject: [PATCH] Revert "drm_hwcomposer: remove compositor interface" This reverts commit 7912438911de042dc035cf1ea39daaf4e56bf9f3. For now until we can get back to a stable SF/compositor. Change-Id: I2ba7cab4f1cccfe44b3d35fb18c7784125e88fd6 --- Android.mk | 1 + compositor.cpp | 35 +++++++++++++++++ compositor.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ drmcomposition.h | 9 +++-- drmcompositor.cpp | 10 +++-- drmcompositor.h | 18 +++++---- drmresources.cpp | 4 +- hwcomposer.cpp | 6 +-- 8 files changed, 175 insertions(+), 20 deletions(-) create mode 100644 compositor.cpp create mode 100644 compositor.h diff --git a/Android.mk b/Android.mk index de1658f..ccb230e 100644 --- a/Android.mk +++ b/Android.mk @@ -37,6 +37,7 @@ LOCAL_C_INCLUDES := \ system/core/libsync/include \ LOCAL_SRC_FILES := \ + compositor.cpp \ drmresources.cpp \ drmcomposition.cpp \ drmcompositor.cpp \ diff --git a/compositor.cpp b/compositor.cpp new file mode 100644 index 0000000..3f85dc7 --- /dev/null +++ b/compositor.cpp @@ -0,0 +1,35 @@ +/* + * 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 + +namespace android { + +Targeting::~Targeting() { +} + +Composition::~Composition() { +} + +Compositor::~Compositor() { +} + +void Compositor::Dump(std::ostringstream */* out */) const { +} + +} // namespace android diff --git a/compositor.h b/compositor.h new file mode 100644 index 0000000..b424b37 --- /dev/null +++ b/compositor.h @@ -0,0 +1,112 @@ +/* + * 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 + +struct hwc_layer_1; +struct hwc_drm_bo; + +namespace android { + +class GraphicBuffer; +template +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 &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 diff --git a/drmcomposition.h b/drmcomposition.h index 69bf6d9..06af71d 100644 --- a/drmcomposition.h +++ b/drmcomposition.h @@ -17,6 +17,7 @@ #ifndef ANDROID_DRM_COMPOSITION_H_ #define ANDROID_DRM_COMPOSITION_H_ +#include "compositor.h" #include "drm_hwcomposer.h" #include "drmdisplaycomposition.h" #include "drmplane.h" @@ -31,15 +32,15 @@ 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(); diff --git a/drmcompositor.cpp b/drmcompositor.cpp index 082e75d..3bab93f 100644 --- a/drmcompositor.cpp +++ b/drmcompositor.cpp @@ -47,7 +47,7 @@ int DrmCompositor::Init() { 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"); @@ -62,8 +62,10 @@ DrmComposition *DrmCompositor::CreateComposition(Importer *importer) { 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; @@ -73,7 +75,7 @@ int DrmCompositor::QueueComposition(DrmComposition *composition) { 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; diff --git a/drmcompositor.h b/drmcompositor.h index aa4a876..5f47034 100644 --- a/drmcompositor.h +++ b/drmcompositor.h @@ -17,7 +17,7 @@ #ifndef ANDROID_DRM_COMPOSITOR_H_ #define ANDROID_DRM_COMPOSITOR_H_ -#include "drmcomposition.h" +#include "compositor.h" #include "drmdisplaycompositor.h" #include "importer.h" @@ -26,18 +26,22 @@ 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; diff --git a/drmresources.cpp b/drmresources.cpp index feb5187..9be990f 100644 --- a/drmresources.cpp +++ b/drmresources.cpp @@ -467,7 +467,7 @@ int DrmResources::SetDpmsMode(int display, uint64_t mode) { 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; @@ -478,7 +478,7 @@ int DrmResources::SetDpmsMode(int display, uint64_t mode) { 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; diff --git a/hwcomposer.cpp b/hwcomposer.cpp index a83c247..b4b1a50 100644 --- a/hwcomposer.cpp +++ b/hwcomposer.cpp @@ -110,7 +110,7 @@ static int hwc_prepare(hwc_composer_device_1_t *dev, size_t num_displays, 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; @@ -133,7 +133,7 @@ static void hwc_set_cleanup(size_t num_displays, } 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) { @@ -171,7 +171,7 @@ static int hwc_set(hwc_composer_device_1_t *dev, size_t num_displays, 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"); -- 2.11.0