eb262c576f71d0eb41f6f6a5c2e0ad37352a18a5
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / display-connection-impl-ecore-wl.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_Wayland.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL HEADERS
26 #include <native-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 {
46 }
47
48 DisplayConnection::~DisplayConnection()
49 {
50   if( mSurfaceType == RenderSurface::NATIVE_RENDER_SURFACE )
51   {
52     ReleaseNativeDisplay();
53   }
54 }
55
56 Any DisplayConnection::GetDisplay()
57 {
58   return Any( mDisplay );
59 }
60
61 void DisplayConnection::ConsumeEvents()
62 {
63 }
64
65 bool DisplayConnection::InitializeEgl(EglInterface& egl)
66 {
67   EglImplementation& eglImpl = static_cast<EglImplementation&>(egl);
68
69   if( !eglImpl.InitializeGles( mDisplay ) )
70   {
71     DALI_LOG_ERROR("Failed to initialize GLES.\n");
72     return false;
73   }
74
75   return true;
76 }
77
78 void DisplayConnection::SetSurfaceType( RenderSurface::Type type )
79 {
80   mSurfaceType = type;
81
82   if( mSurfaceType == RenderSurface::NATIVE_RENDER_SURFACE )
83   {
84     mDisplay = GetNativeDisplay();
85   }
86   else
87   {
88     mDisplay = reinterpret_cast< EGLNativeDisplayType >( ecore_wl_display_get() );
89   }
90 }
91
92 void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
93 {
94   // calculate DPI
95   float xres, yres;
96
97   // 1 inch = 25.4 millimeters
98   xres = ecore_wl_dpi_get();
99   yres = ecore_wl_dpi_get();
100
101   dpiHorizontal = int(xres + 0.5f);  // rounding
102   dpiVertical   = int(yres + 0.5f);
103 }
104
105 } // namespace Adaptor
106
107 } // namespace Internal
108
109 } // namespace Dali