Make |track_| in MediaStreamTrack const. and a couple of other cosmetic changes.
[chromium-blink-merge.git] / cc / surfaces / surface_manager.cc
blob920f464cdd03595b76c260b287d41a560fa6b9a4
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
3 // found in the LICENSE file.
5 #include "cc/surfaces/surface_manager.h"
7 #include "base/logging.h"
8 #include "cc/surfaces/surface.h"
9 #include "cc/surfaces/surface_id_allocator.h"
11 namespace cc {
13 SurfaceManager::SurfaceManager() {
14 thread_checker_.DetachFromThread();
17 SurfaceManager::~SurfaceManager() {
18 DCHECK(thread_checker_.CalledOnValidThread());
19 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin();
20 it != surfaces_to_destroy_.end();
21 ++it) {
22 DeregisterSurface(it->first->surface_id());
23 delete it->first;
27 void SurfaceManager::RegisterSurface(Surface* surface) {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 DCHECK(surface);
30 DCHECK(!surface_map_.count(surface->surface_id()));
31 surface_map_[surface->surface_id()] = surface;
34 void SurfaceManager::DeregisterSurface(SurfaceId surface_id) {
35 DCHECK(thread_checker_.CalledOnValidThread());
36 SurfaceMap::iterator it = surface_map_.find(surface_id);
37 DCHECK(it != surface_map_.end());
38 surface_map_.erase(it);
41 void SurfaceManager::DestroyOnSequence(
42 scoped_ptr<Surface> surface,
43 const std::set<SurfaceSequence>& dependency_set) {
44 surfaces_to_destroy_.push_back(make_pair(surface.release(), dependency_set));
45 SearchForSatisfaction();
48 void SurfaceManager::DidSatisfySequences(SurfaceId id,
49 std::vector<uint32_t>* sequence) {
50 for (std::vector<uint32_t>::iterator it = sequence->begin();
51 it != sequence->end();
52 ++it) {
53 satisfied_sequences_.insert(
54 SurfaceSequence(SurfaceIdAllocator::NamespaceForId(id), *it));
56 sequence->clear();
57 SearchForSatisfaction();
60 void SurfaceManager::SearchForSatisfaction() {
61 for (SurfaceDestroyList::iterator dest_it = surfaces_to_destroy_.begin();
62 dest_it != surfaces_to_destroy_.end();) {
63 std::set<SurfaceSequence>& dependency_set = dest_it->second;
65 for (std::set<SurfaceSequence>::iterator it = dependency_set.begin();
66 it != dependency_set.end();) {
67 if (satisfied_sequences_.count(*it) > 0) {
68 satisfied_sequences_.erase(*it);
69 std::set<SurfaceSequence>::iterator old_it = it;
70 ++it;
71 dependency_set.erase(old_it);
72 } else {
73 ++it;
76 if (dependency_set.empty()) {
77 scoped_ptr<Surface> surf(dest_it->first);
78 DeregisterSurface(surf->surface_id());
79 dest_it = surfaces_to_destroy_.erase(dest_it);
80 } else {
81 ++dest_it;
86 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) {
87 DCHECK(thread_checker_.CalledOnValidThread());
88 SurfaceMap::iterator it = surface_map_.find(surface_id);
89 if (it == surface_map_.end())
90 return NULL;
91 return it->second;
94 void SurfaceManager::SurfaceModified(SurfaceId surface_id) {
95 DCHECK(thread_checker_.CalledOnValidThread());
96 FOR_EACH_OBSERVER(
97 SurfaceDamageObserver, observer_list_, OnSurfaceDamaged(surface_id));
100 } // namespace cc