Skip to content

Commit

Permalink
Allow 1.0f scale factor on pixel
Browse files Browse the repository at this point in the history
BUG=246274
TEST=covered by test

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236112 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Nov 20, 2013
1 parent f57d7f7 commit ccb962d
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 158 deletions.
8 changes: 4 additions & 4 deletions ash/desktop_background/desktop_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class LayerControlView : public views::View {
GetWidget()->GetNativeView());
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
DisplayInfo info = display_manager->GetDisplayInfo(display.id());

float ui_scale = info.GetEffectiveUIScale();
gfx::SizeF pixel_size = display.size();
pixel_size.Scale(1.0f / info.ui_scale());
pixel_size.Scale(1.0f / ui_scale);
gfx::Size rounded_size = gfx::ToCeiledSize(pixel_size);
DCHECK_EQ(1, child_count());
views::View* child = child_at(0);
child->SetBounds(0, 0, rounded_size.width(), rounded_size.height());
gfx::Transform transform;
transform.Scale(info.ui_scale(), info.ui_scale());
transform.Scale(ui_scale, ui_scale);
child->SetTransform(transform);
}

Expand Down Expand Up @@ -103,7 +103,7 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {

DisplayManager* display_manager = Shell::GetInstance()->display_manager();
DisplayInfo display_info = display_manager->GetDisplayInfo(display.id());
float scaling = display_info.ui_scale();
float scaling = display_info.GetEffectiveUIScale();
if (scaling <= 1.0f)
scaling = 1.0f;
// Allow scaling up to the UI scaling.
Expand Down
3 changes: 2 additions & 1 deletion ash/display/display_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ gfx::Display::Rotation GetStoredRotation(int64 id) {
}

float GetStoredUIScale(int64 id) {
return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale();
return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).
GetEffectiveUIScale();
}

#if defined(USE_X11)
Expand Down
18 changes: 12 additions & 6 deletions ash/display/display_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
display_info.set_device_scale_factor(device_scale_factor);
display_info.set_rotation(rotation);
display_info.set_ui_scale(ui_scale);
display_info.set_configured_ui_scale(ui_scale);
display_info.SetBounds(bounds_in_native);
display_info.set_resolutions(resolutions);

Expand All @@ -140,7 +140,7 @@ DisplayInfo::DisplayInfo()
touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN),
device_scale_factor_(1.0f),
overscan_insets_in_dip_(0, 0, 0, 0),
ui_scale_(1.0f),
configured_ui_scale_(1.0f),
native_(false) {
}

Expand All @@ -154,7 +154,7 @@ DisplayInfo::DisplayInfo(int64 id,
touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN),
device_scale_factor_(1.0f),
overscan_insets_in_dip_(0, 0, 0, 0),
ui_scale_(1.0f),
configured_ui_scale_(1.0f),
native_(false) {
}

Expand Down Expand Up @@ -185,7 +185,7 @@ void DisplayInfo::Copy(const DisplayInfo& native_info) {
// DisplayChangeObserver.
if (!native_info.native()) {
rotation_ = native_info.rotation_;
ui_scale_ = native_info.ui_scale_;
configured_ui_scale_ = native_info.configured_ui_scale_;
}
// Don't copy insets as it may be given by preference. |rotation_|
// is treated as a native so that it can be specified in
Expand All @@ -198,6 +198,12 @@ void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) {
UpdateDisplaySize();
}

float DisplayInfo::GetEffectiveUIScale() const {
if (device_scale_factor_ == 2.0f && configured_ui_scale_ == 2.0f)
return 1.0f;
return configured_ui_scale_;
}

