| 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_id_allocator.h" | 5 #include "cc/surfaces/surface_id_allocator.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_manager.h" | 7 #include "cc/surfaces/surface_manager.h" |
| 8 | 8 |
| 9 namespace cc { | 9 namespace cc { |
| 10 | 10 |
| 11 SurfaceIdAllocator::SurfaceIdAllocator(uint32_t id_namespace) | 11 SurfaceIdAllocator::SurfaceIdAllocator(uint32_t id_namespace) |
| 12 : id_namespace_(id_namespace), next_id_(1u), manager_(nullptr) { | 12 : id_namespace_(id_namespace), next_id_(1u), manager_(nullptr) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 void SurfaceIdAllocator::RegisterSurfaceIdNamespace(SurfaceManager* manager) { | 15 void SurfaceIdAllocator::RegisterSurfaceIdNamespace(SurfaceManager* manager) { |
| 16 DCHECK(!manager_); | 16 DCHECK(!manager_); |
| 17 manager_ = manager; | 17 manager_ = manager; |
| 18 manager_->RegisterSurfaceIdNamespace(id_namespace_); | 18 manager_->RegisterSurfaceIdNamespace(id_namespace_); |
| 19 } | 19 } |
| 20 | 20 |
| 21 SurfaceIdAllocator::~SurfaceIdAllocator() { | 21 SurfaceIdAllocator::~SurfaceIdAllocator() { |
| 22 if (manager_) | 22 if (manager_) |
| 23 manager_->InvalidateSurfaceIdNamespace(id_namespace_); | 23 manager_->InvalidateSurfaceIdNamespace(id_namespace_); |
| 24 } | 24 } |
| 25 | 25 |
| 26 SurfaceId SurfaceIdAllocator::GenerateId() { | 26 SurfaceId SurfaceIdAllocator::GenerateId() { |
| 27 SurfaceId id(static_cast<uint64_t>(id_namespace_) << 32 | next_id_); | 27 SurfaceId id = SurfaceId::FromUnsafeValue( |
| 28 static_cast<uint64_t>(id_namespace_) << 32 | next_id_); |
| 28 next_id_++; | 29 next_id_++; |
| 29 return id; | 30 return id; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 uint32_t SurfaceIdAllocator::NamespaceForId(SurfaceId id) { | 34 uint32_t SurfaceIdAllocator::NamespaceForId(SurfaceId id) { |
| 34 return id.id >> 32; | 35 return id.GetUnsafeValue() >> 32; |
| 35 } | 36 } |
| 36 | 37 |
| 37 } // namespace cc | 38 } // namespace cc |
| OLD | NEW |