[dali_2.3.25] Merge branch 'devel/master'
[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   mBufMgr(nullptr)
50 {
51 }
52
53 DisplayConnectionEcoreWl::~DisplayConnectionEcoreWl()
54 {
55   if(mSurfaceType == RenderSurfaceInterface::NATIVE_RENDER_SURFACE)
56   {
57     ReleaseNativeDisplay();
58   }
59 }
60
61 Any DisplayConnectionEcoreWl::GetDisplay()
62 {
63   return Any(mDisplay);
64 }
65
66 void DisplayConnectionEcoreWl::ConsumeEvents()
67 {
68 }
69
70 bool DisplayConnectionEcoreWl::InitializeGraphics()
71 {
72   auto               eglGraphics = static_cast<EglGraphics*>(mGraphics);
73   EglImplementation& eglImpl     = eglGraphics->GetEglImplementation();
74
75   if(!eglImpl.InitializeGles(mDisplay))
76   {
77     DALI_LOG_ERROR("Failed to initialize GLES.\n");
78     return false;
79   }
80
81   return true;
82 }
83
84 void DisplayConnectionEcoreWl::SetSurfaceType(Dali::RenderSurfaceInterface::Type type)
85 {
86   mSurfaceType = type;
87
88   if(mSurfaceType == Dali::RenderSurfaceInterface::NATIVE_RENDER_SURFACE)
89   {
90     mDisplay = GetNativeDisplay();
91   }
92   else
93   {
94 #ifdef ECORE_WAYLAND2
95     Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
96     mDisplay                   = reinterpret_cast<EGLNativeDisplayType>(ecore_wl2_display_get(display));
97 #else
98     mDisplay = reinterpret_cast<EGLNativeDisplayType>(ecore_wl_display_get());
99 #endif
100   }
101 }
102
103 void DisplayConnectionEcoreWl::SetGraphicsInterface(GraphicsInterface& graphics)
104 {
105   mGraphics = &graphics;
106 }
107
108 EGLNativeDisplayType DisplayConnectionEcoreWl::GetNativeDisplay()
109 {
110   mBufMgr = tbm_bufmgr_init(-1);  // -1 is meaningless. The parameter in this function is deprecated.
111   if(mBufMgr == nullptr)
112   {
113     DALI_LOG_ERROR("Fail to init tbm buf mgr\n");
114     return nullptr;
115   }
116   return reinterpret_cast<EGLNativeDisplayType>(tbm_dummy_display_create());
117 }
118
119 void DisplayConnectionEcoreWl::ReleaseNativeDisplay()
120 {
121   if(mDisplay)
122   {
123     tbm_dummy_display_destroy(reinterpret_cast<tbm_dummy_display*>(mDisplay));
124   }
125
126   if(mBufMgr != nullptr)
127   {
128     tbm_bufmgr_deinit(mBufMgr);
129   }
130 }
131
132 } // namespace Adaptor
133
134 } // namespace Internal
135
136 } // namespace Dali