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 // TODO(kylechar): The origin here isn't right if any displays have | |
70 // scale_factor other than 1.0 but will prevent windows from being stacked. | |
71 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); | |
69 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
70 platform_window_.reset(new ui::WinWindow(this, metrics_.bounds)); | 73 platform_window_.reset(new ui::WinWindow(this, bounds)); |
71 #elif defined(USE_X11) | 74 #elif defined(USE_X11) |
72 platform_window_.reset(new ui::X11Window(this)); | 75 platform_window_.reset(new ui::X11Window(this)); |
73 #elif defined(OS_ANDROID) | 76 #elif defined(OS_ANDROID) |
74 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 77 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
75 #elif defined(USE_OZONE) | 78 #elif defined(USE_OZONE) |
76 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | 79 platform_window_ = |
77 this, metrics_.bounds); | 80 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
78 #else | 81 #else |
79 NOTREACHED() << "Unsupported platform"; | 82 NOTREACHED() << "Unsupported platform"; |
80 #endif | 83 #endif |
81 platform_window_->SetBounds(metrics_.bounds); | 84 platform_window_->SetBounds(bounds); |
82 platform_window_->Show(); | 85 platform_window_->Show(); |
86 | |
87 delegate_->OnViewportMetricsChanged(ViewportMetrics(), metrics_); | |
rjkroege
2016/09/21 13:23:47
this is required? And if it is, why do you show th
kylechar
2016/09/21 16:31:13
Yes/no. First, yes it's required because OnViewpor
| |
83 } | 88 } |
84 | 89 |
85 int64_t DefaultPlatformDisplay::GetId() const { | 90 int64_t DefaultPlatformDisplay::GetId() const { |
86 return id_; | 91 return id_; |
87 } | 92 } |
88 | 93 |
89 DefaultPlatformDisplay::~DefaultPlatformDisplay() { | 94 DefaultPlatformDisplay::~DefaultPlatformDisplay() { |
90 // Don't notify the delegate from the destructor. | 95 // Don't notify the delegate from the destructor. |
91 delegate_ = nullptr; | 96 delegate_ = nullptr; |
92 | 97 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { | 176 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { |
172 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; | 177 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; |
173 } | 178 } |
174 | 179 |
175 void DefaultPlatformDisplay::OnGpuChannelEstablished( | 180 void DefaultPlatformDisplay::OnGpuChannelEstablished( |
176 scoped_refptr<gpu::GpuChannelHost> channel) { | 181 scoped_refptr<gpu::GpuChannelHost> channel) { |
177 frame_generator_->OnGpuChannelEstablished(channel); | 182 frame_generator_->OnGpuChannelEstablished(channel); |
178 } | 183 } |
179 | 184 |
180 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, | 185 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, |
186 const gfx::Size& pixel_size, | |
181 float device_scale_factor) { | 187 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 | 188 // 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. | 189 // related to the origin of the display in our screen space. |
187 if (metrics_.bounds.size() == bounds.size() && | 190 if (metrics_.bounds == bounds && metrics_.pixel_size == pixel_size && |
188 metrics_.device_scale_factor == device_scale_factor) | 191 metrics_.device_scale_factor == device_scale_factor) |
189 return; | 192 return; |
190 | 193 |
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_; | 194 ViewportMetrics old_metrics = metrics_; |
194 metrics_.bounds.set_size(bounds.size()); | 195 metrics_.bounds = bounds; |
196 metrics_.pixel_size = pixel_size; | |
195 metrics_.device_scale_factor = device_scale_factor; | 197 metrics_.device_scale_factor = device_scale_factor; |
196 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 198 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
197 } | 199 } |
198 | 200 |
199 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { | 201 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { |
200 gfx::Point location = event->location(); | 202 gfx::Point location = event->location(); |
201 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 203 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
202 event->set_root_location(location); | 204 event->set_root_location(location); |
203 } | 205 } |
204 | 206 |
205 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 207 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
206 UpdateMetrics(new_bounds, metrics_.device_scale_factor); | 208 // TODO(kylechar): We're updating the bounds assuming that the device scale |
209 // factor is 1 here. The correct thing to do is let PlatformSreen know the | |
210 // display size has changed and let it update the display. | |
211 gfx::Size pixel_size = new_bounds.size(); | |
212 gfx::Rect bounds = gfx::Rect(metrics_.bounds.origin(), pixel_size); | |
213 UpdateMetrics(bounds, pixel_size, metrics_.device_scale_factor); | |
207 } | 214 } |
208 | 215 |
209 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 216 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
210 frame_generator_->RequestRedraw(damaged_region); | 217 frame_generator_->RequestRedraw(damaged_region); |
211 } | 218 } |
212 | 219 |
213 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 220 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
214 if (event->IsLocatedEvent()) | 221 if (event->IsLocatedEvent()) |
215 UpdateEventRootLocation(event->AsLocatedEvent()); | 222 UpdateEventRootLocation(event->AsLocatedEvent()); |
216 | 223 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 ui::PlatformWindowState new_state) {} | 271 ui::PlatformWindowState new_state) {} |
265 | 272 |
266 void DefaultPlatformDisplay::OnLostCapture() { | 273 void DefaultPlatformDisplay::OnLostCapture() { |
267 delegate_->OnNativeCaptureLost(); | 274 delegate_->OnNativeCaptureLost(); |
268 } | 275 } |
269 | 276 |
270 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( | 277 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( |
271 gfx::AcceleratedWidget widget, | 278 gfx::AcceleratedWidget widget, |
272 float device_scale_factor) { | 279 float device_scale_factor) { |
273 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 280 frame_generator_->OnAcceleratedWidgetAvailable(widget); |
274 UpdateMetrics(metrics_.bounds, device_scale_factor); | |
275 } | 281 } |
276 | 282 |
277 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { | 283 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { |
278 NOTREACHED(); | 284 NOTREACHED(); |
279 } | 285 } |
280 | 286 |
281 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 287 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} |
282 | 288 |
283 void DefaultPlatformDisplay::RequestCopyOfOutput( | 289 void DefaultPlatformDisplay::RequestCopyOfOutput( |
284 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 290 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
(...skipping 13 matching lines...) Expand all Loading... | |
298 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 304 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
299 } | 305 } |
300 | 306 |
301 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 307 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { |
302 return metrics_; | 308 return metrics_; |
303 } | 309 } |
304 | 310 |
305 } // namespace ws | 311 } // namespace ws |
306 | 312 |
307 } // namespace ui | 313 } // namespace ui |
OLD | NEW |