Refactor ozone drm cursor code for mojo
Adjust code in ozone drm platform to simplify the introduction of mojo IPC for
cursor control.
BUG=620927
Review-Url: https://codereview.chromium.org/2088533002
Cr-Commit-Position: refs/heads/master@{#401265}
diff --git a/ui/events/ozone/evdev/cursor_delegate_evdev.h b/ui/events/ozone/evdev/cursor_delegate_evdev.h
index bba23d1..6a6820f 100644
--- a/ui/events/ozone/evdev/cursor_delegate_evdev.h
+++ b/ui/events/ozone/evdev/cursor_delegate_evdev.h
@@ -20,20 +20,25 @@
public:
virtual ~CursorDelegateEvdev() {}
- // Move the cursor.
+ // Move the cursor from the Evdev thread.
virtual void MoveCursor(const gfx::Vector2dF& delta) = 0;
+ // Move the cursor from the UI thread only.
virtual void MoveCursorTo(gfx::AcceleratedWidget widget,
const gfx::PointF& location) = 0;
+ // Move the cursor from the UI thread only.
virtual void MoveCursorTo(const gfx::PointF& location) = 0;
- // Location in screen.
+ // Location in screen. Either thread, IPC-free.
virtual gfx::PointF GetLocation() = 0;
- // Cursor visibility.
+ // Cursor visibility. Either thread, IPC-free.
virtual bool IsCursorVisible() = 0;
- // The bounds that the cursor is confined to.
+ // The bounds that the cursor is confined to. Either thread, IPC-free.
virtual gfx::Rect GetCursorConfinedBounds() = 0;
+
+ // Any necessary initialization from Evdev thread.
+ virtual void InitializeOnEvdev() = 0;
};
} // namespace ui
diff --git a/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc b/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
index 856891b..406451f 100644
--- a/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
+++ b/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
@@ -73,7 +73,7 @@
return gfx::Rect();
}
gfx::PointF GetLocation() override { return cursor_location_; }
-
+ void InitializeOnEvdev() override {}
private:
// The location of the mock cursor.
gfx::PointF cursor_location_;
diff --git a/ui/events/ozone/evdev/event_thread_evdev.cc b/ui/events/ozone/evdev/event_thread_evdev.cc
index 4d153c9..5ffe27d9 100644
--- a/ui/events/ozone/evdev/event_thread_evdev.cc
+++ b/ui/events/ozone/evdev/event_thread_evdev.cc
@@ -12,6 +12,7 @@
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
+#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h"
#include "ui/events/ozone/evdev/input_device_factory_evdev.h"
#include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h"
@@ -42,6 +43,8 @@
new InputDeviceFactoryEvdevProxy(base::ThreadTaskRunnerHandle::Get(),
input_device_factory_->GetWeakPtr()));
+ cursor_->InitializeOnEvdev();
+
init_runner_->PostTask(FROM_HERE,
base::Bind(init_callback_, base::Passed(&proxy)));
}
diff --git a/ui/events/ozone/evdev/input_injector_evdev_unittest.cc b/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
index a2fd1b6..fe07e32 100644
--- a/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
+++ b/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
@@ -66,7 +66,7 @@
return gfx::Rect();
}
gfx::PointF GetLocation() override { return cursor_location_; }
-
+ void InitializeOnEvdev() override {}
private:
// The location of the mock cursor.
gfx::PointF cursor_location_;
diff --git a/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc b/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
index 7ec8375..b049287 100644
--- a/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
+++ b/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
@@ -123,7 +123,7 @@
gfx::Rect GetCursorConfinedBounds() override {
return cursor_confined_bounds_;
}
-
+ void InitializeOnEvdev() override {}
private:
gfx::PointF cursor_location_;
gfx::Rect cursor_confined_bounds_;
diff --git a/ui/ozone/platform/drm/gpu/drm_thread.cc b/ui/ozone/platform/drm/gpu/drm_thread.cc
index 6e173b5..995373eb 100644
--- a/ui/ozone/platform/drm/gpu/drm_thread.cc
+++ b/ui/ozone/platform/drm/gpu/drm_thread.cc
@@ -175,7 +175,7 @@
->SetCursor(bitmaps, location, frame_delay_ms);
}
-void DrmThread::MoveCursor(gfx::AcceleratedWidget widget,
+void DrmThread::MoveCursor(const gfx::AcceleratedWidget& widget,
const gfx::Point& location) {
screen_manager_->GetWindow(widget)->MoveCursor(location);
}
diff --git a/ui/ozone/platform/drm/gpu/drm_thread.h b/ui/ozone/platform/drm/gpu/drm_thread.h
index 56e566d..3dcf284 100644
--- a/ui/ozone/platform/drm/gpu/drm_thread.h
+++ b/ui/ozone/platform/drm/gpu/drm_thread.h
@@ -82,7 +82,8 @@
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms);
- void MoveCursor(gfx::AcceleratedWidget widget, const gfx::Point& location);
+ void MoveCursor(const gfx::AcceleratedWidget& widget,
+ const gfx::Point& location);
void CheckOverlayCapabilities(
gfx::AcceleratedWidget widget,
const std::vector<OverlayCheck_Params>& overlays,
diff --git a/ui/ozone/platform/drm/host/drm_cursor.cc b/ui/ozone/platform/drm/host/drm_cursor.cc
index 6ee48c8..0dc9ae5 100644
--- a/ui/ozone/platform/drm/host/drm_cursor.cc
+++ b/ui/ozone/platform/drm/host/drm_cursor.cc
@@ -27,6 +27,7 @@
const gfx::Point& point,
int frame_delay_ms) override {}
void Move(gfx::AcceleratedWidget window, const gfx::Point& point) override {}
+ void InitializeOnEvdev() override {}
private:
DISALLOW_COPY_AND_ASSIGN(NullProxy);
@@ -37,7 +38,9 @@
DrmCursor::DrmCursor(DrmWindowHostManager* window_manager)
: window_(gfx::kNullAcceleratedWidget),
window_manager_(window_manager),
- proxy_(new NullProxy()) {}
+ proxy_(new NullProxy()) {
+ evdev_thread_checker_.DetachFromThread();
+}
DrmCursor::~DrmCursor() {}
@@ -177,6 +180,7 @@
}
void DrmCursor::MoveCursor(const gfx::Vector2dF& delta) {
+ DCHECK(evdev_thread_checker_.CalledOnValidThread());
TRACE_EVENT0("drmcursor", "DrmCursor::MoveCursor");
base::AutoLock lock(lock_);
@@ -210,6 +214,11 @@
return confined_bounds_ + display_bounds_in_screen_.OffsetFromOrigin();
}
+void DrmCursor::InitializeOnEvdev() {
+ DCHECK(evdev_thread_checker_.CalledOnValidThread());
+ proxy_->InitializeOnEvdev();
+}
+
void DrmCursor::SetCursorLocationLocked(const gfx::PointF& location) {
gfx::PointF clamped_location = location;
clamped_location.SetToMax(gfx::PointF(confined_bounds_.origin()));
diff --git a/ui/ozone/platform/drm/host/drm_cursor.h b/ui/ozone/platform/drm/host/drm_cursor.h
index 70b18f3..f8a6bfd 100644
--- a/ui/ozone/platform/drm/host/drm_cursor.h
+++ b/ui/ozone/platform/drm/host/drm_cursor.h
@@ -32,6 +32,9 @@
int frame_delay_ms) = 0;
// Moves the cursor in |window| to |point|
virtual void Move(gfx::AcceleratedWidget window, const gfx::Point& point) = 0;
+
+ // Initialize EvdevThread-specific state.
+ virtual void InitializeOnEvdev() = 0;
};
// DrmCursor manages all cursor state and semantics.
@@ -67,6 +70,7 @@
bool IsCursorVisible() override;
gfx::PointF GetLocation() override;
gfx::Rect GetCursorConfinedBounds() override;
+ void InitializeOnEvdev() override;
private:
void SetCursorLocationLocked(const gfx::PointF& location);
@@ -86,6 +90,7 @@
// Enforce our threading constraints.
base::ThreadChecker thread_checker_;
+ base::ThreadChecker evdev_thread_checker_;
// The location of the bitmap (the cursor location is the hotspot location).
gfx::Point GetBitmapLocationLocked();
diff --git a/ui/ozone/platform/drm/host/drm_gpu_platform_support_host.cc b/ui/ozone/platform/drm/host/drm_gpu_platform_support_host.cc
index 9f42ec2..eba9b9a 100644
--- a/ui/ozone/platform/drm/host/drm_gpu_platform_support_host.cc
+++ b/ui/ozone/platform/drm/host/drm_gpu_platform_support_host.cc
@@ -33,6 +33,7 @@
const gfx::Point& point,
int frame_delay_ms) override;
void Move(gfx::AcceleratedWidget window, const gfx::Point& point) override;
+ void InitializeOnEvdev() override;
private:
bool IsConnected();
@@ -65,6 +66,8 @@
Send(new OzoneGpuMsg_CursorMove(window, point));
}
+void CursorIPC::InitializeOnEvdev() {}
+
void CursorIPC::Send(IPC::Message* message) {
if (IsConnected() &&
send_runner_->PostTask(FROM_HERE, base::Bind(send_callback_, message)))
diff --git a/ui/ozone/platform/drm/mus_thread_proxy.cc b/ui/ozone/platform/drm/mus_thread_proxy.cc
index 795b084..a331c522 100644
--- a/ui/ozone/platform/drm/mus_thread_proxy.cc
+++ b/ui/ozone/platform/drm/mus_thread_proxy.cc
@@ -20,6 +20,8 @@
drm_thread_(nullptr),
weak_ptr_factory_(this) {}
+void MusThreadProxy::InitializeOnEvdev() {}
+
MusThreadProxy::~MusThreadProxy() {
DCHECK(on_window_server_thread_.CalledOnValidThread());
FOR_EACH_OBSERVER(GpuThreadObserver, gpu_thread_observers_,
diff --git a/ui/ozone/platform/drm/mus_thread_proxy.h b/ui/ozone/platform/drm/mus_thread_proxy.h
index e39eefcb..054f73e 100644
--- a/ui/ozone/platform/drm/mus_thread_proxy.h
+++ b/ui/ozone/platform/drm/mus_thread_proxy.h
@@ -95,6 +95,7 @@
const gfx::Point& point,
int frame_delay_ms) override;
void Move(gfx::AcceleratedWidget window, const gfx::Point& point) override;
+ void InitializeOnEvdev() override;
private:
void RunObservers();