| 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 #ifndef CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ | 5 #ifndef CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ |
| 6 #define CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ | 6 #define CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "cc/surfaces/surface_id.h" | 11 #include "cc/surfaces/surface_id.h" |
| 12 #include "cc/surfaces/surfaces_export.h" | 12 #include "cc/surfaces/surfaces_export.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 class SurfaceManager; | 16 class SurfaceManager; |
| 17 | 17 |
| 18 // This is a helper class for generating surface IDs within a specified | 18 // This is a helper class for generating surface IDs within a specified |
| 19 // namespace. This is not threadsafe, to use from multiple threads wrap this | 19 // namespace. This is not threadsafe, to use from multiple threads wrap this |
| 20 // class in a mutex. | 20 // class in a mutex. |
| 21 class CC_SURFACES_EXPORT SurfaceIdAllocator { | 21 class CC_SURFACES_EXPORT SurfaceIdAllocator { |
| 22 public: | 22 public: |
| 23 explicit SurfaceIdAllocator(uint32_t id_namespace); | 23 explicit SurfaceIdAllocator(uint32_t id_namespace); |
| 24 ~SurfaceIdAllocator(); | 24 ~SurfaceIdAllocator(); |
| 25 | 25 |
| 26 SurfaceId GenerateId(); | 26 SurfaceId GenerateId(); |
| 27 | 27 |
| 28 static uint32_t NamespaceForId(SurfaceId id); | |
| 29 | |
| 30 // This needs to be called before any sequences with this allocator's | 28 // This needs to be called before any sequences with this allocator's |
| 31 // namespace will be used to enforce destruction dependencies. | 29 // namespace will be used to enforce destruction dependencies. |
| 32 // When this SurfaceIdAllocator is destroyed, its namespace is | 30 // When this SurfaceIdAllocator is destroyed, its namespace is |
| 33 // automatically invalidated and any remaining sequences with that | 31 // automatically invalidated and any remaining sequences with that |
| 34 // namespace will be ignored. This method does not need to be called in | 32 // namespace will be ignored. This method does not need to be called in |
| 35 // contexts where there is no SurfaceManager (e.g. a renderer process). | 33 // contexts where there is no SurfaceManager (e.g. a renderer process). |
| 36 void RegisterSurfaceIdNamespace(SurfaceManager* manager); | 34 void RegisterSurfaceIdNamespace(SurfaceManager* manager); |
| 37 | 35 |
| 38 uint32_t id_namespace() const { return id_namespace_; } | 36 uint32_t id_namespace() const { return id_namespace_; } |
| 39 | 37 |
| 40 private: | 38 private: |
| 41 const uint32_t id_namespace_; | 39 const uint32_t id_namespace_; |
| 42 uint32_t next_id_; | 40 uint32_t next_id_; |
| 43 SurfaceManager* manager_; | 41 SurfaceManager* manager_; |
| 44 | 42 |
| 45 DISALLOW_COPY_AND_ASSIGN(SurfaceIdAllocator); | 43 DISALLOW_COPY_AND_ASSIGN(SurfaceIdAllocator); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 } // namespace cc | 46 } // namespace cc |
| 49 | 47 |
| 50 #endif // CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ | 48 #endif // CC_SURFACES_SURFACE_ID_ALLOCATOR_H_ |
| OLD | NEW |