Merge "Add input region APIs" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / macos / native-image-source-impl-mac.h
1 #pragma once
2
3 /*
4  * Copyright (c) 2021 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::GetExtension()
143    */
144   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
145   {
146     return nullptr;
147   }
148
149   /**
150    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
151    */
152   uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
153
154   /**
155    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
156    */
157   bool ReleaseBuffer() override;
158
159 private:
160   /**
161    * Private constructor; @see NativeImageSource::New()
162    * @param[in] width The width of the image.
163    * @param[in] height The height of the image.
164    * @param[in] colour depth of the image.
165    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
166    */
167   NativeImageSourceCocoa(
168     unsigned int                        width,
169     unsigned int                        height,
170     Dali::NativeImageSource::ColorDepth depth,
171     Any                                 nativeImageSource);
172
173 private:
174   CFRef<CGImageRef> mImage;
175 };
176
177 } // namespace Dali::Internal::Adaptor