[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-test-application.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <toolkit-test-application.h>
20
21 // INTERNAL INCLUDES
22 #include <dali-test-suite-utils.h>
23 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
24 #include <dali/devel-api/atspi-interfaces/accessible.h>
25 #include <dali/devel-api/text-abstraction/font-client.h>
26 #include <dali/integration-api/adaptor-framework/adaptor.h>
27 #include <toolkit-adaptor-impl.h>
28 #include <toolkit-lifecycle-controller.h>
29
30 namespace Dali
31 {
32 using AdaptorImpl = Dali::Internal::Adaptor::Adaptor;
33
34 ToolkitTestApplication::ToolkitTestApplication(size_t surfaceWidth, size_t surfaceHeight, float horizontalDpi, float verticalDpi)
35 : TestApplication(surfaceWidth, surfaceHeight, horizontalDpi, verticalDpi, false /* Do not Initialize Core */),
36   mMainWindow(),
37   mAdaptor(&AdaptorImpl::New()) // Need to create Adaptor first as many singletons in dali-adaptor need it
38 {
39   // Create Core next
40   CreateCore();
41
42   // Override Scene creation in TestApplication by creating a window.
43   // The window will create a Scene & surface and set up the scene's surface appropriately.
44   mMainWindow = Window::New(PositionSize(0, 0, surfaceWidth, surfaceHeight), "");
45   mScene      = AdaptorImpl::GetScene(mMainWindow);
46   mScene.SetDpi(Vector2(horizontalDpi, verticalDpi));
47
48   // Create render target for the scene
49   Graphics::RenderTargetCreateInfo rtInfo{};
50   rtInfo.SetExtent({mSurfaceWidth, mSurfaceHeight});
51   mScene.SetSurfaceRenderTarget(rtInfo);
52
53   mScenes.push_back(mScene);
54
55   // Core needs to be initialized next before we start the adaptor
56   InitializeCore();
57   Accessibility::Accessible::SetObjectRegistry(mCore->GetObjectRegistry());
58
59   // This will also emit the window created signals
60   AdaptorImpl::GetImpl(*mAdaptor).Start(mMainWindow);
61   AdaptorImpl::GetImpl(*mAdaptor).SetApplication(*this);
62
63   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
64   lifecycleController.InitSignal().Emit();
65
66   // set the DPI value for font rendering
67   TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
68   if(fontClient)
69   {
70     fontClient.SetDpi(mDpi.x, mDpi.y);
71   }
72 }
73
74 ToolkitTestApplication::~ToolkitTestApplication()
75 {
76   Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();
77   lifecycleController.TerminateSignal().Emit();
78
79   // Need to delete core before we delete the adaptor.
80   delete mCore;
81   mCore = NULL;
82 }
83
84 void ToolkitTestApplication::RunIdles()
85 {
86   AdaptorImpl::GetImpl(*mAdaptor.get()).RunIdles();
87 }
88
89 } // namespace Dali