This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / cc / surfaces / surface_id_allocator.cc
blob04f60d9fad7fcf6b7688e66ea0309f783fa8eb8a
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_id_allocator.h"
7 #include "cc/surfaces/surface_manager.h"
9 namespace cc {
11 SurfaceIdAllocator::SurfaceIdAllocator(uint32_t id_namespace)
12 : id_namespace_(id_namespace), next_id_(1u), manager_(nullptr) {
15 void SurfaceIdAllocator::RegisterSurfaceIdNamespace(SurfaceManager* manager) {
16 DCHECK(!manager_);
17 manager_ = manager;
18 manager_->RegisterSurfaceIdNamespace(id_namespace_);
21 SurfaceIdAllocator::~SurfaceIdAllocator() {
22 if (manager_)
23 manager_->InvalidateSurfaceIdNamespace(id_namespace_);
26 SurfaceId SurfaceIdAllocator::GenerateId() {
27 SurfaceId id(static_cast<uint64_t>(id_namespace_) << 32 | next_id_);
28 next_id_++;
29 return id;
32 // static
33 uint32_t SurfaceIdAllocator::NamespaceForId(SurfaceId id) {
34 return id.id >> 32;
37 } // namespace cc