Index: services/ui/ws/threaded_image_cursors.cc |
diff --git a/services/ui/ws/threaded_image_cursors.cc b/services/ui/ws/threaded_image_cursors.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3f1fb3715d304f2ad2c6417d809dc473498c69e3 |
--- /dev/null |
+++ b/services/ui/ws/threaded_image_cursors.cc |
@@ -0,0 +1,58 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/ui/ws/threaded_image_cursors.h" |
+#include "base/bind.h" |
+#include "base/single_thread_task_runner.h" |
+#include "ui/platform_window/platform_window.h" |
+ |
+namespace ui { |
+namespace ws { |
+ |
+ThreadedImageCursors::ThreadedImageCursors( |
+ scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
+ : task_runner_(task_runner), weak_ptr_factory_(this) { |
+ DCHECK(task_runner_); |
+} |
+ |
+ThreadedImageCursors::~ThreadedImageCursors() {} |
+ |
+void ThreadedImageCursors::SetDisplay(const display::Display& display, |
+ float scale_factor) { |
+ if (task_runner_) { |
sky
2017/06/20 22:33:13
WDYT of *always* using a task runner? I realize it
mfomitchev
2017/06/21 21:22:51
Done.
|
+ task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadedImageCursors::SetDisplaySync, |
+ weak_ptr_factory_.GetWeakPtr(), display, scale_factor)); |
+ } else { |
+ SetDisplaySync(display, scale_factor); |
+ } |
+} |
+ |
+void ThreadedImageCursors::SetCursor(ui::CursorType cursor_type, |
+ ui::PlatformWindow* platform_window) { |
+ if (task_runner_) { |
+ task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorSync, |
+ weak_ptr_factory_.GetWeakPtr(), cursor_type, |
+ platform_window)); |
+ } else { |
+ SetCursorSync(cursor_type, platform_window); |
+ } |
+} |
+ |
+void ThreadedImageCursors::SetDisplaySync(const display::Display& display, |
+ float scale_factor) { |
+ image_cursors_.SetDisplay(display, scale_factor); |
+} |
+ |
+void ThreadedImageCursors::SetCursorSync(ui::CursorType cursor_type, |
+ ui::PlatformWindow* platform_window) { |
sky
2017/06/20 22:33:13
How do you know platformwindow is still valid by t
mfomitchev
2017/06/21 21:22:51
Sigh.
Ok, so platform_window_ will outlive Thread
|
+ ui::Cursor native_cursor(cursor_type); |
+ image_cursors_.SetPlatformCursor(&native_cursor); |
+ platform_window->SetCursor(native_cursor.platform()); |
+} |
+ |
+} // namesapce ws |
+} // namesapce ui |