4f9ff6d63de7112f3414843b648727bad7b0fe4e
[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 EglImageExtensions;
40
41 /**
42  * Dali internal NativeImageSource.
43  */
44 class NativeImageSourceQueueTizen: public Internal::Adaptor::NativeImageSourceQueue, public NativeImageInterface::Extension
45 {
46 public:
47
48   /**
49    * Create a new NativeImageSourceQueueTizen internally.
50    * Depending on hardware the width and height may have to be a power of two.
51    * @param[in] width The width of the image.
52    * @param[in] height The height of the image.
53    * @param[in] depth color depth of the image.
54    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
55    * @return A smart-pointer to a newly allocated image.
56    */
57   static NativeImageSourceQueueTizen* New(unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
58
59   /**
60    * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
61    */
62   Any GetNativeImageSourceQueue() const override;
63
64   /**
65    * @copydoc Dali::NativeImageSourceQueue::SetSource( Any source )
66    */
67   void SetSource( Any source ) override;
68
69   /**
70    * destructor
71    */
72   ~NativeImageSourceQueueTizen() override;
73
74   /**
75    * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
76    */
77   bool GlExtensionCreate() override;
78
79   /**
80    * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
81    */
82   void GlExtensionDestroy() override;
83
84   /**
85    * @copydoc Dali::NativeImageInterface::TargetTexture()
86    */
87   unsigned int TargetTexture() override;
88
89   /**
90    * @copydoc Dali::NativeImageInterface::PrepareTexture()
91    */
92   void PrepareTexture() override;
93
94   /**
95    * @copydoc Dali::NativeImageInterface::GetWidth()
96    */
97   unsigned int GetWidth() const override
98   {
99     return mWidth;
100   }
101
102   /**
103    * @copydoc Dali::NativeImageInterface::GetHeight()
104    */
105   unsigned int GetHeight() const override
106   {
107     return mHeight;
108   }
109
110   /**
111    * @copydoc Dali::NativeImageInterface::RequiresBlending()
112    */
113   bool RequiresBlending() const override
114   {
115     return mBlendingRequired;
116   }
117
118   /**
119    * @copydoc Dali::NativeImageInterface::GetExtension()
120    */
121   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
122   {
123     return this;
124   }
125
126   /**
127    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
128    */
129   const char* GetCustomFragmentPreFix() override;
130
131   /**
132    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
133    */
134   const char* GetCustomSamplerTypename() override;
135
136   /**
137    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
138    */
139   int GetEglImageTextureTarget() override;
140
141   /**
142    * @copydoc Dali::NativeImageInterface::Extension::SetDestructorNotification((void *notification)
143    */
144   void SetDestructorNotification(void* notification) override;
145
146 private:
147
148   /**
149    * Private constructor; @see NativeImageSourceQueue::New()
150    * @param[in] width The width of the image.
151    * @param[in] height The height of the image.
152    * @param[in] colour depth of the image.
153    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
154    */
155   NativeImageSourceQueueTizen( unsigned int width, unsigned int height, Dali::NativeImageSourceQueue::ColorDepth depth, Any nativeImageSourceQueue );
156
157   void Initialize( Dali::NativeImageSourceQueue::ColorDepth depth );
158
159   void DestroyQueue();
160
161   tbm_surface_queue_h GetSurfaceFromAny( Any source ) const;
162
163   bool CheckBlending( int format );
164
165 private:
166
167   typedef std::pair< tbm_surface_h, void* > EglImagePair;
168
169   unsigned int                     mWidth;                ///< image width
170   unsigned int                     mHeight;               ///< image height
171   tbm_surface_queue_h              mTbmQueue;             ///< Tbm surface queue handle
172   tbm_surface_h                    mConsumeSurface;       ///< The current tbm surface
173   std::vector< EglImagePair >      mEglImages;            ///< EGL Image vector
174   EglImageExtensions*              mEglImageExtensions;   ///< The EGL Image Extensions
175   bool                             mOwnTbmQueue;          ///< Whether we created tbm queue
176   bool                             mBlendingRequired;     ///< Whether blending is required
177 };
178
179 } // namespace Adaptor
180
181 } // namespace Internal
182
183 } // namespace Dali
184
185 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H