1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_RENDER_THREAD_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_RENDER_THREAD_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/devel-api/threading/conditional-wait.h>
23 #include <dali/devel-api/threading/thread.h>
26 #include <dali/internal/graphics/gles/egl-graphics.h>
27 #include <dali/internal/window-system/common/window-base.h>
41 * @brief It is for render thread for GlWindow.
42 * User callbacks works in the thread.
46 * a. Main/Event Thread.
48 * 2. There is NO VSync thread:
49 * a. We calculate the difference between these two times and if:
50 * i. The difference is less than the default frame time, we sleep.
51 * ii. If it’s more or the same, we continue.
52 * 3. Support Rendering mode
54 * i. The rendering loop works continuously.
56 * i. The rendering works by user's request.
57 * ii. User's request is the renderOnce()'s function calling.
60 class GlWindowRenderThread : public Dali::Thread
66 * @param[in] positionSize The position and size of the physical window
67 * @param[in] depth color depth of the physical window
69 GlWindowRenderThread(PositionSize positionSize, ColorDepth colorDepth);
74 virtual ~GlWindowRenderThread();
77 * Sets the GraphicsInterface instance.
78 * This graphics instance is used to create and initialize graphics resource
80 * @param[in] graphics The graphice instance
82 void SetGraphicsInterface(GraphicsInterface* graphics);
85 * Sets the WindowBase instance
86 * This WindowBase instance is used to call wl egl window APIs.
88 * @param[in] windowBase The WindowBase instance
90 void SetWindowBase(WindowBase* windowBase);
93 * @brief Sets egl configuration for GlWindow
95 * @param[in] depth the flag of depth buffer. If true is set, 24bit depth buffer is enabled.
96 * @param[in] stencil the flag of stencil. it true is set, 8bit stencil buffer is enabled.
97 * @param[in] msaa the bit of msaa.
98 * @param[in] version the GLES version.
101 void SetEglConfig(bool depth, bool stencil, int msaa, int version);
104 * Pauses the Render Thread.
105 * It is called when GlWindow is iconified or hidden.
107 * This will lock the mutex in mRenderThreadWaitCondition.
112 * Resumes the Render Thread.
113 * It is called when GlWindow is de-iconified or shown.
115 * This will lock the mutex in mRenderThreadWaitCondition.
120 * Stops the Render Thread.
121 * This will lock the mutex in mRenderThreadWaitCondition.
123 * @note Should only be called in Stop as calling this will kill the render thread.
128 * @copydoc Dali::GlWindow::RegisterGlCallback()
130 void RegisterGlCallback(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback);
133 * Enable OnDemand Rendering Mode
135 * @param[in] onDemand the flag of OnDemand Rendering Mode. If the flag is true, rendering mode is OnDemand, otherwise the flag is false, rendering mode is continuous mode.
137 void SetOnDemandRenderMode(bool onDemand);
140 * @copydoc Dali::GlWindow::RenderOnce()
146 * The Render thread loop. This thread will be destroyed on exit from this function.
152 * @brief Initialize and create EGL resource
154 void InitializeGraphics(EglGraphics* eglGraphics);
157 * Called by the Render Thread which ensures a wait if required.
159 * @param[out] timeToSleepUntil The time remaining in nanoseconds to keep the thread sleeping before resuming.
160 * @return false, if the thread should stop.
162 bool RenderReady(uint64_t& timeToSleepUntil);
165 GraphicsInterface* mGraphics; ///< Graphics interface
166 WindowBase* mWindowBase;
168 const Dali::LogFactoryInterface& mLogFactory;
170 PositionSize mPositionSize; ///< Position
171 ColorDepth mColorDepth;
174 std::unique_ptr<CallbackBase> mGLInitCallback;
175 std::unique_ptr<CallbackBase> mGLRenderFrameCallback;
176 std::unique_ptr<CallbackBase> mGLTerminateCallback;
177 EGLSurface mEGLSurface;
178 EGLContext mEGLContext;
181 bool mIsEGLInitialize : 1;
185 // To manage the render/main thread
186 ConditionalWait mRenderThreadWaitCondition; ///< The wait condition for the update-render-thread.
187 volatile unsigned int mDestroyRenderThread; ///< Stop render thread. It means this rendter thread will be destoried.
188 volatile unsigned int mPauseRenderThread; ///< Sleep render thread by pause.
189 volatile unsigned int mRenderingMode; ///< Rendering Mode, 0: continuous, 1:OnDemad
190 volatile unsigned int mRequestRenderOnce; ///< Request rendering once
192 uint64_t mDefaultFrameDurationNanoseconds; ///< Default duration of a frame (used for sleeping if not enough time elapsed). Not protected by lock, but written to rarely so not worth adding a lock when reading.
194 }; // GlWindowRenderThread
196 } // namespace Adaptor
197 } // namespace Internal