hwc/overlay: Dynamic pipe tracking.
Remove state based pipe handling and make pipes tracked dynamically.
Add the configStart, configDone, nextPipe availablePipes APIs.
Remove setState API.
-configStart marks all pipes available.
-configDone garbage-collects unused pipe objects.
-nextPipe returns the index of next available pipe and create a corresponding
pipe object if not present
-availablePipes returns total of "unallocated" pipes. (Pipes could be allocated
but unused)
Changes in hwc adapt to the new overlay APIs.
Compile out MDP comp.
Remove unused files in overlay and hwc.
Update licenses.
Conflicts:
libhwcomposer/hwc.cpp
libhwcomposer/hwc_utils.cpp
Bug: 7626586
Change-Id: Id8e56901d34e5dc0fd088260d05e3e46f68ff090
Signed-off-by: Saurabh Shah <saurshah@codeaurora.org>
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index 170b8a9..7b7719c 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
-* * Neither the name of Code Aurora Forum, Inc. nor the names of its
+* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,180 +27,202 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "overlayUtils.h"
-#include "overlayImpl.h"
#include "overlay.h"
+#include "pipes/overlayGenPipe.h"
+#include "mdp_version.h"
-#include "overlayMdp.h"
-#include "overlayCtrlData.h"
+#define PIPE_DEBUG 0
namespace overlay {
+using namespace utils;
-//Helper
-bool isStateValid(const utils::eOverlayState& st) {
- switch (st) {
- case utils::OV_CLOSED:
- ALOGE("Overlay %s failed, state is OV_CLOSED; set state first",
- __FUNCTION__);
- return false;
- break;
- case utils::OV_2D_VIDEO_ON_PANEL:
- case utils::OV_2D_VIDEO_ON_PANEL_TV:
- case utils::OV_2D_VIDEO_ON_TV:
- case utils::OV_3D_VIDEO_ON_2D_PANEL:
- case utils::OV_3D_VIDEO_ON_3D_PANEL:
- case utils::OV_3D_VIDEO_ON_3D_TV:
- case utils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
- case utils::OV_UI_MIRROR:
- case utils::OV_2D_TRUE_UI_MIRROR:
- case utils::OV_UI_VIDEO_TV:
- case utils::OV_BYPASS_1_LAYER:
- case utils::OV_BYPASS_2_LAYER:
- case utils::OV_BYPASS_3_LAYER:
- case utils::OV_DUAL_DISP:
- break;
- default:
- OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st);
- return false;
+Overlay::Overlay() {
+ int numPipes = 0;
+ int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
+ if (mdpVersion > qdutils::MDP_V3_1) numPipes = 4;
+ if (mdpVersion >= qdutils::MDSS_V5) numPipes = 6;
+
+ PipeBook::NUM_PIPES = numPipes;
+ for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+ mPipeBook[i].init();
}
- return true;
-}
-Overlay::Overlay(): mOv(0) {
+ mDumpStr[0] = '\0';
}
Overlay::~Overlay() {
- mOv = mState.handleEvent(utils::OV_CLOSED, mOv);
- delete mOv;
- mOv = 0;
+ for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+ mPipeBook[i].destroy();
+ }
}
-bool Overlay::commit(utils::eDest dest)
-{
- OVASSERT(mOv,
- "%s Overlay and Rotator should be init at this point",
- __FUNCTION__);
- utils::eOverlayState st = mState.state();
- if(isStateValid(st)) {
- if(!mOv->commit(dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
+void Overlay::configBegin() {
+ for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+ //Mark as available for this round.
+ PipeBook::resetUse(i);
+ PipeBook::resetAllocation(i);
+ }
+ mDumpStr[0] = '\0';
+}
+
+void Overlay::configDone() {
+ if(PipeBook::pipeUsageUnchanged()) return;
+
+ for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+ if(PipeBook::isNotUsed(i)) {
+ //Forces UNSET on pipes, flushes rotator memory and session, closes
+ //fds
+ if(mPipeBook[i].valid()) {
+ char str[32];
+ sprintf(str, "Unset pipe=%s dpy=%d; ", getDestStr((eDest)i),
+ mPipeBook[i].mDisplay);
+ strncat(mDumpStr, str, strlen(str));
+ }
+ mPipeBook[i].destroy();
}
}
- return true;
+ dump();
+ PipeBook::save();
+}
+
+eDest Overlay::nextPipe(eMdpPipeType type, int dpy) {
+ eDest dest = OV_INVALID;
+
+ for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+ //Match requested pipe type
+ if(type == OV_MDP_PIPE_ANY || type == getPipeType((eDest)i)) {
+ //If the pipe is not allocated to any display or used by the
+ //requesting display already in previous round.
+ if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
+ mPipeBook[i].mDisplay == dpy) &&
+ PipeBook::isNotAllocated(i)) {
+ dest = (eDest)i;
+ PipeBook::setAllocation(i);
+ break;
+ }
+ }
+ }
+
+ if(dest != OV_INVALID) {
+ int index = (int)dest;
+ //If the pipe is not registered with any display OR if the pipe is
+ //requested again by the same display using it, then go ahead.
+ mPipeBook[index].mDisplay = dpy;
+ if(not mPipeBook[index].valid()) {
+ mPipeBook[index].mPipe = new GenericPipe(dpy);
+ char str[32];
+ snprintf(str, 32, "Set pipe=%s dpy=%d; ", getDestStr(dest), dpy);
+ strncat(mDumpStr, str, strlen(str));
+ }
+ } else {
+ ALOGD_IF(PIPE_DEBUG, "Pipe unavailable type=%d display=%d",
+ (int)type, dpy);
+ }
+
+ return dest;
+}
+
+bool Overlay::commit(utils::eDest dest) {
+ bool ret = false;
+ int index = (int)dest;
+ validate(index);
+
+ if(mPipeBook[index].mPipe->commit()) {
+ ret = true;
+ PipeBook::setUse((int)dest);
+ } else {
+ PipeBook::resetUse((int)dest);
+ }
+ return ret;
}
bool Overlay::queueBuffer(int fd, uint32_t offset,
- utils::eDest dest)
-{
- OVASSERT(mOv,
- "%s Overlay and Rotator should be init at this point",
- __FUNCTION__);
- utils::eOverlayState st = mState.state();
- if(isStateValid(st)) {
- if(!mOv->queueBuffer(fd, offset, dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
- }
+ utils::eDest dest) {
+ int index = (int)dest;
+ bool ret = false;
+ validate(index);
+ //Queue only if commit() has succeeded (and the bit set)
+ if(PipeBook::isUsed((int)dest)) {
+ ret = mPipeBook[index].mPipe->queueBuffer(fd, offset);
}
- return true;
+ return ret;
}
-bool Overlay::setCrop(const utils::Dim& d,
- utils::eDest dest)
-{
- OVASSERT(mOv,
- "%s Overlay and Rotator should be init at this point",
- __FUNCTION__);
- utils::eOverlayState st = mState.state();
- if(isStateValid(st)) {
- if(!mOv->setCrop(d, dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
- }
- }
- return true;
-}
-bool Overlay::setPosition(const utils::Dim& d,
- utils::eDest dest)
-{
- OVASSERT(mOv,
- "%s Overlay and Rotator should be init at this point",
- __FUNCTION__);
- utils::eOverlayState st = mState.state();
- if(isStateValid(st)) {
- if(!mOv->setPosition(d, dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
- }
- }
- return true;
+void Overlay::setCrop(const utils::Dim& d,
+ utils::eDest dest) {
+ int index = (int)dest;
+ validate(index);
+ mPipeBook[index].mPipe->setCrop(d);
}
-bool Overlay::setTransform(const int orient,
- utils::eDest dest)
-{
+void Overlay::setPosition(const utils::Dim& d,
+ utils::eDest dest) {
+ int index = (int)dest;
+ validate(index);
+ mPipeBook[index].mPipe->setPosition(d);
+}
+
+void Overlay::setTransform(const int orient,
+ utils::eDest dest) {
+ int index = (int)dest;
+ validate(index);
+
utils::eTransform transform =
static_cast<utils::eTransform>(orient);
+ mPipeBook[index].mPipe->setTransform(transform);
- utils::eOverlayState st = mState.state();
- if(isStateValid(st)) {
- if(!mOv->setTransform(transform, dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
- }
+}
+
+void Overlay::setSource(const utils::PipeArgs args,
+ utils::eDest dest) {
+ int index = (int)dest;
+ validate(index);
+
+ PipeArgs newArgs(args);
+ if(dest == OV_VG0 || dest == OV_VG1) {
+ setMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
+ } else {
+ clearMdpFlags(newArgs.mdpFlags, OV_MDP_PIPE_SHARE);
}
- return true;
+ mPipeBook[index].mPipe->setSource(newArgs);
}
-bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES],
- utils::eDest dest)
-{
- utils::PipeArgs margs[utils::MAX_PIPES] = {
- args[0], args[1], args[2] };
- utils::eOverlayState st = mState.state();
-
- if(isStateValid(st)) {
- if (!mOv->setSource(margs, dest)) {
- ALOGE("Overlay %s failed", __FUNCTION__);
- return false;
- }
+Overlay* Overlay::getInstance() {
+ if(sInstance == NULL) {
+ sInstance = new Overlay();
}
- return true;
-}
-
-void Overlay::dump() const
-{
- OVASSERT(mOv,
- "%s Overlay and Rotator should be init at this point",
- __FUNCTION__);
- ALOGE("== Dump Overlay start ==");
- mState.dump();
- mOv->dump();
- ALOGE("== Dump Overlay end ==");
-}
-
-void Overlay::setState(utils::eOverlayState s) {
- mOv = mState.handleEvent(s, mOv);
-}
-
-utils::eOverlayState Overlay::getState() const {
- return mState.state();
-}
-
-Overlay *Overlay::sInstance[] = {0};
-
-Overlay* Overlay::getInstance(int disp) {
- if(sInstance[disp] == NULL) {
- sInstance[disp] = new Overlay();
- }
- return sInstance[disp];
+ return sInstance;
}
void Overlay::initOverlay() {
if(utils::initOverlay() == -1) {
- ALOGE("utils::initOverlay() ERROR!!");
+ ALOGE("%s failed", __FUNCTION__);
}
}
-} // overlay
+void Overlay::dump() const {
+ if(strlen(mDumpStr)) { //dump only on state change
+ ALOGD("%s\n", mDumpStr);
+ }
+}
+
+void Overlay::PipeBook::init() {
+ mPipe = NULL;
+ mDisplay = DPY_UNUSED;
+}
+
+void Overlay::PipeBook::destroy() {
+ if(mPipe) {
+ delete mPipe;
+ mPipe = NULL;
+ }
+ mDisplay = DPY_UNUSED;
+}
+
+Overlay* Overlay::sInstance = 0;
+int Overlay::PipeBook::NUM_PIPES = 0;
+int Overlay::PipeBook::sPipeUsageBitmap = 0;
+int Overlay::PipeBook::sLastUsageBitmap = 0;
+int Overlay::PipeBook::sAllocatedBitmap = 0;
+
+}; // namespace overlay