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