| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 DefaultPlatformDisplay::DefaultPlatformDisplay( | 56 DefaultPlatformDisplay::DefaultPlatformDisplay( |
| 57 const PlatformDisplayInitParams& init_params) | 57 const PlatformDisplayInitParams& init_params) |
| 58 : display_id_(init_params.display_id), | 58 : display_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, | 62 frame_generator_(new FrameGenerator(this, |
| 63 init_params.gpu_state, | 63 init_params.gpu_state, |
| 64 init_params.surfaces_state)) { | 64 init_params.surfaces_state)) { |
| 65 metrics_.size_in_pixels = init_params.display_bounds.size(); | 65 metrics_.bounds = init_params.display_bounds; |
| 66 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. | 66 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. |
| 67 } | 67 } |
| 68 | 68 |
| 69 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 69 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| 70 delegate_ = delegate; | 70 delegate_ = delegate; |
| 71 | 71 |
| 72 gfx::Rect bounds(metrics_.size_in_pixels); | |
| 73 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 74 platform_window_.reset(new ui::WinWindow(this, bounds)); | 73 platform_window_.reset(new ui::WinWindow(this, metrics_.bounds)); |
| 75 #elif defined(USE_X11) | 74 #elif defined(USE_X11) |
| 76 platform_window_.reset(new ui::X11Window(this)); | 75 platform_window_.reset(new ui::X11Window(this)); |
| 77 #elif defined(OS_ANDROID) | 76 #elif defined(OS_ANDROID) |
| 78 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 77 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
| 79 #elif defined(USE_OZONE) | 78 #elif defined(USE_OZONE) |
| 80 platform_window_ = | 79 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
| 81 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 80 this, metrics_.bounds); |
| 82 #else | 81 #else |
| 83 NOTREACHED() << "Unsupported platform"; | 82 NOTREACHED() << "Unsupported platform"; |
| 84 #endif | 83 #endif |
| 85 platform_window_->SetBounds(bounds); | 84 platform_window_->SetBounds(metrics_.bounds); |
| 86 platform_window_->Show(); | 85 platform_window_->Show(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 DefaultPlatformDisplay::~DefaultPlatformDisplay() { | 88 DefaultPlatformDisplay::~DefaultPlatformDisplay() { |
| 90 // Don't notify the delegate from the destructor. | 89 // Don't notify the delegate from the destructor. |
| 91 delegate_ = nullptr; | 90 delegate_ = nullptr; |
| 92 | 91 |
| 93 frame_generator_.reset(); | 92 frame_generator_.reset(); |
| 94 // Destroy the PlatformWindow early on as it may call us back during | 93 // Destroy the PlatformWindow early on as it may call us back during |
| 95 // destruction and we want to be in a known state. But destroy the surface | 94 // destruction and we want to be in a known state. But destroy the surface |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 160 } |
| 162 | 161 |
| 163 bool DefaultPlatformDisplay::IsFramePending() const { | 162 bool DefaultPlatformDisplay::IsFramePending() const { |
| 164 return frame_generator_->is_frame_pending(); | 163 return frame_generator_->is_frame_pending(); |
| 165 } | 164 } |
| 166 | 165 |
| 167 int64_t DefaultPlatformDisplay::GetDisplayId() const { | 166 int64_t DefaultPlatformDisplay::GetDisplayId() const { |
| 168 return display_id_; | 167 return display_id_; |
| 169 } | 168 } |
| 170 | 169 |
| 171 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Size& size, | 170 gfx::Rect DefaultPlatformDisplay::GetBounds() const { |
| 171 return metrics_.bounds; |
| 172 } |
| 173 |
| 174 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Rect& bounds, |
| 172 float device_scale_factor) { | 175 float device_scale_factor) { |
| 173 if (display::Display::HasForceDeviceScaleFactor()) | 176 if (display::Display::HasForceDeviceScaleFactor()) |
| 174 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); | 177 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); |
| 175 if (metrics_.size_in_pixels == size && | 178 if (metrics_.bounds == bounds && |
| 176 metrics_.device_scale_factor == device_scale_factor) | 179 metrics_.device_scale_factor == device_scale_factor) |
| 177 return; | 180 return; |
| 178 | 181 |
| 179 ViewportMetrics old_metrics = metrics_; | 182 ViewportMetrics old_metrics = metrics_; |
| 180 metrics_.size_in_pixels = size; | 183 metrics_.bounds = bounds; |
| 181 metrics_.device_scale_factor = device_scale_factor; | 184 metrics_.device_scale_factor = device_scale_factor; |
| 182 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 185 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 183 } | 186 } |
| 184 | 187 |
| 185 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 188 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 186 UpdateMetrics(new_bounds.size(), metrics_.device_scale_factor); | 189 // TODO(kylechar): We should keep track of the actual top left of the window |
| 190 // and also the internal top left of the window (eg. first window is at 0,0). |
| 191 UpdateMetrics(new_bounds, metrics_.device_scale_factor); |
| 187 } | 192 } |
| 188 | 193 |
| 189 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 194 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
| 190 frame_generator_->RequestRedraw(damaged_region); | 195 frame_generator_->RequestRedraw(damaged_region); |
| 191 } | 196 } |
| 192 | 197 |
| 193 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 198 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
| 194 if (event->IsScrollEvent()) { | 199 if (event->IsScrollEvent()) { |
| 195 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 200 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| 196 // they are once we have proper support for scroll events. | 201 // they are once we have proper support for scroll events. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ui::PlatformWindowState new_state) {} | 246 ui::PlatformWindowState new_state) {} |
| 242 | 247 |
| 243 void DefaultPlatformDisplay::OnLostCapture() { | 248 void DefaultPlatformDisplay::OnLostCapture() { |
| 244 delegate_->OnNativeCaptureLost(); | 249 delegate_->OnNativeCaptureLost(); |
| 245 } | 250 } |
| 246 | 251 |
| 247 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( | 252 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( |
| 248 gfx::AcceleratedWidget widget, | 253 gfx::AcceleratedWidget widget, |
| 249 float device_scale_factor) { | 254 float device_scale_factor) { |
| 250 frame_generator_->OnAcceleratedWidgetAvailable(widget); | 255 frame_generator_->OnAcceleratedWidgetAvailable(widget); |
| 251 UpdateMetrics(metrics_.size_in_pixels, device_scale_factor); | 256 UpdateMetrics(metrics_.bounds, device_scale_factor); |
| 252 } | 257 } |
| 253 | 258 |
| 254 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { | 259 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { |
| 255 NOTREACHED(); | 260 NOTREACHED(); |
| 256 } | 261 } |
| 257 | 262 |
| 258 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 263 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} |
| 259 | 264 |
| 260 void DefaultPlatformDisplay::RequestCopyOfOutput( | 265 void DefaultPlatformDisplay::RequestCopyOfOutput( |
| 261 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 266 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 275 return delegate_ ? delegate_->IsInHighContrastMode() : false; | 280 return delegate_ ? delegate_->IsInHighContrastMode() : false; |
| 276 } | 281 } |
| 277 | 282 |
| 278 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 283 const ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { |
| 279 return metrics_; | 284 return metrics_; |
| 280 } | 285 } |
| 281 | 286 |
| 282 } // namespace ws | 287 } // namespace ws |
| 283 | 288 |
| 284 } // namespace ui | 289 } // namespace ui |
| OLD | NEW |