• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2018 The Android Open Source Project
2 // Copyright (C) 2018 Google Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 #pragma once
16 
17 #include <vulkan/vulkan.h>
18 
19 #include "VulkanHandles.h"
20 #include "VulkanDispatch.h"
21 
22 #include <functional>
23 
24 namespace goldfish_vk {
25 
26 class VkDecoderGlobalState;
27 
28 class VulkanHandleMapping {
29 public:
VulkanHandleMapping(VkDecoderGlobalState * state)30     VulkanHandleMapping(VkDecoderGlobalState* state) : m_state (state) { }
~VulkanHandleMapping()31     virtual ~VulkanHandleMapping() { }
32 
33 #define DECLARE_HANDLE_MAP_PURE_VIRTUAL_METHOD(type) \
34     virtual void mapHandles_##type(type* handles, size_t count = 1) = 0; \
35     virtual void mapHandles_##type##_u64(const type* handles, uint64_t* handle_u64s, size_t count = 1) = 0; \
36     virtual void mapHandles_u64_##type(const uint64_t* handle_u64s, type* handles, size_t count = 1) = 0; \
37 
38     GOLDFISH_VK_LIST_HANDLE_TYPES(DECLARE_HANDLE_MAP_PURE_VIRTUAL_METHOD)
39 protected:
40     VkDecoderGlobalState* m_state;
41 };
42 
43 class DefaultHandleMapping : public VulkanHandleMapping {
44 public:
45     DefaultHandleMapping() : VulkanHandleMapping(nullptr) { }
46     virtual ~DefaultHandleMapping() { }
47 
48 #define DECLARE_HANDLE_MAP_OVERRIDE(type) \
49     void mapHandles_##type(type* handles, size_t count) override; \
50     void mapHandles_##type##_u64(const type* handles, uint64_t* handle_u64s, size_t count) override; \
51     void mapHandles_u64_##type(const uint64_t* handle_u64s, type* handles, size_t count) override; \
52 
53     GOLDFISH_VK_LIST_HANDLE_TYPES(DECLARE_HANDLE_MAP_OVERRIDE)
54 };
55 
56 #define DEFINE_BOXED_DISPATCHABLE_HANDLE_GLOBAL_API_DECL(type) \
57     type unbox_##type(type boxed); \
58     type unboxed_to_boxed_##type(type boxed); \
59     void delete_##type(type boxed); \
60     VulkanDispatch* dispatch_##type(type boxed); \
61 
62 GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(DEFINE_BOXED_DISPATCHABLE_HANDLE_GLOBAL_API_DECL)
63 
64 #define DEFINE_BOXED_NON_DISPATCHABLE_HANDLE_GLOBAL_API_DECL(type) \
65     type new_boxed_non_dispatchable_##type(type underlying); \
66     void delete_##type(type boxed); \
67     void delayed_delete_##type(type boxed, VkDevice device, std::function<void()> callback); \
68     type unbox_##type(type boxed); \
69     type unboxed_to_boxed_non_dispatchable_##type(type boxed); \
70 
71 GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(DEFINE_BOXED_NON_DISPATCHABLE_HANDLE_GLOBAL_API_DECL)
72 
73 } // namespace goldfish_vk
74