解决在redraw的场景下rs crash的问题

Merge pull request  from BruceXuXu/bugfix_rs_crash
This commit is contained in:
openharmony_ci 2022-02-08 01:23:28 +00:00 committed by Gitee
commit 1485eca4cb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 73 additions and 40 deletions

View File

@ -52,6 +52,11 @@ public:
BufferHandle *GetBufferHandle() const override;
int32_t GetWidth() const override;
int32_t GetHeight() const override;
int32_t GetStride() const override;
int32_t GetSurfaceBufferWidth() const override;
int32_t GetSurfaceBufferHeight() const override;
GSError SetSurfaceBufferWidth(int32_t width) override;
GSError SetSurfaceBufferHeight(int32_t height) override;
int32_t GetFormat() const override;
int64_t GetUsage() const override;
uint64_t GetPhyAddr() const override;
@ -92,6 +97,8 @@ private:
int32_t sequenceNumber = -1;
BufferExtraDataImpl bedataimpl;
sptr<EglData> eglData_ = nullptr;
int32_t surfaceBufferWidth_ = 0;
int32_t surfaceBufferHeight_ = 0;
};
} // namespace OHOS

View File

@ -103,6 +103,9 @@ GSError BufferManager::Alloc(const BufferRequestConfig &config, sptr<SurfaceBuff
auto dret = displayGralloc_->AllocMem(info, handle);
if (dret == DISPLAY_SUCCESS) {
buffer->SetBufferHandle(handle);
buffer->SetSurfaceBufferWidth(config.width);
buffer->SetSurfaceBufferHeight(config.height);
BLOGI("buffer handle %{public}p w: %{public}d h: %{public}d", handle, config.width, config.height);
return GSERROR_OK;
}
BLOGW("Failed with %{public}d", dret);
@ -176,12 +179,12 @@ GSError BufferManager::Free(sptr<SurfaceBufferImpl> &buffer)
CHECK_BUFFER(buffer);
BufferHandle *handle = buffer->GetBufferHandle();
buffer->SetBufferHandle(nullptr);
if (handle == nullptr) {
return GSERROR_INVALID_ARGUMENTS;
}
displayGralloc_->FreeMem(*handle);
buffer->SetBufferHandle(nullptr);
return GSERROR_OK;
}
} // namespace OHOS

View File

@ -505,11 +505,10 @@ GSError BufferQueue::AllocBuffer(sptr<SurfaceBufferImpl> &buffer,
.fence = -1
};
bufferQueueCache_[sequence] = ele;
ret = bufferManager_->Map(buffer);
if (ret == GSERROR_OK) {
BLOGN_SUCCESS_ID(sequence, "Map");
bufferQueueCache_[sequence] = ele;
return GSERROR_OK;
}

View File

@ -131,8 +131,8 @@ int32_t NativeWindowFlushBuffer(struct NativeWindow *window, struct NativeWindow
} else {
config.damage.x = 0;
config.damage.y = 0;
config.damage.w = 0;
config.damage.h = 0;
config.damage.w = window->config.width;
config.damage.h = window->config.height;
config.timestamp = 0;
}

View File

