OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "cc/ipc/quads.mojom.h" | 9 #include "cc/ipc/quads.mojom.h" |
10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 return new DefaultPlatformDisplay(init_params); | 53 return new DefaultPlatformDisplay(init_params); |
54 } | 54 } |
55 | 55 |
56 DefaultPlatformDisplay::DefaultPlatformDisplay( | 56 DefaultPlatformDisplay::DefaultPlatformDisplay( |
57 const PlatformDisplayInitParams& init_params) | 57 const PlatformDisplayInitParams& init_params) |
58 : id_(init_params.display_id), | 58 : id_(init_params.display_id), |
59 #if !defined(OS_ANDROID) | 59 #if !defined(OS_ANDROID) |
60 cursor_loader_(ui::CursorLoader::Create()), | 60 cursor_loader_(ui::CursorLoader::Create()), |
61 #endif | 61 #endif |
62 frame_generator_(new FrameGenerator(this, init_params.surfaces_state)) { | 62 frame_generator_(new FrameGenerator(this, init_params.surfaces_state)), |
63 metrics_.bounds = init_params.display_bounds; | 63 metrics_(init_params.metrics) { |
64 } | 64 } |
65 | 65 |
66 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 66 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
67 delegate_ = delegate; | 67 delegate_ = delegate; |
68 | 68 |
| 69 DCHECK(!metrics_.pixel_size.IsEmpty()); |
| 70 |
| 71 // TODO(kylechar): The origin here isn't right if any displays have |
| 72 // scale_factor other than 1.0 but will prevent windows from being stacked. |
| 73 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); |
69 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
70 platform_window_.reset(new ui::WinWindow(this, metrics_.bounds)); | 75 platform_window_.reset(new ui::WinWindow(this, bounds)); |
71 #elif defined(USE_X11) | 76 #elif defined(USE_X11) |
72 platform_window_.reset(new ui::X11Window(this)); | 77 platform_window_.reset(new ui::X11Window(this)); |
73 #elif defined(OS_ANDROID) | 78 #elif defined(OS_ANDROID) |
74 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 79 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
75 #elif defined(USE_OZONE) | 80 #elif defined(USE_OZONE) |
76 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | 81 platform_window_ = |
77 this, metrics_.bounds); | 82 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
78 #else | 83 #else |
79 NOTREACHED() << "Unsupported platform"; | 84 NOTREACHED() << "Unsupported platform"; |
80 #endif | 85 #endif |
81 platform_window_->SetBounds(metrics_.bounds); | 86 delegate_->CreateRootWindow(metrics_.bounds.size()); |
| 87 |
| 88 platform_window_->SetBounds(bounds); |
82 platform_window_->Show(); | 89 platform_window_->Show(); |
83 } | 90 } |
84 | 91 |
85 int64_t DefaultPlatformDisplay::GetId() const { | 92 int64_t DefaultPlatformDisplay::GetId() const { |
86 return id_; | 93 return id_; |
87 } | 94 } |
88 | 95 |
89 DefaultPlatformDisplay::~DefaultPlatformDisplay() { | 96 DefaultPlatformDisplay::~DefaultPlatformDisplay() { |
90 // Don't notify the delegate from the destructor. | 97 // Don't notify the delegate from the destructor. |
91 delegate_ = nullptr; | 98 delegate_ = nullptr; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { | 178 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { |
172 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; | 179 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; |
173 } | 180 } |
174 | 181 |
175 void DefaultPlatformDisplay::OnGpuChannelEstablished( | 182 void DefaultPlatformDisplay::OnGpuChannelEstablished( |
176 scoped_refptr<gpu::GpuChannelHost> channel) { | 183 scoped_refptr<gpu::GpuChannelHost> channel) { |
177 frame_generator_->OnGpuChannelEstablished(channel); | 184 frame_generator_->OnGpuChannelEstablished(channel); |
178 } | 185 } |
179 | 186 |
180 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, | 187 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, |
| 188 const gfx::Size& pixel_size, |
181 float device_scale_factor) { | 189 float device_scale_factor) { |
182 if (display::Display::HasForceDeviceScaleFactor()) | |
183 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); | |
184 | |
185 // We don't care about the origin of the platform window, as that may not be | 190 // We don't care about the origin of the platform window, as that may not be |
186 // related to the origin of the display in our screen space. | 191 // related to the origin of the display in our screen space. |
187 if (metrics_.bounds.size() == bounds.size() && | 192 if (metrics_.bounds == bounds && metrics_.pixel_size == pixel_size && |
188 metrics_.device_scale_factor == device_scale_factor) | 193 metrics_.device_scale_factor == device_scale_factor) |
189 return; | 194 return; |
190 | 195 |
191 // TODO(kylechar): If the window size is updated then we may need to update | |
192 // the origin for any other windows. | |
193 ViewportMetrics old_metrics = metrics_; | 196 ViewportMetrics old_metrics = metrics_; |
194 metrics_.bounds.set_size(bounds.size()); | 197 metrics_.bounds = bounds; |
| 198 metrics_.pixel_size = pixel_size; |
195 metrics_.device_scale_factor = device_scale_factor; | 199 metrics_.device_scale_factor = device_scale_factor; |
196 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 200 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
197 } | 201 } |
198 | 202 |
199 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { | 203 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { |
200 gfx::Point location = event->location(); | 204 gfx::Point location = event->location(); |
201 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 205 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
202 event->set_root_location(location); | 206 event->set_root_location(location); |
203 } | 207 } |
204 | 208 |
205 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 209 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
206 UpdateMetrics(new_bounds, metrics_.device_scale_factor); | 210 // TODO(kylechar): We're updating the bounds assuming that the device scale |
| 211 // factor is 1 here. The correct thing to do is let PlatformSreen know the |
| 212 // display size has changed and let it update the display. |
| 213 gfx::Size pixel_size = new_bounds.size(); |
| 214 gfx::Rect bounds = gfx::Rect(metrics_.bounds.origin(), pixel_size); |
| 215 UpdateMetrics(bounds, pixel_size, metrics_.device_scale_factor); |
207 } | 216 } |
208 | 217 |
209 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 218 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
210 frame_generator_->RequestRedraw(damaged_region); | 219 frame_generator_->RequestRedraw(damaged_region); |
211 } | 220 } |
212 | 221 |
213 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 222 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
214 if (event->IsLocatedEvent()) | 223 if (event->IsLocatedEvent()) |
215 UpdateEventRootLocation(event->AsLocatedEvent()); | 224 UpdateEventRootLocation(event->AsLocatedEvent()); |
216 | 225 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 ui::PlatformWindowState new_state) {} | 273 ui::PlatformWindowState new_state) {} |
265 | 274 |
266 void DefaultPlatformDisplay::OnLostCapture() { | 275 void DefaultPlatformDisplay::OnLostCapture() { |
267 delegate_->OnNativeCaptureLost(); | 276 delegate_->OnNativeCaptureLost(); |
268 } | 277 } |
269 | 278 |
270 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( | 279 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( |
271 gfx::AcceleratedWidget widget, | 280 gfx::AcceleratedWidget widget, |
272 float device_scale_factor) { | 281 float device_scale_factor) { |
273 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 282 frame_generator_->OnAcceleratedWidgetAvailable(widget); |
274 UpdateMetrics(metrics_.bounds, device_scale_factor); | |
275 } | 283 } |
276 | 284 |
277 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { | 285 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { |
278 NOTREACHED(); | 286 NOTREACHED(); |
279 } | 287 } |
280 | 288 |
281 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 289 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} |
282 | 290 |
283 void DefaultPlatformDisplay::RequestCopyOfOutput( | 291 void DefaultPlatformDisplay::RequestCopyOfOutput( |
284 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 292 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
(...skipping 13 matching lines...) Expand all Loading... |
298 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 306 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
299 } | 307 } |
300 | 308 |
301 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 309 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { |
302 return metrics_; | 310 return metrics_; |
303 } | 311 } |
304 | 312 |
305 } // namespace ws | 313 } // namespace ws |
306 | 314 |
307 } // namespace ui | 315 } // namespace ui |
OLD | NEW |