Remove TypeRegistration from deprecated Image classes
[platform/core/uifw/dali-core.git] / dali / internal / event / images / frame-buffer-image-impl.cpp
index e20e2c4..def730a 100644 (file)
@@ -1,25 +1,26 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // CLASS HEADER
 #include <dali/internal/event/images/frame-buffer-image-impl.h>
 
 // INTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
 #include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/resources/resource-client.h>
 
 namespace Dali
 {
@@ -27,98 +28,69 @@ namespace Dali
 namespace Internal
 {
 
-FrameBufferImage::~FrameBufferImage()
+namespace
 {
-}
-
-FrameBufferImagePtr  FrameBufferImage::New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
+const int RenderBufferFormatToFrameBufferAttachments[]  = { Dali::FrameBuffer::Attachment::NONE,
+                                                            Dali::FrameBuffer::Attachment::DEPTH,
+                                                            Dali::FrameBuffer::Attachment::STENCIL,
+                                                            Dali::FrameBuffer::Attachment::DEPTH_STENCIL
+                                                          };
+
+} // unnamed namespace
+
+FrameBufferImagePtr FrameBufferImage::New( unsigned int width,
+                                           unsigned int height,
+                                           Pixel::Format pixelFormat,
+                                           RenderBuffer::Format bufferformat )
 {
-  FrameBufferImagePtr image = new FrameBufferImage(width, height, pixelFormat, releasePolicy);
+  FrameBufferImagePtr image = new FrameBufferImage( width, height );
   image->Initialize();
-  return image;
-}
 
-FrameBufferImagePtr  FrameBufferImage::New( NativeImage& nativeImage )
-{
-  FrameBufferImagePtr image = new FrameBufferImage(nativeImage);
-  image->Initialize();
+  image->mTexture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelFormat, width, height );
+  image->mFrameBufferObject = FrameBuffer::New( width, height, RenderBufferFormatToFrameBufferAttachments[bufferformat] );
+  image->mFrameBufferObject->AttachColorTexture( image->mTexture, 0u, 0u );
+
   return image;
 }
 
-FrameBufferImagePtr  FrameBufferImage::New( NativeImage& nativeImage, ReleasePolicy releasePolicy )
+FrameBufferImagePtr FrameBufferImage::New( NativeImageInterface& nativeImage )
 {
-  FrameBufferImagePtr image = new FrameBufferImage(nativeImage, releasePolicy);
+  FrameBufferImagePtr image = new FrameBufferImage( nativeImage );
   image->Initialize();
+
+  image->mTexture = Texture::New( nativeImage );
+  image->mFrameBufferObject = FrameBuffer::New( image->mTexture->GetWidth(), image->mTexture->GetHeight(), Dali::FrameBuffer::Attachment::NONE );
+  image->mFrameBufferObject->AttachColorTexture( image->mTexture, 0u, 0u );
+
   return image;
 }
 
-FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy)
-: Image(Dali::Image::Immediate, releasePolicy),
-  mPixelFormat(pixelFormat)
+FrameBufferImage::FrameBufferImage( unsigned int width, unsigned int height)
+: Image(),
+  mNativeImage(0),
+  mIsNativeFbo( false )
 {
   mWidth  = width;
   mHeight = height;
 }
 
-
-FrameBufferImage::FrameBufferImage( NativeImage& nativeImage )
-: Image(Dali::Image::Immediate),
-  mNativeImage(&nativeImage),
-  mPixelFormat(nativeImage.GetPixelFormat())
+FrameBufferImage::FrameBufferImage( NativeImageInterface& nativeImage )
+: Image(),
+  mNativeImage( &nativeImage ),
+  mIsNativeFbo( true )
 {
   mWidth = nativeImage.GetWidth();
   mHeight = nativeImage.GetHeight();
 }
 
 
-FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
-: Image(Dali::Image::Immediate, releasePolicy),
-  mNativeImage(&nativeImage),
-  mPixelFormat(nativeImage.GetPixelFormat())
-{
-  mWidth = nativeImage.GetWidth();
-  mHeight = nativeImage.GetHeight();
-}
-
-void FrameBufferImage::Connect()
+bool FrameBufferImage::IsNativeFbo() const
 {
-  ++mConnectionCount;
-
-  if (mConnectionCount == 1)
-  {
-    // ticket was thrown away when related actors went offstage
-    if (!mTicket)
-    {
-      ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
-      if (mNativeImage)
-      {
-        mTicket = resourceClient.AddFrameBufferImage(*mNativeImage);
-        mTicket->AddObserver(*this);
-      }
-      else
-      {
-        mTicket = resourceClient.AddFrameBufferImage(mWidth, mHeight, mPixelFormat);
-        mTicket->AddObserver(*this);
-      }
-    }
-  }
+  return mIsNativeFbo;
 }
 
-void FrameBufferImage::Disconnect()
+FrameBufferImage::~FrameBufferImage()
 {
-  if(!mTicket)
-  {
-    return;
-  }
-
-  DALI_ASSERT_DEBUG(mConnectionCount > 0);
-  --mConnectionCount;
-  if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused)
-  {
-    // release image memory when it's not visible anymore (decrease ref. count of texture)
-    mTicket->RemoveObserver(*this);
-    mTicket.Reset();
-  }
 }
 
 } // namespace Internal