From 9bf0929e4fd7c41ce2466908941740fa43c0d51e Mon Sep 17 00:00:00 2001 From: Wonsik Jung Date: Wed, 7 Oct 2020 18:19:23 +0900 Subject: [PATCH] Use CallbackBase in GlWindow Use CallbackBase in GlWindow's register gl callback function. In addition, renderFrameCallback function's return value is changed. It is for efficient rendering in render callback function. Change-Id: I7b1210d3a0ff7f1e4b30f10ae1809924a9f867e5 --- .../src/dali-adaptor/utc-Dali-Gl-Window.cpp | 12 ++++---- dali/devel-api/adaptor-framework/gl-window.cpp | 4 +-- dali/devel-api/adaptor-framework/gl-window.h | 34 +++++++++++++++------- .../window-system/common/gl-window-impl.cpp | 27 ++++++++++------- .../internal/window-system/common/gl-window-impl.h | 8 ++--- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/automated-tests/src/dali-adaptor/utc-Dali-Gl-Window.cpp b/automated-tests/src/dali-adaptor/utc-Dali-Gl-Window.cpp index d77d9bf..d551f4a 100644 --- a/automated-tests/src/dali-adaptor/utc-Dali-Gl-Window.cpp +++ b/automated-tests/src/dali-adaptor/utc-Dali-Gl-Window.cpp @@ -382,15 +382,17 @@ int UtcDaliWindowGetCurrentOrientation(void) } // Internal callback function -void glInit() +void glInit(void) { } -void glRenderFrame() +int glRenderFrame(void) { + static unsigned int retFlag = 0; + return retFlag++; } -void glTerminate() +void glTerminate(void) { } @@ -400,7 +402,7 @@ int UtcDaliGlWindowRegisterGlCallback(void) try { - window.RegisterGlCallback( glInit, glRenderFrame, glTerminate ); + window.RegisterGlCallback( Dali::MakeCallback( glInit ), Dali::MakeCallback( glRenderFrame ), Dali::MakeCallback( glTerminate ) ); DALI_TEST_CHECK( false ); } @@ -417,7 +419,7 @@ int UtcDaliGlWindowRenderOnce(void) try { - window.RegisterGlCallback( glInit, glRenderFrame, glTerminate ); + window.RegisterGlCallback( Dali::MakeCallback( glInit ), Dali::MakeCallback( glRenderFrame ), Dali::MakeCallback( glTerminate ) ); window.RenderOnce(); DALI_TEST_CHECK( false ); diff --git a/dali/devel-api/adaptor-framework/gl-window.cpp b/dali/devel-api/adaptor-framework/gl-window.cpp index bbad021..e9346e3 100644 --- a/dali/devel-api/adaptor-framework/gl-window.cpp +++ b/dali/devel-api/adaptor-framework/gl-window.cpp @@ -150,9 +150,9 @@ void GlWindow::SetPreferredOrientation( Dali::GlWindow::GlWindowOrientation orie { GetImplementation(*this).SetPreferredOrientation( orientation ); } -void GlWindow::RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate ) +void GlWindow::RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback ) { - GetImplementation(*this).RegisterGlCallback( glInit, glRenderFrame, glTerminate ); + GetImplementation(*this).RegisterGlCallback( initCallback, renderFrameCallback, terminateCallback ); } void GlWindow::RenderOnce() { diff --git a/dali/devel-api/adaptor-framework/gl-window.h b/dali/devel-api/adaptor-framework/gl-window.h index 1efc014..c8b4ab2 100644 --- a/dali/devel-api/adaptor-framework/gl-window.h +++ b/dali/devel-api/adaptor-framework/gl-window.h @@ -48,13 +48,6 @@ class GlWindow; } } -namespace -{ -typedef void (*GlInitialize)(); -typedef void (*GlRenderFrame)(); -typedef void (*GlTerminate)(); -} - class TouchEvent; class KeyEvent; @@ -350,12 +343,31 @@ public: /** * @brief Registers a GL callback function for application. * - * @param[in] glInit the callback function for application initialize - * @param[in] glRenderFrame the callback function to render to the frame. - * @param[in] glTerminate the callback function to clean-up application GL resource. + * @param[in] initCallback the callback function for application initialize + * @param[in] renderFrameCallback the callback function to render for the frame. + * @param[in] terminateCallback the callback function to clean-up application GL resource. + * + * @note Function must be called on idle time + * + * A initCallback of the following type should be used: + * @code + * void intializeGL(); + * @endcode + * This callback will be called before renderFrame callback is called at once. + * + * A renderFrameCallback of the following type should be used: + * @code + * int renderFrameGL(); + * @endcode + * This callback's return value is not 0, the eglSwapBuffers() will be called. * + * A terminateCallback of the following type should be used: + * @code + * void terminateGL(); + * @endcode + * This callback is called when GlWindow is deleted. */ - void RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate ); + void RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback ); /** * @brief Renders once more even if GL render functions are not added to idler. diff --git a/dali/internal/window-system/common/gl-window-impl.cpp b/dali/internal/window-system/common/gl-window-impl.cpp index 33952ea..d17d5d0 100644 --- a/dali/internal/window-system/common/gl-window-impl.cpp +++ b/dali/internal/window-system/common/gl-window-impl.cpp @@ -93,9 +93,9 @@ GlWindow::GlWindow() mFocusChangeSignal(), mResizeSignal(), mVisibilityChangedSignal(), - mGLInitCallback( 0 ), - mGLRenderFrameCallback( 0 ), - mGLTerminateCallback( 0 ), + mGLInitCallback(), + mGLRenderFrameCallback(), + mGLTerminateCallback(), mGLRenderCallback( nullptr ), mEGLSurface( nullptr ), mEGLContext( nullptr ), @@ -117,7 +117,7 @@ GlWindow::~GlWindow() if( mGLTerminateCallback ) { - mGLTerminateCallback(); + CallbackBase::Execute(*mGLTerminateCallback); } if( mIsEGLInitialize ) @@ -747,15 +747,15 @@ void GlWindow::SetChild( Dali::Window& child ) } } -void GlWindow::RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate ) +void GlWindow::RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback ) { if( mIsEGLInitialize == false ) { InitializeGraphics(); } - mGLInitCallback = glInit; - mGLRenderFrameCallback = glRenderFrame; - mGLTerminateCallback = glTerminate; + mGLInitCallback = std::unique_ptr< CallbackBase >(initCallback); + mGLRenderFrameCallback = std::unique_ptr< CallbackBase >( renderFrameCallback ); + mGLTerminateCallback = std::unique_ptr< CallbackBase >( terminateCallback ); mInitCallback = false; @@ -783,6 +783,8 @@ bool GlWindow::RunCallback() eglImpl.MakeContextCurrent( mEGLSurface, mEGLContext ); + int renderFrameResult = 0; + if( mIsRotated ) { mWindowBase->SetEglWindowBufferTransform( mTotalRotationAngle ); @@ -797,14 +799,14 @@ bool GlWindow::RunCallback() { if( mGLInitCallback ) { - mGLInitCallback(); + CallbackBase::Execute(*mGLInitCallback); } mInitCallback = true; } if( mGLRenderFrameCallback ) { - mGLRenderFrameCallback(); + renderFrameResult = CallbackBase::ExecuteReturn(*mGLRenderFrameCallback); } if( mIsWindowRotated ) @@ -813,7 +815,10 @@ bool GlWindow::RunCallback() mIsWindowRotated = false; } - eglImpl.SwapBuffers( mEGLSurface ); + if(renderFrameResult) + { + eglImpl.SwapBuffers( mEGLSurface ); + } return true; } diff --git a/dali/internal/window-system/common/gl-window-impl.h b/dali/internal/window-system/common/gl-window-impl.h index fbecfc5..cd18a2b 100644 --- a/dali/internal/window-system/common/gl-window-impl.h +++ b/dali/internal/window-system/common/gl-window-impl.h @@ -176,7 +176,7 @@ public: /** * @copydoc Dali::GlWindow::RegisterGlCallback() */ - void RegisterGlCallback( GlInitialize glInit, GlRenderFrame glRenderFrame, GlTerminate glTerminate ); + void RegisterGlCallback( CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback ); /** * @copydoc Dali::GlWindow::RenderOnce() @@ -399,9 +399,9 @@ private: VisibilityChangedSignalType mVisibilityChangedSignal; // EGL, GL Resource - GlInitialize mGLInitCallback; - GlRenderFrame mGLRenderFrameCallback; - GlTerminate mGLTerminateCallback; + std::unique_ptr< CallbackBase > mGLInitCallback; + std::unique_ptr< CallbackBase > mGLRenderFrameCallback; + std::unique_ptr< CallbackBase > mGLTerminateCallback; CallbackBase* mGLRenderCallback; EGLSurface mEGLSurface; EGLContext mEGLContext; -- 2.7.4