From: Joogab Yun Date: Tue, 10 Mar 2020 01:18:08 +0000 (+0900) Subject: Acquire / Release information of an internal native image. X-Git-Tag: dali_1.5.7~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=144454962e8563b88bba0ff057fbb43d7277d356;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Acquire / Release information of an internal native image. Change-Id: I6a92c20e0b2395c26dac29a1b5b565ddcd31dc16 --- diff --git a/dali/devel-api/adaptor-framework/native-image-source-devel.cpp b/dali/devel-api/adaptor-framework/native-image-source-devel.cpp new file mode 100755 index 0000000..3072690 --- /dev/null +++ b/dali/devel-api/adaptor-framework/native-image-source-devel.cpp @@ -0,0 +1,43 @@ +/* + * 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. + * 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 + + +namespace Dali +{ + +namespace DevelNativeImageSource +{ + +uint8_t* AcquireBuffer( NativeImageSource& image, uint16_t& width, uint16_t& height, uint16_t& stride ) +{ + return Dali::Internal::Adaptor::NativeImageSource::GetImplementation( image ).AcquireBuffer( width, height, stride ); +} + +bool ReleaseBuffer( NativeImageSource& image ) +{ + return Dali::Internal::Adaptor::NativeImageSource::GetImplementation( image ).ReleaseBuffer(); +} + +} // namespace DevelNativeImageSource + +} // namespace Dali diff --git a/dali/devel-api/adaptor-framework/native-image-source-devel.h b/dali/devel-api/adaptor-framework/native-image-source-devel.h new file mode 100755 index 0000000..0c470c8 --- /dev/null +++ b/dali/devel-api/adaptor-framework/native-image-source-devel.h @@ -0,0 +1,56 @@ +#ifndef DALI_NATIVE_IMAGE_SOURCE_DEVEL_H +#define DALI_NATIVE_IMAGE_SOURCE_DEVEL_H +/* + * 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. + * 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 + +namespace Dali +{ + +namespace DevelNativeImageSource +{ + +/** + * @brief Acquire buffer and information of an internal native image. + * + * AcquireBuffer() and ReleaseBuffer() are a pair. + * It should be call ReleaseBuffer() after AcquireBuffer(). + * @param[in] image The instance of NativeImageSource. + * @param[out] width The width of image + * @param[out] height The height of image + * @param[out] stride The stride of image + * @return The buffer of an internal native image + */ +DALI_ADAPTOR_API uint8_t* AcquireBuffer( NativeImageSource& image, uint16_t& width, uint16_t& height, uint16_t& stride ); + +/** + * @brief Release information of an internal native image. + * + * AcquireBuffer() and ReleaseBuffer() are a pair. + * It should be call ReleaseBuffer() after AcquireBuffer(). + * @param[in] image The instance of NativeImageSource. + * @return @c true If the buffer is released successfully, and @c false otherwise + */ +DALI_ADAPTOR_API bool ReleaseBuffer( NativeImageSource& image ); + +} // namespace DevelNativeImageSource + +} // namespace Dali + +#endif // DALI_NATIVE_IMAGE_SOURCE_DEVEL_H diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index e85cb13..33c3ab3 100755 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -1,118 +1,120 @@ SET( devel_api_src_files - ${adaptor_devel_api_dir}/adaptor-framework/accessibility-adaptor.cpp - ${adaptor_devel_api_dir}/adaptor-framework/application-devel.cpp - ${adaptor_devel_api_dir}/adaptor-framework/bitmap-saver.cpp - ${adaptor_devel_api_dir}/adaptor-framework/clipboard.cpp - ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.cpp - ${adaptor_devel_api_dir}/adaptor-framework/color-controller.cpp - ${adaptor_devel_api_dir}/adaptor-framework/environment-variable.cpp - ${adaptor_devel_api_dir}/adaptor-framework/event-feeder.cpp - ${adaptor_devel_api_dir}/adaptor-framework/event-thread-callback.cpp - ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.cpp - ${adaptor_devel_api_dir}/adaptor-framework/file-loader.cpp - ${adaptor_devel_api_dir}/adaptor-framework/file-stream.cpp - ${adaptor_devel_api_dir}/adaptor-framework/image-loading.cpp - ${adaptor_devel_api_dir}/adaptor-framework/gif-loading.cpp - ${adaptor_devel_api_dir}/adaptor-framework/input-method-context.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 - ${adaptor_devel_api_dir}/adaptor-framework/key-devel.cpp - ${adaptor_devel_api_dir}/adaptor-framework/pixel-buffer.cpp - ${adaptor_devel_api_dir}/adaptor-framework/sound-player.cpp - ${adaptor_devel_api_dir}/adaptor-framework/style-monitor.cpp - ${adaptor_devel_api_dir}/adaptor-framework/tilt-sensor.cpp - ${adaptor_devel_api_dir}/adaptor-framework/lifecycle-controller.cpp - ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer.cpp - ${adaptor_devel_api_dir}/adaptor-framework/video-player.cpp - ${adaptor_devel_api_dir}/adaptor-framework/virtual-keyboard.cpp - ${adaptor_devel_api_dir}/adaptor-framework/thread-settings.cpp - ${adaptor_devel_api_dir}/adaptor-framework/web-engine.cpp + ${adaptor_devel_api_dir}/adaptor-framework/accessibility-adaptor.cpp + ${adaptor_devel_api_dir}/adaptor-framework/application-devel.cpp + ${adaptor_devel_api_dir}/adaptor-framework/bitmap-saver.cpp + ${adaptor_devel_api_dir}/adaptor-framework/clipboard.cpp + ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.cpp + ${adaptor_devel_api_dir}/adaptor-framework/color-controller.cpp + ${adaptor_devel_api_dir}/adaptor-framework/environment-variable.cpp + ${adaptor_devel_api_dir}/adaptor-framework/event-feeder.cpp + ${adaptor_devel_api_dir}/adaptor-framework/event-thread-callback.cpp + ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.cpp + ${adaptor_devel_api_dir}/adaptor-framework/file-loader.cpp + ${adaptor_devel_api_dir}/adaptor-framework/file-stream.cpp + ${adaptor_devel_api_dir}/adaptor-framework/image-loading.cpp + ${adaptor_devel_api_dir}/adaptor-framework/gif-loading.cpp + ${adaptor_devel_api_dir}/adaptor-framework/input-method-context.cpp + ${adaptor_devel_api_dir}/adaptor-framework/input-method-options.cpp + ${adaptor_devel_api_dir}/adaptor-framework/native-image-source-devel.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 + ${adaptor_devel_api_dir}/adaptor-framework/key-devel.cpp + ${adaptor_devel_api_dir}/adaptor-framework/pixel-buffer.cpp + ${adaptor_devel_api_dir}/adaptor-framework/sound-player.cpp + ${adaptor_devel_api_dir}/adaptor-framework/style-monitor.cpp + ${adaptor_devel_api_dir}/adaptor-framework/tilt-sensor.cpp + ${adaptor_devel_api_dir}/adaptor-framework/lifecycle-controller.cpp + ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer.cpp + ${adaptor_devel_api_dir}/adaptor-framework/video-player.cpp + ${adaptor_devel_api_dir}/adaptor-framework/virtual-keyboard.cpp + ${adaptor_devel_api_dir}/adaptor-framework/thread-settings.cpp + ${adaptor_devel_api_dir}/adaptor-framework/web-engine.cpp ${adaptor_devel_api_dir}/adaptor-framework/window-devel.cpp ) SET( devel_api_adaptor_framework_header_files - ${adaptor_devel_api_dir}/adaptor-framework/accessibility-adaptor.h - ${adaptor_devel_api_dir}/adaptor-framework/accessibility-action-handler.h - ${adaptor_devel_api_dir}/adaptor-framework/accessibility-gesture-handler.h - ${adaptor_devel_api_dir}/adaptor-framework/accessibility-gesture-event.h - ${adaptor_devel_api_dir}/adaptor-framework/application-devel.h - ${adaptor_devel_api_dir}/adaptor-framework/atspi-accessibility.h - ${adaptor_devel_api_dir}/adaptor-framework/bitmap-saver.h - ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.h - ${adaptor_devel_api_dir}/adaptor-framework/clipboard.h - ${adaptor_devel_api_dir}/adaptor-framework/color-controller-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/color-controller.h - ${adaptor_devel_api_dir}/adaptor-framework/environment-variable.h - ${adaptor_devel_api_dir}/adaptor-framework/event-feeder.h - ${adaptor_devel_api_dir}/adaptor-framework/event-thread-callback.h - ${adaptor_devel_api_dir}/adaptor-framework/feedback-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.h - ${adaptor_devel_api_dir}/adaptor-framework/file-loader.h - ${adaptor_devel_api_dir}/adaptor-framework/file-stream.h - ${adaptor_devel_api_dir}/adaptor-framework/image-loader-input.h - ${adaptor_devel_api_dir}/adaptor-framework/image-loader-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/image-loading.h - ${adaptor_devel_api_dir}/adaptor-framework/gif-loading.h - ${adaptor_devel_api_dir}/adaptor-framework/input-method-context.h - ${adaptor_devel_api_dir}/adaptor-framework/input-method-options.h - ${adaptor_devel_api_dir}/adaptor-framework/keyboard.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 - ${adaptor_devel_api_dir}/adaptor-framework/sound-player.h - ${adaptor_devel_api_dir}/adaptor-framework/style-monitor.h - ${adaptor_devel_api_dir}/adaptor-framework/tilt-sensor.h - ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer.h - ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/video-player.h - ${adaptor_devel_api_dir}/adaptor-framework/video-player-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/web-engine.h - ${adaptor_devel_api_dir}/adaptor-framework/web-engine-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/key-extension-plugin.h - ${adaptor_devel_api_dir}/adaptor-framework/virtual-keyboard.h - ${adaptor_devel_api_dir}/adaptor-framework/physical-keyboard.h - ${adaptor_devel_api_dir}/adaptor-framework/key-devel.h - ${adaptor_devel_api_dir}/adaptor-framework/thread-settings.h + ${adaptor_devel_api_dir}/adaptor-framework/accessibility-adaptor.h + ${adaptor_devel_api_dir}/adaptor-framework/accessibility-action-handler.h + ${adaptor_devel_api_dir}/adaptor-framework/accessibility-gesture-handler.h + ${adaptor_devel_api_dir}/adaptor-framework/accessibility-gesture-event.h + ${adaptor_devel_api_dir}/adaptor-framework/application-devel.h + ${adaptor_devel_api_dir}/adaptor-framework/atspi-accessibility.h + ${adaptor_devel_api_dir}/adaptor-framework/bitmap-saver.h + ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.h + ${adaptor_devel_api_dir}/adaptor-framework/clipboard.h + ${adaptor_devel_api_dir}/adaptor-framework/color-controller-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/color-controller.h + ${adaptor_devel_api_dir}/adaptor-framework/environment-variable.h + ${adaptor_devel_api_dir}/adaptor-framework/event-feeder.h + ${adaptor_devel_api_dir}/adaptor-framework/event-thread-callback.h + ${adaptor_devel_api_dir}/adaptor-framework/feedback-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.h + ${adaptor_devel_api_dir}/adaptor-framework/file-loader.h + ${adaptor_devel_api_dir}/adaptor-framework/file-stream.h + ${adaptor_devel_api_dir}/adaptor-framework/image-loader-input.h + ${adaptor_devel_api_dir}/adaptor-framework/image-loader-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/image-loading.h + ${adaptor_devel_api_dir}/adaptor-framework/gif-loading.h + ${adaptor_devel_api_dir}/adaptor-framework/input-method-context.h + ${adaptor_devel_api_dir}/adaptor-framework/input-method-options.h + ${adaptor_devel_api_dir}/adaptor-framework/keyboard.h + ${adaptor_devel_api_dir}/adaptor-framework/lifecycle-controller.h + ${adaptor_devel_api_dir}/adaptor-framework/native-image-source-devel.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 + ${adaptor_devel_api_dir}/adaptor-framework/sound-player.h + ${adaptor_devel_api_dir}/adaptor-framework/style-monitor.h + ${adaptor_devel_api_dir}/adaptor-framework/tilt-sensor.h + ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer.h + ${adaptor_devel_api_dir}/adaptor-framework/vector-animation-renderer-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/video-player.h + ${adaptor_devel_api_dir}/adaptor-framework/video-player-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/key-extension-plugin.h + ${adaptor_devel_api_dir}/adaptor-framework/virtual-keyboard.h + ${adaptor_devel_api_dir}/adaptor-framework/physical-keyboard.h + ${adaptor_devel_api_dir}/adaptor-framework/key-devel.h + ${adaptor_devel_api_dir}/adaptor-framework/thread-settings.h ${adaptor_devel_api_dir}/adaptor-framework/window-devel.h ) SET( devel_api_text_abstraction_src_files - ${adaptor_devel_api_dir}/text-abstraction/bidirectional-support.cpp - ${adaptor_devel_api_dir}/text-abstraction/bitmap-font.cpp - ${adaptor_devel_api_dir}/text-abstraction/font-client.cpp - ${adaptor_devel_api_dir}/text-abstraction/font-list.cpp - ${adaptor_devel_api_dir}/text-abstraction/font-metrics.cpp - ${adaptor_devel_api_dir}/text-abstraction/glyph-info.cpp - ${adaptor_devel_api_dir}/text-abstraction/script.cpp - ${adaptor_devel_api_dir}/text-abstraction/segmentation.cpp - ${adaptor_devel_api_dir}/text-abstraction/shaping.cpp - ${adaptor_devel_api_dir}/text-abstraction/text-renderer.cpp + ${adaptor_devel_api_dir}/text-abstraction/bidirectional-support.cpp + ${adaptor_devel_api_dir}/text-abstraction/bitmap-font.cpp + ${adaptor_devel_api_dir}/text-abstraction/font-client.cpp + ${adaptor_devel_api_dir}/text-abstraction/font-list.cpp + ${adaptor_devel_api_dir}/text-abstraction/font-metrics.cpp + ${adaptor_devel_api_dir}/text-abstraction/glyph-info.cpp + ${adaptor_devel_api_dir}/text-abstraction/script.cpp + ${adaptor_devel_api_dir}/text-abstraction/segmentation.cpp + ${adaptor_devel_api_dir}/text-abstraction/shaping.cpp + ${adaptor_devel_api_dir}/text-abstraction/text-renderer.cpp ${adaptor_devel_api_dir}/text-abstraction/text-renderer-layout-helper.cpp ) SET( text_abstraction_header_files - ${adaptor_devel_api_dir}/text-abstraction/bidirectional-support.h - ${adaptor_devel_api_dir}/text-abstraction/bitmap-font.h - ${adaptor_devel_api_dir}/text-abstraction/font-client.h - ${adaptor_devel_api_dir}/text-abstraction/font-list.h - ${adaptor_devel_api_dir}/text-abstraction/font-metrics.h - ${adaptor_devel_api_dir}/text-abstraction/glyph-info.h - ${adaptor_devel_api_dir}/text-abstraction/script.h - ${adaptor_devel_api_dir}/text-abstraction/segmentation.h - ${adaptor_devel_api_dir}/text-abstraction/shaping.h - ${adaptor_devel_api_dir}/text-abstraction/text-abstraction.h - ${adaptor_devel_api_dir}/text-abstraction/text-abstraction-definitions.h - ${adaptor_devel_api_dir}/text-abstraction/text-renderer.h + ${adaptor_devel_api_dir}/text-abstraction/bidirectional-support.h + ${adaptor_devel_api_dir}/text-abstraction/bitmap-font.h + ${adaptor_devel_api_dir}/text-abstraction/font-client.h + ${adaptor_devel_api_dir}/text-abstraction/font-list.h + ${adaptor_devel_api_dir}/text-abstraction/font-metrics.h + ${adaptor_devel_api_dir}/text-abstraction/glyph-info.h + ${adaptor_devel_api_dir}/text-abstraction/script.h + ${adaptor_devel_api_dir}/text-abstraction/segmentation.h + ${adaptor_devel_api_dir}/text-abstraction/shaping.h + ${adaptor_devel_api_dir}/text-abstraction/text-abstraction.h + ${adaptor_devel_api_dir}/text-abstraction/text-abstraction-definitions.h + ${adaptor_devel_api_dir}/text-abstraction/text-renderer.h ${adaptor_devel_api_dir}/text-abstraction/text-renderer-layout-helper.h ) diff --git a/dali/internal/imaging/android/native-image-source-impl-android.cpp b/dali/internal/imaging/android/native-image-source-impl-android.cpp old mode 100644 new mode 100755 index fcf3ae5..53fdc8c --- a/dali/internal/imaging/android/native-image-source-impl-android.cpp +++ b/dali/internal/imaging/android/native-image-source-impl-android.cpp @@ -308,12 +308,13 @@ void NativeImageSourceAndroid::GetPixmapDetails() // get the width, height and depth mBlendingRequired = false; - AHardwareBuffer_Desc* bufferDescription = nullptr; - AHardwareBuffer_describe( mPixmap, bufferDescription ); + AHardwareBuffer_Desc bufferDescription; + memset( &bufferDescription, 0, sizeof( AHardwareBuffer_Desc ) ); + AHardwareBuffer_describe( mPixmap, &bufferDescription ); - mWidth = bufferDescription->width; - mHeight = bufferDescription->height; - switch (bufferDescription->format) + mWidth = bufferDescription.width; + mHeight = bufferDescription.height; + switch (bufferDescription.format) { case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: mColorDepth = Dali::NativeImageSource::COLOR_DEPTH_32; @@ -330,6 +331,46 @@ void NativeImageSourceAndroid::GetPixmapDetails() } } +uint8_t* NativeImageSourceAndroid::AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) +{ + if( mPixmap ) + { + AHardwareBuffer_Desc bufferDescription; + memset( &bufferDescription, 0, sizeof( AHardwareBuffer_Desc ) ); + AHardwareBuffer_describe( mPixmap, &bufferDescription ); + + void* buffer = NULL; + if( AHardwareBuffer_lock( mPixmap, AHARDWAREBUFFER_USAGE_CPU_READ_RARELY, -1, NULL, &buffer ) != 0 ) + { + DALI_LOG_ERROR( "Failed to AHardwareBuffer_lock\n" ); + return NULL; + } + + stride = bufferDescription.stride; + width = bufferDescription.width; + height = bufferDescription.height; + + return static_cast< uint8_t* >( buffer ); + } + + return NULL; +} + + +bool NativeImageSourceAndroid::ReleaseBuffer() +{ + if( mPixmap ) + { + if( AHardwareBuffer_unlock( mPixmap, NULL ) != 0 ) + { + DALI_LOG_ERROR( "failed to AHardwareBuffer_unlock\n" ); + return false; + } + return true; + } + return false; +} + } // namespace Adaptor } // namespace internal diff --git a/dali/internal/imaging/android/native-image-source-impl-android.h b/dali/internal/imaging/android/native-image-source-impl-android.h old mode 100644 new mode 100755 index a2c40ab..7d941ca --- a/dali/internal/imaging/android/native-image-source-impl-android.h +++ b/dali/internal/imaging/android/native-image-source-impl-android.h @@ -140,6 +140,16 @@ public: return nullptr; } + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer() + */ + uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override; + + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer() + */ + bool ReleaseBuffer() override; + private: /** diff --git a/dali/internal/imaging/common/native-image-source-impl.h b/dali/internal/imaging/common/native-image-source-impl.h index 2b26e9a..d5f292f 100755 --- a/dali/internal/imaging/common/native-image-source-impl.h +++ b/dali/internal/imaging/common/native-image-source-impl.h @@ -119,6 +119,19 @@ public: * @copydoc Dali::NativeImageInterface::GetExtension() */ virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0; + + /** + * @brief Dali::DevelNativeImageSource::AcquireBuffer() + */ + virtual uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) = 0; + + /** + * @brief Dali::DevelNativeImageSource::ReleaseBuffer() + */ + virtual bool ReleaseBuffer() = 0; + +public: + inline static Internal::Adaptor::NativeImageSource& GetImplementation( Dali::NativeImageSource& image ) { return *image.mImpl; } }; } // namespace Adaptor diff --git a/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp b/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp index 6970fc0..ca7ce05 100755 --- a/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp +++ b/dali/internal/imaging/tizen/native-image-source-impl-tizen.cpp @@ -90,7 +90,8 @@ NativeImageSourceTizen::NativeImageSourceTizen( uint32_t width, uint32_t height, mEglGraphics( NULL ), mEglImageExtensions( NULL ), mSetSource( false ), - mMutex() + mMutex(), + mIsBufferAcquired( false ) { DALI_ASSERT_ALWAYS( Adaptor::IsAvailable() ); @@ -122,7 +123,7 @@ void NativeImageSourceTizen::Initialize() { case Dali::NativeImageSource::COLOR_DEPTH_DEFAULT: { - format = TBM_FORMAT_RGBA8888; + format = TBM_FORMAT_ARGB8888; depth = 32; break; } @@ -146,7 +147,7 @@ void NativeImageSourceTizen::Initialize() } case Dali::NativeImageSource::COLOR_DEPTH_32: { - format = TBM_FORMAT_RGBA8888; + format = TBM_FORMAT_ARGB8888; depth = 32; break; } @@ -185,24 +186,33 @@ tbm_surface_h NativeImageSourceTizen::GetSurfaceFromAny( Any source ) const } } -NativeImageSourceTizen::~NativeImageSourceTizen() +void NativeImageSourceTizen::DestroySurface() { - if( mOwnTbmSurface ) + if( mTbmSurface ) { - if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE ) + if( mIsBufferAcquired ) { - DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" ); + ReleaseBuffer(); } - } - else - { - if( mTbmSurface != NULL ) + if( mOwnTbmSurface ) + { + if( tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE ) + { + DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" ); + } + } + else { tbm_surface_internal_unref( mTbmSurface ); } } } +NativeImageSourceTizen::~NativeImageSourceTizen() +{ + DestroySurface(); +} + Any NativeImageSourceTizen::GetNativeImageSource() const { return Any( mTbmSurface ); @@ -278,6 +288,27 @@ bool NativeImageSourceTizen::GetPixels(std::vector& pixbuf, unsig } break; } + case TBM_FORMAT_ARGB8888: + { + lineSize = width*4; + pixelFormat = Pixel::RGBA8888; + pixbuf.resize( lineSize*height ); + unsigned char* bufptr = &pixbuf[0]; + + for( unsigned int r = 0; r < height; ++r, bufptr += lineSize ) + { + for( unsigned int c = 0; c < width; ++c ) + { + cOffset = c*4; + offset = cOffset + r*stride; + *(bufptr+cOffset) = ptr[offset]; + *(bufptr+cOffset+1) = ptr[offset+3]; + *(bufptr+cOffset+2) = ptr[offset+2]; + *(bufptr+cOffset+3) = ptr[offset+1]; + } + } + break; + } default: { DALI_ASSERT_ALWAYS( 0 && "Tbm surface has unsupported pixel format.\n" ); @@ -318,25 +349,10 @@ bool NativeImageSourceTizen::EncodeToFile(const std::string& filename) const void NativeImageSourceTizen::SetSource( Any source ) { Dali::Mutex::ScopedLock lock( mMutex ); - if( mOwnTbmSurface ) - { - if( mTbmSurface != NULL && tbm_surface_destroy( mTbmSurface ) != TBM_SURFACE_ERROR_NONE ) - { - DALI_LOG_ERROR( "Failed to destroy tbm_surface\n" ); - } - mTbmSurface = NULL; - mOwnTbmSurface = false; - } - else - { - if( mTbmSurface != NULL ) - { - tbm_surface_internal_unref( mTbmSurface ); - mTbmSurface = NULL; - } - } + DestroySurface(); + mOwnTbmSurface = false; mTbmSurface = GetSurfaceFromAny( source ); if( mTbmSurface != NULL ) @@ -359,7 +375,7 @@ bool NativeImageSourceTizen::IsColorDepthSupported( Dali::NativeImageSource::Col { case Dali::NativeImageSource::COLOR_DEPTH_DEFAULT: { - format = TBM_FORMAT_RGBA8888; + format = TBM_FORMAT_ARGB8888; break; } case Dali::NativeImageSource::COLOR_DEPTH_8: @@ -379,7 +395,7 @@ bool NativeImageSourceTizen::IsColorDepthSupported( Dali::NativeImageSource::Col } case Dali::NativeImageSource::COLOR_DEPTH_32: { - format = TBM_FORMAT_RGBA8888; + format = TBM_FORMAT_ARGB8888; break; } } @@ -487,6 +503,53 @@ bool NativeImageSourceTizen::CheckBlending( tbm_format format ) return mBlendingRequired; } +uint8_t* NativeImageSourceTizen::AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) +{ + Dali::Mutex::ScopedLock lock( mMutex ); + if( mTbmSurface != NULL ) + { + tbm_surface_info_s info; + + if( tbm_surface_map( mTbmSurface, TBM_SURF_OPTION_READ, &info) != TBM_SURFACE_ERROR_NONE ) + { + DALI_LOG_ERROR( "Fail to map tbm_surface\n" ); + + width = 0; + height = 0; + + return NULL; + } + tbm_surface_internal_ref( mTbmSurface ); + mIsBufferAcquired = true; + + stride = info.planes[0].stride; + width = mWidth; + height = mHeight; + + return info.planes[0].ptr; + } + return NULL; +} + + +bool NativeImageSourceTizen::ReleaseBuffer() +{ + Dali::Mutex::ScopedLock lock( mMutex ); + bool ret = false; + if( mTbmSurface != NULL ) + { + ret = ( tbm_surface_unmap( mTbmSurface ) != TBM_SURFACE_ERROR_NONE ); + if( !ret ) + { + DALI_LOG_ERROR( "Fail to unmap tbm_surface\n" ); + } + tbm_surface_internal_unref( mTbmSurface ); + mIsBufferAcquired = false; + } + return ret; +} + + } // namespace Adaptor } // namespace internal diff --git a/dali/internal/imaging/tizen/native-image-source-impl-tizen.h b/dali/internal/imaging/tizen/native-image-source-impl-tizen.h index fdeca56..d40142c 100755 --- a/dali/internal/imaging/tizen/native-image-source-impl-tizen.h +++ b/dali/internal/imaging/tizen/native-image-source-impl-tizen.h @@ -158,6 +158,16 @@ public: */ int GetEglImageTextureTarget() override; + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer() + */ + uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override; + + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer() + */ + bool ReleaseBuffer() override; + private: /** @@ -178,6 +188,8 @@ private: bool CheckBlending( tbm_format format ); + void DestroySurface(); + private: uint32_t mWidth; ///< image width @@ -192,6 +204,7 @@ private: EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions bool mSetSource; mutable Dali::Mutex mMutex; + bool mIsBufferAcquired; ///< Whether AcquireBuffer is called }; } // namespace Adaptor diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp old mode 100644 new mode 100755 index 6391c8f..51c89d3 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.cpp @@ -402,6 +402,17 @@ void NativeImageSourceX::GetPixmapDetails() mBlendingRequired = ( depth == 32 || depth == 8 ); } +uint8_t* NativeImageSourceX::AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) +{ + return NULL; +} + + +bool NativeImageSourceX::ReleaseBuffer() +{ + return false; +} + } // namespace Adaptor } // namespace internal diff --git a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h index fb8ae29..5306938 100755 --- a/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h +++ b/dali/internal/imaging/ubuntu-x11/native-image-source-impl-x.h @@ -140,6 +140,16 @@ public: return nullptr; } + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer() + */ + uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override; + + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer() + */ + bool ReleaseBuffer() override; + private: /** diff --git a/dali/internal/imaging/windows/native-image-source-impl-win.cpp b/dali/internal/imaging/windows/native-image-source-impl-win.cpp index 95761b7..12db4fd 100755 --- a/dali/internal/imaging/windows/native-image-source-impl-win.cpp +++ b/dali/internal/imaging/windows/native-image-source-impl-win.cpp @@ -244,6 +244,17 @@ void NativeImageSourceWin::GetPixmapDetails() { } +uint8_t* NativeImageSourceWin::AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) +{ + return NULL; +} + + +bool NativeImageSourceWin::ReleaseBuffer() +{ + return false; +} + } // namespace Adaptor } // namespace internal diff --git a/dali/internal/imaging/windows/native-image-source-impl-win.h b/dali/internal/imaging/windows/native-image-source-impl-win.h index cc76cf4..6fe3fab 100755 --- a/dali/internal/imaging/windows/native-image-source-impl-win.h +++ b/dali/internal/imaging/windows/native-image-source-impl-win.h @@ -135,6 +135,16 @@ public: return nullptr; } + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer() + */ + uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override; + + /** + * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer() + */ + bool ReleaseBuffer() override; + private: /** diff --git a/dali/public-api/adaptor-framework/native-image-source.h b/dali/public-api/adaptor-framework/native-image-source.h index e76cfca..597f063 100755 --- a/dali/public-api/adaptor-framework/native-image-source.h +++ b/dali/public-api/adaptor-framework/native-image-source.h @@ -238,6 +238,8 @@ private: /// @cond internal Internal::Adaptor::NativeImageSource* mImpl; ///< Implementation pointer + friend class Internal::Adaptor::NativeImageSource; + /// @endcond };