4 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/adaptor-framework/native-image-source.h>
23 #include <CoreGraphics/CoreGraphics.h>
24 #include <dali/internal/imaging/common/native-image-source-impl.h>
25 #include <extern-definitions.h>
27 namespace Dali::Internal::Adaptor
29 class EglImageExtensions;
32 * Dali internal NativeImageSource.
34 class NativeImageSourceCocoa : public Internal::Adaptor::NativeImageSource
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.
46 static NativeImageSourceCocoa* New(
49 Dali::NativeImageSource::ColorDepth depth,
50 Any nativeImageSource);
53 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
55 Any GetNativeImageSource() const override;
58 * @copydoc Dali::NativeImageSource::GetPixels()
61 std::vector<unsigned char>& pixbuf,
64 Pixel::Format& pixelFormat) const override;
67 * @copydoc Dali::NativeImageSource::SetSource( Any source )
69 void SetSource(Any source) override;
72 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
74 bool IsColorDepthSupported(Dali::NativeImageSource::ColorDepth colorDepth) override;
79 ~NativeImageSourceCocoa() override;
82 * @copydoc Dali::NativeImageSource::CreateResource()
84 bool CreateResource() override;
87 * @copydoc Dali::NativeImageSource::DestroyResource()
89 void DestroyResource() override;
92 * @copydoc Dali::NativeImageSource::TargetTexture()
94 unsigned int TargetTexture() override;
97 * @copydoc Dali::NativeImageSource::PrepareTexture()
99 void PrepareTexture() override;
102 * @copydoc Dali::NativeImageSource::GetWidth()
104 unsigned int GetWidth() const override;
107 * @copydoc Dali::NativeImageSource::GetHeight()
109 unsigned int GetHeight() const override;
112 * @copydoc Dali::NativeImageSource::RequiresBlending()
114 bool RequiresBlending() const override;
117 * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
119 bool ApplyNativeFragmentShader(std::string& shader) override;
122 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
124 const char* GetCustomSamplerTypename() const override;
127 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
129 int GetTextureTarget() const override;
132 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
134 Any GetNativeImageHandle() const override;
137 * @copydoc Dali::NativeImageInterface::SourceChanged()
139 bool SourceChanged() const override;
142 * @copydoc Dali::NativeImageInterface::GetExtension()
144 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
150 * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
152 uint8_t* AcquireBuffer(uint16_t& width, uint16_t& height, uint16_t& stride) override;
155 * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
157 bool ReleaseBuffer() override;
160 * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
162 void SetResourceDestructionCallback(EventThreadCallback* callback) override;
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
172 NativeImageSourceCocoa(
175 Dali::NativeImageSource::ColorDepth depth,
176 Any nativeImageSource);
179 CFRef<CGImageRef> mImage;
180 std::unique_ptr<EventThreadCallback> mResourceDestructionCallback; ///< The Resource Destruction Callback
183 } // namespace Dali::Internal::Adaptor