1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/adaptor-framework/native-image-source.h>
23 #include <dali/devel-api/adaptor-framework/bitmap-saver.h>
24 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
36 * Dali internal NativeImageSource.
38 class NativeImageSource
42 static constexpr uint32_t DEFAULT_QUALITY = 100;
45 * Create a new NativeImageSource internally.
46 * Depending on hardware the width and height may have to be a power of two.
47 * @param[in] width The width of the image.
48 * @param[in] height The height of the image.
49 * @param[in] depth color depth of the image.
50 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
51 * @return A smart-pointer to a newly allocated image.
53 static NativeImageSource* New(uint32_t width,
55 Dali::NativeImageSource::ColorDepth depth,
56 Any nativeImageSource);
58 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
60 virtual Any GetNativeImageSource() const = 0;
63 * @copydoc Dali::NativeImageSource::GetPixels()
65 virtual bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const = 0;
68 * @copydoc Dali::NativeImageSource::SetSource( Any source )
70 virtual void SetSource( Any source ) = 0;
73 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
75 virtual bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) = 0;
80 virtual ~NativeImageSource() = default;
83 * @copydoc Dali::NativeImageSource::CreateResource()
85 virtual bool CreateResource() = 0;
88 * @copydoc Dali::NativeImageSource::DestroyResource()
90 virtual void DestroyResource() = 0;
93 * @copydoc Dali::NativeImageSource::TargetTexture()
95 virtual uint32_t TargetTexture() = 0;
98 * @copydoc Dali::NativeImageSource::PrepareTexture()
100 virtual void PrepareTexture() = 0;
103 * @copydoc Dali::NativeImageSource::GetWidth()
105 virtual uint32_t GetWidth() const = 0;
108 * @copydoc Dali::NativeImageSource::GetHeight()
110 virtual uint32_t GetHeight() const = 0;
113 * @copydoc Dali::NativeImageSource::RequiresBlending()
115 virtual bool RequiresBlending() const = 0;
118 * @copydoc Dali::NativeImageSource::GetTextureTarget()
120 virtual int GetTextureTarget() const = 0;
123 * @copydoc Dali::NativeImageSource::GetCustomFragmentPrefix()
125 virtual const char* GetCustomFragmentPrefix() const = 0;
128 * @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
130 virtual const char* GetCustomSamplerTypename() const = 0;
133 * @copydoc Dali::NativeImageSource::GetNativeImageHandle()
135 virtual Any GetNativeImageHandle() const = 0;
138 * @copydoc Dali::NativeImageSource::SourceChanged()
140 virtual bool SourceChanged() const = 0;
143 * @copydoc Dali::NativeImageInterface::GetExtension()
145 virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0;
148 * @brief Dali::DevelNativeImageSource::AcquireBuffer()
150 virtual uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) = 0;
153 * @brief Dali::DevelNativeImageSource::ReleaseBuffer()
155 virtual bool ReleaseBuffer() = 0;
158 * @brief Dali::DevelNativeImageSource::SetResourceDestructionCallback()
160 virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0;
163 * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
165 inline bool EncodeToFile( const std::string& filename ) const
167 return EncodeToFile( filename, DEFAULT_QUALITY );
171 * @brief Converts the current pixel contents to either a JPEG or PNG format
172 * and write that to the filesystem.
174 * @param[in] filename Identify the filesystem location at which to write the encoded image.
175 * The extension determines the encoding used.
176 * The two valid encoding are (".jpeg"|".jpg") and ".png".
177 * @param[in] quality The quality of encoded jpeg image
178 * @return @c true if the pixels were written, and @c false otherwise
180 inline bool EncodeToFile( const std::string& filename, const uint32_t quality ) const
182 std::vector< uint8_t > pixbuf;
183 uint32_t width( 0 ), height( 0 );
184 Pixel::Format pixelFormat;
186 if( GetPixels( pixbuf, width, height, pixelFormat ) )
188 return Dali::EncodeToFile( &pixbuf[0], filename, pixelFormat, width, height, quality );
194 inline static Internal::Adaptor::NativeImageSource& GetImplementation( Dali::NativeImageSource& image ) { return *image.mImpl; }
197 } // namespace Adaptor
199 } // namespace Internal
203 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H