OLD | NEW |
---|---|
(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" | |
7 #include "base/single_thread_task_runner.h" | |
8 #include "ui/platform_window/platform_window.h" | |
9 | |
10 namespace ui { | |
11 namespace ws { | |
12 | |
13 ThreadedImageCursors::ThreadedImageCursors( | |
14 scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | |
15 : task_runner_(task_runner), weak_ptr_factory_(this) { | |
16 DCHECK(task_runner_); | |
17 } | |
18 | |
19 ThreadedImageCursors::~ThreadedImageCursors() {} | |
20 | |
21 void ThreadedImageCursors::SetDisplay(const display::Display& display, | |
22 float scale_factor) { | |
23 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.
| |
24 task_runner_->PostTask( | |
25 FROM_HERE, | |
26 base::Bind(&ThreadedImageCursors::SetDisplaySync, | |
27 weak_ptr_factory_.GetWeakPtr(), display, scale_factor)); | |
28 } else { | |
29 SetDisplaySync(display, scale_factor); | |
30 } | |
31 } | |
32 | |
33 void ThreadedImageCursors::SetCursor(ui::CursorType cursor_type, | |
34 ui::PlatformWindow* platform_window) { | |
35 if (task_runner_) { | |
36 task_runner_->PostTask( | |
37 FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorSync, | |
38 weak_ptr_factory_.GetWeakPtr(), cursor_type, | |
39 platform_window)); | |
40 } else { | |
41 SetCursorSync(cursor_type, platform_window); | |
42 } | |
43 } | |
44 | |
45 void ThreadedImageCursors::SetDisplaySync(const display::Display& display, | |
46 float scale_factor) { | |
47 image_cursors_.SetDisplay(display, scale_factor); | |
48 } | |
49 | |
50 void ThreadedImageCursors::SetCursorSync(ui::CursorType cursor_type, | |
51 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
| |
52 ui::Cursor native_cursor(cursor_type); | |
53 image_cursors_.SetPlatformCursor(&native_cursor); | |
54 platform_window->SetCursor(native_cursor.platform()); | |
55 } | |
56 | |
57 } // namesapce ws | |
58 } // namesapce ui | |
OLD | NEW |