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 "separate-update-render-controller.h"
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>
38 SeparateUpdateRenderController::SeparateUpdateRenderController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions )
39 : ThreadControllerInterface(),
40 mAdaptorInterfaces( adaptorInterfaces ),
41 mUpdateThread( NULL ),
42 mRenderThread( NULL ),
43 mVSyncNotifier( NULL ),
45 mNumberOfVSyncsPerRender( environmentOptions.GetRenderRefreshRate() )
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 );
55 // Set the thread-synchronization interface on the render-surface
56 RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
59 currentSurface->SetThreadSynchronization( *mThreadSync );
63 SeparateUpdateRenderController::~SeparateUpdateRenderController()
65 delete mVSyncNotifier;
71 void SeparateUpdateRenderController::Initialize()
73 // Notify the synchronization object before starting the threads
74 mThreadSync->Initialise();
76 // We want to the threads to be set up before they start
77 mUpdateThread->Start();
78 mRenderThread->Start();
79 mVSyncNotifier->Start();
82 void SeparateUpdateRenderController::Start()
87 void SeparateUpdateRenderController::Pause()
92 void SeparateUpdateRenderController::Resume()
94 mThreadSync->Resume();
97 void SeparateUpdateRenderController::Stop()
99 // Notify the synchronization object before stopping the threads
102 mVSyncNotifier->Stop();
103 mUpdateThread->Stop();
104 mRenderThread->Stop();
107 void SeparateUpdateRenderController::RequestUpdate()
109 mThreadSync->UpdateRequest();
112 void SeparateUpdateRenderController::RequestUpdateOnce()
114 // if we are paused, need to allow one update
115 mThreadSync->UpdateOnce();
118 void SeparateUpdateRenderController::ReplaceSurface( RenderSurface* newSurface )
120 // Set the thread-syncronization on the new surface
121 newSurface->SetThreadSynchronization( *mThreadSync );
123 // tell render thread to start the replace. This call will block until the replace
125 RenderSurface* currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
127 // Ensure the current surface releases any locks to prevent deadlock.
128 currentSurface->StopRender();
130 mThreadSync->ReplaceSurface( newSurface );
133 void SeparateUpdateRenderController::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender )
135 mNumberOfVSyncsPerRender = numberOfVSyncsPerRender;
136 mThreadSync->SetRenderRefreshRate(numberOfVSyncsPerRender);
139 } // namespace Adaptor
141 } // namespace Internal