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 18 #include "pipeline/rs_render_thread.h" 19 #include "ui/rs_ui_director.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 CreateRenderThreadClient()24std::unique_ptr<RSIRenderClient> RSIRenderClient::CreateRenderThreadClient() 25 { 26 return std::make_unique<RSRenderThreadClient>(); 27 } 28 CommitTransaction(std::unique_ptr<RSTransactionData> & transactionData)29void RSRenderThreadClient::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) 30 { 31 RSRenderThread::Instance().RecvTransactionData(transactionData); 32 } 33 ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask> & task)34void RSRenderThreadClient::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) 35 { 36 std::mutex mutex; 37 std::unique_lock<std::mutex> lock(mutex); 38 std::condition_variable cv; 39 auto& renderThread = RSRenderThread::Instance(); 40 renderThread.PostTask([task, &cv, &renderThread]() { 41 if (task == nullptr) { 42 return; 43 } 44 task->Process(renderThread.GetContext()); 45 cv.notify_all(); 46 }); 47 cv.wait_for(lock, std::chrono::nanoseconds(task->GetTimeout())); 48 } 49 50 } // namespace Rosen 51 } // namespace OHOS 52