[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-sync-impl.h
1 #ifndef TEST_SYNC_IMPLEMENTATION_H
2 #define TEST_SYNC_IMPLEMENTATION_H
3
4 /*
5  * Copyright (c) 2024 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
21 // EXTERNAL INCLUDES
22 #include <map>
23 #include <sstream>
24 #include <string>
25
26 // INTERNAL INCLUDES
27 #include <dali/graphics-api/graphics-sync-object-create-info.h>
28 #include <dali/graphics-api/graphics-sync-object.h>
29 #include <dali/integration-api/core.h>
30 #include <dali/integration-api/graphics-sync-abstraction.h>
31
32 #include "test-trace-call-stack.h"
33
34 namespace Dali
35 {
36 class TestGraphicsSyncImplementation;
37
38 class TestSyncObject : public Integration::GraphicsSyncAbstraction::SyncObject
39 {
40 public:
41   TestSyncObject(TraceCallStack& trace);
42   ~TestSyncObject() override;
43   bool IsSynced() override;
44   void Wait() override;
45   void ClientWait() override;
46
47   bool            synced;
48   TraceCallStack& mTrace;
49 };
50
51 /**
52  * Class to emulate the gpu sync functions with tracing
53  */
54 class TestGraphicsSyncImplementation : public Integration::GraphicsSyncAbstraction
55 {
56 public:
57   /**
58    * Constructor
59    */
60   TestGraphicsSyncImplementation();
61
62   /**
63    * Destructor
64    */
65   virtual ~TestGraphicsSyncImplementation();
66
67   /**
68    * Initialize the sync objects
69    */
70   void Initialize();
71
72   /**
73    * Create a sync object that can be polled
74    */
75   GraphicsSyncAbstraction::SyncObject* CreateSyncObject() override;
76
77   /**
78    * Destroy a sync object
79    */
80   void DestroySyncObject(GraphicsSyncAbstraction::SyncObject* syncObject) override;
81
82 public: // TEST FUNCTIONS
83   GraphicsSyncAbstraction::SyncObject* GetLastSyncObject();
84
85   /**
86    * Test method to trigger the object sync behaviour.
87    * @param[in]
88    * @param[in] sync The sync value to set
89    */
90   void SetObjectSynced(GraphicsSyncAbstraction::SyncObject* syncObject, bool sync);
91
92   /**
93    * Turn trace on
94    */
95   void EnableTrace(bool enable);
96
97   /**
98    * Reset the trace callstack
99    */
100   void ResetTrace();
101
102   /**
103    * Get the trace object (allows test case to find methods on it)
104    */
105   TraceCallStack& GetTrace();
106
107   /**
108    * Get the number of sync objects
109    *
110    * @return the number of sync objects
111    */
112   int32_t GetNumberOfSyncObjects();
113
114   TestGraphicsSyncImplementation(const TestGraphicsSyncImplementation&) = delete;
115   TestGraphicsSyncImplementation& operator=(const TestGraphicsSyncImplementation&) = delete;
116
117 private:
118   typedef std::vector<TestSyncObject*> SyncContainer;
119   typedef SyncContainer::iterator      SyncIter;
120   SyncContainer                        mSyncObjects;       ///< The sync objects
121   TraceCallStack                       mTrace{true, "gl"}; ///< the trace call stack for testing
122 };
123
124 } // namespace Dali
125
126 #endif // TEST_GL_SYNC_ABSTRACTION_H