From: Heeyong Song Date: Fri, 7 Sep 2018 05:37:56 +0000 (+0900) Subject: [4.0] Support tbm_surface_queue X-Git-Tag: accepted/tizen/4.0/unified/20190104.230754~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ceb694afcf1f235ffd740f5e72d30a89a849410a;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git [4.0] Support tbm_surface_queue Change-Id: I7e689dff135d6fcb4bb5b44cf3c99fc8fb4414cd --- diff --git a/adaptors/common/native-image-source-factory.h b/adaptors/common/native-image-source-factory.h new file mode 100644 index 0000000..5e0a420 --- /dev/null +++ b/adaptors/common/native-image-source-factory.h @@ -0,0 +1,59 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_H + +/* + * Copyright (c) 2018 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 + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ + +class NativeImageSource; +class NativeImageSourceQueue; + +class NativeImageSourceFactory +{ +public: + + NativeImageSourceFactory() = default; + virtual ~NativeImageSourceFactory() = default; + + virtual std::unique_ptr< NativeImageSource > CreateNativeImageSource( unsigned int width, unsigned int height, + Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) = 0; + + virtual std::unique_ptr< NativeImageSourceQueue > CreateNativeImageSourceQueue( unsigned int width, unsigned int height, + Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) = 0; + +}; + +extern std::unique_ptr< NativeImageSourceFactory > GetNativeImageSourceFactory(); + +} // Adaptor +} // Internal +} // Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_H diff --git a/adaptors/common/native-image-source-impl.h b/adaptors/common/native-image-source-impl.h new file mode 100755 index 0000000..5175e2d --- /dev/null +++ b/adaptors/common/native-image-source-impl.h @@ -0,0 +1,130 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H + +/* + * Copyright (c) 2018 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +/** + * Dali internal NativeImageSource. + */ +class NativeImageSource +{ +public: + + /** + * Create a new NativeImageSource internally. + * Depending on hardware the width and height may have to be a power of two. + * @param[in] width The width of the image. + * @param[in] height The height of the image. + * @param[in] depth color depth of the image. + * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty + * @return A smart-pointer to a newly allocated image. + */ + static NativeImageSource* New(unsigned int width, + unsigned int height, + Dali::NativeImageSource::ColorDepth depth, + Any nativeImageSource); + /** + * @copydoc Dali::NativeImageSource::GetNativeImageSource() + */ + virtual Any GetNativeImageSource() const = 0; + + /** + * @copydoc Dali::NativeImageSource::GetPixels() + */ + virtual bool GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const = 0; + + /** + * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& ) + */ + virtual bool EncodeToFile(const std::string& filename) const = 0; + + /** + * @copydoc Dali::NativeImageSource::SetSource( Any source ) + */ + virtual void SetSource( Any source ) = 0; + + /** + * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth ) + */ + virtual bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) = 0; + + /** + * destructor + */ + virtual ~NativeImageSource() = default; + + /** + * @copydoc Dali::NativeImageSource::GlExtensionCreate() + */ + virtual bool GlExtensionCreate() = 0; + + /** + * @copydoc Dali::NativeImageSource::GlExtensionDestroy() + */ + virtual void GlExtensionDestroy() = 0; + + /** + * @copydoc Dali::NativeImageSource::TargetTexture() + */ + virtual unsigned int TargetTexture() = 0; + + /** + * @copydoc Dali::NativeImageSource::PrepareTexture() + */ + virtual void PrepareTexture() = 0; + + /** + * @copydoc Dali::NativeImageSource::GetWidth() + */ + virtual unsigned int GetWidth() const = 0; + + /** + * @copydoc Dali::NativeImageSource::GetHeight() + */ + virtual unsigned int GetHeight() const = 0; + + /** + * @copydoc Dali::NativeImageSource::RequiresBlending() + */ + virtual bool RequiresBlending() const = 0; + + /** + * @copydoc Dali::NativeImageInterface::GetExtension() + */ + virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H diff --git a/adaptors/common/native-image-source-queue-impl.h b/adaptors/common/native-image-source-queue-impl.h new file mode 100755 index 0000000..c726d45 --- /dev/null +++ b/adaptors/common/native-image-source-queue-impl.h @@ -0,0 +1,107 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_H + +/* + * Copyright (c) 2018 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +/** + * Dali internal NativeImageSourceQueue. + */ +class NativeImageSourceQueue +{ +public: + + /** + * @copydoc Dali::NativeImageSourceQueue::New() + */ + static NativeImageSourceQueue* New( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ); + + /** + * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue() + */ + virtual Any GetNativeImageSourceQueue() const = 0; + + /** + * @copydoc Dali::NativeImageSourceQueue::SetSource( Any source ) + */ + virtual void SetSource( Any source ) = 0; + + /** + * destructor + */ + virtual ~NativeImageSourceQueue() = default; + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionCreate() + */ + virtual bool GlExtensionCreate() = 0; + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionDestroy() + */ + virtual void GlExtensionDestroy() = 0; + + /** + * @copydoc Dali::NativeImageInterface::TargetTexture() + */ + virtual unsigned int TargetTexture() = 0; + + /** + * @copydoc Dali::NativeImageInterface::PrepareTexture() + */ + virtual void PrepareTexture() = 0; + + /** + * @copydoc Dali::NativeImageInterface::GetWidth() + */ + virtual unsigned int GetWidth() const = 0; + + /** + * @copydoc Dali::NativeImageInterface::GetHeight() + */ + virtual unsigned int GetHeight() const = 0; + + /** + * @copydoc Dali::NativeImageInterface::RequiresBlending() + */ + virtual bool RequiresBlending() const = 0; + + /** + * @copydoc Dali::NativeImageInterface::GetExtension() + */ + virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0; +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_H diff --git a/adaptors/devel-api/adaptor-framework/native-image-source-queue.cpp b/adaptors/devel-api/adaptor-framework/native-image-source-queue.cpp new file mode 100755 index 0000000..960b3e4 --- /dev/null +++ b/adaptors/devel-api/adaptor-framework/native-image-source-queue.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018 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 + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +NativeImageSourceQueuePtr NativeImageSourceQueue::New( unsigned int width, unsigned int height, ColorDepth depth ) +{ + Any empty; + NativeImageSourceQueuePtr image = new NativeImageSourceQueue( width, height, depth, empty ); + return image; +} + +NativeImageSourceQueuePtr NativeImageSourceQueue::New( Any nativeImageSourceQueue ) +{ + NativeImageSourceQueuePtr image = new NativeImageSourceQueue( 0, 0, COLOR_DEPTH_DEFAULT, nativeImageSourceQueue ); + return image; +} + +Any NativeImageSourceQueue::GetNativeImageSourceQueue() +{ + return mImpl->GetNativeImageSourceQueue(); +} + +void NativeImageSourceQueue::SetSource( Any source ) +{ + mImpl->SetSource( source ); +} + +bool NativeImageSourceQueue::GlExtensionCreate() +{ + return mImpl->GlExtensionCreate(); +} + +void NativeImageSourceQueue::GlExtensionDestroy() +{ + mImpl->GlExtensionDestroy(); +} + +unsigned int NativeImageSourceQueue::TargetTexture() +{ + return mImpl->TargetTexture(); +} + +void NativeImageSourceQueue::PrepareTexture() +{ + mImpl->PrepareTexture(); +} + +unsigned int NativeImageSourceQueue::GetWidth() const +{ + return mImpl->GetWidth(); +} + +unsigned int NativeImageSourceQueue::GetHeight() const +{ + return mImpl->GetHeight(); +} + +bool NativeImageSourceQueue::RequiresBlending() const +{ + return mImpl->RequiresBlending(); +} + +NativeImageInterface::Extension* NativeImageSourceQueue::GetExtension() +{ + return mImpl->GetNativeImageInterfaceExtension(); +} + +NativeImageSourceQueue::NativeImageSourceQueue( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSourceQueue ) +{ + auto factory = Dali::Internal::Adaptor::GetNativeImageSourceFactory(); + mImpl = factory->CreateNativeImageSourceQueue( width, height, depth, nativeImageSourceQueue ); +} + +NativeImageSourceQueue::~NativeImageSourceQueue() +{ +} + +} // namespace Dali diff --git a/adaptors/devel-api/adaptor-framework/native-image-source-queue.h b/adaptors/devel-api/adaptor-framework/native-image-source-queue.h new file mode 100755 index 0000000..7e55b9b --- /dev/null +++ b/adaptors/devel-api/adaptor-framework/native-image-source-queue.h @@ -0,0 +1,191 @@ +#ifndef DALI_NATIVE_IMAGE_SOURCE_QUEUE_H +#define DALI_NATIVE_IMAGE_SOURCE_QUEUE_H + +/* + * Copyright (c) 2018 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 +#include +#include + +namespace Dali +{ +/** + * @addtogroup dali_adaptor_framework + * @{ + */ + +namespace Internal DALI_INTERNAL +{ +namespace Adaptor +{ +class NativeImageSourceQueue; +} +} + +class NativeImageSourceQueue; + +/** + * @brief Pointer to Dali::NativeImageSourceQueue. + */ +typedef Dali::IntrusivePtr< Dali::NativeImageSourceQueue > NativeImageSourceQueuePtr; + +/** + * @brief Used for displaying native images. + * + * NativeImageSource can be created internally or externally by native image source. + * NativeImage is a platform specific way of providing pixel data to the GPU for rendering,for example via an EGL image. + */ +class DALI_IMPORT_API NativeImageSourceQueue : public NativeImageInterface +{ +public: + + /** + * @brief Enumeration for the instance when creating a native image, the color depth has to be specified. + */ + enum ColorDepth + { + COLOR_DEPTH_DEFAULT, ///< Uses the current screen default depth (recommended) + COLOR_DEPTH_24, ///< 24 bits per pixel + COLOR_DEPTH_32 ///< 32 bits per pixel + }; + + /** + * @brief Creates a new NativeImageSourceQueue. + * Depending on hardware, the width and height may have to be a power of two. + * @param[in] width The width of the image + * @param[in] height The height of the image + * @param[in] depth color depth of the image + * @return A smart-pointer to a newly allocated image + */ + static NativeImageSourceQueuePtr New( unsigned int width, unsigned int height, ColorDepth depth ); + + /** + * @brief Creates a new NativeImageSourceQueue from an existing native image source. + * + * @param[in] nativeImageSourceQueue NativeImageSourceQueue must be a any handle with native image source + * @return A smart-pointer to a newly allocated image + * @see NativeImageInterface + */ + static NativeImageSourceQueuePtr New( Any nativeImageSourceQueue ); + + /** + * @brief Retrieves the internal native image. + * + * @return Any object containing the internal native image source queue + */ + Any GetNativeImageSourceQueue(); + + /** + * @brief Sets an existing source. + * + * @param[in] source Any handle with the source + */ + void SetSource( Any source ); + +private: // native image + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionCreate() + */ + virtual bool GlExtensionCreate(); + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionDestroy() + */ + virtual void GlExtensionDestroy(); + + /** + * @copydoc Dali::NativeImageInterface::TargetTexture() + */ + virtual unsigned int TargetTexture(); + + /** + * @copydoc Dali::NativeImageInterface::PrepareTexture() + */ + virtual void PrepareTexture(); + + /** + * @copydoc Dali::NativeImageInterface::GetWidth() + */ + virtual unsigned int GetWidth() const; + + /** + * @copydoc Dali::NativeImageInterface::GetHeight() + */ + virtual unsigned int GetHeight() const; + + /** + * @copydoc Dali::NativeImageInterface::RequiresBlending() + */ + virtual bool RequiresBlending() const; + + /** + * @copydoc Dali::NativeImageInterface::GetExtension() + */ + NativeImageInterface::Extension* GetExtension(); + +private: + + /// @cond internal + /** + * @brief Private constructor. + * @param[in] width The width of the image + * @param[in] height The height of the image + * @param[in] depth color depth of the image + * @param[in] nativeImageSourceQueue contains either: native image source or is empty + */ + DALI_INTERNAL NativeImageSourceQueue( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSourceQueue ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + * + * The implementation should destroy the NativeImage resources. + */ + DALI_INTERNAL virtual ~NativeImageSourceQueue(); + + /** + * @brief Undefined copy constructor. + * + * This avoids accidental calls to a default copy constructor. + * @param[in] nativeImageSourceQueue A reference to the object to copy + */ + DALI_INTERNAL NativeImageSourceQueue( const NativeImageSourceQueue& nativeImageSourceQueue ); + + /** + * @brief Undefined assignment operator. + * + * This avoids accidental calls to a default assignment operator. + * @param[in] rhs A reference to the object to copy + */ + DALI_INTERNAL NativeImageSourceQueue& operator=(const NativeImageSourceQueue& rhs); + /// @endcond + +private: + + /// @cond internal + std::unique_ptr< Internal::Adaptor::NativeImageSourceQueue > mImpl; ///< Implementation pointer + /// @endcond +}; + +/** + * @} + */ +} // namespace Dali + +#endif // DALI_NATIVE_IMAGE_SOURCE_QUEUE_H diff --git a/adaptors/devel-api/file.list b/adaptors/devel-api/file.list index bff0658..be07de7 100644 --- a/adaptors/devel-api/file.list +++ b/adaptors/devel-api/file.list @@ -16,6 +16,7 @@ devel_api_src_files = \ $(adaptor_devel_api_dir)/adaptor-framework/gif-loading.cpp \ $(adaptor_devel_api_dir)/adaptor-framework/imf-manager.cpp \ $(adaptor_devel_api_dir)/adaptor-framework/input-method-options.cpp \ + $(adaptor_devel_api_dir)/adaptor-framework/native-image-source-queue.cpp \ $(adaptor_devel_api_dir)/adaptor-framework/orientation.cpp \ $(adaptor_devel_api_dir)/adaptor-framework/performance-logger.cpp \ $(adaptor_devel_api_dir)/adaptor-framework/physical-keyboard.cpp \ @@ -52,6 +53,7 @@ devel_api_adaptor_framework_header_files = \ $(adaptor_devel_api_dir)/adaptor-framework/input-method-devel.h \ $(adaptor_devel_api_dir)/adaptor-framework/input-method-options.h \ $(adaptor_devel_api_dir)/adaptor-framework/lifecycle-controller.h \ + $(adaptor_devel_api_dir)/adaptor-framework/native-image-source-queue.h \ $(adaptor_devel_api_dir)/adaptor-framework/orientation.h \ $(adaptor_devel_api_dir)/adaptor-framework/performance-logger.h \ $(adaptor_devel_api_dir)/adaptor-framework/pixel-buffer.h \ diff --git a/adaptors/public-api/adaptor-framework/native-image-source.cpp b/adaptors/public-api/adaptor-framework/native-image-source.cpp index 7897195..709f819 100644 --- a/adaptors/public-api/adaptor-framework/native-image-source.cpp +++ b/adaptors/public-api/adaptor-framework/native-image-source.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -107,7 +108,8 @@ NativeImageInterface::Extension* NativeImageSource::GetExtension() NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource ) { - mImpl = Internal::Adaptor::NativeImageSource::New( width, height, depth, nativeImageSource ); + auto factory = Dali::Internal::Adaptor::GetNativeImageSourceFactory(); + mImpl = factory->CreateNativeImageSource( width, height, depth, nativeImageSource ).release(); } NativeImageSource::~NativeImageSource() diff --git a/adaptors/tizen/file-3.list b/adaptors/tizen/file-3.list index fa8e657..35192fc 100644 --- a/adaptors/tizen/file-3.list +++ b/adaptors/tizen/file-3.list @@ -20,6 +20,7 @@ adaptor_tizen_internal_egl_extension_src_files = \ adaptor_tizen_internal_native_image_src_files = \ $(adaptor_tizen_dir)/display-connection-impl-tizen.cpp \ $(adaptor_tizen_dir)/native-render-surface-tizen.cpp \ + $(adaptor_tizen_dir)/native-image-source-factory-tizen.cpp \ $(adaptor_tizen_dir)/native-image-source-impl-tizen.cpp public_api_adaptor_tizen_header_files = \ diff --git a/adaptors/tizen/file.list b/adaptors/tizen/file.list index 53944f7..d61d13e 100644 --- a/adaptors/tizen/file.list +++ b/adaptors/tizen/file.list @@ -21,7 +21,9 @@ adaptor_tizen_internal_native_image_src_files = \ $(adaptor_tizen_dir)/display-connection-impl-tizen.cpp \ $(adaptor_tizen_dir)/native-render-surface-tizen.cpp \ $(adaptor_tizen_dir)/native-render-surface-factory-tizen.cpp \ - $(adaptor_tizen_dir)/native-image-source-impl-tizen.cpp + $(adaptor_tizen_dir)/native-image-source-factory-tizen.cpp \ + $(adaptor_tizen_dir)/native-image-source-impl-tizen.cpp \ + $(adaptor_tizen_dir)/native-image-source-queue-impl-tizen.cpp public_api_adaptor_tizen_header_files = \ $(adaptor_tizen_dir)/key-grab.h diff --git a/adaptors/tizen/gl/egl-image-extensions-tizen.cpp b/adaptors/tizen/gl/egl-image-extensions-tizen.cpp index 57d0c08..ab16aca 100644 --- a/adaptors/tizen/gl/egl-image-extensions-tizen.cpp +++ b/adaptors/tizen/gl/egl-image-extensions-tizen.cpp @@ -97,7 +97,6 @@ void* EglImageExtensions::CreateImageKHR(EGLClientBuffer clientBuffer) clientBuffer, attribs ); - DALI_ASSERT_DEBUG( EGL_NO_IMAGE_KHR != eglImage && "X11Image::GlExtensionCreate eglCreateImageKHR failed!\n"); if( EGL_NO_IMAGE_KHR == eglImage ) { switch( eglGetError() ) @@ -142,6 +141,7 @@ void* EglImageExtensions::CreateImageKHR(EGLClientBuffer clientBuffer) } } } + DALI_ASSERT_DEBUG( EGL_NO_IMAGE_KHR != eglImage && "EglImageExtensions::CreateImageKHR: eglCreateImageKHR failed!\n"); return eglImage; } diff --git a/adaptors/tizen/native-image-source-factory-tizen.cpp b/adaptors/tizen/native-image-source-factory-tizen.cpp new file mode 100644 index 0000000..5fcccca --- /dev/null +++ b/adaptors/tizen/native-image-source-factory-tizen.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018 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 + +// INTERNAL HEADERS +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ + +std::unique_ptr< NativeImageSource > NativeImageSourceFactoryTizen::CreateNativeImageSource( unsigned int width, unsigned int height, + Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +{ + return std::unique_ptr< NativeImageSource >( NativeImageSourceTizen::New( width, height, depth, nativeImageSource ) ); +} + +std::unique_ptr< NativeImageSourceQueue > NativeImageSourceFactoryTizen::CreateNativeImageSourceQueue( unsigned int width, unsigned int height, + Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) +{ + return std::unique_ptr< NativeImageSourceQueue >( NativeImageSourceQueueTizen::New( width, height, depth, nativeImageSourceQueue ) ); +} + +// this should be created from somewhere +std::unique_ptr< NativeImageSourceFactory > GetNativeImageSourceFactory() +{ + // returns native image source factory + return std::unique_ptr< NativeImageSourceFactoryTizen >( new NativeImageSourceFactoryTizen() ); +} + +} // Adaptor +} // Internal +} // Dali diff --git a/adaptors/tizen/native-image-source-factory-tizen.h b/adaptors/tizen/native-image-source-factory-tizen.h new file mode 100644 index 0000000..1913c08 --- /dev/null +++ b/adaptors/tizen/native-image-source-factory-tizen.h @@ -0,0 +1,47 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_TIZEN_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_TIZEN_H + +/* + * Copyright (c) 2018 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ + +class NativeImageSourceFactoryTizen : public NativeImageSourceFactory +{ +public: + + std::unique_ptr< NativeImageSource > CreateNativeImageSource( unsigned int width, unsigned int height, + Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) override; + + std::unique_ptr< NativeImageSourceQueue > CreateNativeImageSourceQueue( unsigned int width, unsigned int height, + Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) override; + +}; + +} // Adaptor +} // Internal +} // Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_TIZEN_H diff --git a/adaptors/tizen/native-image-source-impl-tizen.cpp b/adaptors/tizen/native-image-source-impl-tizen.cpp index fecf43b..5ead8ae 100644 --- a/adaptors/tizen/native-image-source-impl-tizen.cpp +++ b/adaptors/tizen/native-image-source-impl-tizen.cpp @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include "native-image-source-impl.h" +#include // EXTERNAL INCLUDES #include @@ -31,7 +31,6 @@ #include #include - // Allow this to be encoded and saved: #include @@ -67,9 +66,9 @@ const int NUM_FORMATS_BLENDING_REQUIRED = 18; using Dali::Integration::PixelBuffer; -NativeImageSource* NativeImageSource::New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +NativeImageSourceTizen* NativeImageSourceTizen::New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) { - NativeImageSource* image = new NativeImageSource( width, height, depth, nativeImageSource ); + NativeImageSourceTizen* image = new NativeImageSourceTizen( width, height, depth, nativeImageSource ); DALI_ASSERT_DEBUG( image && "NativeImageSource allocation failed." ); if( image ) @@ -80,7 +79,7 @@ NativeImageSource* NativeImageSource::New(unsigned int width, unsigned int heigh return image; } -NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +NativeImageSourceTizen::NativeImageSourceTizen( unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) : mWidth( width ), mHeight( height ), mOwnTbmSurface( false ), @@ -109,7 +108,7 @@ NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, D } } -void NativeImageSource::Initialize() +void NativeImageSourceTizen::Initialize() { if( mTbmSurface != NULL || mWidth == 0 || mHeight == 0 ) { @@ -169,7 +168,7 @@ void NativeImageSource::Initialize() mOwnTbmSurface = true; } -tbm_surface_h NativeImageSource::GetSurfaceFromAny( Any source ) const +tbm_surface_h NativeImageSourceTizen::GetSurfaceFromAny( Any source ) const { if( source.Empty() ) { @@ -186,7 +185,7 @@ tbm_surface_h NativeImageSource::GetSurfaceFromAny( Any source ) const } } -NativeImageSource::~NativeImageSource() +NativeImageSourceTizen::~NativeImageSourceTizen() { if( mOwnTbmSurface ) { @@ -209,18 +208,18 @@ NativeImageSource::~NativeImageSource() } } -Any NativeImageSource::GetNativeImageSource() const +Any NativeImageSourceTizen::GetNativeImageSource() const { return Any( mTbmSurface ); } -void NativeImageSource::SetDestructorNotification(void* notification) +void NativeImageSourceTizen::SetDestructorNotification(void* notification) { mNotification = notification; } -bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const +bool NativeImageSourceTizen::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const { if( mTbmSurface != NULL ) { @@ -313,7 +312,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& return false; } -bool NativeImageSource::EncodeToFile(const std::string& filename) const +bool NativeImageSourceTizen::EncodeToFile(const std::string& filename) const { std::vector< unsigned char > pixbuf; unsigned int width(0), height(0); @@ -326,7 +325,7 @@ bool NativeImageSource::EncodeToFile(const std::string& filename) const return false; } -void NativeImageSource::SetSource( Any source ) +void NativeImageSourceTizen::SetSource( Any source ) { if( mOwnTbmSurface ) { @@ -359,7 +358,7 @@ void NativeImageSource::SetSource( Any source ) } } -bool NativeImageSource::IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) +bool NativeImageSourceTizen::IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) { uint32_t* formats; uint32_t formatNum; @@ -410,7 +409,7 @@ bool NativeImageSource::IsColorDepthSupported( Dali::NativeImageSource::ColorDep return false; } -bool NativeImageSource::GlExtensionCreate() +bool NativeImageSourceTizen::GlExtensionCreate() { // casting from an unsigned int to a void *, which should then be cast back // to an unsigned int in the driver. @@ -425,7 +424,7 @@ bool NativeImageSource::GlExtensionCreate() return mEglImageKHR != NULL; } -void NativeImageSource::GlExtensionDestroy() +void NativeImageSourceTizen::GlExtensionDestroy() { if( mEglImageKHR ) { @@ -435,14 +434,14 @@ void NativeImageSource::GlExtensionDestroy() } } -unsigned int NativeImageSource::TargetTexture() +unsigned int NativeImageSourceTizen::TargetTexture() { mEglImageExtensions->TargetTextureKHR(mEglImageKHR); return 0; } -void NativeImageSource::PrepareTexture() +void NativeImageSourceTizen::PrepareTexture() { if( mSetSource ) { @@ -459,55 +458,22 @@ void NativeImageSource::PrepareTexture() } } -int NativeImageSource::GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const -{ - switch (depth) - { - case Dali::NativeImageSource::COLOR_DEPTH_DEFAULT: - { - // ToDo: Get the default screen depth - return 32; - } - case Dali::NativeImageSource::COLOR_DEPTH_8: - { - return 8; - } - case Dali::NativeImageSource::COLOR_DEPTH_16: - { - return 16; - } - case Dali::NativeImageSource::COLOR_DEPTH_24: - { - return 24; - } - case Dali::NativeImageSource::COLOR_DEPTH_32: - { - return 32; - } - default: - { - DALI_ASSERT_DEBUG(0 && "unknown color enum"); - return 0; - } - } -} - -const char* NativeImageSource::GetCustomFragmentPreFix() +const char* NativeImageSourceTizen::GetCustomFragmentPreFix() { return FRAGMENT_PREFIX; } -const char* NativeImageSource::GetCustomSamplerTypename() +const char* NativeImageSourceTizen::GetCustomSamplerTypename() { return SAMPLER_TYPE; } -int NativeImageSource::GetEglImageTextureTarget() +int NativeImageSourceTizen::GetEglImageTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; } -bool NativeImageSource::CheckBlending( tbm_format format ) +bool NativeImageSourceTizen::CheckBlending( tbm_format format ) { if( mTbmFormat != format ) { diff --git a/adaptors/tizen/native-image-source-impl.h b/adaptors/tizen/native-image-source-impl-tizen.h similarity index 75% rename from adaptors/tizen/native-image-source-impl.h rename to adaptors/tizen/native-image-source-impl-tizen.h index a724d1e..6d72fb8 100644 --- a/adaptors/tizen/native-image-source-impl.h +++ b/adaptors/tizen/native-image-source-impl-tizen.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H__ -#define __DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H__ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -25,6 +25,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -40,7 +41,7 @@ class EglImageExtensions; /** * Dali internal NativeImageSource. */ -class NativeImageSource: public NativeImageInterface::Extension +class NativeImageSourceTizen: public Internal::Adaptor::NativeImageSource, public NativeImageInterface::Extension { public: @@ -50,10 +51,10 @@ public: * @param[in] width The width of the image. * @param[in] height The height of the image. * @param[in] depth color depth of the image. - * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty + * @param[in] nativeImageSource contains tbm_surface_h or is empty * @return A smart-pointer to a newly allocated image. */ - static NativeImageSource* New(unsigned int width, + static NativeImageSourceTizen* New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource); @@ -61,58 +62,57 @@ public: /** * @copydoc Dali::NativeImageSource::GetNativeImageSource() */ - Any GetNativeImageSource() const; - + Any GetNativeImageSource() const override; /** * @copydoc Dali::NativeImageSource::GetPixels() */ - bool GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const; + bool GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const override; /** * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& ) */ - bool EncodeToFile(const std::string& filename) const; + bool EncodeToFile(const std::string& filename) const override; /** * @copydoc Dali::NativeImageSource::SetSource( Any source ) */ - void SetSource( Any source ); + void SetSource( Any source ) override; /** * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth ) */ - bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ); + bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override; /** * destructor */ - ~NativeImageSource(); + ~NativeImageSourceTizen() override; /** * @copydoc Dali::NativeImageSource::GlExtensionCreate() */ - bool GlExtensionCreate(); + bool GlExtensionCreate() override; /** * @copydoc Dali::NativeImageSource::GlExtensionDestroy() */ - void GlExtensionDestroy(); + void GlExtensionDestroy() override; /** * @copydoc Dali::NativeImageSource::TargetTexture() */ - unsigned int TargetTexture(); + unsigned int TargetTexture() override; /** * @copydoc Dali::NativeImageSource::PrepareTexture() */ - void PrepareTexture(); + void PrepareTexture() override; /** * @copydoc Dali::NativeImageSource::GetWidth() */ - unsigned int GetWidth() const + unsigned int GetWidth() const override { return mWidth; } @@ -120,7 +120,7 @@ public: /** * @copydoc Dali::NativeImageSource::GetHeight() */ - unsigned int GetHeight() const + unsigned int GetHeight() const override { return mHeight; } @@ -128,7 +128,7 @@ public: /** * @copydoc Dali::NativeImageSource::RequiresBlending() */ - bool RequiresBlending() const + bool RequiresBlending() const override { return mBlendingRequired; } @@ -136,7 +136,7 @@ public: /** * @copydoc Dali::NativeImageInterface::GetExtension() */ - NativeImageInterface::Extension* GetNativeImageInterfaceExtension() + NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override { return this; } @@ -144,22 +144,22 @@ public: /** * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix() */ - const char* GetCustomFragmentPreFix(); + const char* GetCustomFragmentPreFix() override; /** * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename() */ - const char* GetCustomSamplerTypename(); + const char* GetCustomSamplerTypename() override; /** * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget() */ - int GetEglImageTextureTarget(); + int GetEglImageTextureTarget() override; /** * @copydoc Dali::NativeImageInterface::Extension::SetDestructorNotification((void *notification) */ - void SetDestructorNotification(void* notification); + void SetDestructorNotification(void* notification) override; private: @@ -170,15 +170,13 @@ private: * @param[in] colour depth of the image. * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty */ - NativeImageSource(unsigned int width, + NativeImageSourceTizen(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource); void Initialize(); - int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const; - tbm_surface_h GetSurfaceFromAny( Any source ) const; bool CheckBlending( tbm_format format ); @@ -186,8 +184,8 @@ private: private: unsigned int mWidth; ///< image width - unsigned int mHeight; ///< image heights - bool mOwnTbmSurface; ///< Whether we created pixmap or not + unsigned int mHeight; ///< image height + bool mOwnTbmSurface; ///< Whether we created pixmap or not tbm_surface_h mTbmSurface; tbm_format mTbmFormat; bool mBlendingRequired; ///< Whether blending is required @@ -204,4 +202,4 @@ private: } // namespace Dali -#endif // __DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H__ +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H diff --git a/adaptors/tizen/native-image-source-queue-impl-tizen.cpp b/adaptors/tizen/native-image-source-queue-impl-tizen.cpp new file mode 100644 index 0000000..60a584e --- /dev/null +++ b/adaptors/tizen/native-image-source-queue-impl-tizen.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2018 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 + +// EXTERNAL INCLUDES +#include +#include +#include + +// INTERNAL INCLUDES +#include +#include +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +namespace +{ +#define TBM_SURFACE_QUEUE_SIZE 3 + +const char* FRAGMENT_PREFIX = "#extension GL_OES_EGL_image_external:require\n"; +const char* SAMPLER_TYPE = "samplerExternalOES"; + +int FORMATS_BLENDING_REQUIRED[] = { + TBM_FORMAT_ARGB4444, TBM_FORMAT_ABGR4444, + TBM_FORMAT_RGBA4444, TBM_FORMAT_BGRA4444, + TBM_FORMAT_RGBX5551, TBM_FORMAT_BGRX5551, + TBM_FORMAT_ARGB1555, TBM_FORMAT_ABGR1555, + TBM_FORMAT_RGBA5551, TBM_FORMAT_BGRA5551, + TBM_FORMAT_ARGB8888, TBM_FORMAT_ABGR8888, + TBM_FORMAT_RGBA8888, TBM_FORMAT_BGRA8888, + TBM_FORMAT_ARGB2101010, TBM_FORMAT_ABGR2101010, + TBM_FORMAT_RGBA1010102, TBM_FORMAT_BGRA1010102 +}; + +const int NUM_FORMATS_BLENDING_REQUIRED = 18; + +} + +NativeImageSourceQueueTizen* NativeImageSourceQueueTizen::New( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) +{ + NativeImageSourceQueueTizen* image = new NativeImageSourceQueueTizen( width, height, depth, nativeImageSourceQueue ); + DALI_ASSERT_DEBUG( image && "NativeImageSourceQueueTizen allocation failed." ); + + if( image ) + { + image->Initialize( depth ); + } + + return image; +} + +NativeImageSourceQueueTizen::NativeImageSourceQueueTizen( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) +: mWidth( width ), + mHeight( height ), + mTbmQueue( NULL ), + mConsumeSurface( NULL ), + mEglImages(), + mEglImageExtensions( NULL ), + mOwnTbmQueue( false ), + mBlendingRequired( false ) +{ + DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() ); + EglFactory& eglFactory = Adaptor::GetImplementation( Adaptor::Get() ).GetEGLFactory(); + mEglImageExtensions = eglFactory.GetImageExtensions(); + DALI_ASSERT_DEBUG( mEglImageExtensions ); + + mTbmQueue = GetSurfaceFromAny( nativeImageSourceQueue ); + + if( mTbmQueue != NULL ) + { + mBlendingRequired = CheckBlending( tbm_surface_queue_get_format( mTbmQueue ) ); + mWidth = tbm_surface_queue_get_width( mTbmQueue ); + mHeight = tbm_surface_queue_get_height( mTbmQueue ); + } +} + +NativeImageSourceQueueTizen::~NativeImageSourceQueueTizen() +{ + if( mOwnTbmQueue ) + { + DestroyQueue(); + } +} + +void NativeImageSourceQueueTizen::Initialize( Dali::NativeImageSourceQueue::ColorDepth depth ) +{ + if( mTbmQueue != NULL || mWidth == 0 || mHeight == 0 ) + { + return; + } + + int format = TBM_FORMAT_ARGB8888; + + switch( depth ) + { + case Dali::NativeImageSourceQueue::COLOR_DEPTH_DEFAULT: + case Dali::NativeImageSourceQueue::COLOR_DEPTH_32: + { + format = TBM_FORMAT_ARGB8888; + mBlendingRequired = true; + break; + } + case Dali::NativeImageSourceQueue::COLOR_DEPTH_24: + { + format = TBM_FORMAT_RGB888; + mBlendingRequired = false; + break; + } + default: + { + DALI_LOG_WARNING( "Wrong color depth.\n" ); + return; + } + } + + mTbmQueue = tbm_surface_queue_create( TBM_SURFACE_QUEUE_SIZE, mWidth, mHeight, format, 0 ); + + mOwnTbmQueue = true; +} + +tbm_surface_queue_h NativeImageSourceQueueTizen::GetSurfaceFromAny( Any source ) const +{ + if( source.Empty() ) + { + return NULL; + } + + if( source.GetType() == typeid( tbm_surface_queue_h ) ) + { + return AnyCast< tbm_surface_queue_h >( source ); + } + else + { + return NULL; + } +} + +Any NativeImageSourceQueueTizen::GetNativeImageSourceQueue() const +{ + return Any( mTbmQueue ); +} + +void NativeImageSourceQueueTizen::SetSource( Any source ) +{ + if( mOwnTbmQueue ) + { + DestroyQueue(); + } + + mTbmQueue = GetSurfaceFromAny( source ); + + if( mTbmQueue != NULL ) + { + mBlendingRequired = CheckBlending( tbm_surface_queue_get_format( mTbmQueue ) ); + mWidth = tbm_surface_queue_get_width( mTbmQueue ); + mHeight = tbm_surface_queue_get_height( mTbmQueue ); + } +} + +bool NativeImageSourceQueueTizen::GlExtensionCreate() +{ + return true; +} + +void NativeImageSourceQueueTizen::GlExtensionDestroy() +{ + for( auto&& iter : mEglImages ) + { + mEglImageExtensions->DestroyImageKHR( iter.second ); + + tbm_surface_internal_unref( iter.first ); + } + mEglImages.clear(); +} + +unsigned int NativeImageSourceQueueTizen::TargetTexture() +{ + return 0; +} + +void NativeImageSourceQueueTizen::PrepareTexture() +{ + tbm_surface_h oldSurface = mConsumeSurface; + + bool needToWait = ( mConsumeSurface == NULL ) ? true : false; + + if( tbm_surface_queue_can_acquire( mTbmQueue, needToWait ) ) + { + if( tbm_surface_queue_acquire( mTbmQueue, &mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE ) + { + DALI_LOG_ERROR( "Failed to aquire a tbm_surface\n" ); + return; + } + } + + if( oldSurface && oldSurface != mConsumeSurface ) + { + if( tbm_surface_internal_is_valid( oldSurface ) ) + { + tbm_surface_queue_release( mTbmQueue, oldSurface ); + } + } + + if( mConsumeSurface ) + { + bool existing = false; + for( auto&& iter : mEglImages ) + { + if( iter.first == mConsumeSurface ) + { + // Find the surface in the existing list + existing = true; + mEglImageExtensions->TargetTextureKHR( iter.second ); + break; + } + } + + if( !existing ) + { + // Push the surface + tbm_surface_internal_ref( mConsumeSurface ); + + void* eglImageKHR = mEglImageExtensions->CreateImageKHR( reinterpret_cast< EGLClientBuffer >( mConsumeSurface ) ); + mEglImageExtensions->TargetTextureKHR( eglImageKHR ); + + mEglImages.push_back( EglImagePair( mConsumeSurface, eglImageKHR) ); + } + } +} + +const char* NativeImageSourceQueueTizen::GetCustomFragmentPreFix() +{ + return FRAGMENT_PREFIX; +} + +const char* NativeImageSourceQueueTizen::GetCustomSamplerTypename() +{ + return SAMPLER_TYPE; +} + +int NativeImageSourceQueueTizen::GetEglImageTextureTarget() +{ + return GL_TEXTURE_EXTERNAL_OES; +} + +void NativeImageSourceQueueTizen::SetDestructorNotification(void* notification) +{ +} + +void NativeImageSourceQueueTizen::DestroyQueue() +{ + if( mConsumeSurface ) + { + tbm_surface_internal_unref( mConsumeSurface ); + + if( tbm_surface_internal_is_valid( mConsumeSurface ) ) + { + tbm_surface_queue_release( mTbmQueue, mConsumeSurface ); + } + } + + if( mTbmQueue != NULL ) + { + tbm_surface_queue_destroy( mTbmQueue ); + } + + mTbmQueue = NULL; + mOwnTbmQueue = false; +} + +bool NativeImageSourceQueueTizen::CheckBlending( int format ) +{ + for( int i = 0; i < NUM_FORMATS_BLENDING_REQUIRED; ++i ) + { + if( format == FORMATS_BLENDING_REQUIRED[i] ) + { + return true; + } + } + + return false; +} + +} // namespace Adaptor + +} // namespace internal + +} // namespace Dali diff --git a/adaptors/tizen/native-image-source-queue-impl-tizen.h b/adaptors/tizen/native-image-source-queue-impl-tizen.h new file mode 100755 index 0000000..4f9ff6d --- /dev/null +++ b/adaptors/tizen/native-image-source-queue-impl-tizen.h @@ -0,0 +1,185 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H + +/* + * Copyright (c) 2018 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 +#include +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +class EglImageExtensions; + +/** + * Dali internal NativeImageSource. + */ +class NativeImageSourceQueueTizen: public Internal::Adaptor::NativeImageSourceQueue, public NativeImageInterface::Extension +{ +public: + + /** + * Create a new NativeImageSourceQueueTizen internally. + * Depending on hardware the width and height may have to be a power of two. + * @param[in] width The width of the image. + * @param[in] height The height of the image. + * @param[in] depth color depth of the image. + * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty + * @return A smart-pointer to a newly allocated image. + */ + static NativeImageSourceQueueTizen* New(unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ); + + /** + * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue() + */ + Any GetNativeImageSourceQueue() const override; + + /** + * @copydoc Dali::NativeImageSourceQueue::SetSource( Any source ) + */ + void SetSource( Any source ) override; + + /** + * destructor + */ + ~NativeImageSourceQueueTizen() override; + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionCreate() + */ + bool GlExtensionCreate() override; + + /** + * @copydoc Dali::NativeImageInterface::GlExtensionDestroy() + */ + void GlExtensionDestroy() override; + + /** + * @copydoc Dali::NativeImageInterface::TargetTexture() + */ + unsigned int TargetTexture() override; + + /** + * @copydoc Dali::NativeImageInterface::PrepareTexture() + */ + void PrepareTexture() override; + + /** + * @copydoc Dali::NativeImageInterface::GetWidth() + */ + unsigned int GetWidth() const override + { + return mWidth; + } + + /** + * @copydoc Dali::NativeImageInterface::GetHeight() + */ + unsigned int GetHeight() const override + { + return mHeight; + } + + /** + * @copydoc Dali::NativeImageInterface::RequiresBlending() + */ + bool RequiresBlending() const override + { + return mBlendingRequired; + } + + /** + * @copydoc Dali::NativeImageInterface::GetExtension() + */ + NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override + { + return this; + } + + /** + * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix() + */ + const char* GetCustomFragmentPreFix() override; + + /** + * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename() + */ + const char* GetCustomSamplerTypename() override; + + /** + * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget() + */ + int GetEglImageTextureTarget() override; + + /** + * @copydoc Dali::NativeImageInterface::Extension::SetDestructorNotification((void *notification) + */ + void SetDestructorNotification(void* notification) override; + +private: + + /** + * Private constructor; @see NativeImageSourceQueue::New() + * @param[in] width The width of the image. + * @param[in] height The height of the image. + * @param[in] colour depth of the image. + * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty + */ + NativeImageSourceQueueTizen( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ); + + void Initialize( Dali::NativeImageSourceQueue::ColorDepth depth ); + + void DestroyQueue(); + + tbm_surface_queue_h GetSurfaceFromAny( Any source ) const; + + bool CheckBlending( int format ); + +private: + + typedef std::pair< tbm_surface_h, void* > EglImagePair; + + unsigned int mWidth; ///< image width + unsigned int mHeight; ///< image height + tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle + tbm_surface_h mConsumeSurface; ///< The current tbm surface + std::vector< EglImagePair > mEglImages; ///< EGL Image vector + EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions + bool mOwnTbmQueue; ///< Whether we created tbm queue + bool mBlendingRequired; ///< Whether blending is required +}; + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H diff --git a/adaptors/x11/file.list b/adaptors/x11/file.list index 32e9d14..7e62d6d 100644 --- a/adaptors/x11/file.list +++ b/adaptors/x11/file.list @@ -4,6 +4,7 @@ _adaptor_x11_internal_src_files = \ $(adaptor_x11_dir)/clipboard-impl-x.cpp \ $(adaptor_x11_dir)/display-connection-impl-x.cpp \ $(adaptor_x11_dir)/imf-manager-impl-x.cpp \ + $(adaptor_x11_dir)/native-image-source-factory-x.cpp \ $(adaptor_x11_dir)/native-image-source-impl-x.cpp \ $(adaptor_x11_dir)/virtual-keyboard-impl-x.cpp \ $(adaptor_x11_dir)/window-impl-x.cpp \ diff --git a/adaptors/x11/native-image-source-factory-x.cpp b/adaptors/x11/native-image-source-factory-x.cpp new file mode 100644 index 0000000..cbea31f --- /dev/null +++ b/adaptors/x11/native-image-source-factory-x.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018 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 + +// INTERNAL HEADERS +#include +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ + +std::unique_ptr< NativeImageSource > NativeImageSourceFactoryX::CreateNativeImageSource( unsigned int width, unsigned int height, + Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +{ + return std::unique_ptr< NativeImageSource >( NativeImageSourceX::New( width, height, depth, nativeImageSource ) ); +} + +std::unique_ptr< NativeImageSourceQueue > NativeImageSourceFactoryX::CreateNativeImageSourceQueue( unsigned int width, unsigned int height, + Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) +{ + return std::unique_ptr< NativeImageSourceQueue >( nullptr ); +} + +// this should be created from somewhere +std::unique_ptr< NativeImageSourceFactory > GetNativeImageSourceFactory() +{ + // returns native image source factory + return std::unique_ptr< NativeImageSourceFactoryX >( new NativeImageSourceFactoryX() ); +} + +} // Adaptor +} // Internal +} // Dali diff --git a/adaptors/x11/native-image-source-factory-x.h b/adaptors/x11/native-image-source-factory-x.h new file mode 100644 index 0000000..93c50fd --- /dev/null +++ b/adaptors/x11/native-image-source-factory-x.h @@ -0,0 +1,47 @@ +#ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_X_H +#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_X_H + +/* + * Copyright (c) 2018 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. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Internal +{ +namespace Adaptor +{ + +class NativeImageSourceFactoryX : public NativeImageSourceFactory +{ +public: + + std::unique_ptr< NativeImageSource > CreateNativeImageSource( unsigned int width, unsigned int height, + Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) override; + + std::unique_ptr< NativeImageSourceQueue > CreateNativeImageSourceQueue( unsigned int width, unsigned int height, + Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue ) override; + +}; + +} // Adaptor +} // Internal +} // Dali + +#endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_FACTORY_X_H diff --git a/adaptors/x11/native-image-source-impl-x.cpp b/adaptors/x11/native-image-source-impl-x.cpp index 45562ee..edf0c21 100644 --- a/adaptors/x11/native-image-source-impl-x.cpp +++ b/adaptors/x11/native-image-source-impl-x.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -16,7 +16,7 @@ */ // CLASS HEADER -#include "native-image-source-impl.h" +#include // EXTERNAL INCLUDES #include @@ -72,9 +72,9 @@ namespace }; } -NativeImageSource* NativeImageSource::New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +NativeImageSourceX* NativeImageSourceX::New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) { - NativeImageSource* image = new NativeImageSource( width, height, depth, nativeImageSource ); + NativeImageSourceX* image = new NativeImageSourceX( width, height, depth, nativeImageSource ); DALI_ASSERT_DEBUG( image && "NativeImageSource allocation failed." ); // 2nd phase construction @@ -86,7 +86,7 @@ NativeImageSource* NativeImageSource::New(unsigned int width, unsigned int heigh return image; } -NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) +NativeImageSourceX::NativeImageSourceX( unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource ) : mWidth( width ), mHeight( height ), mOwnPixmap( true ), @@ -105,7 +105,7 @@ NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, D mPixmap = GetPixmapFromAny(nativeImageSource); } -void NativeImageSource::Initialize() +void NativeImageSourceX::Initialize() { // if pixmap has been created outside of X11 Image we can return if (mPixmap) @@ -132,7 +132,7 @@ void NativeImageSource::Initialize() ecore_x_sync(); } -NativeImageSource::~NativeImageSource() +NativeImageSourceX::~NativeImageSourceX() { if (mOwnPixmap && mPixmap) { @@ -140,13 +140,13 @@ NativeImageSource::~NativeImageSource() } } -Any NativeImageSource::GetNativeImageSource() const +Any NativeImageSourceX::GetNativeImageSource() const { // return ecore x11 type return Any(mPixmap); } -bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const +bool NativeImageSourceX::GetPixels(std::vector& pixbuf, unsigned& width, unsigned& height, Pixel::Format& pixelFormat) const { DALI_ASSERT_DEBUG(sizeof(unsigned) == 4); bool success = false; @@ -159,7 +159,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& XImageJanitor xImageJanitor( XGetImage( displayConnection, mPixmap, 0, 0, // x,y of subregion to extract. - width, height, // of suregion to extract. + width, height, // of subregion to extract. 0xFFFFFFFF, ZPixmap ) ); XImage* const pXImage = xImageJanitor.mXImage; @@ -260,7 +260,7 @@ bool NativeImageSource::GetPixels(std::vector& pixbuf, unsigned& return success; } -bool NativeImageSource::EncodeToFile(const std::string& filename) const +bool NativeImageSourceX::EncodeToFile(const std::string& filename) const { std::vector< unsigned char > pixbuf; unsigned int width(0), height(0); @@ -273,7 +273,7 @@ bool NativeImageSource::EncodeToFile(const std::string& filename) const return false; } -void NativeImageSource::SetSource( Any source ) +void NativeImageSourceX::SetSource( Any source ) { mPixmap = GetPixmapFromAny( source ); @@ -287,12 +287,12 @@ void NativeImageSource::SetSource( Any source ) } } -bool NativeImageSource::IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) +bool NativeImageSourceX::IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) { return true; } -bool NativeImageSource::GlExtensionCreate() +bool NativeImageSourceX::GlExtensionCreate() { // if the image existed previously delete it. if (mEglImageKHR != NULL) @@ -309,25 +309,25 @@ bool NativeImageSource::GlExtensionCreate() return mEglImageKHR != NULL; } -void NativeImageSource::GlExtensionDestroy() +void NativeImageSourceX::GlExtensionDestroy() { mEglImageExtensions->DestroyImageKHR(mEglImageKHR); mEglImageKHR = NULL; } -unsigned int NativeImageSource::TargetTexture() +unsigned int NativeImageSourceX::TargetTexture() { mEglImageExtensions->TargetTextureKHR(mEglImageKHR); return 0; } -void NativeImageSource::PrepareTexture() +void NativeImageSourceX::PrepareTexture() { } -int NativeImageSource::GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const +int NativeImageSourceX::GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const { switch (depth) { @@ -360,7 +360,7 @@ int NativeImageSource::GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) } } -Ecore_X_Pixmap NativeImageSource::GetPixmapFromAny(Any pixmap) const +Ecore_X_Pixmap NativeImageSourceX::GetPixmapFromAny(Any pixmap) const { if (pixmap.Empty()) { @@ -382,7 +382,7 @@ Ecore_X_Pixmap NativeImageSource::GetPixmapFromAny(Any pixmap) const } } -void NativeImageSource::GetPixmapDetails() +void NativeImageSourceX::GetPixmapDetails() { int x, y; diff --git a/adaptors/x11/native-image-source-impl.h b/adaptors/x11/native-image-source-impl-x.h similarity index 86% rename from adaptors/x11/native-image-source-impl.h rename to adaptors/x11/native-image-source-impl-x.h index 1838c68..832d178 100644 --- a/adaptors/x11/native-image-source-impl.h +++ b/adaptors/x11/native-image-source-impl-x.h @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -37,7 +38,7 @@ class EglImageExtensions; /** * Dali internal NativeImageSource. */ -class NativeImageSource +class NativeImageSourceX : public Internal::Adaptor::NativeImageSource { public: @@ -50,64 +51,64 @@ public: * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty * @return A smart-pointer to a newly allocated image. */ - static NativeImageSource* New(unsigned int width, + static NativeImageSourceX* New(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource); /** * @copydoc Dali::NativeImageSource::GetNativeImageSource() */ - Any GetNativeImageSource() const; + Any GetNativeImageSource() const override; /** * @copydoc Dali::NativeImageSource::GetPixels() */ - bool GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const; + bool GetPixels(std::vector &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const override; /** * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& ) */ - bool EncodeToFile(const std::string& filename) const; + bool EncodeToFile(const std::string& filename) const override; /** * @copydoc Dali::NativeImageSource::SetSource( Any source ) */ - void SetSource( Any source ); + void SetSource( Any source ) override; /** * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth ) */ - bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ); + bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override; /** * destructor */ - ~NativeImageSource(); + ~NativeImageSourceX() override; /** * @copydoc Dali::NativeImageSource::GlExtensionCreate() */ - bool GlExtensionCreate(); + bool GlExtensionCreate() override; /** * @copydoc Dali::NativeImageSource::GlExtensionDestroy() */ - void GlExtensionDestroy(); + void GlExtensionDestroy() override; /** * @copydoc Dali::NativeImageSource::TargetTexture() */ - unsigned int TargetTexture(); + unsigned int TargetTexture() override; /** * @copydoc Dali::NativeImageSource::PrepareTexture() */ - void PrepareTexture(); + void PrepareTexture() override; /** * @copydoc Dali::NativeImageSource::GetWidth() */ - unsigned int GetWidth() const + unsigned int GetWidth() const override { return mWidth; } @@ -115,7 +116,7 @@ public: /** * @copydoc Dali::NativeImageSource::GetHeight() */ - unsigned int GetHeight() const + unsigned int GetHeight() const override { return mHeight; } @@ -123,7 +124,7 @@ public: /** * @copydoc Dali::NativeImageSource::RequiresBlending() */ - bool RequiresBlending() const + bool RequiresBlending() const override { return mBlendingRequired; } @@ -131,9 +132,9 @@ public: /** * @copydoc Dali::NativeImageInterface::GetExtension() */ - NativeImageInterface::Extension* GetNativeImageInterfaceExtension() + NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override { - return NULL; + return nullptr; } private: @@ -145,7 +146,7 @@ private: * @param[in] colour depth of the image. * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty */ - NativeImageSource(unsigned int width, + NativeImageSourceX(unsigned int width, unsigned int height, Dali::NativeImageSource::ColorDepth depth, Any nativeImageSource);