TestNativeImage::TestNativeImage(uint32_t width, uint32_t height)
: mWidth(width), mHeight(height), mExtensionCreateCalls(0), mExtensionDestroyCalls(0), mTargetTextureCalls(0),createResult(true)
{
- mExtension = new TestNativeImageExtension();
}
TestNativeImage::~TestNativeImage()
{
}
-
-TestNativeImageNoExtPointer TestNativeImageNoExt::New(uint32_t width, uint32_t height)
-{
- return new TestNativeImageNoExt(width, height);
-}
-
-TestNativeImageNoExt::TestNativeImageNoExt(uint32_t width, uint32_t height)
-: mWidth(width), mHeight(height), mExtensionCreateCalls(0), mExtensionDestroyCalls(0), mTargetTextureCalls(0),createResult(true)
-{
-}
-
-TestNativeImageNoExt::~TestNativeImageNoExt()
-{
-}
-
} // namespace dali
// INTERNAL INCLUDES
#include <dali/public-api/images/native-image-interface.h>
-#include <dali/devel-api/images/native-image-interface-extension.h>
#include <dali/integration-api/gl-defines.h>
namespace Dali
{
class TestNativeImage;
-class TestNativeImageNoExt;
typedef IntrusivePtr<TestNativeImage> TestNativeImagePointer;
-typedef IntrusivePtr<TestNativeImageNoExt> TestNativeImageNoExtPointer;
-
-class DALI_CORE_API TestNativeImageExtension: public Dali::NativeImageInterface::Extension
-{
-public:
- inline const char* GetCustomFragmentPreFix(){return "#extension GL_OES_EGL_image_external:require\n";}
- inline const char* GetCustomSamplerTypename(){return "samplerExternalOES";}
-
- inline int32_t GetEglImageTextureTarget(){return GL_TEXTURE_EXTERNAL_OES;}
-
-};
class DALI_CORE_API TestNativeImage : public Dali::NativeImageInterface
{
static TestNativeImagePointer New(uint32_t width, uint32_t height);
inline void SetGlExtensionCreateResult(bool result){ createResult = result;}
- inline virtual bool GlExtensionCreate() { ++mExtensionCreateCalls; return createResult;};
- inline virtual void GlExtensionDestroy() { ++mExtensionDestroyCalls; };
- inline virtual GLenum TargetTexture() { ++mTargetTextureCalls; return 0;};
+ inline virtual bool CreateResource() { ++mExtensionCreateCalls; return createResult;};
+ inline virtual void DestroyResource() { ++mExtensionDestroyCalls; };
+ inline virtual GLenum TargetTexture() { ++mTargetTextureCalls; return mTargetTextureError;};
inline virtual void PrepareTexture() {};
inline virtual uint32_t GetWidth() const {return mWidth;};
inline virtual uint32_t GetHeight() const {return mHeight;};
inline virtual bool RequiresBlending() const {return true;};
- inline virtual Dali::NativeImageInterface::Extension* GetExtension() {return mExtension;}
+ inline virtual int GetTextureTarget() const {return GL_TEXTURE_EXTERNAL_OES;};
+ inline virtual const char* GetCustomFragmentPrefix() const {return "#extension GL_OES_EGL_image_external:require\n";};
+ inline const char* GetCustomSamplerTypename() const override { return "samplerExternalOES"; };
+
+ inline Any GetNativeImageHandle() const override { return nullptr; };
+ inline bool SourceChanged() const override { return false; };
+
+ inline virtual Dali::NativeImageInterface::Extension* GetExtension() {return nullptr;}
private:
TestNativeImage(uint32_t width, uint32_t height);
int32_t mExtensionCreateCalls;
int32_t mExtensionDestroyCalls;
int32_t mTargetTextureCalls;
-
+ uint32_t mTargetTextureError=0u;
bool createResult;
- TestNativeImageExtension* mExtension;
};
-class DALI_CORE_API TestNativeImageNoExt : public Dali::NativeImageInterface
-{
-public:
- static TestNativeImageNoExtPointer New(uint32_t width, uint32_t height);
-
- inline void SetGlExtensionCreateResult(bool result){ createResult = result;}
- inline virtual bool GlExtensionCreate() { ++mExtensionCreateCalls; return createResult;};
- inline virtual void GlExtensionDestroy() { ++mExtensionDestroyCalls; };
- inline virtual GLenum TargetTexture() { ++mTargetTextureCalls; return 1;};
- inline virtual void PrepareTexture() {};
- inline virtual uint32_t GetWidth() const {return mWidth;};
- inline virtual uint32_t GetHeight() const {return mHeight;};
- inline virtual bool RequiresBlending() const {return true;};
-
-private:
- TestNativeImageNoExt(uint32_t width, uint32_t height);
- virtual ~TestNativeImageNoExt();
-
- uint32_t mWidth;
- uint32_t mHeight;
-public:
- int32_t mExtensionCreateCalls;
- int32_t mExtensionDestroyCalls;
- int32_t mTargetTextureCalls;
- bool createResult;
-};
} // Dali
TestApplication application;
// Create a native image source.
- TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::New( 64u, 64u );
+ TestNativeImagePointer testNativeImage = TestNativeImage::New( 64u, 64u );
// Create a texture from the native image source.
Texture nativeTexture = Texture::New( *testNativeImage );
END_TEST;
}
-int UtcDaliNativeImageTexture(void)
+int UtcDaliNativeImageTexture01(void)
{
TestApplication application;
- tet_infoline( "UtcDaliNativeImageTexture" );
+ tet_infoline( "UtcDaliNativeImageTexture01" );
TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
- Texture texture = Texture::New( *(imageInterface.Get()) );
- DALI_TEST_CHECK( texture );
+ {
+ Texture texture = Texture::New( *(imageInterface.Get()) );
+ Actor actor = CreateRenderableActor(texture, "", "");
+ application.GetScene().Add(actor);
+
+ DALI_TEST_CHECK( texture );
+
+ application.SendNotification();
+ application.Render(16);
+
+ DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16,16,0)), TEST_LOCATION);
+ UnparentAndReset(actor);
+
+ application.SendNotification();
+ application.Render(16);
+ }
application.SendNotification();
application.Render(16);
- DALI_TEST_CHECK( texture );
+ DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION );
END_TEST;
}
+
+int UtcDaliNativeImageTexture02(void)
+{
+ TestApplication application;
+ tet_infoline( "UtcDaliNativeImageTexture02 - test error on TargetTexture" );
+
+ TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
+ imageInterface->mTargetTextureError = 1u;
+ {
+ Texture texture = Texture::New( *(imageInterface.Get()) );
+ Actor actor = CreateRenderableActor(texture, "", "");
+ application.GetScene().Add(actor);
+
+ DALI_TEST_CHECK( texture );
+
+ application.SendNotification();
+ application.Render(16);
+
+ // Expect 2 attempts to create the texture - once when adding the texture
+ // to the scene-graph, and again since that failed, during the Bind.
+ DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
+
+ UnparentAndReset(actor);
+
+ application.SendNotification();
+ application.Render(16);
+ }
+ application.SendNotification();
+ application.Render(16);
+
+ // Expect that there are no further calls to create/destroy resource
+ DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
+
+ END_TEST;
+}
SET( devel_api_core_images_header_files
${devel_api_src_dir}/images/distance-field.h
- ${devel_api_src_dir}/images/native-image-interface-extension.h
${devel_api_src_dir}/images/pixel-data-devel.h
)
+++ /dev/null
-#ifndef DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_EXTENSION_H
-#define DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_EXTENSION_H
-
-/*
- * Copyright (c) 2019 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.
- *
- */
-
-#include <dali/public-api/images/native-image-interface.h>
-
-namespace Dali
-{
-
-/**
- * @brief Extension abstract interface to provide platform-specific support for handling image data.
- *
- */
-class NativeImageInterface::Extension
-{
-public:
-
- class Extension2; ///< Forward declare future extension interface
-
- /**
- * @brief Get custom fragment prefix for rendering native image.
- *
- * @return Custom fragment prefix code as string.
- */
- virtual const char* GetCustomFragmentPreFix() = 0;
-
- /**
- * @brief Get custom sampler type name for rendering native image.
- *
- * @return Custom sampler type name.
- */
- virtual const char* GetCustomSamplerTypename() = 0;
-
- /**
- * @brief Get texture target for binding native image as texture.
- *
- * @return Texture target.
- */
- virtual int GetEglImageTextureTarget() = 0;
-
- /**
- * @brief Retrieve the extension for the interface.
- *
- * @return Extension2 pointer if available, NULL otherwise
- */
- virtual Extension2* GetExtension2()
- {
- return NULL;
- }
-
-protected:
-
- /**
- * @brief Destructor.
- *
- */
- virtual ~Extension()
- {
- }
-
-};
-
-} // namespace Dali
-
-#endif // DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_EXTENSION_H
#include <math.h> //floor, log2
// INTERNAL INCLUDES
-#include <dali/devel-api/images/native-image-interface-extension.h>
+
namespace Dali
{
if( mNativeImage )
{
- mNativeImage->GlExtensionDestroy();
+ mNativeImage->DestroyResource();
}
}
}
{
if( mNativeImage )
{
- if( mNativeImage->GlExtensionCreate() )
+ if( mNativeImage->CreateResource() )
{
- NativeImageInterface::Extension* extension = mNativeImage->GetExtension();
- if( extension )
- {
- mTarget = extension->GetEglImageTextureTarget();
- }
+ mTarget = mNativeImage->GetTextureTarget();
context.GenTextures( 1, &mId );
context.BindTexture( mTarget, mId );
if( mNativeImage->TargetTexture() != 0u )
{
context.DeleteTextures( 1, &mId );
- mNativeImage->GlExtensionDestroy();
+ mNativeImage->DestroyResource();
mId = 0u;
}
}
-#ifndef DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_H
-#define DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_H
+#ifndef DALI_NATIVE_IMAGE_INTERFACE_H
+#define DALI_NATIVE_IMAGE_INTERFACE_H
/*
- * Copyright (c) 2019 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.
// INTERNAL INCLUDES
#include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/object/any.h>
namespace Dali
{
class Extension; ///< Forward declare future extension interface
/**
- * @brief Creates the GL resource for the NativeImage.
+ * @brief Creates the resource for the NativeImage.
*
* e.g. For the EglImageKHR extension, this corresponds to calling eglCreateImageKHR().
- * @SINCE_1_0.0
+ * @SINCE_1_9.23
* @return false If the initialization fails
- * @pre There is a GL context for the current thread.
+ * @pre The graphics subsystem has been initialized
*/
- virtual bool GlExtensionCreate() = 0;
+ virtual bool CreateResource() = 0;
/**
- * @brief Destroys the GL resource for the NativeImage.
+ * @brief Destroys the resource for the NativeImage.
*
* e.g. For the EglImageKHR extension, this corresponds to calling eglDestroyImageKHR().
- * @SINCE_1_0.0
- * @pre There is a GL context for the current thread.
+ * @SINCE_1_9.23
+ * @pre The graphics subsystem has been initialized
*/
- virtual void GlExtensionDestroy() = 0;
+ virtual void DestroyResource() = 0;
/**
* @brief Uses the NativeImage as a texture for rendering.
*
* @SINCE_1_0.0
- * @return A GL error code
- * @pre There is a GL context for the current thread.
+ * @return An error code from the graphics subsystem.
+ * @pre The graphics subsystem has been initialized
*/
virtual uint32_t TargetTexture() = 0;
/**
- * @brief Called internally for each Bind call for this texture to allow implementation specific operations.
+ * @brief Called internally when the texture is bound in the GPU
*
* The correct texture sampler has already been bound before the function gets called.
* @SINCE_1_0.0
- * @pre glAbstraction is being used by context in current thread
+ * @pre The graphics subsystem has been initialized
*/
virtual void PrepareTexture() = 0;
virtual bool RequiresBlending() const = 0;
/**
+ * @brief Get the texture target for binding native image as texture.
+ *
+ * @SINCE_1_9.23
+ * @return Texture target.
+ */
+ virtual int GetTextureTarget() const = 0;
+
+ /**
+ * @brief Get custom fragment prefix for rendering native image.
+ *
+ * @SINCE_1_9.23
+ * @return Custom fragment prefix code as string.
+ */
+ virtual const char* GetCustomFragmentPrefix() const = 0;
+
+ /**
+ * @brief Get custom sampler type name for rendering native image.
+ *
+ * @SINCE_1_9.23
+ * @return Custom sampler type name.
+ */
+ virtual const char* GetCustomSamplerTypename() const = 0;
+
+ /**
+ * @brief Retrieves the internal native image.
+ *
+ * @SINCE_1_9.23
+ * @return Any object containing the internal native image source
+ */
+ virtual Any GetNativeImageHandle() const = 0;
+
+ /**
+ * @brief Determine if the source for the native image has changed characteristics.
+ *
+ * @SINCE_1_9.23
+ * @return true if the source data has modified any characteristics of the
+ * native image, for example if the size of the buffer has changed.
+ */
+ virtual bool SourceChanged() const = 0;
+
+ /**
* @brief Retrieves the extension for the interface.
*
* @SINCE_1_0.0
* @brief Pointer to Dali::NativeImageInterface.
* @SINCE_1_0.0
*/
-typedef Dali::IntrusivePtr<NativeImageInterface> NativeImageInterfacePtr;
+using NativeImageInterfacePtr = Dali::IntrusivePtr<NativeImageInterface>;
/**
* @}
*/
} // namespace Dali
-#endif // DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_H
+#endif // DALI_NATIVE_IMAGE_INTERFACE_H