OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/dri_cursor.h" | 5 #include "ui/ozone/platform/dri/dri_cursor.h" |
6 | 6 |
7 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" | 7 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
8 #include "ui/gfx/geometry/point.h" | 8 #include "ui/gfx/geometry/point.h" |
9 #include "ui/gfx/geometry/point_conversions.h" | 9 #include "ui/gfx/geometry/point_conversions.h" |
10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
11 #include "ui/ozone/platform/dri/dri_surface_factory.h" | 11 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
12 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h" | 12 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 DriCursor::DriCursor(HardwareCursorDelegate* hardware) : hardware_(hardware) { | 16 DriCursor::DriCursor(HardwareCursorDelegate* hardware) : hardware_(hardware) { |
17 // TODO(dnicoara) Assume the first widget since at this point there are no | 17 // TODO(dnicoara) Assume the first widget since at this point there are no |
18 // widgets initialized. | 18 // widgets initialized. |
19 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle; | 19 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle; |
20 cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh! | 20 cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh! |
21 } | 21 } |
22 | 22 |
23 DriCursor::~DriCursor() { | 23 DriCursor::~DriCursor() { |
24 } | 24 } |
25 | 25 |
26 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, | 26 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, |
27 PlatformCursor platform_cursor) { | 27 PlatformCursor platform_cursor) { |
28 scoped_refptr<BitmapCursorOzone> cursor = | 28 scoped_refptr<BitmapCursorOzone> cursor = |
29 BitmapCursorFactoryOzone::GetBitmapCursor(platform_cursor); | 29 BitmapCursorFactoryOzone::GetBitmapCursor(platform_cursor); |
30 if (cursor_ == cursor) | 30 if (cursor_ == cursor || cursor_window_ != widget) |
31 return; | 31 return; |
32 | 32 |
33 cursor_ = cursor; | 33 cursor_ = cursor; |
34 if (cursor_.get()) | 34 ShowCursor(); |
| 35 } |
| 36 |
| 37 void DriCursor::ShowCursor() { |
| 38 if (cursor_.get()) |
35 hardware_->SetHardwareCursor(cursor_window_, | 39 hardware_->SetHardwareCursor(cursor_window_, |
36 cursor_->bitmaps(), | 40 cursor_->bitmaps(), |
37 bitmap_location(), | 41 bitmap_location(), |
38 cursor_->frame_delay_ms()); | 42 cursor_->frame_delay_ms()); |
39 else | 43 else |
40 UnsetCursor(cursor_window_); | 44 HideCursor(); |
| 45 } |
| 46 |
| 47 void DriCursor::HideCursor() { |
| 48 hardware_->SetHardwareCursor( |
| 49 cursor_window_, std::vector<SkBitmap>(), gfx::Point(), 0); |
41 } | 50 } |
42 | 51 |
43 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, | 52 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, |
44 const gfx::PointF& location) { | 53 const gfx::PointF& location) { |
45 if (widget != cursor_window_) | 54 if (widget != cursor_window_) |
46 UnsetCursor(cursor_window_); | 55 HideCursor(); |
47 | 56 |
48 cursor_window_ = widget; | 57 cursor_window_ = widget; |
49 cursor_location_ = location; | 58 cursor_location_ = location; |
50 | 59 |
51 gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix. | 60 gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix. |
52 cursor_location_.SetToMax(gfx::PointF(0, 0)); | 61 cursor_location_.SetToMax(gfx::PointF(0, 0)); |
53 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); | 62 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); |
54 | 63 |
55 if (cursor_.get()) | 64 if (cursor_.get()) |
56 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location()); | 65 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location()); |
(...skipping 13 matching lines...) Expand all Loading... |
70 | 79 |
71 gfx::PointF DriCursor::location() { | 80 gfx::PointF DriCursor::location() { |
72 return cursor_location_; | 81 return cursor_location_; |
73 } | 82 } |
74 | 83 |
75 gfx::Point DriCursor::bitmap_location() { | 84 gfx::Point DriCursor::bitmap_location() { |
76 return gfx::ToFlooredPoint(cursor_location_) - | 85 return gfx::ToFlooredPoint(cursor_location_) - |
77 cursor_->hotspot().OffsetFromOrigin(); | 86 cursor_->hotspot().OffsetFromOrigin(); |
78 } | 87 } |
79 | 88 |
80 void DriCursor::UnsetCursor(gfx::AcceleratedWidget widget) { | |
81 hardware_->SetHardwareCursor( | |
82 widget, std::vector<SkBitmap>(), gfx::Point(), 0); | |
83 } | |
84 | |
85 } // namespace ui | 89 } // namespace ui |
OLD | NEW |