diff options
author | oshima <oshima@chromium.org> | 2015-08-05 19:47:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-06 02:47:57 +0000 |
commit | aa9d2b12ce0273f5d4d890a548a4bfda7d849c2b (patch) | |
tree | d95fb6753336c459add33b45f1e745b7e5a6f0e6 /ash | |
parent | 7ab467f3986b10015e8f79a3ce2c9ba25c14d41b (diff) | |
download | chromium_src-aa9d2b12ce0273f5d4d890a548a4bfda7d849c2b.zip chromium_src-aa9d2b12ce0273f5d4d890a548a4bfda7d849c2b.tar.gz chromium_src-aa9d2b12ce0273f5d4d890a548a4bfda7d849c2b.tar.bz2 |
Use the original scale factor for cursor even in software cursor mode
BUG=517252
Review URL: https://codereview.chromium.org/1274893003
Cr-Commit-Position: refs/heads/master@{#342051}
Diffstat (limited to 'ash')
-rw-r--r-- | ash/display/cursor_window_controller.cc | 75 | ||||
-rw-r--r-- | ash/display/cursor_window_controller.h | 2 | ||||
-rw-r--r-- | ash/display/cursor_window_controller_unittest.cc | 26 |
3 files changed, 69 insertions, 34 deletions
diff --git a/ash/display/cursor_window_controller.cc b/ash/display/cursor_window_controller.cc index 9e30dec..eb334b8 100644 --- a/ash/display/cursor_window_controller.cc +++ b/ash/display/cursor_window_controller.cc @@ -20,6 +20,7 @@ #include "ui/compositor/paint_recorder.h" #include "ui/gfx/canvas.h" #include "ui/gfx/display.h" +#include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia_operations.h" @@ -27,7 +28,7 @@ namespace ash { class CursorWindowDelegate : public aura::WindowDelegate { public: - CursorWindowDelegate() : is_cursor_compositing_enabled_(false) {} + CursorWindowDelegate() {} ~CursorWindowDelegate() override {} // aura::WindowDelegate overrides: @@ -60,32 +61,16 @@ class CursorWindowDelegate : public aura::WindowDelegate { bool HasHitTestMask() const override { return false; } void GetHitTestMask(gfx::Path* mask) const override {} - // Sets cursor compositing mode on/off. - void SetCursorCompositingEnabled(bool enabled) { - is_cursor_compositing_enabled_ = enabled; - } - // Sets the cursor image for the |display|'s scale factor. - void SetCursorImage(const gfx::ImageSkia& image, - const gfx::Display& display) { - float scale_factor = display.device_scale_factor(); - const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor); - if (!is_cursor_compositing_enabled_) { - // Note that mirror window's scale factor is always 1.0f, therefore we - // need to take 2x's image and paint as if it's 1x image. - size_ = image_rep.pixel_size(); - cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap()); - } else { - size_ = image.size(); - cursor_image_ = gfx::ImageSkia( - gfx::ImageSkiaRep(image_rep.sk_bitmap(), scale_factor)); - } + void SetCursorImage(const gfx::Size& size, const gfx::ImageSkia& image) { + size_ = size; + cursor_image_ = image; } - const gfx::Size size() const { return size_; } + const gfx::Size& size() const { return size_; } + const gfx::ImageSkia& cursor_image() const { return cursor_image_; } private: - bool is_cursor_compositing_enabled_; gfx::ImageSkia cursor_image_; gfx::Size size_; @@ -108,8 +93,8 @@ CursorWindowController::~CursorWindowController() { void CursorWindowController::SetCursorCompositingEnabled(bool enabled) { if (is_cursor_compositing_enabled_ != enabled) { is_cursor_compositing_enabled_ = enabled; - delegate_->SetCursorCompositingEnabled(enabled); - UpdateCursorImage(); + if (display_.is_valid()) + UpdateCursorImage(); UpdateContainer(); } } @@ -223,19 +208,30 @@ void CursorWindowController::SetBoundsInScreen(const gfx::Rect& bounds) { } void CursorWindowController::UpdateCursorImage() { + float cursor_scale; + if (!is_cursor_compositing_enabled_) { + cursor_scale = display_.device_scale_factor(); + } else { + // Use the original device scale factor instead of the display's, which + // might have been adjusted for the UI scale. + const float original_scale = Shell::GetInstance() + ->display_manager() + ->GetDisplayInfo(display_.id()) + .device_scale_factor(); + // And use the nearest resource scale factor. + cursor_scale = + ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale)); + } int resource_id; // TODO(hshi): support custom cursor set. - if (!ui::GetCursorDataFor(cursor_set_, - cursor_type_, - display_.device_scale_factor(), - &resource_id, - &hot_point_)) { + if (!ui::GetCursorDataFor(cursor_set_, cursor_type_, cursor_scale, + &resource_id, &hot_point_)) { return; } const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); - gfx::ImageSkia rotated = *image; if (!is_cursor_compositing_enabled_) { + gfx::ImageSkia rotated = *image; switch (display_.rotation()) { case gfx::Display::ROTATE_0: break; @@ -261,11 +257,20 @@ void CursorWindowController::UpdateCursorImage() { rotated.height() - hot_point_.x()); break; } + // Note that mirror window's scale factor is always 1.0f, therefore we + // need to take 2x's image and paint as if it's 1x image. + const gfx::ImageSkiaRep& image_rep = + rotated.GetRepresentation(cursor_scale); + delegate_->SetCursorImage( + image_rep.pixel_size(), + gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap())); } else { - hot_point_ = ui::ConvertPointToDIP(Shell::GetPrimaryRootWindow()->layer(), - hot_point_); + const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(cursor_scale); + delegate_->SetCursorImage( + image->size(), + gfx::ImageSkia(gfx::ImageSkiaRep(image_rep.sk_bitmap(), cursor_scale))); + hot_point_ = gfx::ConvertPointToDIP(cursor_scale, hot_point_); } - delegate_->SetCursorImage(rotated, display_); if (cursor_window_) { cursor_window_->SetBounds(gfx::Rect(delegate_->size())); cursor_window_->SchedulePaintInRect( @@ -284,4 +289,8 @@ void CursorWindowController::UpdateCursorVisibility() { cursor_window_->Hide(); } +const gfx::ImageSkia& CursorWindowController::GetCursorImageForTest() const { + return delegate_->cursor_image(); +} + } // namespace ash diff --git a/ash/display/cursor_window_controller.h b/ash/display/cursor_window_controller.h index 8ce1a5b..ae6752f 100644 --- a/ash/display/cursor_window_controller.h +++ b/ash/display/cursor_window_controller.h @@ -65,6 +65,8 @@ class ASH_EXPORT CursorWindowController { // Hides/shows cursor window based on current cursor state. void UpdateCursorVisibility(); + const gfx::ImageSkia& GetCursorImageForTest() const; + bool is_cursor_compositing_enabled_; aura::Window* container_; diff --git a/ash/display/cursor_window_controller_unittest.cc b/ash/display/cursor_window_controller_unittest.cc index d822bce..d1f9445 100644 --- a/ash/display/cursor_window_controller_unittest.cc +++ b/ash/display/cursor_window_controller_unittest.cc @@ -4,10 +4,12 @@ #include "ash/display/cursor_window_controller.h" +#include "ash/display/display_util.h" #include "ash/display/window_tree_host_manager.h" #include "ash/screen_util.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/test/display_manager_test_api.h" #include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" #include "ui/base/cursor/cursor.h" @@ -38,6 +40,10 @@ class CursorWindowControllerTest : public test::AshTestBase { return cursor_window_controller_->cursor_window_.get(); } + const gfx::ImageSkia& GetCursorImage() const { + return cursor_window_controller_->GetCursorImageForTest(); + } + int64 GetCursorDisplayId() const { return cursor_window_controller_->display_.id(); } @@ -104,7 +110,7 @@ TEST_F(CursorWindowControllerTest, MoveToDifferentDisplay) { EXPECT_EQ(secondary_display_id, GetCursorDisplayId()); EXPECT_EQ(ui::kCursorNull, GetCursorType()); hot_point = GetCursorHotPoint(); - EXPECT_EQ("7,7", hot_point.ToString()); + EXPECT_EQ("3,3", hot_point.ToString()); cursor_bounds = GetCursorWindow()->GetBoundsInScreen(); EXPECT_EQ(220, cursor_bounds.x() + hot_point.x()); EXPECT_EQ(50, cursor_bounds.y() + hot_point.y()); @@ -143,6 +149,24 @@ TEST_F(CursorWindowControllerTest, VisibilityTest) { ASSERT_TRUE(GetCursorWindow()); EXPECT_TRUE(GetCursorWindow()->IsVisible()); } + +// Make sure that composition cursor stays big even when +// the DSF becomes 1x as a result of zooming out. +TEST_F(CursorWindowControllerTest, DSF) { + UpdateDisplay("1000x500*2"); + int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); + + test::ScopedSetInternalDisplayId set_internal(primary_id); + SetCursorCompositionEnabled(true); + ASSERT_EQ(2.0f, + Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor()); + EXPECT_TRUE(GetCursorImage().HasRepresentation(2.0f)); + + ASSERT_TRUE(SetDisplayUIScale(primary_id, 2.0f)); + ASSERT_EQ(1.0f, + Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor()); + EXPECT_TRUE(GetCursorImage().HasRepresentation(2.0f)); +} #endif } // namespace ash |