Remove annoying log message
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-sync-pool.cpp
1 /*
2  * Copyright (c) 2022 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 // Class header
18 #include <dali/internal/graphics/gles-impl/gles-sync-pool.h>
19
20 // External Headers
21 #include <dali/graphics-api/graphics-sync-object-create-info.h>
22
23 // Internal Headers
24 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
25
26 namespace Dali::Graphics::GLES
27 {
28 AgingSyncObject::AgingSyncObject(Graphics::EglGraphicsController& controller, const Context* writeContext)
29 : controller(controller),
30   writeContext(writeContext)
31 {
32   auto gl = controller.GetGL();
33   if(gl)
34   {
35     glSyncObject = gl->FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
36   }
37 }
38
39 AgingSyncObject::~AgingSyncObject()
40 {
41   auto gl = controller.GetGL();
42   if(gl && glSyncObject != nullptr)
43   {
44     gl->DeleteSync(glSyncObject);
45   }
46 }
47
48 SyncPool::~SyncPool() = default;
49
50 AgingSyncObject* SyncPool::AllocateSyncObject(const Context* writeContext)
51 {
52   std::unique_ptr<AgingSyncObject> syncObject = std::make_unique<AgingSyncObject>(mController, writeContext);
53   mSyncObjects.push_back(std::move(syncObject));
54   return mSyncObjects.back().get();
55 }
56
57 void SyncPool::Wait(AgingSyncObject* syncPoolObject)
58 {
59   auto gl = mController.GetGL();
60   if(gl && syncPoolObject->glSyncObject != nullptr)
61   {
62     syncPoolObject->syncing = true;
63     gl->WaitSync(syncPoolObject->glSyncObject, 0, GL_TIMEOUT_IGNORED);
64   }
65 }
66
67 void SyncPool::FreeSyncObject(AgingSyncObject* agingSyncObject)
68 {
69   auto iter = std::find_if(mSyncObjects.begin(), mSyncObjects.end(), [&agingSyncObject](AgingSyncPtrRef agingSyncPtr) { return agingSyncPtr.get() == agingSyncObject; });
70   if(iter != mSyncObjects.end())
71   {
72     iter->reset();
73   }
74 }
75
76 /**
77  * Age sync objects. Call at the end of each frame.
78  * When a sync object is older than 2 frames, delete it.
79  */
80 void SyncPool::AgeSyncObjects()
81 {
82   if(!mSyncObjects.empty())
83   {
84     // Age the remaining sync objects.
85     for(auto& agingSyncObject : mSyncObjects)
86     {
87       if(agingSyncObject != nullptr && agingSyncObject->glSyncObject != 0)
88       {
89         if(agingSyncObject->age > 0)
90         {
91           agingSyncObject->age--;
92         }
93         else
94         {
95           agingSyncObject.reset();
96         }
97       }
98     }
99   }
100   // Move any old sync objects to the end of the list, and then remove them all.
101   mSyncObjects.erase(std::remove_if(mSyncObjects.begin(), mSyncObjects.end(), [&](std::unique_ptr<AgingSyncObject>& agingSyncObject) { return agingSyncObject == nullptr; }),
102                      mSyncObjects.end());
103 }
104
105 } // namespace Dali::Graphics::GLES