Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-application.h
1 #ifndef DALI_TEST_APPLICATION_H
2 #define DALI_TEST_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/resource-policies.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/integration-api/trace.h>
25
26 #include <dali/public-api/common/dali-common.h>
27 #include <test-platform-abstraction.h>
28
29 #include "test-graphics-controller.h"
30 #include "test-render-controller.h"
31
32 namespace Dali
33 {
34 class DALI_CORE_API TestApplication : public ConnectionTracker
35 {
36 public:
37   // Default values derived from H2 device.
38   static const uint32_t DEFAULT_SURFACE_WIDTH  = 480;
39   static const uint32_t DEFAULT_SURFACE_HEIGHT = 800;
40
41   static constexpr uint32_t DEFAULT_HORIZONTAL_DPI = 220;
42   static constexpr uint32_t DEFAULT_VERTICAL_DPI   = 217;
43
44   static const uint32_t DEFAULT_RENDER_INTERVAL = 1;
45
46   static const uint32_t RENDER_FRAME_INTERVAL = 16;
47
48   TestApplication(uint32_t surfaceWidth        = DEFAULT_SURFACE_WIDTH,
49                   uint32_t surfaceHeight       = DEFAULT_SURFACE_HEIGHT,
50                   uint32_t horizontalDpi       = DEFAULT_HORIZONTAL_DPI,
51                   uint32_t verticalDpi         = DEFAULT_VERTICAL_DPI,
52                   bool     initialize          = true,
53                   bool     enablePartialUpdate = false);
54
55   void Initialize();
56   void CreateCore();
57   void CreateScene();
58   void InitializeCore();
59   ~TestApplication() override;
60   static void              LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
61   static void              LogContext(bool start, const char* tag);
62   Dali::Integration::Core& GetCore();
63   TestPlatformAbstraction& GetPlatform();
64   TestRenderController&    GetRenderController();
65   TestGraphicsController&  GetGraphicsController();
66
67   TestGlAbstraction&              GetGlAbstraction();
68   TestGlSyncAbstraction&          GetGlSyncAbstraction();
69   TestGlContextHelperAbstraction& GetGlContextHelperAbstraction();
70
71   void        ProcessEvent(const Integration::Event& event);
72   void        SendNotification();
73   bool        Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
74   bool        PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
75   bool        RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
76   uint32_t    GetUpdateStatus();
77   bool        UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
78   bool        RenderOnly();
79   void        ResetContext();
80   bool        GetRenderNeedsUpdate();
81   bool        GetRenderNeedsPostRender();
82   uint32_t    Wait(uint32_t durationToWait);
83   static void EnableLogging(bool enabled)
84   {
85     mLoggingEnabled = enabled;
86   }
87
88   Integration::Scene GetScene() const
89   {
90     return mScene;
91   }
92
93 private:
94   void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
95
96 protected:
97   TestPlatformAbstraction mPlatformAbstraction;
98   TestRenderController    mRenderController;
99   TestGraphicsController  mGraphicsController;
100
101   Integration::UpdateStatus mStatus;
102   Integration::RenderStatus mRenderStatus;
103
104   Integration::Core*       mCore;
105   Dali::Integration::Scene mScene;
106
107   uint32_t mSurfaceWidth;
108   uint32_t mSurfaceHeight;
109   uint32_t mFrame;
110
111   Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget;
112
113   struct
114   {
115     uint32_t x;
116     uint32_t y;
117   } mDpi;
118   uint32_t    mLastVSyncTime;
119   bool        mPartialUpdateEnabled;
120   static bool mLoggingEnabled;
121 };
122
123 } // namespace Dali
124
125 #endif // DALI_TEST_APPLICATION_H