Merge "Event handling refactoring to support EvasPlugin" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen-wayland / tizen-wearable / watch-application-impl.cpp
1 /*
2  * Copyright (c) 2016 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 <dali/internal/adaptor/tizen-wayland/tizen-wearable/watch-application-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/adaptor/common/adaptor-impl.h>
23 #include <dali/internal/system/common/environment-variables.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 namespace
35 {
36
37 unsigned int GetEnvWatchRenderRefreshRate()
38 {
39   const char* envVariable = std::getenv( DALI_WATCH_REFRESH_RATE );
40
41   return envVariable ? std::atoi( envVariable ) : 2u; // Default 30 fps
42 }
43
44 } // unnamed namespace
45
46 WatchApplicationPtr WatchApplication::New(
47   int* argc,
48   char **argv[],
49   const std::string& stylesheet,
50   Dali::WatchApplication::WINDOW_MODE windowMode)
51 {
52   WatchApplicationPtr watch ( new WatchApplication (argc, argv, stylesheet, windowMode ) );
53   return watch;
54 }
55
56 WatchApplication::WatchApplication( int* argc, char** argv[], const std::string& stylesheet, Dali::Application::WINDOW_MODE windowMode )
57 : Application(argc, argv, stylesheet, windowMode, PositionSize(), Framework::WATCH),
58   mState( UNINITIALIZED )
59 {
60 }
61
62 WatchApplication::~WatchApplication()
63 {
64 }
65
66 void WatchApplication::OnInit()
67 {
68   Application::OnInit();
69
70   Dali::Adaptor::Get().SetRenderRefreshRate( GetEnvWatchRenderRefreshRate() );
71
72   mState = INITIALIZED;
73 }
74
75 void WatchApplication::OnTerminate()
76 {
77   Application::OnTerminate();
78
79   mState = TERMINATED;
80 }
81
82 void WatchApplication::OnResume()
83 {
84   Application::OnResume();
85
86   mState = RESUMED;
87 }
88
89 void WatchApplication::OnPause()
90 {
91   Application::OnPause();
92
93   mState = PAUSED;
94 }
95
96 void WatchApplication::OnTimeTick(WatchTime& time)
97 {
98   Dali::WatchApplication watch(this);
99   mTickSignal.Emit( watch, time );
100
101   if(mState == PAUSED)
102   {
103     // This is a pre-resume scenario. All rendering engine of tizen SHOULD forcely update once at this time.
104     Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() ).RequestUpdateOnce();
105   }
106
107   // A watch application will queue messages to update the UI in the signal emitted above
108   // Process these immediately to avoid a blinking issue where the old time is briefly visible
109   CoreEventInterface& eventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
110   eventInterface.ProcessCoreEvents();
111 }
112
113 void WatchApplication::OnAmbientTick(WatchTime& time)
114 {
115   Dali::WatchApplication watch(this);
116   mAmbientTickSignal.Emit( watch, time );
117
118   // A watch application will queue messages to update the UI in the signal emitted above
119   // Process these immediately to avoid a blinking issue where the old time is briefly visible
120   CoreEventInterface& eventInterface = Internal::Adaptor::Adaptor::GetImplementation( GetAdaptor() );
121   eventInterface.ProcessCoreEvents();
122 }
123
124 void WatchApplication::OnAmbientChanged(bool ambient)
125 {
126   Dali::WatchApplication watch(this);
127   mAmbientChangeSignal.Emit( watch, ambient );
128 }
129
130 } // namespace Adaptor
131
132 } // namespace Internal
133
134 } // namespace Dali