From: David Steele Date: Fri, 10 Jul 2020 16:27:25 +0000 (+0100) Subject: Refactored NativeImageInterfaceExtension into NativeImageInterface X-Git-Tag: dali_1.9.23~14^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bdf9fe48e2f027e9555127a9cc5034e10c9371a;p=platform%2Fcore%2Fuifw%2Fdali-core.git Refactored NativeImageInterfaceExtension into NativeImageInterface Migrated the APIs from NativeImageInterfaceExtension into the base interface Changed APIs to remove references to GL. Added 2 new APIs used for Vulkan implementation for future use. Change-Id: I26a41d4494e74dc2410bf9260a134202f5cbefd0 Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-native-image.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-native-image.cpp index ee6c17a..5fdc5c3 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-native-image.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-native-image.cpp @@ -31,26 +31,10 @@ TestNativeImagePointer TestNativeImage::New(uint32_t width, uint32_t height) 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 diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-native-image.h b/automated-tests/src/dali/dali-test-suite-utils/test-native-image.h index 0c215b7..89d5095 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-native-image.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-native-image.h @@ -20,25 +20,12 @@ // INTERNAL INCLUDES #include -#include #include namespace Dali { class TestNativeImage; -class TestNativeImageNoExt; typedef IntrusivePtr TestNativeImagePointer; -typedef IntrusivePtr 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 { @@ -46,14 +33,21 @@ public: 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); @@ -65,38 +59,11 @@ public: 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 diff --git a/automated-tests/src/dali/utc-Dali-Texture.cpp b/automated-tests/src/dali/utc-Dali-Texture.cpp index 0222064..2d78bf0 100644 --- a/automated-tests/src/dali/utc-Dali-Texture.cpp +++ b/automated-tests/src/dali/utc-Dali-Texture.cpp @@ -59,7 +59,7 @@ int UtcDaliTextureNew03(void) 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 ); @@ -738,20 +738,74 @@ int UtcDaliTextureContextLoss(void) 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; +} diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index afe91fc..a78d58f 100644 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -76,7 +76,6 @@ SET( devel_api_core_events_header_files 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 ) diff --git a/dali/devel-api/images/native-image-interface-extension.h b/dali/devel-api/images/native-image-interface-extension.h deleted file mode 100644 index 2ca3d9a..0000000 --- a/dali/devel-api/images/native-image-interface-extension.h +++ /dev/null @@ -1,81 +0,0 @@ -#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 - -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 diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index 5151dc1..20eb465 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -21,7 +21,7 @@ #include //floor, log2 // INTERNAL INCLUDES -#include + namespace Dali { @@ -708,7 +708,7 @@ void Texture::Destroy( Context& context ) if( mNativeImage ) { - mNativeImage->GlExtensionDestroy(); + mNativeImage->DestroyResource(); } } } @@ -722,13 +722,9 @@ void Texture::Initialize(Context& context) { 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 ); @@ -744,7 +740,7 @@ void Texture::Initialize(Context& context) if( mNativeImage->TargetTexture() != 0u ) { context.DeleteTextures( 1, &mId ); - mNativeImage->GlExtensionDestroy(); + mNativeImage->DestroyResource(); mId = 0u; } } diff --git a/dali/public-api/images/native-image-interface.h b/dali/public-api/images/native-image-interface.h index ebffdff..606864d 100644 --- a/dali/public-api/images/native-image-interface.h +++ b/dali/public-api/images/native-image-interface.h @@ -1,8 +1,8 @@ -#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. @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -45,39 +46,39 @@ public: 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; @@ -105,6 +106,47 @@ public: 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 @@ -133,11 +175,11 @@ protected: * @brief Pointer to Dali::NativeImageInterface. * @SINCE_1_0.0 */ -typedef Dali::IntrusivePtr NativeImageInterfacePtr; +using NativeImageInterfacePtr = Dali::IntrusivePtr; /** * @} */ } // namespace Dali -#endif // DALI_INTEGRATION_NATIVE_IMAGE_INTERFACE_H +#endif // DALI_NATIVE_IMAGE_INTERFACE_H