diff options
-rw-r--r-- | cc/surfaces/surface_id.h | 3 | ||||
-rw-r--r-- | cc/surfaces/surface_unittest.cc | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/cc/surfaces/surface_id.h b/cc/surfaces/surface_id.h index c0c4410..bbc485f 100644 --- a/cc/surfaces/surface_id.h +++ b/cc/surfaces/surface_id.h @@ -18,6 +18,9 @@ struct SurfaceId { bool is_null() const { return id == 0; } + // See SurfaceIdAllocator::GenerateId. + uint32_t id_namespace() const { return id >> 32; } + uint64_t id; }; diff --git a/cc/surfaces/surface_unittest.cc b/cc/surfaces/surface_unittest.cc index 72070c6..03ffc3a 100644 --- a/cc/surfaces/surface_unittest.cc +++ b/cc/surfaces/surface_unittest.cc @@ -5,6 +5,7 @@ #include "cc/surfaces/surface.h" #include "cc/surfaces/surface_factory.h" #include "cc/surfaces/surface_factory_client.h" +#include "cc/surfaces/surface_id_allocator.h" #include "cc/surfaces/surface_manager.h" #include "cc/test/scheduler_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -44,5 +45,18 @@ TEST(SurfaceTest, SurfaceLifetime) { EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id)); } +TEST(SurfaceTest, SurfaceIds) { + uint32_t namespaces[] = {0u, 37u, ~0u}; + for (size_t i = 0; i < 3; ++i) { + uint32_t id_namespace = namespaces[i]; + SurfaceIdAllocator allocator(id_namespace); + SurfaceId id1 = allocator.GenerateId(); + EXPECT_EQ(id1.id_namespace(), id_namespace); + SurfaceId id2 = allocator.GenerateId(); + EXPECT_EQ(id2.id_namespace(), id_namespace); + EXPECT_NE(id1.id, id2.id); + } +} + } // namespace } // namespace cc |