为Render Service增加统一的死亡监听接口,用于Client端异常退出时的资源清理

Signed-off-by: xxfeng_hw <yuxiaofeng8@huawei.com>
Change-Id: Ia2ddf3239ce6b8d2362fa1c39564bd16794177be
This commit is contained in:
xxfeng_hw 2022-01-12 17:44:41 +08:00
parent 2499e6bb45
commit e62f8a6a3d
27 changed files with 1635 additions and 1204 deletions

View File

@ -22,14 +22,15 @@ ohos_shared_library("librender_service") {
"core/pipeline/rs_processor.cpp",
"core/pipeline/rs_processor_factory.cpp",
"core/pipeline/rs_render_service.cpp",
"core/pipeline/rs_render_service_connection.cpp",
"core/pipeline/rs_render_service_listener.cpp",
"core/pipeline/rs_render_service_util.cpp",
"core/pipeline/rs_render_service_visitor.cpp",
"core/pipeline/rs_software_processor.cpp",
"core/pipeline/rs_surface_capture_task.cpp",
"core/screen_manager/rs_screen.cpp",
"core/screen_manager/rs_screen_change_callback_death_recipient.cpp",
"core/screen_manager/rs_screen_manager.cpp",
"core/transaction/rs_render_service_connection_stub.cpp",
"core/transaction/rs_render_service_stub.cpp",
]

View File

@ -19,8 +19,12 @@
#include <sys/resource.h>
#include <hilog/log.h>
#include "platform/common/rs_log.h"
#include "pipeline/rs_render_service.h"
using namespace OHOS;
using namespace OHOS::Rosen;
int main(int argc, const char *argv[])
{
signal(SIGPIPE, SIG_IGN);
@ -30,19 +34,18 @@ int main(int argc, const char *argv[])
struct sched_param param = {0};
param.sched_priority = 2;
if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
OHOS::HiviewDFX::HiLog::Error(::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "renderserver"},
"%{public}s: Couldn't set SCHED_FIFO.", __func__);
ROSEN_LOGE("RSRenderService Couldn't set SCHED_FIFO.");
} else {
OHOS::HiviewDFX::HiLog::Error(::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "renderserver"},
"%{public}s: set SCHED_FIFO succ.", __func__);
ROSEN_LOGE("RSRenderService set SCHED_FIFO succeed.");
}
if (!OHOS::Rosen::RSRenderService::GetInstance().Init()) {
OHOS::HiviewDFX::HiLog::Error(::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "renderserver"},
"%{public}s: render service init failed.", __func__);
} else {
OHOS::Rosen::RSRenderService::GetInstance().Run();
sptr<RSRenderService> renderService(new RSRenderService());
if (!renderService->Init()) {
ROSEN_LOGE("RSRenderService init failed.");
return -1;
}
renderService->Run();
return 0;
}

View File

@ -38,7 +38,7 @@ RSMainThread::~RSMainThread() noexcept
{
}
void RSMainThread::Start()
void RSMainThread::Init()
{
mainLoop_ = [&]() {
ROSEN_LOGE("RsDebug mainLoop start");
@ -55,7 +55,11 @@ void RSMainThread::Start()
if (vsyncClient_) {
vsyncClient_->SetVsyncCallback(std::bind(&RSMainThread::OnVsync, this, std::placeholders::_1));
}
while (1) {
}
void RSMainThread::Start()
{
while (true) {
threadLooper_->ProcessAllMessages(-1);
}
}

View File

@ -59,6 +59,7 @@ class RSMainThread {
public:
static RSMainThread* Instance();
void Init();
void Start();
void RecvRSTransactionData(std::unique_ptr<RSTransactionData>& rsTransactionData);
void RequestNextVSync();

View File

@ -13,47 +13,44 @@
* limitations under the License.
*/
#include "pipeline/rs_render_service.h"
#include "rs_render_service.h"
#include "rs_main_thread.h"
#include "rs_render_service_connection.h"
#include <unordered_set>
#include <unistd.h>
#include <iservice_registry.h>
#include <platform/common/rs_log.h>
#include <system_ability_definition.h>
#include "command/rs_command.h"
#include "pipeline/rs_main_thread.h"
#include "pipeline/rs_render_node_map.h"
#include "pipeline/rs_render_service_listener.h"
#include "pipeline/rs_surface_capture_task.h"
#include "pipeline/rs_surface_render_node.h"
#include "platform/common/rs_log.h"
#include "rs_trace.h"
#include "screen_manager/screen_types.h"
namespace OHOS {
namespace Rosen {
RSRenderService& RSRenderService::GetInstance()
{
static RSRenderService instance;
return instance;
}
RSRenderService::RSRenderService() {}
RSRenderService::~RSRenderService() noexcept {}
bool RSRenderService::Init()
{
mainThread_ = RSMainThread::Instance();
screenManager_ = CreateOrGetScreenManager();
if (screenManager_ == nullptr || !screenManager_->Init()) {
ROSEN_LOGI("RSRenderService CreateOrGetScreenManager fail");
ROSEN_LOGE("RSRenderService CreateOrGetScreenManager fail.");
return false;
}
mainThread_ = RSMainThread::Instance();
if (mainThread_ == nullptr) {
return false;
}
mainThread_->Init();
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
samgr->AddSystemAbility(RENDER_SERVICE, &GetInstance());
if (samgr == nullptr) {
ROSEN_LOGE("RSRenderService GetSystemAbilityManager fail.");
return false;
}
samgr->AddSystemAbility(RENDER_SERVICE, this);
return true;
}
@ -63,6 +60,36 @@ void RSRenderService::Run()
mainThread_->Start();
}
sptr<RSIRenderServiceConnection> RSRenderService::CreateConnection(const sptr<RSIConnectionToken>& token)
{
auto tokenObj = token->AsObject();
sptr<RSIRenderServiceConnection> newConn(
new RSRenderServiceConnection(this, mainThread_, screenManager_, tokenObj));
sptr<RSIRenderServiceConnection> tmp;
std::unique_lock<std::mutex> lock(mutex_);
// if connections_ has the same token one, replace it.
if (connections_.count(tokenObj) > 0) {
tmp = connections_.at(tokenObj);
}
connections_[tokenObj] = newConn;
lock.unlock();
return newConn;
}
void RSRenderService::RemoveConnection(sptr<IRemoteObject> token)
{
std::unique_lock<std::mutex> lock(mutex_);
if (connections_.count(token) == 0) {
return;
}
auto tmp = connections_.at(token);
connections_.erase(token);
lock.unlock();
}
int RSRenderService::Dump(int fd, const std::vector<std::u16string>& args)
{
std::unordered_set<std::u16string> argSets;
@ -89,217 +116,5 @@ int RSRenderService::Dump(int fd, const std::vector<std::u16string>& args)
write(fd, dumpString.c_str(), dumpString.size());
return OHOS::NO_ERROR;
}
void RSRenderService::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
{
mainThread_->RecvRSTransactionData(transactionData);
}
void RSRenderService::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
{
std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
std::condition_variable cv;
auto& mainThread = mainThread_;
mainThread->PostTask([task, &cv, &mainThread] {
if (task == nullptr) {
return;
}
task->Process(mainThread->GetContext());
cv.notify_all();
});
cv.wait_for(lock, std::chrono::nanoseconds(task->GetTimeout()));
}
sptr<Surface> RSRenderService::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
{
std::shared_ptr<RSSurfaceRenderNode> node = std::make_shared<RSSurfaceRenderNode>(config);
if (node == nullptr) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface CreateNode fail");
return nullptr;
}
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
if (surface == nullptr) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface get consumer surface fail");
return nullptr;
}
node->SetConsumer(surface);
std::function<void()> registerNode = [node, this]() -> void {
this->mainThread_->GetContext().GetNodeMap().RegisterRenderNode(node);
};
mainThread_->PostTask(registerNode);
std::weak_ptr<RSSurfaceRenderNode> surfaceRenderNode(node);
sptr<IBufferConsumerListener> listener = new RSRenderServiceListener(surfaceRenderNode);
SurfaceError ret = surface->RegisterConsumerListener(listener);
if (ret != SURFACE_ERROR_OK) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface Register Consumer Listener fail");
return nullptr;
}
return surface;
}
ScreenId RSRenderService::GetDefaultScreenId()
{
if (screenManager_ == nullptr) {
return INVALID_SCREEN_ID;
}
return mainThread_->ScheduleTask([this]() {
return screenManager_->GetDefaultScreenId();
}).get();
}
ScreenId RSRenderService::CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags)
{
if (screenManager_ == nullptr) {
return INVALID_SCREEN_ID;
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->CreateVirtualScreen(name, width, height, surface, mirrorId, flags);
}).get();
}
void RSRenderService::RemoveVirtualScreen(ScreenId id)
{
if (screenManager_ == nullptr) {
return;
}
mainThread_->ScheduleTask([=]() {
screenManager_->RemoveVirtualScreen(id);
}).wait();
}
void RSRenderService::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
{
if (screenManager_ == nullptr) {
return;
}
mainThread_->ScheduleTask([=]() {
screenManager_->AddScreenChangeCallback(callback);
}).wait();
}
void RSRenderService::SetScreenActiveMode(ScreenId id, uint32_t modeId)
{
if (screenManager_ == nullptr) {
return;
}
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenActiveMode(id, modeId);
}).wait();
}
void RSRenderService::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
{
if (screenManager_ == nullptr) {
return;
}
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenPowerStatus(id, status);
}).wait();
}
void RSRenderService::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback)
{
std::function<void()> captureTask = [callback, id]() -> void {
ROSEN_LOGD("RSRenderService::TakeSurfaceCapture callback->OnSurfaceCapture nodeId:[%llu]", id);
ROSEN_TRACE_BEGIN(BYTRACE_TAG_GRAPHIC_AGP, "RSRenderService::TakeSurfaceCapture");
RSSurfaceCaptureTask task(id);
std::unique_ptr<Media::PixelMap> pixelmap = task.Run();
callback->OnSurfaceCapture(id, pixelmap.get());
ROSEN_TRACE_END(BYTRACE_TAG_GRAPHIC_AGP);
};
mainThread_->PostTask(captureTask);
}
RSScreenModeInfo RSRenderService::GetScreenActiveMode(ScreenId id)
{
RSScreenModeInfo screenModeInfo;
if (screenManager_ == nullptr) {
return screenModeInfo;
}
mainThread_->ScheduleTask([=, &screenModeInfo]() {
return screenManager_->GetScreenActiveMode(id, screenModeInfo);
}).wait();
return screenModeInfo;
}
std::vector<RSScreenModeInfo> RSRenderService::GetScreenSupportedModes(ScreenId id)
{
if (screenManager_ == nullptr) {
return {};
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenSupportedModes(id);
}).get();
}
RSScreenCapability RSRenderService::GetScreenCapability(ScreenId id)
{
RSScreenCapability screenCapability;
if (screenManager_ == nullptr) {
return screenCapability;
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenCapability(id);
}).get();
}
ScreenPowerStatus RSRenderService::GetScreenPowerStatus(ScreenId id)
{
if (screenManager_ == nullptr) {
return INVALID_POWER_STATUS;
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenPowerStatus(id);
}).get();
}
RSScreenData RSRenderService::GetScreenData(ScreenId id)
{
RSScreenData screenData;
if (screenManager_ == nullptr) {
return screenData;
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenData(id);
}).get();
}
int32_t RSRenderService::GetScreenBacklight(ScreenId id)
{
if (screenManager_ == nullptr) {
return INVALID_BACKLIGHT_VALUE;
}
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenBacklight(id);
}).get();
}
void RSRenderService::SetScreenBacklight(ScreenId id, uint32_t level)
{
if (screenManager_ == nullptr) {
return;
}
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenBacklight(id, level);
}).wait();
}
} // namespace Rosen
} // namespace OHOS

