From: Chih-Wei Huang Date: Sun, 26 Oct 2014 07:39:53 +0000 (+0800) Subject: auto determine the density if not provided in surfaceflinger X-Git-Tag: android-x86-8.1-r1~18 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e627cbe61de0ceba33ef1bec07459f2b65e9ff92;p=android-x86%2Fframeworks-native.git auto determine the density if not provided in surfaceflinger We hope to support tablet UI for different resolutions. So adjust the density according to the resolution. --- diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 45bf686ef3..d1630dcf56 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -751,8 +751,27 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, public: static int getEmuDensity() { return getDensityFromProperty("qemu.sf.lcd_density"); } - static int getBuildDensity() { - return getDensityFromProperty("ro.sf.lcd_density"); } + static int getBuildDensity(const DisplayInfo& info) { + static int density = getDensityFromProperty("ro.sf.lcd_density"); +#if defined(__i386__) || defined(__x86_64__) + if (density == 0) { + uint32_t area = info.w * info.h; + if (area <= 800 * 480) { + density = 120; + } else if (area <= 1024 * 600) { + density = 130; + } else if (area < 1024 * 768) { + density = 140; + } else if (area < 1920 * 1080) { + density = 160; + } else { + density = 240; + } + ALOGI("auto set density to %d", density); + } +#endif + return density; + } }; configs->clear(); @@ -764,10 +783,12 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, float xdpi = hwConfig->getDpiX(); float ydpi = hwConfig->getDpiY(); + info.w = hwConfig->getWidth(); + info.h = hwConfig->getHeight(); if (type == DisplayDevice::DISPLAY_PRIMARY) { // The density of the device is provided by a build property - float density = Density::getBuildDensity() / 160.0f; + float density = Density::getBuildDensity(info) / 160.0f; if (density == 0) { // the build doesn't provide a density -- this is wrong! // use xdpi instead @@ -791,8 +812,6 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, info.orientation = 0; } - info.w = hwConfig->getWidth(); - info.h = hwConfig->getHeight(); info.xdpi = xdpi; info.ydpi = ydpi; info.fps = 1e9 / hwConfig->getVsyncPeriod(); diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp index 169d2cb105..455b020ce8 100644 --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp @@ -682,8 +682,27 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, public: static int getEmuDensity() { return getDensityFromProperty("qemu.sf.lcd_density"); } - static int getBuildDensity() { - return getDensityFromProperty("ro.sf.lcd_density"); } + static int getBuildDensity(const DisplayInfo& info) { + static int density = getDensityFromProperty("ro.sf.lcd_density"); +#if defined(__i386__) || defined(__x86_64__) + if (density == 0) { + uint32_t area = info.w * info.h; + if (area <= 800 * 480) { + density = 120; + } else if (area <= 1024 * 600) { + density = 130; + } else if (area < 1024 * 768) { + density = 140; + } else if (area < 1920 * 1080) { + density = 160; + } else { + density = 240; + } + ALOGI("auto set density to %d", density); + } +#endif + return density; + } }; configs->clear(); @@ -696,10 +715,12 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, float xdpi = hwConfig.xdpi; float ydpi = hwConfig.ydpi; + info.w = hwConfig.width; + info.h = hwConfig.height; if (type == DisplayDevice::DISPLAY_PRIMARY) { // The density of the device is provided by a build property - float density = Density::getBuildDensity() / 160.0f; + float density = Density::getBuildDensity(info) / 160.0f; if (density == 0) { // the build doesn't provide a density -- this is wrong! // use xdpi instead @@ -723,8 +744,6 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp& display, info.orientation = 0; } - info.w = hwConfig.width; - info.h = hwConfig.height; info.xdpi = xdpi; info.ydpi = ydpi; info.fps = float(1e9 / hwConfig.refresh);