Merge "Temporary fix of PreInitialize, Remove FontClient" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / display-connection-impl-ecore-wl.cpp
1 /*
2  * Copyright (c) 2018 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/display-connection-impl-ecore-wl.h>
20 #include <dali/internal/graphics/gles/egl-graphics.h>
21
22 // EXTERNAL_HEADERS
23 #include <tbm_dummy_display.h>
24 #include <dali/integration-api/debug.h>
25
26 #ifdef ECORE_WAYLAND2
27 #include <Ecore_Wl2.h>
28 #else
29 #include <Ecore_Wayland.h>
30 #endif
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 DisplayConnection* DisplayConnectionEcoreWl::New()
42 {
43   DisplayConnection* pDisplayConnection(new DisplayConnectionEcoreWl());
44
45   return pDisplayConnection;
46 }
47
48 DisplayConnectionEcoreWl::DisplayConnectionEcoreWl()
49 : mDisplay( NULL ),
50   mSurfaceType( Integration::RenderSurface::WINDOW_RENDER_SURFACE ),
51   mGraphics( nullptr )
52 {
53 }
54
55 DisplayConnectionEcoreWl::~DisplayConnectionEcoreWl()
56 {
57   if( mSurfaceType == Integration::RenderSurface::NATIVE_RENDER_SURFACE )
58   {
59     ReleaseNativeDisplay();
60   }
61 }
62
63 Any DisplayConnectionEcoreWl::GetDisplay()
64 {
65   return Any( mDisplay );
66 }
67
68 void DisplayConnectionEcoreWl::ConsumeEvents()
69 {
70 }
71
72 bool DisplayConnectionEcoreWl::InitializeGraphics()
73 {
74   auto eglGraphics = static_cast<EglGraphics *>(mGraphics);
75   EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
76
77   if( !eglImpl.InitializeGles( mDisplay ) )
78   {
79     DALI_LOG_ERROR("Failed to initialize GLES.\n");
80     return false;
81   }
82
83   return true;
84 }
85
86 void DisplayConnectionEcoreWl::SetSurfaceType( Integration::RenderSurface::Type type )
87 {
88   mSurfaceType = type;
89
90   if( mSurfaceType == Integration::RenderSurface::NATIVE_RENDER_SURFACE )
91   {
92     mDisplay = GetNativeDisplay();
93   }
94   else
95   {
96 #ifdef ECORE_WAYLAND2
97     Ecore_Wl2_Display* display = ecore_wl2_connected_display_get( NULL );
98     mDisplay = reinterpret_cast< EGLNativeDisplayType >( ecore_wl2_display_get( display ) );
99 #else
100     mDisplay = reinterpret_cast< EGLNativeDisplayType >( ecore_wl_display_get() );
101 #endif
102   }
103 }
104
105 void DisplayConnectionEcoreWl::SetGraphicsInterface( GraphicsInterface& graphics )
106 {
107   mGraphics = &graphics;
108 }
109
110 EGLNativeDisplayType DisplayConnectionEcoreWl::GetNativeDisplay()
111 {
112   return reinterpret_cast< EGLNativeDisplayType >( tbm_dummy_display_create() );
113 }
114
115 void DisplayConnectionEcoreWl::ReleaseNativeDisplay()
116 {
117   if( mDisplay )
118   {
119      tbm_dummy_display_destroy( reinterpret_cast< tbm_dummy_display* >( mDisplay ) );
120   }
121 }
122
123 } // namespace Adaptor
124
125 } // namespace Internal
126
127 } // namespace Dali