1 #ifndef DALI_TEST_GRAPHICS_APPLICATION_H
2 #define DALI_TEST_GRAPHICS_APPLICATION_H
5 * Copyright (c) 2024 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-graphics-sync-impl.h>
33 #include <test-platform-abstraction.h>
34 #include <test-render-controller.h>
38 namespace Internal::Adaptor
40 class ConfigurationManager;
43 class TestGraphicsImpl : public Internal::Adaptor::GraphicsInterface
50 virtual ~TestGraphicsImpl() = default;
52 Dali::Graphics::Controller& GetController() override
54 Dali::Graphics::Controller* controller{nullptr};
59 * Initialize the graphics subsystem, configured from environment
61 void Initialize() override
63 mCallstack.PushCall("Initialize()", "");
67 * Initialize the graphics subsystem, providing explicit parameters.
69 * @param[in] depth True if depth buffer is required
70 * @param[in] stencil True if stencil buffer is required
71 * @param[in] partialRendering True if partial rendering is required
72 * @param[in] msaa level of anti-aliasing required (-1 = off)
74 void Initialize(bool depth, bool stencil, bool partialRendering, int msaa) override
76 TraceCallStack::NamedParams namedParams;
77 namedParams["depth"] << depth;
78 namedParams["stencil"] << stencil;
79 namedParams["partialRendering"] << partialRendering;
80 namedParams["msaa"] << msaa;
81 mCallstack.PushCall("Initialize()", "");
85 * Configure the graphics surface
87 * @param[in] surface The surface to configure, or NULL if not present
89 void ConfigureSurface(Dali::RenderSurfaceInterface* surface) override
94 * Activate the resource context
96 void ActivateResourceContext() override
98 mCallstack.PushCall("ActivateResourceContext()", "");
102 * Activate the resource context
104 * @param[in] surface The surface whose context to be switched to.
106 void ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface) override
108 TraceCallStack::NamedParams namedParams;
109 namedParams["surface"] << std::hex << surface;
110 mCallstack.PushCall("ActivateResourceContext()", namedParams.str(), namedParams);
113 void PostRender() override
115 mCallstack.PushCall("PostRender()", "");
119 * Inform graphics interface that this is the first frame after a resume.
121 void SetFirstFrameAfterResume() override
126 * Shut down the graphics implementation
128 void Shutdown() override
130 mCallstack.PushCall("Shutdown()", "");
134 * Destroy the Graphics implementation
136 void Destroy() override
138 mCallstack.PushCall("Destroy()", "");
142 * @return true if advanced blending options are supported
144 bool IsAdvancedBlendEquationSupported() override
150 * @return true if multisampled render to texture is supported
152 bool IsMultisampledRenderToTextureSupported() override
158 * @return true if graphics subsystem is initialized
160 bool IsInitialized() override
166 * @return true if a separate resource context is supported
168 bool IsResourceContextSupported() override
174 * @return the maximum texture size
176 uint32_t GetMaxTextureSize() override
181 uint32_t GetMaxCombinedTextureUnits() override
187 * @return the maximum texture samples when we use multisampled texture
189 uint8_t GetMaxTextureSamples() override
195 * @return the version number of the shader language
197 uint32_t GetShaderLanguageVersion() override
202 void FrameStart() override
206 void LogMemoryPools() override
211 * Store cached configurations
213 void CacheConfigurations(Internal::Adaptor::ConfigurationManager& configurationManager) override
218 TraceCallStack mCallstack{true, "GraphicsImpl"};
221 class DALI_CORE_API TestGraphicsApplication : public ConnectionTracker
224 // Default values derived from H2 device.
225 static const uint32_t DEFAULT_SURFACE_WIDTH = 480;
226 static const uint32_t DEFAULT_SURFACE_HEIGHT = 800;
228 static constexpr uint32_t DEFAULT_HORIZONTAL_DPI = 220;
229 static constexpr uint32_t DEFAULT_VERTICAL_DPI = 217;
231 static const uint32_t DEFAULT_RENDER_INTERVAL = 1;
233 static const uint32_t RENDER_FRAME_INTERVAL = 16;
235 TestGraphicsApplication(uint32_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
236 uint32_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
237 uint32_t horizontalDpi = DEFAULT_HORIZONTAL_DPI,
238 uint32_t verticalDpi = DEFAULT_VERTICAL_DPI,
239 bool initialize = true,
240 bool enablePartialUpdate = false);
245 void InitializeCore();
246 ~TestGraphicsApplication() override;
247 static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
248 static void LogContext(bool start, const char* tag, const char* message);
249 Dali::Integration::Core& GetCore();
250 TestPlatformAbstraction& GetPlatform();
251 TestRenderController& GetRenderController();
252 Graphics::Controller& GetGraphicsController();
254 TestGlAbstraction& GetGlAbstraction();
256 void ProcessEvent(const Integration::Event& event);
257 void SendNotification();
258 bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
259 bool PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
260 bool RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
261 uint32_t GetUpdateStatus();
262 bool UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
265 bool GetRenderNeedsUpdate();
266 bool GetRenderNeedsPostRender();
267 uint32_t Wait(uint32_t durationToWait);
268 static void EnableLogging(bool enabled)
270 mLoggingEnabled = enabled;
273 Integration::Scene GetScene() const
279 void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
282 TestPlatformAbstraction mPlatformAbstraction;
283 TestRenderController mRenderController;
284 Graphics::EglGraphicsController mGraphicsController; // Use real controller in Adaptor
285 TestGlAbstraction mGlAbstraction;
286 TestGraphicsSyncImplementation mGraphicsSyncImplementation;
287 TestGraphicsImpl mGraphics;
288 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr};
290 Integration::UpdateStatus mStatus;
291 Integration::RenderStatus mRenderStatus;
293 Integration::Core* mCore;
294 Dali::Integration::Scene mScene;
296 uint32_t mSurfaceWidth;
297 uint32_t mSurfaceHeight;
305 uint32_t mLastVSyncTime;
306 bool mPartialUpdateEnabled;
307 static bool mLoggingEnabled;
312 #endif // DALI_TEST_GRAPHICS_APPLICATION_H