Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Unified Diff: services/ui/ws/threaded_image_cursors.cc

Issue 2916823002: Move Mus into chrome's process when running with --mus.
Patch Set: Undo Screen TLS change, don't use Screen::GetScreen() in Mus. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0b51b2e0ab6f40585745b7ae3a3e2cc88a4da63c
--- /dev/null
+++ b/services/ui/ws/threaded_image_cursors.cc
@@ -0,0 +1,94 @@
+// 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"
sky 2017/06/27 19:58:57 newline between 5 and 6.
mfomitchev 2017/07/11 21:47:00 Done.
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "ui/platform_window/platform_window.h"
+
+namespace ui {
+namespace ws {
+namespace {
+
+// Executed on |resource_task_runner_|.
+void SetDisplayOnResourceThread(
+ base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
+ const display::Display& display,
+ float scale_factor) {
+ if (image_cursors_weak_ptr)
+ image_cursors_weak_ptr->SetDisplay(display, scale_factor);
+}
+
+void SetCursorSizeOnResourceThread(
+ base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
+ CursorSize cursor_size) {
+ if (image_cursors_weak_ptr)
+ image_cursors_weak_ptr->SetCursorSize(cursor_size);
+}
+
+// Executed on |resource_task_runner_|. Sets cursor type on
+// |image_cursors_weak_ptr|, and then schedules a task on |ws_task_runner| to
+// set the corresponding PlatformCursor on the provided |platform_window|.
+// |platform_window| pointer needs to be valid while
+// |threaded_image_cursors_weak_ptr| is not invalidated.
+void SetCursorOnResourceThread(
+ base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
+ ui::CursorType cursor_type,
+ ui::PlatformWindow* platform_window,
+ scoped_refptr<base::SingleThreadTaskRunner> ws_task_runner,
+ base::WeakPtr<ThreadedImageCursors> threaded_image_cursors_weak_ptr) {
+ if (image_cursors_weak_ptr) {
+ ui::Cursor native_cursor(cursor_type);
+ image_cursors_weak_ptr->SetPlatformCursor(&native_cursor);
+ ws_task_runner->PostTask(
sky 2017/06/27 19:58:57 It's worth a comment as to why you process setting
mfomitchev 2017/07/11 21:47:00 Done.
+ FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorOnPlatformWindow,
+ threaded_image_cursors_weak_ptr,
+ native_cursor.platform(), platform_window));
+ }
+}
+
+} // namespace
+
+ThreadedImageCursors::ThreadedImageCursors(
+ scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner,
+ base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr)
+ : resource_task_runner_(resource_task_runner),
+ image_cursors_weak_ptr_(image_cursors_weak_ptr),
+ weak_ptr_factory_(this) {
+ DCHECK(resource_task_runner_);
+ ws_task_runner_ = base::ThreadTaskRunnerHandle::Get();
+}
+
+ThreadedImageCursors::~ThreadedImageCursors() {}
+
+void ThreadedImageCursors::SetDisplay(const display::Display& display,
+ float scale_factor) {
+ resource_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&SetDisplayOnResourceThread,
+ image_cursors_weak_ptr_, display, scale_factor));
+}
+
+void ThreadedImageCursors::SetCursorSize(CursorSize cursor_size) {
+ resource_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&SetCursorSizeOnResourceThread,
+ image_cursors_weak_ptr_, cursor_size));
+}
+
+void ThreadedImageCursors::SetCursor(ui::CursorType cursor_type,
+ ui::PlatformWindow* platform_window) {
+ resource_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&SetCursorOnResourceThread, image_cursors_weak_ptr_,
+ cursor_type, platform_window, ws_task_runner_,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ThreadedImageCursors::SetCursorOnPlatformWindow(
+ ui::PlatformCursor platform_cursor,
+ ui::PlatformWindow* platform_window) {
+ platform_window->SetCursor(platform_cursor);
+}
+
+} // namespace ws
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698