[4.0] Supports screen rotation. 68/183768/9 accepted/tizen/4.0/unified/20181011.183758 submit/tizen_4.0/20181004.072517 submit/tizen_4.0/20181005.021603 submit/tizen_4.0/20181010.011946
authorJoogab Yun <joogab.yun@samsung.com>
Wed, 11 Jul 2018 01:11:07 +0000 (10:11 +0900)
committerjoogab yun <joogab.yun@samsung.com>
Thu, 2 Aug 2018 01:03:51 +0000 (01:03 +0000)
If the screen rotates, we need to change egl size and the buffer needs to be rotated.
So we need the orientation value in SurfaceResized.
SurfaceResized() API overloaded.

Change-Id: I81ac894c2f64ea5d71ea95624c00c3fa459d19e5

dali/integration-api/core.cpp [changed mode: 0644->0755]
dali/integration-api/core.h [changed mode: 0644->0755]
dali/internal/common/core-impl.cpp [changed mode: 0644->0755]
dali/internal/common/core-impl.h [changed mode: 0644->0755]
dali/internal/event/common/stage-impl.cpp [changed mode: 0644->0755]
dali/internal/event/common/stage-impl.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 41dfa0d..ac83383
@@ -84,6 +84,11 @@ void Core::SurfaceResized(unsigned int width, unsigned int height)
   mImpl->SurfaceResized(width, height);
 }
 
+void Core::SurfaceResized( unsigned int width, unsigned int height, int orientation )
+{
+  mImpl->SurfaceResized(width, height, orientation);
+}
+
 void Core::SetTopMargin( unsigned int margin )
 {
   mImpl->SetTopMargin(margin);
old mode 100644 (file)
new mode 100755 (executable)
index 39f3416..e099689
@@ -288,6 +288,18 @@ public:
    */
   void SurfaceResized(unsigned int width, unsigned int height);
 
+
+  /**
+   * Notify the Core that the GL surface has been resized and rotated.
+   * This should be done at least once i.e. after the first call to ContextCreated().
+   * The Core will use the surface size or orientation for camera calculations, and to set the GL viewport.
+   * Multi-threading note: this method should be called from the main thread
+   * @param[in] width The new surface width.
+   * @param[in] height The new surface height.
+   * @param[in] orientation The new surface orientation.
+   */
+  void SurfaceResized( unsigned int width, unsigned int height, int orientation );
+
   /**
    * Notify the Core about the top margin size.
    * Available stage size is reduced by this size.
old mode 100644 (file)
new mode 100755 (executable)
index 53378e0..ae5a35a
@@ -196,6 +196,15 @@ void Core::SurfaceResized( unsigned int width, unsigned int height )
   mRelayoutController->SetStageSize( size.width, size.height );
 }
 
+void Core::SurfaceResized( unsigned int width, unsigned int height, int orientation )
+{
+  mStage->SurfaceResized( width, height, orientation );
+
+  // The stage-size may be less than surface-size (reduced by top-margin)
+  Vector2 size = mStage->GetSize();
+  mRelayoutController->SetStageSize( size.width, size.height );
+}
+
 void Core::SetTopMargin( unsigned int margin )
 {
   mStage->SetTopMargin( margin );
old mode 100644 (file)
new mode 100755 (executable)
index 0e745d7..02b6223
@@ -116,6 +116,11 @@ public:
   void SurfaceResized(unsigned int width, unsigned int height);
 
   /**
+   * @copydoc Dali::Integration::Core::SurfaceResized(unsigned int, unsigned int, int orientation)
+   */
+  void SurfaceResized( unsigned int width, unsigned int height, int orientation );
+
+  /**
    * @copydoc Dali::Integration::Core::SetTopMargin( unsigned int margin )
    */
   void SetTopMargin( unsigned int margin );
old mode 100644 (file)
new mode 100755 (executable)
index b54e34f..0ae2eaf
@@ -120,6 +120,10 @@ void Stage::Initialize( bool renderToFbo )
 
   // Create the default render-task
   Dali::RenderTask defaultRenderTask = mRenderTaskList->CreateTask();
+
+  // init current default camera orientation
+  mNeedToRotation = false;
+  mCurrentOrientation = 0;
 }
 
 void Stage::Uninitialize()
