Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / tizen / native-image-source-queue-impl-tizen.h
1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/images/native-image-interface-extension.h>
23 #include <dali/devel-api/threading/mutex.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <tbm_surface.h>
26 #include <tbm_surface_queue.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 class EglGraphics;
41 class EglImageExtensions;
42
43 /**
44  * Dali internal NativeImageSource.
45  */
46 class NativeImageSourceQueueTizen: public Internal::Adaptor::NativeImageSourceQueue, public NativeImageInterface::Extension
47 {
48 public:
49
50   /**
51    * Create a new NativeImageSourceQueueTizen internally.
52    * Depending on hardware the width and height may have to be a power of two.
53    * @param[in] width The width of the image.
54    * @param[in] height The height of the image.
55    * @param[in] depth color depth of the image.
56    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
57    * @return A smart-pointer to a newly allocated image.
58    */
59   static NativeImageSourceQueueTizen* New( uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
60
61   /**
62    * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
63    */
64   Any GetNativeImageSourceQueue() const override;
65
66   /**
67    * @copydoc Dali::NativeImageSourceQueue::SetSize
68    */
69   void SetSize( uint32_t width, uint32_t height ) override;
70
71   /**
72    * @copydoc Dali::NativeImageSourceQueue::IgnoreSourceImage
73    */
74   void IgnoreSourceImage() override;
75
76   /**
77    * destructor
78    */
79   ~NativeImageSourceQueueTizen() override;
80
81   /**
82    * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
83    */
84   bool GlExtensionCreate() override;
85
86   /**
87    * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
88    */
89   void GlExtensionDestroy() override;
90
91   /**
92    * @copydoc Dali::NativeImageInterface::TargetTexture()
93    */
94   uint32_t TargetTexture() override;
95
96   /**
97    * @copydoc Dali::NativeImageInterface::PrepareTexture()
98    */
99   void PrepareTexture() override;
100
101   /**
102    * @copydoc Dali::NativeImageInterface::GetWidth()
103    */
104   uint32_t GetWidth() const override
105   {
106     return mWidth;
107   }
108
109   /**
110    * @copydoc Dali::NativeImageInterface::GetHeight()
111    */
112   uint32_t GetHeight() const override
113   {
114     return mHeight;
115   }
116
117   /**
118    * @copydoc Dali::NativeImageInterface::RequiresBlending()
119    */
120   bool RequiresBlending() const override
121   {
122     return mBlendingRequired;
123   }
124
125   /**
126    * @copydoc Dali::NativeImageInterface::GetExtension()
127    */
128   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
129   {
130     return this;
131   }
132
133   /**
134    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
135    */
136   const char* GetCustomFragmentPreFix() override;
137
138   /**
139    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
140    */
141   const char* GetCustomSamplerTypename() override;
142
143   /**
144    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
145    */
146   int GetEglImageTextureTarget() override;
147
148 private:
149
150   /**
151    * Private constructor; @see NativeImageSourceQueue::New()
152    * @param[in] width The width of the image.
153    * @param[in] height The height of the image.
154    * @param[in] colour depth of the image.
155    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
156    */
157   NativeImageSourceQueueTizen( uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
158
159   void Initialize( Dali::NativeImageSourceQueue::ColorDepth depth );
160
161   void ResetEglImageList();
162
163   tbm_surface_queue_h GetSurfaceFromAny( Any source ) const;
164
165   bool CheckBlending( int format );
166
167 private:
168
169   typedef std::pair< tbm_surface_h, void* > EglImagePair;
170
171   Dali::Mutex                      mMutex;                ///< Mutex
172   uint32_t                         mWidth;                ///< image width
173   uint32_t                         mHeight;               ///< image height
174   tbm_surface_queue_h              mTbmQueue;             ///< Tbm surface queue handle
175   tbm_surface_h                    mConsumeSurface;       ///< The current tbm surface
176   std::vector< EglImagePair >      mEglImages;            ///< EGL Image vector
177   EglGraphics*                     mEglGraphics;          ///< EGL Graphics
178   EglImageExtensions*              mEglImageExtensions;   ///< The EGL Image Extensions
179   bool                             mOwnTbmQueue;          ///< Whether we created tbm queue
180   bool                             mBlendingRequired;     ///< Whether blending is required
181 };
182
183 } // namespace Adaptor
184
185 } // namespace Internal
186
187 } // namespace Dali
188
189 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H