| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/drm/cursor_proxy_mojo.h" | 5 #include "ui/ozone/platform/drm/cursor_proxy_mojo.h" |
| 6 | 6 |
| 7 #include "services/service_manager/public/cpp/connector.h" | 7 #include "services/service_manager/public/cpp/connector.h" |
| 8 #include "services/ui/public/interfaces/constants.mojom.h" | 8 #include "services/ui/public/interfaces/constants.mojom.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| 11 | 11 |
| 12 // We assume that this is invoked only on the UI thread. |
| 12 CursorProxyMojo::CursorProxyMojo(service_manager::Connector* connector) | 13 CursorProxyMojo::CursorProxyMojo(service_manager::Connector* connector) |
| 13 : connector_(connector->Clone()) { | 14 : connector_(connector->Clone()) { |
| 15 ui_thread_ref_ = base::PlatformThread::CurrentRef(); |
| 14 connector->BindInterface(ui::mojom::kServiceName, &main_cursor_ptr_); | 16 connector->BindInterface(ui::mojom::kServiceName, &main_cursor_ptr_); |
| 15 } | 17 } |
| 16 | 18 |
| 17 void CursorProxyMojo::InitializeOnEvdev() { | |
| 18 evdev_ref_ = base::PlatformThread::CurrentRef(); | |
| 19 connector_->BindInterface(ui::mojom::kServiceName, &evdev_cursor_ptr_); | |
| 20 } | |
| 21 | |
| 22 CursorProxyMojo::~CursorProxyMojo() {} | 19 CursorProxyMojo::~CursorProxyMojo() {} |
| 23 | 20 |
| 24 void CursorProxyMojo::CursorSet(gfx::AcceleratedWidget widget, | 21 void CursorProxyMojo::CursorSet(gfx::AcceleratedWidget widget, |
| 25 const std::vector<SkBitmap>& bitmaps, | 22 const std::vector<SkBitmap>& bitmaps, |
| 26 const gfx::Point& location, | 23 const gfx::Point& location, |
| 27 int frame_delay_ms) { | 24 int frame_delay_ms) { |
| 28 if (evdev_ref_ == base::PlatformThread::CurrentRef()) { | 25 InitializeOnEvdevIfNecessary(); |
| 26 if (ui_thread_ref_ == base::PlatformThread::CurrentRef()) { |
| 27 main_cursor_ptr_->SetCursor(widget, bitmaps, location, frame_delay_ms); |
| 28 } else { |
| 29 evdev_cursor_ptr_->SetCursor(widget, bitmaps, location, frame_delay_ms); | 29 evdev_cursor_ptr_->SetCursor(widget, bitmaps, location, frame_delay_ms); |
| 30 } else { | |
| 31 main_cursor_ptr_->SetCursor(widget, bitmaps, location, frame_delay_ms); | |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 | 32 |
| 35 void CursorProxyMojo::Move(gfx::AcceleratedWidget widget, | 33 void CursorProxyMojo::Move(gfx::AcceleratedWidget widget, |
| 36 const gfx::Point& location) { | 34 const gfx::Point& location) { |
| 37 if (evdev_ref_ == base::PlatformThread::CurrentRef()) { | 35 InitializeOnEvdevIfNecessary(); |
| 36 if (ui_thread_ref_ == base::PlatformThread::CurrentRef()) { |
| 37 main_cursor_ptr_->MoveCursor(widget, location); |
| 38 } else { |
| 38 evdev_cursor_ptr_->MoveCursor(widget, location); | 39 evdev_cursor_ptr_->MoveCursor(widget, location); |
| 39 } else { | |
| 40 main_cursor_ptr_->MoveCursor(widget, location); | |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 | 42 |
| 43 // Evdev runs this method on starting. But if a CursorProxyMojo is created long |
| 44 // after Evdev has started (e.g. if the Viz process crashes (and the |
| 45 // |CursorProxyMojo| self-destructs and then a new |CursorProxyMojo| is built |
| 46 // when the GpuThread/DrmThread pair are once again running), we need to run it |
| 47 // on cursor motions. |
| 48 void CursorProxyMojo::InitializeOnEvdevIfNecessary() { |
| 49 if (ui_thread_ref_ != base::PlatformThread::CurrentRef()) { |
| 50 connector_->BindInterface(ui::mojom::kServiceName, &evdev_cursor_ptr_); |
| 51 } |
| 52 } |
| 53 |
| 44 } // namespace ui | 54 } // namespace ui |
| OLD | NEW |