Remove RenderSurface from Core
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / frame-buffer-impl.cpp
index 20d09d3..e26b0ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 
 // INTERNAL INCLUDES
 #include <dali/internal/update/manager/update-manager.h>
-#include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/render/renderers/render-frame-buffer.h>
 
 namespace Dali
@@ -28,52 +27,66 @@ namespace Dali
 namespace Internal
 {
 
-FrameBufferPtr FrameBuffer::New( unsigned int width, unsigned int height, unsigned int attachments  )
+FrameBufferPtr FrameBuffer::New( uint32_t width, uint32_t height, Mask attachments  )
 {
   FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
   frameBuffer->Initialize();
   return frameBuffer;
 }
 
-
 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
 {
   return mRenderObject;
 }
 
-FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments )
-: mEventThreadServices( *Stage::GetCurrent() ),
+FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
+: mEventThreadServices( EventThreadServices::Get() ),
   mRenderObject( NULL ),
-  mColor( NULL ),
+  mColor{ nullptr },
   mWidth( width ),
   mHeight( height ),
-  mAttachments( attachments )
+  mAttachments( attachments ),
+  mColorAttachmentCount( 0 )
 {
 }
 
 void FrameBuffer::Initialize()
 {
-  mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mAttachments );
-  AddFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
+   mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mAttachments );
+
+  OwnerPointer< Render::FrameBuffer > transferOwnership( mRenderObject );
+  AddFrameBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership );
 }
 
-void FrameBuffer::AttachColorTexture( TexturePtr texture, unsigned int mipmapLevel, unsigned int layer )
+void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer )
 {
-  if( ( texture->GetWidth() / ( 1u << mipmapLevel ) == mWidth ) &&
-      ( texture->GetHeight() / ( 1u << mipmapLevel ) == mHeight ) )
+  if( ( texture->GetWidth() / ( 1u << mipmapLevel ) != mWidth ) ||
+      ( texture->GetHeight() / ( 1u << mipmapLevel ) != mHeight ) )
   {
-    mColor = texture;
-    AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
+    DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
+  }
+  else if ( mColorAttachmentCount >= Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS )
+  {
+    DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Exceeded maximum supported color attachments.\n" );
   }
   else
   {
-    DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
+    mColor[mColorAttachmentCount] = texture;
+    ++mColorAttachmentCount;
+
+    AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
   }
 }
 
-Texture* FrameBuffer::GetColorTexture()
+Texture* FrameBuffer::GetColorTexture(uint8_t index) const
+{
+  return ( index >= mColorAttachmentCount ) ? nullptr : mColor[index].Get();
+}
+
+void FrameBuffer::SetSize( uint32_t width, uint32_t height )
 {
-  return mColor.Get();
+  mWidth = width;
+  mHeight = height;
 }
 
 FrameBuffer::~FrameBuffer()