1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "rs_render_thread_client.h"
17 #include <memory>
18 
19 #include "pipeline/rs_render_thread.h"
20 #include "ui/rs_ui_director.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
CreateRenderThreadClient()25 std::unique_ptr<RSIRenderClient> RSIRenderClient::CreateRenderThreadClient()
26 {
27     return std::make_unique<RSRenderThreadClient>();
28 }
29 
CommitTransaction(std::unique_ptr<RSTransactionData> & transactionData)30 void RSRenderThreadClient::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
31 {
32     RSRenderThread::Instance().RecvTransactionData(transactionData);
33 }
34 
ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask> & task)35 void RSRenderThreadClient::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
36 {
37     std::mutex mutex;
38     std::unique_lock<std::mutex> lock(mutex);
39     auto cv = std::make_shared<std::condition_variable>();
40     auto& renderThread = RSRenderThread::Instance();
41     renderThread.PostTask([task, cv, &renderThread]() {
42         if (task == nullptr) {
43             return;
44         }
45         task->Process(renderThread.GetContext());
46         cv->notify_all();
47     });
48     cv->wait_for(lock, std::chrono::nanoseconds(task->GetTimeout()));
49 }
50 
51 } // namespace Rosen
52 } // namespace OHOS
53