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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #include "services/ui/ws/threaded_image_cursors.h"
6 #include "base/bind.h"
sky 2017/06/27 19:58:57 newline between 5 and 6.
mfomitchev 2017/07/11 21:47:00 Done.
7 #include "base/single_thread_task_runner.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "ui/platform_window/platform_window.h"
10
11 namespace ui {
12 namespace ws {
13 namespace {
14
15 // Executed on |resource_task_runner_|.
16 void SetDisplayOnResourceThread(
17 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
18 const display::Display& display,
19 float scale_factor) {
20 if (image_cursors_weak_ptr)
21 image_cursors_weak_ptr->SetDisplay(display, scale_factor);
22 }
23
24 void SetCursorSizeOnResourceThread(
25 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
26 CursorSize cursor_size) {
27 if (image_cursors_weak_ptr)
28 image_cursors_weak_ptr->SetCursorSize(cursor_size);
29 }
30
31 // Executed on |resource_task_runner_|. Sets cursor type on
32 // |image_cursors_weak_ptr|, and then schedules a task on |ws_task_runner| to
33 // set the corresponding PlatformCursor on the provided |platform_window|.
34 // |platform_window| pointer needs to be valid while
35 // |threaded_image_cursors_weak_ptr| is not invalidated.
36 void SetCursorOnResourceThread(
37 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
38 ui::CursorType cursor_type,
39 ui::PlatformWindow* platform_window,
40 scoped_refptr<base::SingleThreadTaskRunner> ws_task_runner,
41 base::WeakPtr<ThreadedImageCursors> threaded_image_cursors_weak_ptr) {
42 if (image_cursors_weak_ptr) {
43 ui::Cursor native_cursor(cursor_type);
44 image_cursors_weak_ptr->SetPlatformCursor(&native_cursor);
45 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.
46 FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorOnPlatformWindow,
47 threaded_image_cursors_weak_ptr,
48 native_cursor.platform(), platform_window));
49 }
50 }
51
52 } // namespace
53
54 ThreadedImageCursors::ThreadedImageCursors(
55 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner,
56 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr)
57 : resource_task_runner_(resource_task_runner),
58 image_cursors_weak_ptr_(image_cursors_weak_ptr),
59 weak_ptr_factory_(this) {
60 DCHECK(resource_task_runner_);
61 ws_task_runner_ = base::ThreadTaskRunnerHandle::Get();
62 }
63
64 ThreadedImageCursors::~ThreadedImageCursors() {}
65
66 void ThreadedImageCursors::SetDisplay(const display::Display& display,
67 float scale_factor) {
68 resource_task_runner_->PostTask(
69 FROM_HERE, base::Bind(&SetDisplayOnResourceThread,
70 image_cursors_weak_ptr_, display, scale_factor));
71 }
72
73 void ThreadedImageCursors::SetCursorSize(CursorSize cursor_size) {
74 resource_task_runner_->PostTask(
75 FROM_HERE, base::Bind(&SetCursorSizeOnResourceThread,
76 image_cursors_weak_ptr_, cursor_size));
77 }
78
79 void ThreadedImageCursors::SetCursor(ui::CursorType cursor_type,
80 ui::PlatformWindow* platform_window) {
81 resource_task_runner_->PostTask(
82 FROM_HERE, base::Bind(&SetCursorOnResourceThread, image_cursors_weak_ptr_,
83 cursor_type, platform_window, ws_task_runner_,
84 weak_ptr_factory_.GetWeakPtr()));
85 }
86
87 void ThreadedImageCursors::SetCursorOnPlatformWindow(
88 ui::PlatformCursor platform_cursor,
89 ui::PlatformWindow* platform_window) {
90 platform_window->SetCursor(platform_cursor);
91 }
92
93 } // namespace ws
94 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698