[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-surface-frame-buffer.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 7cc38bb..babd67f
@@ -30,7 +30,14 @@ namespace Render
 SurfaceFrameBuffer::SurfaceFrameBuffer( Integration::RenderSurface* surface )
 : FrameBuffer(),
   mSurface( surface ),
-  mContext( nullptr )
+  mContext( nullptr ),
+  mWidth( mSurface->GetPositionSize().width ),
+  mHeight( mSurface->GetPositionSize().height ),
+  mBackgroundColor( 0.f, 0.f, 0.f, 1.f ),
+  mSizeChanged( false ),
+  mBackgroundColorChanged( false ),
+  mIsSurfaceInvalid( false ),
+  mPartialUpdateEnabled( true )
 {
 }
 
@@ -39,6 +46,11 @@ SurfaceFrameBuffer::~SurfaceFrameBuffer()
 
 void SurfaceFrameBuffer::Destroy( Context& context )
 {
+  if ( IsSurfaceValid() )
+  {
+    mSurface->DestroySurface();
+    mSurface = nullptr;
+  }
 }
 
 void SurfaceFrameBuffer::GlContextDestroyed()
@@ -47,34 +59,65 @@ void SurfaceFrameBuffer::GlContextDestroyed()
   {
     mContext->GlContextDestroyed();
   }
+
+  if ( IsSurfaceValid() )
+  {
+    mSurface->DestroySurface();
+    mSurface = nullptr;
+  }
 }
 
 void SurfaceFrameBuffer::Initialize(Context& context)
 {
   mContext = &context;
   mContext->GlContextCreated();
-  mSurface->InitializeGraphics();
+
+  if ( IsSurfaceValid() )
+  {
+    mSurface->InitializeGraphics();
+  }
 }
 
 void SurfaceFrameBuffer::Bind( Context& context )
 {
-  mSurface->PreRender( false );
-  context.BindFramebuffer( GL_FRAMEBUFFER, 0u );
+  if ( IsSurfaceValid() )
+  {
+    mSurface->PreRender( mSizeChanged );
+
+    context.BindFramebuffer( GL_FRAMEBUFFER, 0u );
+  }
 }
 
 uint32_t SurfaceFrameBuffer::GetWidth() const
 {
-  return mSurface->GetPositionSize().width;
+  return mWidth;
 }
 
 uint32_t SurfaceFrameBuffer::GetHeight() const
 {
-  return mSurface->GetPositionSize().height;
+  return mHeight;
 }
 
 void SurfaceFrameBuffer::PostRender()
 {
-  mSurface->PostRender( false, false, false );
+  if ( IsSurfaceValid() )
+  {
+    mSurface->PostRender( false, false, mSizeChanged );
+  }
+
+  mSizeChanged = false;
+  mBackgroundColorChanged = false;
+  mPartialUpdateEnabled = true;
+}
+
+Rect<int32_t> SurfaceFrameBuffer::SetDamagedRect( const Rect<int32_t>& damagedRect )
+{
+  Rect<int32_t> ret;
+  if ( IsSurfaceValid() )
+  {
+    ret = mSurface->SetDamagedRect( damagedRect );
+  }
+  return ret;
 }
 
 Context* SurfaceFrameBuffer::GetContext()
@@ -82,19 +125,50 @@ Context* SurfaceFrameBuffer::GetContext()
   return mContext;
 }
 
-Integration::DepthBufferAvailable SurfaceFrameBuffer::GetDepthBufferRequired()
+void SurfaceFrameBuffer::MakeContextCurrent()
 {
-  return mSurface->GetDepthBufferRequired();
+  if ( IsSurfaceValid() )
+  {
+    mSurface->MakeContextCurrent();
+  }
 }
 
-Integration::StencilBufferAvailable SurfaceFrameBuffer::GetStencilBufferRequired()
+Vector4 SurfaceFrameBuffer::GetBackgroundColor()
 {
-  return mSurface->GetStencilBufferRequired();
+  return mBackgroundColor;
 }
 
-Vector4 SurfaceFrameBuffer::GetBackgroundColor()
+void SurfaceFrameBuffer::SetSize( uint32_t width, uint32_t height )
+{
+  mWidth = width;
+  mHeight = height;
+  mSizeChanged = true;
+}
+
+void SurfaceFrameBuffer::SetBackgroundColor( const Vector4& color )
+{
+  mBackgroundColor = color;
+  mBackgroundColorChanged = true;
+}
+
+bool SurfaceFrameBuffer::IsSurfaceValid() const
+{
+  return mSurface && !mIsSurfaceInvalid;
+}
+
+bool SurfaceFrameBuffer::IsPartialUpdateEnabled() const
+{
+  bool ret = false;
+  if ( IsSurfaceValid() )
+  {
+    ret = mSurface->GetBufferAge() && ( mPartialUpdateEnabled && !( mSizeChanged || mBackgroundColorChanged ) );
+  }
+  return ret;
+}
+
+void SurfaceFrameBuffer::SetPartialUpdateEnabled( bool value )
 {
-  return mSurface->GetBackgroundColor();
+  mPartialUpdateEnabled = value;
 }
 
 } //Render