[Tizen] Support Client Rotation and Screen Rotation
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.cpp
index 8fc7c6c..086c553 100644 (file)
@@ -50,6 +50,13 @@ namespace Internal
 namespace SceneGraph
 {
 
+#if defined(DEBUG_ENABLED)
+namespace
+{
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_RENDER_MANAGER" );
+} // unnamed namespace
+#endif
+
 /**
  * Structure to contain internal data
  */
@@ -77,7 +84,8 @@ struct RenderManager::Impl
     lastFrameWasRendered( false ),
     programController( glAbstraction ),
     depthBufferAvailable( depthBufferAvailableParam ),
-    stencilBufferAvailable( stencilBufferAvailableParam )
+    stencilBufferAvailable( stencilBufferAvailableParam ),
+    defaultSurfaceOrientation( 0 )
   {
   }
 
@@ -152,6 +160,8 @@ struct RenderManager::Impl
   Integration::DepthBufferAvailable         depthBufferAvailable;     ///< Whether the depth buffer is available
   Integration::StencilBufferAvailable       stencilBufferAvailable;   ///< Whether the stencil buffer is available
 
+  int                                       defaultSurfaceOrientation; ///< defaultSurfaceOrientation for the default surface we are rendering to
+
 };
 
 RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction,
@@ -235,6 +245,11 @@ void RenderManager::SetDefaultSurfaceRect(const Rect<int32_t>& rect)
   mImpl->defaultSurfaceRect = rect;
 }
 
+void RenderManager::SetDefaultSurfaceOrientation( int orientation )
+{
+  mImpl->defaultSurfaceOrientation = orientation;
+}
+
 void RenderManager::AddRenderer( OwnerPointer< Render::Renderer >& renderer )
 {
   // Initialize the renderer as we are now in render thread
@@ -303,16 +318,17 @@ void RenderManager::SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, u
   sampler->mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
 }
 
-void RenderManager::AddFrameBuffer( Render::FrameBuffer* frameBuffer )
+void RenderManager::AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer )
 {
-  mImpl->frameBufferContainer.PushBack( frameBuffer );
-  if ( frameBuffer->IsSurfaceBacked() )
+  Render::FrameBuffer* frameBufferPtr = frameBuffer.Release();
+  mImpl->frameBufferContainer.PushBack( frameBufferPtr );
+  if ( frameBufferPtr->IsSurfaceBacked() )
   {
-    frameBuffer->Initialize( *mImpl->CreateSurfaceContext() );
+    frameBufferPtr->Initialize( *mImpl->CreateSurfaceContext() );
   }
   else
   {
-    frameBuffer->Initialize( mImpl->context );
+    frameBufferPtr->Initialize( mImpl->context );
   }
 }
 
@@ -450,9 +466,17 @@ void RenderManager::Render( Integration::RenderStatus& status, bool forceClear )
   const uint32_t count = mImpl->instructions.Count( mImpl->renderBufferIndex );
   const bool haveInstructions = count > 0u;
 
+  DALI_LOG_INFO( gLogFilter, Debug::General,
+                 "Render: haveInstructions(%s) || mImpl->lastFrameWasRendered(%s) || forceClear(%s)\n",
+                 haveInstructions ? "true" : "false",
+                 mImpl->lastFrameWasRendered ? "true" : "false",
+                 forceClear ? "true" : "false" );
+
   // Only render if we have instructions to render, or the last frame was rendered (and therefore a clear is required).
   if( haveInstructions || mImpl->lastFrameWasRendered || forceClear )
   {
+    DALI_LOG_INFO( gLogFilter, Debug::General, "Render: Processing\n" );
+
     // Mark that we will require a post-render step to be performed (includes swap-buffers).
     status.SetNeedsPostRender( true );
 
@@ -556,29 +580,38 @@ void RenderManager::DoRender( RenderInstruction& instruction )
   }
 
   Rect<int32_t> surfaceRect = mImpl->defaultSurfaceRect;
