[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / dali-test-suite-utils / test-graphics-application.h
1 #ifndef DALI_TEST_GRAPHICS_APPLICATION_H
2 #define DALI_TEST_GRAPHICS_APPLICATION_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 // INTERNAL INCLUDES
22 #include <dali/integration-api/core.h>
23 #include <dali/integration-api/resource-policies.h>
24 #include <dali/integration-api/scene.h>
25 #include <dali/integration-api/trace.h>
26
27 #include <dali/internal/graphics/common/graphics-interface.h>
28 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
29 #include <dali/public-api/common/dali-common.h>
30
31 #include <test-gl-abstraction.h>
32 #include <test-graphics-sync-impl.h>
33 #include <test-platform-abstraction.h>
34 #include <test-render-controller.h>
35
36 namespace Dali
37 {
38 namespace Internal::Adaptor
39 {
40 class ConfigurationManager;
41 }
42
43 class TestGraphicsImpl : public Internal::Adaptor::GraphicsInterface
44 {
45 public:
46   TestGraphicsImpl()
47   : GraphicsInterface()
48   {
49   }
50   virtual ~TestGraphicsImpl() = default;
51
52   Dali::Graphics::Controller& GetController() override
53   {
54     Dali::Graphics::Controller* controller{nullptr};
55     return *controller;
56   }
57
58   /**
59    * Initialize the graphics subsystem, configured from environment
60    */
61   void Initialize() override
62   {
63     mCallstack.PushCall("Initialize()", "");
64   }
65
66   /**
67    * Initialize the graphics subsystem, providing explicit parameters.
68    *
69    * @param[in] depth True if depth buffer is required
70    * @param[in] stencil True if stencil buffer is required
71    * @param[in] partialRendering True if partial rendering is required
72    * @param[in] msaa level of anti-aliasing required (-1 = off)
73    */
74   void Initialize(bool depth, bool stencil, bool partialRendering, int msaa) override
75   {
76     TraceCallStack::NamedParams namedParams;
77     namedParams["depth"] << depth;
78     namedParams["stencil"] << stencil;
79     namedParams["partialRendering"] << partialRendering;
80     namedParams["msaa"] << msaa;
81     mCallstack.PushCall("Initialize()", "");
82   }
83
84   /**
85    * Configure the graphics surface
86    *
87    * @param[in] surface The surface to configure, or NULL if not present
88    */
89   void ConfigureSurface(Dali::RenderSurfaceInterface* surface) override
90   {
91   }
92
93   /**
94    * Activate the resource context
95    */
96   void ActivateResourceContext() override
97   {
98     mCallstack.PushCall("ActivateResourceContext()", "");
99   }
100
101   /**
102    * Activate the resource context
103    *
104    * @param[in] surface The surface whose context to be switched to.
105    */
106   void ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface) override
107   {
108     TraceCallStack::NamedParams namedParams;
109     namedParams["surface"] << std::hex << surface;
110     mCallstack.PushCall("ActivateResourceContext()", namedParams.str(), namedParams);
111   }
112
113   void PostRender() override
114   {
115     mCallstack.PushCall("PostRender()", "");
116   }
117
118   /**
119    * Inform graphics interface that this is the first frame after a resume.
120    */
121   void SetFirstFrameAfterResume() override
122   {
123   }
124
125   /**
126    * Shut down the graphics implementation
127    */
128   void Shutdown() override
129   {
130     mCallstack.PushCall("Shutdown()", "");
131   }
132
133   /**
134    * Destroy the Graphics implementation
135    */
136   void Destroy() override
137   {
138     mCallstack.PushCall("Destroy()", "");
139   }
140
141   /**
142    * @return true if advanced blending options are supported
143    */
144   bool IsAdvancedBlendEquationSupported() override
145   {
146     return true;
147   }
148
149   /**
150    * @return true if multisampled render to texture is supported
151    */
152   bool IsMultisampledRenderToTextureSupported() override
153   {
154     return true;
155   }
156
157   /**
158    * @return true if graphics subsystem is initialized
159    */
160   bool IsInitialized() override
161   {
162     return true;
163   }
164
165   /**
166    * @return true if a separate resource context is supported
167    */
168   bool IsResourceContextSupported() override
169   {
170     return true;
171   }
172
173   /**
174    * @return the maximum texture size
175    */
176   uint32_t GetMaxTextureSize() override
177   {
178     return 32768u;
179   }
180
181   uint32_t GetMaxCombinedTextureUnits() override
182   {
183     return 96;
184   }
185
186   /**
187    * @return the maximum texture samples when we use multisampled texture
188    */
189   uint8_t GetMaxTextureSamples() override
190   {
191     return 8u;
192   }
193
194   /**
195    * @return the version number of the shader language
196    */
197   uint32_t GetShaderLanguageVersion() override
198   {
199     return 320;
200   }
201
202   void FrameStart() override
203   {
204   }
205
206   void LogMemoryPools() override
207   {
208   }
209
210   /**
211    * Store cached configurations
212    */
213   void CacheConfigurations(Internal::Adaptor::ConfigurationManager& configurationManager) override
214   {
215   }
216
217 public:
218   TraceCallStack mCallstack{true, "GraphicsImpl"};
219 };
220
221 class DALI_CORE_API TestGraphicsApplication : public ConnectionTracker
222 {
223 public:
224   // Default values derived from H2 device.
225   static const uint32_t DEFAULT_SURFACE_WIDTH  = 480;
226   static const uint32_t DEFAULT_SURFACE_HEIGHT = 800;
227
228   static constexpr uint32_t DEFAULT_HORIZONTAL_DPI = 220;
229   static constexpr uint32_t DEFAULT_VERTICAL_DPI   = 217;
230
231   static const uint32_t DEFAULT_RENDER_INTERVAL = 1;
232
233   static const uint32_t RENDER_FRAME_INTERVAL = 16;
234
235   TestGraphicsApplication(uint32_t surfaceWidth        = DEFAULT_SURFACE_WIDTH,
236                           uint32_t surfaceHeight       = DEFAULT_SURFACE_HEIGHT,
237                           uint32_t horizontalDpi       = DEFAULT_HORIZONTAL_DPI,
238                           uint32_t verticalDpi         = DEFAULT_VERTICAL_DPI,
239                           bool     initialize          = true,
240                           bool     enablePartialUpdate = false);
241
242   void Initialize();
243   void CreateCore();
244   void CreateScene();
245   void InitializeCore();
246   ~TestGraphicsApplication() override;
247   static void              LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
248   static void              LogContext(bool start, const char* tag, const char* message);
249   Dali::Integration::Core& GetCore();
250   TestPlatformAbstraction& GetPlatform();
251   TestRenderController&    GetRenderController();
252   Graphics::Controller&    GetGraphicsController();
253
254   TestGlAbstraction& GetGlAbstraction();
255
256   void        ProcessEvent(const Integration::Event& event);
257   void        SendNotification();
258   bool        Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
259   bool        PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
260   bool        RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
261   uint32_t    GetUpdateStatus();
262   bool        UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
263   bool        RenderOnly();
264   void        ResetContext();
265   bool        GetRenderNeedsUpdate();
266   bool        GetRenderNeedsPostRender();
267   uint32_t    Wait(uint32_t durationToWait);
268   static void EnableLogging(bool enabled)
269   {
270     mLoggingEnabled = enabled;
271   }
272
273   Integration::Scene GetScene() const
274   {
275     return mScene;
276   }
277
278 private:
279   void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
280
281 protected:
282   TestPlatformAbstraction                     mPlatformAbstraction;
283   TestRenderController                        mRenderController;
284   Graphics::EglGraphicsController             mGraphicsController; // Use real controller in Adaptor
285   TestGlAbstraction                           mGlAbstraction;
286   TestGraphicsSyncImplementation              mGraphicsSyncImplementation;
287   TestGraphicsImpl                            mGraphics;
288   Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr};
289
290   Integration::UpdateStatus mStatus;
291   Integration::RenderStatus mRenderStatus;
292
293   Integration::Core*       mCore;
294   Dali::Integration::Scene mScene;
295
296   uint32_t mSurfaceWidth;
297   uint32_t mSurfaceHeight;
298   uint32_t mFrame;
299
300   struct
301   {
302     uint32_t x;
303     uint32_t y;
304   } mDpi;
305   uint32_t    mLastVSyncTime;
306   bool        mPartialUpdateEnabled;
307   static bool mLoggingEnabled;
308 };
309
310 } // namespace Dali
311
312 #endif // DALI_TEST_GRAPHICS_APPLICATION_H