| 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 "ui/aura/mus/window_port_mus.h" | 5 #include "ui/aura/mus/window_port_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/transient_window_client.h" | 9 #include "ui/aura/client/transient_window_client.h" |
| 10 #include "ui/aura/mus/client_surface_embedder.h" | 10 #include "ui/aura/mus/client_surface_embedder.h" |
| 11 #include "ui/aura/mus/property_converter.h" | 11 #include "ui/aura/mus/property_converter.h" |
| 12 #include "ui/aura/mus/window_tree_client.h" | 12 #include "ui/aura/mus/window_tree_client.h" |
| 13 #include "ui/aura/mus/window_tree_client_delegate.h" | 13 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 17 #include "ui/base/class_property.h" | 17 #include "ui/base/class_property.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 20 #include "ui/gfx/geometry/dip_util.h" |
| 20 | 21 |
| 21 namespace aura { | 22 namespace aura { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 // Helper function to get the device_scale_factor() of the display::Display | 25 // Helper function to get the device_scale_factor() of the display::Display |
| 25 // nearest to |window|. | 26 // nearest to |window|. |
| 26 float ScaleFactorForDisplay(Window* window) { | 27 float ScaleFactorForDisplay(Window* window) { |
| 27 return display::Screen::GetScreen() | 28 return display::Screen::GetScreen() |
| 28 ->GetDisplayNearestWindow(window) | 29 ->GetDisplayNearestWindow(window) |
| 29 .device_scale_factor(); | 30 .device_scale_factor(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 else | 224 else |
| 224 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); | 225 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void WindowPortMus::SetBoundsFromServer( | 228 void WindowPortMus::SetBoundsFromServer( |
| 228 const gfx::Rect& bounds, | 229 const gfx::Rect& bounds, |
| 229 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { | 230 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { |
| 230 ServerChangeData data; | 231 ServerChangeData data; |
| 231 data.bounds_in_dip = bounds; | 232 data.bounds_in_dip = bounds; |
| 232 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); | 233 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); |
| 233 last_surface_size_ = bounds.size(); | 234 float device_scale_factor = ScaleFactorForDisplay(window_); |
| 235 last_surface_size_in_pixels_ = |
| 236 gfx::ConvertSizeToPixel(device_scale_factor, bounds.size()); |
| 234 if (local_surface_id) | 237 if (local_surface_id) |
| 235 local_surface_id_ = *local_surface_id; | 238 local_surface_id_ = *local_surface_id; |
| 236 else | 239 else |
| 237 local_surface_id_ = cc::LocalSurfaceId(); | 240 local_surface_id_ = cc::LocalSurfaceId(); |
| 238 window_->SetBounds(bounds); | 241 window_->SetBounds(bounds); |
| 239 } | 242 } |
| 240 | 243 |
| 241 void WindowPortMus::SetTransformFromServer(const gfx::Transform& transform) { | 244 void WindowPortMus::SetTransformFromServer(const gfx::Transform& transform) { |
| 242 ServerChangeData data; | 245 ServerChangeData data; |
| 243 data.transform = transform; | 246 data.transform = transform; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 280 |
| 278 void WindowPortMus::SetFrameSinkIdFromServer( | 281 void WindowPortMus::SetFrameSinkIdFromServer( |
| 279 const cc::FrameSinkId& frame_sink_id) { | 282 const cc::FrameSinkId& frame_sink_id) { |
| 280 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 283 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 281 window_mus_type() == WindowMusType::EMBED_IN_OWNER); | 284 window_mus_type() == WindowMusType::EMBED_IN_OWNER); |
| 282 frame_sink_id_ = frame_sink_id; | 285 frame_sink_id_ = frame_sink_id; |
| 283 UpdatePrimarySurfaceInfo(); | 286 UpdatePrimarySurfaceInfo(); |
| 284 } | 287 } |
| 285 | 288 |
| 286 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( | 289 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( |
| 287 const gfx::Size& surface_size) { | 290 const gfx::Size& surface_size_in_pixels) { |
| 288 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) | 291 if (last_surface_size_in_pixels_ == surface_size_in_pixels && |
| 292 local_surface_id_.is_valid()) { |
| 289 return local_surface_id_; | 293 return local_surface_id_; |
| 294 } |
| 290 | 295 |
| 291 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 296 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 292 last_surface_size_ = surface_size; | 297 last_surface_size_in_pixels_ = surface_size_in_pixels; |
| 293 | 298 |
| 294 // If the FrameSinkId is available, then immediately embed the SurfaceId. | 299 // If the FrameSinkId is available, then immediately embed the SurfaceId. |
| 295 // The newly generated frame by the embedder will block in the display | 300 // The newly generated frame by the embedder will block in the display |
| 296 // compositor until the child submits a corresponding CompositorFrame or a | 301 // compositor until the child submits a corresponding CompositorFrame or a |
| 297 // deadline hits. | 302 // deadline hits. |
| 298 if (frame_sink_id_.is_valid()) | 303 if (frame_sink_id_.is_valid()) |
| 299 UpdatePrimarySurfaceInfo(); | 304 UpdatePrimarySurfaceInfo(); |
| 300 | 305 |
| 301 return local_surface_id_; | 306 return local_surface_id_; |
| 302 } | 307 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 bool embeds_surface = | 531 bool embeds_surface = |
| 527 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 532 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 528 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 533 window_mus_type() == WindowMusType::EMBED_IN_OWNER || |
| 529 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 534 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; |
| 530 if (!embeds_surface) | 535 if (!embeds_surface) |
| 531 return; | 536 return; |
| 532 | 537 |
| 533 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 538 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| 534 return; | 539 return; |
| 535 | 540 |
| 536 SetPrimarySurfaceInfo( | 541 SetPrimarySurfaceInfo(cc::SurfaceInfo( |
| 537 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 542 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 538 ScaleFactorForDisplay(window_), last_surface_size_)); | 543 ScaleFactorForDisplay(window_), last_surface_size_in_pixels_)); |
| 539 } | 544 } |
| 540 | 545 |
| 541 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 546 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| 542 bool embeds_surface = | 547 bool embeds_surface = |
| 543 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 548 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 544 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 549 window_mus_type() == WindowMusType::EMBED_IN_OWNER || |
| 545 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 550 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; |
| 546 if (!embeds_surface) | 551 if (!embeds_surface) |
| 547 return; | 552 return; |
| 548 | 553 |
| 549 if (!client_surface_embedder_) { | 554 if (!client_surface_embedder_) { |
| 550 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 555 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 551 window_, window_tree_client_->normal_client_area_insets_); | 556 window_, window_tree_client_->normal_client_area_insets_); |
| 552 } | 557 } |
| 553 | 558 |
| 554 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 559 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 555 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 560 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 556 } | 561 } |
| 557 | 562 |
| 558 } // namespace aura | 563 } // namespace aura |
| OLD | NEW |