1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
5 * Copyright (c) 2023 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/devel-api/adaptor-framework/event-thread-callback.h>
24 #include <dali/public-api/adaptor-framework/native-image-source.h>
33 * Dali internal NativeImageSource.
35 class NativeImageSource
38 static constexpr uint32_t DEFAULT_QUALITY = 100;
41 * Create a new NativeImageSource internally.
42 * Depending on hardware the width and height may have to be a power of two.
43 * @param[in] width The width of the image.
44 * @param[in] height The height of the image.
45 * @param[in] depth color depth of the image.
46 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
47 * @return A smart-pointer to a newly allocated image.
49 static NativeImageSource* New(uint32_t width,
51 Dali::NativeImageSource::ColorDepth depth,
52 Any nativeImageSource);
54 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
56 virtual Any GetNativeImageSource() const = 0;
59 * @copydoc Dali::NativeImageSource::GetPixels()
61 virtual bool GetPixels(std::vector<unsigned char>& pixbuf, uint32_t& width, uint32_t& height, Pixel::Format& pixelFormat) const = 0;
64 * @copydoc Dali::NativeImageSource::SetSource( Any source )
66 virtual void SetSource(Any source) = 0;
69 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
71 virtual bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) = 0;
76 virtual ~NativeImageSource() = default;
79 * @copydoc Dali::NativeImageSource::CreateResource()
81 virtual bool CreateResource() = 0;
84 * @copydoc Dali::NativeImageSource::DestroyResource()
86 virtual void DestroyResource() = 0;
89 * @copydoc Dali::NativeImageSource::TargetTexture()
91 virtual uint32_t TargetTexture() = 0;
94 * @copydoc Dali::NativeImageSource::PrepareTexture()
96 virtual void PrepareTexture() = 0;
99 * @copydoc Dali::NativeImageSource::GetWidth()
101 virtual uint32_t GetWidth() const = 0;
104 * @copydoc Dali::NativeImageSource::GetHeight()
106 virtual uint32_t GetHeight() const = 0;
109 * @copydoc Dali::NativeImageSource::RequiresBlending()
111 virtual bool RequiresBlending() const = 0;
114 * @copydoc Dali::NativeImageSource::GetTextureTarget()
116 virtual int GetTextureTarget() const = 0;
119 * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
121 virtual bool ApplyNativeFragmentShader(std::string& shader) = 0;
124 * @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
126 virtual const char* GetCustomSamplerTypename() const = 0;
129 * @copydoc Dali::NativeImageSource::GetNativeImageHandle()
131 virtual Any GetNativeImageHandle() const = 0;
134 * @copydoc Dali::NativeImageSource::SourceChanged()
136 virtual bool SourceChanged() const = 0;
139 * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
141 virtual Rect<uint32_t> GetUpdatedArea() = 0;
144 * @copydoc Dali::NativeImageInterface::GetExtension()
146 virtual NativeImageInterface::Extension* GetNativeImageInterfaceExtension() = 0;
149 * @copydoc Dali::DevelNativeImageSource::AcquireBuffer()
151 virtual uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) = 0;
154 * @copydoc Dali::DevelNativeImageSource::ReleaseBuffer()
156 virtual bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) = 0;
159 * @copydoc Dali::DevelNativeImageSource::SetResourceDestructionCallback()
161 virtual void SetResourceDestructionCallback(EventThreadCallback* callback) = 0;
164 * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
166 virtual void EnableBackBuffer(bool enable) = 0;
169 * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
171 inline bool EncodeToFile(const std::string& filename) const
173 return EncodeToFile(filename, DEFAULT_QUALITY);
177 * @brief Converts the current pixel contents to either a JPEG or PNG format
178 * and write that to the filesystem.
180 * @param[in] filename Identify the filesystem location at which to write the encoded image.
181 * The extension determines the encoding used.
182 * The two valid encoding are (".jpeg"|".jpg") and ".png".
183 * @param[in] quality The quality of encoded jpeg image
184 * @return @c true if the pixels were written, and @c false otherwise
186 inline bool EncodeToFile(const std::string& filename, const uint32_t quality) const
188 std::vector<uint8_t> pixbuf;
189 uint32_t width(0), height(0);
190 Pixel::Format pixelFormat;
192 if(GetPixels(pixbuf, width, height, pixelFormat))
194 return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height, quality);
200 inline static Internal::Adaptor::NativeImageSource& GetImplementation(Dali::NativeImageSource& image)
206 } // namespace Adaptor
208 } // namespace Internal
212 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H