Added UIThreadLoader to GLIB framework
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / macos / native-image-source-impl-mac.h
1 #pragma once
2
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/adaptor-framework/native-image-source.h>
22
23 #include <CoreGraphics/CoreGraphics.h>
24 #include <dali/internal/imaging/common/native-image-source-impl.h>
25 #include <extern-definitions.h>
26
27 namespace Dali::Internal::Adaptor
28 {
29 class EglImageExtensions;
30
31 /**
32  * Dali internal NativeImageSource.
33  */
34 class NativeImageSourceCocoa : public Internal::Adaptor::NativeImageSource
35 {
36 public:
37   /**
38    * Create a new NativeImageSource internally.
39    * Depending on hardware the width and height may have to be a power of two.
40    * @param[in] width The width of the image.
41    * @param[in] height The height of the image.
42    * @param[in] depth color depth of the image.
43    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
44    * @return A smart-pointer to a newly allocated image.
45    */
46   static NativeImageSourceCocoa* New(
47     unsigned int                        width,
48     unsigned int                        height,
49     Dali::NativeImageSource::ColorDepth depth,
50     Any                                 nativeImageSource);
51
52   /**
53    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
54    */
55   Any GetNativeImageSource() const override;
56
57   /**
58    * @copydoc Dali::NativeImageSource::GetPixels()
59    */
60   bool GetPixels(
61     std::vector<unsigned char>& pixbuf,
62     unsigned int&               width,
63     unsigned int&               height,
64     Pixel::Format&              pixelFormat) const override;
65
66   /**
67    * @copydoc Dali::NativeImageSource::SetSource( Any source )
68    */
69   void SetSource(Any source) override;
70
71   /**
72    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
73    */
74   bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
75
76   /**
77    * destructor
78    */
79   ~NativeImageSourceCocoa() override;
80
81   /**
82    * @copydoc Dali::NativeImageSource::CreateResource()
83    */
84   bool CreateResource() override;
85
86   /**
87    * @copydoc Dali::NativeImageSource::DestroyResource()
88    */
89   void DestroyResource() override;
90
91   /**
92    * @copydoc Dali::NativeImageSource::TargetTexture()
93    */
94   unsigned int TargetTexture() override;
95
96   /**
97    * @copydoc Dali::NativeImageSource::PrepareTexture()
98    */
99   void PrepareTexture() override;
100
101   /**
102    * @copydoc Dali::NativeImageSource::GetWidth()
103    */
104   unsigned int GetWidth() const override;
105
106   /**
107    * @copydoc Dali::NativeImageSource::GetHeight()
108    */
109   unsigned int GetHeight() const override;
110
111   /**
112    * @copydoc Dali::NativeImageSource::RequiresBlending()
113    */
114   bool RequiresBlending() const override;
115
116   /**
117    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
118    */
119   bool ApplyNativeFragmentShader(std::string& shader) override;
120
121   /**
122    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
123    */
124   const char* GetCustomSamplerTypename() const override;
125
126   /**
127    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
128    */
129   int GetTextureTarget() const override;
130
131   /**
132    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
133    */
134   Any GetNativeImageHandle() const override;
135
136   /**
137    * @copydoc Dali::NativeImageInterface::SourceChanged()
138    */
139   bool SourceChanged() const override;
140
141   /**
142    * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
143    */
144   Rect<uint32_t> GetUpdatedArea() override
145   {
146     return Rect<uint32_t>{0, 0, static_cast<uint32_t>(CGImageGetWidth(mImage.get())), static_cast<uint32_t>(CGImageGetHeight(mImage.get()))};
147   }
148
149   /**
150    * @copydoc Dali::NativeImageInterface::GetExtension()
151    */
152   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
153   {
154     return nullptr;
155   }
156
157   /**
158    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
159    */
160   uint8_t* AcquireBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
161
162   /**
163    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
164    */
165   bool ReleaseBuffer(const Rect<uint32_t>& updatedArea) override;
166
167   /**
168    * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
169    */
170   void SetResourceDestructionCallback(EventThreadCallback* callback) override;
171
172   /**
173    * @copydoc Dali::DevelNativeImageSource::EnableBackBuffer()
174    */
175   void EnableBackBuffer(bool enable) override;
176
177 private:
178   /**
179    * Private constructor; @see NativeImageSource::New()
180    * @param[in] width The width of the image.
181    * @param[in] height The height of the image.
182    * @param[in] colour depth of the image.
183    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
184    */
185   NativeImageSourceCocoa(
186     unsigned int                        width,
187     unsigned int                        height,
188     Dali::NativeImageSource::ColorDepth depth,
189     Any                                 nativeImageSource);
190
191 private:
192   CFRef<CGImageRef>                    mImage;
193   std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
194 };
195
196 } // namespace Dali::Internal::Adaptor