[dali_2.3.34] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / display-connection-impl-x.cpp
1 /*
2  * Copyright (c) 2024 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 // CLASS HEADER
19 #include <dali/internal/window-system/ubuntu-x11/display-connection-impl-x.h>
20
21 // EXTERNAL_HEADERS
22 #include <dali/internal/system/linux/dali-ecore-x.h>
23
24 // INTERNAL HEADERS
25 #if !defined(VULKAN_ENABLED)
26 #include <dali/internal/graphics/common/egl-include.h>
27 #endif
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 DisplayConnection* DisplayConnectionX11::New()
36 {
37   return nullptr;
38   DisplayConnection* pDisplayConnection(new DisplayConnectionX11());
39   return pDisplayConnection;
40 }
41
42 DisplayConnectionX11::DisplayConnectionX11()
43 : mDisplay(nullptr)
44 {
45 }
46
47 DisplayConnectionX11::~DisplayConnectionX11()
48 {
49   if(mDisplay)
50   {
51     XCloseDisplay(mDisplay);
52   }
53 }
54
55 Any DisplayConnectionX11::GetDisplay()
56 {
57   return {mDisplay};
58 }
59
60 Any DisplayConnectionX11::GetNativeGraphicsDisplay()
61 {
62 #if defined(VULKAN_ENABLED)
63   return {nullptr};
64 #else
65   return {static_cast<EGLNativeDisplayType>(mDisplay)};
66 #endif
67 }
68
69 void DisplayConnectionX11::ConsumeEvents()
70 {
71   // check events so that we can flush the queue and avoid any potential memory leaks in X
72   // looping if events remain
73   int events(0);
74   do
75   {
76     // Check if there are any events in the queue
77     events = XEventsQueued(mDisplay, QueuedAfterFlush);
78
79     if(events > 0)
80     {
81       // Just flush event to prevent memory leak from event queue as the events get built up in
82       // memory but are only deleted when we retrieve them
83       XEvent ev;
84       XNextEvent(mDisplay, &ev);
85     }
86   } while(events > 0);
87 }
88
89 void DisplayConnectionX11::SetSurfaceType(Dali::Integration::RenderSurfaceInterface::Type type)
90 {
91   if(type == Dali::Integration::RenderSurfaceInterface::WINDOW_RENDER_SURFACE)
92   {
93     // Because of DDK issue, we need to use separated x display instead of ecore default display
94     mDisplay = XOpenDisplay(0);
95   }
96 }
97
98 } // namespace Adaptor
99
100 } // namespace Internal
101
102 } // namespace Dali