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" | |
19 #include "ui/display/screen.h" | |
18 | 20 |
19 namespace aura { | 21 namespace aura { |
20 | 22 |
23 namespace { | |
24 // Helper function to get the device_scale_factor() of the display::Display | |
25 // nearest to |window|. | |
26 float ScaleFactorForDisplay(Window* window) { | |
27 return display::Screen::GetScreen() | |
28 ->GetDisplayNearestWindow(window) | |
29 .device_scale_factor(); | |
30 } | |
31 } // namespace | |
32 | |
21 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 33 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
22 | 34 |
23 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 35 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
24 | 36 |
25 // static | 37 // static |
26 WindowMus* WindowMus::Get(Window* window) { | 38 WindowMus* WindowMus::Get(Window* window) { |
27 return WindowPortMus::Get(window); | 39 return WindowPortMus::Get(window); |
28 } | 40 } |
29 | 41 |
30 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 42 WindowPortMus::WindowPortMus(WindowTreeClient* client, |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 289 |
278 void WindowPortMus::SetFrameSinkIdFromServer( | 290 void WindowPortMus::SetFrameSinkIdFromServer( |
279 const cc::FrameSinkId& frame_sink_id) { | 291 const cc::FrameSinkId& frame_sink_id) { |
280 frame_sink_id_ = frame_sink_id; | 292 frame_sink_id_ = frame_sink_id; |
281 if (!pending_compositor_frame_sink_request_.is_null()) { | 293 if (!pending_compositor_frame_sink_request_.is_null()) { |
282 // TOP_LEVEL_IN_WM, and EMBED_IN_OWNER windows should not be requesting | 294 // TOP_LEVEL_IN_WM, and EMBED_IN_OWNER windows should not be requesting |
283 // CompositorFrameSinks. | 295 // CompositorFrameSinks. |
284 DCHECK_NE(WindowMusType::TOP_LEVEL_IN_WM, window_mus_type()); | 296 DCHECK_NE(WindowMusType::TOP_LEVEL_IN_WM, window_mus_type()); |
285 DCHECK_NE(WindowMusType::EMBED_IN_OWNER, window_mus_type()); | 297 DCHECK_NE(WindowMusType::EMBED_IN_OWNER, window_mus_type()); |
286 base::ResetAndReturn(&pending_compositor_frame_sink_request_).Run(); | 298 base::ResetAndReturn(&pending_compositor_frame_sink_request_).Run(); |
299 return; | |
287 } | 300 } |
288 // TODO(fsamuel): If the window type is TOP_LEVEL_IN_WM or EMBED_IN_OWNER then | 301 if ((window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
289 // we should check if we have a cc::LocalSurfaeId ready as well. If we do, | 302 window_mus_type() == WindowMusType::EMBED_IN_OWNER) && |
290 // then we are ready to embed. | 303 local_surface_id_.is_valid()) { |
304 cc::SurfaceInfo surface_info( | |
305 cc::SurfaceId(frame_sink_id_, local_surface_id_), | |
306 ScaleFactorForDisplay(window_), window_->bounds().size()); | |
307 SetPrimarySurfaceInfo(surface_info); | |
308 } | |
291 } | 309 } |
292 | 310 |
293 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( | 311 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( |
294 const gfx::Size& surface_size) { | 312 const gfx::Size& surface_size) { |
295 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) | 313 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) |
296 return local_surface_id_; | 314 return local_surface_id_; |
297 | 315 |
298 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 316 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
299 last_surface_size_ = surface_size; | 317 last_surface_size_ = surface_size; |
300 | 318 |
301 // TODO(fsamuel): If surface synchronization is enabled and the FrameSinkId | 319 // If surface synchronization is enabled and the FrameSinkId is available, |
302 // is available, then immediately embed the SurfaceId. The newly generated | 320 // then immediately embed the SurfaceId. The newly generated frame by the |
303 // frame by the embedder will block in the display compositor until the | 321 // embedder will block in the display compositor until the child submits a |
304 // child submits a corresponding CompositorFrame or a deadline hits. | 322 // corresponding CompositorFrame or a deadline hits. |
323 if (window_tree_client_->enable_surface_synchronization_ && | |
324 frame_sink_id_.is_valid()) { | |
325 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | |
326 window_mus_type() == WindowMusType::EMBED_IN_OWNER); | |
327 cc::SurfaceInfo surface_info( | |
328 cc::SurfaceId(frame_sink_id_, local_surface_id_), | |
329 ScaleFactorForDisplay(window_), surface_size); | |
330 SetPrimarySurfaceInfo(surface_info); | |
331 } | |
sadrul
2017/03/31 01:26:20
Can we have a method that does this? e.g.
void
Fady Samuel
2017/03/31 01:57:43
Done.
| |
305 | 332 |
306 return local_surface_id_; | 333 return local_surface_id_; |
307 } | 334 } |
308 | 335 |
309 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 336 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { |
310 primary_surface_info_ = surface_info; | 337 primary_surface_info_ = surface_info; |
311 UpdatePrimarySurfaceInfoInternal(); | 338 UpdatePrimarySurfaceInfoInternal(); |
312 } | 339 } |
313 | 340 |
341 void WindowPortMus::SetFallbackSurfaceInfo( | |
342 const cc::SurfaceInfo& surface_info) { | |
343 DCHECK(client_surface_embedder_); | |
344 client_surface_embedder_->SetFallbackSurfaceInfo(surface_info); | |
sadrul
2017/03/31 01:26:20
What happens if the window is hidden + shown after
Fady Samuel
2017/03/31 01:57:43
The fallback surface is lost (it is no longer refe
| |
345 } | |
346 | |
314 void WindowPortMus::DestroyFromServer() { | 347 void WindowPortMus::DestroyFromServer() { |
315 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 348 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
316 if (window_->parent()) { | 349 if (window_->parent()) { |
317 ServerChangeData data; | 350 ServerChangeData data; |
318 data.child_id = server_id(); | 351 data.child_id = server_id(); |
319 WindowPortMus* parent = Get(window_->parent()); | 352 WindowPortMus* parent = Get(window_->parent()); |
320 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( | 353 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
321 parent, ServerChangeType::REMOVE, data); | 354 parent, ServerChangeType::REMOVE, data); |
322 } | 355 } |
323 // NOTE: this can't use ScopedServerChange as |this| is destroyed before the | 356 // NOTE: this can't use ScopedServerChange as |this| is destroyed before the |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 if (!client_surface_embedder_ && primary_surface_info_.is_valid()) | 535 if (!client_surface_embedder_ && primary_surface_info_.is_valid()) |
503 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>(window_); | 536 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>(window_); |
504 | 537 |
505 if (primary_surface_info_.is_valid() && window_->IsVisible()) | 538 if (primary_surface_info_.is_valid() && window_->IsVisible()) |
506 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 539 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
507 else | 540 else |
508 client_surface_embedder_.reset(); | 541 client_surface_embedder_.reset(); |
509 } | 542 } |
510 | 543 |
511 } // namespace aura | 544 } // namespace aura |
OLD | NEW |