Implement WSI layer swapchain functions for Tizen:
[platform/core/uifw/vulkan-wsi-tizen.git] / wsi / tizen / swapchain.hpp
1 /*
2  * Copyright (c) 2017-2019, 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 #pragma once
26
27 #include "wsi/swapchain_base_tizen.hpp"
28
29 extern "C" {
30 #include <vulkan/vk_icd.h>
31 #include <tpl.h>
32 #include <tbm_sync.h>
33 #include <tbm_surface.h>
34 #include <tbm_surface_internal.h>
35 }
36
37 namespace wsi
38 {
39 namespace tizen
40 {
41
42 class swapchain : public wsi::swapchain_base
43 {
44 public:
45    explicit swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *allocator);
46
47    ~swapchain();
48
49 protected:
50    /**
51     * @brief Initialize platform specifics.
52     */
53    VkResult init_platform(VkDevice device, const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo) override;
54
55    /**
56     * @brief Creates swapchain images.
57     *
58     * @param image_create_info Data to be used to create the image.
59     *
60     * @return If image creation is successful returns VK_SUCCESS, otherwise
61     * will return VK_ERROR_OUT_OF_DEVICE_MEMORY or VK_ERROR_INITIALIZATION_FAILED
62     * depending on the error that occurred.
63     */
64    VkResult create_image(const VkImageCreateInfo &image_create_info) override;
65
66    VkResult acquire_image(uint32_t *image_index) override;
67
68    /**
69     * @brief Method to present an image
70     *
71     * @param pendingIndex Index of the pending image to be presented.
72     */
73    void present_image(uint32_t pendingIndex) override;
74
75    /**
76     * @brief Method to release a swapchain image
77     *
78     * @param image Handle to the image about to be released.
79     */
80    void destroy_image(void) override;
81
82 private:
83    struct tizen_image_data;
84    VkResult allocate_image(const VkImageCreateInfo &image_create_info, tizen_image_data *image_data, VkImage *image);
85
86    tpl_display_t *m_tpl_display;
87    tpl_surface_t *m_tpl_surface;
88
89 };
90 } // namespace wayland
91 } // namespace wsi