1 /* 2 * Copyright (C) 2016 Samsung Electronics Co.Ltd 3 * Authors: 4 * Marek Szyprowski <[email protected]> 5 * 6 * DRM core plane blending related functions 7 * 8 * Permission to use, copy, modify, distribute, and sell this software and its 9 * documentation for any purpose is hereby granted without fee, provided that 10 * the above copyright notice appear in all copies and that both that copyright 11 * notice and this permission notice appear in supporting documentation, and 12 * that the name of the copyright holders not be used in advertising or 13 * publicity pertaining to distribution of the software without specific, 14 * written prior permission. The copyright holders make no representations 15 * about the suitability of this software for any purpose. It is provided "as 16 * is" without express or implied warranty. 17 * 18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 24 * OF THIS SOFTWARE. 25 */ 26 27 #include <linux/export.h> 28 #include <linux/slab.h> 29 #include <linux/sort.h> 30 31 #include <drm/drm_atomic.h> 32 #include <drm/drm_blend.h> 33 #include <drm/drm_device.h> 34 #include <drm/drm_print.h> 35 36 #include "drm_crtc_internal.h" 37 38 /** 39 * DOC: overview 40 * 41 * The basic plane composition model supported by standard plane properties only 42 * has a source rectangle (in logical pixels within the &drm_framebuffer), with 43 * sub-pixel accuracy, which is scaled up to a pixel-aligned destination 44 * rectangle in the visible area of a &drm_crtc. The visible area of a CRTC is 45 * defined by the horizontal and vertical visible pixels (stored in @hdisplay 46 * and @vdisplay) of the requested mode (stored in &drm_crtc_state.mode). These 47 * two rectangles are both stored in the &drm_plane_state. 48 * 49 * For the atomic ioctl the following standard (atomic) properties on the plane object 50 * encode the basic plane composition model: 51 * 52 * SRC_X: 53 * X coordinate offset for the source rectangle within the 54 * &drm_framebuffer, in 16.16 fixed point. Must be positive. 55 * SRC_Y: 56 * Y coordinate offset for the source rectangle within the 57 * &drm_framebuffer, in 16.16 fixed point. Must be positive. 58 * SRC_W: 59 * Width for the source rectangle within the &drm_framebuffer, in 16.16 60 * fixed point. SRC_X plus SRC_W must be within the width of the source 61 * framebuffer. Must be positive. 62 * SRC_H: 63 * Height for the source rectangle within the &drm_framebuffer, in 16.16 64 * fixed point. SRC_Y plus SRC_H must be within the height of the source 65 * framebuffer. Must be positive. 66 * CRTC_X: 67 * X coordinate offset for the destination rectangle. Can be negative. 68 * CRTC_Y: 69 * Y coordinate offset for the destination rectangle. Can be negative. 70 * CRTC_W: 71 * Width for the destination rectangle. CRTC_X plus CRTC_W can extend past 72 * the currently visible horizontal area of the &drm_crtc. 73 * CRTC_H: 74 * Height for the destination rectangle. CRTC_Y plus CRTC_H can extend past 75 * the currently visible vertical area of the &drm_crtc. 76 * FB_ID: 77 * Mode object ID of the &drm_framebuffer this plane should scan out. 78 * CRTC_ID: 79 * Mode object ID of the &drm_crtc this plane should be connected to. 80 * 81 * Note that the source rectangle must fully lie within the bounds of the 82 * &drm_framebuffer. The destination rectangle can lie outside of the visible 83 * area of the current mode of the CRTC. It must be appropriately clipped by the 84 * driver, which can be done by calling drm_plane_helper_check_update(). Drivers 85 * are also allowed to round the subpixel sampling positions appropriately, but 86 * only to the next full pixel. No pixel outside of the source rectangle may 87 * ever be sampled, which is important when applying more sophisticated 88 * filtering than just a bilinear one when scaling. The filtering mode when 89 * scaling is unspecified. 90 * 91 * On top of this basic transformation additional properties can be exposed by 92 * the driver: 93 * 94 * alpha: 95 * Alpha is setup with drm_plane_create_alpha_property(). It controls the 96 * plane-wide opacity, from transparent (0) to opaque (0xffff). It can be 97 * combined with pixel alpha. 98 * The pixel values in the framebuffers are expected to not be 99 * pre-multiplied by the global alpha associated to the plane. 100 * 101 * rotation: 102 * Rotation is set up with drm_plane_create_rotation_property(). It adds a 103 * rotation and reflection step between the source and destination rectangles. 104 * Without this property the rectangle is only scaled, but not rotated or 105 * reflected. 106 * 107 * Possbile values: 108 * 109 * "rotate-<degrees>": 110 * Signals that a drm plane is rotated <degrees> degrees in counter 111 * clockwise direction. 112 * 113 * "reflect-<axis>": 114 * Signals that the contents of a drm plane is reflected along the 115 * <axis> axis, in the same way as mirroring. 116 * 117 * reflect-x:: 118 * 119 * |o | | o| 120 * | | -> | | 121 * | v| |v | 122 * 123 * reflect-y:: 124 * 125 * |o | | ^| 126 * | | -> | | 127 * | v| |o | 128 * 129 * zpos: 130 * Z position is set up with drm_plane_create_zpos_immutable_property() and 131 * drm_plane_create_zpos_property(). It controls the visibility of overlapping 132 * planes. Without this property the primary plane is always below the cursor 133 * plane, and ordering between all other planes is undefined. The positive 134 * Z axis points towards the user, i.e. planes with lower Z position values 135 * are underneath planes with higher Z position values. Two planes with the 136 * same Z position value have undefined ordering. Note that the Z position 137 * value can also be immutable, to inform userspace about the hard-coded 138 * stacking of planes, see drm_plane_create_zpos_immutable_property(). If 139 * any plane has a zpos property (either mutable or immutable), then all 140 * planes shall have a zpos property. 141 * 142 * pixel blend mode: 143 * Pixel blend mode is set up with drm_plane_create_blend_mode_property(). 144 * It adds a blend mode for alpha blending equation selection, describing 145 * how the pixels from the current plane are composited with the 146 * background. 147 * 148 * Three alpha blending equations are defined: 149 * 150 * "None": 151 * Blend formula that ignores the pixel alpha:: 152 * 153 * out.rgb = plane_alpha * fg.rgb + 154 * (1 - plane_alpha) * bg.rgb 155 * 156 * "Pre-multiplied": 157 * Blend formula that assumes the pixel color values 158 * have been already pre-multiplied with the alpha 159 * channel values:: 160 * 161 * out.rgb = plane_alpha * fg.rgb + 162 * (1 - (plane_alpha * fg.alpha)) * bg.rgb 163 * 164 * "Coverage": 165 * Blend formula that assumes the pixel color values have not 166 * been pre-multiplied and will do so when blending them to the 167 * background color values:: 168 * 169 * out.rgb = plane_alpha * fg.alpha * fg.rgb + 170 * (1 - (plane_alpha * fg.alpha)) * bg.rgb 171 * 172 * Using the following symbols: 173 * 174 * "fg.rgb": 175 * Each of the RGB component values from the plane's pixel 176 * "fg.alpha": 177 * Alpha component value from the plane's pixel. If the plane's 178 * pixel format has no alpha component, then this is assumed to be 179 * 1.0. In these cases, this property has no effect, as all three 180 * equations become equivalent. 181 * "bg.rgb": 182 * Each of the RGB component values from the background 183 * "plane_alpha": 184 * Plane alpha value set by the plane "alpha" property. If the 185 * plane does not expose the "alpha" property, then this is 186 * assumed to be 1.0 187 * 188 * pixel_source: 189 * pixel_source is set up with drm_plane_create_pixel_source_property(). 190 * It is used to toggle the active source of pixel data for the plane. 191 * The plane will only display data from the set pixel_source -- any 192 * data from other sources will be ignored. 193 * 194 * For non-framebuffer sources, if pixel_source is set to a non-framebuffer 195 * and non-NONE source, and the corresponding source property is NULL, then 196 * the atomic commit should return an error. 197 * 198 * Possible values: 199 * 200 * "NONE": 201 * No active pixel source. 202 * Committing with a NONE pixel source will disable the plane. 203 * 204 * "FB": 205 * Framebuffer source set by the "FB_ID" property. 206 * 207 * Note that all the property extensions described here apply either to the 208 * plane or the CRTC (e.g. for the background color, which currently is not 209 * exposed and assumed to be black). 210 * 211 * SCALING_FILTER: 212 * Indicates scaling filter to be used for plane scaler 213 * 214 * The value of this property can be one of the following: 215 * 216 * Default: 217 * Driver's default scaling filter 218 * Nearest Neighbor: 219 * Nearest Neighbor scaling filter 220 * 221 * Drivers can set up this property for a plane by calling 222 * drm_plane_create_scaling_filter_property 223 */ 224 225 /** 226 * drm_plane_create_alpha_property - create a new alpha property 227 * @plane: drm plane 228 * 229 * This function creates a generic, mutable, alpha property and enables support 230 * for it in the DRM core. It is attached to @plane. 231 * 232 * The alpha property will be allowed to be within the bounds of 0 233 * (transparent) to 0xffff (opaque). 234 * 235 * Returns: 236 * 0 on success, negative error code on failure. 237 */ 238 int drm_plane_create_alpha_property(struct drm_plane *plane) 239 { 240 struct drm_property *prop; 241 242 prop = drm_property_create_range(plane->dev, 0, "alpha", 243 0, DRM_BLEND_ALPHA_OPAQUE); 244 if (!prop) 245 return -ENOMEM; 246 247 drm_object_attach_property(&plane->base, prop, DRM_BLEND_ALPHA_OPAQUE); 248 plane->alpha_property = prop; 249 250 if (plane->state) 251 plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE; 252 253 return 0; 254 } 255 EXPORT_SYMBOL(drm_plane_create_alpha_property); 256 257 /** 258 * drm_plane_create_rotation_property - create a new rotation property 259 * @plane: drm plane 260 * @rotation: initial value of the rotation property 261 * @supported_rotations: bitmask of supported rotations and reflections 262 * 263 * This creates a new property with the selected support for transformations. 264 * 265 * Since a rotation by 180° degress is the same as reflecting both along the x 266 * and the y axis the rotation property is somewhat redundant. Drivers can use 267 * drm_rotation_simplify() to normalize values of this property. 268 * 269 * The property exposed to userspace is a bitmask property (see 270 * drm_property_create_bitmask()) called "rotation" and has the following 271 * bitmask enumaration values: 272 * 273 * DRM_MODE_ROTATE_0: 274 * "rotate-0" 275 * DRM_MODE_ROTATE_90: 276 * "rotate-90" 277 * DRM_MODE_ROTATE_180: 278 * "rotate-180" 279 * DRM_MODE_ROTATE_270: 280 * "rotate-270" 281 * DRM_MODE_REFLECT_X: 282 * "reflect-x" 283 * DRM_MODE_REFLECT_Y: 284 * "reflect-y" 285 * 286 * Rotation is the specified amount in degrees in counter clockwise direction, 287 * the X and Y axis are within the source rectangle, i.e. the X/Y axis before 288 * rotation. After reflection, the rotation is applied to the image sampled from 289 * the source rectangle, before scaling it to fit the destination rectangle. 290 */ 291 int drm_plane_create_rotation_property(struct drm_plane *plane, 292 unsigned int rotation, 293 unsigned int supported_rotations) 294 { 295 static const struct drm_prop_enum_list props[] = { 296 { __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" }, 297 { __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" }, 298 { __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" }, 299 { __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" }, 300 { __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" }, 301 { __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" }, 302 }; 303 struct drm_property *prop; 304 305 WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0); 306 WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK)); 307 WARN_ON(rotation & ~supported_rotations); 308 309 prop = drm_property_create_bitmask(plane->dev, 0, "rotation", 310 props, ARRAY_SIZE(props), 311 supported_rotations); 312 if (!prop) 313 return -ENOMEM; 314 315 drm_object_attach_property(&plane->base, prop, rotation); 316 317 if (plane->state) 318 plane->state->rotation = rotation; 319 320 plane->rotation_property = prop; 321 322 return 0; 323 } 324 EXPORT_SYMBOL(drm_plane_create_rotation_property); 325 326 /** 327 * drm_rotation_simplify() - Try to simplify the rotation 328 * @rotation: Rotation to be simplified 329 * @supported_rotations: Supported rotations 330 * 331 * Attempt to simplify the rotation to a form that is supported. 332 * Eg. if the hardware supports everything except DRM_MODE_REFLECT_X 333 * one could call this function like this: 334 * 335 * drm_rotation_simplify(rotation, DRM_MODE_ROTATE_0 | 336 * DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 | 337 * DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_Y); 338 * 339 * to eliminate the DRM_MODE_REFLECT_X flag. Depending on what kind of 340 * transforms the hardware supports, this function may not 341 * be able to produce a supported transform, so the caller should 342 * check the result afterwards. 343 */ 344 unsigned int drm_rotation_simplify(unsigned int rotation, 345 unsigned int supported_rotations) 346 { 347 if (rotation & ~supported_rotations) { 348 rotation ^= DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y; 349 rotation = (rotation & DRM_MODE_REFLECT_MASK) | 350 BIT((ffs(rotation & DRM_MODE_ROTATE_MASK) + 1) 351 % 4); 352 } 353 354 return rotation; 355 } 356 EXPORT_SYMBOL(drm_rotation_simplify); 357 358 /** 359 * drm_plane_create_zpos_property - create mutable zpos property 360 * @plane: drm plane 361 * @zpos: initial value of zpos property 362 * @min: minimal possible value of zpos property 363 * @max: maximal possible value of zpos property 364 * 365 * This function initializes generic mutable zpos property and enables support 366 * for it in drm core. Drivers can then attach this property to planes to enable 367 * support for configurable planes arrangement during blending operation. 368 * Drivers that attach a mutable zpos property to any plane should call the 369 * drm_atomic_normalize_zpos() helper during their implementation of 370 * &drm_mode_config_funcs.atomic_check(), which will update the normalized zpos 371 * values and store them in &drm_plane_state.normalized_zpos. Usually min 372 * should be set to 0 and max to maximal number of planes for given crtc - 1. 373 * 374 * If zpos of some planes cannot be changed (like fixed background or 375 * cursor/topmost planes), drivers shall adjust the min/max values and assign 376 * those planes immutable zpos properties with lower or higher values (for more 377 * information, see drm_plane_create_zpos_immutable_property() function). In such 378 * case drivers shall also assign proper initial zpos values for all planes in 379 * its plane_reset() callback, so the planes will be always sorted properly. 380 * 381 * See also drm_atomic_normalize_zpos(). 382 * 383 * The property exposed to userspace is called "zpos". 384 * 385 * Returns: 386 * Zero on success, negative errno on failure. 387 */ 388 int drm_plane_create_zpos_property(struct drm_plane *plane, 389 unsigned int zpos, 390 unsigned int min, unsigned int max) 391 { 392 struct drm_property *prop; 393 394 prop = drm_property_create_range(plane->dev, 0, "zpos", min, max); 395 if (!prop) 396 return -ENOMEM; 397 398 drm_object_attach_property(&plane->base, prop, zpos); 399 400 plane->zpos_property = prop; 401 402 if (plane->state) { 403 plane->state->zpos = zpos; 404 plane->state->normalized_zpos = zpos; 405 } 406 407 return 0; 408 } 409 EXPORT_SYMBOL(drm_plane_create_zpos_property); 410 411 /** 412 * drm_plane_create_zpos_immutable_property - create immuttable zpos property 413 * @plane: drm plane 414 * @zpos: value of zpos property 415 * 416 * This function initializes generic immutable zpos property and enables 417 * support for it in drm core. Using this property driver lets userspace 418 * to get the arrangement of the planes for blending operation and notifies 419 * it that the hardware (or driver) doesn't support changing of the planes' 420 * order. For mutable zpos see drm_plane_create_zpos_property(). 421 * 422 * The property exposed to userspace is called "zpos". 423 * 424 * Returns: 425 * Zero on success, negative errno on failure. 426 */ 427 int drm_plane_create_zpos_immutable_property(struct drm_plane *plane, 428 unsigned int zpos) 429 { 430 struct drm_property *prop; 431 432 prop = drm_property_create_range(plane->dev, DRM_MODE_PROP_IMMUTABLE, 433 "zpos", zpos, zpos); 434 if (!prop) 435 return -ENOMEM; 436 437 drm_object_attach_property(&plane->base, prop, zpos); 438 439 plane->zpos_property = prop; 440 441 if (plane->state) { 442 plane->state->zpos = zpos; 443 plane->state->normalized_zpos = zpos; 444 } 445 446 return 0; 447 } 448 EXPORT_SYMBOL(drm_plane_create_zpos_immutable_property); 449 450 static int drm_atomic_state_zpos_cmp(const void *a, const void *b) 451 { 452 const struct drm_plane_state *sa = *(struct drm_plane_state **)a; 453 const struct drm_plane_state *sb = *(struct drm_plane_state **)b; 454 455 if (sa->zpos != sb->zpos) 456 return sa->zpos - sb->zpos; 457 else 458 return sa->plane->base.id - sb->plane->base.id; 459 } 460 461 static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc, 462 struct drm_crtc_state *crtc_state) 463 { 464 struct drm_atomic_state *state = crtc_state->state; 465 struct drm_device *dev = crtc->dev; 466 int total_planes = dev->mode_config.num_total_plane; 467 struct drm_plane_state **states; 468 struct drm_plane *plane; 469 int i, n = 0; 470 int ret = 0; 471 472 drm_dbg_atomic(dev, "[CRTC:%d:%s] calculating normalized zpos values\n", 473 crtc->base.id, crtc->name); 474 475 states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL); 476 if (!states) 477 return -ENOMEM; 478 479 /* 480 * Normalization process might create new states for planes which 481 * normalized_zpos has to be recalculated. 482 */ 483 drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) { 484 struct drm_plane_state *plane_state = 485 drm_atomic_get_plane_state(state, plane); 486 if (IS_ERR(plane_state)) { 487 ret = PTR_ERR(plane_state); 488 goto done; 489 } 490 states[n++] = plane_state; 491 drm_dbg_atomic(dev, "[PLANE:%d:%s] processing zpos value %d\n", 492 plane->base.id, plane->name, plane_state->zpos); 493 } 494 495 sort(states, n, sizeof(*states), drm_atomic_state_zpos_cmp, NULL); 496 497 for (i = 0; i < n; i++) { 498 plane = states[i]->plane; 499 500 states[i]->normalized_zpos = i; 501 drm_dbg_atomic(dev, "[PLANE:%d:%s] normalized zpos value %d\n", 502 plane->base.id, plane->name, i); 503 } 504 crtc_state->zpos_changed = true; 505 506 done: 507 kfree(states); 508 return ret; 509 } 510 511 /** 512 * drm_atomic_normalize_zpos - calculate normalized zpos values for all crtcs 513 * @dev: DRM device 514 * @state: atomic state of DRM device 515 * 516 * This function calculates normalized zpos value for all modified planes in 517 * the provided atomic state of DRM device. 518 * 519 * For every CRTC this function checks new states of all planes assigned to 520 * it and calculates normalized zpos value for these planes. Planes are compared 521 * first by their zpos values, then by plane id (if zpos is equal). The plane 522 * with lowest zpos value is at the bottom. The &drm_plane_state.normalized_zpos 523 * is then filled with unique values from 0 to number of active planes in crtc 524 * minus one. 525 * 526 * RETURNS 527 * Zero for success or -errno 528 */ 529 int drm_atomic_normalize_zpos(struct drm_device *dev, 530 struct drm_atomic_state *state) 531 { 532 struct drm_crtc *crtc; 533 struct drm_crtc_state *old_crtc_state, *new_crtc_state; 534 struct drm_plane *plane; 535 struct drm_plane_state *old_plane_state, *new_plane_state; 536 int i, ret = 0; 537 538 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) { 539 crtc = new_plane_state->crtc; 540 if (!crtc) 541 continue; 542 if (old_plane_state->zpos != new_plane_state->zpos) { 543 new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc); 544 new_crtc_state->zpos_changed = true; 545 } 546 } 547 548 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 549 if (old_crtc_state->plane_mask != new_crtc_state->plane_mask || 550 new_crtc_state->zpos_changed) { 551 ret = drm_atomic_helper_crtc_normalize_zpos(crtc, 552 new_crtc_state); 553 if (ret) 554 return ret; 555 } 556 } 557 return 0; 558 } 559 EXPORT_SYMBOL(drm_atomic_normalize_zpos); 560 561 /** 562 * drm_plane_create_blend_mode_property - create a new blend mode property 563 * @plane: drm plane 564 * @supported_modes: bitmask of supported modes, must include 565 * BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is 566 * that alpha is premultiplied, and old userspace can break if 567 * the property defaults to anything else. 568 * 569 * This creates a new property describing the blend mode. 570 * 571 * The property exposed to userspace is an enumeration property (see 572 * drm_property_create_enum()) called "pixel blend mode" and has the 573 * following enumeration values: 574 * 575 * "None": 576 * Blend formula that ignores the pixel alpha. 577 * 578 * "Pre-multiplied": 579 * Blend formula that assumes the pixel color values have been already 580 * pre-multiplied with the alpha channel values. 581 * 582 * "Coverage": 583 * Blend formula that assumes the pixel color values have not been 584 * pre-multiplied and will do so when blending them to the background color 585 * values. 586 * 587 * RETURNS: 588 * Zero for success or -errno 589 */ 590 int drm_plane_create_blend_mode_property(struct drm_plane *plane, 591 unsigned int supported_modes) 592 { 593 struct drm_device *dev = plane->dev; 594 struct drm_property *prop; 595 static const struct drm_prop_enum_list props[] = { 596 { DRM_MODE_BLEND_PIXEL_NONE, "None" }, 597 { DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" }, 598 { DRM_MODE_BLEND_COVERAGE, "Coverage" }, 599 }; 600 unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) | 601 BIT(DRM_MODE_BLEND_PREMULTI) | 602 BIT(DRM_MODE_BLEND_COVERAGE); 603 int i; 604 605 if (WARN_ON((supported_modes & ~valid_mode_mask) || 606 ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0))) 607 return -EINVAL; 608 609 prop = drm_property_create(dev, DRM_MODE_PROP_ENUM, 610 "pixel blend mode", 611 hweight32(supported_modes)); 612 if (!prop) 613 return -ENOMEM; 614 615 for (i = 0; i < ARRAY_SIZE(props); i++) { 616 int ret; 617 618 if (!(BIT(props[i].type) & supported_modes)) 619 continue; 620 621 ret = drm_property_add_enum(prop, props[i].type, 622 props[i].name); 623 624 if (ret) { 625 drm_property_destroy(dev, prop); 626 627 return ret; 628 } 629 } 630 631 drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI); 632 plane->blend_mode_property = prop; 633 634 return 0; 635 } 636 EXPORT_SYMBOL(drm_plane_create_blend_mode_property); 637 638 static const struct drm_prop_enum_list drm_pixel_source_enum_list[] = { 639 { DRM_PLANE_PIXEL_SOURCE_NONE, "NONE" }, 640 { DRM_PLANE_PIXEL_SOURCE_FB, "FB" }, 641 }; 642 643 /** 644 * drm_plane_create_pixel_source_property - create a new pixel source property 645 * @plane: DRM plane 646 * @extra_sources: Bitmask of additional supported pixel_sources for the driver. 647 * DRM_PLANE_PIXEL_SOURCE_FB and DRM_PLANE_PIXEL_SOURCE_NONE will 648 * always be enabled as supported sources. 649 * 650 * This creates a new property describing the current source of pixel data for the 651 * plane. The pixel_source will be initialized as DRM_PLANE_PIXEL_SOURCE_FB by default. 652 * 653 * Drivers can set a custom default source by overriding the pixel_source value in 654 * drm_plane_funcs.reset() 655 * 656 * The property is exposed to userspace as an enumeration property called 657 * "pixel_source" and has the following enumeration values: 658 * 659 * "NONE": 660 * No active pixel source 661 * 662 * "FB": 663 * Framebuffer pixel source 664 * 665 * Returns: 666 * Zero on success, negative errno on failure. 667 */ 668 int drm_plane_create_pixel_source_property(struct drm_plane *plane, 669 unsigned long extra_sources) 670 { 671 struct drm_device *dev = plane->dev; 672 struct drm_property *prop; 673 static const unsigned int valid_source_mask = BIT(DRM_PLANE_PIXEL_SOURCE_FB) | 674 BIT(DRM_PLANE_PIXEL_SOURCE_NONE); 675 int i; 676 677 /* FB is supported by default */ 678 unsigned long supported_sources = extra_sources | 679 BIT(DRM_PLANE_PIXEL_SOURCE_FB) | 680 BIT(DRM_PLANE_PIXEL_SOURCE_NONE); 681 682 if (WARN_ON(supported_sources & ~valid_source_mask)) 683 return -EINVAL; 684 685 prop = drm_property_create(dev, DRM_MODE_PROP_ENUM | DRM_MODE_PROP_ATOMIC, "pixel_source", 686 hweight32(supported_sources)); 687 688 if (!prop) 689 return -ENOMEM; 690 691 for (i = 0; i < ARRAY_SIZE(drm_pixel_source_enum_list); i++) { 692 int ret; 693 694 if (!test_bit(drm_pixel_source_enum_list[i].type, &supported_sources)) 695 continue; 696 697 ret = drm_property_add_enum(prop, drm_pixel_source_enum_list[i].type, 698 drm_pixel_source_enum_list[i].name); 699 if (ret) { 700 drm_property_destroy(dev, prop); 701 702 return ret; 703 } 704 } 705 706 drm_object_attach_property(&plane->base, prop, DRM_PLANE_PIXEL_SOURCE_FB); 707 plane->pixel_source_property = prop; 708 709 return 0; 710 } 711 EXPORT_SYMBOL(drm_plane_create_pixel_source_property); 712