| 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 "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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Reparent the cursor to the root window where the mouse is located. | 274 // Reparent the cursor to the root window where the mouse is located. |
| 275 if (container->GetRootWindow() != cursor_->GetRootWindow()) { | 275 if (container->GetRootWindow() != cursor_->GetRootWindow()) { |
| 276 if (cursor_->parent()) | 276 if (cursor_->parent()) |
| 277 cursor_->parent()->RemoveChild(cursor_.get()); | 277 cursor_->parent()->RemoveChild(cursor_.get()); |
| 278 container->AddChild(cursor_.get()); | 278 container->AddChild(cursor_.get()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 auto info = helper->GetDisplayInfo(display.id()); | 281 auto info = helper->GetDisplayInfo(display.id()); |
| 282 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor(); | 282 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor(); |
| 283 device_scale_factor_ = display.device_scale_factor(); | 283 device_scale_factor_ = display.device_scale_factor(); |
| 284 rotation_ = display.rotation(); |
| 284 | 285 |
| 285 if (focus_ && surface_) | 286 if (focus_ && surface_) |
| 286 CaptureCursor(); | 287 CaptureCursor(); |
| 287 } | 288 } |
| 288 | 289 |
| 289 //////////////////////////////////////////////////////////////////////////////// | 290 //////////////////////////////////////////////////////////////////////////////// |
| 290 // SurfaceDelegate overrides: | 291 // SurfaceDelegate overrides: |
| 291 | 292 |
| 292 void Pointer::OnSurfaceCommit() { | 293 void Pointer::OnSurfaceCommit() { |
| 293 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 294 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 330 |
| 330 void Pointer::CaptureCursor() { | 331 void Pointer::CaptureCursor() { |
| 331 DCHECK(surface_); | 332 DCHECK(surface_); |
| 332 DCHECK(focus_); | 333 DCHECK(focus_); |
| 333 | 334 |
| 334 float scale = cursor_scale_ * display_scale_; | 335 float scale = cursor_scale_ * display_scale_; |
| 335 float layer_scale = scale / device_scale_factor_; | 336 float layer_scale = scale / device_scale_factor_; |
| 336 | 337 |
| 337 gfx::Transform transform; | 338 gfx::Transform transform; |
| 338 transform.Scale(layer_scale, layer_scale); | 339 transform.Scale(layer_scale, layer_scale); |
| 340 transform.Rotate(display::Display::RotateToDegree(rotation_)); |
| 339 surface_->window()->SetTransform(transform); | 341 surface_->window()->SetTransform(transform); |
| 340 | 342 |
| 343 gfx::Point hotspot = hotspot_; |
| 344 aura::Window::ConvertPointToTarget(surface_->window(), cursor_.get(), |
| 345 &hotspot); |
| 346 |
| 341 std::unique_ptr<cc::CopyOutputRequest> request = | 347 std::unique_ptr<cc::CopyOutputRequest> request = |
| 342 cc::CopyOutputRequest::CreateBitmapRequest( | 348 cc::CopyOutputRequest::CreateBitmapRequest( |
| 343 base::Bind(&Pointer::OnCursorCaptured, | 349 base::Bind(&Pointer::OnCursorCaptured, |
| 344 cursor_capture_weak_ptr_factory_.GetWeakPtr(), | 350 cursor_capture_weak_ptr_factory_.GetWeakPtr(), |
| 345 gfx::ScaleToFlooredPoint(hotspot_, scale))); | 351 gfx::ScaleToFlooredPoint(hotspot, scale))); |
| 346 | 352 |
| 347 request->set_source(cursor_capture_source_id_); | 353 request->set_source(cursor_capture_source_id_); |
| 348 cursor_->layer()->RequestCopyOfOutput(std::move(request)); | 354 cursor_->layer()->RequestCopyOfOutput(std::move(request)); |
| 349 } | 355 } |
| 350 | 356 |
| 351 void Pointer::OnCursorCaptured(const gfx::Point& hotspot, | 357 void Pointer::OnCursorCaptured(gfx::Point hotspot, |
| 352 std::unique_ptr<cc::CopyOutputResult> result) { | 358 std::unique_ptr<cc::CopyOutputResult> result) { |
| 353 if (!focus_) | 359 if (!focus_) |
| 354 return; | 360 return; |
| 355 | 361 |
| 356 gfx::NativeCursor cursor = ui::CursorType::kNull; | 362 gfx::NativeCursor cursor = ui::CursorType::kNull; |
| 357 if (!result->IsEmpty()) { | 363 if (!result->IsEmpty()) { |
| 358 DCHECK(result->HasBitmap()); | 364 DCHECK(result->HasBitmap()); |
| 359 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 365 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
| 360 | 366 |
| 367 switch (rotation_) { |
| 368 case display::Display::ROTATE_0: |
| 369 break; |
| 370 |
| 371 case display::Display::ROTATE_90: |
| 372 hotspot += gfx::Vector2d(bitmap->height(), 0); |
| 373 break; |
| 374 |
| 375 case display::Display::ROTATE_180: |
| 376 hotspot += gfx::Vector2d(bitmap->width(), bitmap->height()); |
| 377 break; |
| 378 |
| 379 case display::Display::ROTATE_270: |
| 380 hotspot += gfx::Vector2d(0, bitmap->width()); |
| 381 break; |
| 382 } |
| 383 |
| 361 ui::PlatformCursor platform_cursor; | 384 ui::PlatformCursor platform_cursor; |
| 362 #if defined(USE_OZONE) | 385 #if defined(USE_OZONE) |
| 363 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers | 386 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers |
| 364 // and use that here instead of the current bitmap API. crbug.com/686600 | 387 // and use that here instead of the current bitmap API. crbug.com/686600 |
| 365 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( | 388 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( |
| 366 *bitmap.get(), hotspot, cursor_scale_); | 389 *bitmap.get(), hotspot, cursor_scale_); |
| 367 #elif defined(USE_X11) | 390 #elif defined(USE_X11) |
| 368 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); | 391 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); |
| 369 platform_cursor = ui::CreateReffedCustomXCursor(image); | 392 platform_cursor = ui::CreateReffedCustomXCursor(image); |
| 370 #endif | 393 #endif |
| (...skipping 16 matching lines...) Expand all Loading... |
| 387 if (!root_window) | 410 if (!root_window) |
| 388 return; | 411 return; |
| 389 | 412 |
| 390 aura::client::CursorClient* cursor_client = | 413 aura::client::CursorClient* cursor_client = |
| 391 aura::client::GetCursorClient(root_window); | 414 aura::client::GetCursorClient(root_window); |
| 392 if (cursor_client) | 415 if (cursor_client) |
| 393 cursor_client->SetCursor(cursor); | 416 cursor_client->SetCursor(cursor); |
| 394 } | 417 } |
| 395 | 418 |
| 396 } // namespace exo | 419 } // namespace exo |
| OLD | NEW |