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