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