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 |
index 0b51b2e0ab6f40585745b7ae3a3e2cc88a4da63c..9736213d3147181770859d86c32f1c465a0af476 100644 |
--- a/services/ui/ws/threaded_image_cursors.cc |
+++ b/services/ui/ws/threaded_image_cursors.cc |
@@ -6,26 +6,38 @@ |
#include "base/bind.h" |
#include "base/single_thread_task_runner.h" |
#include "base/threading/thread_task_runner_handle.h" |
+#include "ui/ozone/public/cursor_factory_ozone.h" |
#include "ui/platform_window/platform_window.h" |
namespace ui { |
namespace ws { |
namespace { |
+void TakeOwnershipOnResourceThread( |
+ base::WeakPtr<ui::ImageCursorsHolder> image_cursors_holder_weak_ptr, |
+ std::unique_ptr<ui::ImageCursors> image_cursors) { |
+ if (image_cursors_holder_weak_ptr) |
+ image_cursors_holder_weak_ptr->SetImageCursors(std::move(image_cursors)); |
+} |
+ |
// Executed on |resource_task_runner_|. |
void SetDisplayOnResourceThread( |
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr, |
+ base::WeakPtr<ui::ImageCursorsHolder> image_cursors_holder_weak_ptr, |
const display::Display& display, |
float scale_factor) { |
- if (image_cursors_weak_ptr) |
- image_cursors_weak_ptr->SetDisplay(display, scale_factor); |
+ if (image_cursors_holder_weak_ptr) { |
+ image_cursors_holder_weak_ptr->GetImageCursors()->SetDisplay(display, |
+ scale_factor); |
+ } |
} |
void SetCursorSizeOnResourceThread( |
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr, |
+ base::WeakPtr<ui::ImageCursorsHolder> image_cursors_holder_weak_ptr, |
CursorSize cursor_size) { |
- if (image_cursors_weak_ptr) |
- image_cursors_weak_ptr->SetCursorSize(cursor_size); |
+ if (image_cursors_holder_weak_ptr) { |
+ image_cursors_holder_weak_ptr->GetImageCursors()->SetCursorSize( |
+ cursor_size); |
+ } |
} |
// Executed on |resource_task_runner_|. Sets cursor type on |
@@ -34,14 +46,15 @@ void SetCursorSizeOnResourceThread( |
// |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, |
+ base::WeakPtr<ui::ImageCursorsHolder> image_cursors_holder_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) { |
+ if (image_cursors_holder_weak_ptr) { |
ui::Cursor native_cursor(cursor_type); |
- image_cursors_weak_ptr->SetPlatformCursor(&native_cursor); |
+ image_cursors_holder_weak_ptr->GetImageCursors()->SetPlatformCursor( |
+ &native_cursor); |
ws_task_runner->PostTask( |
FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorOnPlatformWindow, |
threaded_image_cursors_weak_ptr, |
@@ -53,12 +66,19 @@ void SetCursorOnResourceThread( |
ThreadedImageCursors::ThreadedImageCursors( |
scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner, |
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr) |
+ base::WeakPtr<ui::ImageCursorsHolder> image_cursors_holder_weak_ptr) |
: resource_task_runner_(resource_task_runner), |
- image_cursors_weak_ptr_(image_cursors_weak_ptr), |
+ image_cursors_holder_weak_ptr_(image_cursors_holder_weak_ptr), |
weak_ptr_factory_(this) { |
DCHECK(resource_task_runner_); |
ws_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
+ std::unique_ptr<ui::ImageCursors> image_cursors = |
+ base::MakeUnique<ui::ImageCursors>(); |
+ image_cursors->Initialize(); |
+ resource_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&TakeOwnershipOnResourceThread, image_cursors_holder_weak_ptr_, |
+ base::Passed(std::move(image_cursors)))); |
} |
ThreadedImageCursors::~ThreadedImageCursors() {} |
@@ -66,22 +86,24 @@ 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)); |
+ FROM_HERE, |
+ base::Bind(&SetDisplayOnResourceThread, image_cursors_holder_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)); |
+ image_cursors_holder_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())); |
+ FROM_HERE, |
+ base::Bind(&SetCursorOnResourceThread, image_cursors_holder_weak_ptr_, |
+ cursor_type, platform_window, ws_task_runner_, |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
void ThreadedImageCursors::SetCursorOnPlatformWindow( |