Chromium Code Reviews| 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/env.h" | |
| 10 #include "ui/aura/mus/client_surface_embedder.h" | 11 #include "ui/aura/mus/client_surface_embedder.h" |
| 11 #include "ui/aura/mus/property_converter.h" | 12 #include "ui/aura/mus/property_converter.h" |
| 12 #include "ui/aura/mus/window_tree_client.h" | 13 #include "ui/aura/mus/window_tree_client.h" |
| 13 #include "ui/aura/mus/window_tree_client_delegate.h" | 14 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
| 17 #include "ui/base/class_property.h" | 18 #include "ui/base/class_property.h" |
| 18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 void WindowPortMus::SetFrameSinkIdFromServer( | 267 void WindowPortMus::SetFrameSinkIdFromServer( |
| 267 const cc::FrameSinkId& frame_sink_id) { | 268 const cc::FrameSinkId& frame_sink_id) { |
| 268 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 269 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 269 window_mus_type() == WindowMusType::EMBED_IN_OWNER); | 270 window_mus_type() == WindowMusType::EMBED_IN_OWNER); |
| 270 frame_sink_id_ = frame_sink_id; | 271 frame_sink_id_ = frame_sink_id; |
| 271 UpdatePrimarySurfaceInfo(); | 272 UpdatePrimarySurfaceInfo(); |
| 272 } | 273 } |
| 273 | 274 |
| 274 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( | 275 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( |
| 275 const gfx::Size& surface_size) { | 276 const gfx::Size& surface_size) { |
| 277 if (window_mus_type() == WindowMusType::LOCAL && | |
| 278 !frame_sink_for_local_window_.get()) { | |
| 279 local_surface_id_ = cc::LocalSurfaceId(); | |
| 280 return local_surface_id_; | |
|
Fady Samuel
2017/06/07 17:36:27
Do we need this change?
Peng
2017/06/07 19:30:29
We don't want to generate local surface id, if a l
| |
| 281 } | |
| 282 | |
| 276 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) | 283 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) |
| 277 return local_surface_id_; | 284 return local_surface_id_; |
| 278 | 285 |
| 279 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 286 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 280 last_surface_size_ = surface_size; | 287 last_surface_size_ = surface_size; |
| 281 | 288 |
| 282 // If the FrameSinkId is available, then immediately embed the SurfaceId. | 289 // If the FrameSinkId is available, then immediately embed the SurfaceId. |
| 283 // The newly generated frame by the embedder will block in the display | 290 // The newly generated frame by the embedder will block in the display |
| 284 // compositor until the child submits a corresponding CompositorFrame or a | 291 // compositor until the child submits a corresponding CompositorFrame or a |
| 285 // deadline hits. | 292 // deadline hits. |
| 286 if (frame_sink_id_.is_valid()) | 293 if (frame_sink_id_.is_valid()) |
| 287 UpdatePrimarySurfaceInfo(); | 294 UpdatePrimarySurfaceInfo(); |
| 288 | 295 |
| 296 if (frame_sink_for_local_window_) | |
| 297 frame_sink_for_local_window_->SetLocalSurfaceId(local_surface_id_); | |
|
Fady Samuel
2017/06/07 17:36:27
Just call this compositor_frame_sink_. No point in
Peng
2017/06/07 19:30:29
Done.
| |
| 298 | |
| 289 return local_surface_id_; | 299 return local_surface_id_; |
| 290 } | 300 } |
| 291 | 301 |
| 292 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 302 void WindowPortMus::SetSurfaceInfoFromServer( |
| 293 primary_surface_info_ = surface_info; | 303 const cc::SurfaceInfo& surface_info) { |
| 294 UpdateClientSurfaceEmbedder(); | 304 if (!frame_sink_id_.is_valid()) { |
| 295 if (window_->delegate()) | 305 // This only happens for a "local" window, because the |
| 296 window_->delegate()->OnWindowSurfaceChanged(surface_info); | 306 // |SetFrameSinkIdFromServer| will not be called for a "local" window. |
| 297 } | 307 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| 308 // |primary_surface_info_| shold not be valid, since we didn't know the | |
| 309 // |frame_sink_id_|. | |
| 310 DCHECK(!primary_surface_info_.is_valid()); | |
| 311 frame_sink_id_ = surface_info.id().frame_sink_id(); | |
| 312 UpdatePrimarySurfaceInfo(); | |
|
Fady Samuel
2017/06/07 17:36:27
Do we need this change?
Peng
2017/06/07 19:30:29
Yes. Because we don't know frame sink id for a loc
| |
| 313 } | |
| 298 | 314 |
| 299 void WindowPortMus::SetFallbackSurfaceInfo( | 315 // The frame sink id should never be changed. |
| 300 const cc::SurfaceInfo& surface_info) { | 316 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
| 317 | |
| 318 // If the window is informed of a surface from server then that surface ID is | |
| 319 // guaranteed to be available in the display compositor so we set it as the | |
| 320 // fallback. For embedded window, the primary SurfaceInfo is created by the | |
| 321 // embedder, and the LocalSurfaceId is allocated by the embedder. | |
| 301 fallback_surface_info_ = surface_info; | 322 fallback_surface_info_ = surface_info; |
| 302 UpdateClientSurfaceEmbedder(); | 323 UpdateClientSurfaceEmbedder(); |
| 303 } | 324 } |
| 304 | 325 |
| 305 void WindowPortMus::DestroyFromServer() { | 326 void WindowPortMus::DestroyFromServer() { |
| 306 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 327 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 307 if (window_->parent()) { | 328 if (window_->parent()) { |
| 308 ServerChangeData data; | 329 ServerChangeData data; |
| 309 data.child_id = server_id(); | 330 data.child_id = server_id(); |
| 310 WindowPortMus* parent = Get(window_->parent()); | 331 WindowPortMus* parent = Get(window_->parent()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 // TODO(sky): investigate to see if we need to compare data. In particular do | 505 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 485 // we ever have a case where changing a property cascades into changing the | 506 // we ever have a case where changing a property cascades into changing the |
| 486 // same property? | 507 // same property? |
| 487 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 508 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 488 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 509 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 489 std::move(data)); | 510 std::move(data)); |
| 490 } | 511 } |
| 491 | 512 |
| 492 std::unique_ptr<cc::CompositorFrameSink> | 513 std::unique_ptr<cc::CompositorFrameSink> |
| 493 WindowPortMus::CreateCompositorFrameSink() { | 514 WindowPortMus::CreateCompositorFrameSink() { |
| 494 // TODO(penghuang): Implement it for Mus. | 515 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
|
Fady Samuel
2017/06/07 17:36:26
Can we just have a single code path? Let's not spe
Peng
2017/06/07 19:30:29
We need make sure this function is used on a embed
| |
| 495 return nullptr; | 516 DCHECK(!frame_sink_for_local_window_); |
| 517 auto frame_sink = RequestCompositorFrameSink( | |
| 518 nullptr, | |
| 519 aura::Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager()); | |
| 520 auto* viz_frame_sink = | |
| 521 static_cast<viz::ClientCompositorFrameSink*>(frame_sink.get()); | |
| 522 frame_sink_for_local_window_ = viz_frame_sink->GetWeakPtr(); | |
| 523 return frame_sink; | |
| 496 } | 524 } |
| 497 | 525 |
| 498 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 526 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| 499 // TODO(penghuang): Implement it for Mus. | 527 // This method is only used by exo unittests which are not running against |
| 528 // mus, so don't implement it now. | |
|
Fady Samuel
2017/06/07 17:36:27
Just say this is only used by WindowPortLocal in u
Peng
2017/06/07 19:30:29
Done.
| |
| 500 return cc::SurfaceId(); | 529 return cc::SurfaceId(); |
| 501 } | 530 } |
| 502 | 531 |
| 503 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 532 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| 504 bool embeds_surface = | 533 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
| 505 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 534 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
| 506 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 535 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
| 507 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 536 window_mus_type() != WindowMusType::LOCAL) |
| 508 if (!embeds_surface) | |
| 509 return; | 537 return; |
| 510 | 538 |
| 511 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 539 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| 512 return; | 540 return; |
| 513 | 541 |
| 514 SetPrimarySurfaceInfo( | 542 primary_surface_info_ = |
| 515 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 543 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 516 ScaleFactorForDisplay(window_), last_surface_size_)); | 544 ScaleFactorForDisplay(window_), last_surface_size_); |
| 545 UpdateClientSurfaceEmbedder(); | |
| 546 if (window_->delegate()) | |
| 547 window_->delegate()->OnWindowSurfaceChanged(primary_surface_info_); | |
| 517 } | 548 } |
| 518 | 549 |
| 519 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 550 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| 520 bool embeds_surface = | 551 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
| 521 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 552 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
| 522 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 553 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
| 523 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 554 window_mus_type() != WindowMusType::LOCAL) |
| 524 if (!embeds_surface) | |
| 525 return; | 555 return; |
| 526 | 556 |
| 527 if (!client_surface_embedder_) { | 557 if (!client_surface_embedder_) { |
| 528 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 558 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 529 window_, window_tree_client_->normal_client_area_insets_); | 559 window_, window_tree_client_->normal_client_area_insets_); |
| 530 } | 560 } |
| 531 | 561 |
| 532 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 562 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 533 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 563 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 534 } | 564 } |
| 535 | 565 |
| 536 } // namespace aura | 566 } // namespace aura |
| OLD | NEW |