Fix SVACE errors in various files
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-sync-pool.h
1 #ifndef DALI_GRAPHICS_GLES_SYNC_POOL_H
2 #define DALI_GRAPHICS_GLES_SYNC_POOL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/graphics-api/graphics-types.h>
21 #include <dali/integration-api/gl-abstraction.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 namespace Dali::Graphics
25 {
26 class EglGraphicsController;
27
28 namespace GLES
29 {
30 class Context;
31
32 struct AgingSyncObject
33 {
34   AgingSyncObject(Graphics::EglGraphicsController& controller, const Context* writeContext);
35   ~AgingSyncObject();
36
37   EglGraphicsController& controller;
38   const Context*         writeContext;
39   GLsync                 glSyncObject{0};
40   uint8_t                age{2};
41   bool                   syncing{false};
42 };
43 using AgingSyncPtrRef = std::unique_ptr<AgingSyncObject>&;
44
45 /**
46  * A vector of current fence syncs. They only age if glWaitSync is called on them in the
47  * same frame they are created, otherwise they are deleted.
48  * They must be created in the writeContext, but can be synced from a readContext.
49  * (Pool per context? - probably only ever used in resource context!)
50  */
51 class SyncPool
52 {
53 public:
54   explicit SyncPool(Graphics::EglGraphicsController& graphicsController)
55   : mController(graphicsController)
56   {
57   }
58
59   ~SyncPool();
60
61   /**
62    * Allocate a sync object in the writeContext
63    * @param writeContext
64    * @return An owned ptr to a sync object
65    */
66   AgingSyncObject* AllocateSyncObject(const Context* writeContext);
67
68   /**
69    * Wait on a sync object in any context
70    * @param syncPoolObject The object to wait on.
71    */
72   void Wait(AgingSyncObject* syncPoolObject);
73
74   /**
75    * Delete the sync object if it's not needed.
76    *
77    */
78   void FreeSyncObject(AgingSyncObject* agingSyncObject);
79
80   /**
81    * Age outstanding sync objects. Call at the end of each frame.
82    * When a sync object is older than 2 frames, delete it.
83    */
84   void AgeSyncObjects();
85
86 private:
87   std::vector<std::unique_ptr<AgingSyncObject>> mSyncObjects;
88   EglGraphicsController&                        mController;
89 };
90
91 } // namespace GLES
92 } // namespace Dali::Graphics
93
94 #endif //DALI_GRAPHICS_GLES_SYNC_POOL_H