| OLD | NEW |
| 1 // Copyright 2014 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.h" | 5 #include "services/ui/ws/platform_display_default.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/numerics/safe_conversions.h" | |
| 10 #include "build/build_config.h" | |
| 11 #include "cc/ipc/quads.mojom.h" | |
| 12 #include "cc/output/copy_output_request.h" | |
| 13 #include "cc/output/delegated_frame_data.h" | |
| 14 #include "gpu/ipc/client/gpu_channel_host.h" | 7 #include "gpu/ipc/client/gpu_channel_host.h" |
| 15 #include "services/service_manager/public/cpp/connection.h" | |
| 16 #include "services/service_manager/public/cpp/connector.h" | |
| 17 #include "services/ui/display/platform_screen.h" | 8 #include "services/ui/display/platform_screen.h" |
| 18 #include "services/ui/surfaces/display_compositor.h" | |
| 19 #include "services/ui/ws/platform_display_factory.h" | |
| 20 #include "services/ui/ws/platform_display_init_params.h" | 9 #include "services/ui/ws/platform_display_init_params.h" |
| 21 #include "services/ui/ws/server_window.h" | 10 #include "services/ui/ws/server_window.h" |
| 22 #include "services/ui/ws/window_coordinate_conversions.h" | |
| 23 #include "third_party/skia/include/core/SkXfermode.h" | |
| 24 #include "ui/base/cursor/cursor_loader.h" | 11 #include "ui/base/cursor/cursor_loader.h" |
| 25 #include "ui/display/display.h" | 12 #include "ui/display/display.h" |
| 26 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 27 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
| 28 #include "ui/platform_window/platform_ime_controller.h" | 15 #include "ui/platform_window/platform_ime_controller.h" |
| 29 #include "ui/platform_window/platform_window.h" | |
| 30 | 16 |
| 31 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 32 #include "ui/platform_window/win/win_window.h" | 18 #include "ui/platform_window/win/win_window.h" |
| 33 #elif defined(USE_X11) | 19 #elif defined(USE_X11) |
| 34 #include "ui/platform_window/x11/x11_window.h" | 20 #include "ui/platform_window/x11/x11_window.h" |
| 35 #elif defined(OS_ANDROID) | 21 #elif defined(OS_ANDROID) |
| 36 #include "ui/platform_window/android/platform_window_android.h" | 22 #include "ui/platform_window/android/platform_window_android.h" |
| 37 #elif defined(USE_OZONE) | 23 #elif defined(USE_OZONE) |
| 38 #include "ui/ozone/public/ozone_platform.h" | 24 #include "ui/ozone/public/ozone_platform.h" |
| 39 #endif | 25 #endif |
| 40 | 26 |
| 41 namespace ui { | 27 namespace ui { |
| 42 | |
| 43 namespace ws { | 28 namespace ws { |
| 44 | 29 |
| 45 // static | 30 PlatformDisplayDefault::PlatformDisplayDefault( |
| 46 PlatformDisplayFactory* PlatformDisplay::factory_ = nullptr; | |
| 47 | |
| 48 // static | |
| 49 std::unique_ptr<PlatformDisplay> PlatformDisplay::Create( | |
| 50 const PlatformDisplayInitParams& init_params) { | |
| 51 if (factory_) | |
| 52 return factory_->CreatePlatformDisplay(); | |
| 53 | |
| 54 return base::MakeUnique<DefaultPlatformDisplay>(init_params); | |
| 55 } | |
| 56 | |
| 57 DefaultPlatformDisplay::DefaultPlatformDisplay( | |
| 58 const PlatformDisplayInitParams& init_params) | 31 const PlatformDisplayInitParams& init_params) |
| 59 : id_(init_params.display_id), | 32 : display_id_(init_params.display_id), |
| 60 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
| 61 cursor_loader_(ui::CursorLoader::Create()), | 34 cursor_loader_(ui::CursorLoader::Create()), |
| 62 #endif | 35 #endif |
| 63 frame_generator_(new FrameGenerator(this, init_params.root_window)), | 36 frame_generator_(new FrameGenerator(this, init_params.root_window)), |
| 64 metrics_(init_params.metrics) { | 37 metrics_(init_params.metrics) { |
| 65 } | 38 } |
| 66 | 39 |
| 67 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 40 PlatformDisplayDefault::~PlatformDisplayDefault() { |
| 41 // Don't notify the delegate from the destructor. |
| 42 delegate_ = nullptr; |
| 43 |
| 44 frame_generator_.reset(); |
| 45 // Destroy the PlatformWindow early on as it may call us back during |
| 46 // destruction and we want to be in a known state. But destroy the surface |
| 47 // first because it can still be using the platform window. |
| 48 platform_window_.reset(); |
| 49 } |
| 50 |
| 51 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) { |
| 68 delegate_ = delegate; | 52 delegate_ = delegate; |
| 69 | 53 |
| 70 DCHECK(!metrics_.pixel_size.IsEmpty()); | 54 DCHECK(!metrics_.pixel_size.IsEmpty()); |
| 71 | 55 |
| 72 // TODO(kylechar): The origin here isn't right if any displays have | 56 // TODO(kylechar): The origin here isn't right if any displays have |
| 73 // scale_factor other than 1.0 but will prevent windows from being stacked. | 57 // scale_factor other than 1.0 but will prevent windows from being stacked. |
| 74 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); | 58 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); |
| 75 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 76 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); | 60 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); |
| 77 #elif defined(USE_X11) | 61 #elif defined(USE_X11) |
| 78 platform_window_ = base::MakeUnique<ui::X11Window>(this); | 62 platform_window_ = base::MakeUnique<ui::X11Window>(this); |
| 79 platform_window_->SetBounds(bounds); | 63 platform_window_->SetBounds(bounds); |
| 80 #elif defined(OS_ANDROID) | 64 #elif defined(OS_ANDROID) |
| 81 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); | 65 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); |
| 82 platform_window_->SetBounds(bounds); | 66 platform_window_->SetBounds(bounds); |
| 83 #elif defined(USE_OZONE) | 67 #elif defined(USE_OZONE) |
| 84 platform_window_ = | 68 platform_window_ = |
| 85 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 69 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 86 #else | 70 #else |
| 87 NOTREACHED() << "Unsupported platform"; | 71 NOTREACHED() << "Unsupported platform"; |
| 88 #endif | 72 #endif |
| 89 | 73 |
| 90 platform_window_->Show(); | 74 platform_window_->Show(); |
| 91 } | 75 } |
| 92 | 76 |
| 93 int64_t DefaultPlatformDisplay::GetId() const { | 77 int64_t PlatformDisplayDefault::GetId() const { |
| 94 return id_; | 78 return display_id_; |
| 95 } | 79 } |
| 96 | 80 |
| 97 DefaultPlatformDisplay::~DefaultPlatformDisplay() { | 81 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) { |
| 98 // Don't notify the delegate from the destructor. | |
| 99 delegate_ = nullptr; | |
| 100 | |
| 101 frame_generator_.reset(); | |
| 102 // Destroy the PlatformWindow early on as it may call us back during | |
| 103 // destruction and we want to be in a known state. But destroy the surface | |
| 104 // first because it can still be using the platform window. | |
| 105 platform_window_.reset(); | |
| 106 } | |
| 107 | |
| 108 void DefaultPlatformDisplay::SetViewportSize(const gfx::Size& size) { | |
| 109 platform_window_->SetBounds(gfx::Rect(size)); | 82 platform_window_->SetBounds(gfx::Rect(size)); |
| 110 } | 83 } |
| 111 | 84 |
| 112 void DefaultPlatformDisplay::SetTitle(const base::string16& title) { | 85 void PlatformDisplayDefault::SetTitle(const base::string16& title) { |
| 113 platform_window_->SetTitle(title); | 86 platform_window_->SetTitle(title); |
| 114 } | 87 } |
| 115 | 88 |
| 116 void DefaultPlatformDisplay::SetCapture() { | 89 void PlatformDisplayDefault::SetCapture() { |
| 117 platform_window_->SetCapture(); | 90 platform_window_->SetCapture(); |
| 118 } | 91 } |
| 119 | 92 |
| 120 void DefaultPlatformDisplay::ReleaseCapture() { | 93 void PlatformDisplayDefault::ReleaseCapture() { |
| 121 platform_window_->ReleaseCapture(); | 94 platform_window_->ReleaseCapture(); |
| 122 } | 95 } |
| 123 | 96 |
| 124 void DefaultPlatformDisplay::SetCursorById(mojom::Cursor cursor_id) { | 97 void PlatformDisplayDefault::SetCursorById(mojom::Cursor cursor_id) { |
| 125 #if !defined(OS_ANDROID) | 98 #if !defined(OS_ANDROID) |
| 126 // TODO(erg): This still isn't sufficient, and will only use native cursors | 99 // TODO(erg): This still isn't sufficient, and will only use native cursors |
| 127 // that chrome would use, not custom image cursors. For that, we should | 100 // that chrome would use, not custom image cursors. For that, we should |
| 128 // delegate to the window manager to load images from resource packs. | 101 // delegate to the window manager to load images from resource packs. |
| 129 // | 102 // |
| 130 // We probably also need to deal with different DPIs. | 103 // We probably also need to deal with different DPIs. |
| 131 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); | 104 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); |
| 132 cursor_loader_->SetPlatformCursor(&cursor); | 105 cursor_loader_->SetPlatformCursor(&cursor); |
| 133 platform_window_->SetCursor(cursor.platform()); | 106 platform_window_->SetCursor(cursor.platform()); |
| 134 #endif | 107 #endif |
| 135 } | 108 } |
| 136 | 109 |
| 137 void DefaultPlatformDisplay::UpdateTextInputState( | 110 void PlatformDisplayDefault::UpdateTextInputState( |
| 138 const ui::TextInputState& state) { | 111 const ui::TextInputState& state) { |
| 139 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 112 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 140 if (ime) | 113 if (ime) |
| 141 ime->UpdateTextInputState(state); | 114 ime->UpdateTextInputState(state); |
| 142 } | 115 } |
| 143 | 116 |
| 144 void DefaultPlatformDisplay::SetImeVisibility(bool visible) { | 117 void PlatformDisplayDefault::SetImeVisibility(bool visible) { |
| 145 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 118 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| 146 if (ime) | 119 if (ime) |
| 147 ime->SetImeVisibility(visible); | 120 ime->SetImeVisibility(visible); |
| 148 } | 121 } |
| 149 | 122 |
| 150 gfx::Rect DefaultPlatformDisplay::GetBounds() const { | 123 gfx::Rect PlatformDisplayDefault::GetBounds() const { |
| 151 return metrics_.bounds; | 124 return metrics_.bounds; |
| 152 } | 125 } |
| 153 | 126 |
| 154 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { | 127 bool PlatformDisplayDefault::IsPrimaryDisplay() const { |
| 155 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; | 128 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == |
| 129 display_id_; |
| 156 } | 130 } |
| 157 | 131 |
| 158 void DefaultPlatformDisplay::OnGpuChannelEstablished( | 132 void PlatformDisplayDefault::OnGpuChannelEstablished( |
| 159 scoped_refptr<gpu::GpuChannelHost> channel) { | 133 scoped_refptr<gpu::GpuChannelHost> channel) { |
| 160 frame_generator_->OnGpuChannelEstablished(channel); | 134 frame_generator_->OnGpuChannelEstablished(channel); |
| 161 } | 135 } |
| 162 | 136 |
| 163 bool DefaultPlatformDisplay::UpdateViewportMetrics( | 137 bool PlatformDisplayDefault::UpdateViewportMetrics( |
| 164 const display::ViewportMetrics& metrics) { | 138 const display::ViewportMetrics& metrics) { |
| 165 if (metrics_ == metrics) | 139 if (metrics_ == metrics) |
| 166 return false; | 140 return false; |
| 167 | 141 |
| 168 gfx::Rect bounds = platform_window_->GetBounds(); | 142 gfx::Rect bounds = platform_window_->GetBounds(); |
| 169 if (bounds.size() != metrics.pixel_size) { | 143 if (bounds.size() != metrics.pixel_size) { |
| 170 bounds.set_size(metrics.pixel_size); | 144 bounds.set_size(metrics.pixel_size); |
| 171 platform_window_->SetBounds(bounds); | 145 platform_window_->SetBounds(bounds); |
| 172 } | 146 } |
| 173 | 147 |
| 174 metrics_ = metrics; | 148 metrics_ = metrics; |
| 175 return true; | 149 return true; |
| 176 } | 150 } |
| 177 | 151 |
| 178 const display::ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() | 152 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() |
| 179 const { | 153 const { |
| 180 return metrics_; | 154 return metrics_; |
| 181 } | 155 } |
| 182 | 156 |
| 183 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { | 157 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
| 184 gfx::Point location = event->location(); | 158 gfx::Point location = event->location(); |
| 185 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 159 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
| 186 event->set_root_location(location); | 160 event->set_root_location(location); |
| 187 } | 161 } |
| 188 | 162 |
| 189 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 163 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 190 // We only care if the window size has changed. | 164 // We only care if the window size has changed. |
| 191 if (new_bounds.size() == metrics_.pixel_size) | 165 if (new_bounds.size() == metrics_.pixel_size) |
| 192 return; | 166 return; |
| 193 | 167 |
| 194 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support | 168 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support |
| 195 // PlatformWindow initiated resizes. For other platforms we need to do | 169 // PlatformWindow initiated resizes. For other platforms we need to do |
| 196 // something but that isn't fully flushed out. | 170 // something but that isn't fully flushed out. |
| 197 } | 171 } |
| 198 | 172 |
| 199 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 173 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) {} |
| 200 } | |
| 201 | 174 |
| 202 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 175 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
| 203 if (event->IsLocatedEvent()) | 176 if (event->IsLocatedEvent()) |
| 204 UpdateEventRootLocation(event->AsLocatedEvent()); | 177 UpdateEventRootLocation(event->AsLocatedEvent()); |
| 205 | 178 |
| 206 if (event->IsScrollEvent()) { | 179 if (event->IsScrollEvent()) { |
| 207 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 180 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| 208 // they are once we have proper support for scroll events. | 181 // they are once we have proper support for scroll events. |
| 209 delegate_->OnEvent( | 182 delegate_->OnEvent( |
| 210 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent()))); | 183 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent()))); |
| 211 } else if (event->IsMouseEvent()) { | 184 } else if (event->IsMouseEvent()) { |
| 212 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); | 185 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 236 // We don't check that GetCharacter() is equal because changing a key event | 209 // We don't check that GetCharacter() is equal because changing a key event |
| 237 // with an accelerator to a character event can change the character, for | 210 // with an accelerator to a character event can change the character, for |
| 238 // example, from 'M' to '^M'. | 211 // example, from 'M' to '^M'. |
| 239 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); | 212 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); |
| 240 DCHECK_EQ(key_press_event->flags(), char_event.flags()); | 213 DCHECK_EQ(key_press_event->flags(), char_event.flags()); |
| 241 delegate_->OnEvent(char_event); | 214 delegate_->OnEvent(char_event); |
| 242 } | 215 } |
| 243 #endif | 216 #endif |
| 244 } | 217 } |
| 245 | 218 |
| 246 void DefaultPlatformDisplay::OnCloseRequest() { | 219 void PlatformDisplayDefault::OnCloseRequest() { |
| 247 display::PlatformScreen::GetInstance()->RequestCloseDisplay(GetId()); | 220 display::PlatformScreen::GetInstance()->RequestCloseDisplay(GetId()); |
| 248 } | 221 } |
| 249 | 222 |
| 250 void DefaultPlatformDisplay::OnClosed() {} | 223 void PlatformDisplayDefault::OnClosed() {} |
| 251 | 224 |
| 252 void DefaultPlatformDisplay::OnWindowStateChanged( | 225 void PlatformDisplayDefault::OnWindowStateChanged( |
| 253 ui::PlatformWindowState new_state) {} | 226 ui::PlatformWindowState new_state) {} |
| 254 | 227 |
| 255 void DefaultPlatformDisplay::OnLostCapture() { | 228 void PlatformDisplayDefault::OnLostCapture() { |
| 256 delegate_->OnNativeCaptureLost(); | 229 delegate_->OnNativeCaptureLost(); |
| 257 } | 230 } |
| 258 | 231 |
| 259 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( | 232 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( |
| 260 gfx::AcceleratedWidget widget, | 233 gfx::AcceleratedWidget widget, |
| 261 float device_scale_factor) { | 234 float device_scale_factor) { |
| 262 // This will get called after Init() is called, either synchronously as part | 235 // This will get called after Init() is called, either synchronously as part |
| 263 // of the Init() callstack or async after Init() has returned, depending on | 236 // of the Init() callstack or async after Init() has returned, depending on |
| 264 // the platform. | 237 // the platform. |
| 265 delegate_->OnAcceleratedWidgetAvailable(); | 238 delegate_->OnAcceleratedWidgetAvailable(); |
| 266 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 239 frame_generator_->OnAcceleratedWidgetAvailable(widget); |
| 267 } | 240 } |
| 268 | 241 |
| 269 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { | 242 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
| 270 NOTREACHED(); | 243 NOTREACHED(); |
| 271 } | 244 } |
| 272 | 245 |
| 273 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 246 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
| 274 | 247 |
| 275 bool DefaultPlatformDisplay::IsInHighContrastMode() { | 248 bool PlatformDisplayDefault::IsInHighContrastMode() { |
| 276 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 249 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 277 } | 250 } |
| 278 | 251 |
| 279 } // namespace ws | 252 } // namespace ws |
| 280 | |
| 281 } // namespace ui | 253 } // namespace ui |
| OLD | NEW |