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 <widget_base.h>
25 #include <style-monitor.h>
26 #include <command-line-options.h>
27 #include <common/adaptor-impl.h>
28 #include <common/framework.h>
29 #include <singleton-service-impl.h>
30 #include <window-impl.h>
35 namespace TizenPlatform
37 class TizenPlatformAbstraction;
51 WidgetApplicationPtr WidgetApplication::New(
54 const std::string& stylesheet)
56 WidgetApplicationPtr widgetApplication( new WidgetApplication (argc, argv, stylesheet ) );
57 return widgetApplication;
60 WidgetApplication::WidgetApplication( int* argc, char** argv[], const std::string& stylesheet )
63 mLanguageChangedSignal(),
64 mRegionChangedSignal(),
68 mContextLossConfiguration( Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS ),
69 mCommandLineOptions( NULL ),
70 mSingletonService( SingletonService::New() ),
73 mStylesheet( stylesheet ),
74 mEnvironmentOptions(),
77 // Get mName from environment options
78 mName = mEnvironmentOptions.GetWindowName();
79 if( mName.empty() && argc && ( *argc > 0 ) )
81 // Set mName from command-line args if environment option not set
85 mCommandLineOptions = new CommandLineOptions(argc, argv);
86 mFramework = new Framework( *this, argc, argv, Framework::WIDGET );
89 WidgetApplication::~WidgetApplication()
91 mSingletonService.UnregisterAll();
94 delete mCommandLineOptions;
98 void WidgetApplication::CreateAdaptor()
100 mAdaptor = Dali::Internal::Adaptor::Adaptor::New( mWindow, mContextLossConfiguration, &mEnvironmentOptions );
102 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetUseRemoteSurface( true );
105 void WidgetApplication::MainLoop()
107 // Run the application
111 void WidgetApplication::Quit()
113 // Actually quit the application.
114 AddIdle( MakeCallback( this, &WidgetApplication::QuitFromMainLoop ) );
117 void WidgetApplication::QuitFromMainLoop()
122 // This will trigger OnTerminate(), below, after the main loop has completed.
125 void WidgetApplication::DoInit()
127 mWindow = Dali::Window::New( PositionSize(), "", mEnvironmentOptions.GetWindowClassName(), 1 );
128 // Quit the application when the window is closed
129 mWindow.ShowIndicator(Dali::Window::IndicatorVisibleMode::INVISIBLE);
130 GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &WidgetApplication::Quit );
136 // Check if user requires no vsyncing and set Adaptor
137 if (mCommandLineOptions->noVSyncOnRender)
139 mAdaptor->SetUseHardwareVSync(false);
142 Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
144 if( ! mStylesheet.empty() )
146 Dali::StyleMonitor::Get().SetTheme( mStylesheet );
150 void WidgetApplication::DoStart()
152 mAdaptor->NotifySceneCreated();
155 void WidgetApplication::DoTerminate()
159 // Ensure that the render-thread is not using the surface(window) after we delete it
166 void WidgetApplication::DoLanguageChange()
168 mAdaptor->NotifyLanguageChanged();
171 void WidgetApplication::OnInit()
173 mFramework->AddAbortCallback( MakeCallback( this, &WidgetApplication::QuitFromMainLoop ) );
176 Dali::WidgetApplication widgetApplication(this);
177 mInitSignal.Emit( widgetApplication );
182 void WidgetApplication::OnTerminate()
184 Dali::WidgetApplication widgetApplication(this);
185 mTerminateSignal.Emit( widgetApplication );
190 void WidgetApplication::OnLanguageChanged()
193 Dali::WidgetApplication widgetApplication(this);
194 mLanguageChangedSignal.Emit( widgetApplication );
197 void WidgetApplication::OnRegionChanged()
199 Dali::WidgetApplication widgetApplication(this);
200 mRegionChangedSignal.Emit( widgetApplication );
203 void WidgetApplication::OnBatteryLow( Dali::DeviceStatus::Battery::Status status )
205 Dali::WidgetApplication widgetApplication(this);
206 mLowBatterySignal.Emit( status );
209 void WidgetApplication::OnMemoryLow( Dali::DeviceStatus::Memory::Status status )
211 Dali::WidgetApplication widgetApplication(this);
212 mLowMemorySignal.Emit( status );
215 bool WidgetApplication::AddIdle( CallbackBase* callback )
217 return mAdaptor->AddIdle( callback );
220 Dali::Adaptor& WidgetApplication::GetAdaptor()
225 std::string WidgetApplication::GetResourcePath()
227 return Internal::Adaptor::Framework::GetResourcePath();
230 std::string WidgetApplication::GetRegion()
232 return mFramework->GetRegion();
235 std::string WidgetApplication::GetLanguage()
237 return mFramework->GetLanguage();
240 } // namespace Adaptor
242 } // namespace Internal