1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 01:24:14 +01:00

[wsi] Add parseColorimetryInfo helper

This commit is contained in:
Joshua Ashton 2022-11-17 17:07:50 +00:00 committed by Philip Rebohle
parent ac10c75ca0
commit fabe4a85e3
4 changed files with 120 additions and 6 deletions

View File

@ -1,3 +1,7 @@
wsi_common_src = [
'wsi_edid.cpp',
]
wsi_win32_src = [
'win32/wsi_monitor_win32.cpp',
'win32/wsi_window_win32.cpp',
@ -9,11 +13,11 @@ wsi_sdl2_src = [
]
if dxvk_wsi == 'win32'
wsi_src = wsi_win32_src
wsi_deps = []
wsi_src = wsi_common_src + wsi_win32_src
wsi_deps = [ dep_displayinfo ]
elif dxvk_wsi == 'sdl2'
wsi_src = wsi_sdl2_src
wsi_deps = [ lib_sdl2 ]
wsi_src = wsi_common_src + wsi_sdl2_src
wsi_deps = [ dep_displayinfo, lib_sdl2 ]
else
error('Unknown wsi')
endif

72
src/wsi/wsi_edid.cpp Normal file
View File

@ -0,0 +1,72 @@
extern "C" {
#include "libdisplay-info/info.h"
#include "libdisplay-info/edid.h"
#include "libdisplay-info/cta.h"
}
#include "wsi_edid.h"
#include "../util/util_string.h"
#include "../util/log/log.h"
namespace dxvk::wsi {
std::optional<WsiDisplayMetadata> parseColorimetryInfo(
const WsiEdidData& edidData) {
WsiDisplayMetadata metadata = {};
di_info* info = di_info_parse_edid(edidData.data(), edidData.size());
if (!info) {
Logger::err(str::format("wsi: parseColorimetryInfo: Failed to get parse edid. Reason: ", di_info_get_failure_msg(info)));
return std::nullopt;
}
const di_edid* edid = di_info_get_edid(info);
const di_edid_chromaticity_coords* chroma = di_edid_get_chromaticity_coords(edid);
const di_cta_hdr_static_metadata_block* hdr_static_metadata = nullptr;
const di_cta_colorimetry_block* colorimetry = nullptr;
const di_edid_cta* cta = nullptr;
const di_edid_ext* const* exts = di_edid_get_extensions(edid);
for (; *exts != nullptr; exts++) {
if ((cta = di_edid_ext_get_cta(*exts)))
break;
}
if (cta) {
const di_cta_data_block* const* blocks = di_edid_cta_get_data_blocks(cta);
for (; *blocks != nullptr; blocks++) {
if ((hdr_static_metadata = di_cta_data_block_get_hdr_static_metadata(*blocks)))
continue;
if ((colorimetry = di_cta_data_block_get_colorimetry(*blocks)))
continue;
}
}
if (chroma) {
metadata.redPrimary[0] = chroma->red_x;
metadata.redPrimary[1] = chroma->red_y;
metadata.greenPrimary[0] = chroma->green_x;
metadata.greenPrimary[1] = chroma->green_y;
metadata.bluePrimary[0] = chroma->blue_x;
metadata.bluePrimary[1] = chroma->blue_y;
metadata.whitePoint[0] = chroma->white_x;
metadata.whitePoint[1] = chroma->white_y;
}
if (hdr_static_metadata) {
metadata.maxFullFrameLuminance = hdr_static_metadata->desired_content_max_frame_avg_luminance;
metadata.minLuminance = hdr_static_metadata->desired_content_min_luminance;
metadata.maxLuminance = hdr_static_metadata->desired_content_max_luminance;
}
metadata.supportsST2084 =
chroma &&
colorimetry && colorimetry->bt2020_rgb &&
hdr_static_metadata && hdr_static_metadata->eotfs && hdr_static_metadata->eotfs->pq;
return metadata;
}
}

38
src/wsi/wsi_edid.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include <vector>
#include <cstdint>
#include <optional>
namespace dxvk::wsi {
/**
* \brief Edid blob
*/
using WsiEdidData = std::vector<uint8_t>;
/**
* \brief Display colorimetry info
*/
struct WsiDisplayMetadata {
bool supportsST2084;
float redPrimary[2];
float greenPrimary[2];
float bluePrimary[2];
float whitePoint[2];
float minLuminance;
float maxLuminance;
float maxFullFrameLuminance;
};
/**
* \brief Parse colorimetry info from the EDID
*
* \param [in] edidData The edid blob
* \returns The display metadata + colorimetry info
*/
std::optional<WsiDisplayMetadata> parseColorimetryInfo(
const WsiEdidData& edidData);
}

View File

@ -6,6 +6,8 @@
#include <vector>
#include <cstdint>
#include "wsi_edid.h"
namespace dxvk::wsi {
/**
@ -125,8 +127,6 @@ namespace dxvk::wsi {
*pHeight = rect.bottom - rect.top;
}
using WsiEdidData = std::vector<uint8_t>;
/**
* \brief Get the EDID of a monitor
*