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; |
Fady Samuel
2017/02/13 21:31:20
It seems like this should just be in the initializ
| |
42 init_params.metrics.device_scale_factor); | |
43 } | 41 } |
44 | 42 |
45 PlatformDisplayDefault::~PlatformDisplayDefault() { | 43 PlatformDisplayDefault::~PlatformDisplayDefault() { |
46 // Don't notify the delegate from the destructor. | 44 // Don't notify the delegate from the destructor. |
47 delegate_ = nullptr; | 45 delegate_ = nullptr; |
48 | 46 |
49 frame_generator_.reset(); | 47 frame_generator_.reset(); |
50 // Destroy the PlatformWindow early on as it may call us back during | 48 // 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 | 49 // 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. | 50 // 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) | 139 if (metrics_ == metrics) |
142 return false; | 140 return false; |
143 | 141 |
144 gfx::Rect bounds = platform_window_->GetBounds(); | 142 gfx::Rect bounds = platform_window_->GetBounds(); |
145 if (bounds.size() != metrics.pixel_size) { | 143 if (bounds.size() != metrics.pixel_size) { |
146 bounds.set_size(metrics.pixel_size); | 144 bounds.set_size(metrics.pixel_size); |
147 platform_window_->SetBounds(bounds); | 145 platform_window_->SetBounds(bounds); |
148 } | 146 } |
149 | 147 |
150 metrics_ = metrics; | 148 metrics_ = metrics; |
151 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | 149 if (frame_generator_) |
150 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | |
152 return true; | 151 return true; |
153 } | 152 } |
154 | 153 |
155 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() | 154 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() |
156 const { | 155 const { |
157 return metrics_; | 156 return metrics_; |
158 } | 157 } |
159 | 158 |
160 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { | 159 gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const { |
161 return widget_; | 160 return widget_; |
162 } | 161 } |
163 | 162 |
164 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { | 163 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) { |
165 gfx::Point location = event->location(); | 164 gfx::Point location = event->location(); |
166 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); | 165 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); |
167 event->set_root_location(location); | 166 event->set_root_location(location); |
168 } | 167 } |
169 | 168 |
170 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { | 169 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) { |
171 // We only care if the window size has changed. | 170 // We only care if the window size has changed. |
172 if (new_bounds.size() == metrics_.pixel_size) | 171 if (new_bounds.size() == metrics_.pixel_size) |
173 return; | 172 return; |
174 | 173 |
175 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support | 174 // 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 | 175 // PlatformWindow initiated resizes. For other platforms we need to do |
177 // something but that isn't fully flushed out. | 176 // something but that isn't fully flushed out. |
178 } | 177 } |
179 | 178 |
180 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { | 179 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) { |
181 frame_generator_->OnWindowDamaged(); | 180 if (frame_generator_) |
181 frame_generator_->OnWindowDamaged(); | |
182 } | 182 } |
183 | 183 |
184 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { | 184 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) { |
185 if (event->IsLocatedEvent()) | 185 if (event->IsLocatedEvent()) |
186 UpdateEventRootLocation(event->AsLocatedEvent()); | 186 UpdateEventRootLocation(event->AsLocatedEvent()); |
187 | 187 |
188 if (event->IsScrollEvent()) { | 188 if (event->IsScrollEvent()) { |
189 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 189 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
190 // they are once we have proper support for scroll events. | 190 // they are once we have proper support for scroll events. |
191 delegate_->OnEvent( | 191 delegate_->OnEvent( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 240 |
241 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( | 241 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable( |
242 gfx::AcceleratedWidget widget, | 242 gfx::AcceleratedWidget widget, |
243 float device_scale_factor) { | 243 float device_scale_factor) { |
244 // 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 |
245 // 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 |
246 // the platform. | 246 // the platform. |
247 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); | 247 DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_); |
248 widget_ = widget; | 248 widget_ = widget; |
249 delegate_->OnAcceleratedWidgetAvailable(); | 249 delegate_->OnAcceleratedWidgetAvailable(); |
250 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 250 frame_generator_.reset(new FrameGenerator(this, root_window_, widget_)); |
251 frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor); | |
251 } | 252 } |
252 | 253 |
253 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { | 254 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { |
254 NOTREACHED(); | 255 NOTREACHED(); |
255 } | 256 } |
256 | 257 |
257 void PlatformDisplayDefault::OnActivationChanged(bool active) {} | 258 void PlatformDisplayDefault::OnActivationChanged(bool active) {} |
258 | 259 |
259 bool PlatformDisplayDefault::IsInHighContrastMode() { | 260 bool PlatformDisplayDefault::IsInHighContrastMode() { |
260 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 261 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
261 } | 262 } |
262 | 263 |
263 } // namespace ws | 264 } // namespace ws |
264 } // namespace ui | 265 } // namespace ui |
OLD | NEW |