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