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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h"
7 #include "ui/gfx/geometry/point_conversions.h"
8 #include "ui/ozone/platform/dri/dri_surface_factory.h"
9 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h"
13 CursorFactoryEvdevDri::CursorFactoryEvdevDri(HardwareCursorDelegate* hardware)
14 : hardware_(hardware) {
15 // TODO(dnicoara) Assume the first widget since at this point there are no
16 // widgets initialized.
17 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle;
18 cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh!
21 CursorFactoryEvdevDri::~CursorFactoryEvdevDri() {}
23 void CursorFactoryEvdevDri::SetBitmapCursor(
24 gfx::AcceleratedWidget widget,
25 scoped_refptr<BitmapCursorOzone> cursor) {
26 if (cursor_ == cursor)
31 hardware_->SetHardwareCursor(
32 cursor_window_, cursor_->bitmap(), bitmap_location());
34 hardware_->SetHardwareCursor(cursor_window_, SkBitmap(), gfx::Point());
37 void CursorFactoryEvdevDri::MoveCursorTo(gfx::AcceleratedWidget widget,
38 const gfx::PointF& location) {
39 if (widget != cursor_window_)
40 hardware_->SetHardwareCursor(cursor_window_, SkBitmap(), gfx::Point());
42 cursor_window_ = widget;
43 cursor_location_ = location;
45 gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix.
46 cursor_location_.SetToMax(gfx::PointF(0, 0));
47 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height()));
50 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location());
53 void CursorFactoryEvdevDri::MoveCursor(const gfx::Vector2dF& delta) {
54 MoveCursorTo(cursor_window_, cursor_location_ + delta);
57 gfx::AcceleratedWidget CursorFactoryEvdevDri::GetCursorWindow() {
58 return cursor_window_;
61 gfx::PointF CursorFactoryEvdevDri::location() { return cursor_location_; }
63 gfx::Point CursorFactoryEvdevDri::bitmap_location() {
64 return gfx::ToFlooredPoint(cursor_location_) -
65 cursor_->hotspot().OffsetFromOrigin();