From 1c569c4d45f89ec05abf8f8fe3a560e68bf39a8e Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Fri, 5 Apr 2013 13:44:52 -0700 Subject: [PATCH] Tell HWComposer the dimensions of virtual displays HWComposer queries the HWC for dimensions of physical displays, but can't do that for virtual displays. The dimensions are used to set the display frame of the framebuffer target layer passed to HWC, and implicitly the dimensions of the virtual display. Bug: 8316155 Change-Id: I9cbd2530d2fa878f86128a1472def520b5d694a5 --- .../DisplayHardware/HWComposer.cpp | 36 ++++++++++++------- .../DisplayHardware/HWComposer.h | 3 ++ services/surfaceflinger/SurfaceFlinger.cpp | 9 ++++- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index a29c06844..3f00f073f 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -38,6 +38,8 @@ #include #include +#include + #include #include @@ -297,6 +299,11 @@ void HWComposer::hotplug(int disp, int connected) { mEventHandler.onHotplugReceived(disp, bool(connected)); } +static float getDefaultDensity(uint32_t height) { + if (height >= 1080) return ACONFIGURATION_DENSITY_XHIGH; + else return ACONFIGURATION_DENSITY_TV; +} + static const uint32_t DISPLAY_ATTRIBUTES[] = { HWC_DISPLAY_VSYNC_PERIOD, HWC_DISPLAY_WIDTH, @@ -307,10 +314,6 @@ static const uint32_t DISPLAY_ATTRIBUTES[] = { }; #define NUM_DISPLAY_ATTRIBUTES (sizeof(DISPLAY_ATTRIBUTES) / sizeof(DISPLAY_ATTRIBUTES)[0]) -// http://developer.android.com/reference/android/util/DisplayMetrics.html -#define ANDROID_DENSITY_TV 213 -#define ANDROID_DENSITY_XHIGH 320 - status_t HWComposer::queryDisplayProperties(int disp) { LOG_ALWAYS_FATAL_IF(!mHwc || !hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)); @@ -364,18 +367,26 @@ status_t HWComposer::queryDisplayProperties(int disp) { mDisplayData[disp].format = HAL_PIXEL_FORMAT_RGBA_8888; mDisplayData[disp].connected = true; if (mDisplayData[disp].xdpi == 0.0f || mDisplayData[disp].ydpi == 0.0f) { - // is there anything smarter we can do? - if (h >= 1080) { - mDisplayData[disp].xdpi = ANDROID_DENSITY_XHIGH; - mDisplayData[disp].ydpi = ANDROID_DENSITY_XHIGH; - } else { - mDisplayData[disp].xdpi = ANDROID_DENSITY_TV; - mDisplayData[disp].ydpi = ANDROID_DENSITY_TV; - } + float dpi = getDefaultDensity(h); + mDisplayData[disp].xdpi = dpi; + mDisplayData[disp].ydpi = dpi; } return NO_ERROR; } +status_t HWComposer::setVirtualDisplayProperties(int32_t id, + uint32_t w, uint32_t h, uint32_t format) { + if (id < VIRTUAL_DISPLAY_ID_BASE || id >= int32_t(mNumDisplays) || + !mAllocatedDisplayIDs.hasBit(id)) { + return BAD_INDEX; + } + mDisplayData[id].width = w; + mDisplayData[id].height = h; + mDisplayData[id].format = format; + mDisplayData[id].xdpi = mDisplayData[id].ydpi = getDefaultDensity(h); + return NO_ERROR; +} + int32_t HWComposer::allocateDisplayId() { if (mAllocatedDisplayIDs.count() >= mNumDisplays) { return NO_MEMORY; @@ -416,7 +427,6 @@ sp HWComposer::getDisplayFence(int disp) const { return mDisplayData[disp].lastDisplayFence; } - uint32_t HWComposer::getWidth(int disp) const { return mDisplayData[disp].width; } diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 58f7e8fff..604de385c 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -253,6 +253,9 @@ public: float getDpiY(int disp) const; bool isConnected(int disp) const; + status_t setVirtualDisplayProperties(int32_t id, uint32_t w, uint32_t h, + uint32_t format); + // this class is only used to fake the VSync event on systems that don't // have it. class VSyncThread : public Thread { diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 9102f5c1f..a4426cde1 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1187,8 +1187,15 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) state.viewport, state.frame); hw->setDisplayName(state.displayName); mDisplays.add(display, hw); - if (state.type < DisplayDevice::NUM_DISPLAY_TYPES) + if (state.isVirtualDisplay()) { + if (hwcDisplayId >= 0) { + mHwc->setVirtualDisplayProperties(hwcDisplayId, + hw->getWidth(), hw->getHeight(), + hw->getFormat()); + } + } else { mEventThread->onHotplugReceived(state.type, true); + } } } }