| 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 "services/ui/ws/frame_generator.h" | 5 #include "services/ui/ws/frame_generator.h" |
| 6 | 6 |
| 7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/quads/render_pass.h" | 9 #include "cc/quads/render_pass.h" |
| 10 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
| 11 #include "cc/quads/shared_quad_state.h" | 11 #include "cc/quads/shared_quad_state.h" |
| 12 #include "cc/quads/surface_draw_quad.h" | 12 #include "cc/quads/surface_draw_quad.h" |
| 13 #include "cc/surfaces/surface.h" | |
| 14 #include "cc/surfaces/surface_id.h" | 13 #include "cc/surfaces/surface_id.h" |
| 15 #include "gpu/ipc/client/gpu_channel_host.h" | 14 #include "gpu/ipc/client/gpu_channel_host.h" |
| 16 #include "services/ui/surfaces/display_compositor.h" | 15 #include "services/ui/surfaces/display_compositor.h" |
| 17 #include "services/ui/surfaces/surfaces_context_provider.h" | 16 #include "services/ui/surfaces/surfaces_context_provider.h" |
| 18 #include "services/ui/ws/frame_generator_delegate.h" | 17 #include "services/ui/ws/frame_generator_delegate.h" |
| 19 #include "services/ui/ws/server_window.h" | 18 #include "services/ui/ws/server_window.h" |
| 20 #include "services/ui/ws/server_window_compositor_frame_sink.h" | |
| 21 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 19 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 20 #include "services/ui/ws/server_window_delegate.h" |
| 22 | 21 |
| 23 namespace ui { | 22 namespace ui { |
| 24 | 23 |
| 25 namespace ws { | 24 namespace ws { |
| 26 | 25 |
| 27 FrameGenerator::FrameGenerator( | 26 FrameGenerator::FrameGenerator(FrameGeneratorDelegate* delegate, |
| 28 FrameGeneratorDelegate* delegate, | 27 ServerWindow* root_window) |
| 29 ServerWindow* root_window, | |
| 30 scoped_refptr<DisplayCompositor> display_compositor) | |
| 31 : delegate_(delegate), | 28 : delegate_(delegate), |
| 32 display_compositor_(display_compositor), | |
| 33 frame_sink_id_( | 29 frame_sink_id_( |
| 34 WindowIdToTransportId(root_window->id()), | 30 WindowIdToTransportId(root_window->id()), |
| 35 static_cast<uint32_t>(mojom::CompositorFrameSinkType::DEFAULT)), | 31 static_cast<uint32_t>(mojom::CompositorFrameSinkType::DEFAULT)), |
| 36 root_window_(root_window), | 32 root_window_(root_window), |
| 37 draw_timer_(false, false), | 33 draw_timer_(false, false), |
| 38 binding_(this), | 34 binding_(this), |
| 39 weak_factory_(this) { | 35 weak_factory_(this) { |
| 40 DCHECK(delegate_); | 36 DCHECK(delegate_); |
| 41 surface_sequence_generator_.set_frame_sink_id(frame_sink_id_); | 37 surface_sequence_generator_.set_frame_sink_id(frame_sink_id_); |
| 42 } | 38 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 236 } |
| 241 } | 237 } |
| 242 | 238 |
| 243 void FrameGenerator::AddOrUpdateSurfaceReference( | 239 void FrameGenerator::AddOrUpdateSurfaceReference( |
| 244 mojom::CompositorFrameSinkType type, | 240 mojom::CompositorFrameSinkType type, |
| 245 ServerWindow* window) { | 241 ServerWindow* window) { |
| 246 cc::SurfaceId surface_id = | 242 cc::SurfaceId surface_id = |
| 247 window->compositor_frame_sink_manager()->GetLatestSurfaceId(type); | 243 window->compositor_frame_sink_manager()->GetLatestSurfaceId(type); |
| 248 if (surface_id.is_null()) | 244 if (surface_id.is_null()) |
| 249 return; | 245 return; |
| 250 // TODO(fsamuel): Use mojo interface to give root window a surface reference. | |
| 251 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | |
| 252 auto it = dependencies_.find(surface_id.frame_sink_id()); | 246 auto it = dependencies_.find(surface_id.frame_sink_id()); |
| 253 if (it == dependencies_.end()) { | 247 if (it == dependencies_.end()) { |
| 254 cc::Surface* surface = surface_manager->GetSurfaceForId(surface_id); | |
| 255 if (!surface) { | |
| 256 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " | |
| 257 << surface_id.ToString(); | |
| 258 return; | |
| 259 } | |
| 260 SurfaceDependency dependency = { | 248 SurfaceDependency dependency = { |
| 261 surface_id.local_frame_id(), | 249 surface_id.local_frame_id(), |
| 262 surface_sequence_generator_.CreateSurfaceSequence()}; | 250 surface_sequence_generator_.CreateSurfaceSequence()}; |
| 263 surface->AddDestructionDependency(dependency.sequence); | |
| 264 dependencies_[surface_id.frame_sink_id()] = dependency; | 251 dependencies_[surface_id.frame_sink_id()] = dependency; |
| 252 GetDisplayCompositor()->AddSurfaceReference(surface_id, |
| 253 dependency.sequence); |
| 265 // Observe |window_surface|'s window so that we can release references when | 254 // Observe |window_surface|'s window so that we can release references when |
| 266 // the window is destroyed. | 255 // the window is destroyed. |
| 267 Add(window); | 256 Add(window); |
| 268 return; | 257 return; |
| 269 } | 258 } |
| 270 | 259 |
| 271 // We are already holding a reference to this surface so there's no work to do | 260 // We are already holding a reference to this surface so there's no work to do |
| 272 // here. | 261 // here. |
| 273 if (surface_id.local_frame_id() == it->second.local_frame_id) | 262 if (surface_id.local_frame_id() == it->second.local_frame_id) |
| 274 return; | 263 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 AddOrUpdateSurfaceReference(type, window); | 276 AddOrUpdateSurfaceReference(type, window); |
| 288 } | 277 } |
| 289 | 278 |
| 290 void FrameGenerator::ReleaseFrameSinkReference( | 279 void FrameGenerator::ReleaseFrameSinkReference( |
| 291 const cc::FrameSinkId& frame_sink_id) { | 280 const cc::FrameSinkId& frame_sink_id) { |
| 292 auto it = dependencies_.find(frame_sink_id); | 281 auto it = dependencies_.find(frame_sink_id); |
| 293 if (it == dependencies_.end()) | 282 if (it == dependencies_.end()) |
| 294 return; | 283 return; |
| 295 std::vector<uint32_t> sequences; | 284 std::vector<uint32_t> sequences; |
| 296 sequences.push_back(it->second.sequence.sequence); | 285 sequences.push_back(it->second.sequence.sequence); |
| 297 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | 286 GetDisplayCompositor()->ReturnSurfaceReferences(frame_sink_id, sequences); |
| 298 surface_manager->DidSatisfySequences(frame_sink_id_, &sequences); | |
| 299 dependencies_.erase(it); | 287 dependencies_.erase(it); |
| 300 } | 288 } |
| 301 | 289 |
| 302 void FrameGenerator::ReleaseAllSurfaceReferences() { | 290 void FrameGenerator::ReleaseAllSurfaceReferences() { |
| 303 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | |
| 304 std::vector<uint32_t> sequences; | 291 std::vector<uint32_t> sequences; |
| 305 for (auto& dependency : dependencies_) | 292 for (auto& dependency : dependencies_) |
| 306 sequences.push_back(dependency.second.sequence.sequence); | 293 sequences.push_back(dependency.second.sequence.sequence); |
| 307 surface_manager->DidSatisfySequences(frame_sink_id_, &sequences); | 294 GetDisplayCompositor()->ReturnSurfaceReferences(frame_sink_id_, sequences); |
| 308 dependencies_.clear(); | 295 dependencies_.clear(); |
| 309 } | 296 } |
| 310 | 297 |
| 298 ui::DisplayCompositor* FrameGenerator::GetDisplayCompositor() { |
| 299 return root_window_->delegate()->GetDisplayCompositor(); |
| 300 } |
| 301 |
| 311 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { | 302 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { |
| 312 Remove(window); | 303 Remove(window); |
| 313 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = | 304 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = |
| 314 window->compositor_frame_sink_manager(); | 305 window->compositor_frame_sink_manager(); |
| 315 // If FrameGenerator was observing |window|, then that means it had a | 306 // If FrameGenerator was observing |window|, then that means it had a |
| 316 // CompositorFrame at some point in time and should have a | 307 // CompositorFrame at some point in time and should have a |
| 317 // ServerWindowCompositorFrameSinkManager. | 308 // ServerWindowCompositorFrameSinkManager. |
| 318 DCHECK(compositor_frame_sink_manager); | 309 DCHECK(compositor_frame_sink_manager); |
| 319 | 310 |
| 320 cc::SurfaceId default_surface_id = | 311 cc::SurfaceId default_surface_id = |
| 321 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 312 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 322 mojom::CompositorFrameSinkType::DEFAULT); | 313 mojom::CompositorFrameSinkType::DEFAULT); |
| 323 if (!default_surface_id.is_null()) | 314 if (!default_surface_id.is_null()) |
| 324 ReleaseFrameSinkReference(default_surface_id.frame_sink_id()); | 315 ReleaseFrameSinkReference(default_surface_id.frame_sink_id()); |
| 325 | 316 |
| 326 cc::SurfaceId underlay_surface_id = | 317 cc::SurfaceId underlay_surface_id = |
| 327 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 318 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 328 mojom::CompositorFrameSinkType::UNDERLAY); | 319 mojom::CompositorFrameSinkType::UNDERLAY); |
| 329 if (!underlay_surface_id.is_null()) | 320 if (!underlay_surface_id.is_null()) |
| 330 ReleaseFrameSinkReference(underlay_surface_id.frame_sink_id()); | 321 ReleaseFrameSinkReference(underlay_surface_id.frame_sink_id()); |
| 331 } | 322 } |
| 332 | 323 |
| 333 } // namespace ws | 324 } // namespace ws |
| 334 | 325 |
| 335 } // namespace ui | 326 } // namespace ui |
| OLD | NEW |