void DisplayInfo::UpdateDisplaySize() {
size_in_pixel_ = bounds_in_native_.size();
if (!overscan_insets_in_dip_.empty()) {
Expand All @@ -212,7 +218,7 @@ void DisplayInfo::UpdateDisplaySize() {
rotation_ == gfx::Display::ROTATE_270)
size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
gfx::SizeF size_f(size_in_pixel_);
size_f.Scale(ui_scale_);
size_f.Scale(GetEffectiveUIScale());
size_in_pixel_ = gfx::ToFlooredSize(size_f);
}

Expand All @@ -235,7 +241,7 @@ std::string DisplayInfo::ToString() const {
device_scale_factor_,
overscan_insets_in_dip_.ToString().c_str(),
rotation_degree,
ui_scale_,
configured_ui_scale_,
touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE ? "yes" :
touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE ? "no" :
"unknown");
Expand Down
28 changes: 18 additions & 10 deletions ash/display/display_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <vector>

#include "ash/ash_export.h"
#include "base/gtest_prod_util.h"
#include "ui/gfx/display.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/rect.h"
Expand Down Expand Up @@ -98,8 +97,9 @@ class ASH_EXPORT DisplayInfo {
float device_scale_factor() const { return device_scale_factor_; }
void set_device_scale_factor(float scale) { device_scale_factor_ = scale; }

// The native bounds for the display. The size of this can be different from
// the |size_in_pixel| when overscan insets are set and/or |ui_scale_| is set.
// The native bounds for the display. The size of this can be
// different from the |size_in_pixel| when overscan insets are set
// and/or |configured_ui_scale_| is set.
const gfx::Rect bounds_in_native() const {
return bounds_in_native_;
}
Expand All @@ -112,12 +112,19 @@ class ASH_EXPORT DisplayInfo {
return overscan_insets_in_dip_;
}

float ui_scale() const { return ui_scale_; }
void set_ui_scale(float scale) { ui_scale_ = scale; }
// Sets/gets configured ui scale. This can be different from the ui
// scale actually used when the scale is 2.0 and DSF is 2.0.
// (the effective ui scale is 1.0 in this case).
float configured_ui_scale() const { return configured_ui_scale_; }
void set_configured_ui_scale(float scale) { configured_ui_scale_ = scale; }

// Copy the display info except for fields that can be modified by a user
// (|rotation_| and |ui_scale_|). |rotation_| and |ui_scale_| are copied
// when the |another_info| isn't native one.
// Returns the ui scale used for the device scale factor. This
// return 1.0f if the ui scale and dsf are both set to 2.0.
float GetEffectiveUIScale() const;

// Copy the display info except for fields that can be modified by a
// user (|rotation_| and |configured_ui_scale_|). |rotation_| and
// |configured_ui_scale_| are copied when the |another_info| isn't native one.
void Copy(const DisplayInfo& another_info);

// Update the |bounds_in_native_| and |size_in_pixel_| using
Expand Down Expand Up @@ -174,8 +181,9 @@ class ASH_EXPORT DisplayInfo {
// shrink) the desktop over the native display resolution (useful in
// HighDPI display). Note that this should not be confused with the
// device scale factor, which specifies the pixel density of the
// display.
float ui_scale_;
// display. The actuall scale value to be used depends on the device
// scale factor. See |GetEffectiveScaleFactor()|.
float configured_ui_scale_;

// True if this comes from native platform (DisplayChangeObserver).
bool native_;
Expand Down
4 changes: 2 additions & 2 deletions ash/display/display_info_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_F(DisplayInfoTest, CreateFromSpec) {
EXPECT_EQ("200x100", info.size_in_pixel().ToString());
EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
EXPECT_EQ("0,0,0,0", info.overscan_insets_in_dip().ToString());
EXPECT_EQ(1.0f, info.ui_scale());
EXPECT_EQ(1.0f, info.configured_ui_scale());

info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/o", 10);
EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
Expand All @@ -42,7 +42,7 @@ TEST_F(DisplayInfoTest, CreateFromSpec) {
info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/l@1.5", 10);
EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
EXPECT_EQ(gfx::Display::ROTATE_270, info.rotation());
EXPECT_EQ(1.5f, info.ui_scale());
EXPECT_EQ(1.5f, info.configured_ui_scale());

info = DisplayInfo::CreateFromSpecWithID(
"200x200#300x200|200x200|100x100", 10);
Expand Down
16 changes: 10 additions & 6 deletions ash/display/display_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const int kMinimumOverlapForInvalidOffset = 100;
// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on
// 2560 pixel width 2x density display. Please see crbug.com/233375
// for the full list of resolutions.
const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f};
const float kUIScalesFor2x[] =
{0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f};
const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f };
const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f };

Expand Down Expand Up @@ -187,7 +188,7 @@ std::vector<float> DisplayManager::GetScalesForDisplay(

// static
float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) {
float scale = info.ui_scale();
float scale = info.configured_ui_scale();
std::vector<float> scales = GetScalesForDisplay(info);
for (size_t i = 0; i < scales.size(); ++i) {
if (ScaleComparator(scales[i])(scale)) {
Expand Down Expand Up @@ -395,15 +396,15 @@ void DisplayManager::SetDisplayUIScale(int64 display_id,
iter != displays_.end(); ++iter) {
DisplayInfo info = GetDisplayInfo(iter->id());
if (info.id() == display_id) {
if (info.ui_scale() == ui_scale)
if (info.configured_ui_scale() == ui_scale)
return;
std::vector<float> scales = GetScalesForDisplay(info);
ScaleComparator comparator(ui_scale);
if (std::find_if(scales.begin(), scales.end(), comparator) ==
scales.end()) {
return;
}
info.set_ui_scale(ui_scale);
info.set_configured_ui_scale(ui_scale);
}
display_info_list.push_back(info);
}
Expand Down Expand Up @@ -453,7 +454,7 @@ void DisplayManager::RegisterDisplayProperty(
display_info_[display_id].set_rotation(rotation);
// Just in case the preference file was corrupted.
if (0.5f <= ui_scale && ui_scale <= 2.0f)
display_info_[display_id].set_ui_scale(ui_scale);
display_info_[display_id].set_configured_ui_scale(ui_scale);
if (overscan_insets)
display_info_[display_id].SetOverscanInsets(*overscan_insets);
if (!resolution_in_pixels.IsEmpty())
Expand Down Expand Up @@ -932,12 +933,15 @@ gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64 id) {

gfx::Display new_display(display_info.id());
gfx::Rect bounds_in_native(display_info.size_in_pixel());
float device_scale_factor = display_info.device_scale_factor();
if (device_scale_factor == 2.0f && display_info.configured_ui_scale() == 2.0f)
device_scale_factor = 1.0f;

// Simply set the origin to (0,0). The primary display's origin is
// always (0,0) and the secondary display's bounds will be updated
// in |UpdateSecondaryDisplayBoundsForLayout| called in |UpdateDisplay|.
new_display.SetScaleAndBounds(
display_info.device_scale_factor(), gfx::Rect(bounds_in_native.size()));
device_scale_factor, gfx::Rect(bounds_in_native.size()));
new_display.set_rotation(display_info.rotation());
new_display.set_touch_support(display_info.touch_support());
return new_display;
Expand Down
71 changes: 42 additions & 29 deletions ash/display/display_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,69 +804,82 @@ TEST_F(DisplayManagerTest, UIScale) {
UpdateDisplay("1280x800");
int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
display_manager()->SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.0, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());

gfx::Display::SetInternalDisplayId(display_id);

display_manager()->SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());

UpdateDisplay("1366x768");
display_manager()->SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.75f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.75f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());

UpdateDisplay("1280x850*2");
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.5f);
EXPECT_EQ(1.5f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.5f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.25f);
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.125f);
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 1.0f);
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(2.0f, display.device_scale_factor());
EXPECT_EQ("640x425", display.bounds().size().ToString());

