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>
39 UpdateRenderController::UpdateRenderController( AdaptorInternalServices& adaptorInterfaces,
40 const EnvironmentOptions& environmentOptions ): mUpdateThread( NULL ),
41 mRenderThread( NULL ),
42 mVSyncNotifier( NULL ),
43 mUpdateRenderSync( NULL )
46 mUpdateRenderSync = new UpdateRenderSynchronization( adaptorInterfaces );
48 mUpdateThread = new UpdateThread( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
50 mRenderThread = new RenderThread( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
52 mVSyncNotifier = new VSyncNotifier( *mUpdateRenderSync, adaptorInterfaces, environmentOptions );
55 UpdateRenderController::~UpdateRenderController()
57 delete mVSyncNotifier;
60 delete mUpdateRenderSync;
63 void UpdateRenderController::Start()
65 // Notify the synchronization object before starting the threads
66 mUpdateRenderSync->Start();
68 mUpdateThread->Start();
69 mRenderThread->Start();
70 mVSyncNotifier->Start();
73 void UpdateRenderController::Pause()
75 mUpdateRenderSync->Pause();
76 // if update thread is napping, wake it up to get it to pause in correct place
77 mUpdateRenderSync->UpdateRequested();
80 void UpdateRenderController::Resume()
82 mUpdateRenderSync->Resume();
85 void UpdateRenderController::Stop()
87 // Notify the synchronization object before stopping the threads
88 mUpdateRenderSync->Stop();
90 mVSyncNotifier->Stop();
91 mUpdateThread->Stop();
92 mRenderThread->Stop();
95 void UpdateRenderController::RequestUpdate()
97 mUpdateRenderSync->UpdateRequested();
100 void UpdateRenderController::RequestUpdateOnce()
102 // we may be sleeping
103 mUpdateRenderSync->UpdateRequested();
104 // if we are paused, need to allow one update
105 mUpdateRenderSync->UpdateWhilePaused();
108 void UpdateRenderController::ReplaceSurface( RenderSurface* surface )
110 // tell render thread to start the replace
111 mRenderThread->ReplaceSurface(surface);
113 // Ensure that a frame gets processed and render thread runs at least once
114 // Note: ReplaceSurface may be called while threads are paused so call
115 // RequestUpdateOnce to ensure we do an update/render pass even if paused
118 // block here until replace complete
119 mRenderThread->WaitForSurfaceReplaceComplete();
122 void UpdateRenderController::RenderSync()
124 mRenderThread->RenderSync();
127 void UpdateRenderController::DisableVSync()
129 mRenderThread->SetVSyncMode( EglInterface::NO_SYNC );
132 } // namespace Adaptor
134 } // namespace Internal