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/public-api/common/dali-common.h>
31 class DALI_IMPORT_API TestApplication : public ConnectionTracker
35 // Default values derived from H2 device.
36 static const unsigned int DEFAULT_SURFACE_WIDTH = 480;
37 static const unsigned int DEFAULT_SURFACE_HEIGHT = 800;
40 static constexpr float DEFAULT_HORIZONTAL_DPI = 220.0f;
41 static constexpr float DEFAULT_VERTICAL_DPI = 217.0f;
43 static const float DEFAULT_HORIZONTAL_DPI = 220.0f;
44 static const float DEFAULT_VERTICAL_DPI = 217.0f;
47 static const unsigned int DEFAULT_RENDER_INTERVAL = 1;
49 TestApplication( size_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
50 size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
51 float horizontalDpi = DEFAULT_HORIZONTAL_DPI,
52 float verticalDpi = DEFAULT_VERTICAL_DPI )
54 mSurfaceWidth( surfaceWidth ),
55 mSurfaceHeight( surfaceHeight ),
57 mDpi( horizontalDpi, verticalDpi )
62 TestApplication( bool initialize,
63 size_t surfaceWidth = DEFAULT_SURFACE_WIDTH,
64 size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
65 float horizontalDpi = DEFAULT_HORIZONTAL_DPI,
66 float verticalDpi = DEFAULT_VERTICAL_DPI )
68 mSurfaceWidth( surfaceWidth ),
69 mSurfaceHeight( surfaceHeight ),
71 mDpi( horizontalDpi, verticalDpi )
81 mCore = Dali::Integration::Core::New(
88 mCore->ContextCreated();
89 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
90 mCore->SetDpi( mDpi.x, mDpi.y );
92 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
93 Dali::Integration::Log::InstallLogFunction(logFunction);
96 virtual ~TestApplication()
98 Dali::Integration::Log::UninstallLogFunction();
102 static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
106 case Dali::Integration::Log::DebugInfo:
107 tet_printf("INFO: %s", message.c_str());
109 case Dali::Integration::Log::DebugWarning:
110 tet_printf("WARN: %s", message.c_str());
112 case Dali::Integration::Log::DebugError:
113 tet_printf("ERROR: %s", message.c_str());
116 tet_printf("DEFAULT: %s", message.c_str());
121 Dali::Integration::Core& GetCore()
126 TestPlatformAbstraction& GetPlatform()
128 return mPlatformAbstraction;
131 TestRenderController& GetRenderController()
133 return mRenderController;
136 TestGlAbstraction& GetGlAbstraction()
138 return mGlAbstraction;
141 TestGlSyncAbstraction& GetGlSyncAbstraction()
143 return mGlSyncAbstraction;
146 TestGestureManager& GetGestureManager()
148 return mGestureManager;
151 void ProcessEvent(const Integration::Event& event)
153 mCore->QueueEvent(event);
154 mCore->ProcessEvents();
157 void SendNotification()
159 mCore->ProcessEvents();
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;