OSDN Git Service

Determine the density according to DisplayDevice (q-x86) q-x86
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 4 Jun 2020 15:59:30 +0000 (23:59 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sun, 26 Dec 2021 07:20:01 +0000 (15:20 +0800)
Previously we use hwConfig to get the dimension of the display.
However, there may be several hwConfig modes of a display. Only
the first mode is used to calculate the density. But first mode
may not be the default mode. Hence the calculated density may not
be suitable to the default mode.

Now use the dimension of the DisplayDevice to calculate the density.

(q-x86) Changelog:
        Adapt code for change from 'static int density' to 'static float density'
        Remove duplicated info.{w,h} assignements
        Keep info.{w,h} and info.viewport{W,H} assignements as they are
        Move up 'const auto display = getDefaultDisplayDeviceLocked();'
        Use 'display' variable instead of 'hw' in SurfaceFlinger::getDisplayConfigs

services/surfaceflinger/SurfaceFlinger.cpp

index f2e9c6e..76ebd24 100644 (file)
@@ -845,11 +845,11 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken,
     public:
         static float getEmuDensity() {
             return getDensityFromProperty("qemu.sf.lcd_density"); }
-        static float getBuildDensity(const DisplayInfo& info)  {
+        static float getBuildDensity(const sp<const DisplayDevice>& hw) {
             static float density = getDensityFromProperty("ro.sf.lcd_density");
 #if defined(__i386__) || defined(__x86_64__)
-            if (density == 0.0f) {
-                uint32_t area = info.w * info.h;
+            if (density == 0.0f && hw) {
+                uint32_t area = hw->getWidth() * hw->getHeight();
                 if (area <= 800 * 480) {
                     density = 120.0f;
                 } else if (area <= 1024 * 600) {
@@ -863,7 +863,7 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken,
                 } else {
                     density = 320.0f;
                 }
-                ALOGI("auto set density to %f", density);
+                ALOGI("auto set density to %f for primary display %d x %d", density, hw->getWidth(), hw->getHeight());
             }
 #endif
             return density;
@@ -879,16 +879,14 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken,
         float ydpi = hwConfig->getDpiY();
         info.w = hwConfig->getWidth();
         info.h = hwConfig->getHeight();
-
-        info.w = hwConfig->getWidth();
-        info.h = hwConfig->getHeight();
         // Default display viewport to display width and height
         info.viewportW = info.w;
         info.viewportH = info.h;
 
         if (displayId == getInternalDisplayIdLocked()) {
+            const auto display = getDefaultDisplayDeviceLocked();
             // The density of the device is provided by a build property
-            float density = Density::getBuildDensity(info) / 160.0f;
+            float density = Density::getBuildDensity(display) / 160.0f;
             if (density == 0) {
                 // the build doesn't provide a density -- this is wrong!
                 // use xdpi instead
@@ -903,7 +901,6 @@ status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken,
             info.density = density;
 
             // TODO: this needs to go away (currently needed only by webkit)
-            const auto display = getDefaultDisplayDeviceLocked();
             info.orientation = display ? display->getOrientation() : 0;
 
             // This is for screenrecord