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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Reparent the cursor to the root window where the mouse is located. | 258 // Reparent the cursor to the root window where the mouse is located. |
259 if (container->GetRootWindow() != cursor_->GetRootWindow()) { | 259 if (container->GetRootWindow() != cursor_->GetRootWindow()) { |
260 if (cursor_->parent()) | 260 if (cursor_->parent()) |
261 cursor_->parent()->RemoveChild(cursor_.get()); | 261 cursor_->parent()->RemoveChild(cursor_.get()); |
262 container->AddChild(cursor_.get()); | 262 container->AddChild(cursor_.get()); |
263 } | 263 } |
264 | 264 |
265 auto info = helper->GetDisplayInfo(display.id()); | 265 auto info = helper->GetDisplayInfo(display.id()); |
266 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor(); | 266 display_scale_ = info.GetEffectiveUIScale() * info.device_scale_factor(); |
267 device_scale_factor_ = display.device_scale_factor(); | 267 device_scale_factor_ = display.device_scale_factor(); |
| 268 rotation_ = display.rotation(); |
268 | 269 |
269 if (focus_ && surface_) { | 270 if (focus_ && surface_) { |
270 // Capture is asynchronous, so avoid rendering old cursor in the meantime. | 271 // Capture is asynchronous, so avoid rendering old cursor in the meantime. |
271 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs(); | 272 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs(); |
272 UpdateCursor(ui::CursorType::kNone); | 273 UpdateCursor(ui::CursorType::kNone); |
273 CaptureCursor(); | 274 CaptureCursor(); |
274 } | 275 } |
275 } | 276 } |
276 | 277 |
277 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 318 |
318 void Pointer::CaptureCursor() { | 319 void Pointer::CaptureCursor() { |
319 DCHECK(surface_); | 320 DCHECK(surface_); |
320 DCHECK(focus_); | 321 DCHECK(focus_); |
321 | 322 |
322 float scale = cursor_scale_ * display_scale_; | 323 float scale = cursor_scale_ * display_scale_; |
323 float layer_scale = scale / device_scale_factor_; | 324 float layer_scale = scale / device_scale_factor_; |
324 | 325 |
325 gfx::Transform transform; | 326 gfx::Transform transform; |
326 transform.Scale(layer_scale, layer_scale); | 327 transform.Scale(layer_scale, layer_scale); |
| 328 transform.Rotate(display::Display::RotateToDegree(rotation_)); |
327 surface_->window()->SetTransform(transform); | 329 surface_->window()->SetTransform(transform); |
328 | 330 |
| 331 gfx::Point hotspot = hotspot_; |
| 332 aura::Window::ConvertPointToTarget(surface_->window(), cursor_.get(), |
| 333 &hotspot); |
| 334 |
329 std::unique_ptr<cc::CopyOutputRequest> request = | 335 std::unique_ptr<cc::CopyOutputRequest> request = |
330 cc::CopyOutputRequest::CreateBitmapRequest( | 336 cc::CopyOutputRequest::CreateBitmapRequest( |
331 base::Bind(&Pointer::OnCursorCaptured, | 337 base::Bind(&Pointer::OnCursorCaptured, |
332 cursor_capture_weak_ptr_factory_.GetWeakPtr(), | 338 cursor_capture_weak_ptr_factory_.GetWeakPtr(), |
333 gfx::ScaleToFlooredPoint(hotspot_, scale))); | 339 gfx::ScaleToFlooredPoint(hotspot, scale))); |
334 | 340 |
335 request->set_source(cursor_capture_source_id_); | 341 request->set_source(cursor_capture_source_id_); |
336 cursor_->layer()->RequestCopyOfOutput(std::move(request)); | 342 cursor_->layer()->RequestCopyOfOutput(std::move(request)); |
337 } | 343 } |
338 | 344 |
339 void Pointer::OnCursorCaptured(const gfx::Point& hotspot, | 345 void Pointer::OnCursorCaptured(gfx::Point hotspot, |
340 std::unique_ptr<cc::CopyOutputResult> result) { | 346 std::unique_ptr<cc::CopyOutputResult> result) { |
341 if (!focus_) | 347 if (!focus_) |
342 return; | 348 return; |
343 | 349 |
344 gfx::NativeCursor cursor = ui::CursorType::kNull; | 350 gfx::NativeCursor cursor = ui::CursorType::kNull; |
345 if (!result->IsEmpty()) { | 351 if (!result->IsEmpty()) { |
346 DCHECK(result->HasBitmap()); | 352 DCHECK(result->HasBitmap()); |
347 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 353 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
348 | 354 |
| 355 switch (rotation_) { |
| 356 case display::Display::ROTATE_0: |
| 357 break; |
| 358 |
| 359 case display::Display::ROTATE_90: |
| 360 hotspot += gfx::Vector2d(bitmap->height(), 0); |
| 361 break; |
| 362 |
| 363 case display::Display::ROTATE_180: |
| 364 hotspot += gfx::Vector2d(bitmap->width(), bitmap->height()); |
| 365 break; |
| 366 |
| 367 case display::Display::ROTATE_270: |
| 368 hotspot += gfx::Vector2d(0, bitmap->width()); |
| 369 break; |
| 370 } |
| 371 |
349 ui::PlatformCursor platform_cursor; | 372 ui::PlatformCursor platform_cursor; |
350 #if defined(USE_OZONE) | 373 #if defined(USE_OZONE) |
351 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers | 374 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers |
352 // and use that here instead of the current bitmap API. crbug.com/686600 | 375 // and use that here instead of the current bitmap API. crbug.com/686600 |
353 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( | 376 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( |
354 *bitmap.get(), hotspot, cursor_scale_); | 377 *bitmap.get(), hotspot, cursor_scale_); |
355 #elif defined(USE_X11) | 378 #elif defined(USE_X11) |
356 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); | 379 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); |
357 platform_cursor = ui::CreateReffedCustomXCursor(image); | 380 platform_cursor = ui::CreateReffedCustomXCursor(image); |
358 #endif | 381 #endif |
(...skipping 16 matching lines...) Expand all Loading... |
375 if (!root_window) | 398 if (!root_window) |
376 return; | 399 return; |
377 | 400 |
378 aura::client::CursorClient* cursor_client = | 401 aura::client::CursorClient* cursor_client = |
379 aura::client::GetCursorClient(root_window); | 402 aura::client::GetCursorClient(root_window); |
380 if (cursor_client) | 403 if (cursor_client) |
381 cursor_client->SetCursor(cursor); | 404 cursor_client->SetCursor(cursor); |
382 } | 405 } |
383 | 406 |
384 } // namespace exo | 407 } // namespace exo |
OLD | NEW |