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-graphics-sync-impl.h>
34 #include <test-platform-abstraction.h>
35 #include <test-render-controller.h>
39 namespace Internal::Adaptor
41 class ConfigurationManager;
44 class TestGraphicsImpl : public Internal::Adaptor::GraphicsInterface
51 virtual ~TestGraphicsImpl() = default;
53 Dali::Graphics::Controller& GetController() override
55 Dali::Graphics::Controller* controller{nullptr};
60 * Initialize the graphics subsystem, configured from environment
62 void Initialize() override
64 mCallstack.PushCall("Initialize()", "");
68 * Initialize the graphics subsystem, providing explicit parameters.
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)
75 void Initialize(bool depth, bool stencil, bool partialRendering, int msaa) override
77 TraceCallStack::NamedParams namedParams;
78 namedParams["depth"] << depth;
79 namedParams["stencil"] << stencil;
80 namedParams["partialRendering"] << partialRendering;
81 namedParams["msaa"] << msaa;
82 mCallstack.PushCall("Initialize()", "");
86 * Configure the graphics surface
88 * @param[in] surface The surface to configure, or NULL if not present
90 void ConfigureSurface(Dali::RenderSurfaceInterface* surface) override
95 * Activate the resource context
97 void ActivateResourceContext() override
99 mCallstack.PushCall("ActivateResourceContext()", "");
103 * Activate the resource context
105 * @param[in] surface The surface whose context to be switched to.
107 void ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface) override
109 TraceCallStack::NamedParams namedParams;
110 namedParams["surface"] << std::hex << surface;
111 mCallstack.PushCall("ActivateResourceContext()", namedParams.str(), namedParams);
114 void PostRender() override
116 mCallstack.PushCall("PostRender()", "");
120 * Inform graphics interface that this is the first frame after a resume.
122 void SetFirstFrameAfterResume() override
127 * Shut down the graphics implementation
129 void Shutdown() override
131 mCallstack.PushCall("Shutdown()", "");
135 * Destroy the Graphics implementation
137 void Destroy() override
139 mCallstack.PushCall("Destroy()", "");
143 * @return true if advanced blending options are supported
145 bool IsAdvancedBlendEquationSupported() override
151 * @return true if graphics subsystem is initialized
153 bool IsInitialized() override
159 * @return true if a separate resource context is supported
161 bool IsResourceContextSupported() override
167 * @return the maximum texture size
169 uint32_t GetMaxTextureSize() override
175 * @return the version number of the shader language
177 uint32_t GetShaderLanguageVersion() override
183 * Store cached configurations
185 void CacheConfigurations(Internal::Adaptor::ConfigurationManager& configurationManager) override
190 TraceCallStack mCallstack{true, "GraphicsImpl"};
193 class DALI_CORE_API TestGraphicsApplication : public ConnectionTracker
196 // Default values derived from H2 device.
197 static const uint32_t DEFAULT_SURFACE_WIDTH = 480;
198 static const uint32_t DEFAULT_SURFACE_HEIGHT = 800;
200 static constexpr uint32_t DEFAULT_HORIZONTAL_DPI = 220;
201 static constexpr uint32_t DEFAULT_VERTICAL_DPI = 217;
203 static const uint32_t DEFAULT_RENDER_INTERVAL = 1;
205 static const uint32_t RENDER_FRAME_INTERVAL = 16;
207 TestGraphicsApplication(uint32_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
208 uint32_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
209 uint32_t horizontalDpi = DEFAULT_HORIZONTAL_DPI,
210 uint32_t verticalDpi = DEFAULT_VERTICAL_DPI,
211 bool initialize = true,
212 bool enablePartialUpdate = false);
217 void InitializeCore();
218 ~TestGraphicsApplication() override;
219 static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message);
220 static void LogContext(bool start, const char* tag);
221 Dali::Integration::Core& GetCore();
222 TestPlatformAbstraction& GetPlatform();
223 TestRenderController& GetRenderController();
224 Graphics::Controller& GetGraphicsController();
226 TestGlAbstraction& GetGlAbstraction();
227 TestGlContextHelperAbstraction& GetGlContextHelperAbstraction();
229 void ProcessEvent(const Integration::Event& event);
230 void SendNotification();
231 bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL);
232 bool PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects);
233 bool RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect);
234 uint32_t GetUpdateStatus();
235 bool UpdateOnly(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL);
238 bool GetRenderNeedsUpdate();
239 bool GetRenderNeedsPostRender();
240 uint32_t Wait(uint32_t durationToWait);
241 static void EnableLogging(bool enabled)
243 mLoggingEnabled = enabled;
246 Integration::Scene GetScene() const
252 void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL);
255 TestPlatformAbstraction mPlatformAbstraction;
256 TestRenderController mRenderController;
257 Graphics::EglGraphicsController mGraphicsController; // Use real controller in Adaptor
258 TestGlAbstraction mGlAbstraction;
259 TestGlContextHelperAbstraction mGlContextHelperAbstraction;
260 TestGraphicsSyncImplementation mGraphicsSyncImplementation;
261 TestGraphicsImpl mGraphics;
262 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr};
264 Integration::UpdateStatus mStatus;
265 Integration::RenderStatus mRenderStatus;
267 Integration::Core* mCore;
268 Dali::Integration::Scene mScene;
270 uint32_t mSurfaceWidth;
271 uint32_t mSurfaceHeight;
279 uint32_t mLastVSyncTime;
280 bool mPartialUpdateEnabled;
281 static bool mLoggingEnabled;
286 #endif // DALI_TEST_GRAPHICS_APPLICATION_H