 Chromium Code Reviews
 Chromium Code Reviews Issue 27156003:
  linux_aura: Enable HIDPI support  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 27156003:
  linux_aura: Enable HIDPI support  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: ui/views/widget/desktop_aura/desktop_screen_x11.cc | 
| diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/ui/views/widget/desktop_aura/desktop_screen_x11.cc | 
| index 9358875895ac0bd2f1aadb30c27df4f1fd018773..8bf3e9f85f767829831a54db100cc7dab3be7997 100644 | 
| --- a/ui/views/widget/desktop_aura/desktop_screen_x11.cc | 
| +++ b/ui/views/widget/desktop_aura/desktop_screen_x11.cc | 
| @@ -14,6 +14,7 @@ | 
| #include "base/x11/edid_parser_x11.h" | 
| #include "ui/aura/root_window.h" | 
| #include "ui/aura/root_window_host.h" | 
| +#include "ui/base/layout.h" | 
| #include "ui/base/x/x11_util.h" | 
| #include "ui/gfx/display.h" | 
| #include "ui/gfx/display_observer.h" | 
| @@ -29,14 +30,65 @@ namespace { | 
| // in |Dispatch()|. | 
| const int64 kConfigureDelayMs = 500; | 
| +float g_device_scale_factor = 1.0f; | 
| + | 
| +// A list of bogus sizes in mm that X detects that should be ignored. | 
| +// See crbug.com/136533. The first element maintains the minimum | 
| +// size required to be valid size. | 
| +// (Taken from ash/display/display_change_observer_chromeos.cc) | 
| +const unsigned long kInvalidDisplaySizeList[][2] = { | 
| + {40, 30}, | 
| + {50, 40}, | 
| + {160, 90}, | 
| + {160, 100}, | 
| +}; | 
| + | 
| +bool ShouldIgnoreScreen(unsigned long mm_width, unsigned long mm_height) { | 
| 
oshima
2013/10/23 18:10:59
I thought I left the comment, but apparently not,
 | 
| + // Ignore if the reported display is smaller than minimum size. | 
| + if (mm_width <= kInvalidDisplaySizeList[0][0] || | 
| + mm_height <= kInvalidDisplaySizeList[0][1]) { | 
| + LOG(WARNING) << "Smaller than minimum display size"; | 
| + return true; | 
| + } | 
| + for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) { | 
| + const unsigned long* size = kInvalidDisplaySizeList[i]; | 
| + if (mm_width == size[0] && mm_height == size[1]) { | 
| + LOG(WARNING) << "Black listed display size detected:" | 
| + << size[0] << "x" << size[1]; | 
| + return true; | 
| + } | 
| + } | 
| + return false; | 
| +} | 
| + | 
| +float GetDeviceScaleFactor(int screen_dim, int mm_screen_dim) { | 
| + const int kCSSDefaultDIPCountPerInch = 96; | 
| + const float kInchInMm = 25.4f; | 
| + | 
| + float screen_DPI = (screen_dim * kInchInMm) / mm_screen_dim; | 
| + float scale = screen_DPI / kCSSDefaultDIPCountPerInch; | 
| + | 
| + return ui::GetImageScale(ui::GetSupportedScaleFactor(scale)); | 
| +} | 
| + | 
| std::vector<gfx::Display> GetFallbackDisplayList() { | 
| ::XDisplay* display = gfx::GetXDisplay(); | 
| ::Screen* screen = DefaultScreenOfDisplay(display); | 
| int width = WidthOfScreen(screen); | 
| int height = HeightOfScreen(screen); | 
| + int mm_width = WidthMMOfScreen(screen); | 
| + int mm_height = HeightMMOfScreen(screen); | 
| + | 
| + gfx::Rect bounds_in_pixels(0, 0, width, height); | 
| + gfx::Display gfx_display(0, bounds_in_pixels); | 
| + if (!gfx::Display::HasForceDeviceScaleFactor() | 
| + && !ShouldIgnoreScreen(mm_width, mm_height)) { | 
| 
Elliot Glaysher
2013/10/23 17:51:19
&& on previous line.
 | 
| + g_device_scale_factor = GetDeviceScaleFactor(width, mm_width); | 
| + DCHECK_LE(1.0f, g_device_scale_factor); | 
| + gfx_display.SetScaleAndBounds(g_device_scale_factor, bounds_in_pixels); | 
| + } | 
| - return std::vector<gfx::Display>( | 
| - 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); | 
| + return std::vector<gfx::Display>(1, gfx_display); | 
| } | 
| } // namespace | 
| @@ -128,7 +180,7 @@ void DesktopScreenX11::ProcessDisplayChange( | 
| // DesktopScreenX11, gfx::Screen implementation: | 
| bool DesktopScreenX11::IsDIPEnabled() { | 
| - return false; | 
| + return true; | 
| } | 
| gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 
| @@ -317,6 +369,19 @@ std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { | 
| gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 
| gfx::Display display(display_id, crtc_bounds); | 
| + | 
| + if (!gfx::Display::HasForceDeviceScaleFactor()) { | 
| + if (i == 0 && !ShouldIgnoreScreen(output_info->mm_width, | 
| + output_info->mm_height)) { | 
| + // As per display scale factor is not supported right now, | 
| + // the primary display's scale factor is always used. | 
| + g_device_scale_factor = GetDeviceScaleFactor(crtc->width, | 
| + output_info->mm_width); | 
| + } | 
| + DCHECK_LE(1.0f, g_device_scale_factor); | 
| + display.SetScaleAndBounds(g_device_scale_factor, crtc_bounds); | 
| + } | 
| + | 
| if (has_work_area) { | 
| gfx::Rect intersection = crtc_bounds; | 
| intersection.Intersect(work_area); |