Revert "[3.0] Add native render surface for wayland"
[platform/core/uifw/dali-adaptor.git] / adaptors / 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 "display-connection-impl.h"
20
21 // EXTERNAL_HEADERS
22 #include <Ecore_X.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL HEADERS
26 #include <pixmap-render-surface.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 DisplayConnection* DisplayConnection::New()
38 {
39   DisplayConnection* pDisplayConnection(new DisplayConnection());
40
41   return pDisplayConnection;
42 }
43
44 DisplayConnection::DisplayConnection()
45 : mDisplay(NULL)
46 {
47   // Because of DDK issue, we need to use separated x display instead of ecore default display
48   mDisplay = XOpenDisplay(0);
49 }
50
51 DisplayConnection::~DisplayConnection()
52 {
53   if(mDisplay)
54   {
55     XCloseDisplay(mDisplay);
56   }
57 }
58
59 Any DisplayConnection::GetDisplay()
60 {
61   return Any(mDisplay);
62 }
63
64 void DisplayConnection::ConsumeEvents()
65 {
66   // check events so that we can flush the queue and avoid any potential memory leaks in X
67   // looping if events remain
68   int events(0);
69   do
70   {
71     // Check if there are any events in the queue
72     events = XEventsQueued(mDisplay, QueuedAfterFlush);
73
74     if (events > 0)
75     {
76       // Just flush event to prevent memory leak from event queue as the events get built up in
77       // memory but are only deleted when we retrieve them
78       XEvent ev;
79       XNextEvent(mDisplay, &ev);
80     }
81   }
82   while (events > 0);
83 }
84
85 bool DisplayConnection::InitializeEgl(EglInterface& egl)
86 {
87   EglImplementation& eglImpl = static_cast<EglImplementation&>(egl);
88
89   if (!eglImpl.InitializeGles(reinterpret_cast<EGLNativeDisplayType>(mDisplay)))
90   {
91     DALI_LOG_ERROR("Failed to initialize GLES.\n");
92     return false;
93   }
94
95   return true;
96 }
97
98 void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
99 {
100   // calculate DPI
101   float xres, yres;
102
103   // 1 inch = 25.4 millimeters
104   xres = ecore_x_dpi_get();
105   yres = ecore_x_dpi_get();
106
107   dpiHorizontal = int(xres + 0.5f);  // rounding
108   dpiVertical   = int(yres + 0.5f);
109 }
110
111 } // namespace Adaptor
112
113 } // namespace Internal
114
115 } // namespace Dali