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