Merge "Enable atspi" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / display-connection-impl-x.cpp
1 /*
2  * Copyright (c) 2021 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/integration-api/debug.h>
23 #include <dali/internal/system/linux/dali-ecore-x.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/graphics/gles/egl-graphics.h>
27 #include <dali/internal/window-system/ubuntu-x11/pixmap-render-surface-ecore-x.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 DisplayConnection* DisplayConnectionX11::New()
36 {
37   //DisplayConnection* pDisplayConnection(new DisplayConnection());
38
39   //return pDisplayConnection;
40   return nullptr;
41 }
42
43 DisplayConnectionX11::DisplayConnectionX11()
44 : mGraphics(nullptr),
45   mDisplay(nullptr)
46 {
47 }
48
49 DisplayConnectionX11::~DisplayConnectionX11()
50 {
51   if(mDisplay)
52   {
53     XCloseDisplay(mDisplay);
54   }
55 }
56
57 Any DisplayConnectionX11::GetDisplay()
58 {
59   return Any(mDisplay);
60 }
61
62 void DisplayConnectionX11::ConsumeEvents()
63 {
64   // check events so that we can flush the queue and avoid any potential memory leaks in X
65   // looping if events remain
66   int events(0);
67   do
68   {
69     // Check if there are any events in the queue
70     events = XEventsQueued(mDisplay, QueuedAfterFlush);
71
72     if(events > 0)
73     {
74       // Just flush event to prevent memory leak from event queue as the events get built up in
75       // memory but are only deleted when we retrieve them
76       XEvent ev;
77       XNextEvent(mDisplay, &ev);
78     }
79   } while(events > 0);
80 }
81
82 bool DisplayConnectionX11::InitializeGraphics()
83 {
84   auto               eglGraphics = static_cast<EglGraphics*>(mGraphics);
85   EglImplementation& eglImpl     = eglGraphics->GetEglImplementation();
86
87   if(!eglImpl.InitializeGles(reinterpret_cast<EGLNativeDisplayType>(mDisplay)))
88   {
89     DALI_LOG_ERROR("Failed to initialize GLES.\n");
90     return false;
91   }
92
93   return true;
94 }
95
96 void DisplayConnectionX11::SetSurfaceType(Dali::RenderSurfaceInterface::Type type)
97 {
98   if(type == Dali::RenderSurfaceInterface::WINDOW_RENDER_SURFACE)
99   {
100     // Because of DDK issue, we need to use separated x display instead of ecore default display
101     mDisplay = XOpenDisplay(0);
102   }
103 }
104
105 void DisplayConnectionX11::SetGraphicsInterface(GraphicsInterface& graphics)
106 {
107   mGraphics = &graphics;
108 }
109
110 } // namespace Adaptor
111
112 } // namespace Internal
113
114 } // namespace Dali