diff --git a/src/util/u_gralloc/u_gralloc_imapper4_api.cpp b/src/util/u_gralloc/u_gralloc_imapper4_api.cpp index dc1980f6a99..986088cb4db 100644 --- a/src/util/u_gralloc/u_gralloc_imapper4_api.cpp +++ b/src/util/u_gralloc/u_gralloc_imapper4_api.cpp @@ -209,6 +209,34 @@ mapper4_get_buffer_basic_info(struct u_gralloc *gralloc, return 0; } +static __inline__ Dataspace +_legacy_dataspace_to_v0(Dataspace ds) +{ + switch((android_dataspace_t)ds) { + case HAL_DATASPACE_SRGB: + ds = Dataspace::SRGB; + break; + case HAL_DATASPACE_BT709: + ds = Dataspace::BT709; + break; + case HAL_DATASPACE_SRGB_LINEAR: + ds = Dataspace::SRGB_LINEAR; + break; + case HAL_DATASPACE_BT601_525: + ds = Dataspace::BT601_525; + break; + case HAL_DATASPACE_BT601_625: + ds = Dataspace::BT601_625; + break; + case HAL_DATASPACE_JFIF: + ds = Dataspace::JFIF; + break; + default: + break; + } + return ds; +} + static int mapper4_get_buffer_color_info(struct u_gralloc *gralloc, struct u_gralloc_buffer_handle *hnd, @@ -262,6 +290,14 @@ mapper4_get_buffer_color_info(struct u_gralloc *gralloc, if (status != android::OK) return -EINVAL; + // The dataspace value passed down might be a legacy value, + // which does not comply with the pattern: + // (Standard << 16) |(Transfer << 22) | (Range << 27) + // Just convert the legacy value to v0 value, + // according to standard “hardware/interfaces/graphics/common/1.0/types.hal”. + if ((int)dataspace & 0xffff) + dataspace = _legacy_dataspace_to_v0(dataspace); + Dataspace standard = (Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK); switch (standard) {