mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 23:20:32 +00:00
fix colorspace
Signed-off-by: wanganjie <wanganjie1@huawei.com>
This commit is contained in:
parent
a04d78c1a7
commit
fce7d68b02
@ -141,7 +141,6 @@ private:
|
||||
void RecordCompositionTime(int64_t timeStamp);
|
||||
inline bool CheckFbSurface();
|
||||
bool CheckAndUpdateClientBufferCahce(sptr<SurfaceBuffer> buffer, uint32_t& index);
|
||||
static void SetBufferColorSpace(sptr<SurfaceBuffer>& buffer, const std::vector<LayerPtr>& layers);
|
||||
|
||||
// DISPLAY ENGINE
|
||||
bool CheckIfDoArsrPre(const LayerInfoPtr &layerInfo);
|
||||
|
@ -415,48 +415,6 @@ bool HdiOutput::CheckAndUpdateClientBufferCahce(sptr<SurfaceBuffer> buffer, uint
|
||||
return false;
|
||||
}
|
||||
|
||||
void HdiOutput::SetBufferColorSpace(sptr<SurfaceBuffer>& buffer, const std::vector<LayerPtr>& layers)
|
||||
{
|
||||
if (buffer == nullptr) {
|
||||
HLOGE("HdiOutput::SetBufferColorSpace null buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
CM_ColorSpaceType targetColorSpace = CM_DISPLAY_SRGB;
|
||||
for (auto& layer : layers) {
|
||||
if (layer == nullptr) {
|
||||
HLOGW("HdiOutput::SetBufferColorSpace The layer is nullptr");
|
||||
continue;
|
||||
}
|
||||
auto layerInfo = layer->GetLayerInfo();
|
||||
if (layerInfo == nullptr) {
|
||||
HLOGW("HdiOutput::SetBufferColorSpace The info of layer is nullptr");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto layerBuffer = layerInfo->GetBuffer();
|
||||
if (layerBuffer == nullptr) {
|
||||
HLOGW("HdiOutput::SetBufferColorSpace The buffer of layer is nullptr");
|
||||
continue;
|
||||
}
|
||||
|
||||
CM_ColorSpaceInfo colorSpaceInfo;
|
||||
if (MetadataHelper::GetColorSpaceInfo(layerBuffer, colorSpaceInfo) != GSERROR_OK) {
|
||||
HLOGD("HdiOutput::SetBufferColorSpace Get color space failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (colorSpaceInfo.primaries != COLORPRIMARIES_SRGB) {
|
||||
targetColorSpace = CM_DISPLAY_P3_SRGB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MetadataHelper::SetColorSpaceType(buffer, targetColorSpace) != GSERROR_OK) {
|
||||
HLOGE("HdiOutput::SetBufferColorSpace set metadata to buffer failed");
|
||||
}
|
||||
}
|
||||
|
||||
// DISPLAY ENGINE
|
||||
bool HdiOutput::CheckIfDoArsrPre(const LayerInfoPtr &layerInfo)
|
||||
{
|
||||
@ -535,8 +493,6 @@ int32_t HdiOutput::FlushScreen(std::vector<LayerPtr> &compClientLayers)
|
||||
bufferCached = CheckAndUpdateClientBufferCahce(currFrameBuffer_, index);
|
||||
}
|
||||
|
||||
SetBufferColorSpace(currFrameBuffer_, compClientLayers);
|
||||
|
||||
CHECK_DEVICE_NULL(device_);
|
||||
int32_t ret = device_->SetScreenClientDamage(screenId_, outputDamages_);
|
||||
if (ret != GRAPHIC_DISPLAY_SUCCESS) {
|
||||
|
@ -336,25 +336,6 @@ HWTEST_F(HdiOutputTest, CheckAndUpdateClientBufferCahce003, Function | MediumTes
|
||||
ASSERT_EQ(hdiOutput->bufferCache_[0], buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: SetBufferColorSpace
|
||||
* Type: Function
|
||||
* Rank: Important(1)
|
||||
* EnvConditions: N/A
|
||||
* CaseDescription: 1.call SetBufferColorSpace()
|
||||
* 2.check ret
|
||||
*/
|
||||
HWTEST_F(HdiOutputTest, SetBufferColorSpace, Function | MediumTest | Level1)
|
||||
{
|
||||
std::vector<LayerPtr> layers;
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
layers.emplace_back(std::make_shared<HdiLayer>(i));
|
||||
}
|
||||
sptr<SurfaceBuffer> buffer = nullptr;
|
||||
HdiOutputTest::hdiOutput_->SetBufferColorSpace(buffer, layers);
|
||||
sptr<SurfaceBuffer> buffer1 = new SurfaceBufferImpl();
|
||||
HdiOutputTest::hdiOutput_->SetBufferColorSpace(buffer1, layers);
|
||||
}
|
||||
/*
|
||||
* Function: ReleaseLayers
|
||||
* Type: Function
|
||||
|
@ -680,6 +680,35 @@ void RSSurfaceRenderNodeDrawable::CaptureSurface(RSPaintFilterCanvas& canvas, RS
|
||||
RSRenderParams::SetParentSurfaceMatrix(parentSurfaceMatrix);
|
||||
}
|
||||
|
||||
GraphicColorGamut RSSurfaceRenderNodeDrawable::GetAncestorDisplayColorGamut(const RSSurfaceRenderParams& surfaceParams)
|
||||
{
|
||||
GraphicColorGamut targetColorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
|
||||
auto ancestorDrawable = surfaceParams.GetAncestorDisplayDrawable().lock();
|
||||
if (!ancestorDrawable) {
|
||||
RS_LOGE("ancestorDrawable return nullptr");
|
||||
return targetColorGamut;
|
||||
}
|
||||
auto ancestorDisplayDrawable = std::static_pointer_cast<RSDisplayRenderNodeDrawable>(ancestorDrawable);
|
||||
if (!ancestorDisplayDrawable) {
|
||||
RS_LOGE("ancestorDisplayDrawable return nullptr");
|
||||
return targetColorGamut;
|
||||
}
|
||||
auto& ancestorParam = ancestorDrawable->GetRenderParams();
|
||||
if (!ancestorParam) {
|
||||
RS_LOGE("ancestorParam return nullptr");
|
||||
return targetColorGamut;
|
||||
}
|
||||
auto renderParams = static_cast<RSDisplayRenderParams*>(ancestorParam.get());
|
||||
if (!renderParams) {
|
||||
RS_LOGE("renderParams return nullptr");
|
||||
return targetColorGamut;
|
||||
}
|
||||
|
||||
targetColorGamut = renderParams->GetNewColorSpace();
|
||||
RS_LOGD("params.targetColorGamut is %{public}d in DealWithSelfDrawingNodeBuffer", targetColorGamut);
|
||||
return targetColorGamut;
|
||||
}
|
||||
|
||||
void RSSurfaceRenderNodeDrawable::DealWithSelfDrawingNodeBuffer(
|
||||
RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams)
|
||||
{
|
||||
@ -698,7 +727,7 @@ void RSSurfaceRenderNodeDrawable::DealWithSelfDrawingNodeBuffer(
|
||||
surfaceParams.SetGlobalAlpha(1.0f);
|
||||
pid_t threadId = gettid();
|
||||
auto params = RSUniRenderUtil::CreateBufferDrawParam(*this, false, threadId);
|
||||
params.targetColorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
|
||||
params.targetColorGamut = GetAncestorDisplayColorGamut(surfaceParams);
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
params.sdrNits = surfaceParams.GetSdrNit();
|
||||
params.tmoNits = surfaceParams.GetDisplayNit();
|
||||
|
@ -215,6 +215,7 @@ public:
|
||||
void SetDirtyRegionAlignedEnable(bool enable);
|
||||
void SetDirtyRegionBelowCurrentLayer(Occlusion::Region& region);
|
||||
std::shared_ptr<RSDirtyRegionManager> GetSyncDirtyManager() const override;
|
||||
GraphicColorGamut GetAncestorDisplayColorGamut(const RSSurfaceRenderParams& surfaceParams);
|
||||
void DealWithSelfDrawingNodeBuffer(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
|
||||
void ClearCacheSurfaceOnly();
|
||||
|
||||
|
@ -224,7 +224,7 @@ std::shared_ptr<Drawing::Image> RSBaseRenderEngine::CreateEglImageFromBuffer(RSP
|
||||
}
|
||||
externalTextureInfo.SetFormat(glType);
|
||||
if (!image->BuildFromTexture(*canvas.GetGPUContext(), externalTextureInfo,
|
||||
surfaceOrigin, bitmapFormat, nullptr)) {
|
||||
surfaceOrigin, bitmapFormat, drawingColorSpace)) {
|
||||
RS_LOGE("RSBaseRenderEngine::CreateEglImageFromBuffer image BuildFromTexture failed");
|
||||
return nullptr;
|
||||
}
|
||||
@ -234,7 +234,7 @@ std::shared_ptr<Drawing::Image> RSBaseRenderEngine::CreateEglImageFromBuffer(RSP
|
||||
#if defined(RS_ENABLE_VK)
|
||||
if (RSSystemProperties::IsUseVulkan() &&
|
||||
!image->BuildFromTexture(*renderContext_->GetDrGPUContext(), externalTextureInfo,
|
||||
surfaceOrigin, bitmapFormat, nullptr)) {
|
||||
surfaceOrigin, bitmapFormat, drawingColorSpace)) {
|
||||
RS_LOGE("RSBaseRenderEngine::CreateEglImageFromBuffer image BuildFromTexture failed");
|
||||
return nullptr;
|
||||
}
|
||||
@ -634,7 +634,7 @@ void RSBaseRenderEngine::ColorSpaceConvertor(std::shared_ptr<Drawing::ShaderEffe
|
||||
|
||||
void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam& params)
|
||||
{
|
||||
RS_TRACE_NAME("RSBaseRenderEngine::DrawImage(GPU)");
|
||||
RS_TRACE_NAME_FMT("RSBaseRenderEngine::DrawImage(GPU) targetColorGamut=%d", params.targetColorGamut);
|
||||
auto image = std::make_shared<Drawing::Image>();
|
||||
if (!RSBaseRenderUtil::IsBufferValid(params.buffer)) {
|
||||
RS_LOGE("RSBaseRenderEngine::DrawImage invalid buffer!");
|
||||
@ -662,7 +662,7 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam&
|
||||
}
|
||||
auto& backendTexture = imageCache->GetBackendTexture();
|
||||
if (!image->BuildFromTexture(*contextDrawingVk, backendTexture.GetTextureInfo(),
|
||||
surfaceOrigin, bitmapFormat, nullptr,
|
||||
surfaceOrigin, bitmapFormat, drawingColorSpace,
|
||||
NativeBufferUtils::DeleteVkImage, imageCache->RefCleanupHelper())) {
|
||||
ROSEN_LOGE("RSBaseRenderEngine::DrawImage: backendTexture is not valid!!!");
|
||||
return;
|
||||
@ -717,8 +717,8 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam&
|
||||
|
||||
if (ret != GSERROR_OK) {
|
||||
RS_LOGD("RSBaseRenderEngine::DrawImage GetColorSpaceInfo failed with %{public}u.", ret);
|
||||
DrawImageRect(canvas, image, params, samplingOptions);
|
||||
return;
|
||||
MetadataHelper::ConvertColorSpaceTypeToInfo(HDI::Display::Graphic::Common::V1_0::CM_BT709_LIMIT,
|
||||
parameter.inputColorSpace.colorSpaceInfo);
|
||||
}
|
||||
|
||||
if (!ConvertColorGamutToSpaceInfo(params.targetColorGamut, parameter.outputColorSpace.colorSpaceInfo)) {
|
||||
|
@ -473,6 +473,12 @@ void RSHardwareThread::Redraw(const sptr<Surface>& surface, const std::vector<La
|
||||
auto renderFrameConfig = RSBaseRenderUtil::GetFrameBufferRequestConfig(screenInfo,
|
||||
true, isProtected, colorGamut, pixelFormat);
|
||||
drawingColorSpace = RSBaseRenderEngine::ConvertColorGamutToDrawingColorSpace(colorGamut);
|
||||
// set color space to surface buffer metadata
|
||||
using namespace HDI::Display::Graphic::Common::V1_0;
|
||||
CM_ColorSpaceType colorSpace = CM_SRGB_FULL;
|
||||
if (ConvertColorGamutToSpaceType(colorGamut, colorSpace)) {
|
||||
surface->SetUserData("ATTRKEY_COLORSPACE_INFO", std::to_string(colorSpace));
|
||||
}
|
||||
#else
|
||||
auto renderFrameConfig = RSBaseRenderUtil::GetFrameBufferRequestConfig(screenInfo, true, isProtected);
|
||||
#endif
|
||||
@ -620,5 +626,29 @@ GraphicPixelFormat RSHardwareThread::ComputeTargetPixelFormat(const std::vector<
|
||||
|
||||
return pixelFormat;
|
||||
}
|
||||
|
||||
bool RSHardwareThread::ConvertColorGamutToSpaceType(const GraphicColorGamut& colorGamut,
|
||||
HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceType)
|
||||
{
|
||||
using namespace HDI::Display::Graphic::Common::V1_0;
|
||||
static const std::map<GraphicColorGamut, CM_ColorSpaceType> RS_TO_COMMON_COLOR_SPACE_TYPE_MAP {
|
||||
{GRAPHIC_COLOR_GAMUT_STANDARD_BT601, CM_BT601_EBU_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_STANDARD_BT709, CM_BT709_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_SRGB, CM_SRGB_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_ADOBE_RGB, CM_ADOBERGB_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_DISPLAY_P3, CM_P3_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_BT2020, CM_DISPLAY_BT2020_SRGB},
|
||||
{GRAPHIC_COLOR_GAMUT_BT2100_PQ, CM_BT2020_PQ_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_BT2100_HLG, CM_BT2020_HLG_FULL},
|
||||
{GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020, CM_DISPLAY_BT2020_SRGB},
|
||||
};
|
||||
|
||||
if (RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.find(colorGamut) == RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
colorSpaceType = RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.at(colorGamut);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ private:
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
static GraphicColorGamut ComputeTargetColorGamut(const std::vector<LayerInfoPtr>& layers);
|
||||
static GraphicPixelFormat ComputeTargetPixelFormat(const std::vector<LayerInfoPtr>& layers);
|
||||
static bool ConvertColorGamutToSpaceType(const GraphicColorGamut& colorGamut,
|
||||
HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType& colorSpaceInfo);
|
||||
#endif
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user