Moved ECore specific indicator-impl out of common
[platform/core/uifw/dali-adaptor.git] / adaptors / base / separate-update-render / separate-update-render-controller.cpp
1 /*
2  * Copyright (c) 2015 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 "separate-update-render-controller.h"
20
21 // INTERNAL INCLUDES
22 #include <base/separate-update-render/update-thread.h>
23 #include <base/separate-update-render/render-thread.h>
24 #include <base/separate-update-render/thread-synchronization.h>
25 #include <base/separate-update-render/vsync-notifier.h>
26 #include <base/interfaces/adaptor-internal-services.h>
27 #include <base/environment-options.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 SeparateUpdateRenderController::SeparateUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions )
39 : ThreadControllerInterface(),
40   mAdaptorInterfaces( adaptorInterfaces ),
41   mUpdateThread( NULL ),
42   mRenderThread( NULL ),
43   mVSyncNotifier( NULL ),
44   mThreadSync( NULL ),
45   mNumberOfVSyncsPerRender( environmentOptions.GetRenderRefreshRate() )
46 {
47   mThreadSync = new ThreadSynchronization( adaptorInterfaces, mNumberOfVSyncsPerRender );
48
49   mUpdateThread = new UpdateThread( *mThreadSync, adaptorInterfaces, environmentOptions );
50
51   mRenderThread = new RenderThread( *mThreadSync, adaptorInterfaces, environmentOptions );
52
53   mVSyncNotifier = new VSyncNotifier( *mThreadSync, adaptorInterfaces, environmentOptions );
54
55   // Set the thread-synchronization interface on the render-surface
56   RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
57   if( currentSurface )
58   {
59     currentSurface->SetThreadSynchronization( *mThreadSync );
60   }
61 }
62
63 SeparateUpdateRenderController::~SeparateUpdateRenderController()
64 {
65   delete mVSyncNotifier;
66   delete mRenderThread;
67   delete mUpdateThread;
68   delete mThreadSync;
69 }
70
71 void SeparateUpdateRenderController::Initialize()
72 {
73   // Notify the synchronization object before starting the threads
74   mThreadSync->Initialise();
75
76   // We want to the threads to be set up before they start
77   mUpdateThread->Start();
78   mRenderThread->Start();
79   mVSyncNotifier->Start();
80 }
81
82 void SeparateUpdateRenderController::Start()
83 {
84   mThreadSync->Start();
85 }
86
87 void SeparateUpdateRenderController::Pause()
88 {
89   mThreadSync->Pause();
90 }
91
92 void SeparateUpdateRenderController::Resume()
93 {
94   mThreadSync->Resume();
95 }
96
97 void SeparateUpdateRenderController::Stop()
98 {
99   // Notify the synchronization object before stopping the threads
100   mThreadSync->Stop();
101
102   mVSyncNotifier->Stop();
103   mUpdateThread->Stop();
104   mRenderThread->Stop();
105 }
106
107 void SeparateUpdateRenderController::RequestUpdate()
108 {
109   mThreadSync->UpdateRequest();
110 }
111
112 void SeparateUpdateRenderController::RequestUpdateOnce()
113 {
114   // if we are paused, need to allow one update
115   mThreadSync->UpdateOnce();
116 }
117
118 void SeparateUpdateRenderController::ReplaceSurface( RenderSurface* newSurface )
119 {
120   // Set the thread-syncronization on the new surface
121   newSurface->SetThreadSynchronization( *mThreadSync );
122
123   // tell render thread to start the replace. This call will block until the replace
124   // has completed.
125   RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
126
127   // Ensure the current surface releases any locks to prevent deadlock.
128   currentSurface->StopRender();
129
130   mThreadSync->ReplaceSurface( newSurface );
131 }
132
133 void SeparateUpdateRenderController::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender )
134 {
135   mNumberOfVSyncsPerRender = numberOfVSyncsPerRender;
136   mThreadSync->SetRenderRefreshRate(numberOfVSyncsPerRender);
137 }
138
139 } // namespace Adaptor
140
141 } // namespace Internal
142
143 } // namespace Dali