[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-image.h
1 #ifndef DALI_GRAPHICS_VULKAN_IMAGE
2 #define DALI_GRAPHICS_VULKAN_IMAGE
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 #include <dali/graphics/vulkan/vulkan-types.h>
22
23 namespace Dali
24 {
25 namespace Graphics
26 {
27 namespace Vulkan
28 {
29
30 class ImageView;
31 enum class ResourceOwnershipType
32 {
33   OWNED,
34   EXTERNAL
35 };
36
37 class Image : public VkManaged
38 {
39 public:
40   /**
41    * Creates new VkImage with given specification, it doesn't
42    * bind the memory.
43    * @param graphics
44    * @param createInfo
45    */
46   Image(Graphics& graphics, const vk::ImageCreateInfo& createInfo);
47
48   /**
49    * Constructor creates wrapper on the VkImage coming from external
50    * source. It doesn't take over ownership so it's still owner's
51    * responsibility to destroy it and maintain the usage.
52    *
53    * @param graphics
54    * @param externalImage
55    */
56   Image(Graphics& graphics, vk::Image externalImage);
57
58   /**
59    * Destructor
60    */
61   virtual ~Image() = default;
62
63   /**
64    * Creates UNMANAGED VkImageView from the current image.
65    * Usage requires external lifecycle management and synchronization
66    * Memory MUST be bound for this function to work!
67    * @param info
68    * @return
69    */
70   vk::ImageView CreateUnmanagedView(const vk::ImageViewCreateInfo& info);
71
72   /**
73    * Creates MANAGED ImageView from the current image
74    * Memory MUST be bound for this function to work!
75    * @param info
76    * @return
77    */
78   ImageViewRef CreateView(const vk::ImageViewCreateInfo& info);
79
80   /**
81    * Returns underlying Vulkan object
82    * @return
83    */
84   vk::Image GetImage() const
85   {
86     return mImage;
87   }
88
89 private:
90
91   Graphics& mGraphics;
92
93   vk::Image       mImage;
94   vk::ImageLayout mLayout;
95
96   ResourceOwnershipType mOwnershipType;
97 };
98
99 /*
100  * ImageView
101  * todo: move it to its own file
102  */
103 class ImageView : public VkManaged
104 {
105 public:
106   ImageView(Graphics& graphics, Image& image);
107   ImageView(Graphics& graphics, Image& image, const VkImageViewCreateInfo& createInfo);
108
109   virtual ~ImageView() override;
110
111   const vk::ImageView& GetImageView() const
112   {
113     return mImageView;
114   }
115
116   Image& GetImage() const
117   {
118     return *mImageRef;
119   }
120
121 private:
122
123   Graphics&             mGraphics;
124   Handle<Image>         mImageRef;
125
126   vk::ImageView mImageView;
127 };
128
129 } // namespace Vulkan
130
131 } // namespace Graphics
132
133 } // namespace Dali
134
135 #endif // DALI_GRAPHICS_VULKAN_IMAGE