OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/surfaces/surface_manager.h" | 5 #include "cc/surfaces/surface_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "cc/surfaces/compositor_frame_sink_support.h" |
14 #include "cc/surfaces/direct_surface_reference_factory.h" | 15 #include "cc/surfaces/direct_surface_reference_factory.h" |
15 #include "cc/surfaces/local_surface_id_allocator.h" | 16 #include "cc/surfaces/local_surface_id_allocator.h" |
16 #include "cc/surfaces/surface.h" | 17 #include "cc/surfaces/surface.h" |
17 #include "cc/surfaces/surface_factory_client.h" | |
18 #include "cc/surfaces/surface_info.h" | 18 #include "cc/surfaces/surface_info.h" |
19 | 19 |
20 #if DCHECK_IS_ON() | 20 #if DCHECK_IS_ON() |
21 #include <sstream> | 21 #include <sstream> |
22 #endif | 22 #endif |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 | 25 |
26 SurfaceManager::SurfaceManager(LifetimeType lifetime_type) | 26 SurfaceManager::SurfaceManager(LifetimeType lifetime_type) |
27 : lifetime_type_(lifetime_type), | 27 : lifetime_type_(lifetime_type), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) { | 68 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) { |
69 dependency_tracker_ = std::move(dependency_tracker); | 69 dependency_tracker_ = std::move(dependency_tracker); |
70 } | 70 } |
71 | 71 |
72 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) { | 72 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) { |
73 if (dependency_tracker_) | 73 if (dependency_tracker_) |
74 dependency_tracker_->RequestSurfaceResolution(pending_surface); | 74 dependency_tracker_->RequestSurfaceResolution(pending_surface); |
75 } | 75 } |
76 | 76 |
77 std::unique_ptr<Surface> SurfaceManager::CreateSurface( | 77 std::unique_ptr<Surface> SurfaceManager::CreateSurface( |
78 base::WeakPtr<SurfaceFactory> surface_factory, | 78 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
79 const LocalSurfaceId& local_surface_id) { | 79 const LocalSurfaceId& local_surface_id) { |
80 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
81 DCHECK(local_surface_id.is_valid() && surface_factory); | 81 DCHECK(local_surface_id.is_valid() && compositor_frame_sink_support); |
82 | 82 |
83 SurfaceId surface_id(surface_factory->frame_sink_id(), local_surface_id); | 83 SurfaceId surface_id(compositor_frame_sink_support->frame_sink_id(), |
| 84 local_surface_id); |
84 | 85 |
85 // If no surface with this SurfaceId exists, simply create the surface and | 86 // If no surface with this SurfaceId exists, simply create the surface and |
86 // return. | 87 // return. |
87 auto surface_iter = surface_map_.find(surface_id); | 88 auto surface_iter = surface_map_.find(surface_id); |
88 if (surface_iter == surface_map_.end()) { | 89 if (surface_iter == surface_map_.end()) { |
89 auto surface = base::MakeUnique<Surface>(surface_id, surface_factory); | 90 auto surface = |
| 91 base::MakeUnique<Surface>(surface_id, compositor_frame_sink_support); |
90 surface_map_[surface->surface_id()] = surface.get(); | 92 surface_map_[surface->surface_id()] = surface.get(); |
91 return surface; | 93 return surface; |
92 } | 94 } |
93 | 95 |
94 // If a surface with this SurfaceId exists and it's not marked as destroyed, | 96 // If a surface with this SurfaceId exists and it's not marked as destroyed, |
95 // we should not receive a request to create a new surface with the same | 97 // we should not receive a request to create a new surface with the same |
96 // SurfaceId. | 98 // SurfaceId. |
97 DCHECK(surface_iter->second->destroyed()); | 99 DCHECK(surface_iter->second->destroyed()); |
98 | 100 |
99 // If a surface with this SurfaceId exists and it's marked as destroyed, | 101 // If a surface with this SurfaceId exists and it's marked as destroyed, |
100 // it means it's in the garbage collector's queue. We simply take it out of | 102 // it means it's in the garbage collector's queue. We simply take it out of |
101 // the queue and reuse it. | 103 // the queue and reuse it. |
102 auto it = | 104 auto it = |
103 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), | 105 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), |
104 [&surface_id](const std::unique_ptr<Surface>& surface) { | 106 [&surface_id](const std::unique_ptr<Surface>& surface) { |
105 return surface->surface_id() == surface_id; | 107 return surface->surface_id() == surface_id; |
106 }); | 108 }); |
107 DCHECK(it != surfaces_to_destroy_.end()); | 109 DCHECK(it != surfaces_to_destroy_.end()); |
108 std::unique_ptr<Surface> surface = std::move(*it); | 110 std::unique_ptr<Surface> surface = std::move(*it); |
109 surfaces_to_destroy_.erase(it); | 111 surfaces_to_destroy_.erase(it); |
110 surface->set_destroyed(false); | 112 surface->set_destroyed(false); |
111 DCHECK_EQ(surface_factory.get(), surface->factory().get()); | 113 DCHECK_EQ(compositor_frame_sink_support.get(), |
| 114 surface->compositor_frame_sink_support().get()); |
112 return surface; | 115 return surface; |
113 } | 116 } |
114 | 117 |
115 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { | 118 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { |
116 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
117 surface->set_destroyed(true); | 120 surface->set_destroyed(true); |
118 surfaces_to_destroy_.push_back(std::move(surface)); | 121 surfaces_to_destroy_.push_back(std::move(surface)); |
119 GarbageCollectSurfaces(); | 122 GarbageCollectSurfaces(); |
120 } | 123 } |
121 | 124 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 for (auto iter = begin_iter; iter != end_iter; ++iter) | 396 for (auto iter = begin_iter; iter != end_iter; ++iter) |
394 temporary_references_.erase(SurfaceId(frame_sink_id, *iter)); | 397 temporary_references_.erase(SurfaceId(frame_sink_id, *iter)); |
395 frame_sink_temp_refs.erase(begin_iter, end_iter); | 398 frame_sink_temp_refs.erase(begin_iter, end_iter); |
396 | 399 |
397 // If last temporary reference is removed for |frame_sink_id| then cleanup | 400 // If last temporary reference is removed for |frame_sink_id| then cleanup |
398 // range tracking map entry. | 401 // range tracking map entry. |
399 if (frame_sink_temp_refs.empty()) | 402 if (frame_sink_temp_refs.empty()) |
400 temporary_reference_ranges_.erase(frame_sink_id); | 403 temporary_reference_ranges_.erase(frame_sink_id); |
401 } | 404 } |
402 | 405 |
403 void SurfaceManager::RegisterSurfaceFactoryClient( | 406 void SurfaceManager::RegisterCompositorFrameSinkSupport( |
404 const FrameSinkId& frame_sink_id, | 407 const FrameSinkId& frame_sink_id, |
405 SurfaceFactoryClient* client) { | 408 CompositorFrameSinkSupport* support) { |
406 framesink_manager_.RegisterSurfaceFactoryClient(frame_sink_id, client); | 409 framesink_manager_.RegisterCompositorFrameSinkSupport(frame_sink_id, support); |
407 } | 410 } |
408 | 411 |
409 void SurfaceManager::UnregisterSurfaceFactoryClient( | 412 void SurfaceManager::UnregisterCompositorFrameSinkSupport( |
410 const FrameSinkId& frame_sink_id) { | 413 const FrameSinkId& frame_sink_id) { |
411 framesink_manager_.UnregisterSurfaceFactoryClient(frame_sink_id); | 414 framesink_manager_.UnregisterCompositorFrameSinkSupport(frame_sink_id); |
412 } | 415 } |
413 | 416 |
414 void SurfaceManager::RegisterBeginFrameSource( | 417 void SurfaceManager::RegisterBeginFrameSource( |
415 BeginFrameSource* source, | 418 BeginFrameSource* source, |
416 const FrameSinkId& frame_sink_id) { | 419 const FrameSinkId& frame_sink_id) { |
417 framesink_manager_.RegisterBeginFrameSource(source, frame_sink_id); | 420 framesink_manager_.RegisterBeginFrameSource(source, frame_sink_id); |
418 } | 421 } |
419 | 422 |
420 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) { | 423 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) { |
421 framesink_manager_.UnregisterBeginFrameSource(source); | 424 framesink_manager_.UnregisterBeginFrameSource(source); |
(...skipping 29 matching lines...) Expand all Loading... |
451 return changed; | 454 return changed; |
452 } | 455 } |
453 | 456 |
454 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { | 457 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { |
455 CHECK(thread_checker_.CalledOnValidThread()); | 458 CHECK(thread_checker_.CalledOnValidThread()); |
456 | 459 |
457 if (lifetime_type_ == LifetimeType::REFERENCES) { | 460 if (lifetime_type_ == LifetimeType::REFERENCES) { |
458 // We can get into a situation where multiple CompositorFrames arrive for | 461 // We can get into a situation where multiple CompositorFrames arrive for |
459 // a CompositorFrameSink before the client can add any references for the | 462 // a CompositorFrameSink before the client can add any references for the |
460 // frame. When the second frame with a new size arrives, the first will be | 463 // frame. When the second frame with a new size arrives, the first will be |
461 // destroyed in SurfaceFactory and then if there are no references it will | 464 // destroyed in CompositorFrameSinkSupport and then if there are no |
462 // be deleted during surface GC. A temporary reference, removed when a | 465 // references it will be deleted during surface GC. A temporary reference, |
463 // real reference is received, is added to prevent this from happening. | 466 // removed when a real reference is received, is added to prevent this from |
| 467 // happening. |
464 auto it = child_to_parent_refs_.find(surface_info.id()); | 468 auto it = child_to_parent_refs_.find(surface_info.id()); |
465 // TODO(fsamuel): Tests create empty sets and so we also need to check that | 469 // TODO(fsamuel): Tests create empty sets and so we also need to check that |
466 // they're not empty here. Ideally tests shouldn't do that and we shouldn't | 470 // they're not empty here. Ideally tests shouldn't do that and we shouldn't |
467 // use array notation into maps in tests (see https://crbug.com/691115). | 471 // use array notation into maps in tests (see https://crbug.com/691115). |
468 bool has_real_reference = | 472 bool has_real_reference = |
469 it != child_to_parent_refs_.end() && !it->second.empty(); | 473 it != child_to_parent_refs_.end() && !it->second.empty(); |
470 if (!has_real_reference) | 474 if (!has_real_reference) |
471 AddTemporaryReference(surface_info.id()); | 475 AddTemporaryReference(surface_info.id()); |
472 } | 476 } |
473 | 477 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | 528 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
525 std::sort(children.begin(), children.end()); | 529 std::sort(children.begin(), children.end()); |
526 | 530 |
527 for (const SurfaceId& child_id : children) | 531 for (const SurfaceId& child_id : children) |
528 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 532 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
529 } | 533 } |
530 } | 534 } |
531 #endif // DCHECK_IS_ON() | 535 #endif // DCHECK_IS_ON() |
532 | 536 |
533 } // namespace cc | 537 } // namespace cc |
OLD | NEW |