2 * Copyright (c) 2014 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 "update-render-controller.h"
22 #include <base/update-thread.h>
23 #include <base/render-thread.h>
24 #include <base/update-render-synchronization.h>
25 #include <base/vsync-notifier.h>
26 #include <base/interfaces/adaptor-internal-services.h>
27 #include <base/environment-options.h>
38 UpdateRenderController::UpdateRenderController( AdaptorInternalServices& adaptorInterfaces,
39 const EnvironmentOptions& environmentOptions )
40 : mAdaptorInterfaces( adaptorInterfaces ),
41 mUpdateThread( NULL ),
42 mRenderThread( NULL ),
43 mVSyncNotifier( NULL ),
44 mUpdateRenderSync( NULL ),
45 mNumberOfVSyncsPerRender( 1 )
47 mUpdateRenderSync = new UpdateRenderSynchronization( adaptorInterfaces, mNumberOfVSyncsPerRender );
49 mUpdateThread = new UpdateThread( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
51 mRenderThread = new RenderThread( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
53 mVSyncNotifier = new VSyncNotifier( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
56 UpdateRenderController::~UpdateRenderController()
58 delete mVSyncNotifier;
61 delete mUpdateRenderSync;
64 void UpdateRenderController::Start()
66 // Notify the synchronization object before starting the threads
67 mUpdateRenderSync->Start();
69 mUpdateThread->Start();
70 mRenderThread->Start();
71 mVSyncNotifier->Start();
74 void UpdateRenderController::Pause()
76 mUpdateRenderSync->Pause();
78 // if update thread is napping, wake it up to get it to pause in correct place
79 mUpdateRenderSync->UpdateRequested();
82 void UpdateRenderController::ResumeFrameTime()
84 mUpdateRenderSync->ResumeFrameTime();
87 void UpdateRenderController::Resume()
89 mUpdateRenderSync->Resume();
92 void UpdateRenderController::Stop()
94 // Notify the synchronization object before stopping the threads
95 mUpdateRenderSync->Stop();
97 mVSyncNotifier->Stop();
98 mUpdateThread->Stop();
99 mRenderThread->Stop();
102 void UpdateRenderController::RequestUpdate()
104 mUpdateRenderSync->UpdateRequested();
107 void UpdateRenderController::RequestUpdateOnce()
109 // we may be sleeping
110 mUpdateRenderSync->UpdateRequested();
111 // if we are paused, need to allow one update
112 mUpdateRenderSync->UpdateWhilePaused();
115 void UpdateRenderController::ReplaceSurface( RenderSurface* newSurface )
117 // tell render thread to start the replace. This call will block until the replace
119 RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
121 // Ensure the current surface releases any locks to prevent deadlock.
122 currentSurface->StopRender();
124 mUpdateRenderSync->ReplaceSurface( newSurface );
127 void UpdateRenderController::NewSurface( RenderSurface* newSurface )
129 // This API shouldn't be used when there is a current surface, but check anyway.
130 RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
133 currentSurface->StopRender();
136 mUpdateRenderSync->NewSurface( newSurface );
139 void UpdateRenderController::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender )
141 mNumberOfVSyncsPerRender = numberOfVSyncsPerRender;
142 mUpdateRenderSync->SetRenderRefreshRate(numberOfVSyncsPerRender);
146 } // namespace Adaptor
148 } // namespace Internal