@ -52,7 +52,7 @@ SurfaceBufferImpl::SurfaceBufferImpl(int seqNum)
SurfaceBufferImpl::~SurfaceBufferImpl()
{
BLOGD("dtor ~[%{public}d]", sequenceNumber);
BLOGD("dtor ~[%{public}d] handle_ %{public}p", sequenceNumber, handle_);
if (handle_) {
FreeBufferHandle(handle_);
}
@ -69,6 +69,28 @@ BufferHandle *SurfaceBufferImpl::GetBufferHandle() const
return handle_;
}
GSError SurfaceBufferImpl::SetSurfaceBufferWidth(int32_t width)
{
surfaceBufferWidth_ = width;
return GSERROR_OK;
}
GSError SurfaceBufferImpl::SetSurfaceBufferHeight(int32_t height)
{
surfaceBufferHeight_ = height;
return GSERROR_OK;
}
int32_t SurfaceBufferImpl::GetSurfaceBufferHeight() const
{
return surfaceBufferHeight_;
}
int32_t SurfaceBufferImpl::GetSurfaceBufferWidth() const
{
return surfaceBufferWidth_;
}
int32_t SurfaceBufferImpl::GetWidth() const
{
if (handle_ == nullptr) {
@ -87,6 +109,15 @@ int32_t SurfaceBufferImpl::GetHeight() const
return handle_->height;
}
int32_t SurfaceBufferImpl::GetStride() const
{
if (handle_ == nullptr) {
BLOGW("handle is nullptr");
return -1;
}
return handle_->stride;
}
int32_t SurfaceBufferImpl::GetFormat() const
{
if (handle_ == nullptr) {

View File

@ -30,6 +30,11 @@ public:
virtual BufferHandle *GetBufferHandle() const = 0;
virtual int32_t GetWidth() const = 0;
virtual int32_t GetHeight() const = 0;
virtual int32_t GetStride() const = 0;
virtual int32_t GetSurfaceBufferWidth() const = 0;
virtual int32_t GetSurfaceBufferHeight() const = 0;
virtual GSError SetSurfaceBufferWidth(int32_t width) = 0;
virtual GSError SetSurfaceBufferHeight(int32_t height) = 0;
virtual int32_t GetFormat() const = 0;
virtual int64_t GetUsage() const = 0;
virtual uint64_t GetPhyAddr() const = 0;

View File

@ -102,8 +102,7 @@ void RSCompatibleProcessor::ProcessSurface(RSSurfaceRenderNode& node)
matrix.reset();
RsRenderServiceUtil::DrawBuffer(canvas_.get(), matrix, node.GetBuffer(),
static_cast<float>(geoPtr->GetAbsRect().left_), static_cast<float>(geoPtr->GetAbsRect().top_),
static_cast<float>(geoPtr->GetAbsRect().width_), static_cast<float>(geoPtr->GetAbsRect().height_),
node.GetDamageRegion().w, node.GetDamageRegion().h);
static_cast<float>(geoPtr->GetAbsRect().width_), static_cast<float>(geoPtr->GetAbsRect().height_));
}
void RSCompatibleProcessor::PostProcess()

View File

@ -99,13 +99,12 @@ void RSHardwareProcessor::ProcessSurface(RSSurfaceRenderNode &node)
ROSEN_LOGE("RsDebug RSHardwareProcessor::ProcessSurface geoPtr == nullptr");
return;
}
bool needUseBufferRegion = node.GetDamageRegion().w <= 0 || node.GetDamageRegion().h <= 0;
ComposeInfo info = {
.srcRect = {
.x = 0,
.y = 0,
.w = needUseBufferRegion ? node.GetBuffer()->GetWidth() : node.GetDamageRegion().w,
.h = needUseBufferRegion ? node.GetBuffer()->GetHeight() : node.GetDamageRegion().h,
.w = node.GetBuffer()->GetSurfaceBufferWidth(),
.h = node.GetBuffer()->GetSurfaceBufferHeight(),
},
.dstRect = {
.x = geoPtr->GetAbsRect().left_,
@ -122,12 +121,12 @@ void RSHardwareProcessor::ProcessSurface(RSSurfaceRenderNode &node)
.blendType = node.GetBlendType(),
};
std::shared_ptr<HdiLayerInfo> layer = HdiLayerInfo::CreateHdiLayerInfo();
ROSEN_LOGE("RsDebug RSHardwareProcessor::ProcessSurface surfaceNode id:%llu name:[%s] [%d %d %d %d]"\
"SrcRect [%d %d] bufferSize [%d %d] DamageSize [%d %d] buffaddr:%p, z:%f, globalZOrder:%d, blendType = %d",
ROSEN_LOGE("RsDebug RSHardwareProcessor::ProcessSurface surfaceNode id:%llu name:[%s] dst [%d %d %d %d]"\
"SrcRect [%d %d] rawbuffer [%d %d] surfaceBuffer [%d %d] buffaddr:%p, z:%f, globalZOrder:%d, blendType = %d",
node.GetId(), node.GetName().c_str(),
info.dstRect.x, info.dstRect.y, info.dstRect.w, info.dstRect.h,
info.srcRect.w, info.srcRect.h, node.GetBuffer()->GetWidth(), node.GetBuffer()->GetHeight(),
node.GetDamageRegion().w, node.GetDamageRegion().h, node.GetBuffer().GetRefPtr(),
info.dstRect.x, info.dstRect.y, info.dstRect.w, info.dstRect.h, info.srcRect.w, info.srcRect.h,
node.GetBuffer()->GetWidth(), node.GetBuffer()->GetHeight(), node.GetBuffer()->GetSurfaceBufferWidth(),
node.GetBuffer()->GetSurfaceBufferHeight(), node.GetBuffer().GetRefPtr(),
node.GetRenderProperties().GetPositionZ(), info.zOrder, info.blendType);
RsRenderServiceUtil::ComposeSurface(layer, node.GetConsumer(), layers_, info);
}
@ -168,8 +167,7 @@ void RSHardwareProcessor::Redraw(sptr<Surface>& surface, const struct PrepareCom
ROSEN_LOGE("RsDebug RSHardwareProcessor::Redraw layer [%d %d %d %d]", (*iter)->GetLayerSize().x,
(*iter)->GetLayerSize().y, (*iter)->GetLayerSize().w, (*iter)->GetLayerSize().h);
RsRenderServiceUtil::DrawBuffer(canvas.get(), matrix, (*iter)->GetBuffer(), (*iter)->GetLayerSize().x,
(*iter)->GetLayerSize().y, (*iter)->GetLayerSize().w, (*iter)->GetLayerSize().h,
(*iter)->GetDirtyRegion().w, (*iter)->GetDirtyRegion().h);
(*iter)->GetLayerSize().y, (*iter)->GetLayerSize().w, (*iter)->GetLayerSize().h);
}
BufferFlushConfig flushConfig = {
.damage = {

View File

@ -41,7 +41,7 @@ std::unique_ptr<SkCanvas> RSProcessor::CreateCanvas(sptr<Surface> producerSurfac
}
SkImageInfo info = SkImageInfo::Make(buffer_->GetWidth(), buffer_->GetHeight(),
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
return SkCanvas::MakeRasterDirect(info, addr, buffer_->GetSize() / buffer_->GetHeight());
return SkCanvas::MakeRasterDirect(info, addr, buffer_->GetStride());
}
void RSProcessor::FlushBuffer(sptr<Surface> surface, BufferFlushConfig flushConfig)

View File

@ -39,7 +39,7 @@ void RsRenderServiceUtil::ComposeSurface(std::shared_ptr<HdiLayerInfo> layer, sp
}
void RsRenderServiceUtil::DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, sptr<OHOS::SurfaceBuffer> buffer,
float tranX, float tranY, float width, float height, int32_t bufferWidth, int32_t bufferHeight)
float tranX, float tranY, float width, float height)
{
if (!canvas) {
ROSEN_LOGE("RsRenderServiceUtil::DrawBuffer canvas is nullptr");
@ -50,24 +50,24 @@ void RsRenderServiceUtil::DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, s
return;
}
auto addr = static_cast<uint32_t*>(buffer->GetVirAddr());
if (addr == nullptr || bufferWidth <= 0 || bufferHeight <= 0) {
if (addr == nullptr || buffer->GetWidth() <= 0 || buffer->GetHeight() <= 0) {
ROSEN_LOGE("RsRenderServiceUtil::DrawBuffer this buffer have no vir add or width or height is negative");
return;
}
SkColorType colorType;
colorType = buffer->GetFormat() == PIXEL_FMT_BGRA_8888 ? kBGRA_8888_SkColorType : kRGBA_8888_SkColorType;
SkImageInfo layerInfo = SkImageInfo::Make(bufferWidth, bufferHeight,
SkImageInfo layerInfo = SkImageInfo::Make(buffer->GetWidth(), buffer->GetHeight(),
colorType, kPremul_SkAlphaType);
SkPixmap pixmap(layerInfo, addr, layerInfo.bytesPerPixel() * bufferWidth);
SkPixmap pixmap(layerInfo, addr, buffer->GetStride());
SkBitmap bitmap;
float scaleX = width / static_cast<float>(bufferWidth);
float scaleY = height / static_cast<float>(bufferHeight);
float scaleX = width / static_cast<float>(buffer->GetWidth());
float scaleY = height / static_cast<float>(buffer->GetHeight());
if (bitmap.installPixels(pixmap)) {
canvas->save();
canvas->setMatrix(matrix);
canvas->translate(tranX, tranY);
canvas->scale(scaleX, scaleY);
canvas->drawBitmapRect(bitmap, SkRect::MakeXYWH(0, 0, bufferWidth, bufferHeight), nullptr);
canvas->drawBitmapRect(bitmap, SkRect::MakeXYWH(0, 0, buffer->GetWidth(), buffer->GetHeight()), nullptr);
canvas->restore();
}
}
@ -75,13 +75,9 @@ void RsRenderServiceUtil::DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, s
void RsRenderServiceUtil::DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, sptr<OHOS::SurfaceBuffer> buffer,
RSSurfaceRenderNode& node)
{
bool needUseBufferRegion = node.GetDamageRegion().w <= 0 || node.GetDamageRegion().h <= 0;
int32_t damageRegionWidth = needUseBufferRegion ? node.GetBuffer()->GetWidth() : node.GetDamageRegion().w;
int32_t damageRegionHeight = needUseBufferRegion ? node.GetBuffer()->GetHeight() : node.GetDamageRegion().h;
DrawBuffer(canvas, matrix, node.GetBuffer(),
node.GetRenderProperties().GetBoundsPositionX(), node.GetRenderProperties().GetBoundsPositionY(),
node.GetRenderProperties().GetBoundsWidth(), node.GetRenderProperties().GetBoundsHeight(),
damageRegionWidth, damageRegionHeight);
node.GetRenderProperties().GetBoundsWidth(), node.GetRenderProperties().GetBoundsHeight());
}
} // namespace Rosen

