Bug 1771374 - Disable color management based on pref in DCLayerTree. r=jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D150276
This commit is contained in:
Kelsey Gilbert 2022-07-12 23:55:51 +00:00
parent 8eb05ff04b
commit 32502f761c
3 changed files with 27 additions and 11 deletions

View File

@ -24,6 +24,7 @@
#include "mozilla/gfx/CanvasManagerParent.h"
#include "mozilla/gfx/CanvasRenderThread.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "mozilla/StaticPrefs_apz.h"
#include "mozilla/StaticPrefs_bidi.h"
@ -2021,6 +2022,14 @@ const mozilla::gfx::ContentDeviceData* gfxPlatform::GetInitContentDeviceData() {
return gContentDeviceInitData;
}
CMSMode GfxColorManagementMode() {
const auto mode = StaticPrefs::gfx_color_management_mode();
if (mode >= 0 && mode < UnderlyingValue(CMSMode::AllCount)) {
return CMSMode(mode);
}
return CMSMode::Off;
}
void gfxPlatform::InitializeCMS() {
if (gCMSInitialized) {
return;
@ -2039,12 +2048,7 @@ void gfxPlatform::InitializeCMS() {
return;
}
{
int32_t mode = StaticPrefs::gfx_color_management_mode();
if (mode >= 0 && mode < int32_t(CMSMode::AllCount)) {
gCMSMode = CMSMode(mode);
}
}
gCMSMode = GfxColorManagementMode();
gCMSsRGBProfile = qcms_profile_sRGB();

View File

@ -1027,4 +1027,6 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
const gfxSkipChars kEmptySkipChars;
};
CMSMode GfxColorManagementMode();
#endif /* GFX_PLATFORM_H */

View File

@ -1043,7 +1043,9 @@ static CspaceTransformPlan ChooseCspaceTransformPlan(
// transform mis-translates colors if you ask VideoProcessor to resize.
// (jgilbert's RTX 3070 machine "osiris")
// Absent more investigation, let's avoid VP with non-YUV sources for now.
if (srcSpace.yuvRange) {
const auto cmsMode = GfxColorManagementMode();
const bool doColorManagement = cmsMode != CMSMode::Off;
if (srcSpace.yuvRange && doColorManagement) {
const auto exactDxgiSpace = ExactDXGIColorSpace(srcSpace);
if (exactDxgiSpace) {
auto plan = CspaceTransformPlan::WithVideoProcessor{};
@ -1098,6 +1100,10 @@ static CspaceTransformPlan ChooseCspaceTransformPlan(
};
break;
}
if (!doColorManagement) {
plan.dstSpace = plan.srcSpace;
plan.dstSpace.yuv = {};
}
return {{}, Some(plan)};
}
@ -1329,10 +1335,14 @@ static Maybe<DCSurfaceSwapChain::Dest> CreateSwapChain(
return {};
}
hr = swapChain.swapChain->SetColorSpace1(aColorSpace);
if (FAILED(hr)) {
gfxCriticalNote << "SetColorSpace1 failed: " << gfx::hexa(hr);
return {};
const auto cmsMode = GfxColorManagementMode();
const bool doColorManagement = cmsMode != CMSMode::Off;
if (doColorManagement) {
hr = swapChain.swapChain->SetColorSpace1(aColorSpace);
if (FAILED(hr)) {
gfxCriticalNote << "SetColorSpace1 failed: " << gfx::hexa(hr);
return {};
}
}
}