Added UIThreadLoader to GLIB framework
[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
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Adaptor
31 {
32 class EglGraphics;
33 class EglImageExtensions;
34
35 /**
36  * Dali internal NativeImageSource.
37  */
38 class NativeImageSourceWin : public Internal::Adaptor::NativeImageSource
39 {
40 public:
41   /**
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.
49    */
50   static NativeImageSourceWin* New(unsigned int                        width,
51                                    unsigned int                        height,
52                                    Dali::NativeImageSource::ColorDepth depth,
53                                    Any                                 nativeImageSource);
54   /**
55    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
56    */
57   Any GetNativeImageSource() const override;
58
59   /**
60    * @copydoc Dali::NativeImageSource::GetPixels()
61    */
62   bool GetPixels(std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat) const override;
63
64   /**
65    * @copydoc Dali::NativeImageSource::SetSource( Any source )
66    */
67   void SetSource(Any source) override;
68
69   /**
70    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
71    */
72   bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
73
74   /**
75    * destructor
76    */
77   ~NativeImageSourceWin() override;
78
79   /**
80    * @copydoc Dali::NativeImageSource::CreateResource()
81    */
82   bool CreateResource() override;
83
84   /**
85    * @copydoc Dali::NativeImageSource::DestroyResource()
86    */
87   void DestroyResource() override;
88
89   /**
90    * @copydoc Dali::NativeImageSource::TargetTexture()
91    */
92   unsigned int TargetTexture() override;
93
94   /**
95    * @copydoc Dali::NativeImageSource::PrepareTexture()
96    */
97   void PrepareTexture() override;
98
99   /**
100    * @copydoc Dali::NativeImageSource::GetWidth()
101    */
102   unsigned int GetWidth() const override
103   {
104     return mWidth;
105   }
106
107   /**
108    * @copydoc Dali::NativeImageSource::GetHeight()
109    */
110   unsigned int GetHeight() const override
111   {
112     return mHeight;
113   }
114
115   /**
116    * @copydoc Dali::NativeImageSource::RequiresBlending()
117    */
118   bool RequiresBlending() const override
119   {
120     return mBlendingRequired;
121   }
122
123   /**
124    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
125    */
126   bool ApplyNativeFragmentShader(std::string& shader) override;
127
128   /**
129    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
130    */
131   const char* GetCustomSamplerTypename() const override;
132
133   /**
134    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
135    */
136   int GetTextureTarget() const override;
137
138   /**
139    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
140    */
141   Any GetNativeImageHandle() const override;
142
143   /**
144    * @copydoc Dali::NativeImageInterface::SourceChanged()
145    */
146   bool SourceChanged() const override;
147
148   /**
149    * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
150    */
151   Rect<uint32_t> GetUpdatedArea() override
152   {
153     return Rect<uint32_t>{0, 0, mWidth, mHeight};
154   }
155
156   /**
157    * @copydoc Dali::NativeImageInterface::GetExtension()
158    */
159   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
160   {
161     return nullptr;
162   }
163
164   /**
165    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
166    */
167   uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
168
169   /**
170    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
171    */
172   bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
173
174   /**
175    * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
176    */
177   void SetResourceDestructionCallback(EventThreadCallback* callback) override;
178
179   /**
180    * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
181    */
182   void EnableBackBuffer(bool enable) override;
183
184 private:
185   /**
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
191    */
192   NativeImageSourceWin(unsigned int                        width,
193                        unsigned int                        height,
194                        Dali::NativeImageSource::ColorDepth depth,
195                        Any                                 nativeImageSource);
196
197   /**
198    * 2nd phase construction.
199    */
200   void Initialize();
201
202   /**
203    * Uses X11 to get the default depth.
204    * @param depth the PixelImage depth enum
205    * @return default win32 pixel depth
206    */
207   int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const;
208
209   /**
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
213    */
214   unsigned int GetPixmapFromAny(Any pixmap) const;
215
216   /**
217    * Given an existing pixmap, the function uses X to find out
218    * the width, heigth and depth of that pixmap.
219    */
220   void GetPixmapDetails();
221
222 private:
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
233 };
234
235 } // namespace Adaptor
236
237 } // namespace Internal
238
239 } // namespace Dali
240
241 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H