View File

@ -45,7 +45,7 @@ public:
static void ComposeSurface(std::shared_ptr<HdiLayerInfo> layer, sptr<Surface> consumerSurface,
std::vector<LayerInfoPtr>& layers, ComposeInfo info);
static void DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, sptr<OHOS::SurfaceBuffer> buffer,
float tranX, float tranY, float width, float height, int32_t bufferWidth, int32_t bufferHeight);
float tranX, float tranY, float width, float height);
static void DrawBuffer(SkCanvas* canvas, const SkMatrix& matrix, sptr<OHOS::SurfaceBuffer> buffer,
RSSurfaceRenderNode& node);
};

View File

@ -152,11 +152,7 @@ void RSSurfaceCaptureTask::RSSurfaceCaptureVisitor::ProcessSurfaceRenderNode(RSS
} else {
float scaleX = node.GetRenderProperties().GetBoundsWidth();
float scaleY = node.GetRenderProperties().GetBoundsHeight();
bool needUseBufferRegion = node.GetDamageRegion().w <= 0 || node.GetDamageRegion().h <= 0;
int32_t damageRegionWidth = needUseBufferRegion ? node.GetBuffer()->GetWidth() : node.GetDamageRegion().w;
int32_t damageRegionHeight = needUseBufferRegion ? node.GetBuffer()->GetHeight() : node.GetDamageRegion().h;
RsRenderServiceUtil::DrawBuffer(canvas_.get(), node.GetMatrix(), node.GetBuffer(), 0, 0, scaleX, scaleY,
damageRegionWidth, damageRegionHeight);
RsRenderServiceUtil::DrawBuffer(canvas_.get(), node.GetMatrix(), node.GetBuffer(), 0, 0, scaleX, scaleY);
}
for (auto child : node.GetChildren()) {
auto existingChild = child.lock();

View File

@ -23,9 +23,8 @@ namespace Rosen {
RSSurfaceFrameOhosRaster::RSSurfaceFrameOhosRaster(int32_t width, int32_t height)
{
constexpr int32_t pixelBase = 16;
requestConfig_.width = (width % pixelBase == 0) ? width : ((width / pixelBase + 1) * pixelBase);
requestConfig_.height = (height % pixelBase == 0) ? height : ((height / pixelBase + 1) * pixelBase);
requestConfig_.width = width;
requestConfig_.height = height;
flushConfig_.damage.w = width;
flushConfig_.damage.h = height;
}