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