[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / windows / native-image-source-impl-win.h
1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/adaptor-framework/native-image-source.h>
23
24 #include <dali/internal/imaging/common/native-image-source-impl.h>
25 #include <cstdint>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33 class EglGraphics;
34 class EglImageExtensions;
35
36 /**
37  * Dali internal NativeImageSource.
38  */
39 class NativeImageSourceWin : public Internal::Adaptor::NativeImageSource
40 {
41 public:
42   /**
43    * Create a new NativeImageSource internally.
44    * Depending on hardware the width and height may have to be a power of two.
45    * @param[in] width The width of the image.
46    * @param[in] height The height of the image.
47    * @param[in] depth color depth of the image.
48    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
49    * @return A smart-pointer to a newly allocated image.
50    */
51   static NativeImageSourceWin* New(uint32_t                            width,
52                                    uint32_t                            height,
53                                    Dali::NativeImageSource::ColorDepth depth,
54                                    Any                                 nativeImageSource);
55   /**
56    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
57    */
58   Any GetNativeImageSource() const override;
59
60   /**
61    * @copydoc Dali::NativeImageSource::GetPixels()
62    */
63   bool GetPixels(std::vector<uint8_t>& pixbuf, uint32_t& width, uint32_t& height, Pixel::Format& pixelFormat) const override;
64
65   /**
66    * @copydoc Dali::NativeImageSource::SetSource( Any source )
67    */
68   void SetSource(Any source) override;
69
70   /**
71    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
72    */
73   bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
74
75   /**
76    * destructor
77    */
78   ~NativeImageSourceWin() override;
79
80   /**
81    * @copydoc Dali::NativeImageSource::CreateResource()
82    */
83   bool CreateResource() override;
84
85   /**
86    * @copydoc Dali::NativeImageSource::DestroyResource()
87    */
88   void DestroyResource() override;
89
90   /**
91    * @copydoc Dali::NativeImageSource::TargetTexture()
92    */
93   uint32_t TargetTexture() override;
94
95   /**
96    * @copydoc Dali::NativeImageSource::PrepareTexture()
97    */
98   void PrepareTexture() override;
99
100   /**
101    * @copydoc Dali::NativeImageSource::GetWidth()
102    */
103   uint32_t GetWidth() const override
104   {
105     return mWidth;
106   }
107
108   /**
109    * @copydoc Dali::NativeImageSource::GetHeight()
110    */
111   uint32_t GetHeight() const override
112   {
113     return mHeight;
114   }
115
116   /**
117    * @copydoc Dali::NativeImageSource::RequiresBlending()
118    */
119   bool RequiresBlending() const override
120   {
121     return mBlendingRequired;
122   }
123
124   /**
125    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
126    */
127   bool ApplyNativeFragmentShader(std::string& shader) override;
128
129   /**
130    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
131    */
132   const char* GetCustomSamplerTypename() const override;
133
134   /**
135    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
136    */
137   int GetTextureTarget() const override;
138
139   /**
140    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
141    */
142   Any GetNativeImageHandle() const override;
143
144   /**
145    * @copydoc Dali::NativeImageInterface::SourceChanged()
146    */
147   bool SourceChanged() const override;
148
149   /**
150    * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
151    */
152   Rect<uint32_t> GetUpdatedArea() override
153   {
154     return Rect<uint32_t>{0, 0, mWidth, mHeight};
155   }
156
157   /**
158    * @copydoc Dali::NativeImageInterface::GetExtension()
159    */
160   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
161   {
162     return nullptr;
163   }
164
165   /**
166    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
167    */
168   uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
169
170   /**
171    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
172    */
173   bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
174
175   /**
176    * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
177    */
178   void SetResourceDestructionCallback(EventThreadCallback* callback) override;
179
180   /**
181    * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
182    */
183   void EnableBackBuffer(bool enable) override;
184
185 private:
186   /**
187    * Private constructor; @see NativeImageSource::New()
188    * @param[in] width The width of the image.
189    * @param[in] height The height of the image.
190    * @param[in] colour depth of the image.
191    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
192    */
193   NativeImageSourceWin(uint32_t                            width,
194                        uint32_t                            height,
195                        Dali::NativeImageSource::ColorDepth depth,
196                        Any                                 nativeImageSource);
197
198   /**
199    * 2nd phase construction.
200    */
201   void Initialize();
202
203   /**
204    * Uses X11 to get the default depth.
205    * @param depth the PixelImage depth enum
206    * @return default win32 pixel depth
207    */
208   int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const;
209
210   /**
211    * Gets the pixmap from the Any parameter
212    * @param pixmap contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
213    * @return pixmap x11 pixmap
214    */
215   unsigned int GetPixmapFromAny(Any pixmap) const;
216
217   /**
218    * Given an existing pixmap, the function uses X to find out
219    * the width, heigth and depth of that pixmap.
220    */
221   void GetPixmapDetails();
222
223 private:
224   uint32_t                             mWidth;                       ///< image width
225   uint32_t                             mHeight;                      ///< image heights
226   bool                                 mOwnPixmap;                   ///< Whether we created pixmap or not
227   unsigned int                         mPixmap;                      ///< From Windows
228   bool                                 mBlendingRequired;            ///< Whether blending is required
229   Dali::NativeImageSource::ColorDepth  mColorDepth;                  ///< color depth of image
230   void*                                mEglImageKHR;                 ///< From EGL extension
231   EglGraphics*                         mEglGraphics;                 ///< EGL Graphics
232   EglImageExtensions*                  mEglImageExtensions;          ///< The EGL Image Extensions
233   std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
234 };
235
236 } // namespace Adaptor
237
238 } // namespace Internal
239
240 } // namespace Dali
241
242 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H