Updates for NativeImageInterface
[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/threading/mutex.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <tbm_surface.h>
25 #include <tbm_surface_queue.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 class EglGraphics;
40 class EglImageExtensions;
41
42 /**
43  * Dali internal NativeImageSource.
44  */
45 class NativeImageSourceQueueTizen: public Internal::Adaptor::NativeImageSourceQueue
46 {
47 public:
48
49   /**
50    * Create a new NativeImageSourceQueueTizen internally.
51    * Depending on hardware the width and height may have to be a power of two.
52    * @param[in] width The width of the image.
53    * @param[in] height The height of the image.
54    * @param[in] depth color depth of the image.
55    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
56    * @return A smart-pointer to a newly allocated image.
57    */
58   static NativeImageSourceQueueTizen* New( uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
59
60   /**
61    * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
62    */
63   Any GetNativeImageSourceQueue() const override;
64
65   /**
66    * @copydoc Dali::NativeImageSourceQueue::SetSize
67    */
68   void SetSize( uint32_t width, uint32_t height ) override;
69
70   /**
71    * @copydoc Dali::NativeImageSourceQueue::IgnoreSourceImage
72    */
73   void IgnoreSourceImage() override;
74
75   /**
76    * destructor
77    */
78   ~NativeImageSourceQueueTizen() override;
79
80   /**
81    * @copydoc Dali::NativeImageInterface::CreateResource
82    */
83   bool CreateResource() override;
84
85   /**
86    * @copydoc Dali::NativeImageInterface::DestroyResource()
87    */
88   void DestroyResource() override;
89
90   /**
91    * @copydoc Dali::NativeImageInterface::TargetTexture()
92    */
93   uint32_t TargetTexture() override;
94
95   /**
96    * @copydoc Dali::NativeImageInterface::PrepareTexture()
97    */
98   void PrepareTexture() override;
99
100   /**
101    * @copydoc Dali::NativeImageInterface::GetWidth()
102    */
103   uint32_t GetWidth() const override
104   {
105     return mWidth;
106   }
107
108   /**
109    * @copydoc Dali::NativeImageInterface::GetHeight()
110    */
111   uint32_t GetHeight() const override
112   {
113     return mHeight;
114   }
115
116   /**
117    * @copydoc Dali::NativeImageInterface::RequiresBlending()
118    */
119   bool RequiresBlending() const override
120   {
121     return mBlendingRequired;
122   }
123
124   /**
125    * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
126    */
127   const char* GetCustomFragmentPrefix() const override;
128
129   /**
130    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
131    */
132   const char* GetCustomSamplerTypename() const override;
133
134   /**
135    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
136    */
137   int GetTextureTarget() const override;
138
139   /**
140    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
141    */
142   Any GetNativeImageHandle() const override;
143
144   /**
145    * @copydoc Dali::NativeImageInterface::SourceChanged()
146    */
147   bool SourceChanged() const override;
148
149   /**
150    * @copydoc Dali::NativeImageInterface::GetExtension()
151    */
152   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
153   {
154     return nullptr;
155   }
156
157 private:
158
159   /**
160    * Private constructor; @see NativeImageSourceQueue::New()
161    * @param[in] width The width of the image.
162    * @param[in] height The height of the image.
163    * @param[in] colour depth of the image.
164    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
165    */
166   NativeImageSourceQueueTizen( uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
167
168   void Initialize( Dali::NativeImageSourceQueue::ColorDepth depth );
169
170   void ResetEglImageList();
171
172   tbm_surface_queue_h GetSurfaceFromAny( Any source ) const;
173
174   bool CheckBlending( int format );
175
176 private:
177
178   typedef std::pair< tbm_surface_h, void* > EglImagePair;
179
180   Dali::Mutex                      mMutex;                ///< Mutex
181   uint32_t                         mWidth;                ///< image width
182   uint32_t                         mHeight;               ///< image height
183   tbm_surface_queue_h              mTbmQueue;             ///< Tbm surface queue handle
184   tbm_surface_h                    mConsumeSurface;       ///< The current tbm surface
185   std::vector< EglImagePair >      mEglImages;            ///< EGL Image vector
186   EglGraphics*                     mEglGraphics;          ///< EGL Graphics
187   EglImageExtensions*              mEglImageExtensions;   ///< The EGL Image Extensions
188   bool                             mOwnTbmQueue;          ///< Whether we created tbm queue
189   bool                             mBlendingRequired;     ///< Whether blending is required
190 };
191
192 } // namespace Adaptor
193
194 } // namespace Internal
195
196 } // namespace Dali
197
198 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H