1 #ifndef __DALI_TEST_APPLICATION_H__
2 #define __DALI_TEST_APPLICATION_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include "test-platform-abstraction.h"
22 #include "test-gesture-manager.h"
23 #include "test-gl-sync-abstraction.h"
24 #include "test-gl-abstraction.h"
25 #include "test-render-controller.h"
26 #include <dali/integration-api/events/notification-event.h>
27 #include <dali/public-api/common/dali-common.h>
32 class DALI_IMPORT_API TestApplication : public ConnectionTracker
36 // Default values derived from H2 device.
37 static const unsigned int DEFAULT_SURFACE_WIDTH = 480;
38 static const unsigned int DEFAULT_SURFACE_HEIGHT = 800;
41 static constexpr float DEFAULT_HORIZONTAL_DPI = 220.0f;
42 static constexpr float DEFAULT_VERTICAL_DPI = 217.0f;
44 static const float DEFAULT_HORIZONTAL_DPI = 220.0f;
45 static const float DEFAULT_VERTICAL_DPI = 217.0f;
48 static const unsigned int DEFAULT_RENDER_INTERVAL = 1;
50 TestApplication( size_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
51 size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
52 float horizontalDpi = DEFAULT_HORIZONTAL_DPI,
53 float verticalDpi = DEFAULT_VERTICAL_DPI )
55 mSurfaceWidth( surfaceWidth ),
56 mSurfaceHeight( surfaceHeight ),
58 mDpi( horizontalDpi, verticalDpi )
63 TestApplication( bool initialize,
64 size_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
65 size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
66 float horizontalDpi = DEFAULT_HORIZONTAL_DPI,
67 float verticalDpi = DEFAULT_VERTICAL_DPI )
69 mSurfaceWidth( surfaceWidth ),
70 mSurfaceHeight( surfaceHeight ),
72 mDpi( horizontalDpi, verticalDpi )
82 mCore = Dali::Integration::Core::New(
89 mCore->ContextCreated();
90 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
91 mCore->SetDpi( mDpi.x, mDpi.y );
93 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
94 unsigned int logOpts = Dali::Integration::Log::ParseLogOptions("");
95 Dali::Integration::Log::InstallLogFunction(logFunction, logOpts);
98 virtual ~TestApplication()
100 Dali::Integration::Log::UninstallLogFunction();
104 static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
108 case Dali::Integration::Log::DebugInfo:
109 tet_printf("INFO: %s", message.c_str());
111 case Dali::Integration::Log::DebugWarning:
112 tet_printf("WARN: %s", message.c_str());
114 case Dali::Integration::Log::DebugError:
115 tet_printf("ERROR: %s", message.c_str());
117 case Dali::Integration::Log::DebugResources:
118 tet_printf("INFO: %s", message.c_str());
121 tet_printf("DEFAULT: %s", message.c_str());
126 Dali::Integration::Core& GetCore()
131 TestPlatformAbstraction& GetPlatform()
133 return mPlatformAbstraction;
136 TestRenderController& GetRenderController()
138 return mRenderController;
141 TestGlAbstraction& GetGlAbstraction()
143 return mGlAbstraction;
146 TestGlSyncAbstraction& GetGlSyncAbstraction()
148 return mGlSyncAbstraction;
151 TestGestureManager& GetGestureManager()
153 return mGestureManager;
156 void SendNotification()
158 Integration::NotificationEvent event;
159 mCore->SendEvent(event);
162 void SetSurfaceWidth( unsigned int width, unsigned height )
164 mSurfaceWidth = width;
165 mSurfaceHeight = height;
167 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
170 bool Render( unsigned int intervalMilliseconds = DEFAULT_RENDER_INTERVAL )
172 // Update Time values
173 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
174 unsigned int seconds(0u), microseconds(0u);
175 mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
177 mCore->VSync( mFrame, seconds, microseconds );
178 mCore->Update( mStatus );
179 mCore->Render( mRenderStatus );
183 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
186 unsigned int GetUpdateStatus()
188 return mStatus.KeepUpdating();
191 bool UpdateOnly( unsigned int intervalMilliseconds = DEFAULT_RENDER_INTERVAL )
193 // Update Time values
194 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
195 unsigned int seconds(0u), microseconds(0u);
196 mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
198 mCore->VSync( mFrame, seconds, microseconds );
199 mCore->Update( mStatus );
201 return mStatus.KeepUpdating();
206 // Update Time values
207 mCore->Render( mRenderStatus );
211 return mRenderStatus.NeedsUpdate();
216 mCore->ContextToBeDestroyed();
217 mCore->ContextCreated();
221 TestPlatformAbstraction mPlatformAbstraction;
222 TestRenderController mRenderController;
223 TestGlAbstraction mGlAbstraction;
224 TestGlSyncAbstraction mGlSyncAbstraction;
225 TestGestureManager mGestureManager;
227 Integration::UpdateStatus mStatus;
228 Integration::RenderStatus mRenderStatus;
230 Integration::Core* mCore;
232 unsigned int mSurfaceWidth;
233 unsigned int mSurfaceHeight;