Merged NativeFrameBufferTexture into FrameBufferTexture 84/48184/4
authorPaul Wisbey <p.wisbey@samsung.com>
Tue, 15 Sep 2015 17:46:18 +0000 (18:46 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Tue, 22 Sep 2015 09:38:39 +0000 (02:38 -0700)
Change-Id: I5b4b3a7b811bb56a8fb6ccee9ca54478a68f4eee

dali/internal/file.list
dali/internal/render/common/render-manager.cpp
dali/internal/render/gl-resources/frame-buffer-texture.cpp
dali/internal/render/gl-resources/frame-buffer-texture.h
dali/internal/render/gl-resources/native-frame-buffer-texture.cpp [deleted file]
dali/internal/render/gl-resources/native-frame-buffer-texture.h [deleted file]
dali/internal/render/gl-resources/texture-factory.cpp
dali/internal/render/gl-resources/texture.cpp

index 866696d..617e67d 100644 (file)
@@ -112,7 +112,6 @@ internal_src_files = \
   $(internal_src_dir)/render/gl-resources/frame-buffer-texture.cpp \
   $(internal_src_dir)/render/gl-resources/gl-call-debug.cpp \
   $(internal_src_dir)/render/gl-resources/gpu-buffer.cpp \
-  $(internal_src_dir)/render/gl-resources/native-frame-buffer-texture.cpp \
   $(internal_src_dir)/render/gl-resources/native-texture.cpp \
   $(internal_src_dir)/render/gl-resources/texture.cpp \
   $(internal_src_dir)/render/gl-resources/texture-factory.cpp \
index b1fafc0..caa49e5 100644 (file)
@@ -33,7 +33,6 @@
 #include <dali/internal/render/common/render-instruction.h>
 #include <dali/internal/render/gl-resources/context.h>
 #include <dali/internal/render/gl-resources/frame-buffer-texture.h>
-#include <dali/internal/render/gl-resources/native-frame-buffer-texture.h>
 #include <dali/internal/render/gl-resources/texture-cache.h>
 #include <dali/internal/render/renderers/scene-graph-renderer.h>
 #include <dali/internal/render/renderers/render-geometry.h>
index f0b2246..9d0259a 100644 (file)
@@ -19,6 +19,7 @@
 #include <dali/internal/render/gl-resources/frame-buffer-texture.h>
 
 // INTERNAL INCLUDES
+#include <dali/public-api/images/native-image-interface.h>
 #include <dali/internal/render/gl-resources/context.h>
 #include <dali/internal/render/gl-resources/texture-units.h>
 #include <dali/integration-api/debug.h>
@@ -31,13 +32,13 @@ namespace Internal
 
 FrameBufferTexture::FrameBufferTexture(unsigned int width, unsigned int height, Context& context)
 : Texture( context,
-           width, height,
            width, height ),
   mFrameBufferName(0),
   mRenderBufferName(0),
   mStencilBufferName(0),
   mPixelFormat(Pixel::RGBA8888),
-  mBufferFormat(RenderBuffer::COLOR)
+  mBufferFormat(RenderBuffer::COLOR),
+  mNativeImage(NULL)
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
 
@@ -45,13 +46,13 @@ FrameBufferTexture::FrameBufferTexture(unsigned int width, unsigned int height,
 
 FrameBufferTexture::FrameBufferTexture(unsigned int width, unsigned int height, Pixel::Format pixelFormat, Context& context)
 : Texture( context,
-           width, height,
            width, height ),
   mFrameBufferName(0),
   mRenderBufferName(0),
   mStencilBufferName(0),
   mPixelFormat( pixelFormat ),
-  mBufferFormat(RenderBuffer::COLOR)
+  mBufferFormat(RenderBuffer::COLOR),
+  mNativeImage(NULL)
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
 
@@ -59,17 +60,30 @@ FrameBufferTexture::FrameBufferTexture(unsigned int width, unsigned int height,
 
 FrameBufferTexture::FrameBufferTexture(unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat, Context& context)
 : Texture( context,
-           width, height,
            width, height ),
   mFrameBufferName(0),
   mRenderBufferName(0),
   mStencilBufferName(0),
   mPixelFormat( pixelFormat ),
-  mBufferFormat( bufferFormat )
+  mBufferFormat( bufferFormat ),
+  mNativeImage(NULL)
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
 }
 
+FrameBufferTexture::FrameBufferTexture( NativeImageInterfacePtr nativeImage, Context& context )
+: Texture( context,
+           nativeImage->GetWidth(), nativeImage->GetHeight() ),
+  mFrameBufferName(0),
+  mRenderBufferName(0),
+  mStencilBufferName(0),
+  mPixelFormat( Pixel::RGBA8888 ), // Not really used for nativeImage
+  mBufferFormat(RenderBuffer::COLOR_DEPTH),
+  mNativeImage( nativeImage )
+{
+  DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeFrameBufferTexture created 0x%x\n", &nativeImage );
+}
+
 FrameBufferTexture::~FrameBufferTexture()
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
@@ -79,11 +93,16 @@ FrameBufferTexture::~FrameBufferTexture()
 
 bool FrameBufferTexture::IsFullyOpaque() const
 {
-  return true;
+  return !HasAlphaChannel();
 }
 
 bool FrameBufferTexture::HasAlphaChannel() const
 {
+  if( mNativeImage )
+  {
+    return mNativeImage->RequiresBlending();
+  }
+
   return false;
 }
 
@@ -114,6 +133,13 @@ bool FrameBufferTexture::CreateGlTexture()
 {
   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
 
+  if( mNativeImage &&
+      !mNativeImage->GlExtensionCreate() )
+  {
+    DALI_LOG_ERROR( "Error creating native image!" );
+    return false;
+  }
+
   mContext.GenTextures(1, &mId);
   mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD );  // bind in unused unit so rebind works the first time
   mContext.Bind2dTexture(mId);
@@ -123,12 +149,20 @@ bool FrameBufferTexture::CreateGlTexture()
   mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-  // Assign memory for texture in GL memory space
-  GLenum pixelFormat = GL_RGBA;
-  GLenum pixelDataType = GL_UNSIGNED_BYTE;
-  Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
+  if( mNativeImage )
+  {
+    // platform specific implementation decides on what GL extension to use
+    mNativeImage->TargetTexture();
+  }
+  else
+  {
+    // Assign memory for texture in GL memory space
+    GLenum pixelFormat = GL_RGBA;
+    GLenum pixelDataType = GL_UNSIGNED_BYTE;
+    Integration::ConvertToGlFormat(mPixelFormat, pixelDataType, pixelFormat);
 
-  mContext.TexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, NULL);
+    mContext.TexImage2D(GL_TEXTURE_2D, 0, pixelFormat, mWidth, mHeight, 0, pixelFormat, pixelDataType, NULL);
+  }
 
   // generate frame and render buffer names
   mContext.GenFramebuffers(1, &mFrameBufferName);
@@ -212,6 +246,12 @@ void FrameBufferTexture::GlCleanup()
     mContext.DeleteRenderbuffers(1, &mStencilBufferName );
     mStencilBufferName = 0;
   }
