Commit 840bfccd authored by oshima@chromium.org's avatar oshima@chromium.org

Use 1.25 DSF for 150~180 DPI

BUG=372212

Review URL: https://codereview.chromium.org/411763004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285115 0039d316-1c4b-4281-b951-d872f2087c98
parent 71618ed3
......@@ -30,9 +30,18 @@ using ui::DisplayConfigurator;
namespace {
// The DPI threshold to detect high density screen.
// Higher DPI than this will use device_scale_factor=2.
const unsigned int kHighDensityDPIThreshold = 170;
// The DPI threshold to determine the device scale factor.
// DPI higher than |dpi| will use |device_scale_factor|.
struct DeviceScaleFactorDPIThreshold {
float dpi;
float device_scale_factor;
};
const DeviceScaleFactorDPIThreshold kThresholdTable[] = {
{180.0f, 2.0f},
{150.0f, 1.25f},
{0.0f, 1.0f},
};
// 1 inch in mm.
const float kInchInMm = 25.4f;
......@@ -134,10 +143,10 @@ void DisplayChangeObserver::OnDisplayModeChanged(
continue;
float device_scale_factor = 1.0f;
if (!ui::IsDisplaySizeBlackListed(state.display->physical_size()) &&
(kInchInMm * mode_info->size().width() /
state.display->physical_size().width()) > kHighDensityDPIThreshold) {
device_scale_factor = 2.0f;
if (!ui::IsDisplaySizeBlackListed(state.display->physical_size())) {
device_scale_factor =
FindDeviceScaleFactor((kInchInMm * mode_info->size().width() /
state.display->physical_size().width()));
}
gfx::Rect display_bounds(state.display->origin(), mode_info->size());
......@@ -184,4 +193,13 @@ void DisplayChangeObserver::OnAppTerminating() {
#endif
}
// static
float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) {
for (size_t i = 0; i < arraysize(kThresholdTable); ++i) {
if (dpi > kThresholdTable[i].dpi)
return kThresholdTable[i].device_scale_factor;
}
return 1.0f;
}
} // namespace ash
......@@ -40,6 +40,9 @@ class DisplayChangeObserver : public ui::DisplayConfigurator::StateController,
// Overriden from ShellObserver:
virtual void OnAppTerminating() OVERRIDE;
// Exposed for testing.
ASH_EXPORT static float FindDeviceScaleFactor(float dpi);
private:
DISALLOW_COPY_AND_ASSIGN(DisplayChangeObserver);
};
......
......@@ -82,4 +82,29 @@ TEST_F(DisplayChangeObserverTest, GetDisplayModeList) {
EXPECT_EQ(0u, display_modes.size());
}
TEST_F(DisplayChangeObserverTest, FindDeviceScaleFactor) {
// 19.5" 1600x900
EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(94.14f));
// 21.5" 1920x1080
EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(102.46f));
// 12.1" 1280x800
EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(124.75f));
// 13.3" 1920x1080
EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(157.35f));
// 14" 1920x1080
EXPECT_EQ(1.25f, DisplayChangeObserver::FindDeviceScaleFactor(165.63f));
// 12.85" 2560x1700
EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(239.15f));
// Erroneous values should still work.
EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(-100.0f));
EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(0.0f));
EXPECT_EQ(2.0f, DisplayChangeObserver::FindDeviceScaleFactor(10000.0f));
}
} // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment