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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "gpu/ipc/client/gpu_channel_host.h" | 8 #include "gpu/ipc/client/gpu_channel_host.h" |
9 #include "services/ui/display/screen_manager.h" | 9 #include "services/ui/display/screen_manager.h" |
10 #include "services/ui/ws/platform_display_init_params.h" | 10 #include "services/ui/ws/platform_display_init_params.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 namespace ui { | 29 namespace ui { |
30 namespace ws { | 30 namespace ws { |
31 | 31 |
32 PlatformDisplayDefault::PlatformDisplayDefault( | 32 PlatformDisplayDefault::PlatformDisplayDefault( |
33 const PlatformDisplayInitParams& init_params) | 33 const PlatformDisplayInitParams& init_params) |
34 : display_id_(init_params.display_id), | 34 : display_id_(init_params.display_id), |
35 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
36 image_cursors_(new ImageCursors), | 36 image_cursors_(new ImageCursors), |
37 #endif | 37 #endif |
38 frame_generator_(new FrameGenerator(this, init_params.root_window)), | |
39 metrics_(init_params.metrics), | 38 metrics_(init_params.metrics), |
40 widget_(gfx::kNullAcceleratedWidget) { | 39 widget_(gfx::kNullAcceleratedWidget), |
41 frame_generator_->SetDeviceScaleFactor( | 40 root_window_(init_params.root_window), |
42 init_params.metrics.device_scale_factor); | 41 init_device_scale_factor_(init_params.metrics.device_scale_factor) { |
43 } | 42 } |
44 | 43 |
45 PlatformDisplayDefault::~PlatformDisplayDefault() { | 44 PlatformDisplayDefault::~PlatformDisplayDefault() { |
46 // Don't notify the delegate from the destructor. | 45 // Don't notify the delegate from the destructor. |
47 delegate_ = nullptr; | 46 delegate_ = nullptr; |
48 | 47 |
49 frame_generator_.reset(); | 48 frame_generator_.reset(); |
50 // Destroy the PlatformWindow early on as it may call us back during | 49 // Destroy the PlatformWindow early on as it may call us back during |
51 // destruction and we want to be in a known state. But destroy the surface | 50 // destruction and we want to be in a known state. But destroy the surface |
52 // first because it can still be using the platform window. | 51 // first because it can still be using the platform window. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (metrics_ == metrics) | 140 if (metrics_ == metrics) |
142 return false; | 141 return false; |
143 | 142 |
144 gfx::Rect bounds = platform_window_->GetBounds(); | 143 gfx::Rect bounds = platform_window_->GetBounds(); |
145 if (bounds.size() != metrics.pixel_size) { | 144 if (bounds.size() != metrics.pixel_size) { |
146 bounds.set_size(metrics.pixel_size); | 145 bounds.set_size(metrics.pixel_size); |
147 platform_window_->SetBounds(bounds); | 146 platform_window_->SetBounds(bounds); |
148 } | 147 } |
149 | 148 |
150 metrics_ = metrics; | 149 metrics_ = metrics; |
151 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | 150 if (frame_generator_) |
| 151 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() | 155 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() |
156 const { | 156 const { |
157 return metrics_; | 157 return metrics_; |
158 } | 158 } |
159 | 159 |
160 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { | 160 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { |
161 return widget_; | 161 return widget_; |
162 } | 162 } |
163 | 163 |
164 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { | 164 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
165 gfx::Point location = event->location(); | 165 gfx::Point location = event->location(); |
166 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 166 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
167 event->set_root_location(location); | 167 event->set_root_location(location); |
168 } | 168 } |
169 | 169 |
170 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { | 170 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
171 // We only care if the window size has changed. | 171 // We only care if the window size has changed. |
172 if (new_bounds.size() == metrics_.pixel_size) | 172 if (new_bounds.size() == metrics_.pixel_size) |
173 return; | 173 return; |
174 | 174 |
175 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support | 175 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support |
176 // PlatformWindow initiated resizes. For other platforms we need to do | 176 // PlatformWindow initiated resizes. For other platforms we need to do |
177 // something but that isn't fully flushed out. | 177 // something but that isn't fully flushed out. |
178 } | 178 } |
179 | 179 |
180 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { | 180 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { |
181 frame_generator_->OnWindowDamaged(); | 181 if (frame_generator_) |
| 182 frame_generator_->OnWindowDamaged(); |
182 } | 183 } |
183 | 184 |
184 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 185 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
185 if (event->IsLocatedEvent()) | 186 if (event->IsLocatedEvent()) |
186 UpdateEventRootLocation(event->AsLocatedEvent()); | 187 UpdateEventRootLocation(event->AsLocatedEvent()); |
187 | 188 |
188 if (event->IsScrollEvent()) { | 189 if (event->IsScrollEvent()) { |
189 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 190 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
190 // they are once we have proper support for scroll events. | 191 // they are once we have proper support for scroll events. |
191 delegate_->OnEvent( | 192 delegate_->OnEvent( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 241 |
241 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( | 242 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( |
242 gfx::AcceleratedWidget widget, | 243 gfx::AcceleratedWidget widget, |
243 float device_scale_factor) { | 244 float device_scale_factor) { |
244 // This will get called after Init() is called, either synchronously as part | 245 // This will get called after Init() is called, either synchronously as part |
245 // of the Init() callstack or async after Init() has returned, depending on | 246 // of the Init() callstack or async after Init() has returned, depending on |
246 // the platform. | 247 // the platform. |
247 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); | 248 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); |
248 widget_ = widget; | 249 widget_ = widget; |
249 delegate_->OnAcceleratedWidgetAvailable(); | 250 delegate_->OnAcceleratedWidgetAvailable(); |
250 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 251 frame_generator_.reset(new FrameGenerator(this, root_window_, widget_)); |
| 252 frame_generator_->SetDeviceScaleFactor(init_device_scale_factor_); |
251 } | 253 } |
252 | 254 |
253 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 255 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
254 NOTREACHED(); | 256 NOTREACHED(); |
255 } | 257 } |
256 | 258 |
257 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 259 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
258 | 260 |
259 bool PlatformDisplayDefault::IsInHighContrastMode() { | 261 bool PlatformDisplayDefault::IsInHighContrastMode() { |
260 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 262 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
261 } | 263 } |
262 | 264 |
263 } // namespace ws | 265 } // namespace ws |
264 } // namespace ui | 266 } // namespace ui |
OLD | NEW |