mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 17:21:51 +00:00
!15887 修复截图色域设置
Merge pull request !15887 from yanghua_angel/canvas_colorspace
This commit is contained in:
commit
974f2b1a52
@ -118,6 +118,8 @@ public:
|
||||
sk_sp<SkColorSpace> GetSkColorSpace() const;
|
||||
std::shared_ptr<Data> Serialize() const;
|
||||
bool Deserialize(std::shared_ptr<Data> data);
|
||||
bool IsSRGB() const;
|
||||
bool Equals(const std::shared_ptr<ColorSpace>& colorSpace) const;
|
||||
|
||||
private:
|
||||
ColorSpaceType type_;
|
||||
|
@ -113,6 +113,16 @@ bool ColorSpace::Deserialize(std::shared_ptr<Data> data)
|
||||
return impl_->Deserialize(data);
|
||||
}
|
||||
|
||||
bool ColorSpace::IsSRGB() const
|
||||
{
|
||||
return impl_->IsSRGB();
|
||||
}
|
||||
|
||||
bool ColorSpace::Equals(const std::shared_ptr<ColorSpace>& colorSpace) const
|
||||
{
|
||||
return impl_->Equals(colorSpace);
|
||||
}
|
||||
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -28,6 +28,7 @@ enum class CMSTransferFuncType;
|
||||
enum class CMSMatrixType;
|
||||
struct CMSTransferFunction;
|
||||
struct CMSMatrix3x3;
|
||||
class ColorSpace;
|
||||
class Image;
|
||||
class ColorSpaceImpl : public BaseImpl {
|
||||
public:
|
||||
@ -42,6 +43,8 @@ public:
|
||||
virtual sk_sp<SkColorSpace> GetSkColorSpace() const = 0;
|
||||
virtual std::shared_ptr<Data> Serialize() const = 0;
|
||||
virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
|
||||
virtual bool IsSRGB() const = 0;
|
||||
virtual bool Equals(const std::shared_ptr<ColorSpace>& colorSpace) const = 0;
|
||||
};
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
|
@ -130,6 +130,27 @@ bool SkiaColorSpace::Deserialize(std::shared_ptr<Data> data)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkiaColorSpace::IsSRGB() const
|
||||
{
|
||||
if (colorSpace_ == nullptr) {
|
||||
LOGD("SkiaColorSpace::IsSRGB, colorSpace_ is nullptr!");
|
||||
return false;
|
||||
}
|
||||
return colorSpace_->isSRGB();
|
||||
}
|
||||
|
||||
bool SkiaColorSpace::Equals(const std::shared_ptr<ColorSpace>& colorSpace) const
|
||||
{
|
||||
sk_sp<SkColorSpace> skColorSpace = nullptr;
|
||||
if (colorSpace != nullptr) {
|
||||
auto skiaColorSpace = colorSpace->GetImpl<SkiaColorSpace>();
|
||||
if (skiaColorSpace != nullptr) {
|
||||
skColorSpace = skiaColorSpace->colorSpace_;
|
||||
}
|
||||
}
|
||||
return SkColorSpace::Equals(colorSpace_.get(), skColorSpace.get());
|
||||
}
|
||||
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -45,6 +45,8 @@ public:
|
||||
sk_sp<SkColorSpace> GetSkColorSpace() const override;
|
||||
std::shared_ptr<Data> Serialize() const override;
|
||||
bool Deserialize(std::shared_ptr<Data> data) override;
|
||||
bool IsSRGB() const override;
|
||||
bool Equals(const std::shared_ptr<ColorSpace>& colorSpace) const override;
|
||||
private:
|
||||
sk_sp<SkColorSpace> colorSpace_;
|
||||
};
|
||||
|
@ -170,7 +170,7 @@ bool RSBaseRenderEngine::NeedForceCPU(const std::vector<LayerInfoPtr>& layers)
|
||||
|
||||
std::shared_ptr<Drawing::Image> RSBaseRenderEngine::CreateEglImageFromBuffer(RSPaintFilterCanvas& canvas,
|
||||
const sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& acquireFence, const uint32_t threadIndex,
|
||||
GraphicColorGamut colorGamut)
|
||||
const std::shared_ptr<Drawing::ColorSpace>& drawingColorSpace)
|
||||
{
|
||||
#ifdef RS_ENABLE_EGLIMAGE
|
||||
#if defined(RS_ENABLE_GL)
|
||||
@ -190,12 +190,6 @@ std::shared_ptr<Drawing::Image> RSBaseRenderEngine::CreateEglImageFromBuffer(RSP
|
||||
RS_LOGE("RSBaseRenderEngine::CreateEglImageFromBuffer MapEglImageFromSurfaceBuffer return invalid texture ID");
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<Drawing::ColorSpace> drawingColorSpace = nullptr;
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
drawingColorSpace = ConvertColorGamutToDrawingColorSpace(colorGamut);
|
||||
#else
|
||||
(void)colorGamut;
|
||||
#endif
|
||||
auto pixelFmt = buffer->GetFormat();
|
||||
auto bitmapFormat = RSBaseRenderUtil::GenerateDrawingBitmapFormat(buffer);
|
||||
|
||||
@ -505,30 +499,30 @@ void RSBaseRenderEngine::DrawBuffer(RSPaintFilterCanvas& canvas, BufferDrawParam
|
||||
}
|
||||
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
bool RSBaseRenderEngine::ConvertColorGamutToSpaceInfo(const GraphicColorGamut& colorGamut,
|
||||
bool RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo(const std::shared_ptr<Drawing::ColorSpace>& colorSpace,
|
||||
HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceInfo& colorSpaceInfo)
|
||||
{
|
||||
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},
|
||||
};
|
||||
|
||||
CM_ColorSpaceType colorSpaceType = CM_COLORSPACE_NONE;
|
||||
if (RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.find(colorGamut) != RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.end()) {
|
||||
colorSpaceType = RS_TO_COMMON_COLOR_SPACE_TYPE_MAP.at(colorGamut);
|
||||
if (colorSpace == nullptr || colorSpace->Equals(nullptr) || colorSpace->IsSRGB()) {
|
||||
colorSpaceType = CM_SRGB_FULL;
|
||||
} else if (colorSpace->Equals(Drawing::ColorSpace::CreateRGB(
|
||||
Drawing::CMSTransferFuncType::SRGB, Drawing::CMSMatrixType::DCIP3))) {
|
||||
colorSpaceType = CM_P3_FULL;
|
||||
} else if (colorSpace->Equals(Drawing::ColorSpace::CreateRGB(
|
||||
Drawing::CMSTransferFuncType::SRGB, Drawing::CMSMatrixType::ADOBE_RGB))) {
|
||||
colorSpaceType = CM_ADOBERGB_FULL;
|
||||
} else if (colorSpace->Equals(Drawing::ColorSpace::CreateRGB(
|
||||
Drawing::CMSTransferFuncType::SRGB, Drawing::CMSMatrixType::REC2020))) {
|
||||
colorSpaceType = CM_DISPLAY_BT2020_SRGB;
|
||||
} else {
|
||||
RS_LOGD("RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo color space not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
GSError ret = MetadataHelper::ConvertColorSpaceTypeToInfo(colorSpaceType, colorSpaceInfo);
|
||||
if (ret != GSERROR_OK) {
|
||||
RS_LOGE("RSBaseRenderEngine::ConvertColorGamutToSpaceInfo ConvertColorSpaceTypeToInfo failed with \
|
||||
RS_LOGE("RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo ConvertColorSpaceTypeToInfo failed with \
|
||||
%{public}u.", ret);
|
||||
return false;
|
||||
}
|
||||
@ -536,6 +530,16 @@ bool RSBaseRenderEngine::ConvertColorGamutToSpaceInfo(const GraphicColorGamut& c
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawing::ColorSpace> RSBaseRenderEngine::GetCanvasColorSpace(const RSPaintFilterCanvas& canvas)
|
||||
{
|
||||
auto surface = canvas.GetSurface();
|
||||
if (surface == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return surface->GetImageInfo().GetColorSpace();
|
||||
}
|
||||
|
||||
bool RSBaseRenderEngine::SetColorSpaceConverterDisplayParameter(
|
||||
const BufferDrawParam& params, Media::VideoProcessingEngine::ColorSpaceConverterDisplayParameter& parameter)
|
||||
{
|
||||
@ -642,22 +646,19 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam&
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawing::ColorSpace> drawingColorSpace = Drawing::ColorSpace::CreateSRGB();
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
Media::VideoProcessingEngine::ColorSpaceConverterDisplayParameter parameter;
|
||||
GSError ret = MetadataHelper::GetColorSpaceInfo(params.buffer, parameter.inputColorSpace.colorSpaceInfo);
|
||||
if (ret == GSERROR_OK) {
|
||||
drawingColorSpace = GetCanvasColorSpace(canvas);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RS_ENABLE_VK
|
||||
if (RSSystemProperties::IsUseVulkan()) {
|
||||
auto imageCache = vkImageManager_->MapVkImageFromSurfaceBuffer(params.buffer,
|
||||
params.acquireFence, params.threadIndex);
|
||||
std::shared_ptr<Drawing::ColorSpace> drawingColorSpace = Drawing::ColorSpace::CreateSRGB();
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
drawingColorSpace = ConvertColorGamutToDrawingColorSpace(params.targetColorGamut);
|
||||
if (ret != GSERROR_OK) {
|
||||
drawingColorSpace = nullptr;
|
||||
}
|
||||
#endif
|
||||
auto bitmapFormat = RSBaseRenderUtil::GenerateDrawingBitmapFormat(params.buffer);
|
||||
#ifndef ROSEN_EMULATOR
|
||||
auto surfaceOrigin = Drawing::TextureOrigin::TOP_LEFT;
|
||||
@ -681,13 +682,8 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam&
|
||||
|
||||
#ifdef RS_ENABLE_GL // RS_ENABLE_GL
|
||||
if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) {
|
||||
auto colorGamut = params.targetColorGamut;
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
if (ret != GSERROR_OK) {
|
||||
colorGamut = GRAPHIC_COLOR_GAMUT_SRGB;
|
||||
}
|
||||
#endif
|
||||
image = CreateEglImageFromBuffer(canvas, params.buffer, params.acquireFence, params.threadIndex, colorGamut);
|
||||
image = CreateEglImageFromBuffer(canvas, params.buffer, params.acquireFence, params.threadIndex,
|
||||
drawingColorSpace);
|
||||
if (image == nullptr) {
|
||||
RS_LOGE("RSBaseRenderEngine::DrawImage: image is nullptr!");
|
||||
return;
|
||||
@ -733,8 +729,8 @@ void RSBaseRenderEngine::DrawImage(RSPaintFilterCanvas& canvas, BufferDrawParam&
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConvertColorGamutToSpaceInfo(params.targetColorGamut, parameter.outputColorSpace.colorSpaceInfo)) {
|
||||
RS_LOGD("RSBaseRenderEngine::DrawImage ConvertColorGamutToSpaceInfo failed");
|
||||
if (!ConvertDrawingColorSpaceToSpaceInfo(drawingColorSpace, parameter.outputColorSpace.colorSpaceInfo)) {
|
||||
RS_LOGD("RSBaseRenderEngine::DrawImage ConvertDrawingColorSpaceToSpaceInfo failed");
|
||||
DrawImageRect(canvas, image, params, samplingOptions);
|
||||
return;
|
||||
}
|
||||
|
@ -227,7 +227,8 @@ protected:
|
||||
private:
|
||||
std::shared_ptr<Drawing::Image> CreateEglImageFromBuffer(RSPaintFilterCanvas& canvas,
|
||||
const sptr<SurfaceBuffer>& buffer, const sptr<SyncFence>& acquireFence,
|
||||
const uint32_t threadIndex = UNI_MAIN_THREAD_INDEX, GraphicColorGamut colorGamut = GRAPHIC_COLOR_GAMUT_SRGB);
|
||||
const uint32_t threadIndex = UNI_MAIN_THREAD_INDEX,
|
||||
const std::shared_ptr<Drawing::ColorSpace>& drawingColorSpace = nullptr);
|
||||
|
||||
#if (defined RS_ENABLE_GL) || (defined RS_ENABLE_VK)
|
||||
std::shared_ptr<RenderContext> renderContext_ = nullptr;
|
||||
@ -245,7 +246,8 @@ private:
|
||||
#ifdef USE_VIDEO_PROCESSING_ENGINE
|
||||
static bool SetColorSpaceConverterDisplayParameter(
|
||||
const BufferDrawParam& params, Media::VideoProcessingEngine::ColorSpaceConverterDisplayParameter& parameter);
|
||||
static bool ConvertColorGamutToSpaceInfo(const GraphicColorGamut& colorGamut,
|
||||
static std::shared_ptr<Drawing::ColorSpace> GetCanvasColorSpace(const RSPaintFilterCanvas& canvas);
|
||||
static bool ConvertDrawingColorSpaceToSpaceInfo(const std::shared_ptr<Drawing::ColorSpace>& colorSpace,
|
||||
HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceInfo& colorSpaceInfo);
|
||||
std::shared_ptr<Media::VideoProcessingEngine::ColorSpaceConverterDisplay> colorSpaceConverterDisplay_ = nullptr;
|
||||
#endif
|
||||
|
@ -118,6 +118,36 @@ HWTEST_F(SkiaColorSpaceTest, Deserialize001, TestSize.Level1)
|
||||
SkiaColorSpace skiaColorSpace;
|
||||
EXPECT_FALSE(skiaColorSpace.Deserialize(nullptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsSRGB001
|
||||
* @tc.desc: Test IsSRGB
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SkiaColorSpaceTest, IsSRGB001, TestSize.Level1)
|
||||
{
|
||||
SkiaColorSpace skiaColorSpace;
|
||||
skiaColorSpace.InitWithSRGB();
|
||||
EXPECT_TRUE(skiaColorSpace.IsSRGB());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Equals001
|
||||
* @tc.desc: Test Equals
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SkiaColorSpaceTest, Equals001, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<ColorSpaceImpl> colorSpaceImpl = std::make_shared<SkiaColorSpace>();
|
||||
colorSpaceImpl->InitWithSRGB();
|
||||
std::shared_ptr<ColorSpace> colorSpace = ColorSpace::CreateFromImpl(colorSpaceImpl);
|
||||
|
||||
SkiaColorSpace skiaColorSpace;
|
||||
skiaColorSpace.InitWithSRGB();
|
||||
EXPECT_TRUE(skiaColorSpace.Equals(colorSpace));
|
||||
}
|
||||
} // namespace Drawing
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -266,5 +266,47 @@ HWTEST(RSBaseRenderEngineUnitTest, ConvertColorGamutToDrawingColorSpace, TestSiz
|
||||
colorSpace = RSBaseRenderEngine::ConvertColorGamutToDrawingColorSpace(GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020);
|
||||
ASSERT_EQ(colorSpace, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ConvertDrawingColorSpaceToSpaceInfo
|
||||
* @tc.desc: Test ConvertDrawingColorSpaceToSpaceInfo
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST(RSBaseRenderEngineUnitTest, ConvertDrawingColorSpaceToSpaceInfo, TestSize.Level1)
|
||||
{
|
||||
using namespace HDI::Display::Graphic::Common::V1_0;
|
||||
std::shared_ptr<Drawing::ColorSpace> colorSpace;
|
||||
CM_ColorSpaceInfo colorSpaceInfo;
|
||||
|
||||
colorSpace = Drawing::ColorSpace::CreateSRGB();
|
||||
EXPECT_TRUE(RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo(colorSpace, colorSpaceInfo));
|
||||
EXPECT_EQ(colorSpaceInfo.primaries, COLORPRIMARIES_SRGB);
|
||||
EXPECT_EQ(colorSpaceInfo.transfunc, TRANSFUNC_SRGB);
|
||||
|
||||
colorSpace = Drawing::ColorSpace::CreateRGB(
|
||||
Drawing::CMSTransferFuncType::SRGB, Drawing::CMSMatrixType::DCIP3);
|
||||
EXPECT_TRUE(RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo(colorSpace, colorSpaceInfo));
|
||||
EXPECT_EQ(colorSpaceInfo.primaries, COLORPRIMARIES_P3_D65);
|
||||
EXPECT_EQ(colorSpaceInfo.transfunc, TRANSFUNC_SRGB);
|
||||
|
||||
colorSpace = Drawing::ColorSpace::CreateRGB(
|
||||
Drawing::CMSTransferFuncType::REC2020, Drawing::CMSMatrixType::REC2020);
|
||||
EXPECT_FALSE(RSBaseRenderEngine::ConvertDrawingColorSpaceToSpaceInfo(colorSpace, colorSpaceInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCanvasColorSpace
|
||||
* @tc.desc: Test GetCanvasColorSpace
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST(RSBaseRenderEngineUnitTest, GetCanvasColorSpace, TestSize.Level1)
|
||||
{
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
EXPECT_EQ(RSBaseRenderEngine::GetCanvasColorSpace(canvas.get()), nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user