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..e6ca408f38c7ce8d18de02088e4ef75b565dae00 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,74 @@ 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) { |
+ // 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; |
+} |
+ |
+inline void InitDeviceScaleFactor(float scale) { |
+ DCHECK_NE(0.0f, scale); |
oshima
2013/10/22 05:35:10
scale must be larger than 1.0f
DCHECK_LE(1.0f, sc
Mikhail
2013/10/23 17:15:02
I've done it just to enforce DCHECK, but we surely
|
+ g_device_scale_factor = scale; |
+} |
+ |
+void InitDeviceScaleFactorFromScreenDim(int screen_dim, int mm_screen_dim) { |
oshima
2013/10/22 05:35:10
....ScreenDimension
|
+ const int kCSSDefaultDIPCountPerInch = 96; |
+ const float kInchInMm = 25.4f; |
+ |
+ float screen_DPI = (screen_dim * kInchInMm) / mm_screen_dim; |
+ float scale = screen_DPI / kCSSDefaultDIPCountPerInch; |
+ |
+ InitDeviceScaleFactor(ui::GetImageScale(ui::GetSupportedScaleFactor(scale))); |
+} |
+ |
+inline float GetDeviceScaleFactor() { |
+ DCHECK_NE(0.0f, g_device_scale_factor); |
oshima
2013/10/22 05:35:10
ditto. nuke "inline"
|
+ return g_device_scale_factor; |
+} |
+ |
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)) { |
+ InitDeviceScaleFactorFromScreenDim(width, mm_width); |
+ gfx_display.SetScaleAndBounds(GetDeviceScaleFactor(), 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 +189,7 @@ void DesktopScreenX11::ProcessDisplayChange( |
// DesktopScreenX11, gfx::Screen implementation: |
bool DesktopScreenX11::IsDIPEnabled() { |
- return false; |
+ return true; |
} |
gfx::Point DesktopScreenX11::GetCursorScreenPoint() { |
@@ -317,6 +378,18 @@ 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) // Primary display. |
+ && !ShouldIgnoreScreen(output_info->mm_width, output_info->mm_height)) { |
oshima
2013/10/22 05:35:10
if (i == 0 &&
!....
|
+ // As Aura does not support per display scale factor right now, |
oshima
2013/10/22 05:35:10
desktop aura does not support ...
I believe this
|
+ // the primary display's scale factor is always used. |
+ InitDeviceScaleFactorFromScreenDim(crtc->width, output_info->mm_width); |
oshima
2013/10/22 05:35:10
indent
You may just want to pass crtc/output_info
Mikhail
2013/10/23 17:15:02
This function is also used from GetFallbackDisplay
|
+ } |
+ |
+ display.SetScaleAndBounds(GetDeviceScaleFactor(), crtc_bounds); |
+ } |
+ |
if (has_work_area) { |
gfx::Rect intersection = crtc_bounds; |
intersection.Intersect(work_area); |