#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
+#include <dali/devel-api/adaptor-framework/event-thread-callback.h>
namespace Dali
{
{
public:
+ static constexpr uint32_t DEFAULT_QUALITY = 100;
+
/**
* Create a new NativeImageSource internally.
* Depending on hardware the width and height may have to be a power of two.
* @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,
+ static NativeImageSource* New(uint32_t width,
+ uint32_t height,
Dali::NativeImageSource::ColorDepth depth,
Any nativeImageSource);
/**
* @copydoc Dali::NativeImageSource::GetNativeImageSource()
*/
- virtual Any GetNativeImageSource() const;
+ virtual Any GetNativeImageSource() const = 0;
/**
* @copydoc Dali::NativeImageSource::GetPixels()
*/
- virtual bool GetPixels(std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const;
-
- /**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- virtual bool EncodeToFile(const std::string& filename) const;
+ virtual bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const = 0;
/**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
*/
- virtual void SetSource( Any source );
+ virtual void SetSource( Any source ) = 0;
/**
* @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
*/
- virtual bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth );
+ virtual bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) = 0;
/**
* destructor
*/
- virtual ~NativeImageSource();
+ virtual ~NativeImageSource() = default;
/**
- * @copydoc Dali::NativeImageSource::GlExtensionCreate()
+ * @copydoc Dali::NativeImageSource::CreateResource()
*/
- virtual bool GlExtensionCreate();
+ virtual bool CreateResource() = 0;
/**
- * @copydoc Dali::NativeImageSource::GlExtensionDestroy()
+ * @copydoc Dali::NativeImageSource::DestroyResource()
*/
- virtual void GlExtensionDestroy();
+ virtual void DestroyResource() = 0;
/**
* @copydoc Dali::NativeImageSource::TargetTexture()
*/
- virtual unsigned int TargetTexture();
+ virtual uint32_t TargetTexture() = 0;
/**
* @copydoc Dali::NativeImageSource::PrepareTexture()
*/
- virtual void PrepareTexture();
+ virtual void PrepareTexture() = 0;
/**
* @copydoc Dali::NativeImageSource::GetWidth()
*/
- virtual unsigned int GetWidth() const;
+ virtual uint32_t GetWidth() const = 0;
/**
* @copydoc Dali::NativeImageSource::GetHeight()
*/
- virtual unsigned int GetHeight() const;
+ virtual uint32_t GetHeight() const = 0;
/**
* @copydoc Dali::NativeImageSource::RequiresBlending()
*/
- virtual bool RequiresBlending() const;
+ virtual bool RequiresBlending() const = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::GetTextureTarget()
+ */
+ virtual int GetTextureTarget() const = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::GetCustomFragmentPrefix()
+ */
+ virtual const char* GetCustomFragmentPrefix() const = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
+ */
+ virtual const char* GetCustomSamplerTypename() const = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::GetNativeImageHandle()
+ */
+ virtual Any GetNativeImageHandle() const = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::SourceChanged()
+ */
+ virtual bool SourceChanged() const = 0;
/**
* @copydoc Dali::NativeImageInterface::GetExtension()
*/
- virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension();
+ 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;
+
+ /**
+ * @brief Dali::DevelNativeImageSource::SetResourceDestructionCallback()
+ */
+ virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0;
+
+ /**
+ * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
+ */
+ inline bool EncodeToFile( const std::string& filename ) const
+ {
+ return EncodeToFile( filename, DEFAULT_QUALITY );
+ }
+
+ /**
+ * @brief Converts the current pixel contents to either a JPEG or PNG format
+ * and write that to the filesystem.
+ *
+ * @param[in] filename Identify the filesystem location at which to write the encoded image.
+ * The extension determines the encoding used.
+ * The two valid encoding are (".jpeg"|".jpg") and ".png".
+ * @param[in] quality The quality of encoded jpeg image
+ * @return @c true if the pixels were written, and @c false otherwise
+ */
+ inline bool EncodeToFile( const std::string& filename, const uint32_t quality ) const
+ {
+ std::vector< uint8_t > pixbuf;
+ uint32_t width( 0 ), height( 0 );
+ Pixel::Format pixelFormat;
+
+ if( GetPixels( pixbuf, width, height, pixelFormat ) )
+ {
+ return Dali::EncodeToFile( &pixbuf[0], filename, pixelFormat, width, height, quality );
+ }
+ return false;
+ }
+
+public:
+ inline static Internal::Adaptor::NativeImageSource& GetImplementation( Dali::NativeImageSource& image ) { return *image.mImpl; }
};
} // namespace Adaptor