| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 290 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 288 surface_->CommitSurfaceHierarchy(); | 291 surface_->CommitSurfaceHierarchy(); |
| 289 | 292 |
| 290 // Capture new cursor to reflect result of commit. | 293 // Capture new cursor to reflect result of commit. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 UpdateCursor(); | 384 UpdateCursor(); |
| 382 } | 385 } |
| 383 | 386 |
| 384 void Pointer::UpdateCursor() { | 387 void Pointer::UpdateCursor() { |
| 385 DCHECK(focus_); | 388 DCHECK(focus_); |
| 386 | 389 |
| 387 if (cursor_bitmap_.drawsNothing()) { | 390 if (cursor_bitmap_.drawsNothing()) { |
| 388 cursor_ = ui::CursorType::kNone; | 391 cursor_ = ui::CursorType::kNone; |
| 389 } else { | 392 } else { |
| 390 SkBitmap bitmap = cursor_bitmap_; | 393 SkBitmap bitmap = cursor_bitmap_; |
| 391 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_scale_); | 394 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_ratio_); |
| 392 | 395 |
| 393 auto* helper = WMHelper::GetInstance(); | 396 auto* helper = WMHelper::GetInstance(); |
| 394 const display::Display& display = helper->GetCursorDisplay(); | 397 const display::Display& display = helper->GetCursorDisplay(); |
| 395 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() / | 398 float scale = |
| 396 capture_scale_; | 399 helper->GetDisplayInfo(display.id()).GetDensityRatio() / capture_ratio_; |
| 397 | 400 |
| 398 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE) | 401 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE) |
| 399 scale *= kLargeCursorScale; | 402 scale *= kLargeCursorScale; |
| 400 | 403 |
| 401 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), | 404 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), |
| 402 &bitmap, &hotspot); | 405 &bitmap, &hotspot); |
| 403 | 406 |
| 404 ui::PlatformCursor platform_cursor; | 407 ui::PlatformCursor platform_cursor; |
| 405 #if defined(USE_OZONE) | 408 #if defined(USE_OZONE) |
| 406 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers | 409 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers |
| (...skipping 17 matching lines...) Expand all Loading... |
| 424 if (!root_window) | 427 if (!root_window) |
| 425 return; | 428 return; |
| 426 | 429 |
| 427 aura::client::CursorClient* cursor_client = | 430 aura::client::CursorClient* cursor_client = |
| 428 aura::client::GetCursorClient(root_window); | 431 aura::client::GetCursorClient(root_window); |
| 429 if (cursor_client) | 432 if (cursor_client) |
| 430 cursor_client->SetCursor(cursor_); | 433 cursor_client->SetCursor(cursor_); |
| 431 } | 434 } |
| 432 | 435 |
| 433 } // namespace exo | 436 } // namespace exo |
| OLD | NEW |