| 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 "components/mus/ws/platform_display.h" | 5 #include "components/mus/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/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const PlatformDisplayInitParams& init_params) | 168 const PlatformDisplayInitParams& init_params) |
| 169 : gpu_state_(init_params.gpu_state), | 169 : gpu_state_(init_params.gpu_state), |
| 170 surfaces_state_(init_params.surfaces_state), | 170 surfaces_state_(init_params.surfaces_state), |
| 171 delegate_(nullptr), | 171 delegate_(nullptr), |
| 172 draw_timer_(false, false), | 172 draw_timer_(false, false), |
| 173 frame_pending_(false), | 173 frame_pending_(false), |
| 174 #if !defined(OS_ANDROID) | 174 #if !defined(OS_ANDROID) |
| 175 cursor_loader_(ui::CursorLoader::Create()), | 175 cursor_loader_(ui::CursorLoader::Create()), |
| 176 #endif | 176 #endif |
| 177 weak_factory_(this) { | 177 weak_factory_(this) { |
| 178 metrics_.size_in_pixels = mojo::Size::New(); | 178 metrics_.size_in_pixels = init_params.display_bounds.size(); |
| 179 metrics_.size_in_pixels->width = init_params.display_bounds.width(); | |
| 180 metrics_.size_in_pixels->height = init_params.display_bounds.height(); | |
| 181 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. | 179 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. |
| 182 } | 180 } |
| 183 | 181 |
| 184 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 182 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| 185 delegate_ = delegate; | 183 delegate_ = delegate; |
| 186 | 184 |
| 187 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); | 185 gfx::Rect bounds(metrics_.size_in_pixels); |
| 188 #if defined(OS_WIN) | 186 #if defined(OS_WIN) |
| 189 platform_window_.reset(new ui::WinWindow(this, bounds)); | 187 platform_window_.reset(new ui::WinWindow(this, bounds)); |
| 190 #elif defined(USE_X11) | 188 #elif defined(USE_X11) |
| 191 platform_window_.reset(new ui::X11Window(this)); | 189 platform_window_.reset(new ui::X11Window(this)); |
| 192 #elif defined(OS_ANDROID) | 190 #elif defined(OS_ANDROID) |
| 193 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 191 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
| 194 #elif defined(USE_OZONE) | 192 #elif defined(USE_OZONE) |
| 195 platform_window_ = | 193 platform_window_ = |
| 196 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 194 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 197 #else | 195 #else |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // that chrome would use, not custom image cursors. For that, we should | 248 // that chrome would use, not custom image cursors. For that, we should |
| 251 // delegate to the window manager to load images from resource packs. | 249 // delegate to the window manager to load images from resource packs. |
| 252 // | 250 // |
| 253 // We probably also need to deal with different DPIs. | 251 // We probably also need to deal with different DPIs. |
| 254 ui::Cursor cursor(cursor_id); | 252 ui::Cursor cursor(cursor_id); |
| 255 cursor_loader_->SetPlatformCursor(&cursor); | 253 cursor_loader_->SetPlatformCursor(&cursor); |
| 256 platform_window_->SetCursor(cursor.platform()); | 254 platform_window_->SetCursor(cursor.platform()); |
| 257 #endif | 255 #endif |
| 258 } | 256 } |
| 259 | 257 |
| 260 const mojom::ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() { | 258 float DefaultPlatformDisplay::GetDeviceScaleFactor() { |
| 261 return metrics_; | 259 return metrics_.device_scale_factor; |
| 262 } | 260 } |
| 263 | 261 |
| 264 mojom::Rotation DefaultPlatformDisplay::GetRotation() { | 262 mojom::Rotation DefaultPlatformDisplay::GetRotation() { |
| 265 // TODO(sky): implement me. | 263 // TODO(sky): implement me. |
| 266 return mojom::Rotation::VALUE_0; | 264 return mojom::Rotation::VALUE_0; |
| 267 } | 265 } |
| 268 | 266 |
| 269 void DefaultPlatformDisplay::UpdateTextInputState( | 267 void DefaultPlatformDisplay::UpdateTextInputState( |
| 270 const ui::TextInputState& state) { | 268 const ui::TextInputState& state) { |
| 271 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); | 269 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (draw_timer_.IsRunning() || frame_pending_) | 307 if (draw_timer_.IsRunning() || frame_pending_) |
| 310 return; | 308 return; |
| 311 | 309 |
| 312 // TODO(rjkroege): Use vblank to kick off Draw. | 310 // TODO(rjkroege): Use vblank to kick off Draw. |
| 313 draw_timer_.Start( | 311 draw_timer_.Start( |
| 314 FROM_HERE, base::TimeDelta(), | 312 FROM_HERE, base::TimeDelta(), |
| 315 base::Bind(&DefaultPlatformDisplay::Draw, weak_factory_.GetWeakPtr())); | 313 base::Bind(&DefaultPlatformDisplay::Draw, weak_factory_.GetWeakPtr())); |
| 316 } | 314 } |
| 317 | 315 |
| 318 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Size& size, | 316 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Size& size, |
| 319 float device_pixel_ratio) { | 317 float device_scale_factor) { |
| 320 if (display::Display::HasForceDeviceScaleFactor()) | 318 if (display::Display::HasForceDeviceScaleFactor()) |
| 321 device_pixel_ratio = display::Display::GetForcedDeviceScaleFactor(); | 319 device_scale_factor = display::Display::GetForcedDeviceScaleFactor(); |
| 322 if (metrics_.size_in_pixels.To<gfx::Size>() == size && | 320 if (metrics_.size_in_pixels == size && |
| 323 metrics_.device_pixel_ratio == device_pixel_ratio) | 321 metrics_.device_scale_factor == device_scale_factor) |
| 324 return; | 322 return; |
| 325 mojom::ViewportMetrics old_metrics; | |
| 326 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); | |
| 327 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; | |
| 328 | 323 |
| 329 metrics_.size_in_pixels = mojo::Size::From(size); | 324 ViewportMetrics old_metrics = metrics_; |
| 330 metrics_.device_pixel_ratio = device_pixel_ratio; | 325 metrics_.size_in_pixels = size; |
| 331 | 326 metrics_.device_scale_factor = device_scale_factor; |
| 332 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); | 327 delegate_->OnViewportMetricsChanged(old_metrics, metrics_); |
| 333 } | 328 } |
| 334 | 329 |
| 335 std::unique_ptr<cc::CompositorFrame> | 330 std::unique_ptr<cc::CompositorFrame> |
| 336 DefaultPlatformDisplay::GenerateCompositorFrame() { | 331 DefaultPlatformDisplay::GenerateCompositorFrame() { |
| 337 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 332 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 338 render_pass->damage_rect = dirty_rect_; | 333 render_pass->damage_rect = dirty_rect_; |
| 339 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()); | 334 render_pass->output_rect = gfx::Rect(metrics_.size_in_pixels); |
| 340 | 335 |
| 341 std::set<WindowId> referenced_window_ids; | 336 std::set<WindowId> referenced_window_ids; |
| 342 DrawWindowTree(render_pass.get(), delegate_->GetRootWindow(), gfx::Vector2d(), | 337 DrawWindowTree(render_pass.get(), delegate_->GetRootWindow(), gfx::Vector2d(), |
| 343 1.0f, &referenced_window_ids); | 338 1.0f, &referenced_window_ids); |
| 344 | 339 |
| 345 std::unique_ptr<cc::DelegatedFrameData> frame_data( | 340 std::unique_ptr<cc::DelegatedFrameData> frame_data( |
| 346 new cc::DelegatedFrameData); | 341 new cc::DelegatedFrameData); |
| 347 frame_data->device_scale_factor = metrics_.device_pixel_ratio; | 342 frame_data->device_scale_factor = metrics_.device_scale_factor; |
| 348 frame_data->render_pass_list.push_back(std::move(render_pass)); | 343 frame_data->render_pass_list.push_back(std::move(render_pass)); |
| 349 | 344 |
| 350 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 345 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 351 frame->delegated_frame_data = std::move(frame_data); | 346 frame->delegated_frame_data = std::move(frame_data); |
| 352 return frame; | 347 return frame; |
| 353 } | 348 } |
| 354 | 349 |
| 355 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { | 350 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { |
| 356 UpdateMetrics(new_bounds.size(), metrics_.device_pixel_ratio); | 351 UpdateMetrics(new_bounds.size(), metrics_.device_scale_factor); |
| 357 } | 352 } |
| 358 | 353 |
| 359 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { | 354 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { |
| 360 dirty_rect_.Union(damaged_region); | 355 dirty_rect_.Union(damaged_region); |
| 361 WantToDraw(); | 356 WantToDraw(); |
| 362 } | 357 } |
| 363 | 358 |
| 364 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { | 359 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { |
| 365 if (event->IsScrollEvent()) { | 360 if (event->IsScrollEvent()) { |
| 366 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as | 361 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 405 |
| 411 void DefaultPlatformDisplay::OnWindowStateChanged( | 406 void DefaultPlatformDisplay::OnWindowStateChanged( |
| 412 ui::PlatformWindowState new_state) {} | 407 ui::PlatformWindowState new_state) {} |
| 413 | 408 |
| 414 void DefaultPlatformDisplay::OnLostCapture() { | 409 void DefaultPlatformDisplay::OnLostCapture() { |
| 415 delegate_->OnNativeCaptureLost(); | 410 delegate_->OnNativeCaptureLost(); |
| 416 } | 411 } |
| 417 | 412 |
| 418 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( | 413 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( |
| 419 gfx::AcceleratedWidget widget, | 414 gfx::AcceleratedWidget widget, |
| 420 float device_pixel_ratio) { | 415 float device_scale_factor) { |
| 421 if (widget != gfx::kNullAcceleratedWidget) { | 416 if (widget != gfx::kNullAcceleratedWidget) { |
| 422 display_compositor_.reset( | 417 display_compositor_.reset( |
| 423 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget, | 418 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget, |
| 424 gpu_state_, surfaces_state_)); | 419 gpu_state_, surfaces_state_)); |
| 425 } | 420 } |
| 426 UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio); | 421 UpdateMetrics(metrics_.size_in_pixels, device_scale_factor); |
| 427 } | 422 } |
| 428 | 423 |
| 429 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { | 424 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { |
| 430 NOTREACHED(); | 425 NOTREACHED(); |
| 431 } | 426 } |
| 432 | 427 |
| 433 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 428 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} |
| 434 | 429 |
| 435 void DefaultPlatformDisplay::RequestCopyOfOutput( | 430 void DefaultPlatformDisplay::RequestCopyOfOutput( |
| 436 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 431 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
| 437 if (display_compositor_) | 432 if (display_compositor_) |
| 438 display_compositor_->RequestCopyOfOutput(std::move(output_request)); | 433 display_compositor_->RequestCopyOfOutput(std::move(output_request)); |
| 439 } | 434 } |
| 440 | 435 |
| 441 } // namespace ws | 436 } // namespace ws |
| 442 | 437 |
| 443 } // namespace mus | 438 } // namespace mus |
| OLD | NEW |