2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "display-connection-impl.h"
23 #include <dali/integration-api/debug.h>
26 #include <pixmap-render-surface.h>
37 DisplayConnection* DisplayConnection::New()
39 DisplayConnection* pDisplayConnection(new DisplayConnection());
41 return pDisplayConnection;
44 DisplayConnection::DisplayConnection()
49 DisplayConnection::~DisplayConnection()
53 XCloseDisplay(mDisplay);
57 Any DisplayConnection::GetDisplay()
62 void DisplayConnection::ConsumeEvents()
64 // check events so that we can flush the queue and avoid any potential memory leaks in X
65 // looping if events remain
69 // Check if there are any events in the queue
70 events = XEventsQueued(mDisplay, QueuedAfterFlush);
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
77 XNextEvent(mDisplay, &ev);
83 bool DisplayConnection::InitializeEgl(EglInterface& egl)
85 EglImplementation& eglImpl = static_cast<EglImplementation&>(egl);
87 if (!eglImpl.InitializeGles(reinterpret_cast<EGLNativeDisplayType>(mDisplay)))
89 DALI_LOG_ERROR("Failed to initialize GLES.\n");
96 void DisplayConnection::SetSurfaceType( RenderSurface::Type type )
98 if( type == RenderSurface::ECORE_RENDER_SURFACE )
100 // Because of DDK issue, we need to use separated x display instead of ecore default display
101 mDisplay = XOpenDisplay(0);
105 void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
110 // 1 inch = 25.4 millimeters
111 xres = ecore_x_dpi_get();
112 yres = ecore_x_dpi_get();
114 dpiHorizontal = int(xres + 0.5f); // rounding
115 dpiVertical = int(yres + 0.5f);
118 } // namespace Adaptor
120 } // namespace Internal