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::GraphicsSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
118 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
119 if(mSyncInitialized == false)
124 auto* syncObject = new EglSyncObject(*mEglImplementation);
125 mSyncObjects.PushBack(syncObject);
129 void EglSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::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 delete static_cast<EglSyncObject*>(syncObject);
149 void EglSyncImplementation::InitializeEglSync()
151 if(!mSyncInitializeFailed)
153 eglCreateSyncKHR = reinterpret_cast<PFNEGLCREATESYNCKHRPROC>(eglGetProcAddress("eglCreateSyncKHR"));
154 eglClientWaitSyncKHR = reinterpret_cast<PFNEGLCLIENTWAITSYNCKHRPROC>(eglGetProcAddress("eglClientWaitSyncKHR"));
155 eglDestroySyncKHR = reinterpret_cast<PFNEGLDESTROYSYNCKHRPROC>(eglGetProcAddress("eglDestroySyncKHR"));
158 if(eglCreateSyncKHR && eglClientWaitSyncKHR && eglDestroySyncKHR)
160 mSyncInitialized = true;
164 mSyncInitializeFailed = true;
170 EglSyncObject::EglSyncObject(EglImplementation& eglImpl)
172 mEglImplementation(eglImpl)
176 EglSyncObject::~EglSyncObject()
180 bool EglSyncObject::IsSynced()
182 if(mPollCounter <= 0)
190 EglSyncImplementation::EglSyncImplementation()
191 : mEglImplementation(NULL),
192 mSyncInitialized(false),
193 mSyncInitializeFailed(false)
197 EglSyncImplementation::~EglSyncImplementation()
201 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)
203 mEglImplementation = eglImpl;
206 Integration::GraphicsSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
208 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
209 return new EglSyncObject(*mEglImplementation);
212 void EglSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::SyncObject* syncObject)
214 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
215 delete static_cast<EglSyncObject*>(syncObject);
218 void EglSyncImplementation::InitializeEglSync()
224 } // namespace Adaptor
225 } // namespace Internal