diff --git a/bundle.json b/bundle.json index b94b4ffb51612700cc4f47dd6b1b4ffafc2fb5d8..2e6001cc95a44038ad4a4751f821e3aae8868fb8 100644 --- a/bundle.json +++ b/bundle.json @@ -164,6 +164,7 @@ "//foundation/graphic/graphic_2d:default", "//foundation/graphic/graphic_2d/rosen/modules/render_service:librender_service", "//foundation/graphic/graphic_2d/rosen/modules/render_service:render_service", + "//foundation/graphic/graphic_2d/rosen/modules/render_service:render_process", "//foundation/graphic/graphic_2d/interfaces/kits/cj/ui_effect:cj_ui_effect_ffi", "//foundation/graphic/graphic_2d/etc:ohos.para.dac", "//foundation/graphic/graphic_2d/etc:ohos.para" diff --git a/rosen/modules/render_service/BUILD.gn b/rosen/modules/render_service/BUILD.gn index 65c98d9fb2e8650543f897fb278e02518bb01925..1966435eca14f9a84eb73c0f93c2e4454c8a7d08 100644 --- a/rosen/modules/render_service/BUILD.gn +++ b/rosen/modules/render_service/BUILD.gn @@ -168,6 +168,23 @@ ohos_shared_library("librender_service") { "core/transaction/rs_render_service_security_utils.cpp", "core/transaction/rs_render_service_stub.cpp", "core/transaction/rs_unmarshal_thread.cpp", + "core/pipeline/render_process/rs_render_process_connection.cpp", + "core/pipeline/render_process/rs_render_compose_connection.cpp", + "core/pipeline/render_process/rs_render_render_connection.cpp", + ] + + #main + sources += [ + "main/render_process/rs_render_process_service.cpp", + "main/server/rs_render_process_service_manager.cpp", + "main/server/rs_render_service.cpp", + ] + + #transaction + sources += [ + "transaction/rs_render_process_connection_stub.cpp", + "transaction/rs_render_compose_connection_stub.cpp", + "transaction/rs_render_render_connection_stub.cpp", ] #feature_cfg @@ -348,6 +365,10 @@ ohos_shared_library("librender_service") { "core/feature_cfg/xml_parser/extend_feature_parser", "core/feature_cfg/xml_parser/performance_feature_parser", "core/round_corner_display", + "main", + "main/server", + "main/render_process", + "transaction", "$graphic_2d_root/rosen/include", "$graphic_2d_root/rosen/modules/2d_graphics", "$graphic_2d_root/rosen/modules/composer/vsync/include", @@ -583,10 +604,12 @@ ohos_executable("render_service") { ubsan = true } } - sources = [ "core/main.cpp" ] + sources = [ "main/server/main.cpp" ] include_dirs = [ "core", + "transaction", + "main", "$graphic_2d_root/interfaces/inner_api/common", "$graphic_2d_root/utils/color_manager/export", "$graphic_2d_root/utils/socketpair/export", @@ -617,3 +640,37 @@ ohos_executable("render_service") { part_name = "graphic_2d" subsystem_name = "graphic" } + +## Build render_process.bin +ohos_executable("render_process") { + install_enable = true + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + sources = [ "main/render_process/rs_render_process_main.cpp" ] + + include_dirs = [ + "core", + "transaction", + "main", + ] + + deps = [ + "$graphic_2d_root/rosen/modules/render_service_base:librender_service_base", + "$graphic_2d_root/rosen/modules/render_service:librender_service", + ] + + external_deps = [ + "c_utils:utils", + "graphic_surface:surface", + "hilog:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "graphic_2d" + subsystem_name = "graphic" +} \ No newline at end of file diff --git a/rosen/modules/render_service/composer/README.md b/rosen/modules/render_service/composer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9687c9a4543ae5a150e530ed6d79c03b303770f1 --- /dev/null +++ b/rosen/modules/render_service/composer/README.md @@ -0,0 +1 @@ +# composer \ No newline at end of file diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.cpp index 9065adffb5903462da6d0ecada6cf6fd09582261..92cd693c17eeba45965d0b021b07ba65d22275ae 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.cpp @@ -439,7 +439,9 @@ void RSMainThread::TraverseCanvasDrawingNodesNotOnTree() }); } -void RSMainThread::Init() +void RSMainThread::Init(std::shared_ptr runner, + std::shared_ptr handler, + std::shared_ptr receiver) { mainLoop_ = [&]() { RS_PROFILER_ON_FRAME_BEGIN(timestamp_); @@ -601,8 +603,8 @@ void RSMainThread::Init() } RS_LOGI("thread init"); - runner_ = AppExecFwk::EventRunner::Create(false); - handler_ = std::make_shared(runner_); + runner_ = runner; + handler_ = handler; uint32_t timeForWatchDog = WATCHDOG_TIMEVAL; int ret = HiviewDFX::Watchdog::GetInstance().AddThread("RenderService", handler_, timeForWatchDog); if (ret != 0) { @@ -613,11 +615,12 @@ void RSMainThread::Init() #endif InitRSEventDetector(); RS_LOGI("VSync init"); - sptr token = new IRemoteStub(); - sptr conn = new VSyncConnection(rsVSyncDistributor_, "rs", token->AsObject()); - conn->id_ = hgmContext_.GetRSFrameRateLinker()->GetId(); - rsVSyncDistributor_->AddConnection(conn); - receiver_ = std::make_shared(conn, token->AsObject(), handler_, "rs"); + // sptr token = new IRemoteStub(); + // sptr conn = new VSyncConnection(rsVSyncDistributor_, "rs", token->AsObject()); + // conn->id_ = hgmContext_.GetRSFrameRateLinker()->GetId(); + // rsVSyncDistributor_->AddConnection(conn); + // receiver_ = std::make_shared(conn, token->AsObject(), handler_, "rs"); + receiver_ = receiver; receiver_->Init(); if (!isUniRender_) { renderEngine_ = std::make_shared(); @@ -633,7 +636,7 @@ void RSMainThread::Init() auto GCNotifyTaskProxy = [](bool isEnable) { RSRenderNodeGC::Instance().SetGCTaskEnable(isEnable); }; - conn->SetGCNotifyTask(GCNotifyTaskProxy); + // conn->SetGCNotifyTask(GCNotifyTaskProxy); RSScreenRenderNode::SetReleaseTask([](ScreenId id) { auto screenManager = CreateOrGetScreenManager(); if (screenManager == nullptr) { diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.h b/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.h index f52863bfdffb2a459994be3d619938feef6c51b5..09c3192296694d384ff0dba79c6dd7f2e140769e 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.h +++ b/rosen/modules/render_service/core/pipeline/main_thread/rs_main_thread.h @@ -94,7 +94,9 @@ class RSMainThread { public: static RSMainThread* Instance(); - void Init(); + void Init(std::shared_ptr runner, + std::shared_ptr handler, + std::shared_ptr receiver); void Start(); bool IsNeedProcessBySingleFrameComposer(std::unique_ptr& rsTransactionData); void UpdateFocusNodeId(NodeId focusNodeId); diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_connection.h b/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_connection.h index e1d2e2ada45674044a9accd47bd641c4222ab3bb..76312f1fb2839dbf56f77aac38d5c1870b5f2b4e 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_connection.h +++ b/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_connection.h @@ -24,7 +24,7 @@ #include "ipc_callbacks/buffer_clear_callback.h" #include "pipeline/hardware_thread/rs_hardware_thread.h" #include "pipeline/render_thread/rs_uni_render_thread.h" -#include "pipeline/main_thread/rs_render_service.h" +#include "../../main/server/rs_render_service.h" #include "screen_manager/rs_screen_manager.h" #include "transaction/rs_render_service_connection_stub.h" #include "vsync_distributor.h" diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_listener.h b/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_listener.h index eac64130b4119ab7be685d99b759dce67431df34..f475c3b3bb5049a60115a6b5dc29dcda3dfe2d84 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_listener.h +++ b/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service_listener.h @@ -19,7 +19,7 @@ #include "pipeline/rs_surface_render_node.h" #include "platform/common/rs_log.h" -#include "rs_render_service.h" +#include "../../main/server/rs_render_service.h" namespace OHOS { namespace Rosen { diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.cpp b/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..753d7d01bdf60b66bf131672f11f8c303d45e47b --- /dev/null +++ b/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_compose_connection.h" + +namespace OHOS { +namespace Rosen { +RSRenderComposeConnection::RSRenderComposeConnection(RSRenderService& renderComposeService, sptr rsVSyncDistributor) : + renderComposeService_(renderComposeService), + rsVsyncDistributor_(rsVSyncDistributor) +{ +} + +sptr RSRenderComposeConnection::CreateVSyncConnection(const sptr& token) +{ + if (!token) { + return nullptr; + } + auto tokenObj = token->AsObject(); + + sptr newConn(new VSyncConnection(rsVsyncDistributor_, "rs", tokenObj)); + rsVsyncDistributor_->AddConnection(newConn); + + return newConn; +} +} +} \ No newline at end of file diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.h b/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..8cf084d9fc9b28784b1b6113e86580d3491a7826 --- /dev/null +++ b/rosen/modules/render_service/core/pipeline/render_process/rs_render_compose_connection.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../../../main/server/rs_render_service.h" +#include "../transaction/rs_render_compose_connection_stub.h" + +namespace OHOS { +namespace Rosen { +public: + RSRenderComposeConnection(RSRenderService& renderComposeService, sptr rsVSyncDistributor); + virtual ~RSRenderComposeConnection() noexcept = default + + sptr CreateVSyncConnection(const sptr& token) override; + +private: + RSRenderService& renderComposeService_; + sptr rsVSyncDistributor_; +} +} \ No newline at end of file diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_process_connection.cpp b/rosen/modules/render_service/core/pipeline/render_process/rs_render_process_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_process_connection.h b/rosen/modules/render_service/core/pipeline/render_process/rs_render_process_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..79fbf48bef203090b36068bfdd539542e3b33749 --- /dev/null +++ b/rosen/modules/render_service/core/pipeline/render_process/rs_render_process_connection.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../../../main/server/rs_render_service.h" +#include "../transaction/rs_render_compose_connection_stub.h" + +namespace OHOS { +namespace Rosen { +class RSRenderProcessConnection : public RSRenderProcessConnectionStub { +public: + RSRenderProcessConnection(RSRenderService& renderProcessService) : + renderProcessService_(renderProcessSerivce) {} + virtual ~RSRenderProcessConnection() noexcept = default + +private: + RSRenderProcess& renderProcessService_; +} +} +} \ No newline at end of file diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_render_connection.cpp b/rosen/modules/render_service/core/pipeline/render_process/rs_render_render_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/rosen/modules/render_service/core/pipeline/render_process/rs_render_render_connection.h b/rosen/modules/render_service/core/pipeline/render_process/rs_render_render_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..debcdf80caab81c942e7778a3898123688cbb915 --- /dev/null +++ b/rosen/modules/render_service/core/pipeline/render_process/rs_render_render_connection.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../../../main/server/rs_render_service.h" +#include "../transaction/rs_render_compose_connection_stub.h" + +namespace OHOS { +namespace Rosen { +class RSRenderRenderConnection : public RSRenderRenderConnectionStub { +public: + RSRenderRenderConnection(RSRenderService& renderProcessService) : + renderProcessService_(renderProcessSerivce) {} + virtual ~RSRenderProcessConnection() noexcept = default + +private: + mutalble std::mutex mutex_; + pid_t remotePid; + wptr renderProcessService_; + sptr token_; +} +} +} \ No newline at end of file diff --git a/rosen/modules/render_service/core/transaction/rs_render_service_stub.cpp b/rosen/modules/render_service/core/transaction/rs_render_service_stub.cpp index 34b24586fcca0f7b92a5671096165edfb4485882..58e1bccb6921c28053aeb8387b28057774cebb01 100644 --- a/rosen/modules/render_service/core/transaction/rs_render_service_stub.cpp +++ b/rosen/modules/render_service/core/transaction/rs_render_service_stub.cpp @@ -85,6 +85,31 @@ int RSRenderServiceStub::OnRemoteRequest( } break; } + case static_cast(RSIRenderServiceInterfaceCode::REGISTER_RENDER_PROCESS_CONNECTION): { + auto interfaceToken = data.ReadInterfaceToken(); + if (interfaceToken != RSIRenderService::GetDescriptor()) { + RS_LOGE("RSRenderServiceStub::CREATE_CONNECTION Read interfaceToken failed!"); + ret = ERR_INVALID_STATE; + break; + } + + auto remoteObj = data.ReadRemoteObject(); + if (remoteObj == nullptr) { + RS_LOGE("RSRenderServiceStub::CREATE_CONNECTION Read remoteObj failed!"); + ret = ERR_NULL_OBJECT; + break; + } + if (!remoteObj->IsProxyObject()) { + ret = ERR_UNKNOWN_OBJECT; + break; + } + + auto newConn = ReigsterRenderProcessConnection(iface_cast(remoteObj)); + if (newConn != nullptr) { + reply.WriteRemoteObject(newConn->AsObject()) + } + break; + } default: { return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/rosen/modules/render_service/main/render_process/README.md b/rosen/modules/render_service/main/render_process/README.md new file mode 100644 index 0000000000000000000000000000000000000000..207e77edd927c17dc142d82d835058ae1d06d2b2 --- /dev/null +++ b/rosen/modules/render_service/main/render_process/README.md @@ -0,0 +1 @@ +# render_process \ No newline at end of file diff --git a/rosen/modules/render_service/main/render_process/rs_render_process.cpp b/rosen/modules/render_service/main/render_process/rs_render_process.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d1891d6ee18327e90d22baa3d7bac52361e9654 --- /dev/null +++ b/rosen/modules/render_service/main/render_process/rs_render_process.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_process.h" + +#include +#include +#include +#include +#include +#include +#include +#include "platform/common/rs_system_properties.h" + +#include "pipelien/render_process/rs_render_process_connection.h" +#include "pipeline/main_thread/rs_main_thread.h" +#include "rs_trace.h" +#include "graphic_feature_param_manager.h" +#include "pipeline/rs_uni_render_judgement.h" + +#undef LOG_TAG +#define LOG_TAG "RSRenderProcess" + +namespace OHOS { +namespace Rosen{ +namespace { +sptr ConnectToServer() +{ + int tryCnt = 0; + sptr renderService = nullptr; + do { + // sleep move time (1000us * tryCnt) when tryCnt++ + usleep(1000 * tryCnt); + ++tryCnt; + // try most 5 times to get render service. + if (tryCnt == 5) { + RS_LOGE("%{public}s: tried 5 times.", __func__); + break; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + RS_LOGE("%{public}s: samgr is null.", __func__); + continue; + } + auto remoteObject = samgr->GetSystemAbility(RENDER_SERVICE); + if (remoteObject == nullptr) { + RS_LOGE("%{public}s: remoteObject is null.", __func__); + continue; + } + renderService = iface_cast(remoteObject); + if (renderService != nullptr) { + RS_LOGE("%{public}s: renderService is null.", __func__); + break; + } + } while (true); + + if (renderService == nullptr) { + RS_LOGE("%{public}s: Failed to get renderService proxy.", __func__); + return nullptr; + } + return renderService; +} +} + +bool RSRenderProcess::Init() +{ + // 注册子进程到主进程 + RS_LOGD("%{public}s: Init.", __func__); + if (!RegisterRenderProcessConnection()) { + RS_LOGE("%{public}s: renderProcess registration failed.", __func__); + return false; + } + + // 多进程独有初始化 + + // 核心组件初始化 + // 子进程runner_, handler_ + runner_ = AppExecFwk::EventRunner::Create(false); + handler_ = std::make_shared(runner_); + + // receiver_ + sptr token = new IRemoteStub(); + sptr conn = renderComposeConnection_->CreateVSyncConnection(token); + receiver_ = std::mak_shared(conn, token->AsObject(), handler_, "rs"); + + // 渲染管线拉起 + // mainThread_ = RSMainThread::Instance(); + // mainThread_->Init(runner_, handler_, receiver_); + + return true; +} + +void RSRenderProcess::Run() +{ + // 消息队列死循环 + if (runner_) { + RS_LOGI("fqy %{public}s: SubProcess Run", __func__); + runner_->Run(); + } +} + +sptr RSRenderProcess::GetRenderServer() +{ + // 到sa获取主进程 + if (renderServer_ == nullptr) { + renderServer_ = ConnectToServer(); + } + return renderServer_; +} + +bool RSRenderProcess:RegisterRenderProcessConnection() +{ + // 注册子进程到主进程 + auto renderServer = GetRenderServer(); + if (UNLIKELY(renderServer == nullptr)) { + RS_LOGE("%{public}s: renderServer is null.", __func__); + return false; + } + + // TODO: 需要一个接口获取当前子进程的screenId + // auto screenId = GetScreenId(); + auto screenId = 0; + auto renderProcessConnection = sptr::MakeSptr(*this); + auto renderComposeConnection = renderServer->RegisterRenderProcessConnection(renderProcessConnection, screenId); + if (renderComposeConnection_ == nullptr) { + RS_LOGE("%{public}s: renderComposeConnection is null.", __func__); + return false; + } + + // TODO: 添加死亡监听 + + return true; +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/main/render_process/rs_render_process.h b/rosen/modules/render_service/main/render_process/rs_render_process.h new file mode 100644 index 0000000000000000000000000000000000000000..c5dd0d2b0e5f164d575bfeb719024eff7ef43766 --- /dev/null +++ b/rosen/modules/render_service/main/render_process/rs_render_process.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RS_RENDER_SERVICE_MAIN_RENDER_PROCESS_RENDER_PROCESS_H +#define RS_RENDER_SERVICE_MAIN_RENDER_PROCESS_RENDER_PROCESS_H + +#include + +#include "platform/ohos/rs_irender_service.h" +#include "platform/ohos/rs_irender_compose_connection.h" +#include "platform/ohos/rs_irender_render_connection.h" + +namespace OHOS { +namespace Rosen { +class RSMainThread; +class RSRenderProcess : public RefBase { +public: + RSRenderProcess() {}; + ~RSRenderProcess() noexcept {}; + + bool Init(); + void Run(); + +private: + sptr GetRenderServer(); + bool RegisterRenderProcessConnection(); + sptr renderServer_ = nullptr; + sptr renderComposeConnection_ = nullptr; + RSMainThread* mainThread_ = nullptr; + + std::shared_ptr runner_ = nullptr; + std::shared_ptr handler_ = nullptr; + std::shared_ptr receiver_ = nullptr; + + std::map, sptr> renderConnections_; + + friend class RSRenderProcessConnection; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // RS_RENDER_SERVICE_MAIN_RENDER_PROCESS_RENDER_PROCESS_H \ No newline at end of file diff --git a/rosen/modules/render_service/main/render_process/rs_render_process_main.cpp b/rosen/modules/render_service/main/render_process/rs_render_process_main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e804b85fb6c04fcad53a47c5ea7081c5d31c4270 --- /dev/null +++ b/rosen/modules/render_service/main/render_process/rs_render_process_main.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "platform/common/rs_log.h" +#include "rs_render_process_service.h" + +#undef LOG_TAG +#define LOG_TAG "RSRenderProcessMain" + +using namespace OHOS; +using namespace OHOS::Rosen; + +int main(int argc, const char *argv[]) +{ + signal(SIGPIPE, SIG_IGN); + + sptr renderProcess(new RSRenderProcess()); + if (!renderProcess->Init()) { + RS_LOGE("%{public}s: Init Failed.", __func__); + return -1; + } + renderProcess->Run(); + + return 0; +} diff --git a/rosen/modules/render_service/main/server/README.md b/rosen/modules/render_service/main/server/README.md new file mode 100644 index 0000000000000000000000000000000000000000..59dd1d07787e4981d2b1232f4fa6c1260650de91 --- /dev/null +++ b/rosen/modules/render_service/main/server/README.md @@ -0,0 +1 @@ +# render_server \ No newline at end of file diff --git a/rosen/modules/render_service/core/main.cpp b/rosen/modules/render_service/main/server/main.cpp similarity index 100% rename from rosen/modules/render_service/core/main.cpp rename to rosen/modules/render_service/main/server/main.cpp diff --git a/rosen/modules/render_service/main/server/rs_render_process_manager.cpp b/rosen/modules/render_service/main/server/rs_render_process_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e31d39cf4c4db76cf34dce1c2d0cc6c26748cc9c --- /dev/null +++ b/rosen/modules/render_service/main/server/rs_render_process_manager.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_process_manager.h" + +#include + +#include "render_process/rs_render_process.h" +#include "rs_profiler.h" +#include "rs_trace.h" +#include "../../../include/screen_manager/screen_types.h" + +namespace OHOS { +namespace Rosen { +constexpr const char* CMD_SEP = " "; +constexpr int32_t PIPE_FD_NUM = 2; +constexpr int32_t PIPE_OUT = 0; +constexpr int32_t PIPE_IN = 1; + +RSRenderProcessManager::RSRenderProcessManager(sptr screenManager) +{ + screenManager_ = screenManager; + ScreenChangeCallback connectCallback = [this](ScreenId id, ScreenEvent event, ScreenChangeReason reason = ScreenChangeReason::DEFAULT) { + // Fork ScreenId对应子进程 + std::string out; + ForkExec("/system/bin/render_process", id, &out); + return; + }; + screenHandler_ = new RSScreenChangeHandler(connectCallback); + screenManager_->AddScreenChangeCallback(screenHandler_); +} + +inline std::vector RSRenderProcessManager::Split(const std::string& str, const std::string& sep) +{ + std::string s = str; + std::vector res; + while (!s.empty()) { + size_t pos = s.find(sep); + if (pos == std::string::npos) { + res.emplace_back(s); + break; + } + res.emplace_back(s.substr(0, pos)); + s = s.substr(pos + sep.size()); + } + return res; +} + +std::vector RSRenderProcessManager::FormatCmd(const std::vector& cmd) +{ + std::vector res; + res.reserve(cmd.size() + 1); + + // string is converted to char* and the result is saved in res + std::transform(cmd.begin(), cmd.end(), std::back_inserter(res), [](const std::string& str) { return str.c_str(); }); + res.emplace_back(nullptr); + return res; +} + +int32_t RSRenderProcessManager::ForkExecChildProcess(const int32_t* pipeFd, int32_t count, const std::vector& args) +{ + RS_LOGW("Fork OK"); + if (count != PIPE_FD_NUM) { + RS_LOGE("Fork exec parent process failed"); + _exit(-1); + } + RS_LOGW("Fork done and ready to close"); + if (close(pipeFd[PIPE_OUT]) != 0) { + RS_LOGE("Fork close failed, errorno: %{public}d, errormsg: %{public}s", errno, strerror(errno)); + _exit(-1); + } + RS_LOGW("Fork close done and ready for dup2"); + if (dup2(pipeFd[PIPE_IN], STDOUT_FILENO) == -1) { + RS_LOGE("Fork dup2 failed, errorno: %{public}d, errormsg: %{public}s", errno, strerror(errno)); + _exit(-1); + } + RS_LOGW("Fork ready for execv"); + if (execv(args[0], const_cast(&args[0])) == -1) { + RS_LOGE("Fork execv command failed, errorno: %{public}d, errormsg: %{public}s", errno, strerror(errno)); + } + RS_LOGW("Fork execv done"); + if (close(pipeFd[PIPE_IN]) != 0) { + RS_LOGE("Fork close failed, errorno: %{public}d, errormsg: %{public}s", errno, strerror(errno)); + _exit(-1); + } + _exit(-1); +} + +int32_t RSRenderProcessManager::ForkExec(const std::string& command, ScreenId screenId, std::string* out) +{ + const std::vector cmd = Split(command, CMD_SEP); + std::vector args = FormatCmd(cmd); + int32_t pipeFd[PIPE_FD_NUM] = {0}; + if (pipe(pipeFd) < 0) { + RS_LOGE("Create pipe failed, errorno: %{public}d, errornomsg: %{public}s", errno, strerrno(errno)); + return -1; + } + RS_LOGW("ForkExec"); + pid_t pid = fork(); + RS_LOGW("ForkDone %{public}d", pid); + if (pid < 0) { + RS_LOGE("Fork failed, errorno: %{public}d, errornomsg: %{public}s", errno, strerrno(errno)); + return -1; + } + if (pid == 0) { + RS_LOGW("Fork begin %{public}d", getpid()); + ForkExecChildProcess(pipeFd, PIPE_FD_NUM, args); + + // 设置screenId对应子进程pid + screenId2RenderProcess_[screenId] getpid(); + + return -1; + } else { + RS_LOGW("Fork error %{public}d", getpid()); + return -1; + } +} + +sptr RSRenderProcessManager::GetRenderProcessConnectionProxy(pid_t pid) +{ + std::unique_lock lock(mutex_); + return renderProcessConnections_[pid]; +} + +void RSRenderProcessManager::SetRenderProcessConnectionProxy(pid_t pid, sptr conn) +{ + renderProcessConnection_[pid] = conn; +} + +pid_t RSRenderProcessManager::GetRenderProcessPid(ScreenId screenId) +{ + std::unique_lock lock(mutex_); + return screenId2RenderProcess_[screenId]; +} + +void RSRenderProcessManager::RSScreenChangeHandler::OnScreenChanged(ScreenId id, ScreenEvent event, ScreenChangeReason reson) +{ + if (event == ScreenEvent::CONNECTED) { + connectCallback_(id, event, reason); + } +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/main/server/rs_render_process_manager.h b/rosen/modules/render_service/main/server/rs_render_process_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..b0c5444d39868b613731734e782cc210b4d2ac87 --- /dev/null +++ b/rosen/modules/render_service/main/server/rs_render_process_manager.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "platform/ohos/rs_irender_service.h" +#include "../render_service_base/include/screen_manager/screen_types.h" + +namespace OHOS { +namespace Rosen { +using ScreenChangeCallback = std::function; +class RSRenderProcessServiceManager : public RefBase { +public: + RSRenderProcessManager(sptr screenManager_); + ~RSRenderProcessManager() noexcept = default; + + inline std::vector Split(const std::string& str, const std::string& sep); + std::vector FormatCmd(const std::vector& cmd); + int32_t ForkExecChildProcess(const int32_t* pipeFd, int32_t count, const std::vector& args); + int32_t ForkExec(const std::string& command, ScreenId screenId, std::string* out); + + sptr GetRenderProcessConnectionProxy(pid_t pid); + pid_t GetRenderProcessPid(ScreenId screenId); + void SetRenderProcessConnectionProxy(pid_t pid, sptr conn); + +private: + mutable std::mutex mutex_; + + class RSScreenChangeHandler : public RSIScreenChangeCallback { + public: + explicit RSScreenChangeHandler(ScreenChangeCallback connectCallback) { this->connectCallback_ = connectCallback; } + ~RSScreenChangeHandler() noexcept = default; + + void OnScreenChanged(ScreenId id, ScreenEvent event, + ScreenChangeReason reason = ScreenChangeReason::DEFAULT) override; + + sptr AsObject() override { return nullptr; } + + private: + ScreenChangeCallback connectCallback_; + }; + + std::unordered_map screenId2RenderProcess_; + std::unordered_map> renderProcessConnections_; + sptr screenManager_; + sptr screenHandler_; +}; +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.cpp b/rosen/modules/render_service/main/server/rs_render_service.cpp similarity index 87% rename from rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.cpp rename to rosen/modules/render_service/main/server/rs_render_service.cpp index 867a7bf044c9e1ac5f2cdffebf0746b9b07e7908..da57ddcfd0ab1fe990abf2eb6a80ff2131b2e47a 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.cpp +++ b/rosen/modules/render_service/main/server/rs_render_service.cpp @@ -27,9 +27,10 @@ #include "hgm_core.h" #include "memory/rs_memory_manager.h" #include "parameter.h" -#include "rs_main_thread.h" +#include "../../pipeline/main_thread/rs_main_thread.h" #include "rs_profiler.h" -#include "rs_render_service_connection.h" +#include "../../pipeline/main_thread/rs_render_service_connection.h" +#include "../../pipeline/render_process/rs_render_compose_connection.h" #include "vsync_generator.h" #include "rs_trace.h" #include "ge_mesa_blur_shader_filter.h" @@ -80,6 +81,90 @@ RSRenderService::RSRenderService() {} RSRenderService::~RSRenderService() noexcept {} +void RSRenderService::ParseXml() +{ + // 多屏xml解析 + return; +} + +bool RSRenderService::Init_V2() +{ + // 读取xml,确认渲染模式 + RS_LOGI("fangqiyuan mainProcess init"); + auto isMultiProcess = false; + ParseXml(); + { + // TODO: 读取多进程xml + + // 读取xml + RSUniRenderJudgement::InitUniRenderConfig(); + // feature param parse + GraphicFeatureParamManager::GetInstance().Init(); + // need called after GraphicFeatureParamManager::GetInstance().Init(); + FilterCCMInit(); + } + + CoreComponentsInit(); + { + // screenManager实例化 + screenManager_ = CreateOrGetScreenManager(); + + // 初始化vSync + vsyncGenerator_ = CreateVSyncGenerator(); + // The offset needs to be set + int64_t offset = 0; + if (!HgmCore::Instance().GetLtpoEnabled()) { + if (RSUniRenderJudgement::GetUniRenderEnabledType() == UniRenderEnabledType::UNI_RENDER_ENABLED_FOR_ALL) { + offset = HgmCore::Instance().IsDelayMode() ? UNI_RENDER_VSYNC_OFFSET_DELAY_MODE : UNI_RENDER_VSYNC_OFFSET; + } + rsVSyncController_ = new VSyncController(vsyncGenerator_, offset); + appVSyncController_ = new VSyncController(vsyncGenerator_, offset); + } else { + rsVSyncController_ = new VSyncController(vsyncGenerator_, 0); + appVSyncController_ = new VSyncController(vsyncGenerator_, 0); + vsyncGenerator_->SetVSyncMode(VSYNC_MODE_LTPO); + } + DVSyncFeatureParam dvsyncParam; + InitDVSyncParams(dvsyncParam); + rsVSyncDistributor_ = new VSyncDistributor(rsVSyncController_, "rs", dvsyncParam); + appVSyncDistributor_ = new VSyncDistributor(appVSyncController_, "app", dvsyncParam); + + vsyncGenerator_->SetRSDistributor(rsVSyncDistributor_); + vsyncGenerator_->SetAppDistributor(appVSyncDistributor_); + + // renderProcessServiceManager创建 + renderProcessManager_ = new RSRenderProcessManager(screenManager_); + + // TODO: screenManager_初始化 + + // 初始化runner_, handler_ + runner_ = AppExecFwk::EventRunner::Create(false); + handler_ = std::make_shared(runner_); + } + + // 单进程模式拉起管线 + bool isSuccess = false; + if (!isMultiProcess) { + isSucess = Init(); + } + + if (!isSuccess) { + return false; + } + + // 注册RS到SA Mgr + if (!SAMgrRegister()) { + return false; + } + + return true; +} + +bool RSRenderService::CoreComponentsInit() +{ + return true; +} + bool RSRenderService::Init() { system::SetParameter(BOOTEVENT_RENDER_SERVICE_READY.c_str(), "false"); @@ -101,19 +186,11 @@ if (Drawing::SystemProperties::IsUseVulkan()) { } #endif RSMainThread::Instance(); - RSUniRenderJudgement::InitUniRenderConfig(); - - // feature param parse - GraphicFeatureParamManager::GetInstance().Init(); - - // need called after GraphicFeatureParamManager::GetInstance().Init(); - FilterCCMInit(); // load optimization params init LoadOptParams loadOptParams; InitLoadOptParams(loadOptParams); - screenManager_ = CreateOrGetScreenManager(); if (screenManager_ != nullptr) { screenManager_->InitLoadOptParams(loadOptParams.loadOptParamsForScreen); } @@ -131,28 +208,12 @@ if (Drawing::SystemProperties::IsUseVulkan()) { #endif } - auto generator = CreateVSyncGenerator(); - - // The offset needs to be set - int64_t offset = 0; - if (!HgmCore::Instance().GetLtpoEnabled()) { - if (RSUniRenderJudgement::GetUniRenderEnabledType() == UniRenderEnabledType::UNI_RENDER_ENABLED_FOR_ALL) { - offset = HgmCore::Instance().IsDelayMode() ? UNI_RENDER_VSYNC_OFFSET_DELAY_MODE : UNI_RENDER_VSYNC_OFFSET; - } - rsVSyncController_ = new VSyncController(generator, offset); - appVSyncController_ = new VSyncController(generator, offset); - } else { - rsVSyncController_ = new VSyncController(generator, 0); - appVSyncController_ = new VSyncController(generator, 0); - generator->SetVSyncMode(VSYNC_MODE_LTPO); - } - DVSyncFeatureParam dvsyncParam; - InitDVSyncParams(dvsyncParam); - rsVSyncDistributor_ = new VSyncDistributor(rsVSyncController_, "rs", dvsyncParam); - appVSyncDistributor_ = new VSyncDistributor(appVSyncController_, "app", dvsyncParam); - - generator->SetRSDistributor(rsVSyncDistributor_); - generator->SetAppDistributor(appVSyncDistributor_); + // receiver_ + sptr token = new IRemoteStub(); + sptr conn = new VSyncConnection(rsVSyncDistributor_, "rs", token->AsObject()); + conn->id_ = hgmContext_.GetRSFrameRateLinker()->GetId(); + rsVSyncDistributor_->AddConnection(conn); + receiver_ = std::make_shared(conn, token->AsObject(), handler_, "rs"); mainThread_ = RSMainThread::Instance(); if (mainThread_ == nullptr) { @@ -161,18 +222,32 @@ if (Drawing::SystemProperties::IsUseVulkan()) { mainThread_->rsVSyncDistributor_ = rsVSyncDistributor_; mainThread_->rsVSyncController_ = rsVSyncController_; mainThread_->appVSyncController_ = appVSyncController_; - mainThread_->vsyncGenerator_ = generator; + mainThread_->vsyncGenerator_ = vsyncGenerator_; mainThread_->SetAppVSyncDistributor(appVSyncDistributor_); - mainThread_->Init(); + mainThread_->Init(runner_, handler_, receiver_); mainThread_->PostTask([]() { system::SetParameter(BOOTEVENT_RENDER_SERVICE_READY.c_str(), "true"); RS_LOGI("Set boot render service started true"); }, "BOOTEVENT_RENDER_SERVICE_READY", 0, AppExecFwk::EventQueue::Priority::VIP); + RSGfxDumpInit(); // Gfx Init + + RS_PROFILER_INIT(this); + +#ifdef RS_ENABLE_RDO + EnableRSCodeCache(); +#endif + + return true; +} + +bool RSRenderService::SAMgrRegister() +{ // Wait samgr ready for up to 5 second to ensure adding service to samgr. int status = WaitParameter("bootevent.samgr.ready", "true", 5); if (status != 0) { RS_LOGE("wait SAMGR error, return value [%d].", status); + return false; } auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -181,16 +256,39 @@ if (Drawing::SystemProperties::IsUseVulkan()) { return false; } samgr->AddSystemAbility(RENDER_SERVICE, this); + return true; +} - RSGfxDumpInit(); // Gfx Init +sptr RSRenderService::RegisterRenderProcessConnection(const sptr& conn, ScreenId screenId) +{ + if (!conn) { + RS_LOGE("%{public}s: conn is null.", __func__); + return nullptr; + } - RS_PROFILER_INIT(this); + auto pid = renderProcessManager_->GetRenderProcessPid(screenId); + renderProcessManager_->SetRenderProcessConnectionProxy(pid, conn); -#ifdef RS_ENABLE_RDO - EnableRSCodeCache(); -#endif - - return true; + // TODO: 添加死亡监听 + + auto renderComposeConnection = sptr::MakeSptr(*this, rsVSyncDistributor_); + return renderComposeConnection; +} + +sptr RSRenderService::CreateRenderConnection(const sptr& token, ScreenId screenId) +{ + if (!mainThread_ || !token) { + RS_LOGE("%{public}s: mainThread or token is nullptr"); + return nullptr; + } + pid_t remotePid = renderProcessManager_->GetRenderProcessPid(screenId); + + auto tokenObj = token->AsObject(); + sptr renderConn = nullptr; + sptr renderProcess = renderProcessManager_->GetRenderProcessConnectionProxy(remotePid); + renderConn = renderProcess->CreateRenderConnection(token, remotePid); + + return renderConn; } void RSRenderService::InitDVSyncParams(DVSyncFeatureParam &dvsyncParam) @@ -227,19 +325,18 @@ void RSRenderService::InitLoadOptParams(LoadOptParams& loadOptParams) void RSRenderService::Run() { - if (!mainThread_) { - RS_LOGE("Run failed, mainThread is nullptr"); - return; + // 消息队列死循环 + if (runner_) { + RS_LOGI("fqy %{public}s: MainProcess Run", __func__); + runner_->Run(); } - RS_LOGE("Run"); - mainThread_->Start(); } -sptr RSRenderService::CreateConnection(const sptr& token) +std::pair, sptr> RSRenderService::CreateConnection(const sptr& token) { if (!mainThread_ || !token) { - RS_LOGE("CreateConnection failed, mainThread or token is nullptr"); - return nullptr; + RS_LOGE("%{public}s: CreateConnection failed, mainThread or token is nullptr", __func__); + return std::make_pair(nullptr, nullptr); } pid_t remotePid = GetCallingPid(); RS_PROFILER_ON_CREATE_CONNECTION(remotePid); @@ -248,6 +345,11 @@ sptr RSRenderService::CreateConnection(const sptr newConn( new RSRenderServiceConnection(remotePid, this, mainThread_, screenManager_, tokenObj, appVSyncDistributor_)); + // TODO: 需要获取screenId信息 + // ScreenId screenId = screenManager_->GetScreenId(pid); + ScreenId screenId = 0; + auto renderConn = CreateRenderConnection(token, screenId); + sptr tmp; std::unique_lock lock(mutex_); // if connections_ has the same token one, replace it. @@ -258,7 +360,7 @@ sptr RSRenderService::CreateConnection(const sptrAddTransactionDataPidInfo(remotePid); - return newConn; + return std::make_pair(newConn, renderConn); } void RSRenderService::RemoveConnection(sptr token) diff --git a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.h b/rosen/modules/render_service/main/server/rs_render_service.h similarity index 99% rename from rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.h rename to rosen/modules/render_service/main/server/rs_render_service.h index bef51ed06bed718cc8f5fb2def74ba89d04b2c7d..8937d6c3fa41a583cb5b81cea2fef3b30cd4e9f9 100644 --- a/rosen/modules/render_service/core/pipeline/main_thread/rs_render_service.h +++ b/rosen/modules/render_service/main/server/rs_render_service.h @@ -22,6 +22,7 @@ #include "transaction/rs_render_service_stub.h" #include "vsync_controller.h" #include "vsync_distributor.h" +#include "rs_render_process_manager.h" namespace OHOS { namespace Rosen { diff --git a/rosen/modules/render_service/screen_manager/README.md b/rosen/modules/render_service/screen_manager/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2457df5b51d6630baa3d3a628f773b1b5b29bb08 --- /dev/null +++ b/rosen/modules/render_service/screen_manager/README.md @@ -0,0 +1 @@ +# screen manager \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/README.md b/rosen/modules/render_service/transaction/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b0c99fd82ca042c117e8ef5050b659d7d9ac5edf --- /dev/null +++ b/rosen/modules/render_service/transaction/README.md @@ -0,0 +1 @@ +# transaction \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.cpp b/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ebd15f9357cf6223c7360b5b27ea6cb55738492 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_compose_connection_stub.h" + +#include "platform/common/rs_log.h" +#include "rs_trace.h" +#include "rs_profiler.h" + +#include "foundation/graphic/graphic_2d/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_conection_ipc_interface_code.h" + +#undef LOG_TAG +#define LOG_TAG "RSRenderComposeConnectionStub" + +namespace OHOS { +namespace Rosen { +int RSRenderComposeConnectionStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) +{ + int ret = ERR_NONE; + switch (code) { + case static_cast(RSIRenderComposeConnectionInterfaceCode::CREATE_VSYNC_CONECTION): { + auto innterfaceToken = data.ReadInterfaceToken(); + if (interfaceToken != IVSyncConnection::GetDescriptor()) { + RS_LOGE("RSIRenderComposeConnectionInterfaceCode::CREATE_VSYNC_CONECTION Read interfaceToken failed!"); + ret = ERR_INVALID_STATE; + break; + } + auto remoteObj = data.ReadRemoteObject(); + if (remoteObj == nullptr) { + RS_LOGE("RSIRenderComposeConnectionInterfaceCode::CREATE_VSYNC_CONECTION Read remoteObj failed!"); + ret = ERR_NULL_OBJECT; + break; + } + if (!remoteObj->IsProxyObject()) { + RS_LOGE("RSIRenderComposeConnectionInterfaceCode::CREATE_VSYNC_CONECTION remoteObj !IsProxyObject() failed!"); + ret = ERR_UNKNOWN_OBJECT; + break; + } + + auto token = iface_cast(remoteObj); + sptr newConn = CreateVSyncConnection(token); + if (newConn != nullptr) { + reply.WriteRemoteObject(ewConn->AsObject()); + } + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return ret; +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.h b/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..f8cbf344fc875410dd7cf42a25b1dbc761a38c56 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_compose_connection_stub.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_COMPOSE_CONNECTION_STUB_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_COMPOSE_CONNECTION_STUB_H + +#include "platform/ohos/rs_irender_compose_connection.h" + +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderComposeConnectionnStub : public IRemoteStub { +public: + RSRenderComposeConnectionStub() = default; + virtual ~RSRenderComposeConectionStub() noexcept = default; + + int OnRemoteRequest(uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) override; +}; + +} // namespace Rosen +} // namespace OHOS +#endif //ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_COMPOSE_CONNECTION_STUB_H \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_process_connection_stub.cpp b/rosen/modules/render_service/transaction/rs_render_process_connection_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..28ce25c3d6dd0a0a9460e08d8eb8f8080c286c73 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_process_connection_stub.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../../transaction/rs_render_process_connection_stub.h" + +#undef LOG_TAG +#define LOG_TAG "RSRenderProcessConnectionStub" + +namespace OHOS { +namespace Rosen { +int RSRenderProcessConnectionStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) +{ + int ret = ERR_NONE; + switch (code) { + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return ret; +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_process_connection_stub.h b/rosen/modules/render_service/transaction/rs_render_process_connection_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..58db5220ede556653daeed49d45c996c4b8830b5 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_process_connection_stub.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_PROCESS_CONNECTION_STUB_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_PROCESS_CONNECTION_STUB_H + +#include "platform/ohos/rs_irender_process_connection.h" + +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderProcessConnectionnStub : public IRemoteStub { +public: + RSRenderProcessConnectionStub() = default; + virtual ~RSRenderProcessConnectionStub() noexcept = default; + + int OnRemoteRequest(uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) override; +}; + +} // namespace Rosen +} // namespace OHOS +#endif //ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_PROCESS_CONNECTION_STUB_H \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_render_connection_stub.cpp b/rosen/modules/render_service/transaction/rs_render_render_connection_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..894090d3f41ee2b1c4e1f8f35524f18f7cf60706 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_render_connection_stub.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../../transaction/rs_render_render_connection_stub.h" + +#undef LOG_TAG +#define LOG_TAG "RSRenderRennderConnectionStub" + +namespace OHOS { +namespace Rosen { +int RSRenderRenderConnectionStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) +{ + int ret = ERR_NONE; + switch (code) { + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return ret; +} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service/transaction/rs_render_render_connection_stub.h b/rosen/modules/render_service/transaction/rs_render_render_connection_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..2ae4d0025a70b18de4b0a65a3afec730be923126 --- /dev/null +++ b/rosen/modules/render_service/transaction/rs_render_render_connection_stub.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_CONNECTION_STUB_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_CONNECTION_STUB_H + +#include "platform/ohos/rs_irender_render_connection.h" + +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderRennderConnectionnStub : public IRemoteStub { +public: + RSRenderRenderConnectionStub() = default; + virtual ~RSRenderRenderConectionStub() noexcept = default; + + int OnRemoteRequest(uint32_t code, MessageParcel& data, MeesageParcel& reply, MessageOption& option) override; +}; + +} // namespace Rosen +} // namespace OHOS +#endif //ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_CONNECTION_STUB_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..0d94e377e154c02cb35c90a9792df561d788b0d8 --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_H + +#include "rs_irender_connection_token.h" +#include "rs_irender_process_connection.h" +#include "foundation/graphic/graphic_graphic_2d/rosen/moudules/composer/vsync/include/vsync_distributor.h" + +namespace OHOS { +namespace Rosen { + +class RSIRenderComposeConnection : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.IRenderComposeConnection"); + + RSIRenderComposeConnection() = default; + virtual ~RSIRenderComposeConnection() noexcept = default; + + virtual sptr CreateVSyncConnection(const sptr& token) = 0; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection_ipc_interface_code.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection_ipc_interface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..7519bd259f64e94bd1cf28fa12e8e87a86c13800 --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_compose_connection_ipc_interface_code.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_INTERFACE_CODE_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_INTERFACE_CODE_H + +#include "ipc_security/rs_ipc_interface_code_underlying_type.h" + +namespace OHOS { +namespace Rosen { + +enum class RSIRenderComposeConnectionInterfaceCode : CodeUnderlyingType { + CREATE_VSYNC_CONNECTION = 0; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_COMPOSE_CONNECTION_INTERFACE_CODE_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_connection_token.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_connection_token.h new file mode 100644 index 0000000000000000000000000000000000000000..9b7051f38aa7a85878c4c6efaaf116c65c394d2d --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_connection_token.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_CONNECTION_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_CONNECTION_H + +#include + +#include "rs_irender_service_connection.h" + +namespace OHOS { +namespace Rosen { +class RSIConnectionToken : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.RSConnectionToken"); + + RSIConnectionToken() = default; + virtual ~RSIConnectionToken() noexcept = default; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_CONNECTION_H diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..64a7678c039b94a3db4c4f4042c731bae99bd3d3 --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_H + +#include "rs_irender_connection_token.h" +#include "rs_irender_render_connection.h" + +namespace OHOS { +namespace Rosen { + +class RSIRenderProcessConnection : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.IRenderProcessConnection"); + + RSIRenderProcessConnection() = default; + virtual ~RSIRenderProcessConnection() noexcept = default; + + virtual bool SendMessage() = 0; + + virtual sptr CreateRenderConnection(const sptr& token, + pid_t remotePid) = 0; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection_ipc_interface_code.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection_ipc_interface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..b7cdf1201230b1f639d0ea604eccaae142d15788 --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_process_connection_ipc_interface_code.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_INTERFACE_CODE_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_INTERFACE_CODE_H + +#include "ipc_security/rs_ipc_interface_code_underlying_type.h" + +namespace OHOS { +namespace Rosen { + +enum class RSIRenderProcessConnectionInterfaceCode : CodeUnderlyingType { + CREATE_CONNECTION = 0; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_PROCESS_CONNECTION_INTERFACE_CODE_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..a9a7b5bf249fc0361500060642dfac9d1768146a --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_H + +#include +#include +#include + +#include "rs_irender_connection_token.h" + +namespace OHOS { +namespace Rosen { + +class RSIRenderRenderConnection : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.IRenderRenderConnection"); + + RSIRenderRenderConnection() = default; + virtual ~RSIRenderRenderConnection() noexcept = default; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection_ipc_interface_code.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection_ipc_interface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..879d6b5e8530d4e53e2d4a2b60f8365b42d71707 --- /dev/null +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_render_connection_ipc_interface_code.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_INTERFACE_CODE_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_INTERFACE_CODE_H + +#include "ipc_security/rs_ipc_interface_code_underlying_type.h" + +namespace OHOS { +namespace Rosen { + +enum class RSIRenderRenderConnectionInterfaceCode : CodeUnderlyingType { + CREATE_CONNECTION = 0; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_RENDER_CONNECTION_INTERFACE_CODE_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service.h index 6797a3f6595d9872a5bfdcf69da1ad0699122005..9ddf269a5f0101250975c519092e6da652bff541 100644 --- a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service.h +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service.h @@ -16,18 +16,14 @@ #ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_H #define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_H +#include "rs_irender_connection_token.h" #include "rs_irender_service_connection.h" +#include "rs_irender_proocess_connection.h" +#include "rs_irender_compose_connection.h" +#include "rs_irender_render_connection.h" namespace OHOS { namespace Rosen { -class RSIConnectionToken : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.RSConnectionToken"); - - RSIConnectionToken() = default; - virtual ~RSIConnectionToken() noexcept = default; -}; - class RSIRenderService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.RenderService"); @@ -36,6 +32,7 @@ public: virtual ~RSIRenderService() noexcept = default; virtual sptr CreateConnection(const sptr& token) = 0; + virtual sptr RegisterRenderProcessConnection(const sptr& token) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_ipc_interface_code.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_ipc_interface_code.h index d42563bc972c940766f8577339946e7754369504..2b9dd75ff4c511da369c7f575b8cfc94f099b4b2 100644 --- a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_ipc_interface_code.h +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_ipc_interface_code.h @@ -22,6 +22,7 @@ namespace OHOS { namespace Rosen { enum class RSIRenderServiceInterfaceCode : CodeUnderlyingType { CREATE_CONNECTION = 0, + REGISTER_RENDER_PROCESS_CONNECTION = 1, }; } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn b/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn index cfce323d5cec80f46a0072e6bc34a52ec97cc5d8..2531e3ae85da1653b32edc52e5fae2183bc8f32c 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn +++ b/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn @@ -65,6 +65,9 @@ ohos_source_set("rosen_ohos_sources") { "rs_surface_ohos_converter.cpp", "rs_system_properties.cpp", "rs_vsync_client_ohos.cpp", + "rs_render_process_connection_proxy.cpp", + "rs_render_compose_connection_proxy.cpp", + "rs_render_render_connection_proxy.cpp", ] if (accessibility_enable) { diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a797e5b284895f15fe9744c7be96f0996e563e13 --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_compose_connection_proxy.h" + +#include +#include +#include +#include +#include +#include "platform/common/rs_log.h" +#include "platform/common/rs_system_properties.h" +#include "transaction/rs_ashmem_helper.h" +#include "transaction/rs_marshalling_helper.h" +#include "rs_trace.h" + +namespace OHOS { +namespace Rosen { +RSRenderComposeConnectionProxy::RSRenderComposeConnectionProxy(const sptr& impl) : + IRemoteProxy(impl) {} + +sptr RSRenderComposeConnectionProxy::CreateVSyncConnection(const sptr& token) +{ + if (token == nullptr) { + ROSEN_LOGE("RSRenderComposeConnectionProxy::CreateVSyncConnection(): token is null."); + return nullptr; + } + + MessageParcel data; + MessageParcel reply; + MessageParcel option; + option.SetFlags(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(IVSyncConnection::GetDescriptor())) { + ROSEN_LOGE("RSRenderComposeConnectionProxy::CreateVSyncConnection(): WriteInterfaceToken failed."); + return nullptr; + } + if (!data.WriteRemoteObject(token->AsObject())) { + ROSEN_LOGE("RSRenderComposeConnectionProxy::CreateVSyncConnection(): WriteRemoteObject failed."); + return nullptr; + } + + uint32_t code = static_cast(RSIRenderComposeConnectionInterfaceCode::CREATE_VSYNC_CONNECTION); + int32_t err = Remote()->SendRequest(code, data, reply, option); + if (err != NO_ERROR) { + ROSEN_LOGE("RSRenderComposeConnectionProxy::CreateVSyncConnection(): SendRequest failed, err is %{public}d.", err); + return nullptr; + } + + auto remoteObj = reply.ReadRemoteObject(); + if (remoteObj == nullptr || !remoteObj->IsProxyObject()) { + ROSEN_LOGE("RSRenderComposeConnectionProxy::CreateVSyncConnection(): Reply is not valid."); + return nullptr; + } + + return iface_cast(remoteObj); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.h b/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..7519d838549e968661032135aef21ed27be8374f --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_compose_connection_proxy.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_COMPOSE_CONNECTION_PROXY_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_COMPOSE_CONNECTION_PROXY_H + +#include "command/rs_node_showing_command.h" +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderComposeConnectionProxy : public IRemoteProxy { +public: + explicit RSRenderComposeConnectionProxy(const sptr& impl); + virtual ~RSRenderComposeConnectionProxy() noexcept = default; + + sptr CreateVSyncConnection(const sptr& token) override; + +private: + static inline BrokerDelegator delegator_; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_COMPOSE_CONNECTION_PROXY_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..866167742560f6f60a72b993d9cf683fc382d275 --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_process_connection_proxy.h" + +namespace OHOS { +namespace Rosen { +RSRenderProcessConnectionProxy::RSRenderProcessConnectionProxy(const sptr& impl) : + IRemoteProxy(impl) {} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.h b/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..f0d1293b44d6af24ec0e2903ea2b50bacb64ab71 --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_process_connection_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_PROCESS_CONNECTION_PROXY_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_PROCESS_CONNECTION_PROXY_H + +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderProcessConnectionProxy : public IRemoteProxy { +public: + explicit RSRenderProcessConnectionProxy(const sptr& impl); + virtual ~RSRenderProcessConnectionProxy() noexcept = default; + + sptr CreateRenderConnection(const sptr& token, pid_t remotePid) override { return nullptr; } + +private: + static inline BrokerDelegator delegator_; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_PROCESS_CONNECTION_PROXY_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b611406a4f3fb79ed6905f88e5f83bfaceafb71a --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rs_render_render_connection_proxy.h" + +namespace OHOS { +namespace Rosen { +RSRenderRenderConnectionProxy::RSRenderRenderConnectionProxy(const sptr& impl) : + IRemoteProxy(impl) {} + +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.h b/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..a17366283d10b9b628462146e61c0be57ac67c59 --- /dev/null +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_render_connection_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_RENDER_CONNECTION_PROXY_H +#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_RENDER_CONNECTION_PROXY_H + +#include "command/rs_node_showing_command.h" +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class RSRenderRenderConnectionProxy : public IRemoteProxy { +public: + explicit RSRenderRenderConnectionProxy(const sptr& impl); + virtual ~RSRenderRenderConnectionProxy() noexcept = default; + +private: + static inline BrokerDelegator delegator_; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_RENDER_CONNECTION_PROXY_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.cpp index 9df612c82bebfd30239b758add2f2010997b7486..af749eddd5c5edf3d5eebb8a3629f49c2c423804 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.cpp @@ -68,5 +68,41 @@ sptr RSRenderServiceProxy::CreateConnection(const sp return iface_cast(remoteObj); } + +sptr RSRenderServiceProxy::RegisterRenderProcessConnection(const sptr& conn) +{ + if (token == nullptr) { + ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): token is null."); + return nullptr; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + option.SetFlags(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) { + ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): WriteInterfaceToken failed."); + return nullptr; + } + if (!data.WriteRemoteObject(token->AsObject())) { + ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): WriteRemoteObject failed."); + return nullptr; + } + + uint32_t code = static_cast(RSIRenderServiceInterfaceCode::REGISTER_RENDER_PROCESS_CONNECTION); + int32_t err = Remote()->SendRequest(code, data, reply, option); + if (err != NO_ERROR) { + ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): SendRequest failed, err is %{public}d.", err); + return nullptr; + } + + auto remoteObj = reply.ReadRemoteObject(); + if (remoteObj == nullptr || !remoteObj->IsProxyObject()) { + ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): Reply is not valid."); + return nullptr; + } + + return iface_cast(remoteObj); +} } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.h b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.h index 8edbe9aecaaa7b1c9fa19cc3299e76cd46432bdb..cfa75863915cd245ca4f24a171d17444a1c02b67 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.h +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_proxy.h @@ -29,6 +29,7 @@ public: virtual ~RSRenderServiceProxy() noexcept = default; sptr CreateConnection(const sptr& token) override; + sptr RegisterRenderProcessConnection(const sptr& conn) override; private: static inline BrokerDelegator delegator_;