| 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 "services/ui/ws/platform_display_default.h" | 5 #include "services/ui/ws/platform_display_default.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "gpu/ipc/client/gpu_channel_host.h" | 10 #include "gpu/ipc/client/gpu_channel_host.h" |
| 11 #include "services/ui/display/screen_manager.h" | 11 #include "services/ui/display/screen_manager.h" |
| 12 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" | 12 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" |
| 13 #include "services/ui/ws/server_window.h" | 13 #include "services/ui/ws/server_window.h" |
| 14 #include "ui/base/cursor/image_cursors.h" | 14 #include "services/ui/ws/threaded_image_cursors.h" |
| 15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 17 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 18 #include "ui/platform_window/platform_ime_controller.h" | 18 #include "ui/platform_window/platform_ime_controller.h" |
| 19 #include "ui/platform_window/platform_window.h" | 19 #include "ui/platform_window/platform_window.h" |
| 20 | 20 |
| 21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 22 #include "ui/platform_window/win/win_window.h" | 22 #include "ui/platform_window/win/win_window.h" |
| 23 #elif defined(USE_X11) && !defined(OS_CHROMEOS) | 23 #elif defined(USE_X11) && !defined(OS_CHROMEOS) |
| 24 #include "ui/platform_window/x11/x11_window.h" | 24 #include "ui/platform_window/x11/x11_window.h" |
| 25 #elif defined(OS_ANDROID) | 25 #elif defined(OS_ANDROID) |
| 26 #include "ui/platform_window/android/platform_window_android.h" | 26 #include "ui/platform_window/android/platform_window_android.h" |
| 27 #elif defined(USE_OZONE) | 27 #elif defined(USE_OZONE) |
| 28 #include "ui/ozone/public/cursor_factory_ozone.h" | 28 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 29 #include "ui/ozone/public/ozone_platform.h" | 29 #include "ui/ozone/public/ozone_platform.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace ui { | 32 namespace ui { |
| 33 namespace ws { | 33 namespace ws { |
| 34 | 34 |
| 35 PlatformDisplayDefault::PlatformDisplayDefault( | 35 PlatformDisplayDefault::PlatformDisplayDefault( |
| 36 ServerWindow* root_window, | 36 ServerWindow* root_window, |
| 37 const display::ViewportMetrics& metrics, | 37 const display::ViewportMetrics& metrics, |
| 38 std::unique_ptr<ImageCursors> image_cursors) | 38 std::unique_ptr<ThreadedImageCursors> image_cursors) |
| 39 : root_window_(root_window), | 39 : root_window_(root_window), |
| 40 image_cursors_(std::move(image_cursors)), | 40 image_cursors_(std::move(image_cursors)), |
| 41 metrics_(metrics), | 41 metrics_(metrics), |
| 42 widget_(gfx::kNullAcceleratedWidget) {} | 42 widget_(gfx::kNullAcceleratedWidget) {} |
| 43 | 43 |
| 44 PlatformDisplayDefault::~PlatformDisplayDefault() { | 44 PlatformDisplayDefault::~PlatformDisplayDefault() { |
| 45 // Don't notify the delegate from the destructor. | 45 // Don't notify the delegate from the destructor. |
| 46 delegate_ = nullptr; | 46 delegate_ = nullptr; |
| 47 | 47 |
| 48 frame_generator_.reset(); | 48 frame_generator_.reset(); |
| 49 image_cursors_.reset(); |
| 49 // Destroy the PlatformWindow early on as it may call us back during | 50 // Destroy the PlatformWindow early on as it may call us back during |
| 50 // destruction and we want to be in a known state. But destroy the surface | 51 // destruction and we want to be in a known state. But destroy the surface |
| 51 // first because it can still be using the platform window. | 52 // and ThreadedImageCursors first because they can still be using the platform |
| 53 // window. |
| 52 platform_window_.reset(); | 54 platform_window_.reset(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 EventSink* PlatformDisplayDefault::GetEventSink() { | 57 EventSink* PlatformDisplayDefault::GetEventSink() { |
| 56 return delegate_->GetEventSink(); | 58 return delegate_->GetEventSink(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { | 61 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
| 60 DCHECK(delegate); | 62 DCHECK(delegate); |
| 61 delegate_ = delegate; | 63 delegate_ = delegate; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 99 } |
| 98 | 100 |
| 99 void PlatformDisplayDefault::ReleaseCapture() { | 101 void PlatformDisplayDefault::ReleaseCapture() { |
| 100 platform_window_->ReleaseCapture(); | 102 platform_window_->ReleaseCapture(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void PlatformDisplayDefault::SetCursor(const ui::CursorData& cursor_data) { | 105 void PlatformDisplayDefault::SetCursor(const ui::CursorData& cursor_data) { |
| 104 if (!image_cursors_) | 106 if (!image_cursors_) |
| 105 return; | 107 return; |
| 106 | 108 |
| 107 ui::Cursor native_cursor(cursor_data.cursor_type()); | 109 ui::CursorType cursor_type = cursor_data.cursor_type(); |
| 108 | 110 |
| 109 #if defined(USE_OZONE) | 111 #if defined(USE_OZONE) |
| 110 if (cursor_data.cursor_type() != ui::CursorType::kCustom) { | 112 if (cursor_type != ui::CursorType::kCustom) { |
| 111 image_cursors_->SetPlatformCursor(&native_cursor); | 113 // |platform_window_| is destroyed after |image_cursors_|, so it is |
| 114 // guaranteed to outlive |image_cursors_|. |
| 115 image_cursors_->SetCursor(cursor_type, platform_window_.get()); |
| 112 } else { | 116 } else { |
| 117 ui::Cursor native_cursor(cursor_type); |
| 113 // In Ozone builds, we have an interface available which turns bitmap data | 118 // In Ozone builds, we have an interface available which turns bitmap data |
| 114 // into platform cursors. | 119 // into platform cursors. |
| 115 ui::CursorFactoryOzone* cursor_factory = | 120 ui::CursorFactoryOzone* cursor_factory = |
| 116 delegate_->GetOzonePlatform()->GetCursorFactoryOzone(); | 121 delegate_->GetOzonePlatform()->GetCursorFactoryOzone(); |
| 117 native_cursor.SetPlatformCursor(cursor_factory->CreateAnimatedCursor( | 122 native_cursor.SetPlatformCursor(cursor_factory->CreateAnimatedCursor( |
| 118 cursor_data.cursor_frames(), cursor_data.hotspot_in_pixels(), | 123 cursor_data.cursor_frames(), cursor_data.hotspot_in_pixels(), |
| 119 cursor_data.frame_delay().InMilliseconds(), | 124 cursor_data.frame_delay().InMilliseconds(), |
| 120 cursor_data.scale_factor())); | 125 cursor_data.scale_factor())); |
| 126 platform_window_->SetCursor(native_cursor.platform()); |
| 121 } | 127 } |
| 122 #else | 128 #else |
| 123 // Outside of ozone builds, there isn't a single interface for creating | 129 // Outside of ozone builds, there isn't a single interface for creating |
| 124 // PlatformCursors. The closest thing to one is in //content/ instead of | 130 // PlatformCursors. The closest thing to one is in //content/ instead of |
| 125 // //ui/ which means we can't use it from here. For now, just don't handle | 131 // //ui/ which means we can't use it from here. For now, just don't handle |
| 126 // custom image cursors. | 132 // custom image cursors. |
| 127 // | 133 // |
| 128 // TODO(erg): Once blink speaks directly to mus, make blink perform its own | 134 // TODO(erg): Once blink speaks directly to mus, make blink perform its own |
| 129 // cursor management on its own mus windows so we can remove Webcursor from | 135 // cursor management on its own mus windows so we can remove Webcursor from |
| 130 // //content/ and do this in way that's safe cross-platform, instead of as an | 136 // //content/ and do this in way that's safe cross-platform, instead of as an |
| 131 // ozone-specific hack. | 137 // ozone-specific hack. |
| 132 if (cursor_data.cursor_type() == ui::CursorType::kCustom) { | 138 if (cursor_type == ui::CursorType::kCustom) { |
| 133 NOTIMPLEMENTED() << "No custom cursor support on non-ozone yet."; | 139 NOTIMPLEMENTED() << "No custom cursor support on non-ozone yet."; |
| 134 native_cursor = ui::Cursor(ui::CursorType::kPointer); | 140 cursor_type = ui::CursorType::kPointer; |
| 135 } | 141 } |
| 136 image_cursors_->SetPlatformCursor(&native_cursor); | 142 image_cursors_->SetCursor(cursor_type, platform_window_.get()); |
| 137 #endif | 143 #endif |
| 138 | |
| 139 platform_window_->SetCursor(native_cursor.platform()); | |
| 140 } | 144 } |
| 141 | 145 |
| 142 void PlatformDisplayDefault::MoveCursorTo( | 146 void PlatformDisplayDefault::MoveCursorTo( |
| 143 const gfx::Point& window_pixel_location) { | 147 const gfx::Point& window_pixel_location) { |
| 144 platform_window_->MoveCursorTo(window_pixel_location); | 148 platform_window_->MoveCursorTo(window_pixel_location); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void PlatformDisplayDefault::SetCursorSize(const ui::CursorSize& cursor_size) { | 151 void PlatformDisplayDefault::SetCursorSize(const ui::CursorSize& cursor_size) { |
| 148 image_cursors_->SetCursorSize(cursor_size); | 152 image_cursors_->SetCursorSize(cursor_size); |
| 149 } | 153 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 277 } |
| 274 | 278 |
| 275 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 279 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
| 276 NOTREACHED(); | 280 NOTREACHED(); |
| 277 } | 281 } |
| 278 | 282 |
| 279 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 283 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 280 | 284 |
| 281 } // namespace ws | 285 } // namespace ws |
| 282 } // namespace ui | 286 } // namespace ui |
| OLD | NEW |