2 * Copyright (c) 2021 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 <EGL/eglext.h>
26 #include <GLES2/gl2.h>
27 #include <GLES2/gl2ext.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;
53 EglSyncObject::EglSyncObject(EglImplementation& eglSyncImpl)
55 mEglImplementation(eglSyncImpl)
57 EGLDisplay display = mEglImplementation.GetDisplay();
58 mEglSync = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
59 if(mEglSync == EGL_NO_SYNC_KHR)
61 DALI_LOG_ERROR("eglCreateSyncKHR failed %#0.4x\n", eglGetError());
66 EglSyncObject::~EglSyncObject()
70 eglDestroySyncKHR(mEglImplementation.GetDisplay(), mEglSync);
71 EGLint error = eglGetError();
72 if(EGL_SUCCESS != error)
74 DALI_LOG_ERROR("eglDestroySyncKHR failed %#0.4x\n", error);
79 bool EglSyncObject::IsSynced()
85 EGLint result = eglClientWaitSyncKHR(mEglImplementation.GetDisplay(), mEglSync, 0, 0ull);
86 EGLint error = eglGetError();
87 if(EGL_SUCCESS != error)
89 DALI_LOG_ERROR("eglClientWaitSyncKHR failed %#0.4x\n", error);
91 else if(result == EGL_CONDITION_SATISFIED_KHR)
100 EglSyncImplementation::EglSyncImplementation()
101 : mEglImplementation(NULL),
102 mSyncInitialized(false),
103 mSyncInitializeFailed(false)
107 EglSyncImplementation::~EglSyncImplementation()
111 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)
113 mEglImplementation = eglImpl;
116 Integration::GlSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
118 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
119 if(mSyncInitialized == false)
124 EglSyncObject* syncObject = new EglSyncObject(*mEglImplementation);
125 mSyncObjects.PushBack(syncObject);
129 void EglSyncImplementation::DestroySyncObject(Integration::GlSyncAbstraction::SyncObject* syncObject)
131 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
133 if(mSyncInitialized == false)
138 for(SyncIter iter = mSyncObjects.Begin(), end = mSyncObjects.End(); iter != end; ++iter)
140 if(*iter == syncObject)
142 mSyncObjects.Erase(iter);
146 EglSyncObject* eglSyncObject = static_cast<EglSyncObject*>(syncObject);
147 delete eglSyncObject;
150 void EglSyncImplementation::InitializeEglSync()
152 if(!mSyncInitializeFailed)
154 eglCreateSyncKHR = reinterpret_cast<PFNEGLCREATESYNCKHRPROC>(eglGetProcAddress("eglCreateSyncKHR"));
155 eglClientWaitSyncKHR = reinterpret_cast<PFNEGLCLIENTWAITSYNCKHRPROC>(eglGetProcAddress("eglClientWaitSyncKHR"));
156 eglDestroySyncKHR = reinterpret_cast<PFNEGLDESTROYSYNCKHRPROC>(eglGetProcAddress("eglDestroySyncKHR"));
159 if(eglCreateSyncKHR && eglClientWaitSyncKHR && eglDestroySyncKHR)
161 mSyncInitialized = true;
165 mSyncInitializeFailed = true;
171 EglSyncObject::EglSyncObject(EglImplementation& eglImpl)
173 mEglImplementation(eglImpl)
177 EglSyncObject::~EglSyncObject()
181 bool EglSyncObject::IsSynced()
183 if(mPollCounter <= 0)
191 EglSyncImplementation::EglSyncImplementation()
192 : mEglImplementation(NULL),
193 mSyncInitialized(false),
194 mSyncInitializeFailed(false)
198 EglSyncImplementation::~EglSyncImplementation()
202 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)
204 mEglImplementation = eglImpl;
207 Integration::GlSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
209 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
210 return new EglSyncObject(*mEglImplementation);
213 void EglSyncImplementation::DestroySyncObject(Integration::GlSyncAbstraction::SyncObject* syncObject)
215 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
217 // The abstraction's virtual destructor is protected, so that Core can't delete the sync objects
218 // directly (This object also needs removing from the mSyncObject container in the ARM
219 // implementation above). We therefore need to cast to the actual implementation object first.
220 EglSyncObject* eglSyncObject = static_cast<EglSyncObject*>(syncObject);
221 delete eglSyncObject;
224 void EglSyncImplementation::InitializeEglSync()
230 } // namespace Adaptor
231 } // namespace Internal