Dali 3D User Interface Engine
egl-sync-implementation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 // CLASS HEADER
20 
21 // EXTERNAL INCLUDES
22 
23 #ifdef _ARCH_ARM_
24 
25 #include <GLES2/gl2.h>
26 #include <GLES2/gl2ext.h>
27 #include <EGL/eglext.h>
28 
29 #endif
30 
32 
33 // INTERNAL INCLUDES
34 #include <gl/egl-implementation.h>
35 
36 #ifdef _ARCH_ARM_
37 
38 // function pointers
39 static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR = NULL;
40 static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR = NULL;
41 static PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR = NULL;
42 
43 #endif
44 
45 namespace Dali
46 {
47 namespace Internal
48 {
49 namespace Adaptor
50 {
51 
52 #ifdef _ARCH_ARM_
53 
54 EglSyncObject::EglSyncObject( EglImplementation& eglSyncImpl )
55 : mEglSync(NULL),
56  mEglImplementation(eglSyncImpl)
57 {
58  EGLDisplay display = mEglImplementation.GetDisplay();
59  mEglSync = eglCreateSyncKHR( display, EGL_SYNC_FENCE_KHR, NULL );
60  if (mEglSync == EGL_NO_SYNC_KHR)
61  {
62  DALI_LOG_ERROR("eglCreateSyncKHR failed %#0.4x\n", eglGetError());
63  mEglSync = NULL;
64  }
65 }
66 
68 {
69  if( mEglSync != NULL )
70  {
71  eglDestroySyncKHR( mEglImplementation.GetDisplay(), mEglSync );
72  EGLint error = eglGetError();
73  if( EGL_SUCCESS != error )
74  {
75  DALI_LOG_ERROR("eglDestroySyncKHR failed %#0.4x\n", error);
76  }
77  }
78 }
79 
81 {
82  bool synced = false;
83 
84  if( mEglSync != NULL )
85  {
86  EGLint result = eglClientWaitSyncKHR( mEglImplementation.GetDisplay(), mEglSync, 0, 0ull );
87  EGLint error = eglGetError();
88  if( EGL_SUCCESS != error )
89  {
90  DALI_LOG_ERROR("eglClientWaitSyncKHR failed %#0.4x\n", error);
91  }
92  else if( result == EGL_CONDITION_SATISFIED_KHR )
93  {
94  synced = true;
95  }
96  }
97 
98  return synced;
99 }
100 
102 : mEglImplementation( NULL ),
103  mSyncInitialized( false ),
104  mSyncInitializeFailed( false )
105 {
106 }
107 
109 {
110 }
111 
112 void EglSyncImplementation::Initialize( EglImplementation* eglImpl )
113 {
114  mEglImplementation = eglImpl;
115 }
116 
117 Integration::GlSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
118 {
119  DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
120  if( mSyncInitialized == false )
121  {
123  }
124 
125  EglSyncObject* syncObject = new EglSyncObject(*mEglImplementation);
126  mSyncObjects.PushBack( syncObject );
127  return syncObject;
128 }
129 
130 void EglSyncImplementation::DestroySyncObject( Integration::GlSyncAbstraction::SyncObject* syncObject )
131 {
132  DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
133 
134  if( mSyncInitialized == false )
135  {
137  }
138 
139  for( SyncIter iter=mSyncObjects.Begin(), end=mSyncObjects.End(); iter != end; ++iter )
140  {
141  if( *iter == syncObject )
142  {
143  mSyncObjects.Erase(iter);
144  break;
145  }
146  }
147  EglSyncObject* eglSyncObject = static_cast<EglSyncObject*>(syncObject);
148  delete eglSyncObject;
149 }
150 
152 {
153  if( ! mSyncInitializeFailed )
154  {
155  eglCreateSyncKHR = (PFNEGLCREATESYNCKHRPROC)eglGetProcAddress("eglCreateSyncKHR");
156  eglClientWaitSyncKHR = (PFNEGLCLIENTWAITSYNCKHRPROC)eglGetProcAddress("eglClientWaitSyncKHR");
157  eglDestroySyncKHR = (PFNEGLDESTROYSYNCKHRPROC)eglGetProcAddress("eglDestroySyncKHR");
158  }
159 
160  if( eglCreateSyncKHR && eglClientWaitSyncKHR && eglDestroySyncKHR )
161  {
162  mSyncInitialized = true;
163  }
164  else
165  {
166  mSyncInitializeFailed = true;
167  }
168 }
169 
170 #else
171 
173 : mPollCounter(3),
174  mEglImplementation(eglImpl)
175 {
176 }
177 
179 {
180 }
181 
183 {
184  if(mPollCounter <= 0)
185  {
186  return true;
187  }
188  --mPollCounter;
189  return false;
190 }
191 
193 : mEglImplementation( NULL ),
194  mSyncInitialized( false ),
195  mSyncInitializeFailed( false )
196 {
197 }
198 
200 {
201 }
202 
204 {
205  mEglImplementation = eglImpl;
206 }
207 
209 {
210  DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
211  return new EglSyncObject(*mEglImplementation);
212 }
213 
215 {
216  DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
217 
218  // The abstraction's virtual destructor is protected, so that Core can't delete the sync objects
219  // directly (This object also needs removing from the mSyncObject container in the ARM
220  // implementation above). We therefore need to cast to the actual implementation object first.
221  EglSyncObject* eglSyncObject = static_cast<EglSyncObject*>(syncObject);
222  delete eglSyncObject;
223 }
224 
226 {
227 }
228 
229 #endif
230 
231 } // namespace Dali
232 } // namespace Internal
233 } // namespace Adaptor
Dali Docs Home
Read more about Dali