| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "cc/surfaces/surface_manager.h" | 10 #include "cc/surfaces/surface_manager.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 SurfaceIdAllocator::SurfaceIdAllocator(uint32_t client_id) | 14 SurfaceIdAllocator::SurfaceIdAllocator(uint32_t client_id) |
| 15 : client_id_(client_id), next_id_(1u), manager_(nullptr) {} | 15 : client_id_(client_id), next_id_(1u) {} |
| 16 | |
| 17 void SurfaceIdAllocator::RegisterSurfaceClientId(SurfaceManager* manager) { | |
| 18 DCHECK(!manager_); | |
| 19 manager_ = manager; | |
| 20 manager_->RegisterSurfaceClientId(client_id_); | |
| 21 } | |
| 22 | 16 |
| 23 SurfaceIdAllocator::~SurfaceIdAllocator() { | 17 SurfaceIdAllocator::~SurfaceIdAllocator() { |
| 24 if (manager_) | |
| 25 manager_->InvalidateSurfaceClientId(client_id_); | |
| 26 } | 18 } |
| 27 | 19 |
| 28 SurfaceId SurfaceIdAllocator::GenerateId() { | 20 SurfaceId SurfaceIdAllocator::GenerateId() { |
| 29 uint64_t nonce = base::RandUint64(); | 21 uint64_t nonce = base::RandUint64(); |
| 30 SurfaceId id(client_id_, next_id_, nonce); | 22 SurfaceId id(client_id_, next_id_, nonce); |
| 31 next_id_++; | 23 next_id_++; |
| 32 return id; | 24 return id; |
| 33 } | 25 } |
| 34 | 26 |
| 35 } // namespace cc | 27 } // namespace cc |
| OLD | NEW |