| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 5 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 6 | 6 |
| 7 #include "cc/ipc/display_compositor.mojom.h" | 7 #include "cc/ipc/display_compositor.mojom.h" |
| 8 #include "mojo/public/cpp/bindings/strong_binding.h" | 8 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 9 #include "services/ui/ws/ids.h" | 9 #include "services/ui/ws/ids.h" |
| 10 #include "services/ui/ws/server_window.h" | 10 #include "services/ui/ws/server_window.h" |
| 11 #include "services/ui/ws/server_window_delegate.h" | 11 #include "services/ui/ws/server_window_delegate.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 namespace ws { | 14 namespace ws { |
| 15 | 15 |
| 16 ServerWindowCompositorFrameSinkManager::ServerWindowCompositorFrameSinkManager( | 16 ServerWindowCompositorFrameSinkManager::ServerWindowCompositorFrameSinkManager( |
| 17 ServerWindow* window) | 17 ServerWindow* window) |
| 18 : window_(window) {} | 18 : window_(window) {} |
| 19 | 19 |
| 20 ServerWindowCompositorFrameSinkManager:: | 20 ServerWindowCompositorFrameSinkManager:: |
| 21 ~ServerWindowCompositorFrameSinkManager() { | 21 ~ServerWindowCompositorFrameSinkManager() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ServerWindowCompositorFrameSinkManager::CreateDisplayCompositorFrameSink( | 24 void ServerWindowCompositorFrameSinkManager::CreateDisplayCompositorFrameSink( |
| 25 gfx::AcceleratedWidget widget, | 25 gfx::AcceleratedWidget widget, |
| 26 cc::mojom::MojoCompositorFrameSinkRequest request, | 26 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 27 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 27 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 28 cc::mojom::DisplayPrivateRequest display_private_request) { | 28 cc::mojom::DisplayPrivateRequest display_private_request) { |
| 29 CreateCompositorFrameSinkInternal( | 29 CreateCompositorFrameSinkInternal(widget, std::move(request), |
| 30 mojom::CompositorFrameSinkType::DEFAULT, widget, std::move(request), | 30 std::move(client), |
| 31 std::move(client), std::move(display_private_request)); | 31 std::move(display_private_request)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ServerWindowCompositorFrameSinkManager::CreateOffscreenCompositorFrameSink( | 34 void ServerWindowCompositorFrameSinkManager::CreateOffscreenCompositorFrameSink( |
| 35 mojom::CompositorFrameSinkType compositor_frame_sink_type, | |
| 36 cc::mojom::MojoCompositorFrameSinkRequest request, | 35 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 37 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 36 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 38 CreateCompositorFrameSinkInternal( | 37 CreateCompositorFrameSinkInternal(gfx::kNullAcceleratedWidget, |
| 39 compositor_frame_sink_type, gfx::kNullAcceleratedWidget, | 38 std::move(request), std::move(client), |
| 40 std::move(request), std::move(client), nullptr); | 39 nullptr); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void ServerWindowCompositorFrameSinkManager::AddChildFrameSinkId( | 42 void ServerWindowCompositorFrameSinkManager::AddChildFrameSinkId( |
| 44 mojom::CompositorFrameSinkType compositor_frame_sink_type, | |
| 45 const cc::FrameSinkId& frame_sink_id) { | 43 const cc::FrameSinkId& frame_sink_id) { |
| 46 auto it = type_to_compositor_frame_sink_map_.find(compositor_frame_sink_type); | 44 if (frame_sink_data_) { |
| 47 if (it != type_to_compositor_frame_sink_map_.end()) { | 45 frame_sink_data_->compositor_frame_sink->AddChildFrameSink(frame_sink_id); |
| 48 it->second.compositor_frame_sink->AddChildFrameSink(frame_sink_id); | |
| 49 return; | 46 return; |
| 50 } | 47 } |
| 51 CompositorFrameSinkData& data = | 48 frame_sink_data_ = base::MakeUnique<CompositorFrameSinkData>(); |
| 52 type_to_compositor_frame_sink_map_[compositor_frame_sink_type]; | 49 frame_sink_data_->pending_compositor_frame_sink_request = |
| 53 data.pending_compositor_frame_sink_request = | 50 mojo::MakeRequest(&frame_sink_data_->compositor_frame_sink); |
| 54 mojo::MakeRequest(&data.compositor_frame_sink); | 51 frame_sink_data_->compositor_frame_sink->AddChildFrameSink(frame_sink_id); |
| 55 data.compositor_frame_sink->AddChildFrameSink(frame_sink_id); | |
| 56 } | 52 } |
| 57 | 53 |
| 58 void ServerWindowCompositorFrameSinkManager::RemoveChildFrameSinkId( | 54 void ServerWindowCompositorFrameSinkManager::RemoveChildFrameSinkId( |
| 59 mojom::CompositorFrameSinkType compositor_frame_sink_type, | |
| 60 const cc::FrameSinkId& frame_sink_id) { | 55 const cc::FrameSinkId& frame_sink_id) { |
| 61 auto it = type_to_compositor_frame_sink_map_.find(compositor_frame_sink_type); | 56 DCHECK(frame_sink_data_); |
| 62 DCHECK(it != type_to_compositor_frame_sink_map_.end()); | 57 frame_sink_data_->compositor_frame_sink->RemoveChildFrameSink(frame_sink_id); |
| 63 it->second.compositor_frame_sink->RemoveChildFrameSink(frame_sink_id); | |
| 64 } | 58 } |
| 65 | 59 |
| 66 bool ServerWindowCompositorFrameSinkManager::HasCompositorFrameSinkOfType( | 60 bool ServerWindowCompositorFrameSinkManager::HasCompositorFrameSink() const { |
| 67 mojom::CompositorFrameSinkType type) const { | 61 return !!frame_sink_data_; |
| 68 return type_to_compositor_frame_sink_map_.count(type) > 0; | |
| 69 } | 62 } |
| 70 | 63 |
| 71 bool ServerWindowCompositorFrameSinkManager::HasAnyCompositorFrameSink() const { | 64 gfx::Size ServerWindowCompositorFrameSinkManager::GetLatestFrameSize() const { |
| 72 return HasCompositorFrameSinkOfType( | 65 if (!frame_sink_data_) |
| 73 mojom::CompositorFrameSinkType::DEFAULT) || | 66 return gfx::Size(); |
| 74 HasCompositorFrameSinkOfType(mojom::CompositorFrameSinkType::UNDERLAY); | 67 |
| 68 return frame_sink_data_->latest_submitted_surface_info.size_in_pixels(); |
| 75 } | 69 } |
| 76 | 70 |
| 77 gfx::Size ServerWindowCompositorFrameSinkManager::GetLatestFrameSize( | 71 cc::SurfaceId ServerWindowCompositorFrameSinkManager::GetLatestSurfaceId() |
| 78 mojom::CompositorFrameSinkType type) const { | 72 const { |
| 79 auto it = type_to_compositor_frame_sink_map_.find(type); | 73 if (!frame_sink_data_) |
| 80 if (it == type_to_compositor_frame_sink_map_.end()) | |
| 81 return gfx::Size(); | |
| 82 | |
| 83 return it->second.latest_submitted_surface_info.size_in_pixels(); | |
| 84 } | |
| 85 | |
| 86 cc::SurfaceId ServerWindowCompositorFrameSinkManager::GetLatestSurfaceId( | |
| 87 mojom::CompositorFrameSinkType type) const { | |
| 88 auto it = type_to_compositor_frame_sink_map_.find(type); | |
| 89 if (it == type_to_compositor_frame_sink_map_.end()) | |
| 90 return cc::SurfaceId(); | 74 return cc::SurfaceId(); |
| 91 | 75 |
| 92 return it->second.latest_submitted_surface_info.id(); | 76 return frame_sink_data_->latest_submitted_surface_info.id(); |
| 93 } | 77 } |
| 94 | 78 |
| 95 void ServerWindowCompositorFrameSinkManager::SetLatestSurfaceInfo( | 79 void ServerWindowCompositorFrameSinkManager::SetLatestSurfaceInfo( |
| 96 mojom::CompositorFrameSinkType type, | |
| 97 const cc::SurfaceInfo& surface_info) { | 80 const cc::SurfaceInfo& surface_info) { |
| 98 CompositorFrameSinkData& data = type_to_compositor_frame_sink_map_[type]; | 81 if (!frame_sink_data_) |
| 99 data.latest_submitted_surface_info = surface_info; | 82 frame_sink_data_ = base::MakeUnique<CompositorFrameSinkData>(); |
| 83 |
| 84 frame_sink_data_->latest_submitted_surface_info = surface_info; |
| 100 } | 85 } |
| 101 | 86 |
| 102 void ServerWindowCompositorFrameSinkManager::OnRootChanged( | 87 void ServerWindowCompositorFrameSinkManager::OnRootChanged( |
| 103 ServerWindow* old_root, | 88 ServerWindow* old_root, |
| 104 ServerWindow* new_root) { | 89 ServerWindow* new_root) { |
| 105 for (const auto& pair : type_to_compositor_frame_sink_map_) { | 90 if (!frame_sink_data_) |
| 106 if (old_root) { | 91 return; |
| 107 old_root->GetOrCreateCompositorFrameSinkManager()->RemoveChildFrameSinkId( | 92 |
| 108 pair.first, pair.second.frame_sink_id); | 93 if (old_root) { |
| 109 } | 94 old_root->GetOrCreateCompositorFrameSinkManager()->RemoveChildFrameSinkId( |
| 110 if (new_root) { | 95 frame_sink_data_->frame_sink_id); |
| 111 new_root->GetOrCreateCompositorFrameSinkManager()->AddChildFrameSinkId( | 96 } |
| 112 pair.first, pair.second.frame_sink_id); | 97 if (new_root) { |
| 113 } | 98 new_root->GetOrCreateCompositorFrameSinkManager()->AddChildFrameSinkId( |
| 99 frame_sink_data_->frame_sink_id); |
| 114 } | 100 } |
| 115 } | 101 } |
| 116 | 102 |
| 117 bool ServerWindowCompositorFrameSinkManager:: | |
| 118 IsCompositorFrameSinkReadyAndNonEmpty( | |
| 119 mojom::CompositorFrameSinkType type) const { | |
| 120 auto iter = type_to_compositor_frame_sink_map_.find(type); | |
| 121 if (iter == type_to_compositor_frame_sink_map_.end()) | |
| 122 return false; | |
| 123 if (iter->second.latest_submitted_surface_info.size_in_pixels().IsEmpty()) | |
| 124 return false; | |
| 125 const gfx::Size& latest_submitted_frame_size = | |
| 126 iter->second.latest_submitted_surface_info.size_in_pixels(); | |
| 127 return latest_submitted_frame_size.width() >= window_->bounds().width() && | |
| 128 latest_submitted_frame_size.height() >= window_->bounds().height(); | |
| 129 } | |
| 130 | |
| 131 void ServerWindowCompositorFrameSinkManager::CreateCompositorFrameSinkInternal( | 103 void ServerWindowCompositorFrameSinkManager::CreateCompositorFrameSinkInternal( |
| 132 mojom::CompositorFrameSinkType compositor_frame_sink_type, | |
| 133 gfx::AcceleratedWidget widget, | 104 gfx::AcceleratedWidget widget, |
| 134 cc::mojom::MojoCompositorFrameSinkRequest request, | 105 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 135 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 106 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 136 cc::mojom::DisplayPrivateRequest display_private_request) { | 107 cc::mojom::DisplayPrivateRequest display_private_request) { |
| 137 cc::FrameSinkId frame_sink_id( | 108 cc::FrameSinkId frame_sink_id(WindowIdToTransportId(window_->id()), 0); |
| 138 WindowIdToTransportId(window_->id()), | 109 |
| 139 static_cast<uint32_t>(compositor_frame_sink_type)); | 110 if (!frame_sink_data_) |
| 140 CompositorFrameSinkData& data = | 111 frame_sink_data_ = base::MakeUnique<CompositorFrameSinkData>(); |
| 141 type_to_compositor_frame_sink_map_[compositor_frame_sink_type]; | 112 |
| 142 data.frame_sink_id = frame_sink_id; | 113 frame_sink_data_->frame_sink_id = frame_sink_id; |
| 143 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request; | 114 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request; |
| 144 if (data.pending_compositor_frame_sink_request.is_pending()) { | 115 if (frame_sink_data_->pending_compositor_frame_sink_request.is_pending()) { |
| 145 private_request = std::move(data.pending_compositor_frame_sink_request); | 116 private_request = |
| 117 std::move(frame_sink_data_->pending_compositor_frame_sink_request); |
| 146 } else { | 118 } else { |
| 147 private_request = mojo::MakeRequest(&data.compositor_frame_sink); | 119 private_request = |
| 120 mojo::MakeRequest(&frame_sink_data_->compositor_frame_sink); |
| 148 } | 121 } |
| 149 if (widget != gfx::kNullAcceleratedWidget) { | 122 if (widget != gfx::kNullAcceleratedWidget) { |
| 150 // TODO(fsamuel): AcceleratedWidget cannot be transported over IPC for Mac | 123 // TODO(fsamuel): AcceleratedWidget cannot be transported over IPC for Mac |
| 151 // or Android. We should instead use GpuSurfaceTracker here on those | 124 // or Android. We should instead use GpuSurfaceTracker here on those |
| 152 // platforms. | 125 // platforms. |
| 153 window_->delegate() | 126 window_->delegate() |
| 154 ->GetDisplayCompositor() | 127 ->GetDisplayCompositor() |
| 155 ->CreateDisplayCompositorFrameSink( | 128 ->CreateDisplayCompositorFrameSink( |
| 156 frame_sink_id, widget, std::move(request), | 129 frame_sink_id, widget, std::move(request), |
| 157 std::move(private_request), std::move(client), | 130 std::move(private_request), std::move(client), |
| 158 std::move(display_private_request)); | 131 std::move(display_private_request)); |
| 159 } else { | 132 } else { |
| 160 DCHECK(display_private_request.Equals(nullptr)); | 133 DCHECK(display_private_request.Equals(nullptr)); |
| 161 window_->delegate() | 134 window_->delegate() |
| 162 ->GetDisplayCompositor() | 135 ->GetDisplayCompositor() |
| 163 ->CreateOffscreenCompositorFrameSink(frame_sink_id, std::move(request), | 136 ->CreateOffscreenCompositorFrameSink(frame_sink_id, std::move(request), |
| 164 std::move(private_request), | 137 std::move(private_request), |
| 165 std::move(client)); | 138 std::move(client)); |
| 166 } | 139 } |
| 167 | 140 |
| 168 if (window_->parent()) { | 141 if (window_->parent()) { |
| 169 ServerWindow* root_window = window_->GetRoot(); | 142 ServerWindow* root_window = window_->GetRoot(); |
| 170 if (root_window) { | 143 if (root_window) { |
| 171 root_window->GetOrCreateCompositorFrameSinkManager()->AddChildFrameSinkId( | 144 root_window->GetOrCreateCompositorFrameSinkManager()->AddChildFrameSinkId( |
| 172 mojom::CompositorFrameSinkType::DEFAULT, frame_sink_id); | 145 frame_sink_id); |
| 173 } | 146 } |
| 174 } | 147 } |
| 175 } | 148 } |
| 176 | 149 |
| 177 CompositorFrameSinkData::CompositorFrameSinkData() {} | 150 CompositorFrameSinkData::CompositorFrameSinkData() {} |
| 178 | 151 |
| 179 CompositorFrameSinkData::~CompositorFrameSinkData() {} | 152 CompositorFrameSinkData::~CompositorFrameSinkData() {} |
| 180 | 153 |
| 181 CompositorFrameSinkData::CompositorFrameSinkData( | 154 CompositorFrameSinkData::CompositorFrameSinkData( |
| 182 CompositorFrameSinkData&& other) | 155 CompositorFrameSinkData&& other) |
| 183 : latest_submitted_surface_info(other.latest_submitted_surface_info), | 156 : latest_submitted_surface_info(other.latest_submitted_surface_info), |
| 184 compositor_frame_sink(std::move(other.compositor_frame_sink)) {} | 157 compositor_frame_sink(std::move(other.compositor_frame_sink)) {} |
| 185 | 158 |
| 186 CompositorFrameSinkData& CompositorFrameSinkData::operator=( | 159 CompositorFrameSinkData& CompositorFrameSinkData::operator=( |
| 187 CompositorFrameSinkData&& other) { | 160 CompositorFrameSinkData&& other) { |
| 188 latest_submitted_surface_info = other.latest_submitted_surface_info; | 161 latest_submitted_surface_info = other.latest_submitted_surface_info; |
| 189 compositor_frame_sink = std::move(other.compositor_frame_sink); | 162 compositor_frame_sink = std::move(other.compositor_frame_sink); |
| 190 return *this; | 163 return *this; |
| 191 } | 164 } |
| 192 | 165 |
| 193 } // namespace ws | 166 } // namespace ws |
| 194 } // namespace ui | 167 } // namespace ui |
| OLD | NEW |