2 * Copyright (c) 2024 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>
23 #include <dali/integration-api/debug.h>
26 #include <dali/internal/graphics/gles/egl-debug.h>
27 #include <dali/internal/graphics/gles/egl-implementation.h>
29 #if defined(DEBUG_ENABLED)
30 Debug::Filter* gLogSyncFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FENCE_SYNC");
39 EglSyncObject::EglSyncObject(EglImplementation& eglImpl)
41 mEglImplementation(eglImpl)
43 EGLDisplay display = mEglImplementation.GetDisplay();
44 mEglSync = eglCreateSync(display, EGL_SYNC_FENCE, NULL);
47 EglSyncObject::~EglSyncObject()
49 if(mEglSync && mEglImplementation.IsGlesInitialized())
51 EGLDisplay display = mEglImplementation.GetDisplay();
52 eglDestroySync(display, mEglSync);
56 bool EglSyncObject::IsSynced()
58 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync\n");
59 auto result = eglClientWaitSync(mEglImplementation.GetDisplay(), mEglSync, 0 | EGL_SYNC_FLUSH_COMMANDS_BIT, 0);
61 if(result == EGL_FALSE)
63 EGLint error = eglGetError();
64 if(EGL_SUCCESS != error)
66 DALI_LOG_ERROR("eglClientSyncWait failed: %#0.4x\n", error);
69 else if(result == EGL_CONDITION_SATISFIED)
71 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync Synced!\n");
74 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync not synced :(\n");
78 void EglSyncObject::Wait()
80 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglWaitSync\n");
81 if(!eglWaitSync(mEglImplementation.GetDisplay(), mEglSync, 0))
83 EGLint error = eglGetError();
84 if(EGL_SUCCESS != error)
86 DALI_LOG_ERROR("eglSyncWait failed: %#0.4x\n", error);
91 void EglSyncObject::ClientWait()
93 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglWaitSync (blocking)\n");
94 auto result = eglClientWaitSync(mEglImplementation.GetDisplay(), mEglSync, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER);
95 if(result == EGL_FALSE)
97 EGLint error = eglGetError();
98 if(EGL_SUCCESS != error)
100 DALI_LOG_ERROR("eglSyncWait failed: %#0.4x\n", error);
103 else if(result == EGL_CONDITION_SATISFIED)
105 DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync Synced!\n");
109 EglSyncImplementation::EglSyncImplementation()
110 : mEglImplementation(NULL),
111 mSyncInitialized(false),
112 mSyncInitializeFailed(false)
116 EglSyncImplementation::~EglSyncImplementation()
120 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)
122 mEglImplementation = eglImpl;
125 Integration::GraphicsSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
127 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
128 return new EglSyncObject(*mEglImplementation);
131 void EglSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::SyncObject* syncObject)
133 DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
134 delete static_cast<EglSyncObject*>(syncObject);
137 void EglSyncImplementation::InitializeEglSync()
141 } // namespace Adaptor
142 } // namespace Internal