@@ -202,8 +206,11 @@ void Stage::Remove( Actor& actor )
 
 void Stage::SurfaceResized( float width, float height )
 {
-  if( ( fabs( width - mSurfaceSize.width ) > Math::MACHINE_EPSILON_1000 ) || ( fabs( height - mSurfaceSize.height ) > Math::MACHINE_EPSILON_1000 ) )
+  if( ( fabs( width - mSurfaceSize.width ) > Math::MACHINE_EPSILON_1000 ) || ( fabs( height - mSurfaceSize.height ) > Math::MACHINE_EPSILON_1000 )
+      || mNeedToRotation )
   {
+    mNeedToRotation = false;
+
     mSurfaceSize.width = width;
     mSurfaceSize.height = height;
 
@@ -227,7 +234,14 @@ void Stage::SurfaceResized( float width, float height )
       mSystemOverlay->GetImpl()->SetSize( width, height );
     }
 
-    SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, width, height ) );
+    if( mCurrentOrientation == 90 || mCurrentOrientation == 270)
+    {
+      SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, height, width ) );
+    }
+    else
+    {
+      SetDefaultSurfaceRectMessage( mUpdateManager, Rect<int>( 0, 0, width, height ) );
+    }
 
     // if single render task to screen then set its viewport parameters
     if( 1 == mRenderTaskList->GetTaskCount() )
@@ -236,7 +250,14 @@ void Stage::SurfaceResized( float width, float height )
 
       if(!defaultRenderTask.GetTargetFrameBuffer())
       {
-        defaultRenderTask.SetViewport( Viewport(0, 0, width, height) );
+        if( mCurrentOrientation == 90 || mCurrentOrientation == 270)
+        {
+          defaultRenderTask.SetViewport( Viewport(0, 0, height, width) );
+        }
+        else
+        {
+          defaultRenderTask.SetViewport( Viewport(0, 0, width, height) );
+        }
       }
     }
 
@@ -252,6 +273,66 @@ void Stage::SurfaceResized( float width, float height )
   }
 }
 
+void Stage::SurfaceResized( float width, float height, int orientation )
+{
+  // Calculates the angle of rotation.
+  int rotDelta = ( 360 + orientation - mCurrentOrientation ) % 360;
+  Quaternion rotateAngle;
+
+  switch( rotDelta )
+  {
+    case 90:
+    {
+      rotateAngle = Quaternion( Dali::ANGLE_270, Vector3::ZAXIS );
+      break;
+    }
+    case 270:
+    {
+      rotateAngle = Quaternion( Dali::ANGLE_90, Vector3::ZAXIS );
+      break;
+    }
+    case 180:
+    {
+      rotateAngle = Quaternion( Dali::ANGLE_180, Vector3::ZAXIS );
+      break;
+    }
+    default:
+      rotateAngle = Quaternion( Dali::ANGLE_0, Vector3::ZAXIS );
+      break;
+  }
+
+  // set current orientation
+  mCurrentOrientation = orientation;
+  if( rotDelta )
+  {
+    mNeedToRotation = true;
+  }
+
+  // do surface resized
+  SurfaceResized( width, height );
+
+  // If we need to rotate, rotate the camera.
+  if( rotDelta )
+  {
+    // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position depending on the orientation
+    if( mCurrentOrientation == 90 || mCurrentOrientation == 270 )
+    {
+      mDefaultCamera->SetPerspectiveProjection( Vector2( height, width ) );
+      if( mSystemOverlay )
+      {
+        mSystemOverlay->GetImpl()->GetDefaultCameraActor().SetPerspectiveProjection( Vector2( height, width ) );
+      }
+    }
+
+    mDefaultCamera->RotateBy( rotateAngle );
+
+    if( mSystemOverlay )
+    {
+      mSystemOverlay->GetImpl()->GetDefaultCameraActor().RotateBy( rotateAngle );
+    }
+  }
+}
+
 Vector2 Stage::GetSize() const
 {
   return mSize;
old mode 100644 (file)
new mode 100755 (executable)
index c8b04b8..35db048
@@ -150,6 +150,14 @@ public:
   void SurfaceResized( float width, float height );
 
   /**
+   * Used to calculate the size and orientation of the stage and indirectly, the root actor.
+   * @param [in] width  The new surface width.
+   * @param [in] height The new surface height.
+   * @param [in] orientation The new surface orientation.
+   */
+  void SurfaceResized( float width, float height, int orientation );
+
+  /**
    * Sets the top margin size.
    * Available stage size is reduced by this size.
    * The stage is located below the size at the top of the display
@@ -548,6 +556,9 @@ private:
   bool mDepthTreeDirty:1;  ///< True if the depth tree needs recalculating
   bool mForceNextUpdate:1; ///< True if the next rendering is really required.
   bool mRenderToFbo:1;     ///< Whether to render to a Frame Buffer Object.
+
+  bool mNeedToRotation:1;
+  int mCurrentOrientation;
 };
 
 } // namespace Internal