From dca07219a9e8e515f1e8d9bf5fb976450725a377 Mon Sep 17 00:00:00 2001 From: Saurabh Shah Date: Tue, 10 Jul 2012 13:07:52 -0700 Subject: [PATCH] liboverlay: Refactor, bug-fixes, upgrade. Fix memory leak during copying pipe objects. Remove unused / unnecessary code. setMemoryId API is merged with queueBuffer. setParameter API is setTransform now. Rotator upgraded to: --Allow different rotator hardware types. --Remove dependency on MDP code. --Allocate memory only during first playback, close when the associated pipe is closed. Have single commit implementation. Include new format types. Change-Id: I28d87179c7ec9c0b97721a9ff17f1526da98b714 --- libhwcomposer/hwc_overlay.cpp | 48 +- liboverlay/mdpWrapper.h | 67 +- liboverlay/overlay.cpp | 173 +---- liboverlay/overlay.h | 25 +- liboverlay/overlayCtrl.cpp | 159 +--- liboverlay/overlayCtrlData.h | 186 +---- liboverlay/overlayImpl.h | 248 +++--- liboverlay/overlayMdp.cpp | 253 +++---- liboverlay/overlayMdp.h | 153 ++-- liboverlay/overlayMem.h | 15 +- liboverlay/overlayRotator.cpp | 392 +++------- liboverlay/overlayRotator.h | 711 +++++++----------- liboverlay/overlayState.h | 22 +- liboverlay/overlayTransitions.cpp | 139 ++-- liboverlay/overlayUtils.cpp | 76 +- liboverlay/overlayUtils.h | 215 +----- liboverlay/pipes/overlay3DPipe.h | 262 ++----- liboverlay/pipes/overlayBypassPipe.h | 60 +- liboverlay/pipes/overlayGenPipe.h | 330 ++++---- liboverlay/pipes/overlayUIMirrorPipe.h | 106 ++- ...verlayHdmiPipe.h => overlayVideoExtPipe.h} | 95 ++- 21 files changed, 1180 insertions(+), 2555 deletions(-) rename liboverlay/pipes/{overlayHdmiPipe.h => overlayVideoExtPipe.h} (55%) diff --git a/libhwcomposer/hwc_overlay.cpp b/libhwcomposer/hwc_overlay.cpp index 77402cc..3138228 100644 --- a/libhwcomposer/hwc_overlay.cpp +++ b/libhwcomposer/hwc_overlay.cpp @@ -137,14 +137,6 @@ bool prepareOverlay(hwc_context_t *ctx, hwc_layer_t *layer) ovutils::OV_PIPE0 | ovutils::OV_PIPE1); } - // Order order order - // setSource - just setting source - // setParameter - changes src w/h/f accordingly - // setCrop - ROI - that is src_rect - // setPosition - need to do scaling - // commit - commit changes to mdp driver - // queueBuffer - not here, happens when draw is called - ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; if (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { ovutils::setMdpFlags(mdpFlags, @@ -167,36 +159,22 @@ bool prepareOverlay(hwc_context_t *ctx, hwc_layer_t *layer) } ovutils::PipeArgs parg(mdpFlags, - orient, info, waitFlag, ovutils::ZORDER_0, isFgFlag, ovutils::ROT_FLAG_DISABLED); ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg }; - ret = ov.setSource(pargs, dest); - if (!ret) { - ALOGE("%s: setSource failed", __FUNCTION__); - return ret; - } - - const ovutils::Params prms (ovutils::OVERLAY_TRANSFORM, orient); - ret = ov.setParameter(prms, dest); - if (!ret) { - ALOGE("%s: setParameter failed transform %x", __FUNCTION__, orient); - return ret; - } + ov.setSource(pargs, dest); hwc_rect_t sourceCrop = layer->sourceCrop; // x,y,w,h ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, // x, y sourceCrop.right - sourceCrop.left, // w sourceCrop.bottom - sourceCrop.top);// h - ret = ov.setCrop(dcrop, dest); - if (!ret) { - ALOGE("%s: setCrop failed", __FUNCTION__); - return ret; - } + ov.setCrop(dcrop, dest); + + ov.setTransform(orient, dest); int orientation = 0; ovutils::Dim dim; @@ -207,11 +185,8 @@ bool prepareOverlay(hwc_context_t *ctx, hwc_layer_t *layer) dim.h = (displayFrame.bottom - displayFrame.top); dim.o = orientation; - ret = ov.setPosition(dim, dest); - if (!ret) { - ALOGE("%s: setPosition failed", __FUNCTION__); - return ret; - } + ov.setPosition(dim, dest); + if (!ov.commit(dest)) { ALOGE("%s: commit fails", __FUNCTION__); return false; @@ -247,18 +222,14 @@ bool drawLayerUsingOverlay(hwc_context_t *ctx, hwc_layer_t *layer) // - external RGB = OV_PIPE2 // - Only in true UI mirroring case, played by fb - // Same FD for both primary and external VG pipes - ov.setMemoryId(hnd->fd, static_cast( - ovutils::OV_PIPE0 | ovutils::OV_PIPE1)); - // Play external - if (!ov.queueBuffer(hnd->offset, ovutils::OV_PIPE1)) { + if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE1)) { ALOGE("%s: queueBuffer failed for external", __FUNCTION__); ret = false; } // Play primary - if (!ov.queueBuffer(hnd->offset, ovutils::OV_PIPE0)) { + if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE0)) { ALOGE("%s: queueBuffer failed for primary", __FUNCTION__); ret = false; } @@ -272,8 +243,7 @@ bool drawLayerUsingOverlay(hwc_context_t *ctx, hwc_layer_t *layer) default: // In most cases, displaying only to one (primary or external) // so use OV_PIPE_ALL since overlay will ignore NullPipes - ov.setMemoryId(hnd->fd, ovutils::OV_PIPE_ALL); - if (!ov.queueBuffer(hnd->offset, ovutils::OV_PIPE_ALL)) { + if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE_ALL)) { ALOGE("%s: queueBuffer failed", __FUNCTION__); ret = false; } diff --git a/liboverlay/mdpWrapper.h b/liboverlay/mdpWrapper.h index 4cfd3e0..8c5f624 100644 --- a/liboverlay/mdpWrapper.h +++ b/liboverlay/mdpWrapper.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. +* Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -76,7 +76,7 @@ bool getOverlay(int fd, mdp_overlay& ov); bool play(int fd, msmfb_overlay_data& od); /* MSMFB_OVERLAY_PLAY_WAIT */ -bool playWait(int fd, msmfb_overlay_data& od); +bool waitForVsync(int fd, msmfb_overlay_data& od); /* MSMFB_OVERLAY_3D */ bool set3D(int fd, msmfb_overlay_3d& ov); @@ -102,96 +102,108 @@ void dump(const char* const s, const fb_var_screeninfo& vinfo); //---------------Inlines ------------------------------------- inline bool getFScreenInfo(int fd, fb_fix_screeninfo& finfo) { - if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) { - ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%d", errno); + if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0) { + ALOGE("Failed to call ioctl FBIOGET_FSCREENINFO err=%s", + strerror(errno)); return false; } return true; } inline bool getVScreenInfo(int fd, fb_var_screeninfo& vinfo) { - if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) { - ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%d", errno); + if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { + ALOGE("Failed to call ioctl FBIOGET_VSCREENINFO err=%s", + strerror(errno)); return false; } return true; } inline bool setVScreenInfo(int fd, fb_var_screeninfo& vinfo) { - if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) == -1) { - ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%d", errno); + if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { + ALOGE("Failed to call ioctl FBIOPUT_VSCREENINFO err=%s", + strerror(errno)); return false; } return true; } inline bool startRotator(int fd, msm_rotator_img_info& rot) { - if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) == -1){ - ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%d", errno); + if (ioctl(fd, MSM_ROTATOR_IOCTL_START, &rot) < 0){ + ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_START err=%s", + strerror(errno)); return false; } return true; } inline bool rotate(int fd, msm_rotator_data_info& rot) { - if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) == -1) { - ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%d", errno); + if (ioctl(fd, MSM_ROTATOR_IOCTL_ROTATE, &rot) < 0) { + ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_ROTATE err=%s", + strerror(errno)); return false; } return true; } inline bool setOverlay(int fd, mdp_overlay& ov) { - if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%d", errno); + if (ioctl(fd, MSMFB_OVERLAY_SET, &ov) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s", + strerror(errno)); return false; } return true; } inline bool endRotator(int fd, int sessionId) { - if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) == -1) { - ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%d", errno); + if (ioctl(fd, MSM_ROTATOR_IOCTL_FINISH, &sessionId) < 0) { + ALOGE("Failed to call ioctl MSM_ROTATOR_IOCTL_FINISH err=%s", + strerror(errno)); return false; } return true; } inline bool unsetOverlay(int fd, int ovId) { - if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%d", errno); + if (ioctl(fd, MSMFB_OVERLAY_UNSET, &ovId) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_UNSET err=%s", + strerror(errno)); return false; } return true; } inline bool getOverlay(int fd, mdp_overlay& ov) { - if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%d", errno); + if (ioctl(fd, MSMFB_OVERLAY_GET, &ov) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_GET err=%s", + strerror(errno)); return false; } return true; } inline bool play(int fd, msmfb_overlay_data& od) { - if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%d", errno); + if (ioctl(fd, MSMFB_OVERLAY_PLAY, &od) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s", + strerror(errno)); return false; } return true; } -inline bool playWait(int fd, msmfb_overlay_data& od) { - if (ioctl(fd, MSMFB_OVERLAY_PLAY_WAIT, &od) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY_WAIT err=%d", errno); +inline bool waitForVsync(int fd, msmfb_overlay_data& od) { + if (ioctl(fd, MSMFB_OVERLAY_PLAY_WAIT, &od) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY_WAIT err=%s", + strerror(errno)); return false; } return true; } inline bool set3D(int fd, msmfb_overlay_3d& ov) { - if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) == -1) { - ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%d", errno); + if (ioctl(fd, MSMFB_OVERLAY_3D, &ov) < 0) { + ALOGE("Failed to call ioctl MSMFB_OVERLAY_3D err=%s", + strerror(errno)); return false; } return true; @@ -262,7 +274,6 @@ inline void dump(const char* const s, const fb_var_screeninfo& vinfo) { s, vinfo.xres, vinfo.yres); } - } // mdp_wrapper } // overlay diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp index ed968c1..e6bbb0a 100644 --- a/liboverlay/overlay.cpp +++ b/liboverlay/overlay.cpp @@ -31,10 +31,8 @@ #include "overlayImpl.h" #include "overlay.h" -// MDP related FIXME move to state #include "overlayMdp.h" #include "overlayCtrlData.h" -#include "overlayRotator.h" namespace overlay { @@ -42,64 +40,16 @@ Overlay::Overlay(): mOv(0) { } Overlay::~Overlay() { - if(mState.state() == utils::OV_CLOSED) return; - close(); + mOv = mState.handleEvent(utils::OV_CLOSED, mOv); delete mOv; mOv = 0; } -bool Overlay::open() { - // We need an empty open to just open the bare minimum for business - return true; -} - -void Overlay::reset(){ - if(mOv && !mOv->close()) { - ALOGE("%s Overlay failed", __FUNCTION__); - } - - delete mOv; - mOv = 0; -} - -bool Overlay::close() -{ - OVASSERT(mOv, - "%s Overlay and Rotator should be init at this point", - __FUNCTION__); - // FIXME that one needs to move to the state machine class - utils::eOverlayState st = mState.state(); - switch (st) { - case utils::OV_CLOSED: - // try to close any partially opened items - break; - case utils::OV_2D_VIDEO_ON_PANEL: - case utils::OV_2D_VIDEO_ON_PANEL_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_BYPASS_1_LAYER: - case utils::OV_BYPASS_2_LAYER: - case utils::OV_BYPASS_3_LAYER: - mOv = mState.handleEvent(utils::OV_CLOSED, mOv); - this->reset(); - break; - default: - OVASSERT(false, "close Unknown state %d", st); - return false; - } - return true; -} - bool Overlay::commit(utils::eDest dest) { OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME that one needs to move to the state machine class utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -125,13 +75,12 @@ bool Overlay::commit(utils::eDest dest) return true; } -bool Overlay::queueBuffer(uint32_t offset, +bool Overlay::queueBuffer(int fd, uint32_t offset, utils::eDest dest) { OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME that one needs to move to the state machine class utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -145,39 +94,7 @@ bool Overlay::queueBuffer(uint32_t offset, case utils::OV_BYPASS_1_LAYER: case utils::OV_BYPASS_2_LAYER: case utils::OV_BYPASS_3_LAYER: - if(!mOv->queueBuffer(offset, dest)) { - ALOGE("Overlay %s failed", __FUNCTION__); - return false; - } - break; - default: - OVASSERT(false, "%s Unknown state %d", __FUNCTION__, st); - return false; - } - return true; -} - -bool Overlay::dequeueBuffer(void*& buf, - utils::eDest dest) -{ - OVASSERT(mOv, - "%s Overlay and Rotator should be init at this point", - __FUNCTION__); - // FIXME that one needs to move to the state machine class - utils::eOverlayState st = mState.state(); - switch (st) { - case utils::OV_2D_VIDEO_ON_PANEL: - case utils::OV_2D_VIDEO_ON_PANEL_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_BYPASS_1_LAYER: - case utils::OV_BYPASS_2_LAYER: - case utils::OV_BYPASS_3_LAYER: - if(!mOv->dequeueBuffer(buf, dest)) { + if(!mOv->queueBuffer(fd, offset, dest)) { ALOGE("Overlay %s failed", __FUNCTION__); return false; } @@ -194,7 +111,6 @@ bool Overlay::waitForVsync(utils::eDest dest) OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME that one needs to move to the state machine class utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -226,7 +142,6 @@ bool Overlay::setCrop(const utils::Dim& d, OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME that one needs to move to the state machine class utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -257,7 +172,6 @@ bool Overlay::setPosition(const utils::Dim& d, OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME that one needs to move to the state machine class utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -282,13 +196,13 @@ bool Overlay::setPosition(const utils::Dim& d, } return true; } -bool Overlay::setParameter(const utils::Params& param, + +bool Overlay::setTransform(const int orient, utils::eDest dest) { - OVASSERT(mOv, - "%s Overlay and Rotator should be init at this point", - __FUNCTION__); - // FIXME that one needs to move to the state machine class + utils::eTransform transform = + static_cast(orient); + utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_2D_VIDEO_ON_PANEL: @@ -302,7 +216,7 @@ bool Overlay::setParameter(const utils::Params& param, case utils::OV_BYPASS_1_LAYER: case utils::OV_BYPASS_2_LAYER: case utils::OV_BYPASS_3_LAYER: - if(!mOv->setParameter(param, dest)) { + if(!mOv->setTransform(transform, dest)) { ALOGE("Overlay %s failed", __FUNCTION__); return false; } @@ -313,25 +227,19 @@ bool Overlay::setParameter(const utils::Params& param, } return true; } + bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES], utils::eDest dest) { - // FIXME that one needs to move to the state machine class utils::PipeArgs margs[utils::MAX_PIPES] = { args[0], args[1], args[2] }; utils::eOverlayState st = mState.state(); switch (st) { case utils::OV_CLOSED: - // if we get setSource when we are closed, then - // we will assume tranistion to OV_2D_VIDEO_ON_PANEL - // returns overlay - mOv = mState.handle_closed(utils::OV_2D_VIDEO_ON_PANEL); - if (!mOv) { - ALOGE("Overlay %s failed", __FUNCTION__); - this->reset(); // cleanup - return false; - } + 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_3D_VIDEO_ON_2D_PANEL: @@ -351,7 +259,7 @@ bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES], margs[utils::CHANNEL_1].wait = utils::NO_WAIT; break; case utils::OV_2D_TRUE_UI_MIRROR: - // Set zorder -- external VG pipe (video) gets 0, RGB pipe (UI) gets 1 + // Set zorder, external VG pipe (video) gets 0, RGB pipe (UI) gets 1 margs[utils::CHANNEL_1].zorder = utils::ZORDER_0; margs[utils::CHANNEL_2].zorder = utils::ZORDER_1; // External VG (video) and RGB (UI) pipe set to be no wait @@ -371,39 +279,12 @@ bool Overlay::setSource(const utils::PipeArgs args[utils::MAX_PIPES], return true; } -void Overlay::setMemoryId(int id, utils::eDest dest) -{ - OVASSERT(mOv, - "%s Overlay and Rotator should be init at this point", - __FUNCTION__); - // FIXME that one needs to move to the state machine class - utils::eOverlayState st = mState.state(); - switch (st) { - case utils::OV_2D_VIDEO_ON_PANEL: - case utils::OV_2D_VIDEO_ON_PANEL_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_BYPASS_1_LAYER: - case utils::OV_BYPASS_2_LAYER: - case utils::OV_BYPASS_3_LAYER: - mOv->setMemoryId(id, dest); - break; - default: - OVASSERT(false, "setMemId Unknown state %d", st); - } -} - void Overlay::dump() const { OVASSERT(mOv, "%s Overlay and Rotator should be init at this point", __FUNCTION__); - // FIXME dump tate object, factory ALOGE("== Dump Overlay start =="); mState.dump(); mOv->dump(); @@ -426,30 +307,4 @@ Overlay* Overlay::getInstance() { return sInstance; } -/**** NullPipe ****/ - -bool NullPipe::open(RotatorBase*) { - ALOGE_IF(DEBUG_OVERLAY, "NullPipe open"); - return true; -} -bool NullPipe::close() { return true; } -bool NullPipe::commit() { return true; } -bool NullPipe::start(const utils::PipeArgs&) { return true; } -bool NullPipe::setCrop(const utils::Dim&) { return true; } -bool NullPipe::setPosition(const utils::Dim&) { return true; } -bool NullPipe::setParameter(const utils::Params&) { return true; } -bool NullPipe::setSource(const utils::PipeArgs&) { return true; } -bool NullPipe::queueBuffer(uint32_t offset) { return true; } -bool NullPipe::dequeueBuffer(void*&) { return true; } -bool NullPipe::waitForVsync() { return true; } -void NullPipe::setMemoryId(int) {} -// NullPipe will return by val here as opposed to other Pipes. -utils::PipeArgs NullPipe::getArgs() const { return utils::PipeArgs(); } -utils::eOverlayPipeType NullPipe::getOvPipeType() const { - return utils::OV_PIPE_TYPE_NULL; -} -void NullPipe::dump() const { - ALOGE("== NullPipe (null) start/end =="); -} - } // overlay diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h index e2ee6cd..b3324eb 100644 --- a/liboverlay/overlay.h +++ b/liboverlay/overlay.h @@ -43,31 +43,22 @@ public: /* Overlay related func */ - /* We need an empty open to just open the bare minimum for - * business. */ - bool open(); - - /* close rotator, state, overlayimpl*/ - bool close(); - /* Following is the same as the pure virt interface in ov impl */ - bool commit(utils::eDest dest = utils::OV_PIPE_ALL); - - bool queueBuffer(uint32_t offset, + bool setSource(const utils::PipeArgs args[utils::MAX_PIPES], utils::eDest dest = utils::OV_PIPE_ALL); - bool dequeueBuffer(void*& buf, - utils::eDest dest = utils::OV_PIPE_ALL); - bool waitForVsync(utils::eDest dest = utils::OV_PIPE1); bool setCrop(const utils::Dim& d, utils::eDest dest = utils::OV_PIPE_ALL); + bool setTransform(const int orientation, + utils::eDest dest = utils::OV_PIPE_ALL); bool setPosition(const utils::Dim& dim, utils::eDest dest = utils::OV_PIPE_ALL); - bool setParameter(const utils::Params& param, + bool commit(utils::eDest dest = utils::OV_PIPE_ALL); + + bool queueBuffer(int fd, uint32_t offset, utils::eDest dest = utils::OV_PIPE_ALL); - bool setSource(const utils::PipeArgs args[utils::MAX_PIPES], - utils::eDest dest = utils::OV_PIPE_ALL); - void setMemoryId(int id, utils::eDest dest = utils::OV_PIPE_ALL); + bool waitForVsync(utils::eDest dest = utils::OV_PIPE1); + void dump() const; /* state related functions */ diff --git a/liboverlay/overlayCtrl.cpp b/liboverlay/overlayCtrl.cpp index 6f84d07..bb91529 100644 --- a/liboverlay/overlayCtrl.cpp +++ b/liboverlay/overlayCtrl.cpp @@ -18,14 +18,14 @@ #include #include "overlayCtrlData.h" #include "fb_priv.h" +#include "gralloc_priv.h" //for interlace namespace overlay{ -bool Ctrl::open(uint32_t fbnum, - RotatorBase* rot) { - // MDP/FD open - if(!mMdp.open(fbnum)) { - ALOGE("Ctrl failed to open fbnum=%d", fbnum); +bool Ctrl::init(uint32_t fbnum) { + // MDP/FD init + if(!mMdp.init(fbnum)) { + ALOGE("Ctrl failed to init fbnum=%d", fbnum); return false; } @@ -34,127 +34,12 @@ bool Ctrl::open(uint32_t fbnum, return false; } - OVASSERT(rot, "rot is null"); - mRot = rot; - // rot should be already opened - return true; } -bool Ctrl::start(const utils::PipeArgs& args) -{ - int colorFormat = utils::getColorFormat(args.whf.format); - utils::eMdpFlags flags = args.mdpFlags; - - //XXX: Support for interlaced content - if (0) { - - setMdpFlags(flags, utils::OV_MDP_DEINTERLACE); - - // Get the actual format - colorFormat = args.whf.format ^ HAL_PIXEL_FORMAT_INTERLACE; - } - utils::Whf hwwhf(args.whf); - int fmt = utils::getMdpFormat(colorFormat); - // FIXME format should probably be int and not uint - if (fmt < 0) { - ALOGE("Ctrl failed getMdpFormat unsopported " - "colorFormat=%d format=%d flags=%d", - colorFormat, fmt, flags); - return false; - } - hwwhf.format = fmt; - - // devices should be already opened - // (by calling open earlier in the flow) - - const utils::PipeArgs newargs(flags, // mdp flags - args.orientation, // trans - hwwhf, - args.wait, - args.zorder, - args.isFg, - args.rotFlags); - if (!setInfo(newargs)) { - ALOGE("Ctrl failed to setInfo mdpflags=%d wait=%d zorder=%d", - newargs.mdpFlags, newargs.wait, newargs.zorder); - hwwhf.dump(); - return false; - } - - // FIXME, can we remove that and have it in - // setSource only when source changed? - if(!mRot->start(newargs)) { - ALOGE("Ctrl failed to start Rotation session"); - return false; - } - - // if geom is different, we need to prepare a new rot buffers. - // remap on demand when the current orientation is 90,180, etc. - // and the prev orientation was 0. It means we go from orient - if(!mRot->remap(utils::ROT_NUM_BUFS, newargs)) { - ALOGE("%s Error in remapping", __FUNCTION__); - } - - if(!mMdp.set()) { - ALOGE("Ctrl start failed set overlay"); - return false; - } - - // cache the src to be the current mCrop vals - mCrop.w = hwwhf.w; - mCrop.h = hwwhf.h; - - return true; -} - -inline void Ctrl::updateSource(RotatorBase* r, - const utils::PipeArgs& args, - utils::ScreenInfo& info) -{ - mMdp.updateSource(r, args, info); -} - bool Ctrl::setSource(const utils::PipeArgs& args) { - mMdp.setWait(args.wait); - - utils::PipeArgs newargs(args); - utils::Whf whf(args.whf); - // check geom change - if(mOvBufInfo != whf) { - // whf.format is given as HAL, that is why it is - // needed to be MDP fmt. - whf.format = utils::getColorFormat(whf.format); - int fmt = utils::getMdpFormat(whf.format); - OVASSERT(-1 != fmt, "Ctrl setSource format is -1"); - whf.format = fmt; - newargs.whf = whf; - updateSource(mRot, newargs, mInfo); - mMdp.setUserData(0); - if(!mRot->start(newargs)) { - ALOGE("%s failed start rot", __FUNCTION__); - return false; - } - - // if geom is different, we need to prepare a new rot buffers. - // remap on demand when the current orientation is 90,180, etc. - // and the prev orientation was 0. It means we go from orient - if(!mRot->remap(utils::ROT_NUM_BUFS, newargs)) { - ALOGE("%s Error in remapping", __FUNCTION__); - } - } - - // needed for setSource - mOrient = args.orientation; - - // cache last whf from gralloc hnd - mOvBufInfo = args.whf; - - // orign impl is returning false here - // because they will close the overlay and reopen it. - // New design would not do that. - return true; + return mMdp.setSource(args); } bool Ctrl::setPosition(const utils::Dim& dim) @@ -172,41 +57,21 @@ bool Ctrl::setPosition(const utils::Dim& dim) return true; } -bool Ctrl::setParameter(const utils::Params& p) +bool Ctrl::setTransform(const utils::eTransform& orient, const bool& rotUsed) { - if (utils::OVERLAY_TRANSFORM == p.param && - p.value == mMdp.getUserData()) { - // nothing to do here - return true; - } - - utils::eTransform trns = static_cast(p.value); - switch (p.param) { - case utils::OVERLAY_DITHER: - // nothing here today - ALOGE("Ctrl setParameter OVERLAY_DITHER not impl"); - return true; - case utils::OVERLAY_TRANSFORM: - if(!mRot->overlayTransform(mMdp, trns)) { - ALOGE("Ctrl setParameter failed Rot overlayTransform"); - return false; - } - break; - default: - ALOGE("Ctrl setParameter unknown param %d", p.param); - return false; + if(!mMdp.setTransform(orient, rotUsed)) { + ALOGE("Ctrl setTransform failed for Mdp"); + return false; } return true; } bool Ctrl::setCrop(const utils::Dim& d) { - // FIXME check channel validity if(!mMdp.setCrop(d)) { ALOGE("Data setCrop failed in MDP setCrop"); return false; } - mCrop = d; return true; } @@ -224,11 +89,9 @@ utils::Dim Ctrl::getAspectRatio(const utils::Whf& whf) const } if (inWhf.w * fbHeight > fbWidth * inWhf.h) { inWhf.h = fbWidth * inWhf.h / inWhf.w; - utils::even_out(inWhf.h); inWhf.w = fbWidth; } else if (inWhf.w * fbHeight < fbWidth * inWhf.h) { inWhf.w = fbHeight * inWhf.w / inWhf.h; - utils::even_out(inWhf.w); inWhf.h = fbHeight; } else { inWhf.w = fbWidth; @@ -339,10 +202,8 @@ utils::Dim Ctrl::getAspectRatio(const utils::Dim& dim) const { void Ctrl::dump() const { ALOGE("== Dump Ctrl start =="); - ALOGE("orient=%d", mOrient); mInfo.dump("mInfo"); mMdp.dump(); - mRot->dump(); ALOGE("== Dump Ctrl end =="); } diff --git a/liboverlay/overlayCtrlData.h b/liboverlay/overlayCtrlData.h index fbd701a..1398ec4 100644 --- a/liboverlay/overlayCtrlData.h +++ b/liboverlay/overlayCtrlData.h @@ -38,65 +38,40 @@ namespace ovutils = overlay::utils; namespace overlay { -// FIXME make int to be uint32 whenever possible - -class RotatorBase; - /* -* FIXME do we want rot to be template parameter? -* It's already using inheritance... -* * Sequence to use: -* open +* init * start * setXXX * close -* -* Can call setRot anytime to replace rotator on-the-fly * */ class Ctrl : utils::NoCopy { public: /* ctor */ explicit Ctrl(); - /* dtor close */ ~Ctrl(); - - /* should open devices? or start()? */ - bool open(uint32_t fbnum, RotatorBase* rot); - + /* init fd etc*/ + bool init(uint32_t fbnum); /* close underlying mdp */ bool close(); - /* Invoke methods for opening underlying devices - * flags - PIPE SHARED - * wait - WAIT, NO_WAIT */ - bool start(const utils::PipeArgs& args); - - /* Dynamically set rotator*/ - void setRot(RotatorBase* rot); - - /* set mdp posision using dim */ - bool setPosition(const utils::Dim& dim); - - /* set param using Params (param,value pair) */ - bool setParameter(const utils::Params& p); - /* set source using whf, orient and wait flag */ bool setSource(const utils::PipeArgs& args); - /* set crop info and pass it down to mdp */ bool setCrop(const utils::Dim& d); - + /* set orientation */ + bool setTransform(const utils::eTransform& p, const bool&); + /* set mdp position using dim */ + bool setPosition(const utils::Dim& dim); /* mdp set overlay/commit changes */ bool commit(); /* ctrl id */ - int getId() const; + int getPipeId() const; /* ctrl fd */ int getFd() const; - bool getRotSessId(int& id) const; utils::Dim getAspectRatio(const utils::Whf& whf) const; utils::Dim getAspectRatio(const utils::Dim& dim) const; @@ -113,40 +88,14 @@ private: /* Retrieve screen info from underlying mdp */ bool getScreenInfo(utils::ScreenInfo& info); - /* calls underlying mdp set info */ - bool setInfo(const utils::PipeArgs& args); - - /* given whf, update src */ - void updateSource(RotatorBase* r, - const utils::PipeArgs& args, - utils::ScreenInfo& info); - // mdp ctrl struct(info e.g.) MdpCtrl mMdp; - // Rotator - RotatorBase* mRot; - - /* Cache cropped value */ - utils::Dim mCrop; - /* Screen info */ utils::ScreenInfo mInfo; - - /* orientation cache FIXME */ - utils::eTransform mOrient; - - /* Cache last known whfz. - * That would help us compare to a previous - * source that was submitted */ - utils::Whf mOvBufInfo; }; -/* -* MDP = DataMdp, ROT = CtrlMdp usually since Rotator<> -* is instansiated with Ctrl data structure. -* */ class Data : utils::NoCopy { public: /* init, reset */ @@ -155,44 +104,30 @@ public: /* calls close */ ~Data(); - /* should open devices? or start()? */ - bool open(uint32_t fbnum, RotatorBase* rot); + /* init fd etc */ + bool init(uint32_t fbnum); /* calls underlying mdp close */ bool close(); - /* set the rotator */ - void setRot(RotatorBase* rot); - - /* set memory id in the mdp struct */ - void setMemoryId(int id); - - /* set overlay id in the mdp struct */ - void setId(int id); + /* set overlay pipe id in the mdp struct */ + void setPipeId(int id); /* get overlay id in the mdp struct */ - int getId() const; + int getPipeId() const; /* queue buffer to the overlay */ - bool queueBuffer(uint32_t offset); + bool queueBuffer(int fd, uint32_t offset); /* wait for vsync to be done */ bool waitForVsync(); /* sump the state of the obj */ void dump() const; + private: - /* play wrapper */ - bool play(); - - /* playWait wrapper */ - bool playWait(); - // mdp data struct MdpData mMdp; - - // Rotator - RotatorBase* mRot; }; /* This class just creates a Ctrl Data pair to be used by a pipe. @@ -207,7 +142,7 @@ struct CtrlData { //-------------Inlines------------------------------- -inline Ctrl::Ctrl() : mRot(0), mOrient(utils::OVERLAY_TRANSFORM_0) { +inline Ctrl::Ctrl() { mMdp.reset(); } @@ -216,7 +151,6 @@ inline Ctrl::~Ctrl() { } inline bool Ctrl::close() { - // do not close the rotator if(!mMdp.close()) return false; return true; @@ -238,70 +172,37 @@ inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) { return true; } -inline bool Ctrl::setInfo(const utils::PipeArgs& args) -{ - // FIXME set flags, zorder and wait separtly - if(!mMdp.setInfo(mRot, args, mInfo)){ - ALOGE("Ctrl failed to setInfo wait=%d mdpflags=%d " - "zorder=%d", args.wait, args.mdpFlags, args.zorder); - return false; - } - return true; -} - -inline int Ctrl::getId() const { - // FIXME check channel up? - return mMdp.getId(); +inline int Ctrl::getPipeId() const { + return mMdp.getPipeId(); } inline int Ctrl::getFd() const { - // FIXME check channel up? return mMdp.getFd(); } -inline bool Ctrl::getRotSessId(int& id) const { - // FIXME check channel up? - // should be -1 in case of no rot session active - id = mRot->getSessId(); - return true; -} - inline utils::ScreenInfo Ctrl::getScreenInfo() const { return mInfo; } inline utils::Dim Ctrl::getCrop() const { - return mCrop; + return mMdp.getSrcRectDim(); } - - -inline Data::Data() : mRot(0) { +inline Data::Data() { mMdp.reset(); } inline Data::~Data() { close(); } -inline void Data::setRot(RotatorBase* rot) { mRot = rot; } +inline void Data::setPipeId(int id) { mMdp.setPipeId(id); } -inline void Data::setMemoryId(int id) { mMdp.setMemoryId(id); } +inline int Data::getPipeId() const { return mMdp.getPipeId(); } -// really a reqid -inline void Data::setId(int id) { mMdp.setId(id); } - -inline int Data::getId() const { return mMdp.getId(); } - -inline bool Data::open(uint32_t fbnum, - RotatorBase* rot) { - if(!mMdp.open(fbnum)) { - ALOGE("Data cannot open mdp"); +inline bool Data::init(uint32_t fbnum) { + if(!mMdp.init(fbnum)) { + ALOGE("Data cannot init mdp"); return false; } - - OVASSERT(rot, "rot is null"); - mRot = rot; - - // rotator should be already opened here return true; } @@ -313,49 +214,22 @@ inline bool Data::close() { return true; } -inline bool Data::queueBuffer(uint32_t offset) { - // FIXME asserts on state validity - - mMdp.setOffset(offset); - mRot->setRotDataSrcMemId(mMdp.getMemoryId()); - // will play if succeeded - if(!mRot->prepareQueueBuf(offset)) { - ALOGE("Data failed to prepareQueueBuf"); - return false; - } - // Play can go either from mdp or rot - if(!this->play()){ - ALOGE("Data error in MDP/ROT play"); - return false; - } - - return true; +inline bool Data::queueBuffer(int fd, uint32_t offset) { + return mMdp.play(fd, offset); } inline bool Data::waitForVsync() { - - // Call mdp playWait - if(!this->playWait()){ - ALOGE("Error in MDP playWait"); + // Call mdp waitForVsync + if(!mMdp.waitForVsync()){ + ALOGE("Error in MDP %s", __FUNCTION__); return false; } - return true; } -inline bool Data::play() { - int fd = mMdp.getFd(); - return mRot->enabled() ? mRot->play(fd) : mMdp.play(); -} - -inline bool Data::playWait() { - return mMdp.playWait(); -} - inline void Data::dump() const { ALOGE("== Dump Data MDP start =="); mMdp.dump(); - mRot->dump(); ALOGE("== Dump Data MDP end =="); } diff --git a/liboverlay/overlayImpl.h b/liboverlay/overlayImpl.h index 5f999f2..6f950c0 100644 --- a/liboverlay/overlayImpl.h +++ b/liboverlay/overlayImpl.h @@ -33,8 +33,6 @@ #include "overlayUtils.h" #include "overlayRotator.h" -// FIXME make int to be uint32 whenever possible - namespace overlay { // Interface only. No member, no definiton (except ~ which can @@ -44,8 +42,8 @@ public: /* empty dtor. can be =0 with cpp impl*/ virtual ~OverlayImplBase() {} - /* Open pipe/rot for one dest */ - virtual bool openPipe(RotatorBase* rot, utils::eDest dest) = 0; + /* Init pipe/rot for one dest */ + virtual bool initPipe(RotatorBase* rot, utils::eDest dest) = 0; /* Close pipe/rot for all specified dest */ virtual bool closePipe(utils::eDest dest) = 0; @@ -53,12 +51,10 @@ public: /* Copy specified pipe/rot from ov passed in (used by state machine only) */ virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest) = 0; - /* TODO open func customized for RGBx pipes */ - - /* Open all pipes - * To open just one pipe, use openPipe() + /* Init all pipes + * To init just one pipe, use initPipe() * */ - virtual bool open(RotatorBase* rot0, + virtual bool init(RotatorBase* rot0, RotatorBase* rot1, RotatorBase* rot2) = 0; @@ -72,12 +68,8 @@ public: * */ virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL) = 0; - /* Queue buffer with offset*/ - virtual bool queueBuffer(uint32_t offset, - utils::eDest dest = utils::OV_PIPE_ALL) = 0; - - /* For RGBx pipes, dequeue buffer (that is fb chunk)*/ - virtual bool dequeueBuffer(void*& buf, + /* Queue buffer with fd from an offset*/ + virtual bool queueBuffer(int fd, uint32_t offset, utils::eDest dest = utils::OV_PIPE_ALL) = 0; /* Wait for vsync to be done on dest */ @@ -93,16 +85,13 @@ public: /* Set parameters - usually needed for Rotator, but would * be passed down the stack as well */ - virtual bool setParameter(const utils::Params& param, + virtual bool setTransform(const utils::eTransform& param, utils::eDest dest = utils::OV_PIPE_ALL) = 0; /* Set new source including orientation */ virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES], utils::eDest dest = utils::OV_PIPE_ALL) = 0; - /* set memory id to the underlying pipes */ - virtual void setMemoryId(int id, utils::eDest dest = utils::OV_PIPE_ALL) = 0; - /* Get the overlay pipe type */ virtual utils::eOverlayPipeType getOvPipeType(utils::eDest dest) const = 0; @@ -112,22 +101,21 @@ public: class NullPipe { public: - /* TODO open func customized for RGBx pipes */ - bool open(RotatorBase* rot); - bool close(); - bool start(const utils::PipeArgs& args); - bool commit(); - bool setCrop(const utils::Dim& d); - bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); - bool setSource(const utils::PipeArgs& args); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); - bool waitForVsync(); - void setMemoryId(int id); - utils::PipeArgs getArgs() const; - utils::eOverlayPipeType getOvPipeType() const; - void dump() const; + bool init(RotatorBase* rot) { return true; } + bool close() { return true; } + bool start(const utils::PipeArgs& args) { return true; } + bool commit() { return true; } + bool setCrop(const utils::Dim& d) { return true; } + bool setPosition(const utils::Dim& dim) { return true; } + bool setTransform(const utils::eTransform& param) { return true; } + bool setSource(const utils::PipeArgs& args) { return true; } + bool queueBuffer(int fd, uint32_t offset) { return true; } + bool waitForVsync() { return true; } + // NullPipe will return by val here as opposed to other Pipes. + utils::eOverlayPipeType getOvPipeType() const { + return utils::OV_PIPE_TYPE_NULL; + } + void dump() const {} }; /* @@ -143,7 +131,6 @@ public: /* ctor */ OverlayImpl(); - OverlayImpl(P0* p0, P1* p1, P2* p2); /* * Comments of the below functions are the same as the one @@ -151,12 +138,11 @@ public: * */ virtual ~OverlayImpl(); - virtual bool openPipe(RotatorBase* rot, utils::eDest dest); + virtual bool initPipe(RotatorBase* rot, utils::eDest dest); virtual bool closePipe(utils::eDest dest); virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest); - /* TODO open func customized for RGBx pipes */ - virtual bool open(RotatorBase* rot0, + virtual bool init(RotatorBase* rot0, RotatorBase* rot1, RotatorBase* rot2); virtual bool close(); @@ -165,16 +151,13 @@ public: utils::eDest dest = utils::OV_PIPE_ALL); virtual bool setPosition(const utils::Dim& dim, utils::eDest dest = utils::OV_PIPE_ALL); - virtual bool setParameter(const utils::Params& param, + virtual bool setTransform(const utils::eTransform& param, utils::eDest dest = utils::OV_PIPE_ALL); virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES], utils::eDest dest = utils::OV_PIPE_ALL); - virtual bool queueBuffer(uint32_t offset, - utils::eDest dest = utils::OV_PIPE_ALL); - virtual bool dequeueBuffer(void*& buf, + virtual bool queueBuffer(int fd, uint32_t offset, utils::eDest dest = utils::OV_PIPE_ALL); virtual bool waitForVsync(utils::eDest dest = utils::OV_PIPE1); - virtual void setMemoryId(int id, utils::eDest dest = utils::OV_PIPE_ALL); virtual utils::eOverlayPipeType getOvPipeType(utils::eDest dest) const; virtual void dump() const; @@ -197,74 +180,97 @@ private: - - //-----------Inlines and Template defn--------------------------------- +/**** OverlayImpl ****/ + template OverlayImpl::OverlayImpl() : - mPipe0(new P0), mPipe1(new P1), mPipe2(new P2), + mPipe0(0), mPipe1(0), mPipe2(0), mRotP0(0), mRotP1(0), mRotP2(0) -{} - -template -OverlayImpl::OverlayImpl(P0* p0, P1* p1, P2* p2) : - mPipe0(p0), mPipe1(p1), mPipe2(p2), - mRotP0(0), mRotP1(0), mRotP2(0) -{} +{ + //Do not create a pipe here. + //Either initPipe can create a pipe OR + //copyOvPipe can assign a pipe. +} template OverlayImpl::~OverlayImpl() { - // no op in the meantime. needed to be clean - // since state machine will do delete. so we - // do not want to close/delete pipes here + //Do not delete pipes. + //closePipe will close and delete. } -/* Open only one pipe/rot pair per call */ +/* Init only one pipe/rot pair per call */ template -bool OverlayImpl::openPipe(RotatorBase* rot, utils::eDest dest) +bool OverlayImpl::initPipe(RotatorBase* rot, utils::eDest dest) { OVASSERT(rot, "%s: OverlayImpl rot is null", __FUNCTION__); OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", __FUNCTION__, dest); - // Need to down case rotator to mdp one. - // we assume p0/p1/p2/px all use the _same_ underlying mdp structure. - // FIXME STATIC_ASSERT here - bool ret = true; if (utils::OV_PIPE0 & dest) { - OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__); - ALOGE_IF(DEBUG_OVERLAY, "Open pipe0"); - ret = mPipe0->open(rot); + ALOGE_IF(DEBUG_OVERLAY, "init pipe0"); + mRotP0 = rot; + ret = mRotP0->init(); if(!ret) { - ALOGE("%s: OverlayImpl pipe0 failed to open", __FUNCTION__); + ALOGE("%s: OverlayImpl rot0 failed to init", __FUNCTION__); + return false; } + + mPipe0 = new P0(); + OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__); + ret = mPipe0->init(rot); + if(!ret) { + ALOGE("%s: OverlayImpl pipe0 failed to init", __FUNCTION__); + return false; + } + return ret; } if (utils::OV_PIPE1 & dest) { - OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__); - ALOGE_IF(DEBUG_OVERLAY, "Open pipe1"); - ret = mPipe1->open(rot); + ALOGE_IF(DEBUG_OVERLAY, "init pipe1"); + mRotP1 = rot; + ret = mRotP1->init(); if(!ret) { - ALOGE("%s: OverlayImpl pipe1 failed to open", __FUNCTION__); + ALOGE("%s: OverlayImpl rot1 failed to init", __FUNCTION__); + return false; } + + mPipe1 = new P1(); + OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__); + ret = mPipe1->init(rot); + if(!ret) { + ALOGE("%s: OverlayImpl pipe1 failed to init", __FUNCTION__); + return false; + } + return ret; } if (utils::OV_PIPE2 & dest) { - OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__); - ALOGE_IF(DEBUG_OVERLAY, "Open pipe2"); - ret = mPipe2->open(rot); + ALOGE_IF(DEBUG_OVERLAY, "init pipe2"); + mRotP2 = rot; + ret = mRotP2->init(); if(!ret) { - ALOGE("%s: OverlayImpl pipe2 failed to open", __FUNCTION__); + ALOGE("%s: OverlayImpl rot2 failed to init", __FUNCTION__); + return false; } + + mPipe2 = new P2(); + OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__); + ret = mPipe2->init(rot); + if(!ret) { + ALOGE("%s: OverlayImpl pipe2 failed to init", __FUNCTION__); + return false; + } + return ret; } @@ -356,44 +362,48 @@ bool OverlayImpl::copyOvPipe(OverlayImplBase* ov, if (utils::OV_PIPE0 & dest) { mPipe0 = ovimpl->mPipe0; mRotP0 = ovimpl->mRotP0; + ovimpl->mPipe0 = 0; + ovimpl->mRotP0 = 0; } if (utils::OV_PIPE1 & dest) { mPipe1 = ovimpl->mPipe1; mRotP1 = ovimpl->mRotP1; + ovimpl->mPipe1 = 0; + ovimpl->mRotP1 = 0; } if (utils::OV_PIPE2 & dest) { mPipe2 = ovimpl->mPipe2; mRotP2 = ovimpl->mRotP2; + ovimpl->mPipe2 = 0; + ovimpl->mRotP2 = 0; } return true; } -/* TODO open func customized for RGBx pipes */ - -/* Open all pipes/rot */ +/* Init all pipes/rot */ template -bool OverlayImpl::open(RotatorBase* rot0, +bool OverlayImpl::init(RotatorBase* rot0, RotatorBase* rot1, RotatorBase* rot2) { - if (!this->openPipe(rot0, utils::OV_PIPE0)) { + if (!this->initPipe(rot0, utils::OV_PIPE0)) { if (!this->close()) { ALOGE("%s: failed to close at least one pipe", __FUNCTION__); } return false; } - if (!this->openPipe(rot1, utils::OV_PIPE1)) { + if (!this->initPipe(rot1, utils::OV_PIPE1)) { if (!this->close()) { ALOGE("%s: failed to close at least one pipe", __FUNCTION__); } return false; } - if (!this->openPipe(rot2, utils::OV_PIPE2)) { + if (!this->initPipe(rot2, utils::OV_PIPE2)) { if (!this->close()) { ALOGE("%s: failed to close at least one pipe", __FUNCTION__); } @@ -509,7 +519,7 @@ bool OverlayImpl::setPosition(const utils::Dim& d, } template -bool OverlayImpl::setParameter(const utils::Params& param, +bool OverlayImpl::setTransform(const utils::eTransform& param, utils::eDest dest) { OVASSERT(mPipe0 && mPipe1 && mPipe2, @@ -517,21 +527,21 @@ bool OverlayImpl::setParameter(const utils::Params& param, __FUNCTION__, mPipe0, mPipe1, mPipe2); if (utils::OV_PIPE0 & dest) { - if(!mPipe0->setParameter(param)) { + if(!mPipe0->setTransform(param)) { ALOGE("OverlayImpl p0 failed to setparam"); return false; } } if (utils::OV_PIPE1 & dest) { - if(!mPipe1->setParameter(param)) { + if(!mPipe1->setTransform(param)) { ALOGE("OverlayImpl p1 failed to setparam"); return false; } } if (utils::OV_PIPE2 & dest) { - if(!mPipe2->setParameter(param)) { + if(!mPipe2->setTransform(param)) { ALOGE("OverlayImpl p2 failed to setparam"); return false; } @@ -541,7 +551,8 @@ bool OverlayImpl::setParameter(const utils::Params& param, } template -bool OverlayImpl::setSource(const utils::PipeArgs args[utils::MAX_PIPES], +bool OverlayImpl::setSource( + const utils::PipeArgs args[utils::MAX_PIPES], utils::eDest dest) { OVASSERT(mPipe0 && mPipe1 && mPipe2, @@ -573,28 +584,29 @@ bool OverlayImpl::setSource(const utils::PipeArgs args[utils::MAX_PI } template -bool OverlayImpl::queueBuffer(uint32_t offset, utils::eDest dest) +bool OverlayImpl::queueBuffer(int fd, uint32_t offset, + utils::eDest dest) { OVASSERT(mPipe0 && mPipe1 && mPipe2, "%s: Pipes are null p0=%p p1=%p p2=%p", __FUNCTION__, mPipe0, mPipe1, mPipe2); if (utils::OV_PIPE0 & dest) { - if(!mPipe0->queueBuffer(offset)) { + if(!mPipe0->queueBuffer(fd, offset)) { ALOGE("OverlayImpl p0 failed to queueBuffer"); return false; } } if (utils::OV_PIPE1 & dest) { - if(!mPipe1->queueBuffer(offset)) { + if(!mPipe1->queueBuffer(fd, offset)) { ALOGE("OverlayImpl p1 failed to queueBuffer"); return false; } } if (utils::OV_PIPE2 & dest) { - if(!mPipe2->queueBuffer(offset)) { + if(!mPipe2->queueBuffer(fd, offset)) { ALOGE("OverlayImpl p2 failed to queueBuffer"); return false; } @@ -603,37 +615,6 @@ bool OverlayImpl::queueBuffer(uint32_t offset, utils::eDest dest) return true; } -template -bool OverlayImpl::dequeueBuffer(void*& buf, utils::eDest dest) -{ - OVASSERT(mPipe0 && mPipe1 && mPipe2, - "%s: Pipes are null p0=%p p1=%p p2=%p", - __FUNCTION__, mPipe0, mPipe1, mPipe2); - - if (utils::OV_PIPE0 & dest) { - if(!mPipe0->dequeueBuffer(buf)) { - ALOGE("OverlayImpl p0 failed to dequeueBuffer"); - return false; - } - } - - if (utils::OV_PIPE1 & dest) { - if(!mPipe1->dequeueBuffer(buf)) { - ALOGE("OverlayImpl p1 failed to dequeueBuffer"); - return false; - } - } - - if (utils::OV_PIPE2 & dest) { - if(!mPipe2->dequeueBuffer(buf)) { - ALOGE("OverlayImpl p2 failed to dequeueBuffer"); - return false; - } - } - - return true; -} - template bool OverlayImpl::waitForVsync(utils::eDest dest) { @@ -666,27 +647,8 @@ bool OverlayImpl::waitForVsync(utils::eDest dest) } template -void OverlayImpl::setMemoryId(int id, utils::eDest dest) -{ - OVASSERT(mPipe0 && mPipe1 && mPipe2, - "%s: Pipes are null p0=%p p1=%p p2=%p", - __FUNCTION__, mPipe0, mPipe1, mPipe2); - - if (utils::OV_PIPE0 & dest) { - mPipe0->setMemoryId(id); - } - - if (utils::OV_PIPE1 & dest) { - mPipe1->setMemoryId(id); - } - - if (utils::OV_PIPE2 & dest) { - mPipe2->setMemoryId(id); - } -} - -template -utils::eOverlayPipeType OverlayImpl::getOvPipeType(utils::eDest dest) const +utils::eOverlayPipeType OverlayImpl::getOvPipeType( + utils::eDest dest) const { OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d", __FUNCTION__, dest); diff --git a/liboverlay/overlayMdp.cpp b/liboverlay/overlayMdp.cpp index 09499c0..dfcfcd5 100644 --- a/liboverlay/overlayMdp.cpp +++ b/liboverlay/overlayMdp.cpp @@ -23,11 +23,11 @@ namespace ovutils = overlay::utils; namespace overlay { -bool MdpCtrl::open(uint32_t fbnum) { - // FD open +bool MdpCtrl::init(uint32_t fbnum) { + // FD init if(!utils::openDev(mFd, fbnum, - Res::devTemplate, O_RDWR)){ - ALOGE("Ctrl failed to open fbnum=%d", fbnum); + Res::fbPath, O_RDWR)){ + ALOGE("Ctrl failed to init fbnum=%d", fbnum); return false; } return true; @@ -36,12 +36,13 @@ bool MdpCtrl::open(uint32_t fbnum) { void MdpCtrl::reset() { utils::memset0(mOVInfo); utils::memset0(mLkgo); - mOVInfo.id = -1; - mLkgo.id = -1; + mOVInfo.id = MSMFB_NEW_REQUEST; + mLkgo.id = MSMFB_NEW_REQUEST; } bool MdpCtrl::close() { - if(-1 == static_cast(mOVInfo.id)) return true; + if(MSMFB_NEW_REQUEST == static_cast(mOVInfo.id)) + return true; if(!mdp_wrapper::unsetOverlay(mFd.getFD(), mOVInfo.id)) { ALOGE("MdpCtrl close error in unset"); return false; @@ -81,43 +82,114 @@ bool MdpCtrl::get() { return true; } -// that is the second part of original setParameter function -void MdpCtrl::setSrcFormat(const utils::Whf& whf) { - - //By default mdp src format is the same as buffer's - mOVInfo.src.format = whf.format; - - //If rotation is used and input formats are tiled then output of rotator is - //non-tiled. - // FIXME mRotInfo.enable = 1; for enable - if (getUserData()) { // if rotations enabled in MdpCtrl - if (whf.format == MDP_Y_CRCB_H2V2_TILE) - mOVInfo.src.format = MDP_Y_CRCB_H2V2; - else if (whf.format == MDP_Y_CBCR_H2V2_TILE) - mOVInfo.src.format = MDP_Y_CBCR_H2V2; - return; +//Adjust width, height, format if rotator is used. +void MdpCtrl::adjustSrcWhf(const bool& rotUsed) { + if(rotUsed) { + utils::Whf whf = getSrcWhf(); + if(whf.format == MDP_Y_CRCB_H2V2_TILE || + whf.format == MDP_Y_CBCR_H2V2_TILE) { + whf.w = utils::alignup(whf.w, 64); + whf.h = utils::alignup(whf.h, 32); + } + //For example: If original format is tiled, rotator outputs non-tiled, + //so update mdp's src fmt to that. + whf.format = utils::getRotOutFmt(whf.format); + setSrcWhf(whf); } - } bool MdpCtrl::set() { - if(!this->ovChanged()) { - return true; // nothing todo here. - } - if(!mdp_wrapper::setOverlay(mFd.getFD(), mOVInfo)) { ALOGE("MdpCtrl failed to setOverlay, restoring last known " "good ov info"); mdp_wrapper::dump("== Bad OVInfo is: ", mOVInfo); mdp_wrapper::dump("== Last good known OVInfo is: ", mLkgo); this->restore(); - // FIXME, do we need to set the old one? return false; } this->save(); return true; } +bool MdpCtrl::setSource(const utils::PipeArgs& args) { + + setSrcWhf(args.whf); + + //TODO These are hardcoded. Can be moved out of setSource. + mOVInfo.alpha = 0xff; + mOVInfo.transp_mask = 0xffffffff; + + //TODO These calls should ideally be a part of setPipeParams API + setFlags(args.mdpFlags); + setZ(args.zorder); + setWait(args.wait); + setIsFg(args.isFg); + return true; +} + +bool MdpCtrl::setCrop(const utils::Dim& d) { + setSrcRectDim(d); + return true; +} + +bool MdpCtrl::setTransform(const utils::eTransform& orient, + const bool& rotUsed) { + + int rot = utils::getMdpOrient(orient); + setUserData(rot); + adjustSrcWhf(rotUsed); + setRotationFlags(); + + switch(static_cast(orient)) { + case utils::OVERLAY_TRANSFORM_0: + case utils::OVERLAY_TRANSFORM_FLIP_H: + case utils::OVERLAY_TRANSFORM_FLIP_V: + case utils::OVERLAY_TRANSFORM_ROT_180: + //No calculations required + break; + case utils::OVERLAY_TRANSFORM_ROT_90: + case (utils::OVERLAY_TRANSFORM_ROT_90|utils::OVERLAY_TRANSFORM_FLIP_H): + case (utils::OVERLAY_TRANSFORM_ROT_90|utils::OVERLAY_TRANSFORM_FLIP_V): + overlayTransFlipRot90(); + break; + case utils::OVERLAY_TRANSFORM_ROT_270: + overlayTransFlipRot270(); + break; + default: + ALOGE("%s: Error due to unknown rot value", __FUNCTION__); + return false; + } + return true; +} + +void MdpCtrl::overlayTransFlipRot90() +{ + utils::Dim d = getSrcRectDim(); + utils::Whf whf = getSrcWhf(); + int tmp = d.x; + d.x = compute(whf.h, + d.y, + d.h); + d.y = tmp; + setSrcRectDim(d); + swapSrcWH(); + swapSrcRectWH(); +} + +void MdpCtrl::overlayTransFlipRot270() +{ + utils::Dim d = getSrcRectDim(); + utils::Whf whf = getSrcWhf(); + int tmp = d.y; + d.y = compute(whf.w, + d.x, + d.w); + d.x = tmp; + setSrcRectDim(d); + swapSrcWH(); + swapSrcRectWH(); +} + bool MdpCtrl::setPosition(const overlay::utils::Dim& d, int fbw, int fbh) { @@ -129,7 +201,7 @@ bool MdpCtrl::setPosition(const overlay::utils::Dim& d, ovutils::Dim dim(d); ovutils::Dim ovsrcdim = getSrcRectDim(); - // Scaling of upto a max of 8 times supported + // Scaling of upto a max of 20 times supported if(dim.w >(ovsrcdim.w * ovutils::HW_OV_MAGNIFICATION_LIMIT)){ dim.w = ovutils::HW_OV_MAGNIFICATION_LIMIT * ovsrcdim.w; dim.x = (fbw - dim.w) / 2; @@ -139,135 +211,12 @@ bool MdpCtrl::setPosition(const overlay::utils::Dim& d, dim.y = (fbh - dim.h) / 2; } - //dim.even_out(); setDstRectDim(dim); return true; } -void MdpCtrl::updateSource(RotatorBase* r, - const utils::PipeArgs& args, - const utils::ScreenInfo& info) { - utils::Whf whf(args.whf); - mOVInfo.src.width = whf.w; - mOVInfo.src.height = whf.h; - mOVInfo.src_rect.x = 0; - mOVInfo.src_rect.y = 0; - mOVInfo.dst_rect.x = 0; - mOVInfo.dst_rect.y = 0; - mOVInfo.dst_rect.w = whf.w; - mOVInfo.dst_rect.h = whf.h; - mOVInfo.src.format = whf.format; - - if(whf.format == MDP_Y_CRCB_H2V2_TILE || - (whf.format == MDP_Y_CBCR_H2V2_TILE)) { - // passing by value, setInfo fills it and return by val - mOVInfo = r->setInfo(args, mOVInfo); - } else { - mOVInfo.src_rect.w = whf.w; - mOVInfo.src_rect.h = whf.h; - } - - if (whf.w > info.mFBWidth) - mOVInfo.dst_rect.w = info.mFBWidth; - if (whf.h > info.mFBHeight) - mOVInfo.dst_rect.h = info.mFBHeight; - mSize = whf.size; -} - - -bool MdpCtrl::setInfo(RotatorBase* r, - const utils::PipeArgs& args, - const utils::ScreenInfo& info) -{ - // new request - utils::Whf whf(args.whf); - mOVInfo.id = MSMFB_NEW_REQUEST; - - updateSource(r, args, info); - - setUserData(0); - mOVInfo.alpha = 0xff; - mOVInfo.transp_mask = 0xffffffff; - setZ(args.zorder); - setFlags(args.mdpFlags); - setWait(args.wait); - setIsFg(args.isFg); - mSize = whf.size; - return true; -} - -bool MdpCtrl::setCrop(const utils::Dim& cdim) { - utils::Dim d(cdim); - const utils::Whf ovwhf = getSrcWhf(); - int udata = getUserData(); - switch(udata) { - case MDP_ROT_NOP: - break; // nothing to do here - case MDP_ROT_90: - case MDP_ROT_90 | MDP_FLIP_UD: - case MDP_ROT_90 | MDP_FLIP_LR: - { - if (ovwhf.w < (d.y + d.h)) { - ALOGE("MdpCtrl setCrop failed ROT 90 udata=%d", - udata); - d.dump(); - this->dump(); - return false; - } - uint32_t tmp = d.x; - d.x = ovwhf.w - (d.y + d.h); - d.y = tmp; - utils::swap(d.w, d.h); - }break; - case MDP_ROT_270: - { - if (ovwhf.h < (d.x + d.w)) { - ALOGE("MdpCtrl setCrop failed ROT 270 udata=%d", - udata); - d.dump(); - this->dump(); - return false; - } - uint32_t tmp = d.y; - d.y = ovwhf.h - (d.x + d.w); - d.x = tmp; - utils::swap(d.w, d.h); - }break; - case MDP_ROT_180: - { - if ((ovwhf.h < (d.y + d.h)) || - (ovwhf.w < ( d.x + d.w))) { - ALOGE("MdpCtrl setCrop failed ROT 180 udata=%d", - udata); - d.dump(); - this->dump(); - return false; - } - d.x = ovwhf.w - (d.x + d.w); - d.y = ovwhf.h - (d.y + d.h); - }break; - default: - if(!(udata & (MDP_FLIP_UD | MDP_FLIP_LR))) { - ALOGE("MdpCtrl setCrop unknown rot %d", udata); - return false; - } - } - - if(getSrcRectDim() == d) { - return true; // Nothing to do here - } - - utils::normalizeCrop(d.x, d.w); - utils::normalizeCrop(d.y, d.h); - - setSrcRectDim(d); - - return true; -} - void MdpCtrl::dump() const { ALOGE("== Dump MdpCtrl start =="); - ALOGE("size=%d", mSize); mFd.dump(); mdp_wrapper::dump("mOVInfo", mOVInfo); ALOGE("== Dump MdpCtrl end =="); diff --git a/liboverlay/overlayMdp.h b/liboverlay/overlayMdp.h index 29f8fd5..b8c173f 100644 --- a/liboverlay/overlayMdp.h +++ b/liboverlay/overlayMdp.h @@ -22,12 +22,9 @@ #include "overlayUtils.h" #include "mdpWrapper.h" -#include "overlayRotator.h" namespace overlay{ -class RotatorBase; - /* * Mdp Ctrl holds corresponding fd and MDP related struct. * It is simple wrapper to MDP services @@ -40,20 +37,20 @@ public: /* dtor close */ ~MdpCtrl(); - /* Open underlying device using fbnum */ - bool open(uint32_t fbnum); + /* init underlying device using fbnum */ + bool init(uint32_t fbnum); /* unset overlay, reset and close fd */ bool close(); - /* reset and set ov id to -1*/ + /* reset and set ov id to -1 / MSMFB_NEW_REQUEST */ void reset(); /* get orient / user_data[0] */ int getOrient() const; /* returns session id */ - int getId() const; + int getPipeId() const; /* returns the fd associated to ctrl*/ int getFd() const; @@ -71,16 +68,6 @@ public: /* set flags to mdp structure */ void setFlags(int f); - /* code taken from OverlayControlChannel::setOverlayInformation */ - bool setInfo(RotatorBase* r, - const utils::PipeArgs& args, - const utils::ScreenInfo& info); - - /* given whf, update src */ - void updateSource(RotatorBase* r, - const utils::PipeArgs& args, - const utils::ScreenInfo& info); - /* set z order */ void setZ(utils::eZorder z); @@ -102,8 +89,8 @@ public: /* set src whf */ void setSrcWhf(const utils::Whf& whf); - /* set source format based on rot info */ - void setSrcFormat(const utils::Whf& whf); + /* adjust source width height format based on rot info */ + void adjustSrcWhf(const bool& rotUsed); /* swap src w/h*/ void swapSrcWH(); @@ -128,7 +115,7 @@ public: void setUserData(int v); /* return true if current overlay is different - * than lask known good overlay */ + * than last known good overlay */ bool ovChanged() const; /* save mOVInfo to be last known good ov*/ @@ -137,6 +124,9 @@ public: /* restore last known good ov to be the current */ void restore(); + /* Sets the source total width, height, format */ + bool setSource(const utils::PipeArgs& pargs); + /* * Sets ROI, the unpadded region, for source buffer. * Should be called before a setPosition, for small clips. @@ -144,6 +134,8 @@ public: */ bool setCrop(const utils::Dim& d); + bool setTransform(const utils::eTransform& orient, const bool& rotUsed); + /* given a dim and w/h, set overlay dim */ bool setPosition(const utils::Dim& dim, int w, int h); @@ -152,8 +144,13 @@ public: /* dump state of the object */ void dump() const; + private: + /* helper functions for overlayTransform */ + void overlayTransFlipRot90(); + void overlayTransFlipRot270(); + /* last good known ov info */ mdp_overlay mLkgo; @@ -162,9 +159,6 @@ private: /* FD for the mdp fbnum */ OvFD mFd; - - /* cached size FIXME do we need it? */ - uint32_t mSize; }; @@ -201,8 +195,8 @@ public: /* dtor close*/ ~MdpData(); - /* open FD */ - bool open(uint32_t fbnum); + /* init FD */ + bool init(uint32_t fbnum); /* memset0 the underlying mdp object */ void reset(); @@ -210,29 +204,23 @@ public: /* close fd, and reset */ bool close(); - /* Set FD / memid */ - void setMemoryId(int id); - /* set id of mdp data */ - void setId(int id); + void setPipeId(int id); /* return ses id of data */ - int getId() const; + int getPipeId() const; /* get underlying fd*/ int getFd() const; /* get memory_id */ - int getMemoryId() const; - - /* set offset in underlying mdp obj */ - void setOffset(uint32_t o); + int getSrcMemoryId() const; /* calls wrapper play */ - bool play(); + bool play(int fd, uint32_t offset); - /* calls wrapper playWait */ - bool playWait(); + /* calls wrapper waitForVsync */ + bool waitForVsync(); /* dump state of the object */ void dump() const; @@ -247,21 +235,22 @@ private: //--------------Inlines--------------------------------- namespace utils { - inline bool openDev(OvFD& fd, int fb, - const char* const s, - int flags) { - return overlay::open(fd, fb, Res::devTemplate, O_RDWR); - } +inline bool openDev(OvFD& fd, int fbnum, + const char* const devpath, + int flags) { + return overlay::open(fd, fbnum, devpath, flags); +} +} +namespace { +// just a helper func for common operations x-(y+z) +int compute(uint32_t x, uint32_t y, uint32_t z) { + return x-(y+z); +} } - -template - inline void init(T& t) { - memset(&t, 0, sizeof(T)); - } ///// MdpCtrl ////// -inline MdpCtrl::MdpCtrl() : mSize(0) { +inline MdpCtrl::MdpCtrl() { reset(); } @@ -273,7 +262,7 @@ inline int MdpCtrl::getOrient() const { return getUserData(); } -inline int MdpCtrl::getId() const { +inline int MdpCtrl::getPipeId() const { return mOVInfo.id; } @@ -310,27 +299,25 @@ inline bool MdpCtrl::ovChanged() const { } inline void MdpCtrl::save() { - if(static_cast(mOVInfo.id) == -1) { + if(static_cast(mOVInfo.id) == MSMFB_NEW_REQUEST) { ALOGE("MdpCtrl current ov has id -1, will not save"); - // FIXME dump both? return; } mLkgo = mOVInfo; } inline void MdpCtrl::restore() { - if(static_cast(mLkgo.id) == -1) { + if(static_cast(mLkgo.id) == MSMFB_NEW_REQUEST) { ALOGE("MdpCtrl Lkgo ov has id -1, will not restore"); - // FIXME dump both? return; } mOVInfo = mLkgo; } inline overlay::utils::Whf MdpCtrl::getSrcWhf() const { - return utils::Whf(mOVInfo.src.width, - mOVInfo.src.height, - mOVInfo.src.format); + return utils::Whf( mOVInfo.src.width, + mOVInfo.src.height, + mOVInfo.src.format); } inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) { @@ -340,10 +327,10 @@ inline void MdpCtrl::setSrcWhf(const overlay::utils::Whf& whf) { } inline overlay::utils::Dim MdpCtrl::getSrcRectDim() const { - return utils::Dim(mOVInfo.src_rect.x, - mOVInfo.src_rect.y, - mOVInfo.src_rect.w, - mOVInfo.src_rect.h); + return utils::Dim( mOVInfo.src_rect.x, + mOVInfo.src_rect.y, + mOVInfo.src_rect.w, + mOVInfo.src_rect.h); } inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) { @@ -354,10 +341,10 @@ inline void MdpCtrl::setSrcRectDim(const overlay::utils::Dim d) { } inline overlay::utils::Dim MdpCtrl::getDstRectDim() const { - return utils::Dim(mOVInfo.dst_rect.x, - mOVInfo.dst_rect.y, - mOVInfo.dst_rect.w, - mOVInfo.dst_rect.h); + return utils::Dim( mOVInfo.dst_rect.x, + mOVInfo.dst_rect.y, + mOVInfo.dst_rect.w, + mOVInfo.dst_rect.h); } inline void MdpCtrl::setDstRectDim(const overlay::utils::Dim d) { @@ -379,14 +366,15 @@ inline void MdpCtrl::setRotationFlags() { mOVInfo.flags &= ~MDP_SOURCE_ROTATED_90; } - inline void MdpCtrl::swapSrcWH() { utils::swap(mOVInfo.src.width, - mOVInfo.src.height); } + mOVInfo.src.height); +} inline void MdpCtrl::swapSrcRectWH() { - utils::swap(mOVInfo.src_rect.h, - mOVInfo.src_rect.w); } + utils::swap(mOVInfo.src_rect.w, + mOVInfo.src_rect.h); +} /////// MdpCtrl3D ////// @@ -434,10 +422,10 @@ inline MdpData::MdpData() { reset(); } inline MdpData::~MdpData() { close(); } -inline bool MdpData::open(uint32_t fbnum) { - // FD open - if(!utils::openDev(mFd, fbnum, Res::devTemplate, O_RDWR)){ - ALOGE("Ctrl failed to open fbnum=%d", fbnum); +inline bool MdpData::init(uint32_t fbnum) { + // FD init + if(!utils::openDev(mFd, fbnum, Res::fbPath, O_RDWR)){ + ALOGE("Ctrl failed to init fbnum=%d", fbnum); return false; } return true; @@ -457,28 +445,29 @@ inline bool MdpData::close() { return true; } -inline void MdpData::setMemoryId(int id) { mOvData.data.memory_id = id; } -inline int MdpData::getMemoryId() const { return mOvData.data.memory_id; } +inline int MdpData::getSrcMemoryId() const { return mOvData.data.memory_id; } -inline void MdpData::setId(int id) { mOvData.id = id; } +inline void MdpData::setPipeId(int id) { mOvData.id = id; } -inline int MdpData::getId() const { return mOvData.id; } +inline int MdpData::getPipeId() const { return mOvData.id; } inline int MdpData::getFd() const { return mFd.getFD(); } -inline void MdpData::setOffset(uint32_t o) { mOvData.data.offset = o; } - -inline bool MdpData::play() { +inline bool MdpData::play(int fd, uint32_t offset) { + mOvData.data.memory_id = fd; + mOvData.data.offset = offset; if(!mdp_wrapper::play(mFd.getFD(), mOvData)){ ALOGE("MdpData failed to play"); + dump(); return false; } return true; } -inline bool MdpData::playWait() { - if(!mdp_wrapper::playWait(mFd.getFD(), mOvData)){ - ALOGE("MdpData failed to playWait"); +inline bool MdpData::waitForVsync() { + if(!mdp_wrapper::waitForVsync(mFd.getFD(), mOvData)){ + ALOGE("%s failed", __FUNCTION__); + dump(); return false; } return true; diff --git a/liboverlay/overlayMem.h b/liboverlay/overlayMem.h index 7c04890..c1cd165 100644 --- a/liboverlay/overlayMem.h +++ b/liboverlay/overlayMem.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. +* Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -118,9 +118,7 @@ inline bool OvMem::open(uint32_t numbufs, uint32_t bufSz, int flags) { alloc_data data; - //XXX: secure buffers and IOMMU heap - int allocFlags = GRALLOC_USAGE_PRIVATE_MM_HEAP | - GRALLOC_USAGE_PRIVATE_DO_NOT_MAP; + int allocFlags = GRALLOC_USAGE_PRIVATE_IOMMU_HEAP; int err = 0; OVASSERT(numbufs && bufSz, "numbufs=%d bufSz=%d", numbufs, bufSz); @@ -138,6 +136,7 @@ inline bool OvMem::open(uint32_t numbufs, err = mAlloc->allocate(data, allocFlags, 0); if (err != 0) { ALOGE("OvMem: error allocating memory"); + return false; } mFd = data.fd; @@ -159,6 +158,7 @@ inline bool OvMem::close() ret = memalloc->free_buffer(mBaseAddr, mBufSz * mNumBuffers, 0, mFd); if (ret != 0) { ALOGE("OvMem: error freeing buffer"); + return false; } mFd = -1; @@ -166,7 +166,7 @@ inline bool OvMem::close() mAllocType = 0; mBufSz = 0; mNumBuffers = 0; - return ret; + return true; } inline bool OvMem::valid() const @@ -196,8 +196,9 @@ inline uint32_t OvMem::numBufs() const inline void OvMem::dump() const { - ALOGE("%s: fd=%d addr=%p type=%d bufsz=%u", - __FUNCTION__, mFd, mBaseAddr, mAllocType, mBufSz); + ALOGE("== Dump OvMem start =="); + ALOGE("fd=%d addr=%p type=%d bufsz=%u", mFd, mBaseAddr, mAllocType, mBufSz); + ALOGE("== Dump OvMem end =="); } } // overlay diff --git a/liboverlay/overlayRotator.cpp b/liboverlay/overlayRotator.cpp index 30c5ea5..38f5807 100644 --- a/liboverlay/overlayRotator.cpp +++ b/liboverlay/overlayRotator.cpp @@ -23,59 +23,87 @@ namespace ovutils = overlay::utils; namespace overlay { -namespace utils { -inline mdp_overlay setInfoNullRot(const utils::PipeArgs& args, - const mdp_overlay& o) -{ - mdp_overlay ov = o; - utils::Whf whf(args.whf); - utils::Dim d(utils::getSrcRectDim(ov)); - - d.w = whf.w - (utils::alignup(whf.w, 64) - whf.w); - d.h = whf.h - (utils::alignup(whf.h, 32) - whf.h); - utils::setSrcRectDim(ov, d); - return ov; +int IRotatorHw::getRotatorHwType() { + //TODO figure out based on ioctl + return TYPE_MDP; } -inline mdp_overlay setInfoRot(const utils::PipeArgs& args, - const mdp_overlay& o) -{ - /* If there are no orientation, then we use setInfoRot - * That is even if we are a real rotator object (not null) - * Note, that if args.rotFlags are ENABLED - * it means we would still like to have rot - * even though it is ROT_0 */ - if(OVERLAY_TRANSFORM_0 == args.orientation && - utils::ROT_FLAG_ENABLED != args.rotFlags) { - return setInfoNullRot(args, o); +bool RotMem::close() { + bool ret = true; + for(uint32_t i=0; i < RotMem::MAX_ROT_MEM; ++i) { + // skip current, and if valid, close + if(m[i].valid()) { + if(m[i].close() == false) { + ALOGE("%s error in closing rot mem %d", __FUNCTION__, i); + ret = false; + } + } } - - mdp_overlay ov = o; - utils::Whf whf(args.whf); - utils::Dim d(utils::getSrcRectDim(ov)); - d.w = whf.w; - d.h = whf.h; - utils::Whf localwhf (utils::getSrcWhf(ov)); - localwhf.w = utils::alignup(whf.w, 64); - localwhf.h = utils::alignup(whf.h, 32); - d.x = localwhf.w - whf.w; - d.y = localwhf.h - whf.h; - utils::setSrcRectDim(ov, d); - utils::setSrcWhf(ov, localwhf); - return ov; + return ret; } -} // utils - -bool MdpRot::open() +bool MdpRot::init() { if(!mFd.open(Res::rotPath, O_RDWR)){ - ALOGE("MdpRot failed to open %s", Res::rotPath); + ALOGE("MdpRot failed to init %s", Res::rotPath); return false; } return true; } +void MdpRot::setSource(const overlay::utils::Whf& awhf) { + utils::Whf whf(awhf); + + mRotImgInfo.src.format = whf.format; + if(whf.format == MDP_Y_CRCB_H2V2_TILE || + whf.format == MDP_Y_CBCR_H2V2_TILE) { + whf.w = utils::alignup(awhf.w, 64); + whf.h = utils::alignup(awhf.h, 32); + } + + mRotImgInfo.src.width = whf.w; + mRotImgInfo.src.height = whf.h; + + mRotImgInfo.src_rect.w = whf.w; + mRotImgInfo.src_rect.h = whf.h; + + mRotImgInfo.dst.width = whf.w; + mRotImgInfo.dst.height = whf.h; + + mBufSize = awhf.size; +} + +void MdpRot::setTransform(const utils::eTransform& rot, const bool& rotUsed) +{ + int r = utils::getMdpOrient(rot); + ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r); + this->setRotations(r); + this->setDisable(); + if(rotUsed) { + this->setEnable(); + } + switch(static_cast(rot)) { + case utils::OVERLAY_TRANSFORM_ROT_90: + case (utils::OVERLAY_TRANSFORM_ROT_90|utils::OVERLAY_TRANSFORM_FLIP_H): + case (utils::OVERLAY_TRANSFORM_ROT_90|utils::OVERLAY_TRANSFORM_FLIP_V): + case utils::OVERLAY_TRANSFORM_ROT_270: + utils::swap(mRotImgInfo.dst.width, mRotImgInfo.dst.height); + break; + default: + break; + } +} + +bool MdpRot::commit() { + if(!overlay::mdp_wrapper::startRotator(mFd.getFD(), mRotImgInfo)) { + ALOGE("MdpRot commit failed"); + dump(); + return false; + } + mRotDataInfo.session_id = mRotImgInfo.session_id; + return true; +} + bool MdpRot::open_i(uint32_t numbufs, uint32_t bufsz) { OvMem mem; @@ -91,25 +119,12 @@ bool MdpRot::open_i(uint32_t numbufs, uint32_t bufsz) OVASSERT(MAP_FAILED != mem.addr(), "MAP failed"); OVASSERT(mem.getFD() != -1, "getFd is -1"); - mData.data.memory_id = mem.getFD(); mRotDataInfo.dst.memory_id = mem.getFD(); mRotDataInfo.dst.offset = 0; mMem.curr().m = mem; return true; } -bool MdpRot::RotMem::close() { - bool ret = true; - for(uint32_t i=0; i < RotMem::MAX_ROT_MEM; ++i) { - // skip current, and if valid, close - if(m[i].valid() && (m[i].close() != 0)) { - ALOGE("%s error in closing prev rot mem %d", __FUNCTION__, i); - ret = false; - } - } - return ret; -} - bool MdpRot::close() { bool success = true; if(mFd.valid() && (getSessId() > 0)) { @@ -131,300 +146,77 @@ bool MdpRot::close() { return success; } -bool MdpRot::unmapNonCurrent() { - bool ret = true; - for(uint32_t i=0; i < RotMem::MAX_ROT_MEM; ++i) { - // skip current, and if valid, close - if(i != mMem._curr % RotMem::MAX_ROT_MEM && - mMem.m[i].valid() && - !mMem.m[i].close()) { - ALOGE("%s error in closing prev rot mem %d", __FUNCTION__, i); - ret = false; - } - } - return ret; -} - -bool MdpRot::remap(uint32_t numbufs, - const utils::PipeArgs& args) { +bool MdpRot::remap(uint32_t numbufs) { // if current size changed, remap - if(args.whf.size == mMem.curr().size()) { - ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, args.whf.size); - return true; - } - - // remap only if we have orientation. - // If rotFlags are ENABLED, it means we need rotation bufs - // even when orientation is 0 - if(utils::OVERLAY_TRANSFORM_0 == args.orientation && - utils::ROT_FLAG_ENABLED != args.rotFlags) { - ALOGE_IF(DEBUG_OVERLAY, "%s: orientation=%d, rotFlags=%d", - __FUNCTION__, args.orientation, args.rotFlags); + if(mBufSize == mMem.curr().size()) { + ALOGE_IF(DEBUG_OVERLAY, "%s: same size %d", __FUNCTION__, mBufSize); return true; } ALOGE_IF(DEBUG_OVERLAY, "%s: size changed - remapping", __FUNCTION__); OVASSERT(!mMem.prev().valid(), "Prev should not be valid"); - // remap and have the current to be the new one. // ++mMem will make curr to be prev, and prev will be curr ++mMem; - if(!open_i(numbufs, args.whf.size)) { + if(!open_i(numbufs, mBufSize)) { ALOGE("%s Error could not open", __FUNCTION__); return false; } - OVASSERT(numbufs <= ROT_MAX_BUF_OFFSET, - "Numbufs %d > ROT_MAX_BUF_OFFSET", numbufs); for (uint32_t i = 0; i < numbufs; ++i) { - mMem.curr().mRotOffset[i] = i * args.whf.size; + mMem.curr().mRotOffset[i] = i * mBufSize; } return true; } -bool MdpRot::start() { - if(!overlay::mdp_wrapper::startRotator(mFd.getFD(), mRotImgInfo)) { - ALOGE("MdpRot start failed"); - this->dump(); - return false; - } - mRotDataInfo.session_id = mRotImgInfo.session_id; - return true; -} - void MdpRot::reset() { ovutils::memset0(mRotImgInfo); ovutils::memset0(mRotDataInfo); - ovutils::memset0(mData); ovutils::memset0(mMem.curr().mRotOffset); ovutils::memset0(mMem.prev().mRotOffset); mMem.curr().mCurrOffset = 0; mMem.prev().mCurrOffset = 0; - isSrcFB = false; + mBufSize = 0; } -bool MdpRot::prepareQueueBuf(uint32_t offset) { - // FIXME if it fails, what happens to the above current item? +bool MdpRot::queueBuffer(int fd, uint32_t offset) { if(enabled()) { - OVASSERT(mMem.curr().m.numBufs(), - "prepareQueueBuf numbufs is 0"); - - // If the rotator source is FB - if(isSrcFB) { - mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB; - } - + mRotDataInfo.src.memory_id = fd; mRotDataInfo.src.offset = offset; + + remap(RotMem::Mem::ROT_NUM_BUFS); + OVASSERT(mMem.curr().m.numBufs(), + "queueBuffer numbufs is 0"); mRotDataInfo.dst.offset = mMem.curr().mRotOffset[mMem.curr().mCurrOffset]; mMem.curr().mCurrOffset = (mMem.curr().mCurrOffset + 1) % mMem.curr().m.numBufs(); + if(!overlay::mdp_wrapper::rotate(mFd.getFD(), mRotDataInfo)) { ALOGE("MdpRot failed rotate"); + dump(); return false; } - mData.data.offset = mRotDataInfo.dst.offset; - } - return true; -} - -bool MdpRot::play(int fd) { - if(!overlay::mdp_wrapper::play(fd, mData)) { - ALOGE("MdpRot failed to play with fd=%d", fd); - return false; - } - - // if the prev mem is valid, we need to close - if(mMem.prev().valid()) { - // FIXME FIXME FIXME if no wait for vsync the above - // play will return immediatly and might cause - // tearing when prev.close is called. - if(!mMem.prev().close()) { - ALOGE("%s error in closing prev rot mem", __FUNCTION__); + // if the prev mem is valid, we need to close + if(mMem.prev().valid()) { + // FIXME if no wait for vsync the above + // play will return immediatly and might cause + // tearing when prev.close is called. + if(!mMem.prev().close()) { + ALOGE("%s error in closing prev rot mem", __FUNCTION__); + return false; + } } } return true; } -///// Null Rot //// - -mdp_overlay NullRotator::setInfo( - const utils::PipeArgs& args, - const mdp_overlay& o) { - return utils::setInfoNullRot(args, o); -} - -///// Rotator //// - -mdp_overlay Rotator::setInfo( - const utils::PipeArgs& args, - const mdp_overlay& o) -{ - return utils::setInfoRot(args, o); -} - -bool Rotator::overlayTransform(MdpCtrl& mdp, - utils::eTransform& rot) -{ - ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rot); - switch(int(rot)) { - case 0: - case HAL_TRANSFORM_FLIP_H: - case HAL_TRANSFORM_FLIP_V: - overlayTransFlipHV(mdp, rot); - break; - case HAL_TRANSFORM_ROT_90: - case (HAL_TRANSFORM_ROT_90|HAL_TRANSFORM_FLIP_H): - case (HAL_TRANSFORM_ROT_90|HAL_TRANSFORM_FLIP_V): - overlayTransFlipRot90(mdp, rot); - break; - case HAL_TRANSFORM_ROT_180: - overlayTransFlipRot180(mdp); - break; - case HAL_TRANSFORM_ROT_270: - overlayTransFlipRot270(mdp); - break; - default: - ALOGE("%s: Error due to unknown rot value %d", __FUNCTION__, rot); - return false; - } - - /* everything below is rotation related */ - int r = utils::getMdpOrient(rot); - ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r); - if (r == -1) { - ALOGE("Ctrl setParameter rot it -1"); - return false; - } - - // Need to have both in sync - mdp.setUserData(r); - this->setRotations(r); - this->setDisable(); - if(r) { - this->setEnable(); - } - - /* set src format using rotation info - * e.g. (12-->5 in case of rotation) */ - mdp.setSrcFormat(this->getSrcWhf()); - - // based on 90/270 set flags - mdp.setRotationFlags(); - return true; -} - -void Rotator::overlayTransFlipHV(MdpCtrl& mdp, - utils::eTransform& rot) -{ - int val = mdp.getUserData(); - ALOGE_IF(DEBUG_OVERLAY, "%s: prev=%d", __FUNCTION__, val); - utils::Dim d = mdp.getSrcRectDim(); - utils::Whf whf = mdp.getSrcWhf(); - if (val == MDP_ROT_90) { - int tmp = d.y; - d.y = compute(whf.w, - d.x, - d.w); - d.x = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } - else if (val == MDP_ROT_270) { - int tmp = d.x; - d.x = compute(whf.h, - d.y, - d.h); - d.y = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } -} - -void Rotator::overlayTransFlipRot90(MdpCtrl& mdp, - utils::eTransform& rot) -{ - int val = mdp.getUserData(); - ALOGE_IF(DEBUG_OVERLAY, "%s: prev=%d", __FUNCTION__, val); - utils::Dim d = mdp.getSrcRectDim(); - utils::Whf whf = mdp.getSrcWhf(); - if (val == MDP_ROT_270) { - d.x = compute(whf.w, - d.x, - d.w); - d.y = compute(whf.h, - d.y, - d.h); - } - else if (val == MDP_ROT_NOP || val == MDP_ROT_180) { - int tmp = d.x; - d.x = compute(whf.h, - d.y, - d.h); - d.y = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } -} - -void Rotator::overlayTransFlipRot180(MdpCtrl& mdp) -{ - int val = mdp.getUserData(); - ALOGE_IF(DEBUG_OVERLAY, "%s: prev=%d", __FUNCTION__, val); - utils::Dim d = mdp.getSrcRectDim(); - utils::Whf whf = mdp.getSrcWhf(); - if (val == MDP_ROT_270) { - int tmp = d.y; - d.y = compute(whf.w, - d.x, - d.w); - d.x = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } - else if (val == MDP_ROT_90) { - int tmp = d.x; - d.x = compute(whf.h, - d.y, - d.h); - d.y = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } -} - -void Rotator::overlayTransFlipRot270(MdpCtrl& mdp) -{ - int val = mdp.getUserData(); - ALOGE_IF(DEBUG_OVERLAY, "%s: prev=%d", __FUNCTION__, val); - utils::Dim d = mdp.getSrcRectDim(); - utils::Whf whf = mdp.getSrcWhf(); - if (val == MDP_ROT_90) { - d.y = compute(whf.h, - d.y, - d.h); - d.x = compute(whf.w, - d.x, - d.w); - } - else if (val == MDP_ROT_NOP || val == MDP_ROT_180) { - int tmp = d.y; - d.y = compute(whf.w, - d.x, - d.w); - d.x = tmp; - mdp.setSrcRectDim(d); - utils::swapOVRotWidthHeight(mRot, mdp); - } -} - void MdpRot::dump() const { ALOGE("== Dump MdpRot start =="); mFd.dump(); mMem.curr().m.dump(); mdp_wrapper::dump("mRotImgInfo", mRotImgInfo); mdp_wrapper::dump("mRotDataInfo", mRotDataInfo); - mdp_wrapper::dump("mData", mData); ALOGE("== Dump MdpRot end =="); } } diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h index 39c4f0c..b952902 100644 --- a/liboverlay/overlayRotator.h +++ b/liboverlay/overlayRotator.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. +* Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -27,8 +27,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OVERLAY_ROTATOR_H -#define OVERLAY_ROTATOR_H +#ifndef OVERlAY_ROTATOR_H +#define OVERlAY_ROTATOR_H #include @@ -37,158 +37,107 @@ #include "overlayMem.h" namespace overlay { - class MdpCtrl; + +class IRotatorHw; /* -* MDP rot holds MDP's rotation related structures. -* -* */ -class MdpRot { -public: - /* ctor */ - explicit MdpRot(); - - /* open fd for rotator. map bufs is defered */ - bool open(); - - /* remap rot buffers */ - bool remap(uint32_t numbufs, const utils::PipeArgs& args); - - /* Unmap everything that is not current */ - bool unmapNonCurrent(); - - /* close fd, mem */ - bool close(); - - /* reset underlying data, basically memset 0 */ - void reset(); - - /* calls underlying wrappers to start rotator */ - bool start(); - - /* start underlying but use given whf and flags */ - bool start(const utils::PipeArgs& args); - - /* start underlying but use given whf and flags. - * Has the ability to parameterize the dst fmt */ - template - bool start(const utils::PipeArgs& args); - - /* assign memory id to mdp structure */ - void setDataMemId(int fd); - void setRotDataSrcMemId(int fd); - - /* Mark src as FB (non-ION) */ - void setSrcFB(bool); - - /* get dst (for offset and memory id) non-virt */ - int getDstMemId() const; - uint32_t getDstOffset() const; - - /* set enable/disable flag */ - void setEnable(); - void setDisable(); - bool enabled() const; - - /* set rotator flag*/ - void setRotations(uint32_t r); - - /* set the req data id in mData */ - void setDataReqId(int id); - - /* swap rot info dst w/h */ - void swapDstWH(); - - /* returns a copy of src whf */ - utils::Whf getSrcWhf() const; - - /* setup rotator data before queue buf calls - * call play if rotate call succeed. return false if failed */ - bool prepareQueueBuf(uint32_t offset); - - /* call play on mdp*/ - bool play(int fd); - - /* set src whf */ - void setSrcWhf(const utils::Whf& whf); - - /* returns rotator session id */ - int getSessId() const; - - /* dump the state of the object */ - void dump() const; - -private: - bool open_i(uint32_t numbufs, uint32_t bufsz); - - /* max buf no for offset */ - enum { ROT_MAX_BUF_OFFSET = 2 }; - /* rot info*/ - msm_rotator_img_info mRotImgInfo; - /* rot data */ - msm_rotator_data_info mRotDataInfo; - /* data needed for rotator */ - msmfb_overlay_data mData; - /* rotator fd */ - OvFD mFd; - /* Array of memory map for rotator - * The array enable us to change rot buffers/mapping - * on the fly*/ - struct RotMem { - enum {MAX_ROT_MEM = 2}; - struct Mem { - Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); } - bool valid() { return m.valid(); } - bool close() { return m.close(); } - uint32_t size() const { return m.bufSz(); } - /* rotator data info dst offset */ - uint32_t mRotOffset[ROT_MAX_BUF_OFFSET]; - /* current offset slot from mRotOffset */ - uint32_t mCurrOffset; - OvMem m; - }; - RotMem() : _curr(0) {} - Mem& curr() { return m[_curr % MAX_ROT_MEM]; } - const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; } - Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; } - RotMem& operator++() { ++_curr; return *this; } - bool close(); - uint32_t _curr; - Mem m[MAX_ROT_MEM]; - } mMem; - bool isSrcFB; -}; - -/* -* RotatorBase. No memebers, just interface. -* ~ can also be =0 with empty impl in cpp. +* RotatorBase. No members, just interface. +* can also be =0 with empty impl in cpp. * */ class RotatorBase { public: /* Most of the below are No op funcs for RotatorBase */ virtual ~RotatorBase() {} - virtual bool open() = 0; - virtual bool remap(uint32_t numbufs, const utils::PipeArgs& args) = 0; + virtual bool init() = 0; virtual bool close() = 0; - virtual bool start(const utils::PipeArgs& args) = 0; - virtual bool start() = 0; - virtual mdp_overlay setInfo(const utils::PipeArgs& args, - const mdp_overlay& o) = 0; - virtual bool overlayTransform(MdpCtrl& mdp, - utils::eTransform& rot) = 0; - virtual void setSrcWhf(const utils::Whf& wfh) = 0; - virtual utils::Whf getSrcWhf() const = 0; - virtual void setRotations(uint32_t r) = 0; - virtual void setDataReqId(int id) = 0; - virtual bool prepareQueueBuf(uint32_t offset) = 0; - virtual bool play(int fd) = 0; + virtual void setSource(const utils::Whf& wfh) = 0; + virtual void setTransform(const utils::eTransform& rot, + const bool& rotUsed) = 0; + virtual bool commit() = 0; + virtual bool queueBuffer(int fd, uint32_t offset) = 0; + virtual void setEnable() = 0; virtual void setDisable() = 0; - virtual bool enabled() const = 0; - virtual void setDataMemId(int fd) = 0; - virtual void setRotDataSrcMemId(int fd) = 0; + virtual void setRotations(uint32_t r) = 0; virtual void setSrcFB(bool) = 0; + + virtual bool enabled() const = 0; virtual int getSessId() const = 0; + virtual int getDstMemId() const = 0; + virtual uint32_t getDstOffset() const = 0; virtual void dump() const = 0; + +protected: + //Hardware specific rotator impl. + IRotatorHw *mRot; +}; + +/* + * Rotator Hw Interface. Any hardware specific implementation should inherit + * from this. + */ +class IRotatorHw { +public: + /* Most of the below are No op funcs for RotatorBase */ + virtual ~IRotatorHw() {} + /* init fd for rotator. map bufs is defered */ + virtual bool init() = 0; + /* close fd, mem */ + virtual bool close() = 0; + /* set src */ + virtual void setSource(const utils::Whf& wfh) = 0; + /* Set rotation and calculate */ + virtual void setTransform(const utils::eTransform& rot, + const bool& rotUsed) = 0; + /* calls underlying wrappers to start rotator */ + virtual bool commit() = 0; + /* Lazy buffer allocation. queue buffer */ + virtual bool queueBuffer(int fd, uint32_t offset) = 0; + /* set enable/disable flag */ + virtual void setEnable() = 0; + virtual void setDisable() = 0; + /* set rotator flag*/ + virtual void setRotations(uint32_t r) = 0; + /* Mark src as FB (non-ION) */ + virtual void setSrcFB(bool) = 0; + /* Retusn true if rotator enabled */ + virtual bool enabled() const = 0; + /* returns rotator session id */ + virtual int getSessId() const = 0; + /* get dst (for offset and memory id) non-virt */ + virtual int getDstMemId() const = 0; + virtual uint32_t getDstOffset() const = 0; + /* dump the state of the object */ + virtual void dump() const = 0; + + enum { TYPE_MDP, TYPE_MDSS }; + /*Returns rotator h/w type */ + static int getRotatorHwType(); +}; + +/* +* Actual Rotator impl. +* */ +class Rotator : public RotatorBase +{ +public: + explicit Rotator(); + virtual ~Rotator(); + virtual bool init(); + virtual bool close(); + virtual void setSource(const utils::Whf& wfh); + virtual void setTransform(const utils::eTransform& rot, + const bool& rotUsed); + virtual bool commit(); + virtual void setRotations(uint32_t r); + virtual void setSrcFB(bool); + virtual int getDstMemId() const; + virtual uint32_t getDstOffset() const; + virtual void setEnable(); + virtual void setDisable(); + virtual bool enabled () const; + virtual int getSessId() const; + virtual bool queueBuffer(int fd, uint32_t offset); + virtual void dump() const; }; /* @@ -198,357 +147,209 @@ class NullRotator : public RotatorBase { public: /* Most of the below are No op funcs for RotatorBase */ virtual ~NullRotator(); - virtual bool open(); - virtual bool remap(uint32_t numbufs, const utils::PipeArgs& args); + virtual bool init(); virtual bool close(); - virtual bool start(const utils::PipeArgs& args); - virtual bool start(); - /* null rotator behavior should set info in a specific way */ - virtual mdp_overlay setInfo(const utils::PipeArgs& args, - const mdp_overlay& o); - virtual bool overlayTransform(MdpCtrl& o, - utils::eTransform& rot); - virtual void setSrcWhf(const utils::Whf& wfh); - virtual utils::Whf getSrcWhf() const; + virtual void setSource(const utils::Whf& wfh); + virtual void setTransform(const utils::eTransform& rot, + const bool& rotUsed); + virtual bool commit(); virtual void setRotations(uint32_t r); - virtual void setDataReqId(int id); - virtual bool prepareQueueBuf(uint32_t offset); - virtual bool play(int fd); + virtual bool queueBuffer(int fd, uint32_t offset); virtual void setEnable(); virtual void setDisable(); virtual bool enabled () const; - virtual void setDataMemId(int fd); - virtual void setRotDataSrcMemId(int fd); virtual void setSrcFB(bool); virtual int getSessId() const; + virtual int getDstMemId() const; + virtual uint32_t getDstOffset() const; virtual void dump() const; }; +/* + Manages the case where new rotator memory needs to be + allocated, before previous is freed, due to resolution change etc. If we make + rotator memory to be always max size, irrespctive of source resolution then + we don't need this RotMem wrapper. The inner class is sufficient. +*/ +struct RotMem { + // Max rotator memory allocations + enum { MAX_ROT_MEM = 2}; + + //Manages the rotator buffer offsets. + struct Mem { + Mem() : mCurrOffset(0) {utils::memset0(mRotOffset); } + bool valid() { return m.valid(); } + bool close() { return m.close(); } + uint32_t size() const { return m.bufSz(); } + // Max rotator buffers + enum { ROT_NUM_BUFS = 2 }; + // rotator data info dst offset + uint32_t mRotOffset[ROT_NUM_BUFS]; + // current offset slot from mRotOffset + uint32_t mCurrOffset; + OvMem m; + }; + + RotMem() : _curr(0) {} + Mem& curr() { return m[_curr % MAX_ROT_MEM]; } + const Mem& curr() const { return m[_curr % MAX_ROT_MEM]; } + Mem& prev() { return m[(_curr+1) % MAX_ROT_MEM]; } + RotMem& operator++() { ++_curr; return *this; } + bool close(); + uint32_t _curr; + Mem m[MAX_ROT_MEM]; +}; /* -* Rotator impl. +* MDP rot holds MDP's rotation related structures. +* * */ -class Rotator : public RotatorBase -{ +class MdpRot : public IRotatorHw { public: - /* construct underlying object */ - explicit Rotator(); - - /* close underlying rot */ - virtual ~Rotator(); - - /* calls underlying open */ - virtual bool open(); - - /* remap rot buffers */ - virtual bool remap(uint32_t numbufs, const utils::PipeArgs& args); - - /* calls underlying close */ - virtual bool close(); - - /* calls underlying start */ - virtual bool start(); - - /* calls underlying start with whf and flags */ - virtual bool start(const utils::PipeArgs& args); - - /* non virtual - calls underlying start with whf and flags. - * Has the ability to parameterize the dst */ - template - bool start(const utils::PipeArgs& args); - - /* Unmap everything that is not current */ - bool unmapNonCurrent(); - - /* set info using whf and given mdp */ - virtual mdp_overlay setInfo(const utils::PipeArgs& args, - const mdp_overlay& o); - - /* transform function for the MDP */ - virtual bool overlayTransform(MdpCtrl& mdp, - utils::eTransform& rot); - - /* set src whf */ - virtual void setSrcWhf(const utils::Whf& wfh); - - /* set Rotations */ - virtual void setRotations(uint32_t r); - - /* set the req data id in mData */ - virtual void setDataReqId(int id); - - /* set memory_id */ - virtual void setDataMemId(int fd); - virtual void setRotDataSrcMemId(int fd); - - /* Mark the src for rotator as FB. usually set by UI mirroing cases */ - virtual void setSrcFB(bool); - - /* get dst (for offset and memory id) non-virt */ + explicit MdpRot(); + ~MdpRot(); + bool init(); + bool close(); + void setSource(const utils::Whf& whf); + void setTransform(const utils::eTransform& rot, + const bool& rotUsed); + bool commit(); + bool queueBuffer(int fd, uint32_t offset); + void setEnable(); + void setDisable(); + void setRotations(uint32_t r); + void setSrcFB(bool); + bool enabled() const; + int getSessId() const; int getDstMemId() const; uint32_t getDstOffset() const; + void dump() const; - /* set enable/disable flag */ - virtual void setEnable(); - virtual void setDisable(); - virtual bool enabled () const; - - /* return rotator sess id */ - virtual int getSessId() const; - - /* return a copy of src whf*/ - virtual utils::Whf getSrcWhf() const; - - /* prepare rot for queue buf*/ - virtual bool prepareQueueBuf(uint32_t offset); - - /* call play on mdp*/ - virtual bool play(int fd); - - /* dump the state of the object */ - virtual void dump() const; private: - /* helper functions for overlayTransform */ - void overlayTransFlipHV(MdpCtrl& mdp, - utils::eTransform& rot); - void overlayTransFlipRot90(MdpCtrl& mdp, - utils::eTransform& rot); - void overlayTransFlipRot180(MdpCtrl& mdp); - void overlayTransFlipRot270(MdpCtrl& mdp); + /* remap rot buffers */ + bool remap(uint32_t numbufs); + bool open_i(uint32_t numbufs, uint32_t bufsz); + /* reset underlying data, basically memset 0 */ + void reset(); - /* underlying rotator MDP object */ - MdpRot mRot; + /* rot info*/ + msm_rotator_img_info mRotImgInfo; + /* rot data */ + msm_rotator_data_info mRotDataInfo; + /* rotator fd */ + OvFD mFd; + /* Rotator memory manager */ + RotMem mMem; + /* Single Rotator buffer size */ + uint32_t mBufSize; }; //--------------inlines------------------------------------ -//// MdpRot //// -inline MdpRot::MdpRot() { reset(); } -inline bool MdpRot::start(const utils::PipeArgs& args) { - return this->start(args); + +///// Rotator ///// +inline Rotator::Rotator() { + int type = IRotatorHw::getRotatorHwType(); + if(type == IRotatorHw::TYPE_MDP) { + mRot = new MdpRot(); //will do reset + } else if(type == IRotatorHw::TYPE_MDSS) { + //TODO create mdss specific rotator + } else { + ALOGE("%s Unknown h/w type %d", __FUNCTION__, type); + } +} +inline Rotator::~Rotator() { + delete mRot; //will do close +} +inline bool Rotator::init() { + if(!mRot->init()) { + ALOGE("Rotator::init failed"); + return false; + } + return true; +} +inline bool Rotator::close() { + return mRot->close(); +} +inline void Rotator::setSource(const utils::Whf& whf) { + mRot->setSource(whf); +} +inline void Rotator::setTransform(const utils::eTransform& rot, + const bool& rotUsed) +{ + mRot->setTransform(rot, rotUsed); +} +inline bool Rotator::commit() { + return mRot->commit(); +} +inline void Rotator::setEnable(){ mRot->setEnable(); } +inline void Rotator::setDisable(){ mRot->setDisable(); } +inline bool Rotator::enabled() const { return mRot->enabled(); } +inline void Rotator::setSrcFB(bool mark) { mRot->setSrcFB(mark); } +inline int Rotator::getDstMemId() const { + return mRot->getDstMemId(); +} +inline uint32_t Rotator::getDstOffset() const { + return mRot->getDstOffset(); +} +inline void Rotator::setRotations(uint32_t rot) { + mRot->setRotations (rot); +} +inline int Rotator::getSessId() const { + return mRot->getSessId(); +} +inline void Rotator::dump() const { + ALOGE("== Dump Rotator start =="); + mRot->dump(); + ALOGE("== Dump Rotator end =="); +} +inline bool Rotator::queueBuffer(int fd, uint32_t offset) { + return mRot->queueBuffer(fd, offset); } -inline void MdpRot::setDataMemId(int fd) { mData.data.memory_id = fd; } -inline void MdpRot::setRotDataSrcMemId(int fd) { - mRotDataInfo.src.memory_id = fd; } +///// Null Rotator ///// +inline NullRotator::~NullRotator() {} +inline bool NullRotator::init() { return true; } +inline bool NullRotator::close() { return true; } +inline bool NullRotator::commit() { return true; } +inline void NullRotator::setSource(const utils::Whf& wfh) {} +inline void NullRotator::setTransform(const utils::eTransform& rot, const bool&) +{} +inline void NullRotator::setRotations(uint32_t) {} +inline void NullRotator::setEnable() {} +inline void NullRotator::setDisable() {} +inline bool NullRotator::enabled() const { return false; } +inline int NullRotator::getSessId() const { return -1; } +inline bool NullRotator::queueBuffer(int fd, uint32_t offset) { return true; } +inline void NullRotator::setSrcFB(bool) {} +inline int NullRotator::getDstMemId() const { return -1; } +inline uint32_t NullRotator::getDstOffset() const { return 0;} +inline void NullRotator::dump() const { + ALOGE("== Dump NullRotator dump (null) start/end =="); +} + + +//// MdpRot //// +inline MdpRot::MdpRot() { reset(); } +inline MdpRot::~MdpRot() { close(); } inline void MdpRot::setEnable() { mRotImgInfo.enable = 1; } inline void MdpRot::setDisable() { mRotImgInfo.enable = 0; } inline bool MdpRot::enabled() const { return mRotImgInfo.enable; } - inline void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; } -inline void MdpRot::setDataReqId(int id) { mData.id = id; } -inline void MdpRot::swapDstWH() { - overlay::utils::swap(mRotImgInfo.dst.width, - mRotImgInfo.dst.height); } - -inline overlay::utils::Whf MdpRot::getSrcWhf() const { - return overlay::utils::Whf(mRotImgInfo.src.width, - mRotImgInfo.src.height, - mRotImgInfo.src.format); -} - inline int MdpRot::getDstMemId() const { return mRotDataInfo.dst.memory_id; } inline uint32_t MdpRot::getDstOffset() const { return mRotDataInfo.dst.offset; } - -inline void MdpRot::setSrcWhf(const overlay::utils::Whf& whf) { - mRotImgInfo.src.width = whf.w; - mRotImgInfo.src.height = whf.h; - mRotImgInfo.src.format = whf.format; -} - inline int MdpRot::getSessId() const { return mRotImgInfo.session_id; } - -inline void MdpRot::setSrcFB(bool mark) { isSrcFB = mark; } - -///// Null Rotator ///// -inline NullRotator::~NullRotator() {} -inline bool NullRotator::open() { - return true; } -inline bool NullRotator::remap(uint32_t numbufs, - const utils::PipeArgs& args){ - return true; } -inline bool NullRotator::close() { return true; } -inline bool NullRotator::start(const utils::PipeArgs& args) -{ return true; } - -inline bool NullRotator::start() { return true; } -inline bool NullRotator::overlayTransform(MdpCtrl& o, - utils::eTransform& rot) -{ return true; } -inline void NullRotator::setSrcWhf(const overlay::utils::Whf& wfh) {} -inline void NullRotator::setRotations(uint32_t) {} -inline void NullRotator::setDataReqId(int id) {} -inline void NullRotator::setEnable() {} -inline void NullRotator::setDisable() {} -inline bool NullRotator::enabled() const { return false; } -inline int NullRotator::getSessId() const { return -1; } -inline overlay::utils::Whf NullRotator::getSrcWhf() const { - return overlay::utils::Whf(); } -inline bool NullRotator::prepareQueueBuf(uint32_t offset) -{ return true; } -inline bool NullRotator::play(int fd) -{ return true; } -inline void NullRotator::setDataMemId(int fd) {} -inline void NullRotator::setRotDataSrcMemId(int fd) {} -inline void NullRotator::setSrcFB(bool) {} -inline void NullRotator::dump() const { - ALOGE("== Dump NullRotator dump (null) start/end =="); +inline void MdpRot::setSrcFB(bool set) { + if(set) + mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB; } -///// Rotator ///// -inline Rotator::Rotator() { } - -inline Rotator::~Rotator() { - mRot.close(); // also will do reset -} - -inline bool Rotator::open() { - if(!mRot.open()) { - ALOGE("Rotator::open failed"); - return false; - } - return true; -} - -template -inline bool Rotator::start(const utils::PipeArgs& args) { - return mRot.start(args); -} - -inline bool Rotator::remap(uint32_t numbufs, - const utils::PipeArgs& args){ - if(!mRot.remap(numbufs, args)) { - ALOGE("%s failed", __FUNCTION__); - return false; - } - return true; -} - -inline bool Rotator::close() { - return mRot.close(); -} - -inline bool Rotator::start() { - return mRot.start(); -} - -inline bool Rotator::start(const utils::PipeArgs& args) { - return mRot.start(args); -} - -inline bool Rotator::unmapNonCurrent() { - return mRot.unmapNonCurrent(); -} - -inline void Rotator::setEnable(){ mRot.setEnable(); } -inline void Rotator::setDisable(){ mRot.setDisable(); } -inline bool Rotator::enabled() const { return mRot.enabled(); } -inline void Rotator::setDataMemId(int fd) { - mRot.setDataMemId(fd); } - -inline void Rotator::setRotDataSrcMemId(int fd) { - mRot.setRotDataSrcMemId(fd); -} - -inline void Rotator::setSrcFB(bool mark) { mRot.setSrcFB(mark); } - -inline int Rotator::getDstMemId() const { - return mRot.getDstMemId(); -} -inline uint32_t Rotator::getDstOffset() const { - return mRot.getDstOffset(); -} - -inline void Rotator::setDataReqId(int id) { - mRot.setDataReqId(id); -} - -inline void Rotator::setSrcWhf( - const overlay::utils::Whf& whf) { - mRot.setSrcWhf(whf); -} - -inline void Rotator::setRotations(uint32_t rot) { - mRot.setRotations (rot); -} - -inline int Rotator::getSessId() const { - return mRot.getSessId(); } - -inline void Rotator::dump() const { - ALOGE("== Dump Rotator start =="); - mRot.dump(); - ALOGE("== Dump Rotator end =="); -} - -inline overlay::utils::Whf Rotator::getSrcWhf() const { - return mRot.getSrcWhf(); } - -inline bool Rotator::prepareQueueBuf(uint32_t offset) -{ - return mRot.prepareQueueBuf(offset); -} - -inline bool Rotator::play(int fd) -{ - return mRot.play(fd); -} - -template -bool MdpRot::start(const utils::PipeArgs& args) { - // Do nothing when no orientation - if(utils::OVERLAY_TRANSFORM_0 == args.orientation && - utils::ROT_FLAG_ENABLED != args.rotFlags) { - return true; - } - utils::Whf whf(args.whf); - mRotImgInfo.src.format = whf.format; - mRotImgInfo.src.width = whf.w; - mRotImgInfo.src.height = whf.h; - mRotImgInfo.src_rect.w = whf.w; - mRotImgInfo.src_rect.h = whf.h; - mRotImgInfo.dst.width = whf.w; - mRotImgInfo.dst.height = whf.h; - if(whf.format == MDP_Y_CRCB_H2V2_TILE || - whf.format == MDP_Y_CBCR_H2V2_TILE) { - mRotImgInfo.src.width = utils::alignup(whf.w, 64); - mRotImgInfo.src.height = utils::alignup(whf.h, 32); - mRotImgInfo.src_rect.w = utils::alignup(whf.w, 64); - mRotImgInfo.src_rect.h = utils::alignup(whf.h, 32); - mRotImgInfo.dst.width = utils::alignup(whf.w, 64); - mRotImgInfo.dst.height = utils::alignup(whf.h, 32); - mRotImgInfo.dst.format = MDP_Y_CRCB_H2V2; - } - // either utils::getRotOutFmt(whf.format); or supplied fmt - // utils::RotOutFmt::fmt; - mRotImgInfo.dst.format = utils::RotOutFmt::fmt(whf.format); - mRotImgInfo.dst_x = 0; - mRotImgInfo.dst_y = 0; - mRotImgInfo.src_rect.x = 0; - mRotImgInfo.src_rect.y = 0; - mRotImgInfo.rotations = 0; - // ROT_FLAG_DISABLED / ENABLED - // Refer to overlayUtils.h eRotFlags - // for more info - mRotImgInfo.enable = args.rotFlags; - mRotImgInfo.session_id = mRotImgInfo.session_id ? - mRotImgInfo.session_id : 0; - - return start(); -} } // overlay -namespace { -// just a helper func for Rotator common operations x-(y+z) -int compute(uint32_t x, uint32_t y, uint32_t z) { - return x-(y+z); -} -} - -#endif // OVERLAY_ROTATOR_H +#endif // OVERlAY_ROTATOR_H diff --git a/liboverlay/overlayState.h b/liboverlay/overlayState.h index 1d13a2e..afa59b5 100644 --- a/liboverlay/overlayState.h +++ b/liboverlay/overlayState.h @@ -35,21 +35,16 @@ #include "overlayRotator.h" #include "pipes/overlayGenPipe.h" #include "pipes/overlayBypassPipe.h" -#include "pipes/overlayHdmiPipe.h" +#include "pipes/overlayVideoExtPipe.h" #include "pipes/overlayUIMirrorPipe.h" #include "pipes/overlay3DPipe.h" -// FIXME make int to be uint32 whenever possible - namespace overlay { /* * Used by Overlay class. Invokes each event * */ -/* TODO case of RGBx will call mOv open with diff -* params customized for RGBx pipes */ - class OverlayState : utils::NoCopy { public: /**/ @@ -153,11 +148,11 @@ template <> struct StateTraits template <> struct StateTraits { typedef overlay::GenericPipe pipe0; - typedef overlay::HdmiPipe pipe1; + typedef overlay::VideoExtPipe pipe1; typedef overlay::NullPipe pipe2; // place holder typedef Rotator rot0; - typedef NullRotator rot1; + typedef Rotator rot1; typedef NullRotator rot2; typedef overlay::OverlayImpl ovimpl; @@ -231,11 +226,11 @@ template <> struct StateTraits template <> struct StateTraits { typedef overlay::GenericPipe pipe0; - typedef overlay::HdmiPipe pipe1; + typedef overlay::VideoExtPipe pipe1; typedef overlay::UIMirrorPipe pipe2; typedef Rotator rot0; - typedef NullRotator rot1; + typedef Rotator rot1; typedef Rotator rot2; typedef overlay::OverlayImpl ovimpl; @@ -310,8 +305,8 @@ inline OverlayImplBase* handle_closed_to_xxx() RotatorBase* rot0 = new typename StateTraits::rot0; RotatorBase* rot1 = new typename StateTraits::rot1; RotatorBase* rot2 = new typename StateTraits::rot2; - if(!ov->open(rot0, rot1, rot2)) { - ALOGE("Overlay failed to open in state %d", STATE); + if(!ov->init(rot0, rot1, rot2)) { + ALOGE("Overlay failed to init in state %d", STATE); return 0; } return ov; @@ -329,7 +324,7 @@ inline OverlayImplBase* handle_xxx_to_closed(OverlayImplBase* ov) return 0; } -/* Hard transitions from any state to any state will close and then open */ +/* Hard transitions from any state to any state will close and then init */ template inline OverlayImplBase* handle_xxx_to_xxx(OverlayImplBase* ov) { @@ -392,6 +387,7 @@ inline OverlayImplBase* OverlayState::handleEvent(utils::eOverlayState newState, // FIXME, how to communicate bad transition? // Should we have bool returned from transition func? + // This is also a very good interview question. return newov; } diff --git a/liboverlay/overlayTransitions.cpp b/liboverlay/overlayTransitions.cpp index 45d3720..8096ad5 100644 --- a/liboverlay/overlayTransitions.cpp +++ b/liboverlay/overlayTransitions.cpp @@ -42,12 +42,12 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DPanel( // Create new ovimpl based on new state typedef StateTraits NewState; - OverlayImplBase* newov = new NewState::ovimpl; + OverlayImplBase* newov = new NewState::ovimpl(); //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (GenericPipe) @@ -55,10 +55,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DPanel( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (GenericPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (GenericPipe)", __FUNCTION__); - RotatorBase* rot0 = new NewState::rot0; + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (GenericPipe)", __FUNCTION__); ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + RotatorBase* rot0 = new NewState::rot0; + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (NullPipe) @@ -66,10 +66,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DPanel( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (NullPipe)", __FUNCTION__); - RotatorBase* rot1 = new NewState::rot1; + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (NullPipe)", __FUNCTION__); ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + RotatorBase* rot1 = new NewState::rot1; + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -77,10 +77,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DPanel( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); - RotatorBase* rot2 = new NewState::rot2; + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + RotatorBase* rot2 = new NewState::rot2; + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -106,7 +106,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DTV( //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (GenericPipe) @@ -114,21 +114,21 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DTV( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (GenericPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (GenericPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (GenericPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } - // pipe1/rot1 (HdmiPipe) - if (ov->getOvPipeType(utils::OV_PIPE1) == utils::OV_PIPE_TYPE_HDMI) { - ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (HdmiPipe)", __FUNCTION__); + // pipe1/rot1 (VideoExtPipe) + if (ov->getOvPipeType(utils::OV_PIPE1) == utils::OV_PIPE_TYPE_VIDEO_EXT) { + ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (VideoExtPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (HdmiPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (VideoExtPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -136,10 +136,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_2DTV( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -162,21 +162,22 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DPanel( typedef StateTraits NewState; OverlayImplBase* newov = new NewState::ovimpl; - //=========================================================== + //================================================================= // For each pipe: - // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl - //=========================================================== + // - If pipe matches, copy from previous into new ovimpl. + // (which also makes previous pipe ref 0, so nobody can use) + // - Otherwise init pipe for new ovimpl and delete from previous + //================================================================= // pipe0/rot0 (M3DPrimaryPipe) if (ov->getOvPipeType(utils::OV_PIPE0) == utils::OV_PIPE_TYPE_M3D_PRIMARY) { ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (M3DPrimaryPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (M3DPrimaryPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (M3DPrimaryPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (NullPipe) @@ -184,10 +185,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DPanel( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (NullPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -195,10 +196,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DPanel( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -224,7 +225,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DTV( //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (M3DPrimaryPipe) @@ -232,10 +233,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DTV( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (M3DPrimaryPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (M3DPrimaryPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (M3DPrimaryPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (M3DExtPipe) @@ -243,10 +244,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DTV( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (M3DExtPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (M3DExtPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (M3DExtPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -254,10 +255,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_3D_2DTV( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -283,7 +284,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_trueUI_Mirror( //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (GenericPipe) @@ -291,21 +292,21 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_trueUI_Mirror( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (GenericPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (GenericPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (GenericPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } - // pipe1/rot1 (HdmiPipe) - if (ov->getOvPipeType(utils::OV_PIPE1) == utils::OV_PIPE_TYPE_HDMI) { - ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (HdmiPipe)", __FUNCTION__); + // pipe1/rot1 (VideoExtPipe) + if (ov->getOvPipeType(utils::OV_PIPE1) == utils::OV_PIPE_TYPE_VIDEO_EXT) { + ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (VideoExtPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (HdmiPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (VideoExtPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (UIMirrorPipe) @@ -313,10 +314,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_2D_trueUI_Mirror( ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (UIMirrorPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (UIMirrorPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (UIMirrorPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -341,7 +342,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass1(OverlayImplBase* ov) //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (BypassPipe) @@ -349,10 +350,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass1(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (BypassPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (NullPipe) @@ -360,10 +361,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass1(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (NullPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -371,10 +372,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass1(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -399,7 +400,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass2(OverlayImplBase* ov) //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (BypassPipe) @@ -407,10 +408,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass2(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (BypassPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (BypassPipe) @@ -418,10 +419,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass2(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (BypassPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (NullPipe) @@ -429,10 +430,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass2(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (NullPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (NullPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (NullPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl @@ -457,7 +458,7 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass3(OverlayImplBase* ov) //=========================================================== // For each pipe: // - If pipe matches, copy from previous into new ovimpl - // - Otherwise open for new and delete from previous ovimpl + // - Otherwise init for new and delete from previous ovimpl //=========================================================== // pipe0/rot0 (BypassPipe) @@ -465,10 +466,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass3(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe0 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE0); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe0 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe0 (BypassPipe)", __FUNCTION__); RotatorBase* rot0 = new NewState::rot0; ov->closePipe(utils::OV_PIPE0); - newov->openPipe(rot0, utils::OV_PIPE0); + newov->initPipe(rot0, utils::OV_PIPE0); } // pipe1/rot1 (BypassPipe) @@ -476,10 +477,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass3(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe1 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE1); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe1 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe1 (BypassPipe)", __FUNCTION__); RotatorBase* rot1 = new NewState::rot1; ov->closePipe(utils::OV_PIPE1); - newov->openPipe(rot1, utils::OV_PIPE1); + newov->initPipe(rot1, utils::OV_PIPE1); } // pipe2/rot2 (BypassPipe) @@ -487,10 +488,10 @@ OverlayImplBase* OverlayState::handle_xxx_to_bypass3(OverlayImplBase* ov) ALOGE_IF(DEBUG_OVERLAY, "%s: Copy pipe2 (BypassPipe)", __FUNCTION__); newov->copyOvPipe(ov, utils::OV_PIPE2); } else { - ALOGE_IF(DEBUG_OVERLAY, "%s: Open pipe2 (BypassPipe)", __FUNCTION__); + ALOGE_IF(DEBUG_OVERLAY, "%s: init pipe2 (BypassPipe)", __FUNCTION__); RotatorBase* rot2 = new NewState::rot2; ov->closePipe(utils::OV_PIPE2); - newov->openPipe(rot2, utils::OV_PIPE2); + newov->initPipe(rot2, utils::OV_PIPE2); } // All pipes are copied or deleted so no more need for previous ovimpl diff --git a/liboverlay/overlayUtils.cpp b/liboverlay/overlayUtils.cpp index 38e3ab2..d22d887 100644 --- a/liboverlay/overlayUtils.cpp +++ b/liboverlay/overlayUtils.cpp @@ -70,7 +70,7 @@ struct IOFile { namespace overlay { //----------From class Res ------------------------------ -const char* const Res::devTemplate = "/dev/graphics/fb%u"; +const char* const Res::fbPath = "/dev/graphics/fb%u"; const char* const Res::rotPath = "/dev/msm_rotator"; const char* const Res::format3DFile = "/sys/class/graphics/fb1/format_3d"; @@ -92,7 +92,7 @@ FrameBufferInfo::FrameBufferInfo() { OvFD mFd; // Use open defined in overlayFD file to open fd for fb0 - if(!overlay::open(mFd, 0, Res::devTemplate)) { + if(!overlay::open(mFd, 0, Res::fbPath)) { ALOGE("FrameBufferInfo: failed to open fd"); return; } @@ -146,41 +146,6 @@ bool FrameBufferInfo::supportTrueMirroring() const { } //-------------------------------------------------------- -uint32_t getSize(const Whf& whf) { - int aligned_height=0, pitch=0; - - uint32_t size = whf.w * whf.h; - switch (whf.format) { - case MDP_RGBA_8888: - case MDP_BGRA_8888: - case MDP_RGBX_8888: - size *= 4; - break; - case MDP_RGB_565: - case MDP_Y_CBCR_H2V1: - size *= 2; - break; - case MDP_Y_CBCR_H2V2: - case MDP_Y_CRCB_H2V2: - size = (size * 3) / 2; - break; - case MDP_Y_CRCB_H2V2_TILE: - case MDP_Y_CBCR_H2V2_TILE: - aligned_height = align(whf.h , 32); - pitch = align(whf.w, 128); - size = pitch * aligned_height; - size = align(size, 8192); - - aligned_height = align(whf.h >> 1, 32); - size += pitch * aligned_height; - size = align(size, 8192); - break; - default: - ALOGE("getSize unknown format %d", whf.format); - return 0; - } - return size; -} int getMdpFormat(int format) { switch (format) { @@ -205,7 +170,7 @@ int getMdpFormat(int format) { case HAL_PIXEL_FORMAT_YV12: return MDP_Y_CR_CB_H2V2; default: - ALOGE("Error getMdpFormat format=%d", format); + ALOGE("Error getMdpFormat format=0x%x", format); return -1; } // not reached @@ -229,7 +194,7 @@ bool is3DTV() { bool isPanel3D() { OvFD fd; - if(!overlay::open(fd, 0 /*fb*/, Res::devTemplate)){ + if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){ ALOGE("isPanel3D Can't open framebuffer 0"); return false; } @@ -299,39 +264,6 @@ uint32_t getS3DFormat(uint32_t fmt) { return fmt3D; } -void normalizeCrop(uint32_t& xy, uint32_t& wh) { - if (xy & 0x0001) { - // x or y is odd, increment it's value - xy += 1; - // Since we've incremented x(y), we need to decrement - // w(h) accordingly - if (wh & 0x0001) { - // w or h is odd, decrement it by 1, to make it even - even_out(wh); - } else { - // w(h) is already even, hence we decrement by 2 - wh -=2; - } - } else { - even_out(wh); - } -} - -void scale(mdp_overlay& ov) -{ - /* Scaling of upto a max of 8 times supported */ - overlay::utils::Dim dst(overlay::utils::getDstRectDim(ov)); - overlay::utils::Dim src(overlay::utils::getSrcRectDim(ov)); - if(dst.w >(src.w * overlay::utils::HW_OV_MAGNIFICATION_LIMIT)) { - dst.w = overlay::utils::HW_OV_MAGNIFICATION_LIMIT * src.w; - } - if(dst.h >(src.h * overlay::utils::HW_OV_MAGNIFICATION_LIMIT)) { - dst.h = overlay::utils::HW_OV_MAGNIFICATION_LIMIT * src.h; - } - - setDstRectDim(dst, ov); -} - } // utils } // overlay diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h index 7d964a9..10b0160 100644 --- a/liboverlay/overlayUtils.h +++ b/liboverlay/overlayUtils.h @@ -42,7 +42,7 @@ #include #include #include - +#include "gralloc_priv.h" //for interlace /* * * Collection of utilities functions/structs/enums etc... @@ -70,12 +70,6 @@ class Overlay; namespace utils { struct Whf; struct Dim; -template - inline void even_out(T& x) { if (x & 0x0001) --x; } - -inline uint32_t getBit(uint32_t x, uint32_t mask) { - return (x & mask); -} inline uint32_t setBit(uint32_t x, uint32_t mask) { return (x | mask); @@ -89,7 +83,7 @@ inline uint32_t clrBit(uint32_t x, uint32_t mask) { * and assignment operator private * * Usage: -* * class SomeClass : utils::NoCopy {...}; +* class SomeClass : utils::NoCopy {...}; */ class NoCopy { protected: @@ -147,7 +141,14 @@ enum { BARRIER_LAND = 1, BARRIER_PORT = 2 }; inline uint32_t format3D(uint32_t x) { return x & 0xFF000; } -inline uint32_t colorFormat(uint32_t x) { return x & 0xFFF; } +inline uint32_t colorFormat(uint32_t fmt) { + /*TODO enable this block only if format has interlace / 3D info in top bits. + if(fmt & INTERLACE_MASK) { + fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE; + } + fmt = fmt & 0xFFF;*/ + return fmt; +} inline uint32_t format3DOutput(uint32_t x) { return (x & 0xF000) >> SHIFT_OUT_3D; } inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; } @@ -160,12 +161,15 @@ bool usePanel3D(); bool send3DInfoPacket (uint32_t fmt); bool enableBarrier (uint32_t orientation); uint32_t getS3DFormat(uint32_t fmt); + template - bool getPositionS3D(const Whf& whf, Dim& out); +bool getPositionS3D(const Whf& whf, Dim& out); + template - bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt); +bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt); + template - void swapWidthHeight(Type& width, Type& height); +void swapWidthHeight(Type& width, Type& height); struct Dim { Dim () : x(0), y(0), @@ -193,13 +197,6 @@ struct Dim { return !operator==(d); } - void even_out() { - utils::even_out(x); - utils::even_out(y); - utils::even_out(w); - utils::even_out(h); - } - void dump() const; uint32_t x; uint32_t y; @@ -227,26 +224,12 @@ struct Whf { void dump() const; uint32_t w; uint32_t h; - // FIXME need to be int32_t ? uint32_t format; uint32_t size; }; enum { MAX_PATH_LEN = 256 }; -enum eParams { - OVERLAY_DITHER, - OVERLAY_TRANSFORM, - OVERLAY_TRANSFORM_UI -}; - -struct Params{ - Params(eParams p, int v) : param(p), value(v) {} - eParams param; - int value; -}; - - /** * Rotator flags: not to be confused with orientation flags. * Ususally, you want to open the rotator to make sure it is @@ -267,10 +250,6 @@ enum eRotFlags { ROT_FLAG_ENABLED = 1 // needed in rot }; -/* Used for rotator open. - * FIXME that is default, might be configs */ -enum { ROT_NUM_BUFS = 2 }; - /* Wait/No wait for waiting for vsync * WAIT - wait for vsync, ignore fb (no need to compose w/ fb) * NO_WAIT - do not wait for vsync and return immediatly since @@ -299,14 +278,16 @@ enum eMdpFlags { OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE, OV_MDP_DEINTERLACE = MDP_DEINTERLACE, OV_MDP_PLAY_NOWAIT = MDP_OV_PLAY_NOWAIT, - OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION + OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION, + OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90, + OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB, }; enum eOverlayPipeType { OV_PIPE_TYPE_NULL, OV_PIPE_TYPE_BYPASS, OV_PIPE_TYPE_GENERIC, - OV_PIPE_TYPE_HDMI, + OV_PIPE_TYPE_VIDEO_EXT, OV_PIPE_TYPE_M3D_EXTERNAL, OV_PIPE_TYPE_M3D_PRIMARY, OV_PIPE_TYPE_RGB, @@ -388,18 +369,15 @@ struct PlayInfo { // Used to consolidate pipe params struct PipeArgs { PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE), - orientation(OVERLAY_TRANSFORM_0), wait(NO_WAIT), zorder(Z_SYSTEM_ALLOC), isFg(IS_FG_OFF), rotFlags(ROT_FLAG_DISABLED){ } - PipeArgs(eMdpFlags f, eTransform o, - Whf _whf, eWait w, + PipeArgs(eMdpFlags f, Whf _whf, eWait w, eZorder z, eIsFg fg, eRotFlags r) : mdpFlags(f), - orientation(o), whf(_whf), wait(w), zorder(z), @@ -408,7 +386,6 @@ struct PipeArgs { } eMdpFlags mdpFlags; // for mdp_overlay flags PIPE_SHARE, NO_WAIT, etc - eTransform orientation; // FIXME docs Whf whf; eWait wait; // flags WAIT/NO_WAIT eZorder zorder; // stage number @@ -524,8 +501,6 @@ int getRotOutFmt(uint32_t format); * rotation is 90, 180 etc * It returns MDP related enum/define that match rot+flip*/ int getMdpOrient(eTransform rotation); -uint32_t getSize(const Whf& whf); -uint32_t getSizeByMdp(const Whf& whf); const char* getFormatString(uint32_t format); const char* getStateString(eOverlayState state); @@ -534,16 +509,6 @@ inline int setWait(eWait wait, int flags) { flags &= ~MDP_OV_PLAY_NOWAIT : flags |= MDP_OV_PLAY_NOWAIT; } -/* possible overlay formats libhardware/include/hardware/hardware.h */ -enum eFormat { - OVERLAY_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, - OVERLAY_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, - OVERLAY_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, - OVERLAY_FORMAT_YCbYCr_422_I = 0x14, - OVERLAY_FORMAT_CbYCrY_422_I = 0x16, - OVERLAY_FORMAT_DEFAULT = 99 // The actual color format is - // determined by the overlay -}; // Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time // of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define @@ -551,25 +516,8 @@ enum { HW_OV_MAGNIFICATION_LIMIT = 20, HW_OV_MINIFICATION_LIMIT = 8 }; -inline bool rotated(int orie) { - return (orie == OVERLAY_TRANSFORM_ROT_90 || - orie == OVERLAY_TRANSFORM_ROT_270); -} - -/* used by crop funcs in order to - * normalizes the crop values to be all even */ -void normalizeCrop(uint32_t& xy, uint32_t& wh); - template - inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); } - -template - inline void swapOVRotWidthHeight(ROT& rot, MDP& mdp) - { - mdp.swapSrcWH(); - mdp.swapSrcRectWH(); - rot.swapDstWH(); - } +inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); } template inline void swap ( T& a, T& b ) { @@ -587,35 +535,6 @@ inline int align(int value, int a) { return a ? ((value + (a-1)) & ~(a-1)) : value; } - -template -inline utils::Dim getSrcRectDim(const MDP& ov) { - return utils::Dim(ov.src_rect.x, - ov.src_rect.y, - ov.src_rect.w, - ov.src_rect.h); -} - -template -inline utils::Whf getSrcWhf(const MDP& ov) { - return utils::Whf(ov.src.width, - ov.src.height, - ov.src.format); -} -template -inline void setSrcRectDim(MDP& ov, const utils::Dim& d) { - ov.src_rect.x = d.x; - ov.src_rect.y = d.y; - ov.src_rect.w = d.w; - ov.src_rect.h = d.h; -} -template -inline void setSrcWhf(MDP& ov, const utils::Whf& whf) { - ov.src.width = whf.w; - ov.src.height = whf.h; - ov.src.format = whf.format; -} - enum eRotOutFmt { ROT_OUT_FMT_DEFAULT, ROT_OUT_FMT_Y_CRCB_H2V2 @@ -691,21 +610,30 @@ inline const char* getFormatString(uint32_t format){ "MDP_RGB_565", "MDP_XRGB_8888", "MDP_Y_CBCR_H2V2", + "MDP_Y_CBCR_H2V2_ADRENO", "MDP_ARGB_8888", "MDP_RGB_888", "MDP_Y_CRCB_H2V2", "MDP_YCRYCB_H2V1", "MDP_Y_CRCB_H2V1", "MDP_Y_CBCR_H2V1", + "MDP_Y_CRCB_H1V2", + "MDP_Y_CBCR_H1V2", "MDP_RGBA_8888", "MDP_BGRA_8888", "MDP_RGBX_8888", "MDP_Y_CRCB_H2V2_TILE", "MDP_Y_CBCR_H2V2_TILE", "MDP_Y_CR_CB_H2V2", + "MDP_Y_CR_CB_GH2V2", "MDP_Y_CB_CR_H2V2", - "MDP_IMGTYPE_LIMIT", + "MDP_Y_CRCB_H1V1", + "MDP_Y_CBCR_H1V1", + "MDP_YCRCB_H1V1", + "MDP_YCBCR_H1V1", "MDP_BGR_565", + "MDP_IMGTYPE_LIMIT", + "MDP_RGB_BORDERFILL", "MDP_FB_FORMAT", "MDP_IMGTYPE_LIMIT2" }; @@ -746,15 +674,6 @@ inline const char* getStateString(eOverlayState state){ return "BAD_STATE"; } -inline uint32_t getSizeByMdp(const Whf& whf) { - Whf _whf(whf); - int fmt = getMdpFormat(whf.format); - OVASSERT(-1 != fmt, "getSizeByMdp error in format %d", - whf.format); - _whf.format = fmt; - return getSize(_whf); -} - inline void Whf::dump() const { ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==", w, h, format, size); @@ -766,7 +685,7 @@ inline void Dim::dump() const { inline int getMdpOrient(eTransform rotation) { ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation); - switch(int(rotation)) + switch(static_cast(rotation)) { case OVERLAY_TRANSFORM_0 : return 0; case HAL_TRANSFORM_FLIP_V: return MDP_FLIP_UD; @@ -779,8 +698,8 @@ inline int getMdpOrient(eTransform rotation) { case HAL_TRANSFORM_ROT_180: return MDP_ROT_180; case HAL_TRANSFORM_ROT_270: return MDP_ROT_270; default: - ALOGE("%s: invalid rotation value (value = 0x%x", - __FUNCTION__, rotation); + ALOGE("%s: invalid rotation value (value = 0x%x", + __FUNCTION__, rotation); } return -1; } @@ -801,28 +720,11 @@ inline int getRotOutFmt(uint32_t format) { return -1; } -template<> -struct RotOutFmt -{ - static inline int fmt(uint32_t format) { - return getRotOutFmt(format); - } -}; - -template<> -struct RotOutFmt -{ - static inline int fmt(uint32_t) { - return MDP_Y_CRCB_H2V2; - } -}; inline uint32_t getColorFormat(uint32_t format) { - //XXX: Earlier this used to mask the format - //to check for interlaced or 3D. Just return - //the format now - return format; + return (format == HAL_PIXEL_FORMAT_YV12) ? + format : colorFormat(format); } // FB0 @@ -937,43 +839,6 @@ inline void ScreenInfo::dump(const char* const s) const { s, mFBWidth, mFBHeight, mFBbpp, mFBystride); } -inline void setSrcRectDim(const overlay::utils::Dim d, - mdp_overlay& ov) { - ov.src_rect.x = d.x; - ov.src_rect.y = d.y; - ov.src_rect.w = d.w; - ov.src_rect.h = d.h; -} - -inline void setDstRectDim(const overlay::utils::Dim d, - mdp_overlay& ov) { - ov.dst_rect.x = d.x; - ov.dst_rect.y = d.y; - ov.dst_rect.w = d.w; - ov.dst_rect.h = d.h; -} - -inline overlay::utils::Whf getSrcWhf(const mdp_overlay& ov) { - return overlay::utils::Whf(ov.src.width, - ov.src.height, - ov.src.format); -} - -inline overlay::utils::Dim getSrcRectDim(const mdp_overlay& ov) { - return overlay::utils::Dim(ov.src_rect.x, - ov.src_rect.y, - ov.src_rect.w, - ov.src_rect.h); -} - -inline overlay::utils::Dim getDstRectDim(const mdp_overlay& ov) { - return overlay::utils::Dim(ov.dst_rect.x, - ov.dst_rect.y, - ov.dst_rect.w, - ov.dst_rect.h); -} - - } // namespace utils ends //--------------------Class Res stuff (namespace overlay only) ----------- @@ -981,7 +846,7 @@ inline overlay::utils::Dim getDstRectDim(const mdp_overlay& ov) { class Res { public: // /dev/graphics/fb%u - static const char* const devTemplate; + static const char* const fbPath; // /dev/msm_rotator static const char* const rotPath; // /sys/class/graphics/fb1/format_3d @@ -1060,7 +925,9 @@ inline OvFD::OvFD() : mFD (INVAL) { mPath[0] = 0; } -inline OvFD::~OvFD() { /* no op in the meantime */ } +inline OvFD::~OvFD() { + //no op since copy() can be used to share fd, in 3d cases. +} inline bool OvFD::open(const char* const dev, int flags) { diff --git a/liboverlay/pipes/overlay3DPipe.h b/liboverlay/pipes/overlay3DPipe.h index dce4bf4..86ebed7 100644 --- a/liboverlay/pipes/overlay3DPipe.h +++ b/liboverlay/pipes/overlay3DPipe.h @@ -50,20 +50,15 @@ public: /* Please look at overlayGenPipe.h for info */ explicit M3DExtPipe(); ~M3DExtPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& d); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: @@ -87,20 +82,15 @@ public: /* Please look at overlayGenPipe.h for info */ explicit M3DPrimaryPipe(); ~M3DPrimaryPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& d); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: @@ -124,20 +114,15 @@ public: /* Please look at overlayGenPipe.h for info */ explicit S3DExtPipe(); ~S3DExtPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& d); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: @@ -161,20 +146,15 @@ public: /* Please look at overlayGenPipe.h for info */ explicit S3DPrimaryPipe(); ~S3DPrimaryPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& d); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: @@ -197,10 +177,10 @@ inline M3DExtPipe::M3DExtPipe() : mM3Dfmt(0) {} template inline M3DExtPipe::~M3DExtPipe() { close(); } template -inline bool M3DExtPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "M3DExtPipe open"); - if(!mM3d.open(rot)) { - ALOGE("3Dpipe failed to open"); +inline bool M3DExtPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "M3DExtPipe init"); + if(!mM3d.init(rot)) { + ALOGE("3Dpipe failed to init"); return false; } return true; @@ -212,15 +192,9 @@ inline bool M3DExtPipe::close() { template inline bool M3DExtPipe::commit() { return mM3d.commit(); } template -inline void M3DExtPipe::setId(int id) { mM3d.setId(id); } -template -inline void M3DExtPipe::setMemoryId(int id) { mM3d.setMemoryId(id); } -template -inline bool M3DExtPipe::queueBuffer(uint32_t offset) { - return mM3d.queueBuffer(offset); } -template -inline bool M3DExtPipe::dequeueBuffer(void*& buf) { - return mM3d.dequeueBuffer(buf); } +inline bool M3DExtPipe::queueBuffer(int fd, uint32_t offset) { + return mM3d.queueBuffer(fd, offset); +} template inline bool M3DExtPipe::waitForVsync() { return mM3d.waitForVsync(); } @@ -233,14 +207,7 @@ inline bool M3DExtPipe::setCrop(const utils::Dim& d) { } return mM3d.setCrop(_dim); } -template -inline bool M3DExtPipe::start(const utils::PipeArgs& args) { - if(!mM3d.start(args)) { - ALOGE("M3DExtPipe start failed"); - return false; - } - return true; -} + template inline bool M3DExtPipe::setPosition(const utils::Dim& d) { utils::Dim _dim; @@ -258,8 +225,8 @@ inline bool M3DExtPipe::setPosition(const utils::Dim& d) { return mM3d.setPosition(_dim); } template -inline bool M3DExtPipe::setParameter(const utils::Params& param) { - return mM3d.setParameter(param); +inline bool M3DExtPipe::setTransform(const utils::eTransform& param) { + return mM3d.setTransform(param); } template inline bool M3DExtPipe::setSource(const utils::PipeArgs& args) @@ -267,19 +234,9 @@ inline bool M3DExtPipe::setSource(const utils::PipeArgs& args) // extract 3D fmt mM3Dfmt = utils::format3DInput(utils::getS3DFormat(args.whf.format)) | utils::HAL_3D_OUT_MONOS_MASK; - if(mM3d.isClosed()){ - if(!this->start(args)) { - ALOGE("M3DExtPipe setSource failed to start"); - return false; - } - } return mM3d.setSource(args); } template -inline const utils::PipeArgs& M3DExtPipe::getArgs() const { - return mM3d.getArgs(); -} -template inline utils::eOverlayPipeType M3DExtPipe::getOvPipeType() const { return utils::OV_PIPE_TYPE_M3D_EXTERNAL; } @@ -296,10 +253,10 @@ inline M3DPrimaryPipe::M3DPrimaryPipe() : mM3Dfmt(0) {} template inline M3DPrimaryPipe::~M3DPrimaryPipe() { close(); } template -inline bool M3DPrimaryPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "M3DPrimaryPipe open"); - if(!mM3d.open(rot)) { - ALOGE("3Dpipe failed to open"); +inline bool M3DPrimaryPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "M3DPrimaryPipe init"); + if(!mM3d.init(rot)) { + ALOGE("3Dpipe failed to init"); return false; } return true; @@ -311,15 +268,9 @@ inline bool M3DPrimaryPipe::close() { template inline bool M3DPrimaryPipe::commit() { return mM3d.commit(); } template -inline void M3DPrimaryPipe::setId(int id) { mM3d.setId(id); } -template -inline void M3DPrimaryPipe::setMemoryId(int id) { mM3d.setMemoryId(id); } -template -inline bool M3DPrimaryPipe::queueBuffer(uint32_t offset) { - return mM3d.queueBuffer(offset); } -template -inline bool M3DPrimaryPipe::dequeueBuffer(void*& buf) { - return mM3d.dequeueBuffer(buf); } +inline bool M3DPrimaryPipe::queueBuffer(int fd, uint32_t offset) { + return mM3d.queueBuffer(fd, offset); +} template inline bool M3DPrimaryPipe::waitForVsync() { return mM3d.waitForVsync(); } @@ -333,20 +284,12 @@ inline bool M3DPrimaryPipe::setCrop(const utils::Dim& d) { return mM3d.setCrop(_dim); } template -inline bool M3DPrimaryPipe::start(const utils::PipeArgs& args) { - if(!mM3d.start(args)) { - ALOGE("M3DPrimaryPipe start failed"); - return false; - } - return true; -} -template inline bool M3DPrimaryPipe::setPosition(const utils::Dim& d) { return mM3d.setPosition(d); } template -inline bool M3DPrimaryPipe::setParameter(const utils::Params& param) { - return mM3d.setParameter(param); +inline bool M3DPrimaryPipe::setTransform(const utils::eTransform& param) { + return mM3d.setTransform(param); } template inline bool M3DPrimaryPipe::setSource(const utils::PipeArgs& args) @@ -354,19 +297,9 @@ inline bool M3DPrimaryPipe::setSource(const utils::PipeArgs& args) // extract 3D fmt mM3Dfmt = utils::format3DInput(utils::getS3DFormat(args.whf.format)) | utils::HAL_3D_OUT_MONOS_MASK; - if (mM3d.isClosed()) { - if (!this->start(args)) { - ALOGE("M3DPrimaryPipe setSource failed to start"); - return false; - } - } return mM3d.setSource(args); } template -inline const utils::PipeArgs& M3DPrimaryPipe::getArgs() const { - return mM3d.getArgs(); -} -template inline utils::eOverlayPipeType M3DPrimaryPipe::getOvPipeType() const { return utils::OV_PIPE_TYPE_M3D_PRIMARY; } @@ -382,10 +315,10 @@ inline S3DExtPipe::S3DExtPipe() : mS3Dfmt(0) {} template inline S3DExtPipe::~S3DExtPipe() { close(); } template -inline bool S3DExtPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "S3DExtPipe open"); - if(!mS3d.open(rot)) { - ALOGE("3Dpipe failed to open"); +inline bool S3DExtPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "S3DExtPipe init"); + if(!mS3d.init(rot)) { + ALOGE("3Dpipe failed to init"); return false; } return true; @@ -400,16 +333,9 @@ inline bool S3DExtPipe::close() { template inline bool S3DExtPipe::commit() { return mS3d.commit(); } template -inline void S3DExtPipe::setId(int id) { mS3d.setId(id); } -template -inline void S3DExtPipe::setMemoryId(int id) { mS3d.setMemoryId(id); } -template -inline bool S3DExtPipe::queueBuffer(uint32_t offset) { - //this->dump(); - return mS3d.queueBuffer(offset); } -template -inline bool S3DExtPipe::dequeueBuffer(void*& buf) { - return mS3d.dequeueBuffer(buf); } +inline bool S3DExtPipe::queueBuffer(int fd, uint32_t offset) { + return mS3d.queueBuffer(fd, offset); +} template inline bool S3DExtPipe::waitForVsync() { return mS3d.waitForVsync(); } @@ -423,20 +349,6 @@ inline bool S3DExtPipe::setCrop(const utils::Dim& d) { return mS3d.setCrop(_dim); } template -inline bool S3DExtPipe::start(const utils::PipeArgs& args) { - OVASSERT(mS3Dfmt, "S3DExtPipe mS3Dfmt should not be 0 here"); - if(!mS3d.start(args)) { - ALOGE("S3DExtPipe start failed"); - return false; - } - uint32_t fmt = mS3Dfmt & utils::OUTPUT_3D_MASK; - if(!utils::send3DInfoPacket(fmt)){ - ALOGE("Error S3DExtPipe start error send3DInfoPacket %d", fmt); - return false; - } - return true; -} -template inline bool S3DExtPipe::setPosition(const utils::Dim& d) { utils::Dim _dim; @@ -450,25 +362,15 @@ inline bool S3DExtPipe::setPosition(const utils::Dim& d) return mS3d.setPosition(_dim); } template -inline bool S3DExtPipe::setParameter(const utils::Params& param) { - return mS3d.setParameter(param); +inline bool S3DExtPipe::setTransform(const utils::eTransform& param) { + return mS3d.setTransform(param); } template inline bool S3DExtPipe::setSource(const utils::PipeArgs& args) { mS3Dfmt = utils::getS3DFormat(args.whf.format); - if(mS3d.isClosed()){ - if(!this->start(args)) { - ALOGE("S3DExtPipe setSource failed to start"); - return false; - } - } return mS3d.setSource(args); } template -inline const utils::PipeArgs& S3DExtPipe::getArgs() const { - return mS3d.getArgs(); -} -template inline utils::eOverlayPipeType S3DExtPipe::getOvPipeType() const { return utils::OV_PIPE_TYPE_S3D_EXTERNAL; } @@ -484,10 +386,10 @@ inline S3DPrimaryPipe::S3DPrimaryPipe() : mS3Dfmt(0) {} template inline S3DPrimaryPipe::~S3DPrimaryPipe() { close(); } template -inline bool S3DPrimaryPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "S3DPrimaryPipe open"); - if(!mS3d.open(rot)) { - ALOGE("3Dpipe failed to open"); +inline bool S3DPrimaryPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "S3DPrimaryPipe init"); + if(!mS3d.init(rot)) { + ALOGE("3Dpipe failed to init"); return false; } // set the ctrl fd @@ -502,18 +404,20 @@ inline bool S3DPrimaryPipe::close() { mCtrl3D.close(); return mS3d.close(); } + template -inline bool S3DPrimaryPipe::commit() { return mS3d.commit(); } +inline bool S3DPrimaryPipe::commit() { + uint32_t fmt = mS3Dfmt & utils::OUTPUT_3D_MASK; + if(!utils::send3DInfoPacket(fmt)){ + ALOGE("Error S3DExtPipe start error send3DInfoPacket %d", fmt); + return false; + } + return mS3d.commit(); +} template -inline void S3DPrimaryPipe::setId(int id) { mS3d.setId(id); } -template -inline void S3DPrimaryPipe::setMemoryId(int id) { mS3d.setMemoryId(id); } -template -inline bool S3DPrimaryPipe::queueBuffer(uint32_t offset) { - return mS3d.queueBuffer(offset); } -template -inline bool S3DPrimaryPipe::dequeueBuffer(void*& buf) { - return mS3d.dequeueBuffer(buf); } +inline bool S3DPrimaryPipe::queueBuffer(int fd, uint32_t offset) { + return mS3d.queueBuffer(fd, offset); +} template inline bool S3DPrimaryPipe::waitForVsync() { return mS3d.waitForVsync(); } @@ -527,14 +431,6 @@ inline bool S3DPrimaryPipe::setCrop(const utils::Dim& d) { return mS3d.setCrop(_dim); } template -inline bool S3DPrimaryPipe::start(const utils::PipeArgs& args) { - if(!mS3d.start(args)) { - ALOGE("S3DPrimaryPipe start failed"); - return false; - } - return true; -} -template inline bool S3DPrimaryPipe::setPosition(const utils::Dim& d) { utils::Whf fbwhf(mS3d.getScreenInfo().mFBWidth, @@ -562,47 +458,35 @@ inline bool S3DPrimaryPipe::setPosition(const utils::Dim& d) * So the easiest way to achieve it, is to make sure FB0 is having it before * setParam is running */ template <> -inline bool S3DPrimaryPipe::setParameter( - const utils::Params& param) { - if(utils::OVERLAY_TRANSFORM == param.param){ - uint32_t barrier=0; - switch(param.value) { - case HAL_TRANSFORM_ROT_90: - case HAL_TRANSFORM_ROT_270: - barrier = utils::BARRIER_LAND; - break; - default: - barrier = utils::BARRIER_PORT; - break; - } - if(!utils::enableBarrier(barrier)) { - ALOGE("S3DPrimaryPipe setParameter failed to enable barrier"); - } +inline bool S3DPrimaryPipe::setTransform( + const utils::eTransform& param) { + uint32_t barrier=0; + switch(param) { + case utils::OVERLAY_TRANSFORM_ROT_90: + case utils::OVERLAY_TRANSFORM_ROT_270: + barrier = utils::BARRIER_LAND; + break; + default: + barrier = utils::BARRIER_PORT; + break; } - return mS3d.setParameter(param); + if(!utils::enableBarrier(barrier)) { + ALOGE("S3DPrimaryPipe setTransform failed to enable barrier"); + } + return mS3d.setTransform(param); } template -inline bool S3DPrimaryPipe::setParameter(const utils::Params& param) { - return mS3d.setParameter(param); +inline bool S3DPrimaryPipe::setTransform(const utils::eTransform& param) { + return mS3d.setTransform(param); } template inline bool S3DPrimaryPipe::setSource(const utils::PipeArgs& args) { mS3Dfmt = utils::getS3DFormat(args.whf.format); - if(mS3d.isClosed()){ - if(!this->start(args)) { - ALOGE("S3DPrimaryPipe setSource failed to start"); - return false; - } - } return mS3d.setSource(args); } template -inline const utils::PipeArgs& S3DPrimaryPipe::getArgs() const { - return mS3d.getArgs(); -} -template inline utils::eOverlayPipeType S3DPrimaryPipe::getOvPipeType() const { return utils::OV_PIPE_TYPE_S3D_PRIMARY; } diff --git a/liboverlay/pipes/overlayBypassPipe.h b/liboverlay/pipes/overlayBypassPipe.h index 593a693..bc2232d 100644 --- a/liboverlay/pipes/overlayBypassPipe.h +++ b/liboverlay/pipes/overlayBypassPipe.h @@ -49,20 +49,15 @@ public: /* Please look at overlayGenPipe.h for info */ explicit BypassPipe(); ~BypassPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& dim); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: @@ -83,9 +78,9 @@ inline BypassPipe::~BypassPipe() { template -inline bool BypassPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "BypassPipe open"); - return mBypass.open(rot); +inline bool BypassPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "BypassPipe init"); + return mBypass.init(rot); } template ::commit() { template -inline void BypassPipe::setId(int id) { - mBypass.setId(id); -} - -template -inline void BypassPipe::setMemoryId(int id) { - mBypass.setMemoryId(id); -} - -template -inline bool BypassPipe::queueBuffer( +inline bool BypassPipe::queueBuffer(int fd, uint32_t offset) { - return mBypass.queueBuffer(offset); -} - -template -inline bool BypassPipe::dequeueBuffer( - void*& buf) { - return mBypass.dequeueBuffer(buf); + return mBypass.queueBuffer(fd, offset); } template ::setCrop( return mBypass.setCrop(dim); } -template -inline bool BypassPipe::start( - const utils::PipeArgs& args) { - return mBypass.start(args); -} - template inline bool BypassPipe::setPosition( @@ -155,9 +124,9 @@ inline bool BypassPipe::setPosition( template -inline bool BypassPipe::setParameter( - const utils::Params& param) { - return mBypass.setParameter(param); +inline bool BypassPipe::setTransform( + const utils::eTransform& param) { + return mBypass.setTransform(param); } template ::setSource( return mBypass.setSource(arg); } -template -inline const utils::PipeArgs& BypassPipe::getArgs() const { - return mBypass.getArgs(); -} - template inline utils::eOverlayPipeType BypassPipe class GenericPipe : utils::NoCopy { public: - /* ctor init */ + /* ctor */ explicit GenericPipe(); - - /* dtor close */ + /* dtor */ ~GenericPipe(); - - /* CTRL/DATA/ROT open */ - bool open(RotatorBase* rot); - + /* CTRL/DATA init. Not owning rotator, will not init it */ + bool init(RotatorBase* rot); /* CTRL/DATA close. Not owning rotator, will not close it */ bool close(); + /* Control APIs */ + /* set source using whf, orient and wait flag */ + bool setSource(const utils::PipeArgs& args); + /* set crop a.k.a the region of interest */ + bool setCrop(const utils::Dim& d); + /* set orientation*/ + bool setTransform(const utils::eTransform& param); + /* set mdp posision using dim */ + bool setPosition(const utils::Dim& dim); /* commit changes to the overlay "set"*/ bool commit(); - /* "Data" related interface */ - - /* set ID directly to data channel */ - void setId(int id); - - /* Set FD / memid */ - void setMemoryId(int id); - + /* Data APIs */ /* queue buffer to the overlay */ - bool queueBuffer(uint32_t offset); - - /* dequeue buffer to the overlay NOTSUPPORTED */ - bool dequeueBuffer(void*& buf); - + bool queueBuffer(int fd, uint32_t offset); /* wait for vsync to be done */ bool waitForVsync(); - /* set crop data FIXME setROI (Region Of Intrest) */ - bool setCrop(const utils::Dim& d); - - /* "Ctrl" related interface */ - - /* - * Start a session, opens the rotator - * FIXME, we might want to open the rotator separately - */ - bool start(const utils::PipeArgs& args); - - /* set mdp posision using dim */ - bool setPosition(const utils::Dim& dim); - - /* set param using Params (param,value pair) */ - bool setParameter(const utils::Params& param); - - /* set source using whf, orient and wait flag */ - bool setSource(const utils::PipeArgs& args); - /* return cached startup args */ const utils::PipeArgs& getArgs() const; @@ -123,10 +96,8 @@ public: /* dump the state of the object */ void dump() const; private: - /* set Closed channel */ + /* set Closed pipe */ bool setClosed(); - // kick off rotator. - bool startRotator(); /* Ctrl/Data aggregator */ CtrlData mCtrlData; @@ -141,15 +112,23 @@ private: * Can point to NullRotator or to Rotator*/ RotatorBase* mRot; - /* my flags */ - enum { CLOSED = 1<<0 }; - uint32_t mFlags; + //Whether rotator is used for 0-rot or otherwise + bool mRotUsed; + + /* Pipe open or closed */ + enum ePipeState { + CLOSED, + OPEN + }; + ePipeState pipeState; }; //------------------------Inlines and Templates ---------------------- template -GenericPipe::GenericPipe() : mRot(0), mFlags(CLOSED) {} +GenericPipe::GenericPipe() : mRot(0), mRotUsed(false), + pipeState(CLOSED) { +} template GenericPipe::~GenericPipe() { @@ -157,33 +136,42 @@ GenericPipe::~GenericPipe() { } template -bool GenericPipe::open(RotatorBase* rot) +bool GenericPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "GenericPipe init"); OVASSERT(rot, "rot is null"); - // open ctrl and data + + // init ctrl and data uint32_t fbnum = utils::getFBForPanel(PANEL); - ALOGE_IF(DEBUG_OVERLAY, "GenericPipe open"); - if(!mCtrlData.ctrl.open(fbnum, rot)) { - ALOGE("GenericPipe failed to open ctrl"); + + if(!mCtrlData.ctrl.init(fbnum)) { + ALOGE("GenericPipe failed to init ctrl"); return false; } - if(!mCtrlData.data.open(fbnum, rot)) { - ALOGE("GenericPipe failed to open data"); + + if(!mCtrlData.data.init(fbnum)) { + ALOGE("GenericPipe failed to init data"); return false; } + + //Cache the rot ref. Ownership is with OverlayImpl. mRot = rot; - // NOTE: we won't have the flags as non CLOSED since we - // consider the pipe opened for business only when we call - // start() + mRotUsed = false; + + // NOTE:init() on the rot is called by OverlayImpl + // Pipes only have to worry about using rot, and not init or close. return true; } template bool GenericPipe::close() { - if(isClosed()) return true; + if(isClosed()) + return true; + bool ret = true; + if(!mCtrlData.ctrl.close()) { ALOGE("GenericPipe failed to close ctrl"); ret = false; @@ -192,153 +180,117 @@ bool GenericPipe::close() { ALOGE("GenericPipe failed to close data"); ret = false; } + + // NOTE:close() on the rot is called by OverlayImpl + // Pipes only have to worry about using rot, and not init or close. + setClosed(); return ret; } template -inline bool GenericPipe::commit(){ - OVASSERT(isOpen(), "State is closed, cannot commit"); - return mCtrlData.ctrl.commit(); +inline bool GenericPipe::setSource( + const utils::PipeArgs& args) +{ + utils::PipeArgs newargs(args); + //Interlace video handling. + if(newargs.whf.format & INTERLACE_MASK) { + setMdpFlags(newargs.mdpFlags, utils::OV_MDP_DEINTERLACE); + } + utils::Whf whf(newargs.whf); + //Extract HAL format from lower bytes. Deinterlace if interlaced. + whf.format = utils::getColorFormat(whf.format); + //Get MDP equivalent of HAL format. + whf.format = utils::getMdpFormat(whf.format); + newargs.whf = whf; + + //Cache if user wants 0-rotation + mRotUsed = newargs.rotFlags & utils::ROT_FLAG_ENABLED; + mRot->setSource(newargs.whf); + return mCtrlData.ctrl.setSource(newargs); } template -inline void GenericPipe::setMemoryId(int id) { - OVASSERT(isOpen(), "State is closed, cannot setMemoryId"); - mCtrlData.data.setMemoryId(id); +inline bool GenericPipe::setCrop( + const overlay::utils::Dim& d) { + return mCtrlData.ctrl.setCrop(d); } template -inline void GenericPipe::setId(int id) { - mCtrlData.data.setId(id); } +inline bool GenericPipe::setTransform( + const utils::eTransform& orient) +{ + //Rotation could be enabled by user for zero-rot or the layer could have + //some transform. Mark rotation enabled in either case. + mRotUsed |= (orient != utils::OVERLAY_TRANSFORM_0); + mRot->setTransform(orient, mRotUsed); + + return mCtrlData.ctrl.setTransform(orient, mRotUsed); +} + +template +inline bool GenericPipe::setPosition(const utils::Dim& d) +{ + return mCtrlData.ctrl.setPosition(d); +} + +template +inline bool GenericPipe::commit() { + bool ret = false; + //If wanting to use rotator, start it. + if(mRotUsed) { + if(!mRot->commit()) { + ALOGE("GenPipe Rotator commit failed"); + return false; + } + } + ret = mCtrlData.ctrl.commit(); + pipeState = ret ? OPEN : CLOSED; + return ret; +} + +template +inline bool GenericPipe::queueBuffer(int fd, uint32_t offset) { + //TODO Move pipe-id transfer to CtrlData class. Make ctrl and data private. + OVASSERT(isOpen(), "State is closed, cannot queueBuffer"); + int pipeId = mCtrlData.ctrl.getPipeId(); + OVASSERT(-1 != pipeId, "Ctrl ID should not be -1"); + // set pipe id from ctrl to data + mCtrlData.data.setPipeId(pipeId); + + int finalFd = fd; + uint32_t finalOffset = offset; + //If rotator is to be used, queue to it, so it can ROTATE. + if(mRotUsed) { + if(!mRot->queueBuffer(fd, offset)) { + ALOGE("GenPipe Rotator play failed"); + return false; + } + //Configure MDP's source buffer as the current output buffer of rotator + if(mRot->getDstMemId() != -1) { + finalFd = mRot->getDstMemId(); + finalOffset = mRot->getDstOffset(); + } else { + //Could be -1 for NullRotator, if queue above succeeds. + //Need an actual rotator. Modify overlay State Traits. + //Not fatal, keep queuing to MDP without rotation. + ALOGE("Null rotator in use, where an actual is required"); + } + } + return mCtrlData.data.queueBuffer(finalFd, finalOffset); +} template inline int GenericPipe::getCtrlFd() const { return mCtrlData.ctrl.getFd(); } -template -inline bool GenericPipe::setCrop( - const overlay::utils::Dim& d) { - OVASSERT(isOpen(), "State is closed, cannot setCrop"); - return mCtrlData.ctrl.setCrop(d); -} - -template -bool GenericPipe::start(const utils::PipeArgs& args) -{ - /* open before your start control rotator */ - uint32_t sz = args.whf.size; //utils::getSizeByMdp(args.whf); - OVASSERT(sz, "GenericPipe sz=%d", sz); - if(!mRot->open()) { - ALOGE("GenericPipe start failed to open rot"); - return false; - } - - if(!mCtrlData.ctrl.start(args)){ - ALOGE("GenericPipe failed to start"); - return false; - } - - int ctrlId = mCtrlData.ctrl.getId(); - OVASSERT(-1 != ctrlId, "Ctrl ID should not be -1"); - // set ID requeset to assoc ctrl to data - setId(ctrlId); - // set ID request to assoc MDP data to ROT MDP data - mRot->setDataReqId(mCtrlData.data.getId()); - - // cache the args for future reference. - mArgs = args; - - // we got here so we are open+start and good to go - mFlags = 0; // clear flags from CLOSED - // TODO make it more robust when more flags - // are added - - return true; -} - -template -inline const utils::PipeArgs& GenericPipe::getArgs() const -{ - return mArgs; -} - -template -bool GenericPipe::startRotator() { - // kick off rotator - if(!mRot->start()) { - ALOGE("GenericPipe failed to start rotator"); - return false; - } - return true; -} - -template -inline bool GenericPipe::queueBuffer(uint32_t offset) { - OVASSERT(isOpen(), "State is closed, cannot queueBuffer"); - return mCtrlData.data.queueBuffer(offset); -} - -template -inline bool GenericPipe::dequeueBuffer(void*&) { - OVASSERT(isOpen(), "State is closed, cannot dequeueBuffer"); - // can also set error to NOTSUPPORTED in the future - return false; -} - template inline bool GenericPipe::waitForVsync() { OVASSERT(isOpen(), "State is closed, cannot waitForVsync"); - return mCtrlData.data.waitForVsync(); } -template -inline bool GenericPipe::setPosition(const utils::Dim& dim) -{ - OVASSERT(isOpen(), "State is closed, cannot setPosition"); - return mCtrlData.ctrl.setPosition(dim); -} - -template -inline bool GenericPipe::setParameter( - const utils::Params& param) -{ - OVASSERT(isOpen(), "State is closed, cannot setParameter"); - // Currently setParameter would start rotator - if(!mCtrlData.ctrl.setParameter(param)) { - ALOGE("GenericPipe failed to setparam"); - return false; - } - // if rot flags are ENABLED it means we would always - // like to have rot. Even with 0 rot. (solves tearing) - if(utils::ROT_FLAG_ENABLED == mArgs.rotFlags) { - mRot->setEnable(); - } - return startRotator(); -} - -template -inline bool GenericPipe::setSource( - const utils::PipeArgs& args) -{ - // cache the recent args. - mArgs = args; - // setSource is the 1st thing that is being called on a pipe. - // If pipe is closed, we should start everything. - // we assume it is being opened with the correct FDs. - if(isClosed()) { - if(!this->start(args)) { - ALOGE("GenericPipe setSource failed to start"); - return false; - } - return true; - } - - return mCtrlData.ctrl.setSource(args); -} - template inline utils::Dim GenericPipe::getAspectRatio( const utils::Whf& whf) const @@ -374,7 +326,7 @@ template void GenericPipe::dump() const { ALOGE("== Dump Generic pipe start =="); - ALOGE("flags=0x%x", mFlags); + ALOGE("pipe state = %d", (int)pipeState); OVASSERT(mRot, "GenericPipe should have a valid Rot"); mCtrlData.ctrl.dump(); mCtrlData.data.dump(); @@ -384,20 +336,20 @@ void GenericPipe::dump() const template inline bool GenericPipe::isClosed() const { - return utils::getBit(mFlags, CLOSED); + return (pipeState == CLOSED); } template inline bool GenericPipe::isOpen() const { - return !isClosed(); + return (pipeState == OPEN); } template inline bool GenericPipe::setClosed() { - return utils::setBit(mFlags, CLOSED); + pipeState = CLOSED; + return true; } - } //namespace overlay #endif // OVERLAY_GENERIC_PIPE_H diff --git a/liboverlay/pipes/overlayUIMirrorPipe.h b/liboverlay/pipes/overlayUIMirrorPipe.h index 47fbc37..733bf84 100644 --- a/liboverlay/pipes/overlayUIMirrorPipe.h +++ b/liboverlay/pipes/overlayUIMirrorPipe.h @@ -46,74 +46,61 @@ public: /* Please look at overlayGenPipe.h for info */ explicit UIMirrorPipe(); ~UIMirrorPipe(); - bool open(RotatorBase* rot); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& dim); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: overlay::GenericPipe mUI; + utils::eTransform mPrimFBOr; //Primary FB's orientation }; //----------------------------Inlines ----------------------------- -inline UIMirrorPipe::UIMirrorPipe() {} +inline UIMirrorPipe::UIMirrorPipe() { mPrimFBOr = utils::OVERLAY_TRANSFORM_0; } inline UIMirrorPipe::~UIMirrorPipe() { close(); } -inline bool UIMirrorPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "UIMirrorPipe open"); - bool ret = mUI.open(rot); - //If source to rotator is framebuffer, which is the case we UI Mirror pipe, - //we need to inform driver during playback. Since FB does not use ION. +inline bool UIMirrorPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "UIMirrorPipe init"); + bool ret = mUI.init(rot); + //If source to rotator is FB, which is the case with UI Mirror pipe, + //we need to inform driver during playback, since FB does not use ION. rot->setSrcFB(true); return ret; } inline bool UIMirrorPipe::close() { return mUI.close(); } inline bool UIMirrorPipe::commit() { return mUI.commit(); } -inline void UIMirrorPipe::setId(int id) { mUI.setId(id); } -inline void UIMirrorPipe::setMemoryId(int id) { mUI.setMemoryId(id); } -inline bool UIMirrorPipe::queueBuffer(uint32_t offset) { - return mUI.queueBuffer(offset); } -inline bool UIMirrorPipe::dequeueBuffer(void*& buf) { - return mUI.dequeueBuffer(buf); } +inline bool UIMirrorPipe::queueBuffer(int fd, uint32_t offset) { + return mUI.queueBuffer(fd, offset); +} inline bool UIMirrorPipe::waitForVsync() { return mUI.waitForVsync(); } inline bool UIMirrorPipe::setCrop(const utils::Dim& dim) { return mUI.setCrop(dim); } -inline bool UIMirrorPipe::start(const utils::PipeArgs& args) { - if(!mUI.start(args)) { - ALOGE("%s failed to start", __FUNCTION__); - return false; - } - return true; -} -inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) { +inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) { ovutils::Dim pdim; - switch (dim.o) { - case 0: - case HAL_TRANSFORM_ROT_180: + //using utils::eTransform; + switch (mPrimFBOr) { + case utils::OVERLAY_TRANSFORM_0: + case utils::OVERLAY_TRANSFORM_ROT_180: { - ovutils::Whf whf(dim.x, dim.y, 0); + ovutils::Whf whf(dim.w, dim.h, 0); pdim = mUI.getAspectRatio(whf); break; } - case HAL_TRANSFORM_ROT_90: - case HAL_TRANSFORM_ROT_270: + case utils::OVERLAY_TRANSFORM_ROT_90: + case utils::OVERLAY_TRANSFORM_ROT_270: { // Calculate the Aspectratio for the UI in the landscape mode // Width and height will be swapped as there is rotation - ovutils::Whf whf(dim.y, dim.x, 0); + ovutils::Whf whf(dim.h, dim.w, 0); pdim = mUI.getAspectRatio(whf); break; } @@ -121,43 +108,43 @@ inline bool UIMirrorPipe::setPosition(const utils::Dim& dim) { ALOGE("%s: Unknown orientation %d", __FUNCTION__, dim.o); return false; } - - ovutils::even_out(pdim.x); - ovutils::even_out(pdim.y); - ovutils::even_out(pdim.w); - ovutils::even_out(pdim.h); return mUI.setPosition(pdim); } -inline bool UIMirrorPipe::setParameter(const utils::Params& param) { - OVASSERT(utils::OVERLAY_TRANSFORM_UI == param.param, - "%p Expecting OVERLAY_TRANSFORM_UI", __FUNCTION__); +inline bool UIMirrorPipe::setTransform(const utils::eTransform& param) { - int orientation = param.value; + //Cache the primary FB orientation, since the TV's will be 0, we need this + //info to translate later. + mPrimFBOr = param; + utils::eTransform transform = param; // Figure out orientation to transform to - switch (param.value) { - case 0: - orientation = 0; + switch (param) { + case utils::OVERLAY_TRANSFORM_0: + transform = utils::OVERLAY_TRANSFORM_0; break; - case HAL_TRANSFORM_ROT_180: - orientation = HAL_TRANSFORM_ROT_180; + case utils::OVERLAY_TRANSFORM_ROT_180: + //If prim FB is drawn 180 rotated, rotate by additional 180 to make + //it to 0, which is TV's orientation. + transform = utils::OVERLAY_TRANSFORM_ROT_180; break; - case HAL_TRANSFORM_ROT_90: - orientation = HAL_TRANSFORM_ROT_270; + case utils::OVERLAY_TRANSFORM_ROT_90: + //If prim FB is drawn 90 rotated, rotate by additional 270 to make + //it to 0, which is TV's orientation. + transform = utils::OVERLAY_TRANSFORM_ROT_270; break; - case HAL_TRANSFORM_ROT_270: - orientation = HAL_TRANSFORM_ROT_90; + case utils::OVERLAY_TRANSFORM_ROT_270: + //If prim FB is drawn 270 rotated, rotate by additional 90 to make + //it to 0, which is TV's orientation. + transform = utils::OVERLAY_TRANSFORM_ROT_90; break; default: - ALOGE("%s: Unknown orientation %d", __FUNCTION__, param.value); + ALOGE("%s: Unknown orientation %d", __FUNCTION__, + static_cast(param)); return false; } - ovutils::eTransform transform = - static_cast(orientation); - const ovutils::Params prms (ovutils::OVERLAY_TRANSFORM, transform); - return mUI.setParameter(prms); + return mUI.setTransform(transform); } inline bool UIMirrorPipe::setSource(const utils::PipeArgs& args) { @@ -175,9 +162,6 @@ inline bool UIMirrorPipe::setSource(const utils::PipeArgs& args) { return mUI.setSource(arg); } -inline const utils::PipeArgs& UIMirrorPipe::getArgs() const { - return mUI.getArgs(); -} inline utils::eOverlayPipeType UIMirrorPipe::getOvPipeType() const { return utils::OV_PIPE_TYPE_UI_MIRROR; } diff --git a/liboverlay/pipes/overlayHdmiPipe.h b/liboverlay/pipes/overlayVideoExtPipe.h similarity index 55% rename from liboverlay/pipes/overlayHdmiPipe.h rename to liboverlay/pipes/overlayVideoExtPipe.h index 48c3817..8196fe7 100644 --- a/liboverlay/pipes/overlayHdmiPipe.h +++ b/liboverlay/pipes/overlayVideoExtPipe.h @@ -27,8 +27,8 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OVERLAY_HDMI_PIPE_H -#define OVERLAY_HDMI_PIPE_H +#ifndef OVERLAY_VIDEO_EXT_PIPE_H +#define OVERLAY_VIDEO_EXT_PIPE_H #include "overlayGenPipe.h" #include "overlayUtils.h" @@ -41,88 +41,79 @@ namespace overlay { /* A specific impl of GenericPipe * Whenever needed to have a pass through - we do it. * If there is a special need for a different behavior - do it here */ -class HdmiPipe : utils::NoCopy { +class VideoExtPipe : utils::NoCopy { public: /* Please look at overlayGenPipe.h for info */ - explicit HdmiPipe(); - ~HdmiPipe(); - bool open(RotatorBase* rot); + explicit VideoExtPipe(); + ~VideoExtPipe(); + bool init(RotatorBase* rot); bool close(); bool commit(); - void setId(int id); - void setMemoryId(int id); - bool queueBuffer(uint32_t offset); - bool dequeueBuffer(void*& buf); + bool queueBuffer(int fd, uint32_t offset); bool waitForVsync(); bool setCrop(const utils::Dim& dim); - bool start(const utils::PipeArgs& args); bool setPosition(const utils::Dim& dim); - bool setParameter(const utils::Params& param); + bool setTransform(const utils::eTransform& param); bool setSource(const utils::PipeArgs& args); - const utils::PipeArgs& getArgs() const; utils::eOverlayPipeType getOvPipeType() const; void dump() const; private: - overlay::GenericPipe mHdmi; + overlay::GenericPipe mVideoExt; }; //------------------Inlines ----------------------------- -inline HdmiPipe::HdmiPipe() {} -inline HdmiPipe::~HdmiPipe() { close(); } -inline bool HdmiPipe::open(RotatorBase* rot) { - ALOGE_IF(DEBUG_OVERLAY, "HdmiPipe open"); - return mHdmi.open(rot); +inline VideoExtPipe::VideoExtPipe() {} +inline VideoExtPipe::~VideoExtPipe() { close(); } +inline bool VideoExtPipe::init(RotatorBase* rot) { + ALOGE_IF(DEBUG_OVERLAY, "VideoExtPipe init"); + return mVideoExt.init(rot); } -inline bool HdmiPipe::close() { return mHdmi.close(); } -inline bool HdmiPipe::commit() { return mHdmi.commit(); } -inline void HdmiPipe::setId(int id) { mHdmi.setId(id); } -inline void HdmiPipe::setMemoryId(int id) { mHdmi.setMemoryId(id); } -inline bool HdmiPipe::queueBuffer(uint32_t offset) { - return mHdmi.queueBuffer(offset); } -inline bool HdmiPipe::dequeueBuffer(void*& buf) { - return mHdmi.dequeueBuffer(buf); } -inline bool HdmiPipe::waitForVsync() { - return mHdmi.waitForVsync(); } -inline bool HdmiPipe::setCrop(const utils::Dim& dim) { - return mHdmi.setCrop(dim); } -inline bool HdmiPipe::start(const utils::PipeArgs& args) { - return mHdmi.start(args); } -inline bool HdmiPipe::setPosition(const utils::Dim& dim) +inline bool VideoExtPipe::close() { return mVideoExt.close(); } +inline bool VideoExtPipe::commit() { return mVideoExt.commit(); } +inline bool VideoExtPipe::queueBuffer(int fd, uint32_t offset) { + return mVideoExt.queueBuffer(fd, offset); +} +inline bool VideoExtPipe::waitForVsync() { + return mVideoExt.waitForVsync(); +} +inline bool VideoExtPipe::setCrop(const utils::Dim& dim) { + return mVideoExt.setCrop(dim); +} +inline bool VideoExtPipe::setPosition(const utils::Dim& dim) { utils::Dim d; // Need to change dim to aspect ratio if (utils::FrameBufferInfo::getInstance()->supportTrueMirroring()) { // Use dim info to calculate aspect ratio for true UI mirroring - d = mHdmi.getAspectRatio(dim); + d = mVideoExt.getAspectRatio(dim); } else { // Use cached crop data to get aspect ratio - utils::Dim crop = mHdmi.getCrop(); + utils::Dim crop = mVideoExt.getCrop(); utils::Whf whf(crop.w, crop.h, 0); - d = mHdmi.getAspectRatio(whf); + d = mVideoExt.getAspectRatio(whf); } - ALOGE_IF(DEBUG_OVERLAY, "Calculated aspect ratio for HDMI: x=%d, y=%d, w=%d, h=%d, o=%d", + ALOGE_IF(DEBUG_OVERLAY, "Calculated aspect ratio for EXT: x=%d, y=%d, w=%d," + "h=%d, o=%d", d.x, d.y, d.w, d.h, d.o); - return mHdmi.setPosition(d); + return mVideoExt.setPosition(d); } -inline bool HdmiPipe::setParameter(const utils::Params& param) { - return mHdmi.setParameter(param); } -inline bool HdmiPipe::setSource(const utils::PipeArgs& args) { +inline bool VideoExtPipe::setTransform(const utils::eTransform& param) { + return mVideoExt.setTransform(param); +} +inline bool VideoExtPipe::setSource(const utils::PipeArgs& args) { utils::PipeArgs arg(args); - return mHdmi.setSource(arg); + return mVideoExt.setSource(arg); } -inline const utils::PipeArgs& HdmiPipe::getArgs() const { - return mHdmi.getArgs(); +inline utils::eOverlayPipeType VideoExtPipe::getOvPipeType() const { + return utils::OV_PIPE_TYPE_VIDEO_EXT; } -inline utils::eOverlayPipeType HdmiPipe::getOvPipeType() const { - return utils::OV_PIPE_TYPE_HDMI; -} -inline void HdmiPipe::dump() const { - ALOGE("HDMI Pipe"); - mHdmi.dump(); +inline void VideoExtPipe::dump() const { + ALOGE("Video Ext Pipe"); + mVideoExt.dump(); } } // overlay -#endif // OVERLAY_HDMI_PIPE_H +#endif // OVERLAY_VIDEO_EXT_PIPE_H