Graphics integration API deployment and fixing missing symbols
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-types.h
1 #ifndef DALI_GRAPHICS_VULKAN_TYPES_H
2 #define DALI_GRAPHICS_VULKAN_TYPES_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <atomic>
23 #include <unordered_map>
24 #include <memory>
25
26 #include <dali/integration-api/graphics/vulkan/vulkan-hpp-wrapper.h>
27
28 namespace Dali
29 {
30 namespace Graphics
31 {
32
33 template< typename T, typename... Args >
34 std::unique_ptr< T > MakeUnique(Args&&... args)
35 {
36   return std::unique_ptr< T >(new T(std::forward< Args >(args)...));
37 }
38
39 namespace Vulkan
40 {
41
42 /**
43  * Forward class declarations
44  */
45 class Graphics;
46 class CommandBuffer;
47 class CommandPool;
48 class Surface;
49 class Queue;
50 class Fence;
51 class DeviceMemory;
52 class Image;
53 class ImageView;
54 class Buffer;
55
56 /**
57  * Unique pointers to Vulkan types
58  */
59 using UniqueSurface       = std::unique_ptr< Surface >;
60 using UniqueCommandBuffer = std::unique_ptr< CommandBuffer >;
61 using UniqueCommandPool   = std::unique_ptr< CommandPool >;
62 using UniqueQueue         = std::unique_ptr< Queue >;
63 using UniqueFence         = std::unique_ptr< Fence >;
64 using UniqueDeviceMemory  = std::unique_ptr< DeviceMemory >;
65 using UniqueBuffer        = std::unique_ptr< Buffer >;
66 using UniqueImage         = std::unique_ptr< Image >;
67 using UniqueImageView     = std::unique_ptr< ImageView >;
68
69 /**
70  * Reference wrappers
71  */
72 using CommandBufferRef = std::reference_wrapper< CommandBuffer >;
73 using QueueRef         = std::reference_wrapper< Queue >;
74 using FenceRef         = std::reference_wrapper< Fence >;
75 using SurfaceRef       = std::reference_wrapper< Surface >;
76
77
78
79 template< typename T >
80 T VkAssert(const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess)
81 {
82   assert(result.result == expected);
83   return result.value;
84 }
85
86 inline vk::Result VkAssert(vk::Result result, vk::Result expected = vk::Result::eSuccess)
87 {
88   assert(result == expected);
89   return result;
90 }
91
92 inline vk::Result VkTest(vk::Result result, vk::Result expected = vk::Result::eSuccess)
93 {
94   // todo: log if result different than expected?
95   return result;
96 }
97
98 template< typename T >
99 inline uint32_t U32(T value)
100 {
101   return static_cast< uint32_t >(value);
102 }
103
104 class Resource
105 {
106 public:
107   Resource() : mUserCount{0u} {}
108   virtual ~Resource() = default;
109
110   void IncreaseUserCount()
111   {
112     ++mUserCount;
113   }
114
115   void DecreaseUserCount()
116   {
117     --mUserCount;
118   }
119
120   uint32_t GetUserCount() const
121   {
122     return mUserCount;
123   }
124
125 private:
126
127   std::atomic<uint32_t> mUserCount;
128 };
129
130 template< typename T>
131 class ResourceRef
132 {
133 public:
134
135   ResourceRef( T& object )
136   : mObject( &object )
137   {
138     mObject->IncreaseUserCount();
139   }
140
141   ResourceRef( ResourceRef& object )
142   {
143     if(mObject)
144     {
145       mObject->DecreaseUserCount();
146     }
147
148     mObject = object.mObject;
149     mObject->IncreaseUserCount();
150   }
151
152   ResourceRef operator=(ResourceRef& object )
153   {
154     if(mObject)
155     {
156       mObject->DecreaseUserCount();
157     }
158
159     mObject = object.mObject;
160     mObject->IncreaseUserCount();
161   }
162
163   ~ResourceRef()
164   {
165     if(mObject)
166     {
167       mObject->DecreaseUserCount();
168     }
169   }
170
171   T& GetResource() const
172   {
173     return *mObject;
174   }
175
176 private:
177
178   T* mObject;
179 };
180
181 using FBID = uint32_t;
182
183 #define NotImplemented() \
184 {\
185 printf("Function %s isn't implemented!\n", __FUNCTION__);\
186 assert( "Function no implemented" );\
187 }
188
189 /*
190 #pragma GCC diagnostic push
191 #pragma GCC diagnostic ignored "-Wframe-larger-than="
192 #pragma GCC diagnostic pop
193 */
194 } // namespace Vulkan
195 } // namespace Graphics
196 } // namespace Dali
197
198 #endif // DALI_GRAPHICS_VULKAN_TYPES_H