+  int surfaceOrientation = mImpl->defaultSurfaceOrientation;
   Vector4 backgroundColor = mImpl->backgroundColor;
   Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
   Integration::StencilBufferAvailable stencilBufferAvailable = mImpl->stencilBufferAvailable;
 
   Render::SurfaceFrameBuffer* surfaceFrameBuffer = nullptr;
-  if ( ( instruction.mFrameBuffer != 0 ) && instruction.mFrameBuffer->IsSurfaceBacked() )
+  if ( instruction.mFrameBuffer != 0 )
   {
-    surfaceFrameBuffer = static_cast<Render::SurfaceFrameBuffer*>( instruction.mFrameBuffer );
-
-    if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+    if ( instruction.mFrameBuffer->IsSurfaceBacked() )
     {
-      Context* surfaceContext = surfaceFrameBuffer->GetContext();
-      if ( mImpl->currentContext != surfaceContext )
+      surfaceFrameBuffer = static_cast<Render::SurfaceFrameBuffer*>( instruction.mFrameBuffer );
+
+      if ( mImpl->currentContext->IsSurfacelessContextSupported() )
       {
-        // Switch the correct context if rendering to a surface
-        mImpl->currentContext = surfaceContext;
-        // Clear the current cached program when the context is switched
-        mImpl->programController.ClearCurrentProgram();
+        Context* surfaceContext = surfaceFrameBuffer->GetContext();
+        if ( mImpl->currentContext != surfaceContext )
+        {
+          // Switch the correct context if rendering to a surface
+          mImpl->currentContext = surfaceContext;
+          // Clear the current cached program when the context is switched
+          mImpl->programController.ClearCurrentProgram();
+        }
       }
-    }
 
-    surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
-    backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
+      surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
+      backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
+    }
+    else
+    {
+      // Switch to shared context for off-screen buffer
+      mImpl->currentContext = &mImpl->context;
+    }
   }
 
   DALI_ASSERT_DEBUG( mImpl->currentContext->IsGlContextCreated() );
@@ -644,7 +677,7 @@ void RenderManager::DoRender( RenderInstruction& instruction )
         // For glViewport the lower-left corner is (0,0)
         // For glViewport the lower-left corner is (0,0)
         const int32_t y = ( surfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y;
-        viewportRect.Set( instruction.mViewport.x,  y, instruction.mViewport.width, instruction.mViewport.height );
+        viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
       }
       else
       {
@@ -663,6 +696,7 @@ void RenderManager::DoRender( RenderInstruction& instruction )
       {
         viewportRect.Set( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
       }
+      surfaceOrientation = 0;
     }
   }
   else // No Offscreen frame buffer rendering
@@ -674,7 +708,7 @@ void RenderManager::DoRender( RenderInstruction& instruction )
       {
         // For glViewport the lower-left corner is (0,0)
         const int32_t y = ( instruction.mFrameBuffer->GetHeight() - instruction.mViewport.height ) - instruction.mViewport.y;
-        viewportRect.Set( instruction.mViewport.x,  y, instruction.mViewport.width, instruction.mViewport.height );
+        viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
       }
       else
       {
@@ -687,6 +721,13 @@ void RenderManager::DoRender( RenderInstruction& instruction )
     }
   }
 
+  if ( surfaceOrientation == 90 || surfaceOrientation == 270 )
+  {
+    int temp = viewportRect.width;
+    viewportRect.width = viewportRect.height;
+    viewportRect.height = temp;
+  }
+
   mImpl->currentContext->Viewport(viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height);
 
   if ( instruction.mIsClearColorSet )
@@ -709,7 +750,8 @@ void RenderManager::DoRender( RenderInstruction& instruction )
       *mImpl->currentContext,
       mImpl->renderBufferIndex,
       depthBufferAvailable,
-      stencilBufferAvailable );
+      stencilBufferAvailable,
+      surfaceOrientation );
 
   if( instruction.mRenderTracker && ( instruction.mFrameBuffer != 0 ) )
   {