cfc301ea6351484e17fc5d2b7039c456aad86d36
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / vulkan / x11 / vk-surface-xlib2xcb.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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  *
16  */
17
18 #include <adaptors/devel-api/adaptor-framework/render-surface.h>
19 #include <dali/internal/graphics/vulkan/x11/vk-surface-xlib2xcb.h>
20 #include <dali/internal/window-system/common/window-render-surface.h>
21
22 #include <X11/Xlib-xcb.h>
23
24 namespace Dali
25 {
26 namespace Graphics
27 {
28 namespace Vulkan
29 {
30
31 VkSurfaceXlib2Xcb::VkSurfaceXlib2Xcb(Dali::RenderSurface& renderSurface)
32 : VkSurfaceFactory()
33 {
34   auto ecoreSurface = dynamic_cast<Dali::ECore::WindowRenderSurface*>(&renderSurface);
35   assert( ecoreSurface != nullptr && "This is not ecore surface!");
36   mConnection = XGetXCBConnection(XOpenDisplay(nullptr));
37   mWindow = static_cast<decltype(mWindow)>(ecoreSurface->GetXWindow());
38 }
39
40 VkSurfaceXlib2Xcb::VkSurfaceXlib2Xcb(Display* display, Window window)
41 : VkSurfaceFactory()
42 {
43   mConnection = XGetXCBConnection(display);
44   mWindow = static_cast<decltype(mWindow)>(window);
45 }
46
47 vk::SurfaceKHR VkSurfaceXlib2Xcb::Create(vk::Instance instance, vk::AllocationCallbacks* allocCallbacks,
48                                      vk::PhysicalDevice physicalDevice) const
49 {
50   vk::XcbSurfaceCreateInfoKHR info;
51   info.setConnection(mConnection).setWindow(mWindow);
52   auto retval = instance.createXcbSurfaceKHR(info, allocCallbacks).value;
53   return retval;
54 }
55 }
56 }
57 }