Chromium Code Reviews| 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 <algorithm> | |
|
reveman
2017/06/22 21:24:01
nit: remove if not needed
Dominik Laskowski
2017/06/22 22:31:14
Removed along with std::max.
| |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
| 11 #include "cc/output/copy_output_result.h" | 12 #include "cc/output/copy_output_result.h" |
| 12 #include "components/exo/pointer_delegate.h" | 13 #include "components/exo/pointer_delegate.h" |
| 13 #include "components/exo/pointer_stylus_delegate.h" | 14 #include "components/exo/pointer_stylus_delegate.h" |
| 14 #include "components/exo/surface.h" | 15 #include "components/exo/surface.h" |
| 15 #include "components/exo/wm_helper.h" | 16 #include "components/exo/wm_helper.h" |
| 16 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 34 | 35 |
| 35 namespace exo { | 36 namespace exo { |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // TODO(oshima): Some accessibility features, including large cursors, disable | 39 // TODO(oshima): Some accessibility features, including large cursors, disable |
| 39 // hardware cursors. Ash does not support compositing for custom cursors, so it | 40 // hardware cursors. Ash does not support compositing for custom cursors, so it |
| 40 // replaces them with the default cursor. As a result, this scale has no effect | 41 // replaces them with the default cursor. As a result, this scale has no effect |
| 41 // for now. See crbug.com/708378. | 42 // for now. See crbug.com/708378. |
| 42 const float kLargeCursorScale = 2.8f; | 43 const float kLargeCursorScale = 2.8f; |
| 43 | 44 |
| 44 // Scale at which cursor snapshot is captured. The resulting bitmap is scaled on | |
| 45 // displays whose DSF does not match this scale. | |
| 46 const float kCursorCaptureScale = 2.0f; | |
| 47 | |
| 48 const double kLocatedEventEpsilonSquared = 1.0 / (2000.0 * 2000.0); | 45 const double kLocatedEventEpsilonSquared = 1.0 / (2000.0 * 2000.0); |
| 49 | 46 |
| 50 // Synthesized events typically lack floating point precision so to avoid | 47 // Synthesized events typically lack floating point precision so to avoid |
| 51 // generating mouse event jitter we consider the location of these events | 48 // generating mouse event jitter we consider the location of these events |
| 52 // to be the same as |location| if floored values match. | 49 // to be the same as |location| if floored values match. |
| 53 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { | 50 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { |
| 54 if (event->flags() & ui::EF_IS_SYNTHESIZED) | 51 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
| 55 return event->location() == gfx::ToFlooredPoint(location); | 52 return event->location() == gfx::ToFlooredPoint(location); |
| 56 | 53 |
| 57 // In general, it is good practice to compare floats using an epsilon. | 54 // In general, it is good practice to compare floats using an epsilon. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 | 69 |
| 73 Pointer::Pointer(PointerDelegate* delegate) | 70 Pointer::Pointer(PointerDelegate* delegate) |
| 74 : delegate_(delegate), | 71 : delegate_(delegate), |
| 75 cursor_(ui::CursorType::kNull), | 72 cursor_(ui::CursorType::kNull), |
| 76 cursor_capture_source_id_(base::UnguessableToken::Create()), | 73 cursor_capture_source_id_(base::UnguessableToken::Create()), |
| 77 cursor_capture_weak_ptr_factory_(this) { | 74 cursor_capture_weak_ptr_factory_(this) { |
| 78 auto* helper = WMHelper::GetInstance(); | 75 auto* helper = WMHelper::GetInstance(); |
| 79 helper->AddPreTargetHandler(this); | 76 helper->AddPreTargetHandler(this); |
| 80 helper->AddCursorObserver(this); | 77 helper->AddCursorObserver(this); |
| 81 helper->AddDisplayConfigurationObserver(this); | 78 helper->AddDisplayConfigurationObserver(this); |
| 79 | |
| 80 OnDisplayConfigurationChanged(); | |
|
reveman
2017/06/22 21:24:01
nit: don't call this here. see comment below
Dominik Laskowski
2017/06/22 22:31:14
Done.
| |
| 82 } | 81 } |
| 83 | 82 |
| 84 Pointer::~Pointer() { | 83 Pointer::~Pointer() { |
| 85 delegate_->OnPointerDestroying(this); | 84 delegate_->OnPointerDestroying(this); |
| 86 if (surface_) | 85 if (surface_) |
| 87 surface_->RemoveSurfaceObserver(this); | 86 surface_->RemoveSurfaceObserver(this); |
| 88 if (focus_) { | 87 if (focus_) { |
| 89 focus_->RemoveSurfaceObserver(this); | 88 focus_->RemoveSurfaceObserver(this); |
| 90 focus_->UnregisterCursorProvider(this); | 89 focus_->UnregisterCursorProvider(this); |
| 91 } | 90 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 void Pointer::OnCursorDisplayChanged(const display::Display& display) { | 262 void Pointer::OnCursorDisplayChanged(const display::Display& display) { |
| 264 if (focus_) | 263 if (focus_) |
| 265 UpdateCursor(); | 264 UpdateCursor(); |
| 266 } | 265 } |
| 267 | 266 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 267 //////////////////////////////////////////////////////////////////////////////// |
| 269 // WMHelper::DisplayConfigurationObserver overrides: | 268 // WMHelper::DisplayConfigurationObserver overrides: |
| 270 | 269 |
| 271 void Pointer::OnDisplayConfigurationChanged() { | 270 void Pointer::OnDisplayConfigurationChanged() { |
| 272 UpdatePointerSurface(surface_); | 271 UpdatePointerSurface(surface_); |
| 272 | |
| 273 capture_scale_ = 1.0f; | |
| 274 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { | |
| 275 const auto& info = WMHelper::GetInstance()->GetDisplayInfo(display.id()); | |
| 276 capture_scale_ = std::max(capture_scale_, info.device_scale_factor()); | |
| 277 } | |
|
reveman
2017/06/22 21:24:01
nit: please move this logic into a GetCaptureScale
Dominik Laskowski
2017/06/22 22:31:14
Done.
| |
| 273 } | 278 } |
| 274 | 279 |
| 275 //////////////////////////////////////////////////////////////////////////////// | 280 //////////////////////////////////////////////////////////////////////////////// |
| 276 // SurfaceDelegate overrides: | 281 // SurfaceDelegate overrides: |
| 277 | 282 |
| 278 void Pointer::OnSurfaceCommit() { | 283 void Pointer::OnSurfaceCommit() { |
| 279 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 284 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 280 surface_->CommitSurfaceHierarchy(); | 285 surface_->CommitSurfaceHierarchy(); |
| 281 | 286 |
| 282 // Capture new cursor to reflect result of commit. | 287 // Capture new cursor to reflect result of commit. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 DCHECK(surface_); | 343 DCHECK(surface_); |
| 339 DCHECK(focus_); | 344 DCHECK(focus_); |
| 340 | 345 |
| 341 // Surface size is in DIPs, while layer size is in pseudo-DIP units that | 346 // Surface size is in DIPs, while layer size is in pseudo-DIP units that |
| 342 // depend on the DSF of the display mode. Scale the layer to capture the | 347 // depend on the DSF of the display mode. Scale the layer to capture the |
| 343 // surface at a constant pixel size, regardless of the primary display's | 348 // surface at a constant pixel size, regardless of the primary display's |
| 344 // UI scale and display mode DSF. | 349 // UI scale and display mode DSF. |
| 345 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | 350 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 346 auto* helper = WMHelper::GetInstance(); | 351 auto* helper = WMHelper::GetInstance(); |
| 347 float scale = helper->GetDisplayInfo(display.id()).GetEffectiveUIScale() * | 352 float scale = helper->GetDisplayInfo(display.id()).GetEffectiveUIScale() * |
| 348 kCursorCaptureScale / display.device_scale_factor(); | 353 capture_scale_ / display.device_scale_factor(); |
| 349 surface_->window()->SetTransform(gfx::GetScaleTransform(gfx::Point(), scale)); | 354 surface_->window()->SetTransform(gfx::GetScaleTransform(gfx::Point(), scale)); |
| 350 | 355 |
| 351 std::unique_ptr<cc::CopyOutputRequest> request = | 356 std::unique_ptr<cc::CopyOutputRequest> request = |
| 352 cc::CopyOutputRequest::CreateBitmapRequest( | 357 cc::CopyOutputRequest::CreateBitmapRequest( |
| 353 base::Bind(&Pointer::OnCursorCaptured, | 358 base::Bind(&Pointer::OnCursorCaptured, |
| 354 cursor_capture_weak_ptr_factory_.GetWeakPtr(), hotspot)); | 359 cursor_capture_weak_ptr_factory_.GetWeakPtr(), hotspot)); |
| 355 | 360 |
| 356 request->set_source(cursor_capture_source_id_); | 361 request->set_source(cursor_capture_source_id_); |
| 357 surface_->window()->layer()->RequestCopyOfOutput(std::move(request)); | 362 surface_->window()->layer()->RequestCopyOfOutput(std::move(request)); |
| 358 } | 363 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 373 UpdateCursor(); | 378 UpdateCursor(); |
| 374 } | 379 } |
| 375 | 380 |
| 376 void Pointer::UpdateCursor() { | 381 void Pointer::UpdateCursor() { |
| 377 DCHECK(focus_); | 382 DCHECK(focus_); |
| 378 | 383 |
| 379 if (cursor_bitmap_.drawsNothing()) { | 384 if (cursor_bitmap_.drawsNothing()) { |
| 380 cursor_ = ui::CursorType::kNone; | 385 cursor_ = ui::CursorType::kNone; |
| 381 } else { | 386 } else { |
| 382 SkBitmap bitmap = cursor_bitmap_; | 387 SkBitmap bitmap = cursor_bitmap_; |
| 383 gfx::Point hotspot = | 388 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_scale_); |
| 384 gfx::ScaleToFlooredPoint(hotspot_, kCursorCaptureScale); | |
| 385 | 389 |
| 386 auto* helper = WMHelper::GetInstance(); | 390 auto* helper = WMHelper::GetInstance(); |
| 387 const display::Display& display = helper->GetCursorDisplay(); | 391 const display::Display& display = helper->GetCursorDisplay(); |
| 388 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() / | 392 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() / |
| 389 kCursorCaptureScale; | 393 capture_scale_; |
| 390 | 394 |
| 391 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE) | 395 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE) |
| 392 scale *= kLargeCursorScale; | 396 scale *= kLargeCursorScale; |
| 393 | 397 |
| 394 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), | 398 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), |
| 395 &bitmap, &hotspot); | 399 &bitmap, &hotspot); |
| 396 | 400 |
| 397 ui::PlatformCursor platform_cursor; | 401 ui::PlatformCursor platform_cursor; |
| 398 #if defined(USE_OZONE) | 402 #if defined(USE_OZONE) |
| 399 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers | 403 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 417 if (!root_window) | 421 if (!root_window) |
| 418 return; | 422 return; |
| 419 | 423 |
| 420 aura::client::CursorClient* cursor_client = | 424 aura::client::CursorClient* cursor_client = |
| 421 aura::client::GetCursorClient(root_window); | 425 aura::client::GetCursorClient(root_window); |
| 422 if (cursor_client) | 426 if (cursor_client) |
| 423 cursor_client->SetCursor(cursor_); | 427 cursor_client->SetCursor(cursor_); |
| 424 } | 428 } |
| 425 | 429 |
| 426 } // namespace exo | 430 } // namespace exo |
| OLD | NEW |