1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_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/public-api/adaptor-framework/native-image-source.h>
24 #include <dali/internal/imaging/common/native-image-source-impl.h>
33 class EglImageExtensions;
36 * Dali internal NativeImageSource.
38 class NativeImageSourceWin : public Internal::Adaptor::NativeImageSource
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 Win32 Pixmap , a WinPixmap or is empty
48 * @return A smart-pointer to a newly allocated image.
50 static NativeImageSourceWin* New(unsigned int width,
52 Dali::NativeImageSource::ColorDepth depth,
53 Any nativeImageSource);
55 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
57 Any GetNativeImageSource() const override;
60 * @copydoc Dali::NativeImageSource::GetPixels()
62 bool GetPixels(std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat) const override;
65 * @copydoc Dali::NativeImageSource::SetSource( Any source )
67 void SetSource(Any source) override;
70 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
72 bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
77 ~NativeImageSourceWin() override;
80 * @copydoc Dali::NativeImageSource::CreateResource()
82 bool CreateResource() override;
85 * @copydoc Dali::NativeImageSource::DestroyResource()
87 void DestroyResource() override;
90 * @copydoc Dali::NativeImageSource::TargetTexture()
92 unsigned int TargetTexture() override;
95 * @copydoc Dali::NativeImageSource::PrepareTexture()
97 void PrepareTexture() override;
100 * @copydoc Dali::NativeImageSource::GetWidth()
102 unsigned int GetWidth() const override
108 * @copydoc Dali::NativeImageSource::GetHeight()
110 unsigned int GetHeight() const override
116 * @copydoc Dali::NativeImageSource::RequiresBlending()
118 bool RequiresBlending() const override
120 return mBlendingRequired;
124 * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
126 bool ApplyNativeFragmentShader(std::string& shader) override;
129 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
131 const char* GetCustomSamplerTypename() const override;
134 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
136 int GetTextureTarget() const override;
139 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
141 Any GetNativeImageHandle() const override;
144 * @copydoc Dali::NativeImageInterface::SourceChanged()
146 bool SourceChanged() const override;
149 * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
151 Rect<uint32_t> GetUpdatedArea() override
153 return Rect<uint32_t>{0, 0, mWidth, mHeight};
157 * @copydoc Dali::NativeImageInterface::GetExtension()
159 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
165 * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
167 uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
170 * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
172 bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
175 * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
177 void SetResourceDestructionCallback(EventThreadCallback* callback) override;
180 * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
182 void EnableBackBuffer(bool enable) override;
186 * Private constructor; @see NativeImageSource::New()
187 * @param[in] width The width of the image.
188 * @param[in] height The height of the image.
189 * @param[in] colour depth of the image.
190 * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
192 NativeImageSourceWin(unsigned int width,
194 Dali::NativeImageSource::ColorDepth depth,
195 Any nativeImageSource);
198 * 2nd phase construction.
203 * Uses X11 to get the default depth.
204 * @param depth the PixelImage depth enum
205 * @return default win32 pixel depth
207 int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const;
210 * Gets the pixmap from the Any parameter
211 * @param pixmap contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
212 * @return pixmap x11 pixmap
214 unsigned int GetPixmapFromAny(Any pixmap) const;
217 * Given an existing pixmap, the function uses X to find out
218 * the width, heigth and depth of that pixmap.
220 void GetPixmapDetails();
223 unsigned int mWidth; ///< image width
224 unsigned int mHeight; ///< image heights
225 bool mOwnPixmap; ///< Whether we created pixmap or not
226 unsigned int mPixmap; ///< From Windows
227 bool mBlendingRequired; ///< Whether blending is required
228 Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image
229 void* mEglImageKHR; ///< From EGL extension
230 EglGraphics* mEglGraphics; ///< EGL Graphics
231 EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
232 std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
235 } // namespace Adaptor
237 } // namespace Internal
241 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H