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

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

Issue 2933133002: exo: Select cursor capture scale at run time (Closed)
Patch Set: Address nits Created 3 years, 6 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') | no next file » | 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 23 matching lines...) Expand all
34 34
35 namespace exo { 35 namespace exo {
36 namespace { 36 namespace {
37 37
38 // TODO(oshima): Some accessibility features, including large cursors, disable 38 // TODO(oshima): Some accessibility features, including large cursors, disable
39 // hardware cursors. Ash does not support compositing for custom cursors, so it 39 // 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 40 // replaces them with the default cursor. As a result, this scale has no effect
41 // for now. See crbug.com/708378. 41 // for now. See crbug.com/708378.
42 const float kLargeCursorScale = 2.8f; 42 const float kLargeCursorScale = 2.8f;
43 43
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); 44 const double kLocatedEventEpsilonSquared = 1.0 / (2000.0 * 2000.0);
49 45
50 // Synthesized events typically lack floating point precision so to avoid 46 // Synthesized events typically lack floating point precision so to avoid
51 // generating mouse event jitter we consider the location of these events 47 // generating mouse event jitter we consider the location of these events
52 // to be the same as |location| if floored values match. 48 // to be the same as |location| if floored values match.
53 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) { 49 bool SameLocation(const ui::LocatedEvent* event, const gfx::PointF& location) {
54 if (event->flags() & ui::EF_IS_SYNTHESIZED) 50 if (event->flags() & ui::EF_IS_SYNTHESIZED)
55 return event->location() == gfx::ToFlooredPoint(location); 51 return event->location() == gfx::ToFlooredPoint(location);
56 52
57 // In general, it is good practice to compare floats using an epsilon. 53 // In general, it is good practice to compare floats using an epsilon.
58 // In particular, the mouse location_f() could differ between the 54 // In particular, the mouse location_f() could differ between the
59 // 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
60 // targeter() already cached, while at MOUSE_PRESSED, it will have to 56 // targeter() already cached, while at MOUSE_PRESSED, it will have to
61 // 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
62 // generate rounding error. std::numeric_limits<float>::epsilon() is not big 58 // generate rounding error. std::numeric_limits<float>::epsilon() is not big
63 // enough to catch this rounding error. 59 // enough to catch this rounding error.
64 gfx::Vector2dF offset = event->location_f() - location; 60 gfx::Vector2dF offset = event->location_f() - location;
65 return offset.LengthSquared() < (2 * kLocatedEventEpsilonSquared); 61 return offset.LengthSquared() < (2 * kLocatedEventEpsilonSquared);
66 } 62 }
67 63
64 float GetCaptureScale() {
65 float capture_scale = 1.0f;
66 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) {
67 const auto& info = WMHelper::GetInstance()->GetDisplayInfo(display.id());
68 if (info.device_scale_factor() > capture_scale)
69 capture_scale = info.device_scale_factor();
70 }
71 return capture_scale;
72 }
73
68 } // namespace 74 } // namespace
69 75
70 //////////////////////////////////////////////////////////////////////////////// 76 ////////////////////////////////////////////////////////////////////////////////
71 // Pointer, public: 77 // Pointer, public:
72 78
73 Pointer::Pointer(PointerDelegate* delegate) 79 Pointer::Pointer(PointerDelegate* delegate)
74 : delegate_(delegate), 80 : delegate_(delegate),
75 cursor_(ui::CursorType::kNull), 81 cursor_(ui::CursorType::kNull),
82 capture_scale_(GetCaptureScale()),
76 cursor_capture_source_id_(base::UnguessableToken::Create()), 83 cursor_capture_source_id_(base::UnguessableToken::Create()),
77 cursor_capture_weak_ptr_factory_(this) { 84 cursor_capture_weak_ptr_factory_(this) {
78 auto* helper = WMHelper::GetInstance(); 85 auto* helper = WMHelper::GetInstance();
79 helper->AddPreTargetHandler(this); 86 helper->AddPreTargetHandler(this);
80 helper->AddCursorObserver(this); 87 helper->AddCursorObserver(this);
81 helper->AddDisplayConfigurationObserver(this); 88 helper->AddDisplayConfigurationObserver(this);
82 } 89 }
83 90
84 Pointer::~Pointer() { 91 Pointer::~Pointer() {
85 delegate_->OnPointerDestroying(this); 92 delegate_->OnPointerDestroying(this);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void Pointer::OnCursorDisplayChanged(const display::Display& display) { 270 void Pointer::OnCursorDisplayChanged(const display::Display& display) {
264 if (focus_) 271 if (focus_)
265 UpdateCursor(); 272 UpdateCursor();
266 } 273 }
267 274
268 //////////////////////////////////////////////////////////////////////////////// 275 ////////////////////////////////////////////////////////////////////////////////
269 // WMHelper::DisplayConfigurationObserver overrides: 276 // WMHelper::DisplayConfigurationObserver overrides:
270 277
271 void Pointer::OnDisplayConfigurationChanged() { 278 void Pointer::OnDisplayConfigurationChanged() {
272 UpdatePointerSurface(surface_); 279 UpdatePointerSurface(surface_);
280 capture_scale_ = GetCaptureScale();
273 } 281 }
274 282
275 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
276 // SurfaceDelegate overrides: 284 // SurfaceDelegate overrides:
277 285
278 void Pointer::OnSurfaceCommit() { 286 void Pointer::OnSurfaceCommit() {
279 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 287 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
280 surface_->CommitSurfaceHierarchy(); 288 surface_->CommitSurfaceHierarchy();
281 289
282 // Capture new cursor to reflect result of commit. 290 // Capture new cursor to reflect result of commit.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 DCHECK(surface_); 346 DCHECK(surface_);
339 DCHECK(focus_); 347 DCHECK(focus_);
340 348
341 // Surface size is in DIPs, while layer size is in pseudo-DIP units that 349 // 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 350 // 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 351 // surface at a constant pixel size, regardless of the primary display's
344 // UI scale and display mode DSF. 352 // UI scale and display mode DSF.
345 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); 353 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
346 auto* helper = WMHelper::GetInstance(); 354 auto* helper = WMHelper::GetInstance();
347 float scale = helper->GetDisplayInfo(display.id()).GetEffectiveUIScale() * 355 float scale = helper->GetDisplayInfo(display.id()).GetEffectiveUIScale() *
348 kCursorCaptureScale / display.device_scale_factor(); 356 capture_scale_ / display.device_scale_factor();
349 surface_->window()->SetTransform(gfx::GetScaleTransform(gfx::Point(), scale)); 357 surface_->window()->SetTransform(gfx::GetScaleTransform(gfx::Point(), scale));
350 358
351 std::unique_ptr<cc::CopyOutputRequest> request = 359 std::unique_ptr<cc::CopyOutputRequest> request =
352 cc::CopyOutputRequest::CreateBitmapRequest( 360 cc::CopyOutputRequest::CreateBitmapRequest(
353 base::Bind(&Pointer::OnCursorCaptured, 361 base::Bind(&Pointer::OnCursorCaptured,
354 cursor_capture_weak_ptr_factory_.GetWeakPtr(), hotspot)); 362 cursor_capture_weak_ptr_factory_.GetWeakPtr(), hotspot));
355 363
356 request->set_source(cursor_capture_source_id_); 364 request->set_source(cursor_capture_source_id_);
357 surface_->window()->layer()->RequestCopyOfOutput(std::move(request)); 365 surface_->window()->layer()->RequestCopyOfOutput(std::move(request));
358 } 366 }
(...skipping 14 matching lines...) Expand all
373 UpdateCursor(); 381 UpdateCursor();
374 } 382 }
375 383
376 void Pointer::UpdateCursor() { 384 void Pointer::UpdateCursor() {
377 DCHECK(focus_); 385 DCHECK(focus_);
378 386
379 if (cursor_bitmap_.drawsNothing()) { 387 if (cursor_bitmap_.drawsNothing()) {
380 cursor_ = ui::CursorType::kNone; 388 cursor_ = ui::CursorType::kNone;
381 } else { 389 } else {
382 SkBitmap bitmap = cursor_bitmap_; 390 SkBitmap bitmap = cursor_bitmap_;
383 gfx::Point hotspot = 391 gfx::Point hotspot = gfx::ScaleToFlooredPoint(hotspot_, capture_scale_);
384 gfx::ScaleToFlooredPoint(hotspot_, kCursorCaptureScale);
385 392
386 auto* helper = WMHelper::GetInstance(); 393 auto* helper = WMHelper::GetInstance();
387 const display::Display& display = helper->GetCursorDisplay(); 394 const display::Display& display = helper->GetCursorDisplay();
388 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() / 395 float scale = helper->GetDisplayInfo(display.id()).device_scale_factor() /
389 kCursorCaptureScale; 396 capture_scale_;
390 397
391 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE) 398 if (helper->GetCursorSet() == ui::CURSOR_SET_LARGE)
392 scale *= kLargeCursorScale; 399 scale *= kLargeCursorScale;
393 400
394 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(), 401 ui::ScaleAndRotateCursorBitmapAndHotpoint(scale, display.rotation(),
395 &bitmap, &hotspot); 402 &bitmap, &hotspot);
396 403
397 ui::PlatformCursor platform_cursor; 404 ui::PlatformCursor platform_cursor;
398 #if defined(USE_OZONE) 405 #if defined(USE_OZONE)
399 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers 406 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers
(...skipping 17 matching lines...) Expand all
417 if (!root_window) 424 if (!root_window)
418 return; 425 return;
419 426
420 aura::client::CursorClient* cursor_client = 427 aura::client::CursorClient* cursor_client =
421 aura::client::GetCursorClient(root_window); 428 aura::client::GetCursorClient(root_window);
422 if (cursor_client) 429 if (cursor_client)
423 cursor_client->SetCursor(cursor_); 430 cursor_client->SetCursor(cursor_);
424 } 431 }
425 432
426 } // namespace exo 433 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698