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

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

Issue 2777343002: exo: Rotate cursor snapshot for rotated displays (Closed)
Patch Set: Created 3 years, 8 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
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 "ash/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "cc/output/copy_output_request.h" 8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h" 9 #include "cc/output/copy_output_result.h"
10 #include "components/exo/pointer_delegate.h" 10 #include "components/exo/pointer_delegate.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Reparent the cursor to the root window where the mouse is located. 260 // Reparent the cursor to the root window where the mouse is located.
261 if (container->GetRootWindow() != cursor_->GetRootWindow()) { 261 if (container->GetRootWindow() != cursor_->GetRootWindow()) {
262 if (cursor_->parent()) 262 if (cursor_->parent())
263 cursor_->parent()->RemoveChild(cursor_.get()); 263 cursor_->parent()->RemoveChild(cursor_.get());
264 container->AddChild(cursor_.get()); 264 container->AddChild(cursor_.get());
265 } 265 }
266 266
267 auto info = helper->GetDisplayInfo(display.id()); 267 auto info = helper->GetDisplayInfo(display.id());
268 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor(); 268 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor();
269 device_scale_factor_ = display.device_scale_factor(); 269 device_scale_factor_ = display.device_scale_factor();
270 rotation_ = display.rotation();
270 271
271 if (focus_ && surface_) { 272 if (focus_ && surface_) {
272 // Capture is asynchronous, so avoid rendering old cursor in the meantime. 273 // Capture is asynchronous, so avoid rendering old cursor in the meantime.
273 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs(); 274 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs();
274 UpdateCursor(ui::kCursorNone, true); 275 UpdateCursor(ui::kCursorNone, true);
275 // Force the cursor to be updated even if locked. 276 // Force the cursor to be updated even if locked.
276 CaptureCursor(true); 277 CaptureCursor(true);
277 } 278 }
278 } 279 }
279 280
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 321
321 void Pointer::CaptureCursor(bool force) { 322 void Pointer::CaptureCursor(bool force) {
322 DCHECK(surface_); 323 DCHECK(surface_);
323 DCHECK(focus_); 324 DCHECK(focus_);
324 325
325 float scale = cursor_scale_ * display_scale_; 326 float scale = cursor_scale_ * display_scale_;
326 float layer_scale = scale / device_scale_factor_; 327 float layer_scale = scale / device_scale_factor_;
327 328
328 gfx::Transform transform; 329 gfx::Transform transform;
329 transform.Scale(layer_scale, layer_scale); 330 transform.Scale(layer_scale, layer_scale);
331 transform.Rotate(display::Display::RotationAsDegree(rotation_));
330 surface_->window()->SetTransform(transform); 332 surface_->window()->SetTransform(transform);
331 333
334 gfx::Point hotspot = hotspot_;
335 aura::Window::ConvertPointToTarget(surface_->window(), cursor_.get(),
336 &hotspot);
337
332 std::unique_ptr<cc::CopyOutputRequest> request = 338 std::unique_ptr<cc::CopyOutputRequest> request =
333 cc::CopyOutputRequest::CreateBitmapRequest( 339 cc::CopyOutputRequest::CreateBitmapRequest(
334 base::Bind(&Pointer::OnCursorCaptured, 340 base::Bind(&Pointer::OnCursorCaptured,
335 cursor_capture_weak_ptr_factory_.GetWeakPtr(), 341 cursor_capture_weak_ptr_factory_.GetWeakPtr(),
336 gfx::ScaleToFlooredPoint(hotspot_, scale), force)); 342 gfx::ScaleToFlooredPoint(hotspot, scale), force));
337 343
338 request->set_source(cursor_capture_source_id_); 344 request->set_source(cursor_capture_source_id_);
339 cursor_->layer()->RequestCopyOfOutput(std::move(request)); 345 cursor_->layer()->RequestCopyOfOutput(std::move(request));
340 346
341 // Prevent subsequent requests in the same frame from aborting this capture. 347 // Prevent subsequent requests in the same frame from aborting this capture.
342 if (force) 348 if (force)
343 cursor_capture_source_id_ = base::UnguessableToken::Create(); 349 cursor_capture_source_id_ = base::UnguessableToken::Create();
344 } 350 }
345 351
346 void Pointer::OnCursorCaptured(gfx::Point hotspot, 352 void Pointer::OnCursorCaptured(gfx::Point hotspot,
347 bool force, 353 bool force,
348 std::unique_ptr<cc::CopyOutputResult> result) { 354 std::unique_ptr<cc::CopyOutputResult> result) {
349 if (!focus_) 355 if (!focus_)
350 return; 356 return;
351 357
352 gfx::NativeCursor cursor = ui::kCursorNull; 358 gfx::NativeCursor cursor = ui::kCursorNull;
353 if (!result->IsEmpty()) { 359 if (!result->IsEmpty()) {
354 DCHECK(result->HasBitmap()); 360 DCHECK(result->HasBitmap());
355 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); 361 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap();
356 362
363 switch (rotation_) {
364 case display::Display::ROTATE_0:
365 break;
366
367 case display::Display::ROTATE_90:
368 hotspot += gfx::Vector2d(bitmap->height(), 0);
369 break;
370
371 case display::Display::ROTATE_180:
372 hotspot += gfx::Vector2d(bitmap->width(), bitmap->height());
373 break;
374
375 case display::Display::ROTATE_270:
376 hotspot += gfx::Vector2d(0, bitmap->width());
377 break;
378 }
379
357 ui::PlatformCursor platform_cursor; 380 ui::PlatformCursor platform_cursor;
358 #if defined(USE_OZONE) 381 #if defined(USE_OZONE)
359 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers 382 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers
360 // and use that here instead of the current bitmap API. crbug.com/686600 383 // and use that here instead of the current bitmap API. crbug.com/686600
361 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( 384 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor(
362 *bitmap.get(), hotspot); 385 *bitmap.get(), hotspot);
363 #elif defined(USE_X11) 386 #elif defined(USE_X11)
364 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); 387 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot);
365 platform_cursor = ui::CreateReffedCustomXCursor(image); 388 platform_cursor = ui::CreateReffedCustomXCursor(image);
366 #endif 389 #endif
(...skipping 15 matching lines...) Expand all
382 if (auto* cursor_client = 405 if (auto* cursor_client =
383 aura::client::GetCursorClient(focus_->window()->GetRootWindow())) { 406 aura::client::GetCursorClient(focus_->window()->GetRootWindow())) {
384 cursor_client->SetCursor(cursor); 407 cursor_client->SetCursor(cursor);
385 408
386 if (force && cursor_client->IsCursorLocked()) 409 if (force && cursor_client->IsCursorLocked())
387 WMHelper::GetInstance()->SetCursor(cursor); 410 WMHelper::GetInstance()->SetCursor(cursor);
388 } 411 }
389 } 412 }
390 413
391 } // namespace exo 414 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | ui/display/display.h » ('j') | ui/display/display.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698