1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
5 * Copyright (c) 2021 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/devel-api/adaptor-framework/bitmap-saver.h>
23 #include <dali/public-api/adaptor-framework/native-image-source.h>
24 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
34 * Dali internal NativeImageSource.
36 class NativeImageSource
39 static constexpr uint32_t DEFAULT_QUALITY = 100;
42 * Create a new NativeImageSource internally.
43 * Depending on hardware the width and height may have to be a power of two.
44 * @param[in] width The width of the image.
45 * @param[in] height The height of the image.
46 * @param[in] depth color depth of the image.
47 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
48 * @return A smart-pointer to a newly allocated image.
50 static NativeImageSource* New(uint32_t width,
52 Dali::NativeImageSource::ColorDepth depth,
53 Any nativeImageSource);
55 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
57 virtual Any GetNativeImageSource() const = 0;
60 * @copydoc Dali::NativeImageSource::GetPixels()
62 virtual bool GetPixels(std::vector<unsigned char>& pixbuf, uint32_t& width, uint32_t& height, Pixel::Format& pixelFormat) const = 0;
65 * @copydoc Dali::NativeImageSource::SetSource( Any source )
67 virtual void SetSource(Any source) = 0;
70 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
72 virtual bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) = 0;
77 virtual ~NativeImageSource() = default;
80 * @copydoc Dali::NativeImageSource::CreateResource()
82 virtual bool CreateResource() = 0;
85 * @copydoc Dali::NativeImageSource::DestroyResource()
87 virtual void DestroyResource() = 0;
90 * @copydoc Dali::NativeImageSource::TargetTexture()
92 virtual uint32_t TargetTexture() = 0;
95 * @copydoc Dali::NativeImageSource::PrepareTexture()
97 virtual void PrepareTexture() = 0;
100 * @copydoc Dali::NativeImageSource::GetWidth()
102 virtual uint32_t GetWidth() const = 0;
105 * @copydoc Dali::NativeImageSource::GetHeight()
107 virtual uint32_t GetHeight() const = 0;
110 * @copydoc Dali::NativeImageSource::RequiresBlending()
112 virtual bool RequiresBlending() const = 0;
115 * @copydoc Dali::NativeImageSource::GetTextureTarget()
117 virtual int GetTextureTarget() const = 0;
120 * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
122 virtual bool ApplyNativeFragmentShader(std::string& shader) = 0;
125 * @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
127 virtual const char* GetCustomSamplerTypename() const = 0;
130 * @copydoc Dali::NativeImageSource::GetNativeImageHandle()
132 virtual Any GetNativeImageHandle() const = 0;
135 * @copydoc Dali::NativeImageSource::SourceChanged()
137 virtual bool SourceChanged() const = 0;
140 * @copydoc Dali::NativeImageInterface::GetExtension()
142 virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0;
145 * @brief Dali::DevelNativeImageSource::AcquireBuffer()
147 virtual uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) = 0;
150 * @brief Dali::DevelNativeImageSource::ReleaseBuffer()
152 virtual bool ReleaseBuffer() = 0;
155 * @brief Dali::DevelNativeImageSource::SetResourceDestructionCallback()
157 virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0;
160 * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
162 inline bool EncodeToFile(const std::string& filename) const
164 return EncodeToFile(filename, DEFAULT_QUALITY);
168 * @brief Converts the current pixel contents to either a JPEG or PNG format
169 * and write that to the filesystem.
171 * @param[in] filename Identify the filesystem location at which to write the encoded image.
172 * The extension determines the encoding used.
173 * The two valid encoding are (".jpeg"|".jpg") and ".png".
174 * @param[in] quality The quality of encoded jpeg image
175 * @return @c true if the pixels were written, and @c false otherwise
177 inline bool EncodeToFile(const std::string& filename, const uint32_t quality) const
179 std::vector<uint8_t> pixbuf;
180 uint32_t width(0), height(0);
181 Pixel::Format pixelFormat;
183 if(GetPixels(pixbuf, width, height, pixelFormat))
185 return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height, quality);
191 inline static Internal::Adaptor::NativeImageSource& GetImplementation(Dali::NativeImageSource& image)
197 } // namespace Adaptor
199 } // namespace Internal
203 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H