Revert "[Tizen] Partial rendering rotation does not work."
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.cpp
index 905032a..3114f55 100644 (file)
 #include <memory.h>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/sampling.h>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/render-tasks/render-task.h>
 #include <dali/devel-api/threading/thread-pool.h>
-#include <dali/integration-api/debug.h>
 #include <dali/integration-api/core.h>
 #include <dali/integration-api/gl-context-helper-abstraction.h>
-#include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/event/common/scene-impl.h>
 #include <dali/internal/render/common/render-algorithms.h>
 #include <dali/internal/render/common/render-debug.h>
 #include <dali/internal/render/common/render-tracker.h>
-#include <dali/internal/render/common/render-instruction-container.h>
-#include <dali/internal/render/common/render-instruction.h>
-#include <dali/internal/render/gl-resources/context.h>
 #include <dali/internal/render/queue/render-queue.h>
-#include <dali/internal/render/renderers/render-frame-buffer.h>
-#include <dali/internal/render/renderers/render-geometry.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-#include <dali/internal/render/renderers/render-sampler.h>
 #include <dali/internal/render/shaders/program-controller.h>
-#include <dali/internal/update/common/scene-graph-scene.h>
 
 namespace Dali
 {
@@ -139,7 +125,8 @@ struct RenderManager::Impl
     depthBufferAvailable( depthBufferAvailableParam ),
     stencilBufferAvailable( stencilBufferAvailableParam ),
     partialUpdateAvailable( partialUpdateAvailableParam ),
-    itemsCheckSum(0)
+    itemsCheckSum(0),
+    defaultSurfaceOrientation( 0 )
   {
      // Create thread pool with just one thread ( there may be a need to create more threads in the future ).
     threadPool = std::unique_ptr<Dali::ThreadPool>( new Dali::ThreadPool() );
@@ -164,22 +151,27 @@ struct RenderManager::Impl
 
   Context* CreateSceneContext()
   {
-    sceneContextContainer.push_back( new Context( glAbstraction ) );
-    return sceneContextContainer[ sceneContextContainer.size() - 1 ];
+    Context* context = new Context( glAbstraction );
+    sceneContextContainer.PushBack( context );
+    return context;
   }
 
   void DestroySceneContext( Context* sceneContext )
   {
-    auto iter = std::find( sceneContextContainer.begin(), sceneContextContainer.end(), sceneContext );
-    if( iter != sceneContextContainer.end() )
+    auto iter = std::find( sceneContextContainer.Begin(), sceneContextContainer.End(), sceneContext );
+    if( iter != sceneContextContainer.End() )
     {
-      sceneContextContainer.erase( iter );
+      ( *iter )->GlContextDestroyed();
+      sceneContextContainer.Erase( iter );
     }
   }
 
   Context* ReplaceSceneContext( Context* oldSceneContext )
   {
     Context* newContext = new Context( glAbstraction );
+
+    oldSceneContext->GlContextDestroyed();
+
     std::replace( sceneContextContainer.begin(), sceneContextContainer.end(), oldSceneContext, newContext );
     return newContext;
   }
@@ -196,7 +188,7 @@ struct RenderManager::Impl
   // programs are owned by context at the moment.
   Context                                   context;                 ///< Holds the GL state of the share resource context
   Context*                                  currentContext;          ///< Holds the GL state of the current context for rendering
-  std::vector< Context* >                   sceneContextContainer;   ///< List of owned contexts holding the GL state per scene
+  OwnerContainer< Context* >                sceneContextContainer;   ///< List of owned contexts holding the GL state per scene
   Integration::GlAbstraction&               glAbstraction;           ///< GL abstraction
   Integration::GlSyncAbstraction&           glSyncAbstraction;       ///< GL sync abstraction
   Integration::GlContextHelperAbstraction&  glContextHelperAbstraction; ///< GL context helper abstraction
@@ -233,6 +225,7 @@ struct RenderManager::Impl
   Vector<GLuint>                            textureDependencyList;    ///< The dependency list of binded textures
   std::size_t                               itemsCheckSum;            ///< The damaged render items checksum from previous prerender phase.
   std::vector<DirtyRect>                    itemsDirtyRects;
+  int                                       defaultSurfaceOrientation; ///< defaultSurfaceOrientation for the default surface we are rendering to
 };
 
 RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction,
@@ -299,10 +292,10 @@ void RenderManager::ContextDestroyed()
     renderer->GlContextDestroyed();
   }
 
-  // inform scenes
-  for( auto&& scene : mImpl->sceneContainer )
+  // inform context
+  for( auto&& context : mImpl->sceneContextContainer )
   {
-    scene->GlContextDestroyed();
+    context->GlContextDestroyed();
   }
 }
 
@@ -316,6 +309,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
@@ -877,6 +875,7 @@ void RenderManager::RenderScene( Integration::RenderStatus& status, Integration:
     Rect<int32_t> surfaceRect = mImpl->defaultSurfaceRect;
     Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
     Integration::StencilBufferAvailable stencilBufferAvailable = mImpl->stencilBufferAvailable;
+    int surfaceOrientation = mImpl->defaultSurfaceOrientation;
 
     if ( instruction.mFrameBuffer )
     {
@@ -912,7 +911,8 @@ void RenderManager::RenderScene( Integration::RenderStatus& status, Integration:
       surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( scene.GetSize().width ), static_cast<int32_t>( scene.GetSize().height ) );
     }
 
-    DALI_ASSERT_DEBUG( mImpl->currentContext->IsGlContextCreated() );
+    // Make sure that GL context must be created
+     mImpl->currentContext->GlContextCreated();
 
     // reset the program matrices for all programs once per frame
     // this ensures we will set view and projection matrix once per program per camera
@@ -975,6 +975,7 @@ void RenderManager::RenderScene( Integration::RenderStatus& status, Integration:
       {
         viewportRect.Set( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
       }
+      surfaceOrientation = 0;
     }
     else // No Offscreen frame buffer rendering
     {
@@ -991,6 +992,13 @@ void RenderManager::RenderScene( Integration::RenderStatus& status, Integration:
       }
     }
 
+    if( surfaceOrientation == 90 || surfaceOrientation == 270 )
+    {
+      int temp = viewportRect.width;
+      viewportRect.width = viewportRect.height;
+      viewportRect.height = temp;
+    }
+
     bool clearFullFrameRect = true;
     if( instruction.mFrameBuffer != 0 )
     {
@@ -1054,7 +1062,8 @@ void RenderManager::RenderScene( Integration::RenderStatus& status, Integration:
         depthBufferAvailable,
         stencilBufferAvailable,
         mImpl->boundTextures,
-        clippingRect );
+        clippingRect,
+        surfaceOrientation );
 
     // Synchronise the FBO/Texture access when there are multiple contexts
     if ( mImpl->currentContext->IsSurfacelessContextSupported() )