Ensure BaseHandle class move noexcept (core public-api)
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / frame-buffer.cpp
index e6a2405..311d66a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 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.
 // CLASS HEADER
 #include <dali/public-api/rendering/frame-buffer.h>
 
+// EXTERNAL INCLUDES
+#include <type_traits>
+
 // INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>                      // DALI_LOG_WARNING_NOFN
 #include <dali/internal/event/rendering/frame-buffer-impl.h> // Dali::Internal::FrameBuffer
-
+#include <dali/internal/event/rendering/texture-impl.h>      // Dali::Internal::Texture
 
 namespace Dali
 {
-
-FrameBuffer FrameBuffer::New( unsigned int width, unsigned int height, Format format )
+namespace
 {
-  Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, format );
-  return FrameBuffer( frameBuffer.Get() );
-}
-
-FrameBuffer::FrameBuffer()
+/// Bool operator for FrameBuffer::Attachment::Mask.
+/// in cpp as only used in this file
+bool operator&(FrameBuffer::Attachment::Mask lhs, FrameBuffer::Attachment::Mask rhs)
 {
+  using UnderlyingType = typename std::underlying_type<FrameBuffer::Attachment::Mask>::type;
+  return static_cast<bool>(static_cast<UnderlyingType>(lhs) & static_cast<UnderlyingType>(rhs));
 }
 
-FrameBuffer::~FrameBuffer()
-{
-}
+} // unnamed namespace
 
-FrameBuffer::FrameBuffer( const FrameBuffer& handle )
-: BaseHandle( handle )
+FrameBuffer FrameBuffer::New(uint32_t width, uint32_t height)
 {
+  return New(width, height, FrameBuffer::Attachment::COLOR);
 }
 
-FrameBuffer FrameBuffer::DownCast( BaseHandle handle )
+FrameBuffer FrameBuffer::New(uint32_t width, uint32_t height, Attachment::Mask attachments)
 {
-  return FrameBuffer( dynamic_cast<Dali::Internal::FrameBuffer*>(handle.GetObjectPtr()));
+  Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New(width, height, attachments);
+  if(attachments & FrameBuffer::Attachment::COLOR)
+  {
+    Internal::TexturePtr texture = Internal::Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
+    frameBuffer->AttachColorTexture(texture, 0u, 0u);
+  }
+  return FrameBuffer(frameBuffer.Get());
 }
 
-FrameBuffer& FrameBuffer::operator=( const FrameBuffer& handle )
+FrameBuffer::FrameBuffer() = default;
+
+FrameBuffer::~FrameBuffer() = default;
+
+FrameBuffer::FrameBuffer(const FrameBuffer& handle) = default;
+
+FrameBuffer FrameBuffer::DownCast(BaseHandle handle)
 {
-  BaseHandle::operator=( handle );
-  return *this;
+  return FrameBuffer(dynamic_cast<Dali::Internal::FrameBuffer*>(handle.GetObjectPtr()));
 }
 
-FrameBuffer::FrameBuffer( Internal::FrameBuffer* pointer )
-: BaseHandle( pointer )
+FrameBuffer& FrameBuffer::operator=(const FrameBuffer& handle) = default;
+
+FrameBuffer::FrameBuffer(Internal::FrameBuffer* pointer)
+: BaseHandle(pointer)
 {
 }
 
-void FrameBuffer::AttachColorTexture( Texture& texture )
+FrameBuffer::FrameBuffer(FrameBuffer&& rhs) noexcept = default;
+
+FrameBuffer& FrameBuffer::operator=(FrameBuffer&& rhs) noexcept = default;
+
+void FrameBuffer::AttachColorTexture(Texture& texture)
 {
-  AttachColorTexture( texture, 0u, 0u );
+  AttachColorTexture(texture, 0u, 0u);
 }
 
-void FrameBuffer::AttachColorTexture( Texture& texture, unsigned int mipmapLevel, unsigned int layer )
+void FrameBuffer::AttachColorTexture(Texture& texture, uint32_t mipmapLevel, uint32_t layer)
 {
-  if( texture )
+  if(texture)
   {
-    Internal::NewTexturePtr texturePtr( &GetImplementation( texture ) );
-    GetImplementation(*this).AttachColorTexture( texturePtr, mipmapLevel, layer );
+    Internal::TexturePtr texturePtr(&GetImplementation(texture));
+    GetImplementation(*this).AttachColorTexture(texturePtr, mipmapLevel, layer);
   }
 }
 
 Texture FrameBuffer::GetColorTexture()
 {
-  Internal::NewTexture* texturePtr = GetImplementation(*this).GetColorTexture();
-  return Dali::Texture( texturePtr );
+  Internal::Texture* texturePtr = GetImplementation(*this).GetColorTexture(0);
+  return Dali::Texture(texturePtr);
 }
 
 } //namespace Dali