| 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" |
| 11 #include "cc/output/delegated_frame_data.h" | 11 #include "cc/output/delegated_frame_data.h" |
| 12 #include "cc/quads/render_pass.h" | 12 #include "cc/quads/render_pass.h" |
| 13 #include "cc/quads/shared_quad_state.h" | 13 #include "cc/quads/shared_quad_state.h" |
| 14 #include "cc/quads/surface_draw_quad.h" | 14 #include "cc/quads/surface_draw_quad.h" |
| 15 #include "components/mus/gles2/gpu_state.h" | 15 #include "components/mus/gles2/gpu_state.h" |
| 16 #include "components/mus/public/interfaces/gpu.mojom.h" | 16 #include "components/mus/public/interfaces/gpu.mojom.h" |
| 17 #include "components/mus/public/interfaces/quads.mojom.h" | 17 #include "components/mus/public/interfaces/quads.mojom.h" |
| 18 #include "components/mus/surfaces/display_compositor.h" | 18 #include "components/mus/surfaces/display_compositor.h" |
| 19 #include "components/mus/surfaces/surfaces_state.h" | 19 #include "components/mus/surfaces/surfaces_state.h" |
| 20 #include "components/mus/ws/platform_display_factory.h" | 20 #include "components/mus/ws/platform_display_factory.h" |
| 21 #include "components/mus/ws/server_window.h" | 21 #include "components/mus/ws/server_window.h" |
| 22 #include "components/mus/ws/server_window_surface.h" | 22 #include "components/mus/ws/server_window_surface.h" |
| 23 #include "components/mus/ws/server_window_surface_manager.h" | 23 #include "components/mus/ws/server_window_surface_manager.h" |
| 24 #include "components/mus/ws/window_coordinate_conversions.h" | 24 #include "components/mus/ws/window_coordinate_conversions.h" |
| 25 #include "mojo/converters/geometry/geometry_type_converters.h" | |
| 26 #include "mojo/converters/input_events/input_events_type_converters.h" | 25 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 27 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" | 26 #include "mojo/converters/input_events/mojo_extended_key_event_data.h" |
| 28 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 27 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 29 #include "mojo/converters/surfaces/surfaces_utils.h" | 28 #include "mojo/converters/surfaces/surfaces_utils.h" |
| 30 #include "mojo/converters/transform/transform_type_converters.h" | 29 #include "mojo/converters/transform/transform_type_converters.h" |
| 31 #include "services/shell/public/cpp/connection.h" | 30 #include "services/shell/public/cpp/connection.h" |
| 32 #include "services/shell/public/cpp/connector.h" | 31 #include "services/shell/public/cpp/connector.h" |
| 33 #include "third_party/skia/include/core/SkXfermode.h" | 32 #include "third_party/skia/include/core/SkXfermode.h" |
| 34 #include "ui/base/cursor/cursor_loader.h" | 33 #include "ui/base/cursor/cursor_loader.h" |
| 35 #include "ui/display/display.h" | 34 #include "ui/display/display.h" |
| 36 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
| 37 #include "ui/events/event_utils.h" | 36 #include "ui/events/event_utils.h" |
| 38 #include "ui/platform_window/platform_ime_controller.h" | 37 #include "ui/platform_window/platform_ime_controller.h" |
| 39 #include "ui/platform_window/platform_window.h" | 38 #include "ui/platform_window/platform_window.h" |
| 40 | 39 |
| 41 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 42 #include "ui/platform_window/win/win_window.h" | 41 #include "ui/platform_window/win/win_window.h" |
| 43 #elif defined(USE_X11) | 42 #elif defined(USE_X11) |
| 44 #include "ui/platform_window/x11/x11_window.h" | 43 #include "ui/platform_window/x11/x11_window.h" |
| 45 #elif defined(OS_ANDROID) | 44 #elif defined(OS_ANDROID) |
| 46 #include "ui/platform_window/android/platform_window_android.h" | 45 #include "ui/platform_window/android/platform_window_android.h" |
| 47 #elif defined(USE_OZONE) | 46 #elif defined(USE_OZONE) |
| 48 #include "ui/ozone/public/ozone_platform.h" | 47 #include "ui/ozone/public/ozone_platform.h" |
| 49 #endif | 48 #endif |
| 50 | 49 |
| 51 using mojo::Rect; | |
| 52 using mojo::Size; | |
| 53 | |
| 54 namespace mus { | 50 namespace mus { |
| 55 | 51 |
| 56 namespace ws { | 52 namespace ws { |
| 57 namespace { | 53 namespace { |
| 58 | 54 |
| 59 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad | 55 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad |
| 60 // for each that lacks one. A ServerWindow may hold a CompositorFrame that | 56 // for each that lacks one. A ServerWindow may hold a CompositorFrame that |
| 61 // references other ServerWindows in SurfaceDrawQuads. We should not create new | 57 // references other ServerWindows in SurfaceDrawQuads. We should not create new |
| 62 // SurfaceDrawQuads for these |referenced_window_ids|. Instead, | 58 // SurfaceDrawQuads for these |referenced_window_ids|. Instead, |
| 63 // cc::SurfaceAggregator will do the heavy lifting here by expanding those | 59 // cc::SurfaceAggregator will do the heavy lifting here by expanding those |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const PlatformDisplayInitParams& init_params) | 164 const PlatformDisplayInitParams& init_params) |
| 169 : gpu_state_(init_params.gpu_state), | 165 : gpu_state_(init_params.gpu_state), |
| 170 surfaces_state_(init_params.surfaces_state), | 166 surfaces_state_(init_params.surfaces_state), |
| 171 delegate_(nullptr), | 167 delegate_(nullptr), |
| 172 draw_timer_(false, false), | 168 draw_timer_(false, false), |
| 173 frame_pending_(false), | 169 frame_pending_(false), |
| 174 #if !defined(OS_ANDROID) | 170 #if !defined(OS_ANDROID) |
| 175 cursor_loader_(ui::CursorLoader::Create()), | 171 cursor_loader_(ui::CursorLoader::Create()), |
| 176 #endif | 172 #endif |
| 177 weak_factory_(this) { | 173 weak_factory_(this) { |
| 178 metrics_.size_in_pixels = mojo::Size::New(); | 174 metrics_.size_in_pixels.SetSize(init_params.display_bounds.width(), |
| 179 metrics_.size_in_pixels->width = init_params.display_bounds.width(); | 175 init_params.display_bounds.height()); |
| 180 metrics_.size_in_pixels->height = init_params.display_bounds.height(); | |
| 181 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. | 176 // TODO(rjkroege): Preserve the display_id when Ozone platform can use it. |
| 182 } | 177 } |
| 183 | 178 |
| 184 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 179 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| 185 delegate_ = delegate; | 180 delegate_ = delegate; |
| 186 | 181 |
| 187 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); | 182 gfx::Rect bounds(metrics_.size_in_pixels); |
| 188 #if defined(OS_WIN) | 183 #if defined(OS_WIN) |
| 189 platform_window_.reset(new ui::WinWindow(this, bounds)); | 184 platform_window_.reset(new ui::WinWindow(this, bounds)); |
| 190 #elif defined(USE_X11) | 185 #elif defined(USE_X11) |
| 191 platform_window_.reset(new ui::X11Window(this)); | 186 platform_window_.reset(new ui::X11Window(this)); |
| 192 #elif defined(OS_ANDROID) | 187 #elif defined(OS_ANDROID) |
| 193 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 188 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
| 194 #elif defined(USE_OZONE) | 189 #elif defined(USE_OZONE) |
| 195 platform_window_ = | 190 platform_window_ = |
| 196 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 191 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 197 #else | 192 #else |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // TODO(rjkroege): Use vblank to kick off Draw. | 307 // TODO(rjkroege): Use vblank to kick off Draw. |
| 313 draw_timer_.Start( | 308 draw_timer_.Start( |
| 314 FROM_HERE, base::TimeDelta(), | 309 FROM_HERE, base::TimeDelta(), |
| 315 base::Bind(&DefaultPlatformDisplay::Draw, weak_factory_.GetWeakPtr())); | 310 base::Bind(&DefaultPlatformDisplay::Draw, weak_factory_.GetWeakPtr())); |
| 316 } | 311 } |
| 317 | 312 |
| 318 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Size& size, | 313 void DefaultPlatformDisplay::UpdateMetrics(const gfx::Size& size, |
| 319 float device_pixel_ratio) { | 314 float device_pixel_ratio) { |
| 320 if (display::Display::HasForceDeviceScaleFactor()) | 315 if (display::Display::HasForceDeviceScaleFactor()) |
| 321 device_pixel_ratio = display::Display::GetForcedDeviceScaleFactor(); | 316 device_pixel_ratio = display::Display::GetForcedDeviceScaleFactor(); |
| 322 if (metrics_.size_in_pixels.To<gfx::Size>() == size && | 317 if (metrics_.size_in_pixels == size && |
| 323 metrics_.device_pixel_ratio == device_pixel_ratio) | 318 metrics_.device_pixel_ratio == device_pixel_ratio) |
| 324 return; | 319 return; |
| 325 mojom::ViewportMetrics old_metrics; | 320 mojom::ViewportMetrics old_metrics; |
| 326 old_metrics.size_in_pixels = metrics_.size_in_pixels.Clone(); | 321 old_metrics.size_in_pixels = metrics_.size_in_pixels; |
| 327 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; | 322 old_metrics.device_pixel_ratio = metrics_.device_pixel_ratio; |
| 328 | 323 |
| 329 metrics_.size_in_pixels = mojo::Size::From(size); | 324 metrics_.size_in_pixels = size; |
| 330 metrics_.device_pixel_ratio = device_pixel_ratio; | 325 metrics_.device_pixel_ratio = device_pixel_ratio; |
| 331 | 326 |
| 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_pixel_ratio; |
| 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 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_pixel_ratio) { |
| 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_pixel_ratio); |
| 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 |