5aa92624bb5a3b101af2bbb7f928907739564685
[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-impl.h>
26 #include <dali/internal/imaging/common/native-image-source-factory.h>
27
28 namespace Dali
29 {
30
31 NativeImageSourcePtr NativeImageSource::New( unsigned int width, unsigned int height, ColorDepth depth )
32 {
33   Any empty;
34   NativeImageSourcePtr image = new NativeImageSource( width, height, depth, empty );
35   return image;
36 }
37
38 Any NativeImageSource::GetNativeImageSource()
39 {
40   return mImpl->GetNativeImageSource();
41 }
42
43 NativeImageSourcePtr NativeImageSource::New( Any nativeImageSource )
44 {
45   NativeImageSourcePtr image = new NativeImageSource(0, 0, COLOR_DEPTH_DEFAULT, nativeImageSource);
46   return image;
47 }
48
49 bool NativeImageSource::GetPixels( std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const
50 {
51   return mImpl->GetPixels( pixbuf, width, height, pixelFormat );
52 }
53
54 bool NativeImageSource::EncodeToFile(const std::string& filename) const
55 {
56   return mImpl->EncodeToFile( filename );
57 }
58
59 void NativeImageSource::SetSource( Any source )
60 {
61   mImpl->SetSource( source );
62 }
63
64 bool NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
65 {
66   return mImpl->IsColorDepthSupported( colorDepth );
67 }
68
69 bool NativeImageSource::GlExtensionCreate()
70 {
71   return mImpl->GlExtensionCreate();
72 }
73
74 void NativeImageSource::GlExtensionDestroy()
75 {
76   mImpl->GlExtensionDestroy();
77 }
78
79 unsigned int NativeImageSource::TargetTexture()
80 {
81   return mImpl->TargetTexture();
82 }
83
84 void NativeImageSource::PrepareTexture()
85 {
86   mImpl->PrepareTexture();
87 }
88
89 unsigned int NativeImageSource::GetWidth() const
90 {
91   return mImpl->GetWidth();
92 }
93
94 unsigned int NativeImageSource::GetHeight() const
95 {
96   return mImpl->GetHeight();
97 }
98
99 bool NativeImageSource::RequiresBlending() const
100 {
101   return mImpl->RequiresBlending();
102 }
103
104 NativeImageInterface::Extension* NativeImageSource::GetExtension()
105 {
106   return mImpl->GetNativeImageInterfaceExtension();
107 }
108
109 NativeImageSource::NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource )
110 {
111   auto factory = Dali::Internal::Adaptor::GetNativeImageSourceFactory();
112   mImpl = factory->CreateNativeImageSource( width, height, depth, nativeImageSource ).release();
113 }
114
115 NativeImageSource::~NativeImageSource()
116 {
117   delete mImpl;
118 }
119
120 } // namespace Dali