Message ID | 20181212010551.6337-2-matthew.d.roper@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add gamma/degamma LUT validation helpers | expand |
Hi Matt, On Tue, Dec 11, 2018 at 05:05:50PM -0800, Matt Roper wrote: > Some hardware may place additional restrictions on the gamma/degamma > curves described by our LUT properties. E.g., that a gamma curve never > decreases or that the red/green/blue channels of a LUT's entries must be > equal. Let's add a couple helpers that drivers can use to test that a > userspace-provided LUT doesn't violate hardware requirements. > > Cc: Uma Shankar <uma.shankar@intel.com> > Cc: Swati Sharma <swati2.sharma@intel.com> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com> > --- > drivers/gpu/drm/drm_color_mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++ > include/drm/drm_color_mgmt.h | 3 +++ > 2 files changed, 56 insertions(+) > > diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c > index 07dcf47daafe..41e617e34c10 100644 > --- a/drivers/gpu/drm/drm_color_mgmt.c > +++ b/drivers/gpu/drm/drm_color_mgmt.c > @@ -462,3 +462,56 @@ int drm_plane_create_color_properties(struct drm_plane *plane, > return 0; > } > EXPORT_SYMBOL(drm_plane_create_color_properties); > + > +/** > + * drm_color_lut_has_equal_channels - check LUT for equal r/g/b values > + * @lut: property blob containing LUT to check > + * > + * Helper to check whether the entries of a LUT all have equal values for the > + * red, green, and blue channels. Some hardware can only be programmed > + * with a single value per LUT entry, which is assumed to apply to all > + * three color components. > + */ > +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut) > +{ > + struct drm_color_lut *entry; > + int i; > + > + if (!lut) > + return true; > + > + entry = lut->data; > + for (i = 0; i < drm_color_lut_size(lut); i++) > + if (entry[i].red != entry[i].blue || > + entry[i].red != entry[i].green) > + return false; > + > + return true; > +} > +EXPORT_SYMBOL(drm_color_lut_has_equal_channels); We've got this open-coded for some of our HW, so thanks for the helper :-) > + > +/** > + * drm_color_lut_is_increasing - check that LUT is always flat/increasing > + * @lut: LUT to check > + * > + * Helper to check whether the entries of a LUT are always flat or increasing > + * (never decreasing). > + */ > +bool drm_color_lut_is_increasing(struct drm_property_blob *lut) > +{ > + struct drm_color_lut *entry; > + int i; > + > + if (!lut) > + return true; > + > + entry = lut->data; > + for (i = 1; i < drm_color_lut_size(lut); i++) > + if (entry[i].red < entry[i-1].red || > + entry[i].green < entry[i-1].green || > + entry[i].blue < entry[i-1].blue) > + return false; nit: I think checkpatch likes spaces around operators: [i - 1] Another thought: in the worst case with a valid LUT with HW that needs both checks, you can end up iterating the whole LUT twice - once for increasing, and once for equal channels. Maybe this could be a single function with a mask of constraints to check: drm_color_lut_check(lut, DRM_COLOR_LUT_EQUAL_CHANNELS | DRM_COLOR_LUT_INCREASING); Not sure if it would turn out messy with the different loop bounds. Either way, for mali-dp it makes no difference, and probably LUTs aren't changing all the time so: Reviewed-by: Brian Starkey <brian.starkey@arm.com> > + > + return true; > +} > +EXPORT_SYMBOL(drm_color_lut_is_increasing); > diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h > index 90ef9996d9a4..6c38f5477e29 100644 > --- a/include/drm/drm_color_mgmt.h > +++ b/include/drm/drm_color_mgmt.h > @@ -69,4 +69,7 @@ int drm_plane_create_color_properties(struct drm_plane *plane, > u32 supported_ranges, > enum drm_color_encoding default_encoding, > enum drm_color_range default_range); > + > +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut); > +bool drm_color_lut_is_increasing(struct drm_property_blob *lut); > #endif > -- > 2.14.4 > > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 07dcf47daafe..41e617e34c10 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -462,3 +462,56 @@ int drm_plane_create_color_properties(struct drm_plane *plane, return 0; } EXPORT_SYMBOL(drm_plane_create_color_properties); + +/** + * drm_color_lut_has_equal_channels - check LUT for equal r/g/b values + * @lut: property blob containing LUT to check + * + * Helper to check whether the entries of a LUT all have equal values for the + * red, green, and blue channels. Some hardware can only be programmed + * with a single value per LUT entry, which is assumed to apply to all + * three color components. + */ +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut) +{ + struct drm_color_lut *entry; + int i; + + if (!lut) + return true; + + entry = lut->data; + for (i = 0; i < drm_color_lut_size(lut); i++) + if (entry[i].red != entry[i].blue || + entry[i].red != entry[i].green) + return false; + + return true; +} +EXPORT_SYMBOL(drm_color_lut_has_equal_channels); + +/** + * drm_color_lut_is_increasing - check that LUT is always flat/increasing + * @lut: LUT to check + * + * Helper to check whether the entries of a LUT are always flat or increasing + * (never decreasing). + */ +bool drm_color_lut_is_increasing(struct drm_property_blob *lut) +{ + struct drm_color_lut *entry; + int i; + + if (!lut) + return true; + + entry = lut->data; + for (i = 1; i < drm_color_lut_size(lut); i++) + if (entry[i].red < entry[i-1].red || + entry[i].green < entry[i-1].green || + entry[i].blue < entry[i-1].blue) + return false; + + return true; +} +EXPORT_SYMBOL(drm_color_lut_is_increasing); diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h index 90ef9996d9a4..6c38f5477e29 100644 --- a/include/drm/drm_color_mgmt.h +++ b/include/drm/drm_color_mgmt.h @@ -69,4 +69,7 @@ int drm_plane_create_color_properties(struct drm_plane *plane, u32 supported_ranges, enum drm_color_encoding default_encoding, enum drm_color_range default_range); + +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut); +bool drm_color_lut_is_increasing(struct drm_property_blob *lut); #endif
Some hardware may place additional restrictions on the gamma/degamma curves described by our LUT properties. E.g., that a gamma curve never decreases or that the red/green/blue channels of a LUT's entries must be equal. Let's add a couple helpers that drivers can use to test that a userspace-provided LUT doesn't violate hardware requirements. Cc: Uma Shankar <uma.shankar@intel.com> Cc: Swati Sharma <swati2.sharma@intel.com> Signed-off-by: Matt Roper <matthew.d.roper@intel.com> --- drivers/gpu/drm/drm_color_mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 3 +++ 2 files changed, 56 insertions(+)