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)), |
38 metrics_(init_params.metrics), | 39 metrics_(init_params.metrics), |
39 widget_(gfx::kNullAcceleratedWidget), | 40 widget_(gfx::kNullAcceleratedWidget) { |
40 root_window_(init_params.root_window), | 41 frame_generator_->SetDeviceScaleFactor( |
41 init_device_scale_factor_(init_params.metrics.device_scale_factor) { | 42 init_params.metrics.device_scale_factor); |
42 } | 43 } |
43 | 44 |
44 PlatformDisplayDefault::~PlatformDisplayDefault() { | 45 PlatformDisplayDefault::~PlatformDisplayDefault() { |
45 // Don't notify the delegate from the destructor. | 46 // Don't notify the delegate from the destructor. |
46 delegate_ = nullptr; | 47 delegate_ = nullptr; |
47 | 48 |
48 frame_generator_.reset(); | 49 frame_generator_.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 // first because it can still be using the platform window. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (metrics_ == metrics) | 141 if (metrics_ == metrics) |
141 return false; | 142 return false; |
142 | 143 |
143 gfx::Rect bounds = platform_window_->GetBounds(); | 144 gfx::Rect bounds = platform_window_->GetBounds(); |
144 if (bounds.size() != metrics.pixel_size) { | 145 if (bounds.size() != metrics.pixel_size) { |
145 bounds.set_size(metrics.pixel_size); | 146 bounds.set_size(metrics.pixel_size); |
146 platform_window_->SetBounds(bounds); | 147 platform_window_->SetBounds(bounds); |
147 } | 148 } |
148 | 149 |
149 metrics_ = metrics; | 150 metrics_ = metrics; |
150 if (frame_generator_) | 151 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); |
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 if (frame_generator_) | 181 frame_generator_->OnWindowDamaged(); |
182 frame_generator_->OnWindowDamaged(); | |
183 } | 182 } |
184 | 183 |
185 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 184 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
186 if (event->IsLocatedEvent()) | 185 if (event->IsLocatedEvent()) |
187 UpdateEventRootLocation(event->AsLocatedEvent()); | 186 UpdateEventRootLocation(event->AsLocatedEvent()); |
188 | 187 |
189 if (event->IsScrollEvent()) { | 188 if (event->IsScrollEvent()) { |
190 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 189 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
191 // they are once we have proper support for scroll events. | 190 // they are once we have proper support for scroll events. |
192 delegate_->OnEvent( | 191 delegate_->OnEvent( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 240 |
242 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( | 241 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( |
243 gfx::AcceleratedWidget widget, | 242 gfx::AcceleratedWidget widget, |
244 float device_scale_factor) { | 243 float device_scale_factor) { |
245 // This will get called after Init() is called, either synchronously as part | 244 // This will get called after Init() is called, either synchronously as part |
246 // of the Init() callstack or async after Init() has returned, depending on | 245 // of the Init() callstack or async after Init() has returned, depending on |
247 // the platform. | 246 // the platform. |
248 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); | 247 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); |
249 widget_ = widget; | 248 widget_ = widget; |
250 delegate_->OnAcceleratedWidgetAvailable(); | 249 delegate_->OnAcceleratedWidgetAvailable(); |
251 frame_generator_ = | 250 frame_generator_->OnAcceleratedWidgetAvailable(widget); |
252 base::MakeUnique<FrameGenerator>(this, root_window_, widget_); | |
253 frame_generator_->SetDeviceScaleFactor(init_device_scale_factor_); | |
254 } | 251 } |
255 | 252 |
256 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 253 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
257 NOTREACHED(); | 254 NOTREACHED(); |
258 } | 255 } |
259 | 256 |
260 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 257 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
261 | 258 |
262 bool PlatformDisplayDefault::IsInHighContrastMode() { | 259 bool PlatformDisplayDefault::IsInHighContrastMode() { |
263 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 260 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
264 } | 261 } |
265 | 262 |
266 } // namespace ws | 263 } // namespace ws |
267 } // namespace ui | 264 } // namespace ui |
OLD | NEW |