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