Use CallbackBase in GlWindow 41/245341/12
authorWonsik Jung <sidein@samsung.com>
Wed, 7 Oct 2020 09:19:23 +0000 (18:19 +0900)
committerWonsik Jung <sidein@samsung.com>
Thu, 5 Nov 2020 02:07:38 +0000 (11:07 +0900)
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

automated-tests/src/dali-adaptor/utc-Dali-Gl-Window.cpp
dali/devel-api/adaptor-framework/gl-window.cpp
dali/devel-api/adaptor-framework/gl-window.h
dali/internal/window-system/common/gl-window-impl.cpp
dali/internal/window-system/common/gl-window-impl.h

index d77d9bf..d551f4a 100644 (file)
@@ -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 );
index bbad021..e9346e3 100644 (file)
@@ -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()
 {
index 1efc014..c8b4ab2 100644 (file)
@@ -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.
index 33952ea..d17d5d0 100644 (file)
@@ -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<int>(*mGLRenderFrameCallback);
   }
 
   if( mIsWindowRotated )
@@ -813,7 +815,10 @@ bool GlWindow::RunCallback()
     mIsWindowRotated = false;
   }
 
-  eglImpl.SwapBuffers( mEGLSurface );
+  if(renderFrameResult)
+  {
+    eglImpl.SwapBuffers( mEGLSurface );
+  }
 
   return true;
 }
index fbecfc5..cd18a2b 100644 (file)
@@ -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;