f01b98ad1c72965270ca8b82b778e7b475436f6a
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / common / gl / egl-sync-implementation.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_EGL_SYNC_IMPLEMENTATION_H__
2 #define __DALI_INTERNAL_ADAPTOR_EGL_SYNC_IMPLEMENTATION_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/integration-api/gl-sync-abstraction.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Adaptor
31 {
32 class EglImplementation;
33
34 class EglSyncObject : public Integration::GlSyncAbstraction::SyncObject
35 {
36 public:
37   /**
38    * Constructor
39    */
40   EglSyncObject( EglImplementation& eglSyncImpl );
41
42   /**
43    * Destructor
44    */
45   virtual ~EglSyncObject();
46
47   /**
48    * @copydoc Dali::Integration::GlSyncAbstraction::SyncObject::IsSynced()
49    */
50   virtual bool IsSynced();
51
52 private:
53 #ifdef _ARCH_ARM_
54   EGLSyncKHR mEglSync;
55 #else
56   int mPollCounter; // Implementations without fence sync use a 3 frame counter
57 #endif
58   EglImplementation& mEglImplementation;
59 };
60
61
62 /**
63  * GlSyncImplementation is a concrete implementation for GlSyncAbstraction.
64  * It provides fence syncing for resources such as FrameBuffers using EGL extensions
65  *
66  * Sync objects are created in the render thread after a render instruction
67  * has been processed (i.e. GL draw calls have completed for a given FB), and
68  * tested in the update
69  */
70 class EglSyncImplementation : public Integration::GlSyncAbstraction
71 {
72 public:
73   /**
74    * Constructor
75    */
76   EglSyncImplementation();
77
78   /**
79    * Destructor
80    */
81   virtual ~EglSyncImplementation();
82
83   /**
84    * Initialize the sync object with the Egl implementation.
85    * @param[in] impl The EGL implementation (to access display)
86    */
87   void Initialize( EglImplementation* impl );
88
89   /**
90    * @copydoc Dali::Integration::GlSyncAbstraction::CreateSyncObject()
91    */
92   virtual SyncObject* CreateSyncObject();
93
94   /**
95    * @copydoc Dali::Integration::GlSyncAbstraction::DestroySyncObject()
96    */
97   virtual void DestroySyncObject(SyncObject* syncObject);
98
99 private:
100   /**
101    * Set up the function pointers
102    */
103   void InitializeEglSync();
104
105 private:
106   typedef Vector<EglSyncObject*>   SyncContainer;
107   typedef SyncContainer::Iterator  SyncIter;
108
109   EglImplementation* mEglImplementation; ///< Egl implementation (to get display)
110   bool mSyncInitialized;        ///< Flag to perform initialization on first use
111   bool mSyncInitializeFailed;   ///< Flag to avoid reloading functions if failed once
112
113   SyncContainer mSyncObjects;
114 };
115
116 } // namespace Adaptor
117 } // namespace Internal
118 } // namespace Dali
119
120 #endif // __DALI_INTERNAL_EGL_ADAPTOR_SYNC_IMPLEMENTATION_H__