aboutsummaryrefslogtreecommitdiff
path: root/layers/unique_objects.h
diff options
context:
space:
mode:
authorChris Forbes <chrisforbes@google.com>2017-05-02 18:18:01 -0700
committerChris Forbes <chrisf@ijw.co.nz>2017-05-03 11:38:06 -0700
commit4ae75644b238b63d0e8f8b7d21cfd51f45b2c943 (patch)
tree6a06449f9fccb1544af01498fd4fd5ca0e280f5c /layers/unique_objects.h
parent32d3246d8bde4f6b5ff79c94749eee44e29f20c0 (diff)
downloadusermoji-4ae75644b238b63d0e8f8b7d21cfd51f45b2c943.tar.xz
layers: Move UO helpers to header
Diffstat (limited to 'layers/unique_objects.h')
-rw-r--r--layers/unique_objects.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/layers/unique_objects.h b/layers/unique_objects.h
index 33616aa1..60c20a39 100644
--- a/layers/unique_objects.h
+++ b/layers/unique_objects.h
@@ -102,4 +102,22 @@ bool ContainsExtStruct(const T *target, VkStructureType ext_type) {
return false;
}
+
+/* Unwrap a handle. */
+// must hold lock!
+template<typename HandleType, typename MapType>
+HandleType Unwrap(MapType *layer_data, HandleType wrappedHandle) {
+ // TODO: don't use operator[] here.
+ return (HandleType)layer_data->unique_id_mapping[reinterpret_cast<uint64_t const &>(wrappedHandle)];
+}
+
+/* Wrap a newly created handle with a new unique ID, and return the new ID. */
+// must hold lock!
+template<typename HandleType, typename MapType>
+HandleType WrapNew(MapType *layer_data, HandleType newlyCreatedHandle) {
+ auto unique_id = global_unique_id++;
+ layer_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t const &>(newlyCreatedHandle);
+ return (HandleType)unique_id;
+}
+
} // namespace unique_objects