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 "rs_application_agent_impl.h" 17 18 #ifdef ROSEN_OHOS 19 #include "platform/ohos/rs_render_service_connect_hub.h" 20 #include "platform/common/rs_log.h" 21 #endif 22 #include "rs_trace.h" 23 #include "ui/rs_ui_director.h" 24 #include "sandbox_utils.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 #ifdef OHOS_PLATFORM 29 static sptr<RSApplicationAgentImpl> gRSApplicationAgentImplInstance; 30 #endif Instance()31RSApplicationAgentImpl* RSApplicationAgentImpl::Instance() 32 { 33 #ifdef OHOS_PLATFORM 34 if (gRSApplicationAgentImplInstance == nullptr) { 35 std::lock_guard<std::mutex> lock(mutex_); 36 if (gRSApplicationAgentImplInstance == nullptr) { 37 gRSApplicationAgentImplInstance = new RSApplicationAgentImpl(); 38 } 39 } 40 return gRSApplicationAgentImplInstance.GetRefPtr(); 41 #else 42 return nullptr; 43 #endif 44 } 45 RegisterRSApplicationAgent()46void RSApplicationAgentImpl::RegisterRSApplicationAgent() 47 { 48 static bool isRegistered = false; 49 if (isRegistered) { 50 return; 51 } 52 isRegistered = true; 53 #ifdef ROSEN_OHOS 54 RSRenderServiceConnectHub::SetOnConnectCallback( 55 [weakThis = wptr<RSApplicationAgentImpl>(this)](sptr<RSIRenderServiceConnection>& conn) { 56 sptr<IApplicationAgent> appSptr = weakThis.promote(); 57 if (appSptr == nullptr) { 58 ROSEN_LOGE("RSApplicationAgentImpl::RegisterRSApplicationAgent appSptr is null"); 59 return; 60 } 61 // Not necessory to set pid 62 conn->RegisterApplicationAgent(0, appSptr); 63 }); 64 #endif 65 } 66 67 #ifdef ROSEN_OHOS OnTransaction(std::shared_ptr<RSTransactionData> transactionData)68void RSApplicationAgentImpl::OnTransaction(std::shared_ptr<RSTransactionData> transactionData) 69 { 70 RS_TRACE_NAME("RSApplicationAgentImpl::OnTransaction"); 71 RSUIDirector::RecvMessages(transactionData); 72 } 73 #endif 74 } 75 } 76