Move GetDpi implementation to RenderSurface
[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
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 DisplayConnection* DisplayConnectionX11::New()
38 {
39   //DisplayConnection* pDisplayConnection(new DisplayConnection());
40
41   //return pDisplayConnection;
42   return nullptr;
43 }
44
45 DisplayConnectionX11::DisplayConnectionX11()
46 : mDisplay(NULL)
47 {
48 }
49
50 DisplayConnectionX11::~DisplayConnectionX11()
51 {
52   if(mDisplay)
53   {
54     XCloseDisplay(mDisplay);
55   }
56 }
57
58 Any DisplayConnectionX11::GetDisplay()
59 {
60   return Any(mDisplay);
61 }
62
63 void DisplayConnectionX11::ConsumeEvents()
64 {
65   // check events so that we can flush the queue and avoid any potential memory leaks in X
66   // looping if events remain
67   int events(0);
68   do
69   {
70     // Check if there are any events in the queue
71     events = XEventsQueued(mDisplay, QueuedAfterFlush);
72
73     if (events > 0)
74     {
75       // Just flush event to prevent memory leak from event queue as the events get built up in
76       // memory but are only deleted when we retrieve them
77       XEvent ev;
78       XNextEvent(mDisplay, &ev);
79     }
80   }
81   while (events > 0);
82 }
83
84 bool DisplayConnectionX11::InitializeEgl(EglInterface& egl)
85 {
86   EglImplementation& eglImpl = static_cast<EglImplementation&>(egl);
87
88   if (!eglImpl.InitializeGles(reinterpret_cast<EGLNativeDisplayType>(mDisplay)))
89   {
90     DALI_LOG_ERROR("Failed to initialize GLES.\n");
91     return false;
92   }
93
94   return true;
95 }
96
97 void DisplayConnectionX11::SetSurfaceType( RenderSurface::Type type )
98 {
99   if( type == RenderSurface::WINDOW_RENDER_SURFACE )
100   {
101     // Because of DDK issue, we need to use separated x display instead of ecore default display
102     mDisplay = XOpenDisplay(0);
103   }
104 }
105
106 } // namespace Adaptor
107
108 } // namespace Internal
109
110 } // namespace Dali