diff options
-rw-r--r-- | ash/ash.gyp | 5 | ||||
-rw-r--r-- | ash/display/display_change_observer_x11.cc | 40 | ||||
-rw-r--r-- | ash/display/display_change_observer_x11.h | 7 | ||||
-rw-r--r-- | ash/display/display_change_observer_x11_unittest.cc | 31 |
4 files changed, 63 insertions, 20 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index b63f9d9f..9fa4d22 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -797,6 +797,11 @@ # are not referenced in code, but are referenced in nibs. 'xcode_settings': {'OTHER_LDFLAGS': ['-Wl,-ObjC']}, }], + ['use_x11==1', { + 'sources': [ + 'display/display_change_observer_x11_unittest.cc' + ], + }], ['chromeos!=1', { 'sources/': [ ['exclude', 'display/display_error_observer_unittest.cc'], diff --git a/ash/display/display_change_observer_x11.cc b/ash/display/display_change_observer_x11.cc index 08c1afe..6e9563f 100644 --- a/ash/display/display_change_observer_x11.cc +++ b/ash/display/display_change_observer_x11.cc @@ -54,22 +54,31 @@ XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { // A list of bogus sizes in mm that X detects and should be ignored. // See crbug.com/136533. const unsigned long kInvalidDisplaySizeList[][2] = { - {160, 100}, - {160, 90}, - {50, 40}, {40, 30}, + {50, 40}, + {160, 90}, + {160, 100}, }; -// Returns true if the size nifo in the output_info isn't valid -// and should be ignored. -bool ShouldIgnoreSize(XRROutputInfo *output_info) { - if (output_info->mm_width == 0 || output_info->mm_height == 0) { - LOG(WARNING) << "No display size available"; +int64 GetDisplayId(XID output, size_t output_index) { + int64 display_id; + if (chromeos::GetDisplayId(output, output_index, &display_id)) + return display_id; + return gfx::Display::kInvalidDisplayID; +} + +} // namespace + +bool ShouldIgnoreSize(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 = 0 ; i < arraysize(kInvalidDisplaySizeList); ++i) { + for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) { const unsigned long* size = kInvalidDisplaySizeList[i]; - if (output_info->mm_width == size[0] && output_info->mm_height == size[1]) { + if (mm_width == size[0] && mm_height == size[1]) { LOG(WARNING) << "Black listed display size detected:" << size[0] << "x" << size[1]; return true; @@ -78,15 +87,6 @@ bool ShouldIgnoreSize(XRROutputInfo *output_info) { return false; } -int64 GetDisplayId(XID output, size_t output_index) { - int64 display_id; - if (chromeos::GetDisplayId(output, output_index, &display_id)) - return display_id; - return gfx::Display::kInvalidDisplayID; -} - -} // namespace - DisplayChangeObserverX11::DisplayChangeObserverX11() : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), x_root_window_(DefaultRootWindow(xdisplay_)), @@ -173,7 +173,7 @@ void DisplayChangeObserverX11::OnDisplayModeChanged() { } float device_scale_factor = 1.0f; - if (!ShouldIgnoreSize(output_info) && + if (!ShouldIgnoreSize(output_info->mm_width, output_info->mm_height) && (kInchInMm * mode->width / output_info->mm_width) > kHighDensityDPIThreshold) { device_scale_factor = 2.0f; diff --git a/ash/display/display_change_observer_x11.h b/ash/display/display_change_observer_x11.h index 4e63180..3d13e0d 100644 --- a/ash/display/display_change_observer_x11.h +++ b/ash/display/display_change_observer_x11.h @@ -10,6 +10,7 @@ // Xlib.h defines RootWindow. #undef RootWindow +#include "ash/ash_export.h" #include "ash/shell_observer.h" #include "base/basictypes.h" #include "chromeos/display/output_configurator.h" @@ -47,6 +48,12 @@ class DisplayChangeObserverX11 DISALLOW_COPY_AND_ASSIGN(DisplayChangeObserverX11); }; +// Returns true if the size info in the output_info isn't valid +// and should be ignored. This is exposed for testing. +// |mm_width| and |mm_height| are given in millimeters. +ASH_EXPORT bool ShouldIgnoreSize(unsigned long mm_width, + unsigned long mm_height); + } // namespace internal } // namespace ash diff --git a/ash/display/display_change_observer_x11_unittest.cc b/ash/display/display_change_observer_x11_unittest.cc new file mode 100644 index 0000000..8f81297 --- /dev/null +++ b/ash/display/display_change_observer_x11_unittest.cc @@ -0,0 +1,31 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/display/display_change_observer_x11.h" + +// Undefine X's macros used in gtest. +#undef Bool +#undef None + +#include "testing/gtest/include/gtest/gtest.h" + +typedef testing::Test DisplayChangeObserverX11Test; + +namespace ash { +namespace internal { + +TEST_F(DisplayChangeObserverX11Test, TestBlackListedDisplay) { + EXPECT_TRUE(ShouldIgnoreSize(10, 10)); + EXPECT_TRUE(ShouldIgnoreSize(40, 30)); + EXPECT_TRUE(ShouldIgnoreSize(50, 40)); + EXPECT_TRUE(ShouldIgnoreSize(160, 90)); + EXPECT_TRUE(ShouldIgnoreSize(160, 100)); + + EXPECT_FALSE(ShouldIgnoreSize(50, 60)); + EXPECT_FALSE(ShouldIgnoreSize(100, 70)); + EXPECT_FALSE(ShouldIgnoreSize(272, 181)); +} + +} // namespace internal +} // namespace ash |