28f77cd12a4ef08fda39a74deb81510eaf33dcd4
[platform/core/uifw/dali-adaptor.git] / adaptors / 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/public-api/common/vector-wrapper.h>
24 #include <tbm_surface.h>
25 #include <tbm_surface_queue.h>
26
27 // INTERNAL INCLUDES
28 #include <native-image-source-queue-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 class EglFactory;
40 class EglImageExtensions;
41
42 /**
43  * Dali internal NativeImageSource.
44  */
45 class NativeImageSourceQueueTizen: public Internal::Adaptor::NativeImageSourceQueue, public NativeImageInterface::Extension
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(unsigned int width, unsigned int 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::SetSource( Any source )
67    */
68   void SetSource( Any source ) override;
69
70   /**
71    * destructor
72    */
73   ~NativeImageSourceQueueTizen() override;
74
75   /**
76    * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
77    */
78   bool GlExtensionCreate() override;
79
80   /**
81    * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
82    */
83   void GlExtensionDestroy() override;
84
85   /**
86    * @copydoc Dali::NativeImageInterface::TargetTexture()
87    */
88   unsigned int TargetTexture() override;
89
90   /**
91    * @copydoc Dali::NativeImageInterface::PrepareTexture()
92    */
93   void PrepareTexture() override;
94
95   /**
96    * @copydoc Dali::NativeImageInterface::GetWidth()
97    */
98   unsigned int GetWidth() const override
99   {
100     return mWidth;
101   }
102
103   /**
104    * @copydoc Dali::NativeImageInterface::GetHeight()
105    */
106   unsigned int GetHeight() const override
107   {
108     return mHeight;
109   }
110
111   /**
112    * @copydoc Dali::NativeImageInterface::RequiresBlending()
113    */
114   bool RequiresBlending() const override
115   {
116     return mBlendingRequired;
117   }
118
119   /**
120    * @copydoc Dali::NativeImageInterface::GetExtension()
121    */
122   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
123   {
124     return this;
125   }
126
127   /**
128    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
129    */
130   const char* GetCustomFragmentPreFix() override;
131
132   /**
133    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
134    */
135   const char* GetCustomSamplerTypename() override;
136
137   /**
138    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
139    */
140   int GetEglImageTextureTarget() override;
141
142   /**
143    * @copydoc Dali::NativeImageInterface::Extension::SetDestructorNotification((void *notification)
144    */
145   void SetDestructorNotification(void* notification) override;
146
147 private:
148
149   /**
150    * Private constructor; @see NativeImageSourceQueue::New()
151    * @param[in] width The width of the image.
152    * @param[in] height The height of the image.
153    * @param[in] colour depth of the image.
154    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
155    */
156   NativeImageSourceQueueTizen( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
157
158   void Initialize( Dali::NativeImageSourceQueue::ColorDepth depth );
159
160   void DestroyQueue();
161
162   tbm_surface_queue_h GetSurfaceFromAny( Any source ) const;
163
164   bool CheckBlending( int format );
165
166 private:
167
168   typedef std::pair< tbm_surface_h, void* > EglImagePair;
169
170   unsigned int                     mWidth;                ///< image width
171   unsigned int                     mHeight;               ///< image height
172   tbm_surface_queue_h              mTbmQueue;             ///< Tbm surface queue handle
173   tbm_surface_h                    mConsumeSurface;       ///< The current tbm surface
174   std::vector< EglImagePair >      mEglImages;            ///< EGL Image vector
175   EglFactory*                      mEglFactory;           ///< EGL Factory
176   EglImageExtensions*              mEglImageExtensions;   ///< The EGL Image Extensions
177   bool                             mOwnTbmQueue;          ///< Whether we created tbm queue
178   bool                             mBlendingRequired;     ///< Whether blending is required
179 };
180
181 } // namespace Adaptor
182
183 } // namespace Internal
184
185 } // namespace Dali
186
187 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H