Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: cc/surfaces/surface_id_allocator.cc

Issue 1496103002: Reusing base::IdType<...> to implement SurfaceId. Base URL: https://chromium.googlesource.com/chromium/src.git@type-safe-id-base
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/surfaces/surface_id.h ('k') | cc/surfaces/surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « cc/surfaces/surface_id.h ('k') | cc/surfaces/surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698