1 #ifndef DALI_TEST_GRAPHICS_APPLICATION_H
2 #define DALI_TEST_GRAPHICS_APPLICATION_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
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>
42 namespace Internal::Adaptor
44 class ConfigurationManager;
47 class TestGraphicsImpl : public Internal::Adaptor::GraphicsInterface
54 virtual ~TestGraphicsImpl() = default;
56 Dali::Graphics::Controller& GetController() override
58 Dali::Graphics::Controller* controller{nullptr};
63 * Initialize the graphics subsystem, configured from environment
65 void Initialize() override
67 mCallstack.PushCall("Initialize()", "");
71 * Initialize the graphics subsystem, providing explicit parameters.
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)
78 void Initialize(bool depth, bool stencil, bool partialRendering, int msaa) override
80 TraceCallStack::NamedParams namedParams;
81 namedParams["depth"] << depth;
82 namedParams["stencil"] << stencil;
83 namedParams["partialRendering"] << partialRendering;
84 namedParams["msaa"] << msaa;
85 mCallstack.PushCall("Initialize()", "");
89 * Configure the graphics surface
91 * @param[in] surface The surface to configure, or NULL if not present
93 void ConfigureSurface(Dali::RenderSurfaceInterface* surface) override
98 * Activate the resource context
100 void ActivateResourceContext() override
102 mCallstack.PushCall("ActivateResourceContext()", "");
106 * Activate the resource context
108 * @param[in] surface The surface whose context to be switched to.
110 void ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface) override
112 TraceCallStack::NamedParams namedParams;
113 namedParams["surface"] << std::hex << surface;
114 mCallstack.PushCall("ActivateResourceContext()", namedParams.str(), namedParams);
118 * Inform graphics interface that this is the first frame after a resume.
120 void SetFirstFrameAfterResume() override
125 * Shut down the graphics implementation
127 void Shutdown() override
129 mCallstack.PushCall("Shutdown()", "");
133 * Destroy the Graphics implementation
135 void Destroy() override
137 mCallstack.PushCall("Destroy()", "");
141 * @return true if advanced blending options are supported
143 bool IsAdvancedBlendEquationSupported() override
149 * @return true if graphics subsystem is initialized
151 bool IsInitialized() override
157 * @return true if a separate resource context is supported
159 bool IsResourceContextSupported() override
165 * @return the maximum texture size
167 uint32_t GetMaxTextureSize() override
173 * @return the version number of the shader language
175 uint32_t GetShaderLanguageVersion() override
181 * Store cached configurations
183 void CacheConfigurations(Internal::Adaptor::ConfigurationManager& configurationManager) override
188 TraceCallStack mCallstack{true, "GraphicsImpl"};
194 class DALI_CORE_API TestGraphicsApplication : public ConnectionTracker
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;
201 static constexpr uint32_t DEFAULT_HORIZONTAL_DPI = 220;
202 static constexpr uint32_t DEFAULT_VERTICAL_DPI = 217;
204 static const uint32_t DEFAULT_RENDER_INTERVAL = 1;
206 static const uint32_t RENDER_FRAME_INTERVAL = 16;
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);
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();
227 TestGlAbstraction& GetGlAbstraction();
228 TestGlSyncAbstraction& GetGlSyncAbstraction();
229 TestGlContextHelperAbstraction& GetGlContextHelperAbstraction();
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);
240 bool GetRenderNeedsUpdate();
241 bool GetRenderNeedsPostRender();
242 uint32_t Wait(uint32_t durationToWait);
243 static void EnableLogging(bool enabled)
245 mLoggingEnabled = enabled;
248 Integration::Scene GetScene() const
254 void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
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;
265 Integration::UpdateStatus mStatus;
266 Integration::RenderStatus mRenderStatus;
268 Integration::Core* mCore;
269 Dali::Integration::Scene mScene;
271 uint32_t mSurfaceWidth;
272 uint32_t mSurfaceHeight;
280 uint32_t mLastVSyncTime;
281 bool mPartialUpdateEnabled;
282 static bool mLoggingEnabled;
287 #endif // DALI_TEST_GRAPHICS_APPLICATION_H