• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "pipeline/rs_unmarshal_thread.h"
17 
18 #include "pipeline/rs_base_render_util.h"
19 #include "pipeline/rs_main_thread.h"
20 #include "platform/common/rs_log.h"
21 #include "transaction/rs_transaction_data.h"
22 
23 namespace OHOS::Rosen {
Instance()24 RSUnmarshalThread& RSUnmarshalThread::Instance()
25 {
26     static RSUnmarshalThread instance;
27     return instance;
28 }
29 
Start()30 void RSUnmarshalThread::Start()
31 {
32     runner_ = AppExecFwk::EventRunner::Create("RSUnmarshalThread");
33     handler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
34 }
35 
PostTask(const std::function<void ()> & task)36 void RSUnmarshalThread::PostTask(const std::function<void()>& task)
37 {
38     if (handler_) {
39         handler_->PostTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE);
40     }
41 }
42 
RecvParcel(std::shared_ptr<MessageParcel> & parcel)43 void RSUnmarshalThread::RecvParcel(std::shared_ptr<MessageParcel>& parcel)
44 {
45     if (!handler_) {
46         RS_LOGE("RSUnmarshalThread::RecvParcel handler_ is nullptr");
47         return;
48     }
49     RSTaskMessage::RSTask task = [this, parcel = parcel]() {
50         auto transData = RSBaseRenderUtil::ParseTransactionData(*parcel);
51         if (!transData) {
52             return;
53         }
54         std::lock_guard<std::mutex> lock(transactionDataMutex_);
55         cachedTransactionDataMap_[transData->GetSendingPid()].emplace_back(std::move(transData));
56     };
57     PostTask(task);
58     RSMainThread::Instance()->RequestNextVSync();
59 }
60 
GetCachedTransactionData()61 TransactionDataMap RSUnmarshalThread::GetCachedTransactionData()
62 {
63     TransactionDataMap transactionData;
64     {
65         std::lock_guard<std::mutex> lock(transactionDataMutex_);
66         std::swap(transactionData, cachedTransactionDataMap_);
67     }
68     return transactionData;
69 }
70 }
71