| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 std::unique_ptr<ui::WindowCompositorFrameSink> | 76 std::unique_ptr<ui::WindowCompositorFrameSink> |
| 77 WindowPortMus::RequestCompositorFrameSink( | 77 WindowPortMus::RequestCompositorFrameSink( |
| 78 scoped_refptr<cc::ContextProvider> context_provider, | 78 scoped_refptr<cc::ContextProvider> context_provider, |
| 79 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 79 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| 80 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> | 80 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> |
| 81 compositor_frame_sink_binding; | 81 compositor_frame_sink_binding; |
| 82 std::unique_ptr<ui::WindowCompositorFrameSink> compositor_frame_sink = | 82 std::unique_ptr<ui::WindowCompositorFrameSink> compositor_frame_sink = |
| 83 ui::WindowCompositorFrameSink::Create( | 83 ui::WindowCompositorFrameSink::Create( |
| 84 cc::FrameSinkId(server_id(), 0), std::move(context_provider), | 84 cc::FrameSinkId(server_id(), 0), std::move(context_provider), |
| 85 gpu_memory_buffer_manager, &compositor_frame_sink_binding); | 85 gpu_memory_buffer_manager, &compositor_frame_sink_binding); |
| 86 compositor_frame_sink_ = compositor_frame_sink->GetWeakPtr(); |
| 86 AttachCompositorFrameSink(std::move(compositor_frame_sink_binding)); | 87 AttachCompositorFrameSink(std::move(compositor_frame_sink_binding)); |
| 88 fprintf(stderr, |
| 89 ">>>WindowPortMus::RequestCompositorFrameSink frame_sink_id: %s " |
| 90 "local_frame_id: %s\n", |
| 91 cc::FrameSinkId(server_id(), 0).ToString().c_str(), |
| 92 current_local_frame_id_.ToString().c_str()); |
| 93 if (current_local_frame_id_.is_valid()) { |
| 94 compositor_frame_sink_->SetLocalFrameId(current_local_frame_id_); |
| 95 } |
| 87 return compositor_frame_sink; | 96 return compositor_frame_sink; |
| 88 } | 97 } |
| 89 | 98 |
| 90 void WindowPortMus::AttachCompositorFrameSink( | 99 void WindowPortMus::AttachCompositorFrameSink( |
| 91 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> | 100 std::unique_ptr<ui::WindowCompositorFrameSinkBinding> |
| 92 compositor_frame_sink_binding) { | 101 compositor_frame_sink_binding) { |
| 93 window_tree_client_->AttachCompositorFrameSink( | 102 window_tree_client_->AttachCompositorFrameSink( |
| 94 server_id(), compositor_frame_sink_binding->TakeFrameSinkRequest(), | 103 server_id(), compositor_frame_sink_binding->TakeFrameSinkRequest(), |
| 95 mojo::MakeProxy(compositor_frame_sink_binding->TakeFrameSinkClient())); | 104 mojo::MakeProxy(compositor_frame_sink_binding->TakeFrameSinkClient())); |
| 96 } | 105 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 173 } |
| 165 | 174 |
| 166 PropertyConverter* WindowPortMus::GetPropertyConverter() { | 175 PropertyConverter* WindowPortMus::GetPropertyConverter() { |
| 167 return window_tree_client_->delegate_->GetPropertyConverter(); | 176 return window_tree_client_->delegate_->GetPropertyConverter(); |
| 168 } | 177 } |
| 169 | 178 |
| 170 Window* WindowPortMus::GetWindow() { | 179 Window* WindowPortMus::GetWindow() { |
| 171 return window_; | 180 return window_; |
| 172 } | 181 } |
| 173 | 182 |
| 183 void WindowPortMus::SetLayerType(ui::LayerType layer_type) { |
| 184 layer_type_ = layer_type; |
| 185 } |
| 186 |
| 187 ui::LayerType WindowPortMus::GetLayerType() const { |
| 188 return layer_type_; |
| 189 } |
| 190 |
| 174 void WindowPortMus::AddChildFromServer(WindowMus* window) { | 191 void WindowPortMus::AddChildFromServer(WindowMus* window) { |
| 175 ServerChangeData data; | 192 ServerChangeData data; |
| 176 data.child_id = window->server_id(); | 193 data.child_id = window->server_id(); |
| 177 ScopedServerChange change(this, ServerChangeType::ADD, data); | 194 ScopedServerChange change(this, ServerChangeType::ADD, data); |
| 178 window_->AddChild(window->GetWindow()); | 195 window_->AddChild(window->GetWindow()); |
| 179 } | 196 } |
| 180 | 197 |
| 181 void WindowPortMus::RemoveChildFromServer(WindowMus* child) { | 198 void WindowPortMus::RemoveChildFromServer(WindowMus* child) { |
| 182 ServerChangeData data; | 199 ServerChangeData data; |
| 183 data.child_id = child->server_id(); | 200 data.child_id = child->server_id(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 194 // a time, so this should be ok. | 211 // a time, so this should be ok. |
| 195 ServerChangeData data; | 212 ServerChangeData data; |
| 196 data.child_id = child->server_id(); | 213 data.child_id = child->server_id(); |
| 197 ScopedServerChange change(this, ServerChangeType::REORDER, data); | 214 ScopedServerChange change(this, ServerChangeType::REORDER, data); |
| 198 if (direction == ui::mojom::OrderDirection::BELOW) | 215 if (direction == ui::mojom::OrderDirection::BELOW) |
| 199 window_->StackChildBelow(child->GetWindow(), relative->GetWindow()); | 216 window_->StackChildBelow(child->GetWindow(), relative->GetWindow()); |
| 200 else | 217 else |
| 201 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); | 218 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); |
| 202 } | 219 } |
| 203 | 220 |
| 204 void WindowPortMus::SetBoundsFromServer(const gfx::Rect& bounds) { | 221 void WindowPortMus::SetBoundsFromServer( |
| 222 const gfx::Rect& bounds, |
| 223 const cc::LocalFrameId& local_frame_id) { |
| 205 ServerChangeData data; | 224 ServerChangeData data; |
| 206 data.bounds_in_dip = bounds; | 225 data.bounds_in_dip = bounds; |
| 207 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); | 226 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); |
| 208 window_->SetBounds(bounds); | 227 window_->SetBounds(bounds); |
| 228 current_local_frame_id_ = local_frame_id; |
| 229 fprintf(stderr, ">>>%s %s\n", __PRETTY_FUNCTION__, |
| 230 local_frame_id.ToString().c_str()); |
| 231 if (compositor_frame_sink_) |
| 232 compositor_frame_sink_->SetLocalFrameId(local_frame_id); |
| 209 } | 233 } |
| 210 | 234 |
| 211 void WindowPortMus::SetVisibleFromServer(bool visible) { | 235 void WindowPortMus::SetVisibleFromServer(bool visible) { |
| 212 ServerChangeData data; | 236 ServerChangeData data; |
| 213 data.visible = visible; | 237 data.visible = visible; |
| 214 ScopedServerChange change(this, ServerChangeType::VISIBLE, data); | 238 ScopedServerChange change(this, ServerChangeType::VISIBLE, data); |
| 215 if (visible) | 239 if (visible) |
| 216 window_->Show(); | 240 window_->Show(); |
| 217 else | 241 else |
| 218 window_->Hide(); | 242 window_->Hide(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 249 existing_surface_id != new_surface_id) { | 273 existing_surface_id != new_surface_id) { |
| 250 // TODO(kylechar): Start return reference here? | 274 // TODO(kylechar): Start return reference here? |
| 251 } | 275 } |
| 252 } | 276 } |
| 253 | 277 |
| 254 // The fact that SetSurfaceIdFromServer was called means that this window | 278 // The fact that SetSurfaceIdFromServer was called means that this window |
| 255 // corresponds to an embedded client. | 279 // corresponds to an embedded client. |
| 256 if (!client_surface_embedder && surface_info.id().is_valid()) | 280 if (!client_surface_embedder && surface_info.id().is_valid()) |
| 257 client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_); | 281 client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_); |
| 258 | 282 |
| 259 if (surface_info.id().is_valid()) | 283 if (surface_info.id().is_valid() && window_->IsVisible()) |
| 260 client_surface_embedder->UpdateSurface(surface_info); | 284 client_surface_embedder->UpdateSurface(surface_info); |
| 261 else | 285 else |
| 262 client_surface_embedder.reset(); | 286 client_surface_embedder.reset(); |
| 263 | 287 |
| 264 surface_info_ = surface_info; | 288 surface_info_ = surface_info; |
| 265 } | 289 } |
| 266 | 290 |
| 291 void WindowPortMus::SetLocalFrameIdFromServer( |
| 292 const cc::LocalFrameId& local_frame_id) { |
| 293 if (window_->bounds().size().IsEmpty()) |
| 294 return; |
| 295 |
| 296 cc::SurfaceInfo surface_info( |
| 297 cc::SurfaceId(cc::FrameSinkId(server_id(), 0), local_frame_id), 1.0f, |
| 298 window_->bounds().size()); |
| 299 |
| 300 fprintf(stderr, ">>>>%s %s\n", __PRETTY_FUNCTION__, |
| 301 local_frame_id.ToString().c_str()); |
| 302 SetSurfaceInfoFromServer(surface_info); |
| 303 } |
| 304 |
| 267 void WindowPortMus::DestroyFromServer() { | 305 void WindowPortMus::DestroyFromServer() { |
| 268 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 306 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 269 if (window_->parent()) { | 307 if (window_->parent()) { |
| 270 ServerChangeData data; | 308 ServerChangeData data; |
| 271 data.child_id = server_id(); | 309 data.child_id = server_id(); |
| 272 WindowPortMus* parent = Get(window_->parent()); | 310 WindowPortMus* parent = Get(window_->parent()); |
| 273 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( | 311 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
| 274 parent, ServerChangeType::REMOVE, data); | 312 parent, ServerChangeType::REMOVE, data); |
| 275 } | 313 } |
| 276 // NOTE: this can't use ScopedServerChange as |this| is destroyed before the | 314 // NOTE: this can't use ScopedServerChange as |this| is destroyed before the |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 const bool removed = RemoveChangeByTypeAndData( | 395 const bool removed = RemoveChangeByTypeAndData( |
| 358 ServerChangeType::TRANSIENT_REORDER, change_data); | 396 ServerChangeType::TRANSIENT_REORDER, change_data); |
| 359 DCHECK(removed); | 397 DCHECK(removed); |
| 360 } | 398 } |
| 361 | 399 |
| 362 void WindowPortMus::NotifyEmbeddedAppDisconnected() { | 400 void WindowPortMus::NotifyEmbeddedAppDisconnected() { |
| 363 for (WindowObserver& observer : *GetObservers(window_)) | 401 for (WindowObserver& observer : *GetObservers(window_)) |
| 364 observer.OnEmbeddedAppDisconnected(window_); | 402 observer.OnEmbeddedAppDisconnected(window_); |
| 365 } | 403 } |
| 366 | 404 |
| 367 void WindowPortMus::OnPreInit(Window* window) { | 405 void WindowPortMus::OnPreInit(Window* window, ui::LayerType layer_type) { |
| 368 window_ = window; | 406 window_ = window; |
| 369 window_tree_client_->OnWindowMusCreated(this); | 407 window_tree_client_->OnWindowMusCreated(this, layer_type); |
| 408 fprintf(stderr, ">>>%s layer_type: %d\n", __PRETTY_FUNCTION__, |
| 409 (uint32_t)layer_type); |
| 370 } | 410 } |
| 371 | 411 |
| 372 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { | 412 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 373 if (window_->delegate()) | 413 if (window_->delegate()) |
| 374 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); | 414 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); |
| 375 } | 415 } |
| 376 | 416 |
| 377 void WindowPortMus::OnWillAddChild(Window* child) { | 417 void WindowPortMus::OnWillAddChild(Window* child) { |
| 378 ServerChangeData change_data; | 418 ServerChangeData change_data; |
| 379 change_data.child_id = Get(child)->server_id(); | 419 change_data.child_id = Get(child)->server_id(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 398 change_data) == server_changes_.end()) { | 438 change_data) == server_changes_.end()) { |
| 399 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); | 439 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); |
| 400 } | 440 } |
| 401 } | 441 } |
| 402 | 442 |
| 403 void WindowPortMus::OnVisibilityChanged(bool visible) { | 443 void WindowPortMus::OnVisibilityChanged(bool visible) { |
| 404 ServerChangeData change_data; | 444 ServerChangeData change_data; |
| 405 change_data.visible = visible; | 445 change_data.visible = visible; |
| 406 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) | 446 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) |
| 407 window_tree_client_->OnWindowMusSetVisible(this, visible); | 447 window_tree_client_->OnWindowMusSetVisible(this, visible); |
| 448 // Update the ClientSurfaceEmbedder on visibility change. |
| 449 if (surface_info_.id().is_valid()) |
| 450 SetSurfaceInfoFromServer(surface_info_); |
| 408 } | 451 } |
| 409 | 452 |
| 410 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, | 453 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, |
| 411 const gfx::Rect& new_bounds) { | 454 const gfx::Rect& new_bounds) { |
| 412 ServerChangeData change_data; | 455 ServerChangeData change_data; |
| 413 change_data.bounds_in_dip = new_bounds; | 456 change_data.bounds_in_dip = new_bounds; |
| 414 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) | 457 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) |
| 415 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); | 458 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); |
| 416 } | 459 } |
| 417 | 460 |
| 418 std::unique_ptr<WindowPortPropertyData> WindowPortMus::OnWillChangeProperty( | 461 std::unique_ptr<WindowPortPropertyData> WindowPortMus::OnWillChangeProperty( |
| 419 const void* key) { | 462 const void* key) { |
| 420 return window_tree_client_->OnWindowMusWillChangeProperty(this, key); | 463 return window_tree_client_->OnWindowMusWillChangeProperty(this, key); |
| 421 } | 464 } |
| 422 | 465 |
| 423 void WindowPortMus::OnPropertyChanged( | 466 void WindowPortMus::OnPropertyChanged( |
| 424 const void* key, | 467 const void* key, |
| 425 std::unique_ptr<WindowPortPropertyData> data) { | 468 std::unique_ptr<WindowPortPropertyData> data) { |
| 426 ServerChangeData change_data; | 469 ServerChangeData change_data; |
| 427 change_data.property_name = | 470 change_data.property_name = |
| 428 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 471 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
| 429 // TODO(sky): investigate to see if we need to compare data. In particular do | 472 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 430 // we ever have a case where changing a property cascades into changing the | 473 // we ever have a case where changing a property cascades into changing the |
| 431 // same property? | 474 // same property? |
| 432 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 475 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 433 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); | 476 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); |
| 434 } | 477 } |
| 435 | 478 |
| 436 } // namespace aura | 479 } // namespace aura |
| OLD | NEW |