fix: HDR video brightness bug

Signed-off-by: xuedong <xuedong@huawei.com>
This commit is contained in:
xuedong 2024-09-11 22:54:01 +08:00
parent efd6eb6faf
commit b8bd421d72
6 changed files with 33 additions and 10 deletions

View File

@ -394,6 +394,11 @@ public:
presentTimestamp_ = timestamp;
}
int32_t GetSdrNit() const
{
return sdrNit_;
}
int32_t GetDisplayNit() const
{
return displayNit_;
@ -404,6 +409,11 @@ public:
return brightnessRatio_;
}
int32_t SetSdrNit(int32_t sdrNit)
{
return sdrNit_ = sdrNit;
}
int32_t SetDisplayNit(int32_t displayNit)
{
return displayNit_ = displayNit;
@ -610,6 +620,7 @@ private:
bool preMulti_ = false;
LayerMask layerMask_ = LayerMask::LAYER_MASK_NORMAL;
mutable std::mutex mutex_;
int32_t sdrNit_ = 500; // default sdr nit
int32_t displayNit_ = 500; // default luminance for sdr
float brightnessRatio_ = 1.0f; // default ratio for sdr
uint64_t nodeId_ = 0;

View File

@ -48,6 +48,7 @@ struct ComposeInfo {
sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
GraphicBlendType blendType = GraphicBlendType::GRAPHIC_BLEND_NONE;
bool needClient = false;
int32_t sdrNit { 0 };
int32_t displayNit { 0 };
float brightnessRatio { 0.0 };
};
@ -129,7 +130,7 @@ public:
static Drawing::Matrix GetSurfaceTransformMatrix(GraphicTransformType rotationTransform, const RectF &bounds,
const RectF &bufferBounds = {0.0f, 0.0f, 0.0f, 0.0f}, Gravity gravity = Gravity::RESIZE);
static Drawing::Matrix GetGravityMatrix(Gravity gravity, const sptr<SurfaceBuffer>& buffer, const RectF& bounds);
static void SetPropertiesForCanvas(RSPaintFilterCanvas& canvas, const BufferDrawParam& params);
static Drawing::ColorType GetColorTypeFromBufferFormat(int32_t pixelFmt);
static Drawing::BitmapFormat GenerateDrawingBitmapFormat(const sptr<OHOS::SurfaceBuffer>& buffer);

View File

@ -165,13 +165,13 @@ constexpr int32_t SYSTEM_ANIMATED_SCENES_RATE = 2;
constexpr uint32_t WAIT_FOR_MEM_MGR_SERVICE = 100;
constexpr uint32_t CAL_NODE_PREFERRED_FPS_LIMIT = 50;
constexpr uint32_t EVENT_SET_HARDWARE_UTIL = 100004;
constexpr float DEFAULT_SCALER = 4.5f;
constexpr float DEFAULT_HDR_RATIO = 1.0f;
constexpr float REFERENCE_WHITE = 203.0f;
constexpr float CAMERA_WHITE_MIN = 500.0f;
constexpr float CAMERA_WHITE_MAX = 510.0f;
constexpr float CAMERA_HDR_RATIO = 2.5f;
constexpr float HDR_WHITE = 1000.0f;
constexpr float DEFAULT_SCALER = HDR_WHITE / REFERENCE_WHITE;
constexpr float GAMMA2_2 = 2.2f;
constexpr const char* WALLPAPER_VIEW = "WallpaperView";
constexpr const char* CLEAR_GPU_CACHE = "ClearGpuCache";
@ -272,8 +272,7 @@ void UpdateSurfaceNodeNit(const sptr<SurfaceBuffer>& surfaceBuffer, RSSurfaceRen
using namespace HDI::Display::Graphic::Common::V1_0;
std::vector<uint8_t> hdrStaticMetadataVec;
if (MetadataHelper::GetHDRStaticMetadata(surfaceBuffer, hdrStaticMetadataVec) != GSERROR_OK) {
RS_LOGE("MetadataHelper GetHDRStaticMetadata failed");
return;
RS_LOGD("MetadataHelper GetHDRStaticMetadata failed");
}
float scaler = DEFAULT_SCALER;
if (hdrStaticMetadataVec.size() != sizeof(hdrStaticMetadataVec) || hdrStaticMetadataVec.data() == nullptr) {
@ -295,6 +294,8 @@ void UpdateSurfaceNodeNit(const sptr<SurfaceBuffer>& surfaceBuffer, RSSurfaceRen
} else {
surfaceNode.SetBrightnessRatio(std::pow(layerNits / displayNits, 1.0f / GAMMA2_2)); // gamma 2.2
}
RS_LOGD("RSMainThread UpdateSurfaceNodeNit layerNits: %{public}f, displayNits: %{public}f, sdrNits: %{public}f,"
" scaler: %{public}f", layerNits, displayNits, sdrNits, scaler);
}
std::string g_dumpStr = "";
@ -1388,8 +1389,8 @@ void RSMainThread::ConsumeAndUpdateAllNodes()
}
UpdateSurfaceNodeNit((*surfaceNode).GetRSSurfaceHandler()->GetBuffer(),
*surfaceNode, CheckIsHdrSurface(*surfaceNode));
RSLuminanceControl::Get().SetHdrStatus(0, hasHdrVideo, HDR_TYPE::VIDEO);
});
RSLuminanceControl::Get().SetHdrStatus(0, hasHdrVideo, HDR_TYPE::VIDEO);
if (needRequestNextVsync) {
RequestNextVSync();
}
@ -2119,7 +2120,7 @@ void RSMainThread::Render()
surfaceNodeWatermarksChanged_ = false;
}
}
renderThreadParams_->SetCurtainScreenUsingStatus(isCurtainScreenOn_);
UniRender(rootNode);
frameCount_++;

