Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: components/exo/pointer.cc

Issue 2944063002: exo: Fix cursor scaling for 1.25 DSF (Closed)
Patch Set: Restore DCHECK Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/pointer.h ('k') | ui/display/manager/managed_display_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // In particular, the mouse location_f() could differ between the 54 // In particular, the mouse location_f() could differ between the
55 // MOUSE_PRESSED and MOUSE_RELEASED events. At MOUSE_RELEASED, it will have a 55 // MOUSE_PRESSED and MOUSE_RELEASED events. At MOUSE_RELEASED, it will have a
56 // targeter() already cached, while at MOUSE_PRESSED, it will have to 56 // targeter() already cached, while at MOUSE_PRESSED, it will have to
57 // calculate it passing through all the hierarchy of windows, and that could 57 // calculate it passing through all the hierarchy of windows, and that could
58 // generate rounding error. std::numeric_limits<float>::epsilon() is not big 58 // generate rounding error. std::numeric_limits<float>::epsilon() is not big
59 // enough to catch this rounding error. 59 // enough to catch this rounding error.
60 gfx::Vector2dF offset = event->location_f() - location; 60 gfx::Vector2dF offset = event->location_f() - location;
61 return offset.LengthSquared() < (2 * kLocatedEventEpsilonSquared); 61 return offset.LengthSquared() < (2 * kLocatedEventEpsilonSquared);
62 } 62 }
63 63
64 float GetCaptureScale() { 64 display::ManagedDisplayInfo GetCaptureDisplayInfo() {
65 float capture_scale = 1.0f; 65 display::ManagedDisplayInfo capture_info;
66 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { 66 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) {
67 const auto& info = WMHelper::GetInstance()->GetDisplayInfo(display.id()); 67 const auto& info = WMHelper::GetInstance()->GetDisplayInfo(display.id());
68 if (info.device_scale_factor() > capture_scale) 68 if (info.device_scale_factor() >= capture_info.device_scale_factor())
69 capture_scale = info.device_scale_factor(); 69 capture_info = info;
70 } 70 }
71 return capture_scale; 71 return capture_info;
72 } 72 }
73 73
74 } // namespace 74 } // namespace
75 75
76 //////////////////////////////////////////////////////////////////////////////// 76 ////////////////////////////////////////////////////////////////////////////////
77 // Pointer, public: 77 // Pointer, public:
78 78
79 Pointer::Pointer(PointerDelegate* delegate) 79 Pointer::Pointer(PointerDelegate* delegate)
80 : delegate_(delegate), 80 : delegate_(delegate),
81 cursor_(ui::CursorType::kNull), 81 cursor_(ui::CursorType::kNull),
82 capture_scale_(GetCaptureScale()), 82 capture_scale_(GetCaptureDisplayInfo().device_scale_factor()),
83 capture_ratio_(GetCaptureDisplayInfo().GetDensityRatio()),
83 cursor_capture_source_id_(base::UnguessableToken::Create()), 84 cursor_capture_source_id_(base::UnguessableToken::Create()),
84 cursor_capture_weak_ptr_factory_(this) { 85 cursor_capture_weak_ptr_factory_(this) {
85 auto* helper = WMHelper::GetInstance(); 86 auto* helper = WMHelper::GetInstance();
86 helper->AddPreTargetHandler(this); 87 helper->AddPreTargetHandler(this);
87 helper->AddCursorObserver(this); 88 helper->AddCursorObserver(this);
88 helper->AddDisplayConfigurationObserver(this); 89 helper->AddDisplayConfigurationObserver(this);
89 } 90 }
90 91
91 Pointer::~Pointer() { 92 Pointer::~Pointer() {
92 delegate_->OnPointerDestroying(this); 93 delegate_->OnPointerDestroying(this);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 void Pointer::OnCursorDisplayChanged(const display::Display& display) { 271 void Pointer::OnCursorDisplayChanged(const display::Display& display) {
271 if (focus_) 272 if (focus_)
272 UpdateCursor(); 273 UpdateCursor();
273 } 274 }
274 275
275 //////////////////////////////////////////////////////////////////////////////// 276 ////////////////////////////////////////////////////////////////////////////////
276 // WMHelper::DisplayConfigurationObserver overrides: 277 // WMHelper::DisplayConfigurationObserver overrides:
277 278
278 void Pointer::OnDisplayConfigurationChanged() { 279 void Pointer::OnDisplayConfigurationChanged() {
279 UpdatePointerSurface(surface_); 280 UpdatePointerSurface(surface_);
280 capture_scale_ = GetCaptureScale(); 281 auto info = GetCaptureDisplayInfo();
282 capture_scale_ = info.device_scale_factor();
283 capture_ratio_ = info.GetDensityRatio();
281 } 284 }
282 285
283 //////////////////////////////////////////////////////////////////////////////// 286 ////////////////////////////////////////////////////////////////////////////////
284 // SurfaceDelegate overrides: 287 // SurfaceDelegate overrides:
285 288
286 void Pointer::OnSurfaceCommit() { 289 void Pointer::OnSurfaceCommit() {
287 surface_->CommitSurfaceHierarchy(); 290 surface_->CommitSurfaceHierarchy();
288 291
289 // Capture new cursor to reflect result of commit. 292 // Capture new cursor to reflect result of commit.
290 if (focus_) 293 if (focus_)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 UpdateCursor(); 383 UpdateCursor();
381 } 384 }
382 385
383 void Pointer::UpdateCursor() { 386 void Pointer::UpdateCursor() {
384 DCHECK(focus_); 387 DCHECK(focus_);
385 388
386 if (cursor_bitmap_.drawsNothing()) { 389 if (cursor_bitmap_.drawsNothing()) {
387 cursor_ = ui::CursorType::kNone; 390 cursor_ = ui::CursorType::kNone;
388 } else { 391 } else {
389 SkBitmap bitmap = cursor_bitmap_; 392 SkBitmap bitmap = cursor_bitmap_;
390 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_scale_); 393 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_ratio_);
391 394
392 auto* helper = WMHelper::GetInstance(); 395 auto* helper = WMHelper::GetInstance();
393 const display::Display& display = helper->GetCursorDisplay(); 396 const display::Display& display = helper->GetCursorDisplay();
394 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() / 397 float scale =
395 capture_scale_; 398 helper->GetDisplayInfo(display.id()).GetDensityRatio() / capture_ratio_;
396 399
397 if (helper->GetCursorSize() == ui::CursorSize::kLarge) 400 if (helper->GetCursorSize() == ui::CursorSize::kLarge)
398 scale *= kLargeCursorScale; 401 scale *= kLargeCursorScale;
399 402
400 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), 403 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(),
401 &bitmap, &hotspot); 404 &bitmap, &hotspot);
402 405
403 ui::PlatformCursor platform_cursor; 406 ui::PlatformCursor platform_cursor;
404 #if defined(USE_OZONE) 407 #if defined(USE_OZONE)
405 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers 408 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers
(...skipping 17 matching lines...) Expand all
423 if (!root_window) 426 if (!root_window)
424 return; 427 return;
425 428
426 aura::client::CursorClient* cursor_client = 429 aura::client::CursorClient* cursor_client =
427 aura::client::GetCursorClient(root_window); 430 aura::client::GetCursorClient(root_window);
428 if (cursor_client) 431 if (cursor_client)
429 cursor_client->SetCursor(cursor_); 432 cursor_client->SetCursor(cursor_);
430 } 433 }
431 434
432 } // namespace exo 435 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | ui/display/manager/managed_display_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698