2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/window-system/tizen-wayland/native-image-surface-impl-ecore-wl.h>
22 #include <dali/integration-api/debug.h>
23 #include <system_info.h>
26 #include <dali/internal/graphics/gles/egl-graphics-factory.h>
27 #include <dali/internal/graphics/gles/egl-graphics.h>
28 #include <dali/internal/graphics/gles/egl-implementation.h>
29 #include <dali/internal/system/common/environment-options.h>
30 #include <dali/internal/window-system/common/display-utils.h>
32 using namespace Dali::Internal::Adaptor;
40 NativeImageSurfaceEcoreWl::NativeImageSurfaceEcoreWl(Dali::NativeImageSourceQueuePtr queue)
41 : mDisplayConnection(nullptr),
46 mColorDepth(COLOR_DEPTH_32),
55 mTbmQueue = AnyCast<tbm_surface_queue_h>(queue->GetNativeImageSourceQueue());
56 mTbmFormat = tbm_surface_queue_get_format(mTbmQueue);
57 mColorDepth = (mTbmFormat == TBM_FORMAT_ARGB8888) ? COLOR_DEPTH_32 : COLOR_DEPTH_24;
61 DALI_LOG_ERROR("NativeImageSourceQueue is null.");
65 bool NativeImageSurfaceEcoreWl::SetGraphicsConfig(bool depth, bool stencil, int msaa, int version)
67 bool featureFlag = false;
68 int error = SYSTEM_INFO_ERROR_NONE;
72 error = system_info_get_platform_bool("http://tizen.org/feature/opengles.version.3_0", &featureFlag);
74 else if(version == 20)
76 error = system_info_get_platform_bool("http://tizen.org/feature/opengles.version.2_0", &featureFlag);
80 DALI_LOG_ERROR("version is not valid");
84 if(error != SYSTEM_INFO_ERROR_NONE)
86 DALI_LOG_ERROR("Can't check platform feature.\n");
103 mGLESVersion = version;
109 Any NativeImageSurfaceEcoreWl::GetNativeRenderable()
114 void NativeImageSurfaceEcoreWl::InitializeGraphics()
116 std::unique_ptr<GraphicsFactory> graphicsFactoryPtr = Utils::MakeUnique<GraphicsFactory>(*(new EnvironmentOptions()));
117 auto graphicsFactory = *graphicsFactoryPtr.get();
119 mGraphics = std::unique_ptr<GraphicsInterface>(&graphicsFactory.Create());
120 GraphicsInterface* graphics = mGraphics.get();
121 auto eglGraphics = static_cast<EglGraphics*>(graphics);
122 eglGraphics->Initialize(mDepth, mStencil, false, mMSAA);
124 mDisplayConnection = std::unique_ptr<Dali::DisplayConnection>(Dali::DisplayConnection::New(*mGraphics, Dali::RenderSurfaceInterface::Type::NATIVE_RENDER_SURFACE));
125 mDisplayConnection->Initialize();
127 mEGL = &eglGraphics->GetEglInterface();
129 if(mEGLContext == NULL)
131 Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>(*mEGL);
132 eglImpl.SetGlesVersion(mGLESVersion);
134 if(eglImpl.ChooseConfig(true, mColorDepth) == false)
136 DALI_LOG_ERROR("InitializeGraphics: Fail to choose config. Version:%d, ColorDepth:%d, depth:%d, stencil:%d, MSAA:%d",
138 mColorDepth == COLOR_DEPTH_32 ? 32 : 24,
145 // Create the OpenGL Surface & Context
146 eglImpl.CreateWindowContext(mEGLContext);
147 mEGLSurface = eglImpl.CreateSurfaceWindow(reinterpret_cast<EGLNativeWindowType>(mTbmQueue), mColorDepth);
149 MakeContextCurrent();
153 void NativeImageSurfaceEcoreWl::TerminateGraphics()
155 GraphicsInterface* graphics = mGraphics.get();
156 auto eglGraphics = static_cast<EglGraphics*>(graphics);
158 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
161 eglImpl.DestroySurface(mEGLSurface);
166 eglImpl.DestroyContext(mEGLContext);
170 void NativeImageSurfaceEcoreWl::PreRender()
172 MakeContextCurrent();
175 void NativeImageSurfaceEcoreWl::PostRender()
177 GraphicsInterface* graphics = mGraphics.get();
178 auto eglGraphics = static_cast<EglGraphics*>(graphics);
181 Internal::Adaptor::EglImplementation& eglImpl = eglGraphics->GetEglImplementation();
182 eglImpl.SwapBuffers(mEGLSurface);
186 void NativeImageSurfaceEcoreWl::MakeContextCurrent()
190 if(mEGLSurface && mEGLContext)
192 mEGL->MakeContextCurrent(mEGLSurface, mEGLContext);
196 DALI_LOG_ERROR("EGLSurface(%p) or mEGLContext(%p) is null\n", mEGLSurface, mEGLContext);
201 bool NativeImageSurfaceEcoreWl::CanRender()
203 return tbm_surface_queue_can_dequeue(mTbmQueue, 0);
206 } // namespace Adaptor
207 } // namespace Internal