Merge "Support scroll in web engine." 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) 2020 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 <dali/internal/imaging/common/native-image-source-impl.h>
24 #include <extern-definitions.h>
25 #include <CoreGraphics/CoreGraphics.h>
26
27 namespace Dali::Internal::Adaptor
28 {
29
30 class EglImageExtensions;
31
32 /**
33  * Dali internal NativeImageSource.
34  */
35 class NativeImageSourceCocoa : public Internal::Adaptor::NativeImageSource
36 {
37 public:
38
39   /**
40    * Create a new NativeImageSource internally.
41    * Depending on hardware the width and height may have to be a power of two.
42    * @param[in] width The width of the image.
43    * @param[in] height The height of the image.
44    * @param[in] depth color depth of the image.
45    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
46    * @return A smart-pointer to a newly allocated image.
47    */
48   static NativeImageSourceCocoa* New(
49     unsigned int width,
50     unsigned int height,
51     Dali::NativeImageSource::ColorDepth depth,
52     Any nativeImageSource
53   );
54
55   /**
56    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
57    */
58   Any GetNativeImageSource() const override;
59
60   /**
61    * @copydoc Dali::NativeImageSource::GetPixels()
62    */
63   bool GetPixels(
64     std::vector<unsigned char> &pixbuf,
65     unsigned int &width,
66     unsigned int &height,
67     Pixel::Format& pixelFormat
68   ) const override;
69
70   /**
71    * @copydoc Dali::NativeImageSource::SetSource( Any source )
72    */
73   void SetSource( Any source ) override;
74
75   /**
76    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
77    */
78   bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
79
80   /**
81    * destructor
82    */
83   ~NativeImageSourceCocoa() override;
84
85   /**
86    * @copydoc Dali::NativeImageSource::CreateResource()
87    */
88   bool CreateResource() override;
89
90   /**
91    * @copydoc Dali::NativeImageSource::DestroyResource()
92    */
93   void DestroyResource() override;
94
95   /**
96    * @copydoc Dali::NativeImageSource::TargetTexture()
97    */
98   unsigned int TargetTexture() override;
99
100   /**
101    * @copydoc Dali::NativeImageSource::PrepareTexture()
102    */
103   void PrepareTexture() override;
104
105   /**
106    * @copydoc Dali::NativeImageSource::GetWidth()
107    */
108   unsigned int GetWidth() const override;
109
110   /**
111    * @copydoc Dali::NativeImageSource::GetHeight()
112    */
113   unsigned int GetHeight() const override;
114
115   /**
116    * @copydoc Dali::NativeImageSource::RequiresBlending()
117    */
118   bool RequiresBlending() const override;
119
120   /**
121    * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
122    */
123   const char* GetCustomFragmentPrefix() const override;
124
125   /**
126    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
127    */
128   const char* GetCustomSamplerTypename() const override;
129
130   /**
131    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
132    */
133   int GetTextureTarget() const override;
134
135   /**
136    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
137    */
138   Any GetNativeImageHandle() const override;
139
140   /**
141    * @copydoc Dali::NativeImageInterface::SourceChanged()
142    */
143   bool SourceChanged() const override;
144
145   /**
146    * @copydoc Dali::NativeImageInterface::GetExtension()
147    */
148   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
149   {
150     return nullptr;
151   }
152
153   /**
154    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
155    */
156   uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override;
157
158   /**
159    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
160    */
161   bool ReleaseBuffer() override;
162
163 private:
164
165   /**
166    * Private constructor; @see NativeImageSource::New()
167    * @param[in] width The width of the image.
168    * @param[in] height The height of the image.
169    * @param[in] colour depth of the image.
170    * @param[in] nativeImageSource contains either: pixmap of type Win32 Pixmap , a WinPixmap or is empty
171    */
172   NativeImageSourceCocoa(
173     unsigned int width,
174     unsigned  int height,
175     Dali::NativeImageSource::ColorDepth depth,
176     Any nativeImageSource
177   );
178
179 private:
180   CFRef<CGImageRef> mImage;
181 };
182
183 } // namespace Dali::Internal::Adaptor