Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / cc / surfaces / surface_manager.cc
blob117d82ab659394458f678ac13da90eaa15b9d00b
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)->surface_id());
23 delete *it;
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::Destroy(scoped_ptr<Surface> surface) {
42 DCHECK(thread_checker_.CalledOnValidThread());
43 surfaces_to_destroy_.push_back(surface.release());
44 SearchForSatisfaction();
47 void SurfaceManager::DidSatisfySequences(uint32_t id_namespace,
48 std::vector<uint32_t>* sequence) {
49 DCHECK(thread_checker_.CalledOnValidThread());
50 for (std::vector<uint32_t>::iterator it = sequence->begin();
51 it != sequence->end();
52 ++it) {
53 satisfied_sequences_.insert(SurfaceSequence(id_namespace, *it));
55 sequence->clear();
56 SearchForSatisfaction();
59 void SurfaceManager::SearchForSatisfaction() {
60 for (SurfaceDestroyList::iterator dest_it = surfaces_to_destroy_.begin();
61 dest_it != surfaces_to_destroy_.end();) {
62 (*dest_it)->SatisfyDestructionDependencies(&satisfied_sequences_);
63 if (!(*dest_it)->GetDestructionDependencyCount()) {
64 scoped_ptr<Surface> surf(*dest_it);
65 DeregisterSurface(surf->surface_id());
66 dest_it = surfaces_to_destroy_.erase(dest_it);
67 } else {
68 ++dest_it;
73 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75 SurfaceMap::iterator it = surface_map_.find(surface_id);
76 if (it == surface_map_.end())
77 return NULL;
78 return it->second;
81 bool SurfaceManager::SurfaceModified(SurfaceId surface_id) {
82 DCHECK(thread_checker_.CalledOnValidThread());
83 bool changed = false;
84 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_,
85 OnSurfaceDamaged(surface_id, &changed));
86 return changed;
89 } // namespace cc