View File

@ -15,73 +15,39 @@
#ifndef RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_H
#define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_H
#include <string>
#include <map>
#include "screen_manager/rs_screen_manager.h"
#include "transaction/rs_render_service_stub.h"
namespace OHOS {
namespace Rosen {
class RSMainThread;
class RSSyncTask;
class RSRenderServiceConnection;
class RSRenderService : public RSRenderServiceStub {
public:
static RSRenderService& GetInstance();
RSRenderService();
~RSRenderService() noexcept;
RSRenderService(const RSRenderService&) = delete;
RSRenderService& operator=(const RSRenderService&) = delete;
bool Init();
void Run();
int Dump(int fd, const std::vector<std::u16string>& args) override;
private:
RSRenderService();
~RSRenderService() noexcept;
void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
ScreenId GetDefaultScreenId() override;
ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) override;
void RemoveVirtualScreen(ScreenId id) override;
void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) override;
RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
RSScreenCapability GetScreenCapability(ScreenId id) override;
ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
RSScreenData GetScreenData(ScreenId id) override;
int32_t GetScreenBacklight(ScreenId id) override;
void SetScreenBacklight(ScreenId id, uint32_t level) override;
int Dump(int fd, const std::vector<std::u16string>& args) override;
sptr<RSIRenderServiceConnection> CreateConnection(const sptr<RSIConnectionToken>& token) override;
void RemoveConnection(sptr<IRemoteObject> token);
RSMainThread* mainThread_ = nullptr;
sptr<RSScreenManager> screenManager_;
friend class RSRenderServiceConnection;
mutable std::mutex mutex_;
std::map<sptr<IRemoteObject>, sptr<RSIRenderServiceConnection>> connections_;
};
} // Rosen
} // OHOS

View File

