[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / generic / egl-sync-implementation.cpp
1 /*
2  * Copyright (c) 2024 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
19 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
20
21 // EXTERNAL INCLUDES
22
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/graphics/gles/egl-debug.h>
27 #include <dali/internal/graphics/gles/egl-implementation.h>
28
29 #if defined(DEBUG_ENABLED)
30 Debug::Filter* gLogSyncFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_FENCE_SYNC");
31 #endif
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace Adaptor
38 {
39 EglSyncObject::EglSyncObject(EglImplementation& eglImpl)
40 : mPollCounter(3),
41   mEglImplementation(eglImpl)
42 {
43   EGLDisplay display = mEglImplementation.GetDisplay();
44   mEglSync           = eglCreateSync(display, EGL_SYNC_FENCE, NULL);
45 }
46
47 EglSyncObject::~EglSyncObject()
48 {
49   if(mEglSync && mEglImplementation.IsGlesInitialized())
50   {
51     EGLDisplay display = mEglImplementation.GetDisplay();
52     eglDestroySync(display, mEglSync);
53   }
54 }
55
56 bool EglSyncObject::IsSynced()
57 {
58   DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync\n");
59   auto result = eglClientWaitSync(mEglImplementation.GetDisplay(), mEglSync, 0 | EGL_SYNC_FLUSH_COMMANDS_BIT, 0);
60
61   if(result == EGL_FALSE)
62   {
63     EGLint error = eglGetError();
64     if(EGL_SUCCESS != error)
65     {
66       DALI_LOG_ERROR("eglClientSyncWait failed: %#0.4x\n", error);
67     }
68   }
69   else if(result == EGL_CONDITION_SATISFIED)
70   {
71     DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync Synced!\n");
72     return true;
73   }
74   DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync not synced :(\n");
75   return false;
76 }
77
78 void EglSyncObject::Wait()
79 {
80   DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglWaitSync\n");
81   if(!eglWaitSync(mEglImplementation.GetDisplay(), mEglSync, 0))
82   {
83     EGLint error = eglGetError();
84     if(EGL_SUCCESS != error)
85     {
86       DALI_LOG_ERROR("eglSyncWait failed: %#0.4x\n", error);
87     }
88   }
89 }
90
91 void EglSyncObject::ClientWait()
92 {
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)
96   {
97     EGLint error = eglGetError();
98     if(EGL_SUCCESS != error)
99     {
100       DALI_LOG_ERROR("eglSyncWait failed: %#0.4x\n", error);
101     }
102   }
103   else if(result == EGL_CONDITION_SATISFIED)
104   {
105     DALI_LOG_INFO(gLogSyncFilter, Debug::General, "eglClientWaitSync Synced!\n");
106   }
107 }
108
109 EglSyncImplementation::EglSyncImplementation()
110 : mEglImplementation(NULL),
111   mSyncInitialized(false),
112   mSyncInitializeFailed(false)
113 {
114 }
115
116 EglSyncImplementation::~EglSyncImplementation()
117 {
118 }
119
120 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)
121 {
122   mEglImplementation = eglImpl;
123 }
124
125 Integration::GraphicsSyncAbstraction::SyncObject* EglSyncImplementation::CreateSyncObject()
126 {
127   DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
128   return new EglSyncObject(*mEglImplementation);
129 }
130
131 void EglSyncImplementation::DestroySyncObject(Integration::GraphicsSyncAbstraction::SyncObject* syncObject)
132 {
133   DALI_ASSERT_ALWAYS(mEglImplementation && "Sync Implementation not initialized");
134   delete static_cast<EglSyncObject*>(syncObject);
135 }
136
137 void EglSyncImplementation::InitializeEglSync()
138 {
139 }
140
141 } // namespace Adaptor
142 } // namespace Internal
143 } // namespace Dali