Do the drawing_context init in render_service's main thread for gpu composition later.

Signed-off-by: xxfeng_hw <yuxiaofeng8@huawei.com>
Change-Id: I7ecc0c0692f4c157774759f78f796dde33c9effe
This commit is contained in:
xxfeng_hw 2022-04-12 11:20:33 +08:00
parent baa0632bc4
commit 28344fb99c
25 changed files with 128 additions and 26 deletions

View File

@ -32,10 +32,13 @@ RSSurfaceOhosGl::~RSSurfaceOhosGl()
std::unique_ptr<RSSurfaceFrame> RSSurfaceOhosGl::RequestFrame(int32_t width, int32_t height)
{
struct NativeWindow* nativeWindow = CreateNativeWindowFromSurface(&producer_);
if (nativeWindow == nullptr) {
return nullptr;
}
frame_ = std::make_unique<RSSurfaceFrameOhosGl>(width, height);
frame_->SetColorSpace(ColorGamut::COLOR_GAMUT_SRGB);
struct NativeWindow* nativeWindow = CreateNativeWindowFromSurface(&producer_);
frame_->SetSurface(static_cast<EGLSurface>(drawingProxy_->CreateSurface((EGLNativeWindowType)nativeWindow)));
NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, frame_->GetWidth(), frame_->GetHeight());
NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, frame_->GetColorSpace());

View File

