1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
5 * Copyright (c) 2022 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 <hardware_buffer.h>
25 #include <dali/internal/graphics/common/graphics-interface.h>
27 #include <dali/public-api/adaptor-framework/native-image-source.h>
29 #include <dali/internal/imaging/common/native-image-source-impl.h>
38 class EglImageExtensions;
41 * Dali internal NativeImageSource.
43 class NativeImageSourceAndroid : public Internal::Adaptor::NativeImageSource
47 * Create a new NativeImageSource internally.
48 * Depending on hardware the width and height may have to be a power of two.
49 * @param[in] width The width of the image.
50 * @param[in] height The height of the image.
51 * @param[in] depth color depth of the image.
52 * @param[in] nativeImageSource contains either: Android hardware buffer or is empty
53 * @return A smart-pointer to a newly allocated image.
55 static NativeImageSourceAndroid* New(uint32_t width,
57 Dali::NativeImageSource::ColorDepth depth,
58 Any nativeImageSource);
60 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
62 Any GetNativeImageSource() const override;
65 * @copydoc Dali::NativeImageSource::GetPixels()
67 bool GetPixels(std::vector<unsigned char>& pixbuf, uint32_t& width, uint32_t& height, Pixel::Format& pixelFormat) const override;
70 * @copydoc Dali::NativeImageSource::SetSource( Any source )
72 void SetSource(Any source) override;
75 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
77 bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
82 ~NativeImageSourceAndroid() override;
85 * @copydoc Dali::NativeImageSource::CreateResource()
87 bool CreateResource() override;
90 * @copydoc Dali::NativeImageSource::DestroyResource()
92 void DestroyResource() override;
95 * @copydoc Dali::NativeImageSource::TargetTexture()
97 uint32_t TargetTexture() override;
100 * @copydoc Dali::NativeImageSource::PrepareTexture()
102 void PrepareTexture() override;
105 * @copydoc Dali::NativeImageSource::GetWidth()
107 uint32_t GetWidth() const override
113 * @copydoc Dali::NativeImageSource::GetHeight()
115 uint32_t GetHeight() const override
121 * @copydoc Dali::NativeImageSource::RequiresBlending()
123 bool RequiresBlending() const override
125 return mBlendingRequired;
129 * @copydoc Dali::NativeImageSource::GetTargetTexture()
131 int GetTextureTarget() const override;
134 * @copydoc Dali::NativeImageSource::ApplyNativeFragmentShader()
136 bool ApplyNativeFragmentShader(std::string& shader) override;
139 * @copydoc Dali::NativeImageSource::GetCustomSamplerTypename()
141 const char* GetCustomSamplerTypename() const override;
144 * @copydoc Dali::NativeImageSource::GetNativeImageHandle()
146 Any GetNativeImageHandle() const override
148 return GetNativeImageSource();
152 * @copydoc Dali::NativeImageSource::SourceChanged()
154 bool SourceChanged() const override
160 * @copydoc Dali::NativeImageInterface::GetExtension()
162 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
168 * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
170 uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
173 * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
175 bool ReleaseBuffer() override;
178 * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
180 void SetResourceDestructionCallback(EventThreadCallback* callback) override;
184 * Private constructor; @see NativeImageSource::New()
185 * @param[in] width The width of the image.
186 * @param[in] height The height of the image.
187 * @param[in] colour depth of the image.
188 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
190 NativeImageSourceAndroid(uint32_t width,
192 Dali::NativeImageSource::ColorDepth depth,
193 Any nativeImageSource);
196 * 2nd phase construction.
201 * Gets the pixmap from the Any parameter
202 * @param pixmap contains either: pixmap of type Android hardware buffer or empty
203 * @return pixmap pixmap
205 void* GetPixmapFromAny(Any pixmap) const;
208 * Given an existing pixmap, the function uses Android hardware buffer API to find
209 * the width, heigth and depth of that pixmap.
211 void GetPixmapDetails();
214 uint32_t mWidth; ///< image width
215 uint32_t mHeight; ///< image heights
216 bool mOwnPixmap; ///< Whether we created pixmap or not
217 AHardwareBuffer* mPixmap; ///<
218 bool mBlendingRequired; ///< Whether blending is required
219 Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image
220 void* mEglImageKHR; ///< From EGL extension
221 EglGraphics* mEglGraphics; ///< EGL Graphics
222 EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
223 std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
226 } // namespace Adaptor
228 } // namespace Internal
232 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H