2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "widget-application-impl.h"
22 #include <appcore_multiwindow_base.h>
23 #include <dali/integration-api/debug.h>
26 #include <style-monitor.h>
27 #include <command-line-options.h>
28 #include <common/adaptor-impl.h>
29 #include <common/framework.h>
30 #include <singleton-service-impl.h>
31 #include <window-impl.h>
36 namespace TizenPlatform
38 class TizenPlatformAbstraction;
52 WidgetApplicationPtr WidgetApplication::New(
55 const std::string& stylesheet)
57 WidgetApplicationPtr widgetApplication( new WidgetApplication (argc, argv, stylesheet ) );
58 return widgetApplication;
61 WidgetApplication::WidgetApplication( int* argc, char** argv[], const std::string& stylesheet )
64 mLanguageChangedSignal(),
65 mRegionChangedSignal(),
69 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
70 mCommandLineOptions( NULL ),
71 mSingletonService( SingletonService::New() ),
74 mStylesheet( stylesheet ),
75 mEnvironmentOptions(),
78 // Get mName from environment options
79 mName = mEnvironmentOptions.GetWindowName();
80 if( mName.empty() && argc && ( *argc > 0 ) )
82 // Set mName from command-line args if environment option not set
86 mCommandLineOptions = new CommandLineOptions(argc, argv);
87 mFramework = new Framework( *this, argc, argv, Framework::WIDGET );
90 WidgetApplication::~WidgetApplication()
92 mSingletonService.UnregisterAll();
95 delete mCommandLineOptions;
99 void WidgetApplication::CreateAdaptor()
101 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
103 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( true );
106 void WidgetApplication::MainLoop()
108 // Run the application
112 void WidgetApplication::Quit()
114 // Actually quit the application.
115 AddIdle( MakeCallback( this, &WidgetApplication::QuitFromMainLoop ) );
118 void WidgetApplication::QuitFromMainLoop()
123 // This will trigger OnTerminate(), below, after the main loop has completed.
126 void WidgetApplication::DoInit()
128 mWindow = Dali::Window::New( PositionSize(), "", mEnvironmentOptions.GetWindowClassName(), 1 );
129 // Quit the application when the window is closed
130 mWindow.ShowIndicator(Dali::Window::IndicatorVisibleMode::INVISIBLE);
131 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &WidgetApplication::Quit );
137 // Check if user requires no vsyncing and set Adaptor
138 if (mCommandLineOptions->noVSyncOnRender)
140 mAdaptor->SetUseHardwareVSync(false);
143 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
145 if( ! mStylesheet.empty() )
147 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
151 void WidgetApplication::DoStart()
153 mAdaptor->NotifySceneCreated();
156 void WidgetApplication::DoTerminate()
160 // Ensure that the render-thread is not using the surface(window) after we delete it
167 void WidgetApplication::DoLanguageChange()
169 mAdaptor->NotifyLanguageChanged();
172 void WidgetApplication::OnInit()
174 mFramework->AddAbortCallback( MakeCallback( this, &WidgetApplication::QuitFromMainLoop ) );
177 Dali::WidgetApplication widgetApplication(this);
178 mInitSignal.Emit( widgetApplication );
183 void WidgetApplication::OnTerminate()
185 Dali::WidgetApplication widgetApplication(this);
186 mTerminateSignal.Emit( widgetApplication );
191 void WidgetApplication::OnLanguageChanged()
195 Dali::WidgetApplication widgetApplication(this);
196 mLanguageChangedSignal.Emit( widgetApplication );
199 void WidgetApplication::OnRegionChanged()
201 Dali::WidgetApplication widgetApplication(this);
202 mRegionChangedSignal.Emit( widgetApplication );
205 void WidgetApplication::OnBatteryLow()
207 Dali::WidgetApplication widgetApplication(this);
208 mBatteryLowSignal.Emit( widgetApplication );
211 void WidgetApplication::OnMemoryLow()
213 Dali::WidgetApplication widgetApplication(this);
214 mMemoryLowSignal.Emit( widgetApplication );
217 bool WidgetApplication::AddIdle( CallbackBase* callback )
219 return mAdaptor->AddIdle( callback );
222 Dali::Window WidgetApplication::GetWindow()
227 Dali::Adaptor& WidgetApplication::GetAdaptor()
232 std::string WidgetApplication::GetResourcePath()
234 return Internal::Adaptor::Framework::GetResourcePath();
237 } // namespace Adaptor
239 } // namespace Internal