mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-12-20 05:39:50 +00:00
support ability view
Signed-off-by: AliceGao <gaobinbin3@huawei.com> Change-Id: I114b6cc8f50e0d605d0e74417e88d7c6038c2dc9
This commit is contained in:
parent
5931ec8edb
commit
d5703785dc
@ -376,11 +376,12 @@ void RSRenderServiceConnection::SetScreenBacklight(ScreenId id, uint32_t level)
|
||||
}).wait();
|
||||
}
|
||||
|
||||
void RSRenderServiceConnection::RegisterBufferAvailableListener(NodeId id, sptr<RSIBufferAvailableCallback> callback)
|
||||
void RSRenderServiceConnection::RegisterBufferAvailableListener(
|
||||
NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
|
||||
{
|
||||
auto registerBufferAvailableListener = [id, callback, this]() -> bool {
|
||||
auto registerBufferAvailableListener = [id, callback, isFromRenderThread, this]() -> bool {
|
||||
if (auto node = this->mainThread_->GetContext().GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
|
||||
node->RegisterBufferAvailableListener(callback);
|
||||
node->RegisterBufferAvailableListener(callback, isFromRenderThread);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -98,7 +98,8 @@ private:
|
||||
|
||||
void SetScreenBacklight(ScreenId id, uint32_t level) override;
|
||||
|
||||
void RegisterBufferAvailableListener(NodeId id, sptr<RSIBufferAvailableCallback> callback) override;
|
||||
void RegisterBufferAvailableListener(
|
||||
NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override;
|
||||
|
||||
int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override;
|
||||
|
||||
|
@ -287,12 +287,13 @@ int RSRenderServiceConnectionStub::OnRemoteRequest(
|
||||
}
|
||||
NodeId id = data.ReadUint64();
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
bool isFromRenderThread = data.ReadBool();
|
||||
if (remoteObject == nullptr) {
|
||||
ret = ERR_NULL_OBJECT;
|
||||
break;
|
||||
}
|
||||
sptr<RSIBufferAvailableCallback> cb = iface_cast<RSIBufferAvailableCallback>(remoteObject);
|
||||
RegisterBufferAvailableListener(id, cb);
|
||||
RegisterBufferAvailableListener(id, cb, isFromRenderThread);
|
||||
break;
|
||||
}
|
||||
case GET_SCREEN_SUPPORTED_GAMUTS: {
|
||||
|
@ -134,8 +134,10 @@ public:
|
||||
BlendType GetBlendType();
|
||||
void SetBlendType(BlendType blendType);
|
||||
|
||||
// Only SurfaceNode in RS calls "RegisterBufferAvailableListener" to save callback method sent by RT
|
||||
void RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback);
|
||||
// Only SurfaceNode in RS calls "RegisterBufferAvailableListener"
|
||||
// to save callback method sent by RT or UI which depands on the value of "isFromRenderThread".
|
||||
void RegisterBufferAvailableListener(
|
||||
sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread);
|
||||
|
||||
// Only SurfaceNode in RT calls "ConnectToNodeInRenderService" to send callback method to RS
|
||||
void ConnectToNodeInRenderService();
|
||||
@ -173,7 +175,8 @@ private:
|
||||
std::string name_;
|
||||
BlendType blendType_ = BlendType::BLEND_SRCOVER;
|
||||
std::atomic<bool> isBufferAvailable_ = false;
|
||||
sptr<RSIBufferAvailableCallback> callback_;
|
||||
sptr<RSIBufferAvailableCallback> callbackFromRT_;
|
||||
sptr<RSIBufferAvailableCallback> callbackFromUI_;
|
||||
std::function<void(void)> callbackForRenderThreadRefresh_ = nullptr;
|
||||
};
|
||||
} // namespace Rosen
|
||||
|
@ -124,7 +124,8 @@ public:
|
||||
|
||||
virtual void SetScreenBacklight(ScreenId id, uint32_t level) = 0;
|
||||
|
||||
virtual void RegisterBufferAvailableListener(NodeId id, sptr<RSIBufferAvailableCallback> callback) = 0;
|
||||
virtual void RegisterBufferAvailableListener(
|
||||
NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) = 0;
|
||||
|
||||
virtual int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) = 0;
|
||||
|
||||
|
@ -96,7 +96,8 @@ public:
|
||||
|
||||
void SetScreenBacklight(ScreenId id, uint32_t level);
|
||||
|
||||
bool RegisterBufferAvailableListener(NodeId id, const BufferAvailableCallback &callback);
|
||||
bool RegisterBufferAvailableListener(
|
||||
NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread = false);
|
||||
bool UnregisterBufferAvailableListener(NodeId id);
|
||||
|
||||
int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
|
||||
@ -117,7 +118,8 @@ public:
|
||||
private:
|
||||
void TriggerSurfaceCaptureCallback(NodeId id, Media::PixelMap* pixelmap);
|
||||
std::mutex mutex_;
|
||||
std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbMap_;
|
||||
std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbRTMap_;
|
||||
std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbUIMap_;
|
||||
sptr<RSIScreenChangeCallback> screenChangeCb_;
|
||||
sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_;
|
||||
std::map<NodeId, std::shared_ptr<SurfaceCaptureCallback>> surfaceCaptureCbMap_;
|
||||
|
@ -212,17 +212,22 @@ void RSSurfaceRenderNode::SetBlendType(BlendType blendType)
|
||||
blendType_ = blendType;
|
||||
}
|
||||
|
||||
void RSSurfaceRenderNode::RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback)
|
||||
void RSSurfaceRenderNode::RegisterBufferAvailableListener(
|
||||
sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
callback_ = callback;
|
||||
if (isFromRenderThread) {
|
||||
callbackFromRT_ = callback;
|
||||
} else {
|
||||
callbackFromUI_ = callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RSSurfaceRenderNode::ConnectToNodeInRenderService()
|
||||
{
|
||||
ROSEN_LOGI("RSSurfaceRenderNode::ConnectToNodeInRenderService nodeId = %llu", this->GetId());
|
||||
ROSEN_LOGI("RSSurfaceRenderNode::ConnectToNodeInRenderService nodeId = %llu", GetId());
|
||||
auto renderServiceClient =
|
||||
std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
|
||||
if (renderServiceClient != nullptr) {
|
||||
@ -233,13 +238,13 @@ void RSSurfaceRenderNode::ConnectToNodeInRenderService()
|
||||
return;
|
||||
}
|
||||
node->NotifyBufferAvailable();
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
void RSSurfaceRenderNode::NotifyBufferAvailable()
|
||||
{
|
||||
ROSEN_LOGI("RSSurfaceRenderNode::NotifyBufferAvailable nodeId = %llu", this->GetId());
|
||||
ROSEN_LOGI("RSSurfaceRenderNode::NotifyBufferAvailable nodeId = %llu", GetId());
|
||||
|
||||
// In RS, "isBufferAvailable_ = true" means buffer is ready and need to trigger ipc callback.
|
||||
// In RT, "isBufferAvailable_ = true" means RT know that RS have had available buffer
|
||||
@ -247,7 +252,6 @@ void RSSurfaceRenderNode::NotifyBufferAvailable()
|
||||
if (isBufferAvailable_) {
|
||||
return;
|
||||
}
|
||||
|
||||
isBufferAvailable_ = true;
|
||||
|
||||
if (callbackForRenderThreadRefresh_) {
|
||||
@ -256,8 +260,11 @@ void RSSurfaceRenderNode::NotifyBufferAvailable()
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (callback_) {
|
||||
callback_->OnBufferAvailable();
|
||||
if (callbackFromRT_) {
|
||||
callbackFromRT_->OnBufferAvailable();
|
||||
}
|
||||
if (callbackFromUI_) {
|
||||
callbackFromUI_->OnBufferAvailable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,33 +322,50 @@ private:
|
||||
BufferAvailableCallback cb_;
|
||||
};
|
||||
|
||||
bool RSRenderServiceClient::RegisterBufferAvailableListener(NodeId id, const BufferAvailableCallback &callback)
|
||||
bool RSRenderServiceClient::RegisterBufferAvailableListener(
|
||||
NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread)
|
||||
{
|
||||
auto renderService = RSRenderServiceConnectHub::GetRenderService();
|
||||
if (renderService == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto iter = bufferAvailableCbMap_.find(id);
|
||||
if (iter != bufferAvailableCbMap_.end()) {
|
||||
|
||||
auto iter = isFromRenderThread ? bufferAvailableCbRTMap_.find(id) : bufferAvailableCbUIMap_.find(id);
|
||||
if (isFromRenderThread && iter != bufferAvailableCbRTMap_.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isFromRenderThread && iter != bufferAvailableCbUIMap_.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<RSIBufferAvailableCallback> bufferAvailableCb = new CustomBufferAvailableCallback(callback);
|
||||
renderService->RegisterBufferAvailableListener(id, bufferAvailableCb);
|
||||
bufferAvailableCbMap_.emplace(id, bufferAvailableCb);
|
||||
renderService->RegisterBufferAvailableListener(id, bufferAvailableCb, isFromRenderThread);
|
||||
if (isFromRenderThread) {
|
||||
bufferAvailableCbRTMap_.emplace(id, bufferAvailableCb);
|
||||
} else {
|
||||
bufferAvailableCbUIMap_.emplace(id, bufferAvailableCb);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RSRenderServiceClient::UnregisterBufferAvailableListener(NodeId id)
|
||||
{
|
||||
auto iter = bufferAvailableCbMap_.find(id);
|
||||
if (iter != bufferAvailableCbMap_.end()) {
|
||||
bufferAvailableCbMap_.erase(iter);
|
||||
return true;
|
||||
auto iter = bufferAvailableCbRTMap_.find(id);
|
||||
if (iter != bufferAvailableCbRTMap_.end()) {
|
||||
bufferAvailableCbRTMap_.erase(iter);
|
||||
} else {
|
||||
ROSEN_LOGI("RSRenderServiceClient::UnregisterBufferAvailableListener "\
|
||||
"Node %llu has not regiatered callback", id);
|
||||
return false;
|
||||
"Node %llu has not regiatered RT callback", id);
|
||||
}
|
||||
iter = bufferAvailableCbUIMap_.find(id);
|
||||
if (iter != bufferAvailableCbUIMap_.end()) {
|
||||
bufferAvailableCbUIMap_.erase(iter);
|
||||
} else {
|
||||
ROSEN_LOGI("RSRenderServiceClient::UnregisterBufferAvailableListener "\
|
||||
"Node %llu has not regiatered UI callback", id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t RSRenderServiceClient::GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode)
|
||||
|
@ -478,7 +478,8 @@ void RSRenderServiceConnectionProxy::SetScreenBacklight(ScreenId id, uint32_t le
|
||||
}
|
||||
}
|
||||
|
||||
void RSRenderServiceConnectionProxy::RegisterBufferAvailableListener(NodeId id, sptr<RSIBufferAvailableCallback> callback)
|
||||
void RSRenderServiceConnectionProxy::RegisterBufferAvailableListener(
|
||||
NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: callback is nullptr.");
|
||||
@ -496,6 +497,7 @@ void RSRenderServiceConnectionProxy::RegisterBufferAvailableListener(NodeId id,
|
||||
option.SetFlags(MessageOption::TF_ASYNC);
|
||||
data.WriteUint64(id);
|
||||
data.WriteRemoteObject(callback->AsObject());
|
||||
data.WriteBool(isFromRenderThread);
|
||||
int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_BUFFER_AVAILABLE_LISTENER, data, reply, option);
|
||||
if (err != NO_ERROR) {
|
||||
ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: Send Request err.");
|
||||
|
@ -73,7 +73,8 @@ public:
|
||||
|
||||
void SetScreenBacklight(ScreenId id, uint32_t level) override;
|
||||
|
||||
void RegisterBufferAvailableListener(NodeId id, sptr<RSIBufferAvailableCallback> callback) override;
|
||||
void RegisterBufferAvailableListener(
|
||||
NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override;
|
||||
|
||||
int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override;
|
||||
|
||||
|
@ -84,10 +84,15 @@ protected:
|
||||
return isRenderServiceNode_;
|
||||
}
|
||||
|
||||
void SetRenderServiceNodeType(bool isRenderServiceNode)
|
||||
{
|
||||
isRenderServiceNode_ = isRenderServiceNode;
|
||||
}
|
||||
|
||||
private:
|
||||
static NodeId GenerateId();
|
||||
NodeId id_;
|
||||
const bool isRenderServiceNode_;
|
||||
bool isRenderServiceNode_;
|
||||
|
||||
NodeId parent_ = 0;
|
||||
std::vector<NodeId> children_;
|
||||
|
@ -60,6 +60,24 @@ RSSurfaceNode::SharedPtr RSSurfaceNode::Create(const RSSurfaceNodeConfig& surfac
|
||||
return node;
|
||||
}
|
||||
|
||||
void RSSurfaceNode::CreateNodeInRenderThread()
|
||||
{
|
||||
if (!IsRenderServiceNode()) {
|
||||
ROSEN_LOGI("RsDebug RSSurfaceNode::CreateNodeInRenderThread id:%llu already has RT Node", GetId());
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeCreate>(GetId());
|
||||
auto transactionProxy = RSTransactionProxy::GetInstance();
|
||||
if (transactionProxy != nullptr) {
|
||||
transactionProxy->AddCommand(command, false);
|
||||
}
|
||||
command = std::make_unique<RSSurfaceNodeConnectToNodeInRenderService>(GetId());
|
||||
if (transactionProxy != nullptr) {
|
||||
transactionProxy->AddCommand(command, false);
|
||||
}
|
||||
SetRenderServiceNodeType(false);
|
||||
}
|
||||
|
||||
void RSSurfaceNode::SetBounds(const Vector4f& bounds)
|
||||
{
|
||||
RSNode::SetBounds(bounds);
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
virtual ~RSSurfaceNode();
|
||||
|
||||
static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true);
|
||||
// This API is only for abilityView create RSRenderSurfaceNode in RenderThread.
|
||||
// Do not call this API unless you are sure what you do.
|
||||
void CreateNodeInRenderThread();
|
||||
|
||||
void SetBounds(const Vector4f& bounds) override;
|
||||
void SetBounds(float positionX, float positionY, float width, float height) override;
|
||||
|
@ -152,7 +152,7 @@ ohos_executable("render_service_client_surface_node_demo") {
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"multimedia_media_standard:media_client",
|
||||
#"multimedia_media_standard:media_client",
|
||||
]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include "media_data_source.h"
|
||||
|
||||
const char* SURFACE_STRIDE_ALIGNMENT = "8";
|
||||
constexpr int32_t SURFACE_QUEUE_SIZE = 5;
|
||||
constexpr int32_t SURFACE_QUEUE_SIZE = 3;
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Rosen;
|
||||
@ -113,10 +113,20 @@ void Init(std::shared_ptr<RSUIDirector> rsUiDirector, int width, int height)
|
||||
rootNode->AddChild(canvasNode, -1);
|
||||
|
||||
struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
|
||||
|
||||
// Create surfaceView node
|
||||
auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, false);
|
||||
|
||||
// Create abilityView node
|
||||
// "auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);"
|
||||
// "surfaceNode->CreateNodeInRenderThread();"
|
||||
|
||||
cout << "surfaceNode id = " << surfaceNode->GetId() << endl;
|
||||
// SetBounds also can be (300, 300, 960, 540);
|
||||
surfaceNode->SetBounds(30, 30, 320, 160);
|
||||
surfaceNode->SetBounds(30, 30, 512, 256);
|
||||
surfaceNode->SetFirstTimeOnScreenCallback([]() {
|
||||
cout << "SetFirstTimeOnScreenCallback" << endl;
|
||||
});
|
||||
|
||||
canvasNode->AddChild(surfaceNode, -1);
|
||||
rsUiDirector->SendMessages();
|
||||
@ -167,7 +177,7 @@ int main()
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
// SetWindowRect also can be {200, 200, 1501, 1200}
|
||||
option->SetWindowRect({120, 120, 500, 500});
|
||||
option->SetWindowRect({120, 120, 512, 512});
|
||||
|
||||
auto scene = new WindowScene();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user