+
+  if( mNativeImage )
+  {
+    mNativeImage->GlExtensionDestroy();
+    mNativeImage.Reset();
+  }
 }
 
 } //namespace Internal
index e3d8ec4..8f26bcf 100644 (file)
@@ -69,6 +69,13 @@ public:
   FrameBufferTexture(unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat, Context& context);
 
   /**
+   * Creates a new texture object
+   * @param[in] nativeImage The NativeImage
+   * @param     context The GL context
+   */
+  FrameBufferTexture( NativeImageInterfacePtr nativeImage, Context& context );
+
+  /**
    * Destructor.
    */
   virtual ~FrameBufferTexture();
@@ -100,6 +107,7 @@ protected:
   unsigned int mStencilBufferName;
   Pixel::Format mPixelFormat;
   RenderBuffer::Format mBufferFormat;
+  NativeImageInterfacePtr mNativeImage; ///< For native FBOs only
 
   /**
    * @copydoc Texture::CreateGlTexture
diff --git a/dali/internal/render/gl-resources/native-frame-buffer-texture.cpp b/dali/internal/render/gl-resources/native-frame-buffer-texture.cpp
deleted file mode 100644 (file)
index 7899963..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2014 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/render/gl-resources/native-frame-buffer-texture.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/gl-resources/texture-units.h>
-#include <dali/integration-api/debug.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-NativeFrameBufferTexture::NativeFrameBufferTexture( NativeImageInterfacePtr nativeImage, Context& context)
-  : FrameBufferTexture(nativeImage->GetWidth(),
-                       nativeImage->GetHeight(),
-                       context),
-    mNativeImage(nativeImage)
-{
-  DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeFrameBufferTexture created 0x%x\n", &nativeImage );
-}
-
-NativeFrameBufferTexture::~NativeFrameBufferTexture()
-{
-  DALI_LOG_INFO (Debug::Filter::gImage, Debug::General, "NativeFrameBufferTexture destroyed\n");
-  // GlCleanup() should already have been called by TextureCache ensuring the resource is destroyed
-  // on the render thread. (And avoiding a potentially problematic virtual call in the destructor)
-}
-
-bool NativeFrameBufferTexture::IsFullyOpaque() const
-{
-  return !HasAlphaChannel();
-}
-
-bool NativeFrameBufferTexture::HasAlphaChannel() const
-{
-  return mNativeImage->RequiresBlending();
-}
-
-bool NativeFrameBufferTexture::Init()
-{
-  DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-
-  bool status( true ); // assume success
-  if( mFrameBufferName == 0 )
-  {
-    status = CreateGlTexture();
-  }
-
-  return status;
-}
-
-bool NativeFrameBufferTexture::CreateGlTexture()
-{
-  DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
-
-  if( mNativeImage->GlExtensionCreate() )
-  {
-    mContext.GenTextures(1, &mId);
-    mContext.ActiveTexture( TEXTURE_UNIT_UPLOAD );  // bind in unused unit so rebind works the first time
-    mContext.Bind2dTexture(mId);
-
-    mContext.PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
-
-    mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    mContext.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
-    // platform specific implementation decides on what GL extension to use
-    mNativeImage->TargetTexture();
-
-    // generate frame and render buffer names
-    mContext.GenFramebuffers(1, &mFrameBufferName);
-    mContext.GenRenderbuffers(1, &mRenderBufferName);
-
-    // Bind render buffer and create 16 depth buffer
-    mContext.BindRenderbuffer(GL_RENDERBUFFER, mRenderBufferName);
-    mContext.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, mWidth, mHeight);
-  }
-  else
-  {
-    DALI_LOG_ERROR( "Error creating native image!" );
-  }
-
-  return mId != 0;
-}
-
-void NativeFrameBufferTexture::GlCleanup()
-{
-  Texture::GlCleanup();
-
-  if (mFrameBufferName != 0)
-  {
-    mContext.DeleteFramebuffers(1, &mFrameBufferName );
-    mFrameBufferName = 0;
-  }
-
-  if (mRenderBufferName != 0)
-  {
-    mContext.DeleteRenderbuffers(1, &mRenderBufferName );
-    mRenderBufferName = 0;
-  }
-
-  mNativeImage->GlExtensionDestroy();
-
-  mNativeImage.Reset();
-}
-
-} //namespace Internal
-
-} //namespace Dali
diff --git a/dali/internal/render/gl-resources/native-frame-buffer-texture.h b/dali/internal/render/gl-resources/native-frame-buffer-texture.h
deleted file mode 100644 (file)
index 0d7cee6..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-#ifndef __DALI_INTERNAL_FRAME_BUFFER_NATIVE_IMAGE_TEXTURE_H__
-#define __DALI_INTERNAL_FRAME_BUFFER_NATIVE_IMAGE_TEXTURE_H__
-
-/*
- * Copyright (c) 2014 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.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <string>
-
-// INTERNAL INCLUDES
-#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/render/gl-resources/frame-buffer-texture.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/integration-api/debug.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-/**
- * Frame Buffer Texture created from NativeImage.
- * Used as a frame buffer for RenderTask
- */
-class NativeFrameBufferTexture : public FrameBufferTexture
-{
-public:
-  /**
-   * Creates a new texture object
-   * @param[in] nativeImage The NativeImage
-   * @param     context The GL context
-   */
-  NativeFrameBufferTexture( NativeImageInterfacePtr nativeImage, Context& context);
-
-  /**
-   * Destructor.
-   */
-  virtual ~NativeFrameBufferTexture();
-
-  /**
-   * @copydoc Texture::IsFullyOpaque
-   */
-  virtual bool IsFullyOpaque() const;
-
-  /**
-   * @copydoc Texture::HasAlphaChannel
-   */
-  virtual bool HasAlphaChannel() const;
-
-  /**
-   * @copydoc Texture::Init
-   */
-  virtual bool Init();
-
-protected:
-  /**
-   * @copydoc Texture::CreateGlTexture
-   */
-  virtual bool CreateGlTexture();
-
-  /**
-   * @copydoc Texture::GlCleanup
-   */
-  virtual void GlCleanup();
-
-private:
-  NativeImageInterfacePtr mNativeImage; ///< reference to NativeImage the Texture was created from
-
-}; // class NativeFrameBufferTexture
-
-}  //namespace Internal
-
-} //namespace Dali
-
-#endif // header
-
index 7f1da8a..08fe136 100644 (file)
@@ -24,7 +24,6 @@
 #include <dali/internal/render/gl-resources/compressed-bitmap-texture.h>
 #include <dali/internal/render/gl-resources/native-texture.h>
 #include <dali/internal/render/gl-resources/frame-buffer-texture.h>
-#include <dali/internal/render/gl-resources/native-frame-buffer-texture.h>
 
 
 namespace Dali
@@ -107,7 +106,7 @@ Internal::Texture* NewFrameBufferTexture( unsigned int width,
 Internal::Texture* NewFrameBufferTexture( NativeImageInterfacePtr nativeImage,
                                           Context& context )
 {
-  NativeFrameBufferTexture* texture = new NativeFrameBufferTexture(nativeImage, context);
+  FrameBufferTexture* texture = new FrameBufferTexture(nativeImage, context);
   if (!texture->Init())
   {
     delete texture;
index 687cbf4..22ce859 100644 (file)
@@ -100,6 +100,19 @@ Texture::Texture(Context&      context,
 {
 }
 
+Texture::Texture(Context&      context,
+                 unsigned int  width,
+                 unsigned int  height)
+: mContext(context),
+  mId(0),
+  mSamplerBitfield( 0 ),
+  mWidth(width),
+  mHeight(height),
+  mImageWidth(width),
+  mImageHeight(height)
+{
+}
+
 Texture::~Texture()
 {
   // GlCleanup() should already have been called by TextureCache ensuring the resource is destroyed