|
88 | 88 | * drm_mode_crtc_set_gamma_size(). Drivers which support both should use |
89 | 89 | * drm_atomic_helper_legacy_gamma_set() to alias the legacy gamma ramp with the |
90 | 90 | * "GAMMA_LUT" property above. |
| 91 | + * |
| 92 | + * Support for different non RGB color encodings is controlled through |
| 93 | + * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They |
| 94 | + * are set up by calling drm_plane_create_color_properties(). |
| 95 | + * |
| 96 | + * "COLOR_ENCODING" |
| 97 | + * Optional plane enum property to support different non RGB |
| 98 | + * color encodings. The driver can provide a subset of standard |
| 99 | + * enum values supported by the DRM plane. |
| 100 | + * |
| 101 | + * "COLOR_RANGE" |
| 102 | + * Optional plane enum property to support different non RGB |
| 103 | + * color parameter ranges. The driver can provide a subset of |
| 104 | + * standard enum values supported by the DRM plane. |
91 | 105 | */ |
92 | 106 |
|
93 | 107 | /** |
@@ -339,3 +353,92 @@ int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
339 | 353 | drm_modeset_unlock(&crtc->mutex); |
340 | 354 | return ret; |
341 | 355 | } |
| 356 | + |
| 357 | +static const char * const color_encoding_name[] = { |
| 358 | + [DRM_COLOR_YCBCR_BT601] = "ITU-R BT.601 YCbCr", |
| 359 | + [DRM_COLOR_YCBCR_BT709] = "ITU-R BT.709 YCbCr", |
| 360 | + [DRM_COLOR_YCBCR_BT2020] = "ITU-R BT.2020 YCbCr", |
| 361 | +}; |
| 362 | + |
| 363 | +static const char * const color_range_name[] = { |
| 364 | + [DRM_COLOR_YCBCR_FULL_RANGE] = "YCbCr full range", |
| 365 | + [DRM_COLOR_YCBCR_LIMITED_RANGE] = "YCbCr limited range", |
| 366 | +}; |
| 367 | + |
| 368 | +/** |
| 369 | + * drm_plane_create_color_properties - color encoding related plane properties |
| 370 | + * @plane: plane object |
| 371 | + * @supported_encodings: bitfield indicating supported color encodings |
| 372 | + * @supported_ranges: bitfileld indicating supported color ranges |
| 373 | + * @default_encoding: default color encoding |
| 374 | + * @default_range: default color range |
| 375 | + * |
| 376 | + * Create and attach plane specific COLOR_ENCODING and COLOR_RANGE |
| 377 | + * properties to @plane. The supported encodings and ranges should |
| 378 | + * be provided in supported_encodings and supported_ranges bitmasks. |
| 379 | + * Each bit set in the bitmask indicates that its number as enum |
| 380 | + * value is supported. |
| 381 | + */ |
| 382 | +int drm_plane_create_color_properties(struct drm_plane *plane, |
| 383 | + u32 supported_encodings, |
| 384 | + u32 supported_ranges, |
| 385 | + enum drm_color_encoding default_encoding, |
| 386 | + enum drm_color_range default_range) |
| 387 | +{ |
| 388 | + struct drm_device *dev = plane->dev; |
| 389 | + struct drm_property *prop; |
| 390 | + struct drm_prop_enum_list enum_list[max(DRM_COLOR_ENCODING_MAX, |
| 391 | + DRM_COLOR_RANGE_MAX)]; |
| 392 | + int i, len; |
| 393 | + |
| 394 | + if (WARN_ON(supported_encodings == 0 || |
| 395 | + (supported_encodings & -BIT(DRM_COLOR_ENCODING_MAX)) != 0 || |
| 396 | + (supported_encodings & BIT(default_encoding)) == 0)) |
| 397 | + return -EINVAL; |
| 398 | + |
| 399 | + if (WARN_ON(supported_ranges == 0 || |
| 400 | + (supported_ranges & -BIT(DRM_COLOR_RANGE_MAX)) != 0 || |
| 401 | + (supported_ranges & BIT(default_range)) == 0)) |
| 402 | + return -EINVAL; |
| 403 | + |
| 404 | + len = 0; |
| 405 | + for (i = 0; i < DRM_COLOR_ENCODING_MAX; i++) { |
| 406 | + if ((supported_encodings & BIT(i)) == 0) |
| 407 | + continue; |
| 408 | + |
| 409 | + enum_list[len].type = i; |
| 410 | + enum_list[len].name = color_encoding_name[i]; |
| 411 | + len++; |
| 412 | + } |
| 413 | + |
| 414 | + prop = drm_property_create_enum(dev, 0, "COLOR_ENCODING", |
| 415 | + enum_list, len); |
| 416 | + if (!prop) |
| 417 | + return -ENOMEM; |
| 418 | + plane->color_encoding_property = prop; |
| 419 | + drm_object_attach_property(&plane->base, prop, default_encoding); |
| 420 | + if (plane->state) |
| 421 | + plane->state->color_encoding = default_encoding; |
| 422 | + |
| 423 | + len = 0; |
| 424 | + for (i = 0; i < DRM_COLOR_RANGE_MAX; i++) { |
| 425 | + if ((supported_ranges & BIT(i)) == 0) |
| 426 | + continue; |
| 427 | + |
| 428 | + enum_list[len].type = i; |
| 429 | + enum_list[len].name = color_range_name[i]; |
| 430 | + len++; |
| 431 | + } |
| 432 | + |
| 433 | + prop = drm_property_create_enum(dev, 0, "COLOR_RANGE", |
| 434 | + enum_list, len); |
| 435 | + if (!prop) |
| 436 | + return -ENOMEM; |
| 437 | + plane->color_range_property = prop; |
| 438 | + drm_object_attach_property(&plane->base, prop, default_range); |
| 439 | + if (plane->state) |
| 440 | + plane->state->color_range = default_range; |
| 441 | + |
| 442 | + return 0; |
| 443 | +} |
| 444 | +EXPORT_SYMBOL(drm_plane_create_color_properties); |
0 commit comments