OSDN Git Service

auto determine the density if not provided in surfaceflinger
authorChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 15 Jan 2013 04:55:51 +0000 (12:55 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 9 Dec 2013 14:30:02 +0000 (22:30 +0800)
We hope to support tablet UI for different resolutions.
So adjust the density according to the resolution.

services/surfaceflinger/SurfaceFlinger.cpp

index b21c464..f6a166b 100644 (file)
@@ -671,6 +671,8 @@ status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo*
     const HWComposer& hwc(getHwComposer());
     float xdpi = hwc.getDpiX(type);
     float ydpi = hwc.getDpiY(type);
+    info->w = hwc.getWidth(type);
+    info->h = hwc.getHeight(type);
 
     // TODO: Not sure if display density should handled by SF any longer
     class Density {
@@ -685,13 +687,32 @@ status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo*
     public:
         static int getEmuDensity() {
             return getDensityFromProperty("qemu.sf.lcd_density"); }
-        static int getBuildDensity()  {
-            return getDensityFromProperty("ro.sf.lcd_density"); }
+        static int getBuildDensity(DisplayInfo* info)  {
+            static int density = getDensityFromProperty("ro.sf.lcd_density");
+#if __i386__
+            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;
+        }
     };
 
     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
@@ -715,8 +736,6 @@ status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo*
         info->orientation = 0;
     }
 
-    info->w = hwc.getWidth(type);
-    info->h = hwc.getHeight(type);
     info->xdpi = xdpi;
     info->ydpi = ydpi;
     info->fps = float(1e9 / hwc.getRefreshPeriod(type));