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 #ifndef CC_SURFACES_SURFACE_ID_ALLOCATOR_H_
6 #define CC_SURFACES_SURFACE_ID_ALLOCATOR_H_
8 #include "cc/surfaces/surface_id.h"
9 #include "cc/surfaces/surfaces_export.h"
15 // This is a helper class for generating surface IDs within a specified
16 // namespace. This is not threadsafe, to use from multiple threads wrap this
18 class CC_SURFACES_EXPORT SurfaceIdAllocator
{
20 explicit SurfaceIdAllocator(uint32_t id_namespace
);
21 ~SurfaceIdAllocator();
23 SurfaceId
GenerateId();
25 static uint32_t NamespaceForId(SurfaceId id
);
27 // This needs to be called before any sequences with this allocator's
28 // namespace will be used to enforce destruction dependencies.
29 // When this SurfaceIdAllocator is destroyed, its namespace is
30 // automatically invalidated and any remaining sequences with that
31 // namespace will be ignored. This method does not need to be called in
32 // contexts where there is no SurfaceManager (e.g. a renderer process).
33 void RegisterSurfaceIdNamespace(SurfaceManager
* manager
);
35 uint32_t id_namespace() const { return id_namespace_
; }
38 const uint32_t id_namespace_
;
40 SurfaceManager
* manager_
;
42 DISALLOW_COPY_AND_ASSIGN(SurfaceIdAllocator
);
47 #endif // CC_SURFACES_SURFACE_ID_ALLOCATOR_H_