107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani/* 207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* Copyright (c) 2011,2013 The Linux Foundation. All rights reserved. 307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* 407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* Redistribution and use in source and binary forms, with or without 507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* modification, are permitted provided that the following conditions are 607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* met: 707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* * Redistributions of source code must retain the above copyright 807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* notice, this list of conditions and the following disclaimer. 907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* * Redistributions in binary form must reproduce the above 1007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* copyright notice, this list of conditions and the following 1107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* disclaimer in the documentation and/or other materials provided 1207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* with the distribution. 1307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* * Neither the name of The Linux Foundation. nor the names of its 1407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* contributors may be used to endorse or promote products derived 1507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* from this software without specific prior written permission. 1607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* 1707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 1807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 2007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 2107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 2607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani*/ 2907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#ifndef OVERlAY_ROTATOR_H 3107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#define OVERlAY_ROTATOR_H 3207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#include <stdlib.h> 3407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#include "mdpWrapper.h" 3607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#include "overlayUtils.h" 3707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#include "overlayMem.h" 3807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaninamespace overlay { 4007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 4107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani/* 4207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani Manages the case where new rotator memory needs to be 4307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani allocated, before previous is freed, due to resolution change etc. If we make 4407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani rotator memory to be always max size, irrespctive of source resolution then 4507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani we don't need this RotMem wrapper. The inner class is sufficient. 4607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani*/ 4707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanistruct RotMem { 4807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Max rotator buffers 4907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani enum { ROT_NUM_BUFS = 2 }; 5007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani RotMem(); 5107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani ~RotMem(); 5207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool close(); 5307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool valid() { return mem.valid(); } 5407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t size() const { return mem.bufSz(); } 5507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void setCurrBufReleaseFd(const int& fence); 5607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void setPrevBufReleaseFd(const int& fence); 5707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 5807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // rotator data info dst offset 5907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t mRotOffset[ROT_NUM_BUFS]; 6007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int mRelFence[ROT_NUM_BUFS]; 6107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // current slot being used 6207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t mCurrIndex; 6307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani OvMem mem; 6407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 6507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 6607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniclass Rotator 6707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani{ 6807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanipublic: 6907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani enum { TYPE_MDP, TYPE_MDSS }; 7007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual ~Rotator(); 7107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setSource(const utils::Whf& wfh) = 0; 7207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setCrop(const utils::Dim& crop) = 0; 7307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setFlags(const utils::eMdpFlags& flags) = 0; 7407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setTransform(const utils::eTransform& rot) = 0; 7507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool commit() = 0; 7607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* return true if the current rotator state is cached */ 7707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool isRotCached(int fd, uint32_t offset) const; 7807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* return true if current rotator config is same as the last round*/ 7907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool rotConfChanged() const = 0; 8007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* return true if the current rotator input buffer fd and offset 8107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * are same as the last round */ 8207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool rotDataChanged(int fd, uint32_t offset) const; 8307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setDownscale(int ds) = 0; 8407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* returns the src buffer of the rotator for the previous/current round, 8507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * depending on when it is called(before/after the queuebuffer)*/ 8607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getSrcMemId() const = 0; 8707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani //Mem id and offset should be retrieved only after rotator kickoff 8807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getDstMemId() const = 0; 8907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSrcOffset() const = 0; 9007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstOffset() const = 0; 9107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani //Destination width, height, format, position should be retrieved only after 9207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani //rotator configuration is committed via commit API 9307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstFormat() const = 0; 9407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Whf getDstWhf() const = 0; 9507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Dim getDstDimensions() const = 0; 9607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSessId() const = 0; 9707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool queueBuffer(int fd, uint32_t offset) = 0; 9807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void dump() const = 0; 9907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void getDump(char *buf, size_t len) const = 0; 10007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani inline void setCurrBufReleaseFd(const int& fence) { 10107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani mMem.setCurrBufReleaseFd(fence); 10207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani } 10307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani inline void setPrevBufReleaseFd(const int& fence) { 10407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani mMem.setPrevBufReleaseFd(fence); 10507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani } 10607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static Rotator *getRotator(); 10707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Returns downscale by successfully applying constraints 10807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Returns 0 if target doesnt support rotator downscaling 10907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * or if any of the constraints are not met 11007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani */ 11107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static int getDownscaleFactor(const int& srcW, const int& srcH, 11207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const int& dstW, const int& dstH, const uint32_t& mdpFormat, 11307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const bool& isInterlaced); 11407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 11507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniprotected: 11607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Rotator memory manager */ 11707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani RotMem mMem; 11807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani Rotator(); 11907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static uint32_t calcOutputBufSize(const utils::Whf& destWhf); 12007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 12107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniprivate: 12207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool mRotCacheDisabled; 12307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /*Returns rotator h/w type */ 12407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static int getRotatorHwType(); 12507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani friend class RotMgr; 12607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 12707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 12807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani/* 12907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* MDP rot holds MDP's rotation related structures. 13007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* 13107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani* */ 13207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniclass MdpRot : public Rotator { 13307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanipublic: 13407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual ~MdpRot(); 13507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setSource(const utils::Whf& wfh); 13607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setCrop(const utils::Dim& crop); 13707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setFlags(const utils::eMdpFlags& flags); 13807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setTransform(const utils::eTransform& rot); 13907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool commit(); 14007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool rotConfChanged() const; 14107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setDownscale(int ds); 14207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getSrcMemId() const; 14307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getDstMemId() const; 14407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSrcOffset() const; 14507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstOffset() const; 14607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstFormat() const; 14707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Whf getDstWhf() const; 14807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Dim getDstDimensions() const; 14907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSessId() const; 15007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool queueBuffer(int fd, uint32_t offset); 15107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void dump() const; 15207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void getDump(char *buf, size_t len) const; 15307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 15407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniprivate: 15507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani explicit MdpRot(); 15607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool init(); 15707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool close(); 15807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void setRotations(uint32_t r); 15907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool enabled () const; 16007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* remap rot buffers */ 16107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool remap(uint32_t numbufs); 16207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool open_i(uint32_t numbufs, uint32_t bufsz); 16307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Deferred transform calculations */ 16407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void doTransform(); 16507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* reset underlying data, basically memset 0 */ 16607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void reset(); 16707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* save mRotImgInfo to be last known good config*/ 16807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void save(); 16907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Calculates the rotator's o/p buffer size post the transform calcs and 17007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * knowing the o/p format depending on whether fastYuv is enabled or not */ 17107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t calcOutputBufSize(); 17207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 17307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Applies downscale by taking areas 17407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Returns a log(downscale) 17507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Constraints applied: 17607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - downscale should be a power of 2 17707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - Max downscale is 1/8 17807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani */ 17907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static int getDownscaleFactor(const int& srcW, const int& srcH, 18007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const int& dstW, const int& dstH, const uint32_t& mdpFormat, 18107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const bool& isInterlaced); 18207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 18307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* rot info*/ 18407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani msm_rotator_img_info mRotImgInfo; 18507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Last saved rot info*/ 18607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani msm_rotator_img_info mLSRotImgInfo; 18707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* rot data */ 18807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani msm_rotator_data_info mRotDataInfo; 18907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Orientation */ 19007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani utils::eTransform mOrientation; 19107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* rotator fd */ 19207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani OvFD mFd; 19307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 19407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani friend Rotator* Rotator::getRotator(); 19507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH, 19607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const int& dstW, const int& dstH, const uint32_t& mdpFormat, 19707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const bool& isInterlaced); 19807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 19907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 20007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani/* 20107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani+* MDSS Rot holds MDSS's rotation related structures. 20207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani+* 20307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani+* */ 20407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniclass MdssRot : public Rotator { 20507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanipublic: 20607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual ~MdssRot(); 20707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setSource(const utils::Whf& wfh); 20807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setCrop(const utils::Dim& crop); 20907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setFlags(const utils::eMdpFlags& flags); 21007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setTransform(const utils::eTransform& rot); 21107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool commit(); 21207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool rotConfChanged() const; 21307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void setDownscale(int ds); 21407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getSrcMemId() const; 21507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int getDstMemId() const; 21607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSrcOffset() const; 21707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstOffset() const; 21807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getDstFormat() const; 21907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Whf getDstWhf() const; 22007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual utils::Dim getDstDimensions() const; 22107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual uint32_t getSessId() const; 22207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual bool queueBuffer(int fd, uint32_t offset); 22307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void dump() const; 22407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual void getDump(char *buf, size_t len) const; 22507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 22607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniprivate: 22707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani explicit MdssRot(); 22807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool init(); 22907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool close(); 23007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void setRotations(uint32_t r); 23107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool enabled () const; 23207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* remap rot buffers */ 23307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool remap(uint32_t numbufs); 23407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool open_i(uint32_t numbufs, uint32_t bufsz); 23507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Deferred transform calculations */ 23607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void doTransform(); 23707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* reset underlying data, basically memset 0 */ 23807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void reset(); 23907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* save mRotInfo to be last known good config*/ 24007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void save(); 24107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Calculates the rotator's o/p buffer size post the transform calcs and 24207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * knowing the o/p format depending on whether fastYuv is enabled or not */ 24307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t calcOutputBufSize(); 24407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Calculate the compressed o/p buffer size for BWC 24507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t calcCompressedBufSize(const utils::Whf& destWhf); 24607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 24707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Caller's responsibility to swap srcW, srcH if there is a 90 transform 24807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Returns actual downscale (not a log value) 24907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Constraints applied: 25007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - downscale should be a power of 2 25107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - Max downscale is 1/32 25207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - Equal downscale is applied in both directions 25307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - {srcW, srcH} mod downscale = 0 25407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * - Interlaced content is not supported 25507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani */ 25607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static int getDownscaleFactor(const int& srcW, const int& srcH, 25707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const int& dstW, const int& dstH, const uint32_t& mdpFormat, 25807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const bool& isInterlaced); 25907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 26007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static utils::Dim getFormatAdjustedCrop(const utils::Dim& crop, 26107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const uint32_t& mdpFormat, const bool& isInterlaced); 26207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 26307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static utils::Dim getDownscaleAdjustedCrop(const utils::Dim& crop, 26407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const uint32_t& downscale); 26507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 26607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* MdssRot info structure */ 26707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani mdp_overlay mRotInfo; 26807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Last saved MdssRot info structure*/ 26907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani mdp_overlay mLSRotInfo; 27007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* MdssRot data structure */ 27107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani msmfb_overlay_data mRotData; 27207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Orientation */ 27307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani utils::eTransform mOrientation; 27407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* rotator fd */ 27507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani OvFD mFd; 27607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Enable/Disable Mdss Rot*/ 27707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool mEnabled; 27807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int mDownscale; 27907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 28007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani friend Rotator* Rotator::getRotator(); 28107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani friend int Rotator::getDownscaleFactor(const int& srcW, const int& srcH, 28207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const int& dstW, const int& dstH, const uint32_t& mdpFormat, 28307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani const bool& isInterlaced); 28407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 28507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 28607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani// Holder of rotator objects. Manages lifetimes 28707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniclass RotMgr { 28807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanipublic: 28907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani //Virtually we can support as many rotator sessions as possible, However 29007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // more number of rotator sessions leads to performance issues, so 29107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // restricting the max rotator session to 4 29207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani enum { MAX_ROT_SESS = 4 }; 29307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 29407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani ~RotMgr(); 29507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void configBegin(); 29607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void configDone(); 29707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani overlay::Rotator *getNext(); 29807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void clear(); //Removes all instances 29907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani //Resets the usage of top count objects, making them available for reuse 30007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void markUnusedTop(const uint32_t& count) { mUseCount -= count; } 30107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani /* Returns rot dump. 30207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Expects a NULL terminated buffer of big enough size. 30307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani */ 30407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void getDump(char *buf, size_t len); 30507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int getRotDevFd(); 30607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int getNumActiveSessions() { return mUseCount; } 30707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 30807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static RotMgr *getInstance(); 30907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 31007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniprivate: 31107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani RotMgr(); 31207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani static RotMgr *sRotMgr; 31307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 31407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani overlay::Rotator *mRot[MAX_ROT_SESS]; 31507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uint32_t mUseCount; 31607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int mRotDevFd; 31707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 31807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 31907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 32007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani} // overlay 32107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 32207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#endif // OVERlAY_ROTATOR_H 323