libvirtual: Cleanup patch for DRC feature

Separated the logic for setting virtual display attributes into 3
functions that:
1. Initialize the virtual res. on an ONLINE event
2. Set virtual res. to match primary res (MDP downscale path)
3. Set MDP downscale mode for either DRC or MDP downscale path

Change-Id: Icbf2a6b6301809fee48272ac8a87c732dd2d6634
This commit is contained in:
Tatenda Chipeperekwa 2013-09-18 10:54:20 -07:00
parent f74ebf4eca
commit 45a3f19532
2 changed files with 79 additions and 34 deletions

View File

@ -55,6 +55,9 @@ namespace qhwc {
#define MAX_SYSFS_FILE_PATH 255
/* Max. resolution assignable to virtual display. */
#define SUPPORTED_VIRTUAL_AREA (1920*1080)
int VirtualDisplay::configure() {
if(!openFrameBuffer())
return -1;
@ -94,47 +97,85 @@ VirtualDisplay::~VirtualDisplay()
closeFrameBuffer();
}
/* Initializes the resolution attributes of the virtual display
that are reported to SurfaceFlinger.
Cases:
1. ONLINE event - initialize to frame buffer resolution
2. RESUME event - retain original resolution
*/
void VirtualDisplay::initResolution(uint32_t &extW, uint32_t &extH) {
// On ONLINE event, display resolution attributes are 0.
if(extW == 0 || extH == 0){
extW = mVInfo.xres;
extH = mVInfo.yres;
}
}
/* Sets the virtual resolution to match that of the primary
display in the event that the virtual display currently
connected has a lower resolution. NB: we always report the
highest available resolution to SurfaceFlinger.
*/
void VirtualDisplay::setToPrimary(uint32_t maxArea,
uint32_t priW,
uint32_t priH,
uint32_t &extW,
uint32_t &extH) {
// for eg., primary in 1600p and WFD in 1080p
// we wont use downscale feature because MAX MDP
// writeback resolution supported is 1080p (tracked
// by SUPPORTED_VIRTUAL_AREA).
if((maxArea == (priW * priH))
&& (maxArea <= SUPPORTED_VIRTUAL_AREA)) {
extW = priW;
extH = priH;
// If WFD is in landscape, assign the higher dimension
// to WFD's xres.
if(priH > priW) {
extW = priH;
extH = priW;
}
}
}
/* Set External Display MDP Downscale mode indicator. Only set to
TRUE for the following scenarios:
1. Valid DRC scenarios i.e. when the original WFD resolution
is greater than the new/requested resolution in mVInfo.
2. WFD down scale path i.e. when WFD resolution is lower than
primary resolution.
Furthermore, downscale mode is only valid when downscaling from
SUPPORTED_VIRTUAL_AREA to a lower resolution.
(SUPPORTED_VIRTUAL_AREA represents the maximum resolution that
we can configure to the virtual display)
*/
void VirtualDisplay::setDownScaleMode(uint32_t maxArea) {
if((maxArea > (mVInfo.xres * mVInfo.yres))
&& (maxArea <= SUPPORTED_VIRTUAL_AREA)) {
mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = true;
}else {
mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false;
}
}
void VirtualDisplay::setAttributes() {
if(mHwcContext) {
unsigned int &w = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres;
unsigned int &h = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres;
uint32_t &extW = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres;
uint32_t &extH = mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres;
uint32_t priW = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
uint32_t priH = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
// Always set dpyAttr res to mVInfo res, only on an ONLINE event. Keep
// the original configuration to cater for DRC initiated RESUME events
if(w == 0 || h == 0){
w = mVInfo.xres;
h = mVInfo.yres;
}
mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false;
initResolution(extW, extH);
if(!qdutils::MDPVersion::getInstance().is8x26()) {
uint32_t priW = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
uint32_t priH = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
// Find the maximum resolution between primary and virtual
uint32_t maxArea = max((w * h), (priW * priH));
// maxArea represents the maximum resolution between
// primary and virtual display.
uint32_t maxArea = max((extW * extH), (priW * priH));
// If primary resolution is more than the wfd resolution
// configure dpy attr to primary resolution and set
// downscale mode.
// DRC is only valid when the original resolution on the WiFi
// display is greater than the new resolution in mVInfo.
if(maxArea > (mVInfo.xres * mVInfo.yres)) {
if(maxArea == (priW * priH)) {
// Here we account for the case when primary resolution is
// greater than that of the WiFi display
w = priW;
h = priH;
// WFD is always in landscape, so always assign the higher
// dimension to wfd's xres
if(priH > priW) {
w = priH;
h = priW;
}
}
// Set External Display MDP Downscale mode indicator
mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = true;
}
setToPrimary(maxArea, priW, priH, extW, extH);
setDownScaleMode(maxArea);
}
mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].vsync_period =
1000000000l /60;

View File

@ -52,6 +52,10 @@ private:
bool openFrameBuffer();
bool closeFrameBuffer();
void setAttributes();
void initResolution(uint32_t &extW, uint32_t &extH);
void setToPrimary(uint32_t maxArea, uint32_t priW, uint32_t priH,
uint32_t &extW, uint32_t &extH);
void setDownScaleMode(uint32_t maxArea);
int mFd;
hwc_context_t *mHwcContext;