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 #include "pipeline/rs_render_thread.h" 19 #ifdef ROSEN_OHOS 20 #include "platform/ohos/rs_render_service_connect_hub.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 { Instance()28RSApplicationAgentImpl& RSApplicationAgentImpl::Instance() 29 { 30 static RSApplicationAgentImpl applicationAgent; 31 return applicationAgent; 32 } 33 RegisterRSApplicationAgent()34void RSApplicationAgentImpl::RegisterRSApplicationAgent() 35 { 36 static bool isRegistered = false; 37 if (isRegistered) { 38 return; 39 } 40 isRegistered = true; 41 #ifdef ROSEN_OHOS 42 RSRenderServiceConnectHub::SetOnConnectCallback( 43 [weakThis = wptr<RSApplicationAgentImpl>(this)](sptr<RSIRenderServiceConnection>& conn) { 44 sptr<IApplicationAgent> appSptr = weakThis.promote(); 45 if (appSptr == nullptr) { 46 return; 47 } 48 conn->RegisterApplicationAgent(GetRealPid(), appSptr); 49 }); 50 #endif 51 } 52 53 #ifdef ROSEN_OHOS OnTransaction(std::shared_ptr<RSTransactionData> transactionData)54void RSApplicationAgentImpl::OnTransaction(std::shared_ptr<RSTransactionData> transactionData) 55 { 56 RS_TRACE_NAME("RSApplicationAgentImpl::OnTransaction"); 57 RSUIDirector::RecvMessages(transactionData); 58 } 59 OnRenderModeChanged(bool renderThreadNeedRender)60void RSApplicationAgentImpl::OnRenderModeChanged(bool renderThreadNeedRender) 61 { 62 RS_TRACE_NAME_FMT("RSApplicationAgentImpl::OnRenderModeChanged isUni:%d", !renderThreadNeedRender); 63 RSSystemProperties::SetRenderMode(!renderThreadNeedRender); 64 RSRenderThread::Instance().UpdateRenderMode(renderThreadNeedRender); 65 } 66 NotifyClearBufferCache()67void RSApplicationAgentImpl::NotifyClearBufferCache() 68 { 69 RS_TRACE_NAME_FMT("RSApplicationAgentImpl::NotifyClearBufferCache"); 70 RSRenderThread::Instance().NotifyClearBufferCache(); 71 } 72 #endif 73 } 74 } 75