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