| 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> |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 312 } |
| 313 | 313 |
| 314 void SurfaceManager::AddSurfaceReferenceImpl(const SurfaceId& parent_id, | 314 void SurfaceManager::AddSurfaceReferenceImpl(const SurfaceId& parent_id, |
| 315 const SurfaceId& child_id) { | 315 const SurfaceId& child_id) { |
| 316 if (parent_id.frame_sink_id() == child_id.frame_sink_id()) { | 316 if (parent_id.frame_sink_id() == child_id.frame_sink_id()) { |
| 317 DLOG(ERROR) << "Cannot add self reference from " << parent_id << " to " | 317 DLOG(ERROR) << "Cannot add self reference from " << parent_id << " to " |
| 318 << child_id; | 318 << child_id; |
| 319 return; | 319 return; |
| 320 } | 320 } |
| 321 | 321 |
| 322 // We trust that |parent_id| either exists or is about to exist, since is not |
| 323 // sent over IPC. We don't trust |child_id|, since it is sent over IPC. |
| 324 if (surface_map_.count(child_id) == 0) { |
| 325 DLOG(ERROR) << "No surface in map for " << child_id.ToString(); |
| 326 return; |
| 327 } |
| 328 |
| 322 parent_to_child_refs_[parent_id].insert(child_id); | 329 parent_to_child_refs_[parent_id].insert(child_id); |
| 323 child_to_parent_refs_[child_id].insert(parent_id); | 330 child_to_parent_refs_[child_id].insert(parent_id); |
| 324 | 331 |
| 325 if (HasTemporaryReference(child_id)) | 332 if (HasTemporaryReference(child_id)) |
| 326 RemoveTemporaryReference(child_id, true); | 333 RemoveTemporaryReference(child_id, true); |
| 327 } | 334 } |
| 328 | 335 |
| 329 void SurfaceManager::RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, | 336 void SurfaceManager::RemoveSurfaceReferenceImpl(const SurfaceId& parent_id, |
| 330 const SurfaceId& child_id) { | 337 const SurfaceId& child_id) { |
| 331 if (parent_to_child_refs_.count(parent_id) == 0 || | 338 if (parent_to_child_refs_.count(parent_id) == 0 || |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { | 461 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { |
| 455 CHECK(thread_checker_.CalledOnValidThread()); | 462 CHECK(thread_checker_.CalledOnValidThread()); |
| 456 | 463 |
| 457 if (lifetime_type_ == LifetimeType::REFERENCES) { | 464 if (lifetime_type_ == LifetimeType::REFERENCES) { |
| 458 // We can get into a situation where multiple CompositorFrames arrive for | 465 // We can get into a situation where multiple CompositorFrames arrive for |
| 459 // a CompositorFrameSink before the client can add any references for the | 466 // 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 | 467 // 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 | 468 // destroyed in SurfaceFactory and then if there are no references it will |
| 462 // be deleted during surface GC. A temporary reference, removed when a | 469 // be deleted during surface GC. A temporary reference, removed when a |
| 463 // real reference is received, is added to prevent this from happening. | 470 // real reference is received, is added to prevent this from happening. |
| 464 auto it = child_to_parent_refs_.find(surface_info.id()); | 471 AddTemporaryReference(surface_info.id()); |
| 465 // 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 | |
| 467 // use array notation into maps in tests (see https://crbug.com/691115). | |
| 468 bool has_real_reference = | |
| 469 it != child_to_parent_refs_.end() && !it->second.empty(); | |
| 470 if (!has_real_reference) | |
| 471 AddTemporaryReference(surface_info.id()); | |
| 472 } | 472 } |
| 473 | 473 |
| 474 for (auto& observer : observer_list_) | 474 for (auto& observer : observer_list_) |
| 475 observer.OnSurfaceCreated(surface_info); | 475 observer.OnSurfaceCreated(surface_info); |
| 476 } | 476 } |
| 477 | 477 |
| 478 void SurfaceManager::UnregisterSurface(const SurfaceId& surface_id) { | 478 void SurfaceManager::UnregisterSurface(const SurfaceId& surface_id) { |
| 479 DCHECK(thread_checker_.CalledOnValidThread()); | 479 DCHECK(thread_checker_.CalledOnValidThread()); |
| 480 SurfaceMap::iterator it = surface_map_.find(surface_id); | 480 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| 481 DCHECK(it != surface_map_.end()); | 481 DCHECK(it != surface_map_.end()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | 524 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
| 525 std::sort(children.begin(), children.end()); | 525 std::sort(children.begin(), children.end()); |
| 526 | 526 |
| 527 for (const SurfaceId& child_id : children) | 527 for (const SurfaceId& child_id : children) |
| 528 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 528 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 #endif // DCHECK_IS_ON() | 531 #endif // DCHECK_IS_ON() |
| 532 | 532 |
| 533 } // namespace cc | 533 } // namespace cc |
| OLD | NEW |