@@ -2172,10 +2172,6 @@ static void info_done(void *data, struct wp_image_description_info_v1 *image_des
21722172 wd -> csp .hdr .max_fall = MPMIN (wd -> csp .hdr .max_fall , wd -> csp .hdr .max_luma );
21732173 }
21742174 wl -> preferred_csp = wd -> csp ;
2175- if (wd -> csp .hdr .max_luma > PL_COLOR_SDR_WHITE ) {
2176- MP_VERBOSE (wl , "Setting preferred transfer to PQ for HDR output.\n" );
2177- wl -> preferred_csp .transfer = PL_COLOR_TRC_PQ ;
2178- }
21792175 } else {
21802176 if (wl -> icc_size ) {
21812177 munmap (wl -> icc_file , wl -> icc_size );
@@ -3982,10 +3978,59 @@ bool vo_wayland_check_visible(struct vo *vo)
39823978 return render ;
39833979}
39843980
3985- struct pl_color_space vo_wayland_preferred_csp (struct vo * vo )
3981+ struct pl_color_space vo_wayland_preferred_csp (struct vo * vo , float source_max_luma )
39863982{
39873983 struct vo_wayland_state * wl = vo -> wl ;
3988- return wl -> preferred_csp ;
3984+ struct pl_color_space csp = wl -> preferred_csp ;
3985+ if (!pl_color_transfer_is_hdr (csp .transfer )) {
3986+ // For transfer functions for which pl_color_transfer_is_hdr returns false, mpv
3987+ // discards the HDR metadata and assumes a max_luma of PL_COLOR_SDR_WHITE.
3988+ // Similarly, mesa discards the HDR metadata for such transfer functions.
3989+ // Therefore, if there is any reason for us to preserve the HDR metadata, we need
3990+ // to switch to a transfer function for which pl_color_transfer_is_hdr returns
3991+ // true. PL_COLOR_TRC_PQ is the most widely supported transfer function of that
3992+ // kind. If VK_COLOR_SPACE_HDR10_ST2084_EXT is not available, then libplacebo will
3993+ // still try to fall back to another HDR transfer function so that mesa passes the
3994+ // metadata on to the compositor. (Therefore, using any HDR transfer function here
3995+ // would do since we cannot actually know which transfer function the compositor
3996+ // prefers.)
3997+
3998+ // The default assumption by all components in the pipeline is that the maximum
3999+ // luminance for non-HDR transfer functions is paper white. Therefore, we don't
4000+ // have to handle this case.
4001+ if (csp .hdr .max_luma != PL_COLOR_SDR_WHITE ) {
4002+ // Otherwise, if we are doing inverse tone mapping, which is indicated by
4003+ // source_max_luma == INFINITY, then libplacebo always needs to know the exact
4004+ // max_luma of the display since that is the target we want to hit.
4005+ if (source_max_luma == INFINITY )
4006+ csp .transfer = PL_COLOR_TRC_PQ ;
4007+ // Otherwise, if the max_luma of the source is brighter than paper white, then
4008+ // libplacebo will always perform tone mapping. To do this correctly, it will
4009+ // need to know the exact max_luma of the display.
4010+ if (source_max_luma > PL_COLOR_SDR_WHITE )
4011+ csp .transfer = PL_COLOR_TRC_PQ ;
4012+ // Otherwise, if max_luma of the display is less than paper white, there are
4013+ // two cases:
4014+ // 1. source_max_luma > csp.hdr.max_luma: In this case, we want libplacebo
4015+ // to tone map to the max_luma of the display.
4016+ // 2. source_max_luma <= csp.hdr.max_luma: In this case, we still need to
4017+ // tell the compositor that the max_luma of our images is
4018+ // < csp.hdr.max_luma since otherwise it will assume that the max_luma of
4019+ // or images is paper white and might do its own tone mapping down to
4020+ // csp.hdr.max_luma.
4021+ // So in both cases we need to pass the actual max_luma of the display through
4022+ // the pipeline.
4023+ if (csp .hdr .max_luma < PL_COLOR_SDR_WHITE )
4024+ csp .transfer = PL_COLOR_TRC_PQ ;
4025+
4026+ // NOTE: If source_max_luma > csp.hdr.max_luma, which seems to be missing from
4027+ // the conditions above, then either source_max_luma > PL_COLOR_SDR_WHITE, in
4028+ // which case we hit the second branch above, or
4029+ // csp.hdr.max_luma < source_max_luma <= PL_COLOR_WHITE in which case we hit
4030+ // the third branch above.
4031+ }
4032+ }
4033+ return csp ;
39894034}
39904035
39914036int vo_wayland_control (struct vo * vo , int * events , int request , void * arg )
0 commit comments