@ -0,0 +1,291 @@
/*
* Copyright (c) 2021 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_service_connection.h"
#include "rs_main_thread.h"
#include "rs_trace.h"
#include "pipeline/rs_render_node_map.h"
#include "pipeline/rs_render_service_listener.h"
#include "pipeline/rs_surface_render_node.h"
#include "pipeline/rs_render_node_map.h"
#include "pipeline/rs_surface_capture_task.h"
#include "platform/common/rs_log.h"
namespace OHOS {
namespace Rosen {
// we guarantee that when constructing this object,
// all these pointers are valid, so will not check them.
RSRenderServiceConnection::RSRenderServiceConnection(
wptr<RSRenderService> renderService,
RSMainThread* mainThread,
sptr<RSScreenManager> screenManager,
sptr<IRemoteObject> token)
: renderService_(renderService),
mainThread_(mainThread),
screenManager_(screenManager),
token_(token),
connDeathRecipient_(new RSConnectionDeathRecipient(this))
{
if (!token_->AddDeathRecipient(connDeathRecipient_)) {
ROSEN_LOGW("RSRenderServiceConnection: Failed to set death recipient.");
}
}
RSRenderServiceConnection::~RSRenderServiceConnection() noexcept
{
CleanAll();
}
void RSRenderServiceConnection::CleanAll(bool toDelete) noexcept
{
{
std::lock_guard<std::mutex> lock(mutex_);
if (cleanDone_) {
return;
}
}
ROSEN_LOGD("RSRenderServiceConnection::CleanAll() start.");
mainThread_->ScheduleTask([this]() {
std::lock_guard<std::mutex> lock(mutex_);
for (auto &id : virtualScreenIds_) {
screenManager_->RemoveVirtualScreen(id);
}
virtualScreenIds_.clear();
if (screenChangeCallback_ != nullptr) {
screenManager_->RemoveScreenChangeCallback(screenChangeCallback_);
screenChangeCallback_ = nullptr;
}
}).wait();
{
std::lock_guard<std::mutex> lock(mutex_);
cleanDone_ = true;
}
if (toDelete) {
auto renderService = renderService_.promote();
if (renderService == nullptr) {
ROSEN_LOGW("RSRenderServiceConnection::CleanAll() RenderService is dead.");
} else {
renderService->RemoveConnection(GetToken());
}
}
ROSEN_LOGD("RSRenderServiceConnection::CleanAll() end.");
}
RSRenderServiceConnection::RSConnectionDeathRecipient::RSConnectionDeathRecipient(
wptr<RSRenderServiceConnection> conn) : conn_(conn)
{
}
void RSRenderServiceConnection::RSConnectionDeathRecipient::OnRemoteDied(
const wptr<IRemoteObject> &token)
{
auto tokenSptr = token.promote();
if (tokenSptr == nullptr) {
ROSEN_LOGW("RSConnectionDeathRecipient::OnRemoteDied: can't promote remote object.");
return;
}
auto rsConn = conn_.promote();
if (rsConn == nullptr) {
ROSEN_LOGW("RSConnectionDeathRecipient::OnRemoteDied: RSRenderServiceConnection was dead, do nothing.");
return;
}
if (rsConn->GetToken() != tokenSptr) {
ROSEN_LOGI("RSConnectionDeathRecipient::OnRemoteDied: token doesn't match, ignore it.");
return;
}
ROSEN_LOGI("RSConnectionDeathRecipient::OnRemoteDied: do the clean work.");
rsConn->CleanAll(true);
}
void RSRenderServiceConnection::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
{
mainThread_->RecvRSTransactionData(transactionData);
}
void RSRenderServiceConnection::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
{
if (task == nullptr) {
return;
}
auto& context = mainThread_->GetContext();
mainThread_->ScheduleTask([task, &context]() {
task->Process(context);
}).wait_for(std::chrono::nanoseconds(task->GetTimeout()));
}
sptr<Surface> RSRenderServiceConnection::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
{
std::shared_ptr<RSSurfaceRenderNode> node = std::make_shared<RSSurfaceRenderNode>(config);
if (node == nullptr) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface CreateNode fail");
return nullptr;
}
sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
if (surface == nullptr) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface get consumer surface fail");
return nullptr;
}
node->SetConsumer(surface);
std::function<void()> registerNode = [node, this]() -> void {
this->mainThread_->GetContext().GetNodeMap().RegisterRenderNode(node);
};
mainThread_->PostTask(registerNode);
std::weak_ptr<RSSurfaceRenderNode> surfaceRenderNode(node);
sptr<IBufferConsumerListener> listener = new RSRenderServiceListener(surfaceRenderNode);
SurfaceError ret = surface->RegisterConsumerListener(listener);
if (ret != SURFACE_ERROR_OK) {
ROSEN_LOGE("RSRenderService::CreateNodeAndSurface Register Consumer Listener fail");
return nullptr;
}
return surface;
}
ScreenId RSRenderServiceConnection::GetDefaultScreenId()
{
return mainThread_->ScheduleTask([this]() {
return screenManager_->GetDefaultScreenId();
}).get();
}
ScreenId RSRenderServiceConnection::CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags)
{
std::lock_guard<std::mutex> lock(mutex_);
auto newVirtualScreenId = screenManager_->CreateVirtualScreen(name, width, height, surface, mirrorId, flags);
virtualScreenIds_.insert(newVirtualScreenId);
return newVirtualScreenId;
}
void RSRenderServiceConnection::RemoveVirtualScreen(ScreenId id)
{
std::lock_guard<std::mutex> lock(mutex_);
screenManager_->RemoveVirtualScreen(id);
virtualScreenIds_.erase(id);
}
void RSRenderServiceConnection::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
{
std::unique_lock<std::mutex> lock(mutex_);
if (screenChangeCallback_ == callback) {
return;
}
if (screenChangeCallback_ != nullptr) {
// remove the old callback
screenManager_->RemoveScreenChangeCallback(screenChangeCallback_);
}
// update
screenManager_->AddScreenChangeCallback(callback);
auto tmp = screenChangeCallback_;
screenChangeCallback_ = callback;
lock.unlock();
}
void RSRenderServiceConnection::SetScreenActiveMode(ScreenId id, uint32_t modeId)
{
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenActiveMode(id, modeId);
}).wait();
}
void RSRenderServiceConnection::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
{
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenPowerStatus(id, status);
}).wait();
}
void RSRenderServiceConnection::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback)
{
std::function<void()> captureTask = [callback, id]() -> void {
ROSEN_LOGD("RSRenderService::TakeSurfaceCapture callback->OnSurfaceCapture nodeId:[%llu]", id);
ROSEN_TRACE_BEGIN(BYTRACE_TAG_GRAPHIC_AGP, "RSRenderService::TakeSurfaceCapture");
RSSurfaceCaptureTask task(id);
std::unique_ptr<Media::PixelMap> pixelmap = task.Run();
callback->OnSurfaceCapture(id, pixelmap.get());
ROSEN_TRACE_END(BYTRACE_TAG_GRAPHIC_AGP);
};
mainThread_->PostTask(captureTask);
}
RSScreenModeInfo RSRenderServiceConnection::GetScreenActiveMode(ScreenId id)
{
RSScreenModeInfo screenModeInfo;
mainThread_->ScheduleTask([=, &screenModeInfo]() {
return screenManager_->GetScreenActiveMode(id, screenModeInfo);
}).wait();
return screenModeInfo;
}
std::vector<RSScreenModeInfo> RSRenderServiceConnection::GetScreenSupportedModes(ScreenId id)
{
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenSupportedModes(id);
}).get();
}
RSScreenCapability RSRenderServiceConnection::GetScreenCapability(ScreenId id)
{
RSScreenCapability screenCapability;
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenCapability(id);
}).get();
}
ScreenPowerStatus RSRenderServiceConnection::GetScreenPowerStatus(ScreenId id)
{
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenPowerStatus(id);
}).get();
}
RSScreenData RSRenderServiceConnection::GetScreenData(ScreenId id)
{
RSScreenData screenData;
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenData(id);
}).get();
}
int32_t RSRenderServiceConnection::GetScreenBacklight(ScreenId id)
{
return mainThread_->ScheduleTask([=]() {
return screenManager_->GetScreenBacklight(id);
}).get();
}
void RSRenderServiceConnection::SetScreenBacklight(ScreenId id, uint32_t level)
{
mainThread_->ScheduleTask([=]() {
screenManager_->SetScreenBacklight(id, level);
}).wait();
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) 2021 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 RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
#define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
#include <mutex>
#include <unordered_set>
#include "pipeline/rs_render_service.h"
#include "screen_manager/rs_screen_manager.h"
#include "transaction/rs_render_service_connection_stub.h"
namespace OHOS {
namespace Rosen {
class RSRenderServiceConnection : public RSRenderServiceConnectionStub {
public:
RSRenderServiceConnection(
wptr<RSRenderService> renderService,
RSMainThread* mainThread,
sptr<RSScreenManager> screenManager,
sptr<IRemoteObject> token);
~RSRenderServiceConnection() noexcept;
RSRenderServiceConnection(const RSRenderServiceConnection&) = delete;
RSRenderServiceConnection& operator=(const RSRenderServiceConnection&) = delete;
sptr<IRemoteObject> GetToken() const
{
return token_;
}
private:
void CleanAll(bool toDelete = false) noexcept;
// IPC RSIRenderServiceConnection Interfaces
void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
ScreenId GetDefaultScreenId() override;
ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) override;
void RemoveVirtualScreen(ScreenId id) override;
void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) override;
RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
RSScreenCapability GetScreenCapability(ScreenId id) override;
ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
RSScreenData GetScreenData(ScreenId id) override;
int32_t GetScreenBacklight(ScreenId id) override;
void SetScreenBacklight(ScreenId id, uint32_t level) override;
wptr<RSRenderService> renderService_;
RSMainThread* mainThread_ = nullptr;
sptr<RSScreenManager> screenManager_;
sptr<IRemoteObject> token_;
class RSConnectionDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit RSConnectionDeathRecipient(wptr<RSRenderServiceConnection> conn);
virtual ~RSConnectionDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
private:
wptr<RSRenderServiceConnection> conn_;
};
friend class RSConnectionDeathRecipient;
sptr<RSConnectionDeathRecipient> connDeathRecipient_;
mutable std::mutex mutex_;
bool cleanDone_ = false;
// save all virtual screenIds created by this connection.
std::unordered_set<ScreenId> virtualScreenIds_;
sptr<RSIScreenChangeCallback> screenChangeCallback_;
};
} // Rosen
} // OHOS
#endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2021 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_screen_change_callback_death_recipient.h"
namespace OHOS {
namespace Rosen {
RSScreenChangeCallbackDeathRecipient::RSScreenChangeCallbackDeathRecipient(sptr<RSScreenManager> screenManager)
: screenManager_(std::move(screenManager))
{
}
void RSScreenChangeCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
screenManager_->OnRemoteScreenChangeCallbackDied(remote);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -15,7 +15,6 @@
#include "rs_screen_manager.h"
#include "pipeline/rs_main_thread.h"
#include "rs_screen_change_callback_death_recipient.h"
#include <cinttypes>
@ -497,11 +496,6 @@ void RSScreenManager::AddScreenChangeCallback(const sptr<RSIScreenChangeCallback
return;
}
sptr<IRemoteObject::DeathRecipient> deathRecipient(new RSScreenChangeCallbackDeathRecipient(instance_));
if (callback->AsObject()->AddDeathRecipient(deathRecipient) == false) {
HiLog::Warn(LOG_LABEL, "%{public}s: Failed to add callback's death recipient.", __func__);
}
std::lock_guard<std::mutex> lock(mutex_);
// when the callback first registered, maybe there were some physical screens already connected,
// so notify to remote immediately.
@ -514,16 +508,11 @@ void RSScreenManager::AddScreenChangeCallback(const sptr<RSIScreenChangeCallback
HiLog::Debug(LOG_LABEL, "%{public}s: add a remote callback succeed.", __func__);
}
void RSScreenManager::OnRemoteScreenChangeCallbackDied(const wptr<IRemoteObject> &remote)
void RSScreenManager::RemoveScreenChangeCallback(const sptr<RSIScreenChangeCallback> &callback)
{
auto sptrRemote = remote.promote();
if (sptrRemote == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(mutex_);
for (auto it = screenChangeCallbacks_.begin(); it != screenChangeCallbacks_.end(); it++) {
if ((*it)->AsObject() == sptrRemote) {
if (*it == callback) {
screenChangeCallbacks_.erase(it);
HiLog::Debug(LOG_LABEL, "%{public}s: remove a remote callback succeed.", __func__);
break;

View File

@ -25,7 +25,6 @@
#include <hdi_backend.h>
#include <hilog/log.h>
#include <ipc_callbacks/screen_change_callback.h>
#include <iremote_object.h>
#include <refbase.h>
#include <screen_manager/rs_screen_props.h>
#include <screen_manager/rs_screen_mode_info.h>
@ -100,7 +99,7 @@ public:
virtual void AddScreenChangeCallback(const sptr<RSIScreenChangeCallback> &callback) = 0;
virtual void OnRemoteScreenChangeCallbackDied(const wptr<IRemoteObject> &remote) = 0;
virtual void RemoveScreenChangeCallback(const sptr<RSIScreenChangeCallback> &callback) = 0;
virtual void ProcessScreenHotPlugEvents() = 0;
@ -172,7 +171,7 @@ public:
void AddScreenChangeCallback(const sptr<RSIScreenChangeCallback> &callback) override;
void OnRemoteScreenChangeCallbackDied(const wptr<IRemoteObject> &remote) override;
void RemoveScreenChangeCallback(const sptr<RSIScreenChangeCallback> &callback) override;
void ProcessScreenHotPlugEvents() override;

View File

@ -0,0 +1,254 @@
/*
* Copyright (c) 2021 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_service_connection_stub.h"
#include "command/rs_command_factory.h"
namespace OHOS {
namespace Rosen {
int RSRenderServiceConnectionStub::OnRemoteRequest(
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
int ret = ERR_NONE;
switch (code) {
case COMMIT_TRANSACTION: {
auto token = data.ReadInterfaceToken();
auto transactionData = data.ReadParcelable<RSTransactionData>();
std::unique_ptr<RSTransactionData> transData(transactionData);
CommitTransaction(transData);
break;
}
case CREATE_NODE_AND_SURFACE: {
auto nodeId = data.ReadUint64();
RSSurfaceRenderNodeConfig config = {.id = nodeId};
sptr<Surface> surface = CreateNodeAndSurface(config);
auto producer = surface->GetProducer();
reply.WriteRemoteObject(producer->AsObject());
break;
}
case GET_DEFAULT_SCREEN_ID: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = GetDefaultScreenId();
reply.WriteUint64(id);
break;
}
case CREATE_VIRTUAL_SCREEN: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
// read the parcel data.
std::string name = data.ReadString();
uint32_t width = data.ReadUint32();
uint32_t height = data.ReadUint32();
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
ret = ERR_NULL_OBJECT;
break;
}
auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
ScreenId mirrorId = data.ReadUint64();
int32_t flags = data.ReadInt32();
ScreenId id = CreateVirtualScreen(name, width, height, surface, mirrorId, flags);
reply.WriteUint64(id);
break;
}
case REMOVE_VIRTUAL_SCREEN: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RemoveVirtualScreen(id);
break;
}
case SET_SCREEN_CHANGE_CALLBACK: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
ret = ERR_NULL_OBJECT;
break;
}
sptr<RSIScreenChangeCallback> cb = iface_cast<RSIScreenChangeCallback>(remoteObject);
SetScreenChangeCallback(cb);
break;
}
case SET_SCREEN_ACTIVE_MODE: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t modeId = data.ReadUint32();
SetScreenActiveMode(id, modeId);
break;
}
case SET_SCREEN_POWER_STATUS: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t status = data.ReadUint32();
SetScreenPowerStatus(id, static_cast<ScreenPowerStatus>(status));
break;
}
case TAKE_SURFACE_CAPTURE: {
NodeId id = data.ReadUint64();
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
ret = ERR_NULL_OBJECT;
break;
}
sptr<RSISurfaceCaptureCallback> cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
TakeSurfaceCapture(id, cb);
break;
}
case GET_SCREEN_ACTIVE_MODE: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenModeInfo screenModeInfo = GetScreenActiveMode(id);
reply.WriteParcelable(&screenModeInfo);
break;
}
case GET_SCREEN_SUPPORTED_MODES: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
std::vector<RSScreenModeInfo> screenSupportedModes = GetScreenSupportedModes(id);
reply.WriteUint64(static_cast<uint64_t>(screenSupportedModes.size()));
for (uint32_t modeIndex = 0; modeIndex < screenSupportedModes.size(); modeIndex++) {
reply.WriteParcelable(&screenSupportedModes[modeIndex]);
}
break;
}
case GET_SCREEN_CAPABILITY: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenCapability screenCapability = GetScreenCapability(id);
reply.WriteParcelable(&screenCapability);
break;
}
case GET_SCREEN_POWER_STATUS: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
ScreenPowerStatus status = GetScreenPowerStatus(id);
reply.WriteUint32(static_cast<uint32_t>(status));
break;
}
case GET_SCREEN_DATA: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenData screenData = GetScreenData(id);
reply.WriteParcelable(&screenData);
break;
}
case EXECUTE_SYNCHRONOUS_TASK: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
auto type = data.ReadUint16();
auto subType = data.ReadUint16();
if (type != RS_NODE_SYNCHRONOUS_READ_PROPERTY) {
ret = ERR_INVALID_STATE;
break;
}
auto func = RSCommandFactory::Instance().GetUnmarshallingFunc(type, subType);
if (func == nullptr) {
ret = ERR_INVALID_STATE;
break;
}
auto command = static_cast<RSSyncTask*>((*func)(data));
if (command == nullptr) {
ret = ERR_INVALID_STATE;
break;
}
std::shared_ptr<RSSyncTask> task(command);
ExecuteSynchronousTask(task);
if (!task->Marshalling(reply)) {
ret = ERR_INVALID_STATE;
}
break;
}
case GET_SCREEN_BACK_LIGHT: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
int32_t level = GetScreenBacklight(id);
reply.WriteInt32(level);
break;
}
case SET_SCREEN_BACK_LIGHT: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderServiceConnection::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t level = data.ReadUint32();
SetScreenBacklight(id, level);
break;
}
default: {
ret = ERR_UNKNOWN_TRANSACTION;
break;
}
}
return ret;
}
} // namespace Rosen
} // namespace OHOS

View File

@ -1,38 +1,37 @@
/*
* Copyright (c) 2021 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_SCREEN_CHANGE_CALLBACK_DEATH_RECIPIENT_H
#define RS_SCREEN_CHANGE_CALLBACK_DEATH_RECIPIENT_H
#include <iremote_object.h>
#include "rs_screen_manager.h"
namespace OHOS {
namespace Rosen {
class RSScreenChangeCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
public:
RSScreenChangeCallbackDeathRecipient(sptr<RSScreenManager> screenManager);
virtual ~RSScreenChangeCallbackDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
private:
sptr<RSScreenManager> screenManager_ = nullptr;
};
} // namespace Rosen
} // namespace OHOS
#endif // RS_SCREEN_CHANGE_CALLBACK_DEATH_RECIPIENT_H
/*
* Copyright (c) 2021 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_SERVICE_CONNECTION_STUB_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_STUB_H
#include <iremote_stub.h>
#include <message_option.h>
#include <message_parcel.h>
#include "platform/ohos/rs_irender_service_connection.h"
namespace OHOS {
namespace Rosen {
class RSRenderServiceConnectionStub : public IRemoteStub<RSIRenderServiceConnection> {
public:
RSRenderServiceConnectionStub() = default;
~RSRenderServiceConnectionStub() noexcept = default;
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
};
} // namespace Rosen
} // namespace OHOS
#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_STUB_H

View File

@ -15,241 +15,54 @@
#include "rs_render_service_stub.h"
#include "command/rs_command.h"
#include "command/rs_command_factory.h"
#include "transaction/rs_transaction_data.h"
#include <iremote_proxy.h>
namespace OHOS {
namespace Rosen {
class RSConnectionTokenProxy : public IRemoteProxy<RSIConnectionToken> {
public:
explicit RSConnectionTokenProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<RSIConnectionToken>(impl) {}
virtual ~RSConnectionTokenProxy() noexcept = default;
private:
static inline BrokerDelegator<RSConnectionTokenProxy> delegator_;
};
int RSRenderServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
int ret = 0;
int ret = ERR_NONE;
switch (code) {
case COMMIT_TRANSACTION: {
auto token = data.ReadInterfaceToken();
auto transactionData = data.ReadParcelable<RSTransactionData>();
std::unique_ptr<RSTransactionData> transData(transactionData);
CommitTransaction(transData);
break;
}
case CREATE_SURFACE: {
auto nodeId = data.ReadUint64();
RSSurfaceRenderNodeConfig config = {.id = nodeId};
sptr<Surface> surface = CreateNodeAndSurface(config);
auto producer = surface->GetProducer();
reply.WriteRemoteObject(producer->AsObject());
break;
}
case GET_DEFAULT_SCREEN_ID: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = GetDefaultScreenId();
reply.WriteUint64(id);
break;
}
case CREATE_VIRTUAL_DISPLAY: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
case CREATE_CONNECTION: {
auto interfaceToken = data.ReadInterfaceToken();
if (interfaceToken != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
// read the parcel data.
std::string name = data.ReadString();
uint32_t width = data.ReadUint32();
uint32_t height = data.ReadUint32();
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
auto remoteObj = data.ReadRemoteObject();
if (remoteObj == nullptr) {
ret = ERR_NULL_OBJECT;
break;
}
auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
ScreenId mirrorId = data.ReadUint64();
int32_t flags = data.ReadInt32();
ScreenId id = CreateVirtualScreen(name, width, height, surface, mirrorId, flags);
reply.WriteUint64(id);
break;
}
case REMOVE_VIRTUAL_DISPLAY: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RemoveVirtualScreen(id);
break;
}
case SET_SCREEN_CHANGE_CALLBACK: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
ret = ERR_NULL_OBJECT;
if (!remoteObj->IsProxyObject()) {
ret = ERR_UNKNOWN_OBJECT;
break;
}
sptr<RSIScreenChangeCallback> cb = iface_cast<RSIScreenChangeCallback>(remoteObject);
SetScreenChangeCallback(cb);
auto token = iface_cast<RSIConnectionToken>(remoteObj);
auto newConn = CreateConnection(token);
reply.WriteRemoteObject(newConn->AsObject());
break;
}
case SET_SCREEN_ACTIVE_MODE: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t modeId = data.ReadUint32();
SetScreenActiveMode(id, modeId);
default: {
ret = ERR_UNKNOWN_TRANSACTION;
break;
}
case SET_SCREEN_POWER_STATUS: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t status = data.ReadUint32();
SetScreenPowerStatus(id, static_cast<ScreenPowerStatus>(status));
break;
}
case TAKE_SURFACE_CAPTURE: {
NodeId id = data.ReadUint64();
auto remoteObject = data.ReadRemoteObject();
if (remoteObject == nullptr) {
ret = ERR_NULL_OBJECT;
break;
}
sptr<RSISurfaceCaptureCallback> cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
TakeSurfaceCapture(id, cb);
break;
}
case GET_SCREEN_ACTIVE_MODE: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenModeInfo screenModeInfo = GetScreenActiveMode(id);
reply.WriteParcelable(&screenModeInfo);
break;
}
case GET_SCREEN_SUPPORTED_MODES: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
std::vector<RSScreenModeInfo> screenSupportedModes = GetScreenSupportedModes(id);
reply.WriteUint64(static_cast<uint64_t>(screenSupportedModes.size()));
for (uint32_t modeIndex = 0; modeIndex < screenSupportedModes.size(); modeIndex++) {
reply.WriteParcelable(&screenSupportedModes[modeIndex]);
}
break;
}
case GET_SCREEN_CAPABILITY: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenCapability screenCapability = GetScreenCapability(id);
reply.WriteParcelable(&screenCapability);
break;
}
case GET_SCREEN_POWER_STATUS: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
ScreenPowerStatus status = GetScreenPowerStatus(id);
reply.WriteUint32(static_cast<uint32_t>(status));
break;
}
case GET_SCREEN_DATA: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
RSScreenData screenData = GetScreenData(id);
reply.WriteParcelable(&screenData);
break;
}
case EXECUTE_SYNCHRONOUS_TASK: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
auto type = data.ReadUint16();
auto subType = data.ReadUint16();
if (type != RS_NODE_SYNCHRONOUS_READ_PROPERTY) {
ret = ERR_INVALID_STATE;
break;
}
auto func = RSCommandFactory::Instance().GetUnmarshallingFunc(type, subType);
if (func == nullptr) {
ret = ERR_INVALID_STATE;
break;
}
auto command = static_cast<RSSyncTask*>((*func)(data));
if (command == nullptr) {
ret = ERR_INVALID_STATE;
break;
}
std::shared_ptr<RSSyncTask> task(command);
ExecuteSynchronousTask(task);
if (!task->Marshalling(reply)) {
ret = ERR_INVALID_STATE;
}
break;
}
case GET_SCREEN_BACK_LIGHT: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
int32_t level = GetScreenBacklight(id);
reply.WriteInt32(level);
break;
}
case SET_SCREEN_BACK_LIGHT: {
auto token = data.ReadInterfaceToken();
if (token != RSIRenderService::GetDescriptor()) {
ret = ERR_INVALID_STATE;
break;
}
ScreenId id = data.ReadUint64();
uint32_t level = data.ReadUint32();
SetScreenBacklight(id, level);
break;
}
default:
break;
}
return ret;
}
} // namespace Rosen
} // namespace OHOS

View File

@ -21,19 +21,16 @@
#include <message_parcel.h>
#include "platform/ohos/rs_irender_service.h"
#include "screen_manager/screen_types.h"
namespace OHOS {
namespace Rosen {
class RSRenderServiceStub : public IRemoteStub<RSIRenderService> {
public:
RSRenderServiceStub() = default;
~RSRenderServiceStub() = default;
~RSRenderServiceStub() noexcept = default;
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -16,93 +16,30 @@
#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_H
#include <memory>
#include <queue>
#include <string>
#include <iremote_broker.h>
#include <surface.h>
#include "command/rs_command.h"
#include "screen_manager/screen_types.h"
#include "screen_manager/rs_screen_mode_info.h"
#include "screen_manager/rs_screen_capability.h"
#include "screen_manager/rs_screen_data.h"
#include "ipc_callbacks/screen_change_callback.h"
#include "ipc_callbacks/surface_capture_callback.h"
#include "transaction/rs_transaction_data.h"
#include "rs_irender_service_connection.h"
namespace OHOS {
namespace Rosen {
class RSSyncTask;
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");
RSIRenderService() = default;
virtual ~RSIRenderService() = default;
virtual ~RSIRenderService() noexcept = default;
enum {
COMMIT_TRANSACTION,
CREATE_SURFACE,
GET_DEFAULT_SCREEN_ID,
CREATE_VIRTUAL_DISPLAY,
REMOVE_VIRTUAL_DISPLAY,
SET_SCREEN_CHANGE_CALLBACK,
SET_SCREEN_ACTIVE_MODE,
SET_SCREEN_POWER_STATUS,
TAKE_SURFACE_CAPTURE,
SET_SCREEN_BACK_LIGHT,
GET_SCREEN_ACTIVE_MODE,
GET_SCREEN_SUPPORTED_MODES,
GET_SCREEN_CAPABILITY,
GET_SCREEN_POWER_STATUS,
GET_SCREEN_DATA,
EXECUTE_SYNCHRONOUS_TASK,
GET_SCREEN_BACK_LIGHT,
CREATE_CONNECTION,
};
virtual void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) = 0;
virtual void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) = 0;
virtual sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) = 0;
virtual ScreenId GetDefaultScreenId() = 0;
// mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
virtual ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) = 0;
virtual void RemoveVirtualScreen(ScreenId id) = 0;
virtual void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) = 0;
virtual void SetScreenActiveMode(ScreenId id, uint32_t modeId) = 0;
virtual void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) = 0;
virtual void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) = 0;
virtual RSScreenModeInfo GetScreenActiveMode(ScreenId id) = 0;
virtual std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) = 0;
virtual RSScreenCapability GetScreenCapability(ScreenId id) = 0;
virtual ScreenPowerStatus GetScreenPowerStatus(ScreenId id) = 0;
virtual RSScreenData GetScreenData(ScreenId id) = 0;
virtual int32_t GetScreenBacklight(ScreenId id) = 0;
virtual void SetScreenBacklight(ScreenId id, uint32_t level) = 0;
virtual sptr<RSIRenderServiceConnection> CreateConnection(const sptr<RSIConnectionToken>& token) = 0;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2021 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_SERVICE_CONNECTION_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_CONNECTION_H
#include <string>
#include <iremote_broker.h>
#include <surface.h>
#include "command/rs_command.h"
#include "screen_manager/screen_types.h"
#include "screen_manager/rs_screen_mode_info.h"
#include "screen_manager/rs_screen_capability.h"
#include "screen_manager/rs_screen_data.h"
#include "ipc_callbacks/screen_change_callback.h"
#include "ipc_callbacks/surface_capture_callback.h"
#include "transaction/rs_transaction_data.h"
namespace OHOS {
namespace Rosen {
class RSSyncTask;
class RSIRenderServiceConnection : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rosen.RenderServiceConnection");
RSIRenderServiceConnection() = default;
virtual ~RSIRenderServiceConnection() noexcept = default;
enum {
COMMIT_TRANSACTION,
CREATE_NODE_AND_SURFACE,
GET_DEFAULT_SCREEN_ID,
CREATE_VIRTUAL_SCREEN,
REMOVE_VIRTUAL_SCREEN,
SET_SCREEN_CHANGE_CALLBACK,
SET_SCREEN_ACTIVE_MODE,
SET_SCREEN_POWER_STATUS,
SET_SCREEN_BACK_LIGHT,
TAKE_SURFACE_CAPTURE,
GET_SCREEN_ACTIVE_MODE,
GET_SCREEN_SUPPORTED_MODES,
GET_SCREEN_CAPABILITY,
GET_SCREEN_POWER_STATUS,
GET_SCREEN_BACK_LIGHT,
GET_SCREEN_DATA,
EXECUTE_SYNCHRONOUS_TASK,
};
virtual void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) = 0;
virtual void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) = 0;
virtual sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) = 0;
virtual ScreenId GetDefaultScreenId() = 0;
// mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
virtual ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) = 0;
virtual void RemoveVirtualScreen(ScreenId id) = 0;
virtual void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) = 0;
virtual void SetScreenActiveMode(ScreenId id, uint32_t modeId) = 0;
virtual void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) = 0;
virtual void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) = 0;
virtual RSScreenModeInfo GetScreenActiveMode(ScreenId id) = 0;
virtual std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) = 0;
virtual RSScreenCapability GetScreenCapability(ScreenId id) = 0;
virtual ScreenPowerStatus GetScreenPowerStatus(ScreenId id) = 0;
virtual RSScreenData GetScreenData(ScreenId id) = 0;
virtual int32_t GetScreenBacklight(ScreenId id) = 0;
virtual void SetScreenBacklight(ScreenId id, uint32_t level) = 0;
};
} // namespace Rosen
} // namespace OHOS
#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_IRENDER_SERVICE_CONNECTION_H

View File

@ -40,7 +40,8 @@ ohos_source_set("rosen_ohos_sources") {
"backend/rs_surface_ohos_raster.cpp",
"rs_log.cpp",
"rs_render_service_client.cpp",
"rs_render_service_connect.cpp",
"rs_render_service_connect_hub.cpp",
"rs_render_service_connection_proxy.cpp",
"rs_render_service_proxy.cpp",
"rs_surface_frame_ohos.cpp",
"rs_surface_ohos.cpp",

View File

@ -21,7 +21,7 @@
#include "ipc_callbacks/screen_change_callback_stub.h"
#include "ipc_callbacks/surface_capture_callback_stub.h"
#include "platform/common/rs_log.h"
#include "rs_render_service_connect.h"
#include "rs_render_service_connect_hub.h"
#include "rs_surface_ohos.h"
namespace OHOS {
@ -34,7 +34,7 @@ std::shared_ptr<RSIRenderClient> RSIRenderClient::CreateRenderServiceClient()
void RSRenderServiceClient::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService != nullptr) {
renderService->CommitTransaction(transactionData);
}
@ -42,7 +42,7 @@ void RSRenderServiceClient::CommitTransaction(std::unique_ptr<RSTransactionData>
void RSRenderServiceClient::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService != nullptr) {
renderService->ExecuteSynchronousTask(task);
}
@ -50,7 +50,7 @@ void RSRenderServiceClient::ExecuteSynchronousTask(const std::shared_ptr<RSSyncT
std::shared_ptr<RSSurface> RSRenderServiceClient::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return nullptr;
}
@ -104,7 +104,7 @@ private:
bool RSRenderServiceClient::TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
ROSEN_LOGE("RSRenderServiceClient::TakeSurfaceCapture renderService == nullptr!");
return false;
@ -131,7 +131,7 @@ bool RSRenderServiceClient::TakeSurfaceCapture(NodeId id, std::shared_ptr<Surfac
ScreenId RSRenderServiceClient::GetDefaultScreenId()
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return INVALID_SCREEN_ID;
}
@ -147,7 +147,7 @@ ScreenId RSRenderServiceClient::CreateVirtualScreen(
ScreenId mirrorId,
int32_t flags)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return INVALID_SCREEN_ID;
}
@ -157,7 +157,7 @@ ScreenId RSRenderServiceClient::CreateVirtualScreen(
void RSRenderServiceClient::RemoveVirtualScreen(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return;
}
@ -184,7 +184,7 @@ private:
void RSRenderServiceClient::SetScreenChangeCallback(const ScreenChangeCallback &callback)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return;
}
@ -195,7 +195,7 @@ void RSRenderServiceClient::SetScreenChangeCallback(const ScreenChangeCallback &
void RSRenderServiceClient::SetScreenActiveMode(ScreenId id, uint32_t modeId)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return;
}
@ -205,7 +205,7 @@ void RSRenderServiceClient::SetScreenActiveMode(ScreenId id, uint32_t modeId)
void RSRenderServiceClient::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return;
}
@ -215,7 +215,7 @@ void RSRenderServiceClient::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus
RSScreenModeInfo RSRenderServiceClient::GetScreenActiveMode(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return RSScreenModeInfo {}; // return empty RSScreenModeInfo.
}
@ -225,7 +225,7 @@ RSScreenModeInfo RSRenderServiceClient::GetScreenActiveMode(ScreenId id)
std::vector<RSScreenModeInfo> RSRenderServiceClient::GetScreenSupportedModes(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return {};
}
@ -235,7 +235,7 @@ std::vector<RSScreenModeInfo> RSRenderServiceClient::GetScreenSupportedModes(Scr
RSScreenCapability RSRenderServiceClient::GetScreenCapability(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return RSScreenCapability {};
}
@ -245,7 +245,7 @@ RSScreenCapability RSRenderServiceClient::GetScreenCapability(ScreenId id)
ScreenPowerStatus RSRenderServiceClient::GetScreenPowerStatus(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return ScreenPowerStatus::INVALID_POWER_STATUS;
}
@ -255,7 +255,7 @@ ScreenPowerStatus RSRenderServiceClient::GetScreenPowerStatus(ScreenId id)
RSScreenData RSRenderServiceClient::GetScreenData(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return RSScreenData {};
}
@ -265,7 +265,7 @@ RSScreenData RSRenderServiceClient::GetScreenData(ScreenId id)
int32_t RSRenderServiceClient::GetScreenBacklight(ScreenId id)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return INVALID_BACKLIGHT_VALUE;
}
@ -275,7 +275,7 @@ int32_t RSRenderServiceClient::GetScreenBacklight(ScreenId id)
void RSRenderServiceClient::SetScreenBacklight(ScreenId id, uint32_t level)
{
auto renderService = RSRenderServiceConnect::GetRenderService();
auto renderService = RSRenderServiceConnectHub::GetRenderService();
if (renderService == nullptr) {
return;
}

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2021 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_service_connect.h"
#include <if_system_ability_manager.h>
#include <iservice_registry.h>
#include <system_ability_definition.h>
#include "rs_render_service_proxy.h"
#include "platform/common/rs_log.h"
namespace OHOS {
namespace Rosen {
RSRenderServiceConnect::RSRenderServiceConnect()
{
}
RSRenderServiceConnect::~RSRenderServiceConnect()
{
}
sptr<RSIRenderService> RSRenderServiceConnect::GetRenderService()
{
std::lock_guard<std::mutex> lock(RSRenderServiceConnect::GetInstance().renderConnectlock_);
if (RSRenderServiceConnect::GetInstance().renderService_ == nullptr) {
bool result = RSRenderServiceConnect::GetInstance().Connect();
if (!result) {
ROSEN_LOGE("RenderService connect fail");
return nullptr;
}
}
return RSRenderServiceConnect::GetInstance().renderService_;
}
bool RSRenderServiceConnect::Connect()
{
if (renderService_ != nullptr) {
return true;
}
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
ROSEN_LOGE("RSRenderServiceConnect::Connect, GetSystemAbilityManager failed");
return false;
}
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(RENDER_SERVICE);
if (remoteObject == nullptr) {
ROSEN_LOGE("RSRenderServiceConnect::Connect, GetSystemAbility(RENDER_SERVICE) failed");
return false;
}
if (deathRecipient_ == nullptr) {
deathRecipient_ = sptr<RenderServiceDeathRecipient>(new RenderServiceDeathRecipient());
}
if ((remoteObject->IsProxyObject()) && (!remoteObject->AddDeathRecipient(deathRecipient_))) {
}
renderService_ = iface_cast<RSRenderServiceProxy>(remoteObject);
if (renderService_ == nullptr) {
ROSEN_LOGE("RSRenderServiceConnect::Connect, renderService_ is nullptr");
return false;
}
return true;
}
void RSRenderServiceConnect::ConnectDied()
{
std::lock_guard<std::mutex> lock(renderConnectlock_);
renderService_ = nullptr;
deathRecipient_ = nullptr;
}
void RSRenderServiceConnect::RenderServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
RSRenderServiceConnect::GetInstance().ConnectDied();
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,160 @@
/*
* Copyright (c) 2021 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_service_connect_hub.h"
#include <if_system_ability_manager.h>
#include <iremote_stub.h>
#include <iservice_registry.h>
#include <mutex>
#include <system_ability_definition.h>
#include <unistd.h>
#include "message_parcel.h"
#include "rs_render_service_proxy.h"
#include "rs_render_service_connection_proxy.h"
#include "platform/common/rs_log.h"
namespace OHOS {
namespace Rosen {
std::once_flag RSRenderServiceConnectHub::flag_;
RSRenderServiceConnectHub* RSRenderServiceConnectHub::instance_ = nullptr;
RSRenderServiceConnectHub* RSRenderServiceConnectHub::GetInstance()
{
std::call_once(flag_, &RSRenderServiceConnectHub::Init);
return instance_;
}
void RSRenderServiceConnectHub::Init()
{
instance_ = new RSRenderServiceConnectHub();
::atexit(&RSRenderServiceConnectHub::Destory);
}
void RSRenderServiceConnectHub::Destory()
{
if (instance_ != nullptr) {
delete instance_;
instance_ = nullptr;
}
}
RSRenderServiceConnectHub::RSRenderServiceConnectHub()
{
}
RSRenderServiceConnectHub::~RSRenderServiceConnectHub()
{
}
sptr<RSIRenderServiceConnection> RSRenderServiceConnectHub::GetRenderService()
{
auto connHub = RSRenderServiceConnectHub::GetInstance();
return connHub == nullptr ? nullptr : connHub->GetRenderServiceConnection();
}
sptr<RSIRenderServiceConnection> RSRenderServiceConnectHub::GetRenderServiceConnection()
{
std::lock_guard<std::mutex> lock(mutex_);
if (conn_ != nullptr && renderService_ != nullptr) {
return conn_;
}
if (!Connect()) {
ROSEN_LOGE("RenderService connect fail");
return nullptr;
}
return conn_;
}
bool RSRenderServiceConnectHub::Connect()
{
int tryCnt = 0;
do {
// sleep move time (1000us * tryCnt) wthen tryCnt++
usleep(1000 * tryCnt);
++tryCnt;
// try most 5 times to get render service.
if (tryCnt == 5) {
ROSEN_LOGE("RSRenderServiceConnect::Connect failed, tried %d times.", tryCnt);
break;
}
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
continue;
}
auto remoteObject = samgr->GetSystemAbility(RENDER_SERVICE);
if (remoteObject == nullptr || !remoteObject->IsProxyObject()) {
continue;
}
renderService_ = iface_cast<RSRenderServiceProxy>(remoteObject);
if (renderService_ != nullptr) {
break;
}
} while (true);
if (renderService_ == nullptr) {
ROSEN_LOGE("RSRenderServiceConnect::Connect, failed to get render service proxy.");
return false;
}
deathRecipient_ = new RenderServiceDeathRecipient(this);
if (!renderService_->AsObject()->AddDeathRecipient(deathRecipient_)) {
ROSEN_LOGW("RSRenderServiceConnect::Connect, failed to AddDeathRecipient of render service.");
}
if (token_ == nullptr) {
token_ = new IRemoteStub<RSIConnectionToken>();
}
conn_ = renderService_->CreateConnection(token_);
if (conn_ == nullptr) {
ROSEN_LOGE("RSRenderServiceConnect::Connect, failed to CreateConnection to render service.");
return false;
}
return true;
}
void RSRenderServiceConnectHub::ConnectDied()
{
std::lock_guard<std::mutex> lock(mutex_);
renderService_ = nullptr;
conn_ = nullptr;
deathRecipient_ = nullptr;
}
void RSRenderServiceConnectHub::RenderServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
auto remoteSptr = remote.promote();
if (remoteSptr == nullptr) {
ROSEN_LOGW("RSRenderServiceConnectHub::RenderServiceDeathRecipient::OnRemoteDied: can't promote.");
return;
}
auto rsConnHub = rsConnHub_.promote();
if (rsConnHub == nullptr) {
ROSEN_LOGW("RSRenderServiceConnectHub::RenderServiceDeathRecipient::OnRemoteDied: connHub was dead.");
return;
}
rsConnHub->ConnectDied();
}
} // namespace Rosen
} // namespace OHOS

View File

@ -13,42 +13,54 @@
* limitations under the License.
*/
#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_H
#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_HUB_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_HUB_H
#include <singleton.h>
#include "platform/ohos/rs_irender_service.h"
#include <mutex>
#include <platform/ohos/rs_irender_service.h>
namespace OHOS {
namespace Rosen {
class RSRenderServiceConnect : public Singleton<RSRenderServiceConnect> {
class RSRenderServiceConnectHub : public RefBase {
public:
static sptr<RSIRenderService> GetRenderService();
static sptr<RSIRenderServiceConnection> GetRenderService();
private:
static RSRenderServiceConnectHub* GetInstance();
static void Init();
static void Destory();
RSRenderServiceConnectHub();
~RSRenderServiceConnectHub() noexcept;
class RenderServiceDeathRecipient final : public IRemoteObject::DeathRecipient {
public:
RenderServiceDeathRecipient() = default;
~RenderServiceDeathRecipient() final = default;
RenderServiceDeathRecipient(wptr<RSRenderServiceConnectHub> rsConnHub)
: rsConnHub_(std::move(rsConnHub)) {}
~RenderServiceDeathRecipient() noexcept final = default;
DISALLOW_COPY_AND_MOVE(RenderServiceDeathRecipient);
void OnRemoteDied(const wptr<IRemoteObject> &remote) final override;
private:
wptr<RSRenderServiceConnectHub> rsConnHub_;
};
sptr<RSIRenderServiceConnection> GetRenderServiceConnection();
bool Connect();
void ConnectDied();
std::mutex renderConnectlock_;
mutable std::mutex mutex_;
sptr<RSIRenderService> renderService_;
sptr<RSIConnectionToken> token_;
sptr<RSIRenderServiceConnection> conn_;
sptr<IRemoteObject::DeathRecipient> deathRecipient_;
DECLARE_SINGLETON(RSRenderServiceConnect)
static std::once_flag flag_;
static RSRenderServiceConnectHub* instance_;
};
} // namespace Rosen
} // namespace OHOS
#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_H
#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECT_HUB_H

View File

@ -0,0 +1,401 @@
/*
* Copyright (c) 2021 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_service_connection_proxy.h"
#include <message_option.h>
#include <message_parcel.h>
#include "platform/common/rs_log.h"
namespace OHOS {
namespace Rosen {
RSRenderServiceConnectionProxy::RSRenderServiceConnectionProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<RSIRenderServiceConnection>(impl)
{
}
void RSRenderServiceConnectionProxy::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
if (!data.WriteParcelable(transactionData.get())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::COMMIT_TRANSACTION, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceConnectionProxy::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
if (!task->Marshalling(data)) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::EXECUTE_SYNCHRONOUS_TASK, data, reply, option);
if (err != NO_ERROR) {
return;
}
if (task->CheckHeader(reply)) {
task->ReadFromParcel(reply);
}
}
sptr<Surface> RSRenderServiceConnectionProxy::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteUint64(config.id)) {
return nullptr;
}
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_NODE_AND_SURFACE, data, reply, option);
if (err != NO_ERROR) {
return nullptr;
}
sptr<IRemoteObject> surfaceObject = reply.ReadRemoteObject();
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
return surface;
}
ScreenId RSRenderServiceConnectionProxy::GetDefaultScreenId()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return INVALID_SCREEN_ID;
}
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_DEFAULT_SCREEN_ID, data, reply, option);
if (err != NO_ERROR) {
return INVALID_SCREEN_ID;
}
ScreenId id = reply.ReadUint64();
return id;
}
ScreenId RSRenderServiceConnectionProxy::CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return INVALID_SCREEN_ID;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteString(name);
data.WriteUint32(width);
data.WriteUint32(height);
auto producer = surface->GetProducer();
data.WriteRemoteObject(producer->AsObject());
data.WriteUint64(mirrorId);
data.WriteInt32(flags);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_VIRTUAL_SCREEN, data, reply, option);
if (err != NO_ERROR) {
return INVALID_SCREEN_ID;
}
ScreenId id = reply.ReadUint64();
return id;
}
void RSRenderServiceConnectionProxy::RemoveVirtualScreen(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::REMOVE_VIRTUAL_SCREEN, data, reply, option);
if (err != NO_ERROR) {
ROSEN_LOGE("RSRenderServiceConnectionProxy::RemoveVirtualScreen: Send Request err.");
}
}
void RSRenderServiceConnectionProxy::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
{
if (callback == nullptr) {
ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: callback is nullptr.");
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteRemoteObject(callback->AsObject());
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_CHANGE_CALLBACK, data, reply, option);
if (err != NO_ERROR) {
ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: Send Request err.");
}
}
void RSRenderServiceConnectionProxy::SetScreenActiveMode(ScreenId id, uint32_t modeId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(modeId);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_ACTIVE_MODE, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceConnectionProxy::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(static_cast<uint32_t>(status));
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_POWER_STATUS, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceConnectionProxy::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback)
{
if (callback == nullptr) {
ROSEN_LOGE("RSRenderServiceProxy: callback == nullptr\n");
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteUint64(id);
data.WriteRemoteObject(callback->AsObject());
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::TAKE_SURFACE_CAPTURE, data, reply, option);
if (err != NO_ERROR) {
ROSEN_LOGE("RSRenderServiceProxy: Remote()->SendRequest() error.\n");
return;
}
}
RSScreenModeInfo RSRenderServiceConnectionProxy::GetScreenActiveMode(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenModeInfo screenModeInfo;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return screenModeInfo;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_ACTIVE_MODE, data, reply, option);
if (err != NO_ERROR) {
return screenModeInfo;
}
sptr<RSScreenModeInfo> pScreenModeInfo(reply.ReadParcelable<RSScreenModeInfo>());
if (pScreenModeInfo == nullptr) {
return screenModeInfo;
}
screenModeInfo = *pScreenModeInfo;
return screenModeInfo;
}
std::vector<RSScreenModeInfo> RSRenderServiceConnectionProxy::GetScreenSupportedModes(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
std::vector<RSScreenModeInfo> screenSupportedModes;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return screenSupportedModes;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_SUPPORTED_MODES, data, reply, option);
if (err != NO_ERROR) {
return screenSupportedModes;
}
uint64_t modeCount = reply.ReadUint64();
screenSupportedModes.resize(modeCount);
for (uint64_t modeIndex = 0; modeIndex < modeCount; modeIndex++) {
sptr<RSScreenModeInfo> itemScreenMode = reply.ReadParcelable<RSScreenModeInfo>();
if (itemScreenMode == nullptr) {
continue;
} else {
screenSupportedModes[modeIndex] = *itemScreenMode;
}
}
return screenSupportedModes;
}
RSScreenCapability RSRenderServiceConnectionProxy::GetScreenCapability(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenCapability screenCapability;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return screenCapability;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_CAPABILITY, data, reply, option);
if (err != NO_ERROR) {
return screenCapability;
}
sptr<RSScreenCapability> pScreenCapability(reply.ReadParcelable<RSScreenCapability>());
if (pScreenCapability == nullptr) {
return screenCapability;
}
screenCapability = *pScreenCapability;
return screenCapability;
}
ScreenPowerStatus RSRenderServiceConnectionProxy::GetScreenPowerStatus(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return INVALID_POWER_STATUS;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_POWER_STATUS, data, reply, option);
if (err != NO_ERROR) {
return INVALID_POWER_STATUS;
}
return static_cast<ScreenPowerStatus>(reply.ReadUint32());
}
RSScreenData RSRenderServiceConnectionProxy::GetScreenData(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenData screenData;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return screenData;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_DATA, data, reply, option);
if (err != NO_ERROR) {
return screenData;
}
sptr<RSScreenData> pScreenData(reply.ReadParcelable<RSScreenData>());
if (pScreenData == nullptr) {
return screenData;
}
screenData = *pScreenData;
return screenData;
}
int32_t RSRenderServiceConnectionProxy::GetScreenBacklight(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return INVALID_BACKLIGHT_VALUE;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_BACK_LIGHT, data, reply, option);
if (err != NO_ERROR) {
return INVALID_BACKLIGHT_VALUE;
}
int32_t level = reply.ReadInt32();
return level;
}
void RSRenderServiceConnectionProxy::SetScreenBacklight(ScreenId id, uint32_t level)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(level);
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_BACK_LIGHT, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 2021 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_SERVICE_CONNECTION_PROXY_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_PROXY_H
#include <iremote_proxy.h>
#include <platform/ohos/rs_irender_service_connection.h>
namespace OHOS {
namespace Rosen {
class RSRenderServiceConnectionProxy : public IRemoteProxy<RSIRenderServiceConnection> {
public:
explicit RSRenderServiceConnectionProxy(const sptr<IRemoteObject>& impl);
virtual ~RSRenderServiceConnectionProxy() noexcept = default;
void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
ScreenId GetDefaultScreenId() override;
// mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) override;
void RemoveVirtualScreen(ScreenId id) override;
void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) override;
RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
RSScreenCapability GetScreenCapability(ScreenId id) override;
ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
RSScreenData GetScreenData(ScreenId id) override;
int32_t GetScreenBacklight(ScreenId id) override;
void SetScreenBacklight(ScreenId id, uint32_t level) override;
private:
static inline BrokerDelegator<RSRenderServiceConnectionProxy> delegator_;
};
} // namespace Rosen
} // namespace OHOS
#endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_PROXY_H

View File

@ -17,383 +17,43 @@
#include <message_option.h>
#include <message_parcel.h>
#include "command/rs_command.h"
#include "platform/common/rs_log.h"
#include <platform/common/rs_log.h>
namespace OHOS {
namespace Rosen {
RSRenderServiceProxy::RSRenderServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<RSIRenderService>(impl) {}
void RSRenderServiceProxy::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
sptr<RSIRenderServiceConnection> RSRenderServiceProxy::CreateConnection(const sptr<RSIConnectionToken>& token)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSRenderServiceProxy::GetDescriptor())) {
return;
}
if (!data.WriteParcelable(transactionData.get())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
int32_t err = Remote()->SendRequest(RSIRenderService::COMMIT_TRANSACTION, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceProxy::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSRenderServiceProxy::GetDescriptor())) {
return;
}
if (!task->Marshalling(data)) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderService::EXECUTE_SYNCHRONOUS_TASK, data, reply, option);
if (err != NO_ERROR) {
return;
}
if (task->CheckHeader(reply)) {
task->ReadFromParcel(reply);
}
}
sptr<Surface> RSRenderServiceProxy::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteUint64(config.id)) {
if (token == nullptr) {
ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): token is null.");
return nullptr;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderService::CREATE_SURFACE, data, reply, option);
if (err != NO_ERROR) {
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): WriteInterfaceToken failed.");
return nullptr;
}
sptr<IRemoteObject> surfaceObject = reply.ReadRemoteObject();
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
return surface;
}
ScreenId RSRenderServiceProxy::GetDefaultScreenId()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return INVALID_SCREEN_ID;
}
option.SetFlags(MessageOption::TF_SYNC);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_DEFAULT_SCREEN_ID, data, reply, option);
data.WriteRemoteObject(token->AsObject());
int32_t err = Remote()->SendRequest(RSIRenderService::CREATE_CONNECTION, data, reply, option);
if (err != NO_ERROR) {
return INVALID_SCREEN_ID;
ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): SendRequest failed, err is %d.", err);
return nullptr;
}
ScreenId id = reply.ReadUint64();
return id;
}
ScreenId RSRenderServiceProxy::CreateVirtualScreen(
const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface, ScreenId mirrorId, int32_t flags)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return INVALID_SCREEN_ID;
auto remoteObj = reply.ReadRemoteObject();
if (remoteObj == nullptr || !remoteObj->IsProxyObject()) {
ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): Reply is not valid.");
return nullptr;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteString(name);
data.WriteUint32(width);
data.WriteUint32(height);
auto producer = surface->GetProducer();
data.WriteRemoteObject(producer->AsObject());
data.WriteUint64(mirrorId);
data.WriteInt32(flags);
int32_t err = Remote()->SendRequest(RSIRenderService::CREATE_VIRTUAL_DISPLAY, data, reply, option);
if (err != NO_ERROR) {
return INVALID_SCREEN_ID;
}
ScreenId id = reply.ReadUint64();
return id;
}
void RSRenderServiceProxy::RemoveVirtualScreen(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::REMOVE_VIRTUAL_DISPLAY, data, reply, option);
if (err != NO_ERROR) {
// TODO: Error log.
}
}
void RSRenderServiceProxy::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
{
if (callback == nullptr) {
// TODO: Error Log
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteRemoteObject(callback->AsObject());
int32_t err = Remote()->SendRequest(RSIRenderService::SET_SCREEN_CHANGE_CALLBACK, data, reply, option);
if (err != NO_ERROR) {
// TODO: Error log.
}
}
void RSRenderServiceProxy::SetScreenActiveMode(ScreenId id, uint32_t modeId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(modeId);
int32_t err = Remote()->SendRequest(RSIRenderService::SET_SCREEN_ACTIVE_MODE, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceProxy::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(static_cast<uint32_t>(status));
int32_t err = Remote()->SendRequest(RSIRenderService::SET_SCREEN_POWER_STATUS, data, reply, option);
if (err != NO_ERROR) {
return;
}
}
void RSRenderServiceProxy::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback)
{
if (callback == nullptr) {
ROSEN_LOGE("RSRenderServiceProxy::TakeSurfaceCapture callback == nullptr");
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
option.SetFlags(MessageOption::TF_ASYNC);
data.WriteUint64(id);
data.WriteRemoteObject(callback->AsObject());
int32_t err = Remote()->SendRequest(RSIRenderService::TAKE_SURFACE_CAPTURE, data, reply, option);
if (err != NO_ERROR) {
ROSEN_LOGE("RSRenderServiceProxy::TakeSurfaceCapture Remote()->SendRequest() error.");
return;
}
}
RSScreenModeInfo RSRenderServiceProxy::GetScreenActiveMode(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenModeInfo screenModeInfo;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return screenModeInfo;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_ACTIVE_MODE, data, reply, option);
if (err != NO_ERROR) {
return screenModeInfo;
}
sptr<RSScreenModeInfo> pScreenModeInfo(reply.ReadParcelable<RSScreenModeInfo>());
if (pScreenModeInfo == nullptr) {
return screenModeInfo;
}
screenModeInfo = *pScreenModeInfo;
return screenModeInfo;
}
std::vector<RSScreenModeInfo> RSRenderServiceProxy::GetScreenSupportedModes(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
std::vector<RSScreenModeInfo> screenSupportedModes;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return screenSupportedModes;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_SUPPORTED_MODES, data, reply, option);
if (err != NO_ERROR) {
return screenSupportedModes;
}
uint64_t modeCount = reply.ReadUint64();
screenSupportedModes.resize(modeCount);
for (uint64_t modeIndex = 0; modeIndex < modeCount; modeIndex++) {
sptr<RSScreenModeInfo> itemScreenMode = reply.ReadParcelable<RSScreenModeInfo>();
if (itemScreenMode == nullptr) {
continue;
} else {
screenSupportedModes[modeIndex] = *itemScreenMode;
}
}
return screenSupportedModes;
}
RSScreenCapability RSRenderServiceProxy::GetScreenCapability(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenCapability screenCapability;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return screenCapability;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_CAPABILITY, data, reply, option);
if (err != NO_ERROR) {
return screenCapability;
}
sptr<RSScreenCapability> pScreenCapability(reply.ReadParcelable<RSScreenCapability>());
if (pScreenCapability == nullptr) {
return screenCapability;
}
screenCapability = *pScreenCapability;
return screenCapability;
}
ScreenPowerStatus RSRenderServiceProxy::GetScreenPowerStatus(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return INVALID_POWER_STATUS;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_POWER_STATUS, data, reply, option);
if (err != NO_ERROR) {
return INVALID_POWER_STATUS;
}
return static_cast<ScreenPowerStatus>(reply.ReadUint32());
}
RSScreenData RSRenderServiceProxy::GetScreenData(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
RSScreenData screenData;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return screenData;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_DATA, data, reply, option);
if (err != NO_ERROR) {
return screenData;
}
sptr<RSScreenData> pScreenData(reply.ReadParcelable<RSScreenData>());
if (pScreenData == nullptr) {
return screenData;
}
screenData = *pScreenData;
return screenData;
}
int RSRenderServiceProxy::Dump(int fd, const std::vector<std::u16string> &args)
{
return Remote()->Dump(fd, args);
}
int32_t RSRenderServiceProxy::GetScreenBacklight(ScreenId id)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return INVALID_BACKLIGHT_VALUE;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
int32_t err = Remote()->SendRequest(RSIRenderService::GET_SCREEN_BACK_LIGHT, data, reply, option);
if (err != NO_ERROR) {
return INVALID_BACKLIGHT_VALUE;
}
int32_t level = reply.ReadInt32();
return level;
}
void RSRenderServiceProxy::SetScreenBacklight(ScreenId id, uint32_t level)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
return;
}
option.SetFlags(MessageOption::TF_SYNC);
data.WriteUint64(id);
data.WriteUint32(level);
int32_t err = Remote()->SendRequest(RSIRenderService::SET_SCREEN_BACK_LIGHT, data, reply, option);
if (err != NO_ERROR) {
return;
}
return iface_cast<RSIRenderServiceConnection>(remoteObj);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -16,13 +16,8 @@
#ifndef ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_PROXY_H
#define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_PROXY_H
#include <queue>
#include <iremote_proxy.h>
#include <surface.h>
#include "platform/ohos/rs_irender_service.h"
#include "screen_manager/screen_types.h"
#include <platform/ohos/rs_irender_service.h>
namespace OHOS {
namespace Rosen {
@ -30,49 +25,9 @@ namespace Rosen {
class RSRenderServiceProxy : public IRemoteProxy<RSIRenderService> {
public:
explicit RSRenderServiceProxy(const sptr<IRemoteObject>& impl);
virtual ~RSRenderServiceProxy() = default;
virtual ~RSRenderServiceProxy() noexcept = default;
void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
ScreenId GetDefaultScreenId() override;
// mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
ScreenId CreateVirtualScreen(
const std::string &name,
uint32_t width,
uint32_t height,
sptr<Surface> surface,
ScreenId mirrorId,
int32_t flags) override;
void RemoveVirtualScreen(ScreenId id) override;
void SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback) override;
RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
RSScreenCapability GetScreenCapability(ScreenId id) override;
ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
RSScreenData GetScreenData(ScreenId id) override;
int Dump(int fd, const std::vector<std::u16string> &args);
int32_t GetScreenBacklight(ScreenId id) override;
void SetScreenBacklight(ScreenId id, uint32_t level) override;
sptr<RSIRenderServiceConnection> CreateConnection(const sptr<RSIConnectionToken>& token) override;
private:
static inline BrokerDelegator<RSRenderServiceProxy> delegator_;

View File

@ -461,6 +461,11 @@ private:
int main()
{
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy == nullptr) {
return -1;
}
DisplayId id = g_dms.GetDefaultDisplayId();
std::cout << "level =" << g_dms.GetDisplayBacklight(id) << std::endl;
int lightValue = 0;
@ -484,12 +489,11 @@ int main()
auto surfaceNode = CreateSurface();
DrawSurface(SkRect::MakeXYWH(0, 0, 200, 200), 0xffa10f1b, SkRect::MakeXYWH(0, 0, 200, 200), surfaceNode);
displayNode->AddChild(surfaceNode, -1);
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
sleep(4);
transactionProxy->FlushImplicitTransaction();
while (1) {
DrawSurface(SkRect::MakeXYWH(0, 0, 200, 200), 0xffa10f1b, SkRect::MakeXYWH(0, 0, 200, 200), surfaceNode);
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
sleep(detail::SLEEP_TIME);
DrawSurface(SkRect::MakeXYWH(0, 0, 200, 200), 0xffa10f1b, SkRect::MakeXYWH(0, 0, 200, 200), surfaceNode);
transactionProxy->FlushImplicitTransaction();
}
return 0;