@ -57,10 +57,17 @@ ohos_shared_library("libcomposer") {
"vsync/src/vsync_sampler.cpp",
]
include_dirs = [ "//foundation/graphic/standard/utils/log" ]
include_dirs = [
"//foundation/graphic/standard/rosen/modules/2d_graphics/src",
"//foundation/graphic/standard/rosen/modules/2d_graphics/src/drawing_engine",
"//foundation/graphic/standard/utils/log",
]
configs = [ ":composer_config" ]
defines = []
defines += gpu_defines
public_configs = [
":composer_public_config",
"//utils/native/base:utils_config",
@ -69,8 +76,10 @@ ohos_shared_library("libcomposer") {
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//drivers/peripheral/display/hal:hdi_display_device",
"//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos",
"//foundation/graphic/standard:libsurface",
"//foundation/graphic/standard/frameworks/vsync:libvsync_module",
"//foundation/graphic/standard/rosen/modules/2d_graphics:2d_graphics",
"//foundation/graphic/standard/utils:libgraphic_utils",
]

View File

@ -38,7 +38,7 @@ struct PrepareCompleteParam {
};
using OnScreenHotplugFunc = std::function<void(OutputPtr &output, bool connected, void* data)>;
using OnPrepareCompleteFunc = std::function<void(sptr<Surface> &surface,
using OnPrepareCompleteFunc = std::function<void(std::shared_ptr<RSSurface> &surface,
const struct PrepareCompleteParam &param, void* data)>;
class HdiBackend {

View File

@ -23,11 +23,12 @@
namespace OHOS {
namespace Rosen {
class RSSurface;
class HdiFramebufferSurface : public IBufferConsumerListener {
public:
static sptr<HdiFramebufferSurface> CreateFramebufferSurface();
sptr<OHOS::Surface> GetProducerSurface();
std::shared_ptr<RSSurface> GetSurface();
sptr<OHOS::SurfaceBuffer> GetFramebuffer();
sptr<SyncFence> GetFramebufferFence();
int32_t ReleaseFramebuffer(const sptr<SyncFence> &releaseFence);
@ -46,6 +47,8 @@ private:
void OnBufferAvailable() override;
OHOS::SurfaceError SetBufferQueueSize(uint32_t bufferSize);
OHOS::SurfaceError CreateSurface(sptr<HdiFramebufferSurface> &fbSurface);
std::shared_ptr<RSSurface> rsSurface_;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -52,7 +52,7 @@ public:
const std::unordered_map<uint32_t, LayerPtr>& GetLayers();
IRect& GetOutputDamage();
uint32_t GetOutputDamageNum() const;
sptr<Surface> GetProducerSurface();
std::shared_ptr<RSSurface> GetFrameBufferSurface();
sptr<SurfaceBuffer> GetFramebuffer();
sptr<SyncFence> GetFramebufferFence();
int32_t ReleaseFramebuffer(const sptr<SyncFence> &releaseFence);

View File

@ -181,10 +181,9 @@ void HdiBackend::OnPrepareComplete(bool needFlush, OutputPtr &output, std::vecto
.layers = newLayerInfos,
};
sptr<Surface> producerSurface = output->GetProducerSurface();
auto fbSurface = output->GetFrameBufferSurface();
if (onPrepareCompleteCb_ != nullptr) {
onPrepareCompleteCb_(producerSurface, param, onPrepareCompleteCbData_);
onPrepareCompleteCb_(fbSurface, param, onPrepareCompleteCbData_);
}
}

View File

@ -17,6 +17,8 @@
#include "hdi_log.h"
#include <drawing_surface/rs_surface_ohos.h>
using namespace OHOS;
namespace OHOS {
@ -56,6 +58,8 @@ SurfaceError HdiFramebufferSurface::CreateSurface(sptr<HdiFramebufferSurface> &f
sptr<IBufferProducer> producer = consumerSurface_->GetProducer();
producerSurface_ = Surface::CreateSurfaceAsProducer(producer);
rsSurface_ = RSSurfaceOhos::CreateSurface(producerSurface_);
sptr<IBufferConsumerListener> listener = fbSurface;
SurfaceError ret = consumerSurface_->RegisterConsumerListener(listener);
if (ret != SURFACE_ERROR_OK) {
@ -93,9 +97,9 @@ void HdiFramebufferSurface::OnBufferAvailable()
fbAcquireFence_ = new SyncFence(fbAcquireFence);
}
sptr<Surface> HdiFramebufferSurface::GetProducerSurface()
std::shared_ptr<RSSurface> HdiFramebufferSurface::GetSurface()
{
return producerSurface_;
return rsSurface_;
}
sptr<SurfaceBuffer> HdiFramebufferSurface::GetFramebuffer()

View File

@ -144,13 +144,13 @@ uint32_t HdiOutput::GetScreenId() const
return screenId_;
}
sptr<Surface> HdiOutput::GetProducerSurface()
std::shared_ptr<RSSurface> HdiOutput::GetFrameBufferSurface()
{
if (!CheckFbSurface()) {
return nullptr;
}
return fbSurface_->GetProducerSurface();
return fbSurface_->GetSurface();
}
sptr<SurfaceBuffer> HdiOutput::GetFramebuffer()

View File

@ -49,7 +49,7 @@ HWTEST_F(HdiBackendSysTest, TestHdiBeckend001, Function | MediumTest| Level3)
{
ASSERT_EQ(HdiBackendSysTest::hdiBackend_->RegScreenHotplug(nullptr, nullptr), ROSEN_ERROR_INVALID_ARGUMENTS);
auto func = [](sptr<Surface> &surface, const struct PrepareCompleteParam &param, void* data) -> void {};
auto func = [](std::shared_ptr<RSSurface> &surface, const struct PrepareCompleteParam &param, void* data) -> void {};
ASSERT_EQ(HdiBackendSysTest::hdiBackend_->RegPrepareComplete(func, nullptr), ROSEN_ERROR_OK);
}
} // namespace

View File

@ -81,7 +81,7 @@ HWTEST_F(HdiOutputSysTest, TestHdiOutput001, Function | MediumTest| Level3)
HdiOutputSysTest::hdiOutput_->SetOutputDamage(num, iRect2);
ASSERT_EQ(HdiOutputSysTest::hdiOutput_->GetOutputDamageNum(), 1u);
ASSERT_NE(HdiOutputSysTest::hdiOutput_->GetProducerSurface(), nullptr);
ASSERT_NE(HdiOutputSysTest::hdiOutput_->GetFrameBufferSurface(), nullptr);
ASSERT_EQ(HdiOutputSysTest::hdiOutput_->GetFramebuffer(), nullptr);
ASSERT_NE(HdiOutputSysTest::hdiOutput_->GetFramebufferFence(), nullptr);
}

View File

@ -60,7 +60,7 @@ HWTEST_F(HdiBackendTest, RegScreenHotplug001, Function | MediumTest| Level3)
HWTEST_F(HdiBackendTest, RegPrepareComplete001, Function | MediumTest| Level3)
{
auto func = [](sptr<Surface> &surface, const struct PrepareCompleteParam &param, void* data) -> void {};
auto func = [](std::shared_ptr<RSSurface> &surface, const struct PrepareCompleteParam &param, void* data) -> void {};
ASSERT_EQ(HdiBackendTest::hdiBackend_->RegPrepareComplete(func, nullptr), ROSEN_ERROR_OK);
}

View File

@ -115,7 +115,7 @@ HWTEST_F(HdiOutputTest, GetOutputDamageNum001, Function | MediumTest| Level3)
*/
HWTEST_F(HdiOutputTest, GetProducerSurface001, Function | MediumTest| Level3)
{
ASSERT_NE(HdiOutputTest::hdiOutput_->GetProducerSurface(), nullptr);
ASSERT_NE(HdiOutputTest::hdiOutput_->GetFrameBufferSurface(), nullptr);
}
/**

View File

@ -12,6 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/graphic/standard/graphic_config.gni")
## Build librender_service.so
ohos_shared_library("librender_service") {
@ -24,6 +25,7 @@ ohos_shared_library("librender_service") {
} else {
defines += [ "PADDING_HEIGHT_32" ]
}
defines += gpu_defines
sources = [
"core/pipeline/rs_compatible_processor.cpp",

View File

@ -22,6 +22,7 @@
#include "common/rs_vector3.h"
#include "common/rs_vector4.h"
#include "display_type.h"
#include <drawing_engine/drawing_surface/rs_surface_ohos.h>
#include "rs_trace.h"
#include "common/rs_vector4.h"
#include "pipeline/rs_main_thread.h"
@ -60,6 +61,11 @@ void RSHardwareProcessor::Init(ScreenId id, int32_t offsetX, int32_t offsetY)
damageRect.w = static_cast<int32_t>(currScreenInfo_.width);
damageRect.h = static_cast<int32_t>(currScreenInfo_.height);
output_->SetOutputDamage(1, damageRect);
auto mainThread = RSMainThread::Instance();
if (mainThread != nullptr) {
drawingProxy_ = mainThread->GetDrawingProxy();
}
}
void RSHardwareProcessor::PostProcess()
@ -277,13 +283,15 @@ void RSHardwareProcessor::CalculateInfoWithAnimation(
};
}
void RSHardwareProcessor::Redraw(sptr<Surface>& surface, const struct PrepareCompleteParam& param, void* data)
void RSHardwareProcessor::Redraw(
std::shared_ptr<RSSurface>& rsSurface, const struct PrepareCompleteParam& param, void* data)
{
if (!param.needFlushFramebuffer) {
RS_LOGI("RsDebug RSHardwareProcessor::Redraw no need to flush frame buffer");
return;
}
sptr<Surface> surface = std::static_pointer_cast<RSSurfaceOhos>(rsSurface)->GetSurface();
if (surface == nullptr) {
RS_LOGE("RSHardwareProcessor::Redraw: surface is null.");
return;

View File

@ -21,7 +21,6 @@
#include "display_type.h"
#include "hdi_backend.h"
#include "hdi_layer_info.h"
#include "hdi_output.h"
#include "hdi_screen.h"
#include <surface.h>
@ -44,7 +43,7 @@ public:
void CropLayers();
private:
void Redraw(sptr<Surface>& surface, const struct PrepareCompleteParam& param, void* data);
void Redraw(std::shared_ptr<RSSurface>& surface, const struct PrepareCompleteParam& param, void* data);
void OnRotate();
void CalculateInfoWithAnimation(const std::unique_ptr<RSTransitionProperties>& transitionProperties,
ComposeInfo& info, RSSurfaceRenderNode& node);

View File

@ -61,6 +61,9 @@ void RSMainThread::Init()
receiver_ = std::make_shared<VSyncReceiver>(conn);
receiver_->Init();
RsRenderServiceUtil::InitEnableClient();
drawingProxy_ = std::make_shared<DrawingProxy>();
drawingProxy_->InitDrawContext();
}
void RSMainThread::Start()

View File

@ -24,6 +24,7 @@
#include "common/rs_thread_handler.h"
#include "common/rs_thread_looper.h"
#include "drawing_engine/drawing_proxy.h"
#include "ipc_callbacks/iapplication_render_thread.h"
#include "pipeline/rs_context.h"
#include "platform/drawing/rs_vsync_client.h"
@ -85,6 +86,10 @@ public:
{
return mainThreadId_;
}
std::shared_ptr<DrawingProxy> GetDrawingProxy() const
{
return drawingProxy_;
}
void RegisterApplicationRenderThread(uint32_t pid, sptr<IApplicationRenderThread> app);
void UnregisterApplicationRenderThread(sptr<IApplicationRenderThread> app);
@ -118,6 +123,8 @@ private:
RSContext context_;
std::thread::id mainThreadId_;
std::shared_ptr<VSyncReceiver> receiver_ = nullptr;
std::shared_ptr<DrawingProxy> drawingProxy_;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -24,6 +24,43 @@
namespace OHOS {
namespace Rosen {
SkCanvas* RSProcessor::CreateCanvas(
const std::shared_ptr<RSSurface>& surface, BufferRequestConfig requestConfig)
{
RS_TRACE_NAME("CreateCanvas");
if (surface == nullptr) {
RS_LOGE("RSProcessor::CreateCanvas: surface is null!");
return nullptr;
}
if (drawingProxy_ == nullptr) {
RS_LOGE("RSProcessor::CreateCanvas: drawingProxy_ is null!");
return nullptr;
}
RS_TRACE_NAME("CreateCanvas");
surface->SetDrawingProxy(drawingProxy_.get());
currFrame_ = surface->RequestFrame(requestConfig.width, requestConfig.height);
if (currFrame_ == nullptr) {
RS_LOGE("RSProcessor::CreateCanvas: requestFrame failed!");
return nullptr;
}
return surface->GetCanvas(currFrame_);
}
void RSProcessor::FlushFrame(const std::shared_ptr<RSSurface>& surface, BufferFlushConfig flushConfig)
{
if (surface == nullptr) {
RS_LOGE("RSProcessor::FlushBuffer surface is null!");
return;
}
RS_TRACE_NAME("FlushBuffer");
surface->FlushFrame(currFrame_);
}
std::unique_ptr<SkCanvas> RSProcessor::CreateCanvas(sptr<Surface> producerSurface, BufferRequestConfig requestConfig)
{
RS_TRACE_NAME("CreateCanvas");

View File

@ -20,6 +20,8 @@
#include "include/core/SkMatrix.h"
#include <surface.h>
#include "drawing_engine/drawing_proxy.h"
#include "hdi_output.h"
#include "pipeline/rs_base_render_node.h"
#include "pipeline/rs_display_render_node.h"
#include "pipeline/rs_surface_render_node.h"
@ -40,12 +42,18 @@ public:
protected:
std::unique_ptr<SkCanvas> CreateCanvas(sptr<Surface> producerSurface, BufferRequestConfig requestConfig);
void FlushBuffer(sptr<Surface> surface, BufferFlushConfig flushConfig);
SkCanvas* CreateCanvas(
const std::shared_ptr<RSSurface>& surface, BufferRequestConfig requestConfig);
void FlushFrame(const std::shared_ptr<RSSurface>& surface, BufferFlushConfig flushConfig);
bool ConsumeAndUpdateBuffer(RSSurfaceRenderNode& node, SpecialTask& task, sptr<SurfaceBuffer>& buffer);
void SetBufferTimeStamp();
int32_t GetOffsetX();
int32_t GetOffsetY();
std::shared_ptr<DrawingProxy> drawingProxy_;
private:
std::unique_ptr<RSSurfaceFrame> currFrame_;
sptr<SurfaceBuffer> buffer_;
int32_t releaseFence_ = -1;
};

View File

@ -57,6 +57,7 @@ ohos_executable("drawing_sample") {
]
deps = [
"//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos",
"//foundation/graphic/standard:libsurface",
"//foundation/graphic/standard/rosen/modules/2d_graphics:2d_graphics",
"//foundation/graphic/standard/rosen/modules/composer:libcomposer",

View File

@ -15,6 +15,7 @@
#include "drawing_sample.h"
#include <drawing_engine/drawing_surface/rs_surface_ohos.h>
#include <securec.h>
#include <sync_fence.h>
#include <vsync_controller.h>
@ -78,13 +79,14 @@ void DrawingSample::OnScreenPlug(std::shared_ptr<HdiOutput>& output, bool connec
thisPtr->OnHotPlugEvent(output, connected);
}
void DrawingSample::OnPrepareCompleted(sptr<Surface>& surface, const struct PrepareCompleteParam& param, void* data)
void DrawingSample::OnPrepareCompleted(
std::shared_ptr<RSSurface>& rsSurface, const struct PrepareCompleteParam& param, void* data)
{
if (!param.needFlushFramebuffer) {
return;
}
if (surface == nullptr) {
if (rsSurface == nullptr) {
LOGE("surface is null");
return;
}
@ -95,6 +97,7 @@ void DrawingSample::OnPrepareCompleted(sptr<Surface>& surface, const struct Prep
}
auto* thisPtr = static_cast<DrawingSample*>(data);
sptr<Surface> surface = std::static_pointer_cast<RSSurfaceOhos>(rsSurface)->GetSurface();
thisPtr->DoPrepareCompleted(surface, param);
}

View File

@ -79,7 +79,7 @@ private:
uint32_t CreatePhysicalScreen();
static void OnScreenPlug(std::shared_ptr<HdiOutput>& output, bool connected, void* data);
static void OnPrepareCompleted(OHOS::sptr<Surface>& surface, const struct PrepareCompleteParam& param, void* data);
static void OnPrepareCompleted(std::shared_ptr<RSSurface>& rsSurface, const struct PrepareCompleteParam& param, void* data);
};
} // namespace Drawing
} // namespace Rosen

View File

@ -26,6 +26,9 @@ config("hello_composer_config") {
config("hello_composer_public_config") {
include_dirs = [
"//foundation/graphic/standard/rosen/modules/2d_graphics/include",
"//foundation/graphic/standard/rosen/modules/2d_graphics/src",
"//foundation/graphic/standard/rosen/modules/2d_graphics/src/drawing_engine",
"//foundation/graphic/standard/rosen/modules/composer/hdi_backend/include",
"//drivers/peripheral/display/interfaces/include",
"//foundation/graphic/standard/rosen/include/common",
@ -49,6 +52,7 @@ ohos_executable("hello_composer") {
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos",
"//foundation/graphic/standard:libsurface",
"//foundation/graphic/standard/rosen/modules/composer:libcomposer",
"//foundation/graphic/standard/utils:libgraphic_utils",

View File

@ -14,6 +14,8 @@
*/
#include "hello_composer.h"
#include <drawing_surface/rs_surface_ohos.h>
#include <vsync_generator.h>
#include <vsync_controller.h>
#include <vsync_distributor.h>
@ -25,12 +27,19 @@ using namespace OHOS;
using namespace OHOS::Rosen;
namespace {
#ifdef LOGI
#undef LOGI
#define LOGI(fmt, ...) ::OHOS::HiviewDFX::HiLog::Info( \
::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "HelloComposer"}, \
"%{public}s: " fmt, __func__, ##__VA_ARGS__)
#endif
#ifdef LOGE
#undef LOGE
#define LOGE(fmt, ...) ::OHOS::HiviewDFX::HiLog::Error( \
::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "HelloComposer"}, \
"%{public}s: " fmt, __func__, ##__VA_ARGS__)
#endif
sptr<VSyncReceiver> g_receiver = nullptr;
}
@ -98,13 +107,14 @@ void HelloComposer::OnScreenPlug(std::shared_ptr<HdiOutput> &output, bool connec
thisPtr->OnHotPlugEvent(output, connected);
}
void HelloComposer::OnPrepareCompleted(sptr<Surface> &surface, const struct PrepareCompleteParam &param, void* data)
void HelloComposer::OnPrepareCompleted(
std::shared_ptr<RSSurface> &rsSurface, const struct PrepareCompleteParam &param, void* data)
{
if (!param.needFlushFramebuffer) {
return;
}
if (surface == nullptr) {
if (rsSurface == nullptr) {
LOGE("surface is null");
return;
}
@ -115,6 +125,7 @@ void HelloComposer::OnPrepareCompleted(sptr<Surface> &surface, const struct Prep
}
auto* thisPtr = static_cast<HelloComposer *>(data);
sptr<Surface> surface = std::static_pointer_cast<RSSurfaceOhos>(rsSurface)->GetSurface();
thisPtr->DoPrepareCompleted(surface, param);
}

View File

@ -73,7 +73,8 @@ private:
uint32_t CreatePhysicalScreen();
static void OnScreenPlug(std::shared_ptr<HdiOutput> &output, bool connected, void* data);
static void OnPrepareCompleted(OHOS::sptr<Surface> &surface, const struct PrepareCompleteParam &param, void* data);
static void OnPrepareCompleted(
std::shared_ptr<RSSurface> &rsSurface, const struct PrepareCompleteParam &param, void* data);
};
} // namespace Rosen
} // namespace OHOS