mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
backends/native: Handle gamma sizes independent of the KMS LUT
Allows for creating LUTs at some fixed size which maintains enough precision for concatenating or otherwise manipulating the LUT without having to care about the precision of the hardware. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2861>
This commit is contained in:
parent
4eb581ffc1
commit
abdd8c54f3
@ -218,6 +218,64 @@ meta_gamma_lut_copy (const MetaGammaLut *gamma)
|
||||
return meta_gamma_lut_new (gamma->size, gamma->red, gamma->green, gamma->blue);
|
||||
}
|
||||
|
||||
MetaGammaLut *
|
||||
meta_gamma_lut_copy_to_size (const MetaGammaLut *gamma,
|
||||
int target_size)
|
||||
{
|
||||
MetaGammaLut *out;
|
||||
|
||||
g_return_val_if_fail (gamma != NULL, NULL);
|
||||
|
||||
if (gamma->size == target_size)
|
||||
return meta_gamma_lut_copy (gamma);
|
||||
|
||||
out = meta_gamma_lut_new (target_size, NULL, NULL, NULL);
|
||||
|
||||
out->red = g_new0 (uint16_t, target_size);
|
||||
out->green = g_new0 (uint16_t, target_size);
|
||||
out->blue = g_new0 (uint16_t, target_size);
|
||||
|
||||
if (target_size >= gamma->size)
|
||||
{
|
||||
int i, j;
|
||||
int slots;
|
||||
|
||||
slots = target_size / gamma->size;
|
||||
for (i = 0; i < gamma->size; i++)
|
||||
{
|
||||
for (j = 0; j < slots; j++)
|
||||
{
|
||||
out->red[i * slots + j] = gamma->red[i];
|
||||
out->green[i * slots + j] = gamma->green[i];
|
||||
out->blue[i * slots + j] = gamma->blue[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (j = i * slots; j < target_size; j++)
|
||||
{
|
||||
out->red[j] = gamma->red[i - 1];
|
||||
out->green[j] = gamma->green[i - 1];
|
||||
out->blue[j] = gamma->blue[i - 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
int idx;
|
||||
|
||||
for (i = 0; i < target_size; i++)
|
||||
{
|
||||
idx = i * (gamma->size - 1) / (target_size - 1);
|
||||
|
||||
out->red[i] = gamma->red[idx];
|
||||
out->green[i] = gamma->green[idx];
|
||||
out->blue[i] = gamma->blue[idx];
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_gamma_lut_equal (const MetaGammaLut *gamma,
|
||||
const MetaGammaLut *other_gamma)
|
||||
|
@ -104,6 +104,9 @@ MetaGammaLut * meta_gamma_lut_new_sized (int size);
|
||||
META_EXPORT_TEST
|
||||
MetaGammaLut * meta_gamma_lut_copy (const MetaGammaLut *gamma);
|
||||
|
||||
MetaGammaLut * meta_gamma_lut_copy_to_size (const MetaGammaLut *gamma,
|
||||
int target_size);
|
||||
|
||||
META_EXPORT_TEST
|
||||
gboolean meta_gamma_lut_equal (const MetaGammaLut *gamma,
|
||||
const MetaGammaLut *other_gamma);
|
||||
|
@ -206,27 +206,13 @@ meta_crtc_kms_set_gamma_lut (MetaCrtc *crtc,
|
||||
const MetaGammaLut *lut)
|
||||
{
|
||||
MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc);
|
||||
MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
|
||||
MetaBackend *backend = meta_gpu_get_backend (meta_crtc_get_gpu (crtc));
|
||||
MetaMonitorManagerNative *monitor_manager_native =
|
||||
monitor_manager_from_crtc (crtc);
|
||||
ClutterActor *stage = meta_backend_get_stage (backend);
|
||||
const MetaKmsCrtcState *crtc_state;
|
||||
g_autofree char *gamma_ramp_string = NULL;
|
||||
MetaGammaLut *new_gamma;
|
||||
|
||||
crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
|
||||
|
||||
if (lut->size != crtc_state->gamma.size)
|
||||
{
|
||||
MetaKmsDevice *kms_device = meta_kms_crtc_get_device (kms_crtc);
|
||||
|
||||
g_warning ("Tried to set a different gamma LUT size on %u (%s)",
|
||||
meta_kms_crtc_get_id (kms_crtc),
|
||||
meta_kms_device_get_path (kms_device));
|
||||
return;
|
||||
}
|
||||
|
||||
gamma_ramp_string = generate_gamma_ramp_string (lut);
|
||||
meta_topic (META_DEBUG_COLOR,
|
||||
"Setting CRTC (%" G_GUINT64_FORMAT ") gamma to %s",
|
||||
|
@ -401,12 +401,13 @@ meta_kms_update_set_crtc_gamma (MetaKmsUpdate *update,
|
||||
{
|
||||
MetaKmsCrtcColorUpdate *color_update;
|
||||
MetaGammaLut *gamma_update = NULL;
|
||||
const MetaKmsCrtcState *crtc_state = meta_kms_crtc_get_current_state (crtc);
|
||||
|
||||
g_assert (!meta_kms_update_is_locked (update));
|
||||
g_assert (meta_kms_crtc_get_device (crtc) == update->device);
|
||||
|
||||
if (gamma)
|
||||
gamma_update = meta_gamma_lut_copy (gamma);
|
||||
gamma_update = meta_gamma_lut_copy_to_size (gamma, crtc_state->gamma.size);
|
||||
|
||||
color_update = ensure_color_update (update, crtc);
|
||||
color_update->gamma.state = gamma_update;
|
||||
|
Loading…
Reference in New Issue
Block a user