display_manager()->SetDisplayUIScale(display_id, 0.8f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.75f);
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.625f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.6f);
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
display_manager()->SetDisplayUIScale(display_id, 0.5f);
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).ui_scale());
EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());

display_manager()->SetDisplayUIScale(display_id, 2.0f);
EXPECT_EQ(2.0f, GetDisplayInfoAt(0).configured_ui_scale());
EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
display = Shell::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(1.0f, display.device_scale_factor());
EXPECT_EQ("1280x850", display.bounds().size().ToString());
}


Expand Down
22 changes: 7 additions & 15 deletions ash/display/root_window_transformers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,24 @@ gfx::Transform CreateInsetsAndScaleTransform(const gfx::Insets& insets,
return transform;
}

gfx::Transform CreateOverscanAndUIScaleTransform(aura::Window* root_window,
const gfx::Display& display) {
DisplayInfo info =
Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
return CreateInsetsAndScaleTransform(
info.GetOverscanInsetsInPixel(),
ui::GetDeviceScaleFactor(root_window->layer()),
info.ui_scale());
}

// RootWindowTransformer for ash environment.
class AshRootWindowTransformer : public aura::RootWindowTransformer {
public:
AshRootWindowTransformer(aura::Window* root,
const gfx::Display& display)
: root_window_(root) {
DisplayInfo info = Shell::GetInstance()->display_manager()->
GetDisplayInfo(display.id());
host_insets_ = info.GetOverscanInsetsInPixel();
root_window_ui_scale_ = info.GetEffectiveUIScale();
root_window_bounds_transform_ =
CreateOverscanAndUIScaleTransform(root, display) *
CreateInsetsAndScaleTransform(host_insets_,
display.device_scale_factor(),
root_window_ui_scale_) *
CreateRotationTransform(root, display);
transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root);
CHECK(transform_.GetInverse(&invert_transform_));

DisplayInfo info = Shell::GetInstance()->display_manager()->
GetDisplayInfo(display.id());
root_window_ui_scale_ = info.ui_scale();
host_insets_ = info.GetOverscanInsetsInPixel();
}

// aura::RootWindowTransformer overrides:
Expand Down
Loading

0 comments on commit ccb962d

Please sign in to comment.