View File

@ -251,6 +251,7 @@ void RSUniRenderComposerAdapter::SetComposeInfoToLayer(
layer->SetMatrix(info.matrix);
layer->SetGravity(info.gravity);
SetMetaDataInfoToLayer(layer, info.buffer, surface);
layer->SetSdrNit(info.sdrNit);
layer->SetDisplayNit(info.displayNit);
layer->SetBrightnessRatio(info.brightnessRatio);
}
@ -806,14 +807,17 @@ ComposeInfo RSUniRenderComposerAdapter::BuildComposeInfo(RSSurfaceRenderNode& no
RS_LOGE("RSUniRenderComposerAdapter::BuildComposeInfo fail, node params is nullptr");
return info;
}
info.sdrNit = renderParam->GetSdrNit();
info.displayNit = renderParam->GetDisplayNit();
info.brightnessRatio = renderParam->GetBrightnessRatio();
RS_LOGD("RSURCA::BuildCInfo sdrNit: %{public}d, displayNit: %{public}d, brightnessRatio: %{public}f",
info.sdrNit, info.displayNit, info.brightnessRatio);
RS_LOGD("RSUniRenderComposerAdapter::BuildCInfo id:%{public}" PRIu64
" zOrder:%{public}d blendType:%{public}d needClient:%{public}d displayNit:%{public}d brightnessRatio:%{public}f"
" zOrder:%{public}d blendType:%{public}d needClient:%{public}d"
" alpha[%{public}d %{public}d] boundRect[%{public}d %{public}d %{public}d %{public}d]"
" srcRect[%{public}d %{public}d %{public}d %{public}d] dstRect[%{public}d %{public}d %{public}d %{public}d]"
" matrix[%{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f]",
node.GetId(), info.zOrder, info.blendType, info.needClient, info.displayNit, info.brightnessRatio,
node.GetId(), info.zOrder, info.blendType, info.needClient,
info.alpha.enGlobalAlpha, info.alpha.gAlpha,
info.boundRect.x, info.boundRect.y, info.boundRect.w, info.boundRect.h,
info.srcRect.x, info.srcRect.y, info.srcRect.w, info.srcRect.y,
@ -872,14 +876,17 @@ ComposeInfo RSUniRenderComposerAdapter::BuildComposeInfo(DrawableV2::RSSurfaceRe
RS_LOGE("RSUniRenderComposerAdapter::curRenderParam is nullptr");
return info;
}
info.sdrNit = curRenderParam->GetSdrNit();
info.displayNit = curRenderParam->GetDisplayNit();
info.brightnessRatio = curRenderParam->GetBrightnessRatio();
RS_LOGD("RSURCA::BuildCInfo sdrNit: %{public}d, displayNit: %{public}d, brightnessRatio: %{public}f",
info.sdrNit, info.displayNit, info.brightnessRatio);
RS_LOGD("RSUniRenderComposerAdapter::BuildCInfo id:%{public}" PRIu64
" zOrder:%{public}d blendType:%{public}d needClient:%{public}d displayNit:%{public}d brightnessRatio:%{public}f"
" zOrder:%{public}d blendType:%{public}d needClient:%{public}d"
" alpha[%{public}d %{public}d] boundRect[%{public}d %{public}d %{public}d %{public}d]"
" srcRect[%{public}d %{public}d %{public}d %{public}d] dstRect[%{public}d %{public}d %{public}d %{public}d]"
" matrix[%{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f %{public}f]",
surfaceDrawable.GetId(), info.zOrder, info.blendType, info.needClient, info.displayNit, info.brightnessRatio,
surfaceDrawable.GetId(), info.zOrder, info.blendType, info.needClient,
info.alpha.enGlobalAlpha, info.alpha.gAlpha,
info.boundRect.x, info.boundRect.y, info.boundRect.w, info.boundRect.h,
info.srcRect.x, info.srcRect.y, info.srcRect.w, info.srcRect.y,

View File

@ -95,6 +95,7 @@ void RSUniRenderEngine::DrawLayers(RSPaintFilterCanvas& canvas, const std::vecto
params.targetColorGamut = colorGamut;
auto screenManager = CreateOrGetScreenManager();
if (screenManager != nullptr) {
params.sdrNits = layer->GetSdrNit();
params.tmoNits = layer->GetDisplayNit();
params.displayNits = params.tmoNits / std::pow(layer->GetBrightnessRatio(), 2.2f); // gamma 2.2
}

View File

@ -116,6 +116,7 @@ void RSUniRenderProcessor::CreateLayer(const RSSurfaceRenderNode& node, RSSurfac
}
LayerInfoPtr layer = GetLayerInfo(
params, buffer, preBuffer, surfaceHandler->GetConsumer(), params.GetAcquireFence());
layer->SetSdrNit(params.GetSdrNit());
layer->SetDisplayNit(params.GetDisplayNit());
layer->SetBrightnessRatio(params.GetBrightnessRatio());
@ -159,6 +160,7 @@ void RSUniRenderProcessor::CreateLayerForRenderThread(DrawableV2::RSSurfaceRende
surfaceDrawable.GetConsumerOnDraw(), params.GetAcquireFence());
layer->SetNodeId(surfaceDrawable.GetId());
auto& renderParams = static_cast<RSSurfaceRenderParams&>(params);
layer->SetSdrNit(renderParams.GetSdrNit());
layer->SetDisplayNit(renderParams.GetDisplayNit());
layer->SetBrightnessRatio(renderParams.GetBrightnessRatio());
uniComposerAdapter_->SetMetaDataInfoToLayer(layer, params.GetBuffer(), surfaceDrawable.GetConsumerOnDraw());