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"
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();
22 DeregisterSurface((*it
)->surface_id());
27 void SurfaceManager::RegisterSurface(Surface
* surface
) {
28 DCHECK(thread_checker_
.CalledOnValidThread());
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();
53 satisfied_sequences_
.insert(SurfaceSequence(id_namespace
, *it
));
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
);
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())
81 bool SurfaceManager::SurfaceModified(SurfaceId surface_id
) {
82 DCHECK(thread_checker_
.CalledOnValidThread());
84 FOR_EACH_OBSERVER(SurfaceDamageObserver
, observer_list_
,
85 OnSurfaceDamaged(surface_id
, &changed
));