2 * Copyright (c) 2015 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 "thread-controller.h"
22 #include <base/update-thread.h>
23 #include <base/render-thread.h>
24 #include <base/thread-synchronization.h>
25 #include <base/vsync-notifier.h>
26 #include <base/interfaces/adaptor-internal-services.h>
27 #include <base/environment-options.h>
38 ThreadController::ThreadController( AdaptorInternalServices& adaptorInterfaces,
39 const EnvironmentOptions& environmentOptions )
40 : mAdaptorInterfaces( adaptorInterfaces ),
41 mUpdateThread( NULL ),
42 mRenderThread( NULL ),
43 mVSyncNotifier( NULL ),
45 mNumberOfVSyncsPerRender( 1 )
47 mThreadSync = new ThreadSynchronization( adaptorInterfaces, mNumberOfVSyncsPerRender );
49 mUpdateThread = new UpdateThread( *mThreadSync, adaptorInterfaces, environmentOptions );
51 mRenderThread = new RenderThread( *mThreadSync, adaptorInterfaces, environmentOptions );
53 mVSyncNotifier = new VSyncNotifier( *mThreadSync, adaptorInterfaces, environmentOptions );
56 ThreadController::~ThreadController()
58 delete mVSyncNotifier;
64 void ThreadController::Initialize()
66 // Notify the synchronization object before starting the threads
67 mThreadSync->Initialise();
69 // We want to the threads to be set up before they start
70 mUpdateThread->Start();
71 mRenderThread->Start();
72 mVSyncNotifier->Start();
75 void ThreadController::Start()
80 void ThreadController::Pause()
85 void ThreadController::Resume()
87 mThreadSync->Resume();
90 void ThreadController::Stop()
92 // Notify the synchronization object before stopping the threads
95 mVSyncNotifier->Stop();
96 mUpdateThread->Stop();
97 mRenderThread->Stop();
100 void ThreadController::RequestUpdate()
102 mThreadSync->UpdateRequest();
105 void ThreadController::RequestUpdateOnce()
107 // if we are paused, need to allow one update
108 mThreadSync->UpdateOnce();
111 void ThreadController::ReplaceSurface( RenderSurface* newSurface )
113 // tell render thread to start the replace. This call will block until the replace
115 RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
117 // Ensure the current surface releases any locks to prevent deadlock.
118 currentSurface->StopRender();
120 mThreadSync->ReplaceSurface( newSurface );
123 void ThreadController::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender )
125 mNumberOfVSyncsPerRender = numberOfVSyncsPerRender;
126 mThreadSync->SetRenderRefreshRate(numberOfVSyncsPerRender);
129 } // namespace Adaptor
131 } // namespace Internal