Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / native-image-source.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/adaptor-framework/native-image-source.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/any.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/imaging/common/native-image-source-factory.h>
26 #include <dali/internal/imaging/common/native-image-source-impl.h>
27
28 namespace Dali
29 {
30 NativeImageSourcePtr NativeImageSource::New(unsigned int width, unsigned int height, ColorDepth depth)
31 {
32   Any                  empty;
33   NativeImageSourcePtr image = new NativeImageSource(width, height, depth, empty);
34   return image;
35 }
36
37 Any NativeImageSource::GetNativeImageSource()
38 {
39   return mImpl->GetNativeImageSource();
40 }
41
42 NativeImageSourcePtr NativeImageSource::New(Any nativeImageSource)
43 {
44   NativeImageSourcePtr image = new NativeImageSource(0, 0, COLOR_DEPTH_DEFAULT, nativeImageSource);
45   return image;
46 }
47
48 bool NativeImageSource::GetPixels(std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat) const
49 {
50   return mImpl->GetPixels(pixbuf, width, height, pixelFormat);
51 }
52
53 bool NativeImageSource::EncodeToFile(const std::string& filename) const
54 {
55   return mImpl->EncodeToFile(filename);
56 }
57
58 void NativeImageSource::SetSource(Any source)
59 {
60   mImpl->SetSource(source);
61 }
62
63 bool NativeImageSource::IsColorDepthSupported(ColorDepth colorDepth)
64 {
65   return mImpl->IsColorDepthSupported(colorDepth);
66 }
67
68 bool NativeImageSource::CreateResource()
69 {
70   return mImpl->CreateResource();
71 }
72
73 void NativeImageSource::DestroyResource()
74 {
75   mImpl->DestroyResource();
76 }
77
78 unsigned int NativeImageSource::TargetTexture()
79 {
80   return mImpl->TargetTexture();
81 }
82
83 void NativeImageSource::PrepareTexture()
84 {
85   mImpl->PrepareTexture();
86 }
87
88 unsigned int NativeImageSource::GetWidth() const
89 {
90   return mImpl->GetWidth();
91 }
92
93 unsigned int NativeImageSource::GetHeight() const
94 {
95   return mImpl->GetHeight();
96 }
97
98 bool NativeImageSource::RequiresBlending() const
99 {
100   return mImpl->RequiresBlending();
101 }
102
103 int NativeImageSource::GetTextureTarget() const
104 {
105   return mImpl->GetTextureTarget();
106 }
107
108 const char* NativeImageSource::GetCustomFragmentPrefix() const
109 {
110   return mImpl->GetCustomFragmentPrefix();
111 }
112
113 const char* NativeImageSource::GetCustomSamplerTypename() const
114 {
115   return mImpl->GetCustomSamplerTypename();
116 }
117
118 Any NativeImageSource::GetNativeImageHandle() const
119 {
120   return mImpl->GetNativeImageHandle();
121 }
122
123 bool NativeImageSource::SourceChanged() const
124 {
125   return mImpl->SourceChanged();
126 }
127
128 NativeImageInterface::Extension* NativeImageSource::GetExtension()
129 {
130   return mImpl->GetNativeImageInterfaceExtension();
131 }
132
133 NativeImageSource::NativeImageSource(unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource)
134 {
135   auto factory = Dali::Internal::Adaptor::GetNativeImageSourceFactory();
136   mImpl        = factory->CreateNativeImageSource(width, height, depth, nativeImageSource).release();
137 }
138
139 NativeImageSource::~NativeImageSource()
140 {
141   delete mImpl;
142 }
143
144 } // namespace Dali