2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
25 #include <GLES2/gl2.h>
26 #include <GLES2/gl2ext.h>
27 #include <EGL/eglext.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali/internal/graphics/gles/egl-implementation.h>
39 static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR = NULL;
40 static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR = NULL;
41 static PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR = NULL;
54 EglSyncObject::EglSyncObject( EglImplementation& eglSyncImpl )
56 mEglImplementation(eglSyncImpl)
58 EGLDisplay display = mEglImplementation.GetDisplay();
59 mEglSync = eglCreateSyncKHR( display, EGL_SYNC_FENCE_KHR, NULL );
60 if (mEglSync == EGL_NO_SYNC_KHR)
62 DALI_LOG_ERROR("eglCreateSyncKHR failed %#0.4x\n", eglGetError());
67 EglSyncObject::~EglSyncObject()
69 if( mEglSync != NULL )
71 eglDestroySyncKHR( mEglImplementation.GetDisplay(), mEglSync );
72 EGLint error = eglGetError();
73 if( EGL_SUCCESS != error )
75 DALI_LOG_ERROR("eglDestroySyncKHR failed %#0.4x\n", error);
80 bool EglSyncObject::IsSynced()
84 if( mEglSync != NULL )
86 EGLint result = eglClientWaitSyncKHR( mEglImplementation.GetDisplay(), mEglSync, 0, 0ull );
87 EGLint error = eglGetError();
88 if( EGL_SUCCESS != error )
90 DALI_LOG_ERROR("eglClientWaitSyncKHR failed %#0.4x\n", error);
92 else if( result == EGL_CONDITION_SATISFIED_KHR )
101 EglSyncImplementation::EglSyncImplementation()
102 : mEglImplementation( NULL ),
103 mSyncInitialized( false ),
104 mSyncInitializeFailed( false )
108 EglSyncImplementation::~EglSyncImplementation()
112 void EglSyncImplementation::Initialize( EglImplementation* eglImpl )
114 mEglImplementation = eglImpl;
117 Integration::GlSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
119 DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
120 if( mSyncInitialized == false )
125 EglSyncObject* syncObject = new EglSyncObject(*mEglImplementation);
126 mSyncObjects.PushBack( syncObject );
130 void EglSyncImplementation::DestroySyncObject( Integration::GlSyncAbstraction::SyncObject* syncObject )
132 DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
134 if( mSyncInitialized == false )
139 for( SyncIter iter=mSyncObjects.Begin(), end=mSyncObjects.End(); iter != end; ++iter )
141 if( *iter == syncObject )
143 mSyncObjects.Erase(iter);
147 EglSyncObject* eglSyncObject = static_cast<EglSyncObject*>(syncObject);
148 delete eglSyncObject;
151 void EglSyncImplementation::InitializeEglSync()
153 if( ! mSyncInitializeFailed )
155 eglCreateSyncKHR = reinterpret_cast< PFNEGLCREATESYNCKHRPROC >( eglGetProcAddress("eglCreateSyncKHR") );
156 eglClientWaitSyncKHR = reinterpret_cast< PFNEGLCLIENTWAITSYNCKHRPROC >( eglGetProcAddress("eglClientWaitSyncKHR") );
157 eglDestroySyncKHR = reinterpret_cast< PFNEGLDESTROYSYNCKHRPROC >( eglGetProcAddress("eglDestroySyncKHR") );
160 if( eglCreateSyncKHR && eglClientWaitSyncKHR && eglDestroySyncKHR )
162 mSyncInitialized = true;
166 mSyncInitializeFailed = true;
172 EglSyncObject::EglSyncObject( EglImplementation& eglImpl )
174 mEglImplementation(eglImpl)
178 EglSyncObject::~EglSyncObject()
182 bool EglSyncObject::IsSynced()
184 if(mPollCounter <= 0)
192 EglSyncImplementation::EglSyncImplementation()
193 : mEglImplementation( NULL ),
194 mSyncInitialized( false ),
195 mSyncInitializeFailed( false )
199 EglSyncImplementation::~EglSyncImplementation()
203 void EglSyncImplementation::Initialize( EglImplementation* eglImpl )
205 mEglImplementation = eglImpl;
208 Integration::GlSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
210 DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
211 return new EglSyncObject(*mEglImplementation);
214 void EglSyncImplementation::DestroySyncObject(Integration::GlSyncAbstraction::SyncObject* syncObject)
216 DALI_ASSERT_ALWAYS( mEglImplementation && "Sync Implementation not initialized" );
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;
225 void EglSyncImplementation::InitializeEglSync()
232 } // namespace Internal
233 } // namespace Adaptor