[Tizen] ecore-wl2: applying ecore-wl2
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / display-connection-impl-ecore-wl2.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/tizen-wayland/ecore-wl2/display-connection-impl-ecore-wl2.h>
20
21 // EXTERNAL_HEADERS
22 #include <Ecore_Wl2.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL HEADERS
26 #include <dali/integration-api/wayland/native-render-surface.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 DisplayConnection* DisplayConnectionEcoreWl2::New()
38 {
39   DisplayConnection* pDisplayConnection(new DisplayConnectionEcoreWl2());
40
41   return pDisplayConnection;
42 }
43
44 DisplayConnectionEcoreWl2::DisplayConnectionEcoreWl2()
45 : mDisplay( NULL ),
46   mSurfaceType( RenderSurface::ECORE_RENDER_SURFACE )
47 {
48 }
49
50 DisplayConnectionEcoreWl2::~DisplayConnectionEcoreWl2()
51 {
52   if( mSurfaceType == RenderSurface::NATIVE_RENDER_SURFACE )
53   {
54     ReleaseNativeDisplay();
55   }
56 }
57
58 Any DisplayConnectionEcoreWl2::GetDisplay()
59 {
60   return Any( mDisplay );
61 }
62
63 void DisplayConnectionEcoreWl2::ConsumeEvents()
64 {
65 }
66
67 bool DisplayConnectionEcoreWl2::InitializeEgl(EglInterface& egl)
68 {
69   EglImplementation& eglImpl = static_cast<EglImplementation&>(egl);
70
71   if( !eglImpl.InitializeGles( mDisplay ) )
72   {
73     DALI_LOG_ERROR("Failed to initialize GLES.\n");
74     return false;
75   }
76
77   return true;
78 }
79
80 void DisplayConnectionEcoreWl2::SetSurfaceType( RenderSurface::Type type )
81 {
82   mSurfaceType = type;
83
84   if( mSurfaceType == RenderSurface::NATIVE_RENDER_SURFACE )
85   {
86     mDisplay = GetNativeDisplay();
87   }
88   else
89   {
90     Ecore_Wl2_Display* ecore_wl2_display = ecore_wl2_connected_display_get(NULL);
91     mDisplay = reinterpret_cast< EGLNativeDisplayType >( ecore_wl2_display_get(ecore_wl2_display) );
92   }
93 }
94
95 void DisplayConnectionEcoreWl2::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
96 {
97   // calculate DPI
98   float xres, yres;
99
100   // 1 inch = 25.4 millimeters
101 #if 0
102   Ecore_Wl2_Window *ecore_wl2_window_find(unsigned int id);
103   Ecore_Wl2_Window *ecore_wl2_window_surface_find(struct wl_surface *surface);
104
105   Ecore_Wl2_Output *ecore_wl2_window_output_find(Ecore_Wl2_Window *window);
106   ecore_wl2_window_output_find(wdata->win);
107   xres = ecore_wl2_output_dpi_get();
108   yres = ecore_wl2_output_dpi_get();
109 #endif
110   xres = 293.0;
111   yres = 293.0;
112   dpiHorizontal = int(xres + 0.5f);  // rounding
113   dpiVertical   = int(yres + 0.5f);
114 }
115
116 void DisplayConnectionEcoreWl2::GetDpi(Any nativeWindow, unsigned int& dpiHorizontal, unsigned int& dpiVertical)
117 {
118     // calculate DPI
119     float xres, yres;
120
121     Ecore_Wl2_Output *wl2_output = ecore_wl2_window_output_find(AnyCast<Ecore_Wl2_Window*>( nativeWindow ));
122
123     if (!wl2_output)
124     {
125       DALI_LOG_ERROR("Failed to get Ecore_Wl2_Output.\n");
126       return;
127     }
128     xres = ecore_wl2_output_dpi_get(wl2_output);
129     yres = ecore_wl2_output_dpi_get(wl2_output);
130
131     dpiHorizontal = int(xres + 0.5f);  // rounding
132     dpiVertical   = int(yres + 0.5f);
133 }
134
135 EGLNativeDisplayType DisplayConnectionEcoreWl2::GetNativeDisplay()
136 {
137   return EGLNativeDisplayType();
138 }
139
140 void DisplayConnectionEcoreWl2::ReleaseNativeDisplay()
141 {
142
143 }
144
145 } // namespace Adaptor
146
147 } // namespace Internal
148
149 } // namespace Dali