Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/*
2 * Copyright (C) 2016 Samsung Electronics Co.Ltd
3 * Authors:
4 * Marek Szyprowski <m.szyprowski@samsung.com>
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 *
79 * When a KMS client is performing front-buffer rendering, it should set
80 * FB_ID to the same front-buffer FB on each atomic commit. This implies
81 * to the driver that it needs to re-read the same FB again. Otherwise
82 * drivers which do not employ continuously repeated scanout cycles might
83 * not update the screen.
84 * CRTC_ID:
85 * Mode object ID of the &drm_crtc this plane should be connected to.
86 *
87 * Note that the source rectangle must fully lie within the bounds of the
88 * &drm_framebuffer. The destination rectangle can lie outside of the visible
89 * area of the current mode of the CRTC. It must be appropriately clipped by the
90 * driver, which can be done by calling drm_plane_helper_check_update(). Drivers
91 * are also allowed to round the subpixel sampling positions appropriately, but
92 * only to the next full pixel. No pixel outside of the source rectangle may
93 * ever be sampled, which is important when applying more sophisticated
94 * filtering than just a bilinear one when scaling. The filtering mode when
95 * scaling is unspecified.
96 *
97 * On top of this basic transformation additional properties can be exposed by
98 * the driver:
99 *
100 * alpha:
101 * Alpha is setup with drm_plane_create_alpha_property(). It controls the
102 * plane-wide opacity, from transparent (0) to opaque (0xffff). It can be
103 * combined with pixel alpha.
104 * The pixel values in the framebuffers are expected to not be
105 * pre-multiplied by the global alpha associated to the plane.
106 *
107 * rotation:
108 * Rotation is set up with drm_plane_create_rotation_property(). It adds a
109 * rotation and reflection step between the source and destination rectangles.
110 * Without this property the rectangle is only scaled, but not rotated or
111 * reflected.
112 *
113 * Possbile values:
114 *
115 * "rotate-<degrees>":
116 * Signals that a drm plane is rotated <degrees> degrees in counter
117 * clockwise direction.
118 *
119 * "reflect-<axis>":
120 * Signals that the contents of a drm plane is reflected along the
121 * <axis> axis, in the same way as mirroring.
122 *
123 * reflect-x::
124 *
125 * |o | | o|
126 * | | -> | |
127 * | v| |v |
128 *
129 * reflect-y::
130 *
131 * |o | | ^|
132 * | | -> | |
133 * | v| |o |
134 *
135 * zpos:
136 * Z position is set up with drm_plane_create_zpos_immutable_property() and
137 * drm_plane_create_zpos_property(). It controls the visibility of overlapping
138 * planes. Without this property the primary plane is always below the cursor
139 * plane, and ordering between all other planes is undefined. The positive
140 * Z axis points towards the user, i.e. planes with lower Z position values
141 * are underneath planes with higher Z position values. Two planes with the
142 * same Z position value have undefined ordering. Note that the Z position
143 * value can also be immutable, to inform userspace about the hard-coded
144 * stacking of planes, see drm_plane_create_zpos_immutable_property(). If
145 * any plane has a zpos property (either mutable or immutable), then all
146 * planes shall have a zpos property.
147 *
148 * pixel blend mode:
149 * Pixel blend mode is set up with drm_plane_create_blend_mode_property().
150 * It adds a blend mode for alpha blending equation selection, describing
151 * how the pixels from the current plane are composited with the
152 * background.
153 *
154 * Three alpha blending equations are defined:
155 *
156 * "None":
157 * Blend formula that ignores the pixel alpha::
158 *
159 * out.rgb = plane_alpha * fg.rgb +
160 * (1 - plane_alpha) * bg.rgb
161 *
162 * "Pre-multiplied":
163 * Blend formula that assumes the pixel color values
164 * have been already pre-multiplied with the alpha
165 * channel values::
166 *
167 * out.rgb = plane_alpha * fg.rgb +
168 * (1 - (plane_alpha * fg.alpha)) * bg.rgb
169 *
170 * "Coverage":
171 * Blend formula that assumes the pixel color values have not
172 * been pre-multiplied and will do so when blending them to the
173 * background color values::
174 *
175 * out.rgb = plane_alpha * fg.alpha * fg.rgb +
176 * (1 - (plane_alpha * fg.alpha)) * bg.rgb
177 *
178 * Using the following symbols:
179 *
180 * "fg.rgb":
181 * Each of the RGB component values from the plane's pixel
182 * "fg.alpha":
183 * Alpha component value from the plane's pixel. If the plane's
184 * pixel format has no alpha component, then this is assumed to be
185 * 1.0. In these cases, this property has no effect, as all three
186 * equations become equivalent.
187 * "bg.rgb":
188 * Each of the RGB component values from the background
189 * "plane_alpha":
190 * Plane alpha value set by the plane "alpha" property. If the
191 * plane does not expose the "alpha" property, then this is
192 * assumed to be 1.0
193 *
194 * SCALING_FILTER:
195 * Indicates scaling filter to be used for plane scaler
196 *
197 * The value of this property can be one of the following:
198 *
199 * Default:
200 * Driver's default scaling filter
201 * Nearest Neighbor:
202 * Nearest Neighbor scaling filter
203 *
204 * Drivers can set up this property for a plane by calling
205 * drm_plane_create_scaling_filter_property
206 *
207 * The property extensions described above all apply to the plane. Drivers
208 * may also expose the following crtc property extension:
209 *
210 * BACKGROUND_COLOR:
211 * Background color is set up with drm_crtc_attach_background_color_property(),
212 * and expects a 64-bit ARGB value following DRM_FORMAT_ARGB16161616, as
213 * generated by the DRM_ARGB64_PREP*() helpers. It controls the color of a
214 * full-screen layer that exists below all planes. This color will be used
215 * for pixels not covered by any plane and may also be blended with plane
216 * contents as allowed by a plane's alpha values.
217 * The background color defaults to black, and is assumed to be black for
218 * drivers that do not expose this property. Although background color
219 * isn't a plane, it is assumed that the color provided here undergoes the
220 * CRTC degamma/CSC/gamma transformations applied after the planes blending.
221 * Note that the color value includes an alpha channel, hence non-opaque
222 * background color values are allowed, but since physically transparent
223 * monitors do not (yet) exists, the final alpha value may not reach the
224 * video sink or it may simply ignore it.
225 */
226
227/**
228 * drm_plane_create_alpha_property - create a new alpha property
229 * @plane: drm plane
230 *
231 * This function creates a generic, mutable, alpha property and enables support
232 * for it in the DRM core. It is attached to @plane.
233 *
234 * The alpha property will be allowed to be within the bounds of 0
235 * (transparent) to 0xffff (opaque).
236 *
237 * Returns:
238 * 0 on success, negative error code on failure.
239 */
240int drm_plane_create_alpha_property(struct drm_plane *plane)
241{
242 struct drm_property *prop;
243
244 prop = drm_property_create_range(plane->dev, 0, "alpha",
245 0, DRM_BLEND_ALPHA_OPAQUE);
246 if (!prop)
247 return -ENOMEM;
248
249 drm_object_attach_property(&plane->base, prop, DRM_BLEND_ALPHA_OPAQUE);
250 plane->alpha_property = prop;
251
252 if (plane->state)
253 plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE;
254
255 return 0;
256}
257EXPORT_SYMBOL(drm_plane_create_alpha_property);
258
259/**
260 * drm_plane_create_rotation_property - create a new rotation property
261 * @plane: drm plane
262 * @rotation: initial value of the rotation property
263 * @supported_rotations: bitmask of supported rotations and reflections
264 *
265 * This creates a new property with the selected support for transformations.
266 *
267 * Since a rotation by 180° degress is the same as reflecting both along the x
268 * and the y axis the rotation property is somewhat redundant. Drivers can use
269 * drm_rotation_simplify() to normalize values of this property.
270 *
271 * The property exposed to userspace is a bitmask property (see
272 * drm_property_create_bitmask()) called "rotation" and has the following
273 * bitmask enumaration values:
274 *
275 * DRM_MODE_ROTATE_0:
276 * "rotate-0"
277 * DRM_MODE_ROTATE_90:
278 * "rotate-90"
279 * DRM_MODE_ROTATE_180:
280 * "rotate-180"
281 * DRM_MODE_ROTATE_270:
282 * "rotate-270"
283 * DRM_MODE_REFLECT_X:
284 * "reflect-x"
285 * DRM_MODE_REFLECT_Y:
286 * "reflect-y"
287 *
288 * Rotation is the specified amount in degrees in counter clockwise direction,
289 * the X and Y axis are within the source rectangle, i.e. the X/Y axis before
290 * rotation. After reflection, the rotation is applied to the image sampled from
291 * the source rectangle, before scaling it to fit the destination rectangle.
292 */
293int drm_plane_create_rotation_property(struct drm_plane *plane,
294 unsigned int rotation,
295 unsigned int supported_rotations)
296{
297 static const struct drm_prop_enum_list props[] = {
298 { __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
299 { __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
300 { __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
301 { __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
302 { __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
303 { __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
304 };
305 struct drm_property *prop;
306
307 WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
308 WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK));
309 WARN_ON(rotation & ~supported_rotations);
310
311 prop = drm_property_create_bitmask(plane->dev, 0, "rotation",
312 props, ARRAY_SIZE(props),
313 supported_rotations);
314 if (!prop)
315 return -ENOMEM;
316
317 drm_object_attach_property(&plane->base, prop, rotation);
318
319 if (plane->state)
320 plane->state->rotation = rotation;
321
322 plane->rotation_property = prop;
323
324 return 0;
325}
326EXPORT_SYMBOL(drm_plane_create_rotation_property);
327
328/**
329 * drm_rotation_simplify() - Try to simplify the rotation
330 * @rotation: Rotation to be simplified
331 * @supported_rotations: Supported rotations
332 *
333 * Attempt to simplify the rotation to a form that is supported.
334 * Eg. if the hardware supports everything except DRM_MODE_REFLECT_X
335 * one could call this function like this:
336 *
337 * drm_rotation_simplify(rotation, DRM_MODE_ROTATE_0 |
338 * DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 |
339 * DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_Y);
340 *
341 * to eliminate the DRM_MODE_REFLECT_X flag. Depending on what kind of
342 * transforms the hardware supports, this function may not
343 * be able to produce a supported transform, so the caller should
344 * check the result afterwards.
345 */
346unsigned int drm_rotation_simplify(unsigned int rotation,
347 unsigned int supported_rotations)
348{
349 if (rotation & ~supported_rotations) {
350 rotation ^= DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y;
351 rotation = (rotation & DRM_MODE_REFLECT_MASK) |
352 BIT((ffs(rotation & DRM_MODE_ROTATE_MASK) + 1)
353 % 4);
354 }
355
356 return rotation;
357}
358EXPORT_SYMBOL(drm_rotation_simplify);
359
360/**
361 * drm_plane_create_zpos_property - create mutable zpos property
362 * @plane: drm plane
363 * @zpos: initial value of zpos property
364 * @min: minimal possible value of zpos property
365 * @max: maximal possible value of zpos property
366 *
367 * This function initializes generic mutable zpos property and enables support
368 * for it in drm core. Drivers can then attach this property to planes to enable
369 * support for configurable planes arrangement during blending operation.
370 * Drivers that attach a mutable zpos property to any plane should call the
371 * drm_atomic_normalize_zpos() helper during their implementation of
372 * &drm_mode_config_funcs.atomic_check(), which will update the normalized zpos
373 * values and store them in &drm_plane_state.normalized_zpos. Usually min
374 * should be set to 0 and max to maximal number of planes for given crtc - 1.
375 *
376 * If zpos of some planes cannot be changed (like fixed background or
377 * cursor/topmost planes), drivers shall adjust the min/max values and assign
378 * those planes immutable zpos properties with lower or higher values (for more
379 * information, see drm_plane_create_zpos_immutable_property() function). In such
380 * case drivers shall also assign proper initial zpos values for all planes in
381 * its plane_reset() callback, so the planes will be always sorted properly.
382 *
383 * See also drm_atomic_normalize_zpos().
384 *
385 * The property exposed to userspace is called "zpos".
386 *
387 * Returns:
388 * Zero on success, negative errno on failure.
389 */
390int drm_plane_create_zpos_property(struct drm_plane *plane,
391 unsigned int zpos,
392 unsigned int min, unsigned int max)
393{
394 struct drm_property *prop;
395
396 prop = drm_property_create_range(plane->dev, 0, "zpos", min, max);
397 if (!prop)
398 return -ENOMEM;
399
400 drm_object_attach_property(&plane->base, prop, zpos);
401
402 plane->zpos_property = prop;
403
404 if (plane->state) {
405 plane->state->zpos = zpos;
406 plane->state->normalized_zpos = zpos;
407 }
408
409 return 0;
410}
411EXPORT_SYMBOL(drm_plane_create_zpos_property);
412
413/**
414 * drm_plane_create_zpos_immutable_property - create immuttable zpos property
415 * @plane: drm plane
416 * @zpos: value of zpos property
417 *
418 * This function initializes generic immutable zpos property and enables
419 * support for it in drm core. Using this property driver lets userspace
420 * to get the arrangement of the planes for blending operation and notifies
421 * it that the hardware (or driver) doesn't support changing of the planes'
422 * order. For mutable zpos see drm_plane_create_zpos_property().
423 *
424 * The property exposed to userspace is called "zpos".
425 *
426 * Returns:
427 * Zero on success, negative errno on failure.
428 */
429int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
430 unsigned int zpos)
431{
432 struct drm_property *prop;
433
434 prop = drm_property_create_range(plane->dev, DRM_MODE_PROP_IMMUTABLE,
435 "zpos", zpos, zpos);
436 if (!prop)
437 return -ENOMEM;
438
439 drm_object_attach_property(&plane->base, prop, zpos);
440
441 plane->zpos_property = prop;
442
443 if (plane->state) {
444 plane->state->zpos = zpos;
445 plane->state->normalized_zpos = zpos;
446 }
447
448 return 0;
449}
450EXPORT_SYMBOL(drm_plane_create_zpos_immutable_property);
451
452static int drm_atomic_state_zpos_cmp(const void *a, const void *b)
453{
454 const struct drm_plane_state *sa = *(struct drm_plane_state **)a;
455 const struct drm_plane_state *sb = *(struct drm_plane_state **)b;
456
457 if (sa->zpos != sb->zpos)
458 return sa->zpos - sb->zpos;
459 else
460 return sa->plane->base.id - sb->plane->base.id;
461}
462
463static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc,
464 struct drm_crtc_state *crtc_state)
465{
466 struct drm_atomic_state *state = crtc_state->state;
467 struct drm_device *dev = crtc->dev;
468 int total_planes = dev->mode_config.num_total_plane;
469 struct drm_plane_state **states;
470 struct drm_plane *plane;
471 int i, n = 0;
472 int ret = 0;
473
474 drm_dbg_atomic(dev, "[CRTC:%d:%s] calculating normalized zpos values\n",
475 crtc->base.id, crtc->name);
476
477 states = kmalloc_objs(*states, total_planes);
478 if (!states)
479 return -ENOMEM;
480
481 /*
482 * Normalization process might create new states for planes which
483 * normalized_zpos has to be recalculated.
484 */
485 drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
486 struct drm_plane_state *plane_state =
487 drm_atomic_get_plane_state(state, plane);
488 if (IS_ERR(plane_state)) {
489 ret = PTR_ERR(plane_state);
490 goto done;
491 }
492 states[n++] = plane_state;
493 drm_dbg_atomic(dev, "[PLANE:%d:%s] processing zpos value %d\n",
494 plane->base.id, plane->name, plane_state->zpos);
495 }
496
497 sort(states, n, sizeof(*states), drm_atomic_state_zpos_cmp, NULL);
498
499 for (i = 0; i < n; i++) {
500 plane = states[i]->plane;
501
502 states[i]->normalized_zpos = i;
503 drm_dbg_atomic(dev, "[PLANE:%d:%s] normalized zpos value %d\n",
504 plane->base.id, plane->name, i);
505 }
506 crtc_state->zpos_changed = true;
507
508done:
509 kfree(states);
510 return ret;
511}
512
513/**
514 * drm_atomic_normalize_zpos - calculate normalized zpos values for all crtcs
515 * @dev: DRM device
516 * @state: atomic state of DRM device
517 *
518 * This function calculates normalized zpos value for all modified planes in
519 * the provided atomic state of DRM device.
520 *
521 * For every CRTC this function checks new states of all planes assigned to
522 * it and calculates normalized zpos value for these planes. Planes are compared
523 * first by their zpos values, then by plane id (if zpos is equal). The plane
524 * with lowest zpos value is at the bottom. The &drm_plane_state.normalized_zpos
525 * is then filled with unique values from 0 to number of active planes in crtc
526 * minus one.
527 *
528 * RETURNS
529 * Zero for success or -errno
530 */
531int drm_atomic_normalize_zpos(struct drm_device *dev,
532 struct drm_atomic_state *state)
533{
534 struct drm_crtc *crtc;
535 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
536 struct drm_plane *plane;
537 struct drm_plane_state *old_plane_state, *new_plane_state;
538 int i, ret = 0;
539
540 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
541 crtc = new_plane_state->crtc;
542 if (!crtc)
543 continue;
544 if (old_plane_state->zpos != new_plane_state->zpos) {
545 new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
546 new_crtc_state->zpos_changed = true;
547 }
548 }
549
550 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
551 if (old_crtc_state->plane_mask != new_crtc_state->plane_mask ||
552 new_crtc_state->zpos_changed) {
553 ret = drm_atomic_helper_crtc_normalize_zpos(crtc,
554 new_crtc_state);
555 if (ret)
556 return ret;
557 }
558 }
559 return 0;
560}
561EXPORT_SYMBOL(drm_atomic_normalize_zpos);
562
563/**
564 * drm_plane_create_blend_mode_property - create a new blend mode property
565 * @plane: drm plane
566 * @supported_modes: bitmask of supported modes, must include
567 * BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is
568 * that alpha is premultiplied, and old userspace can break if
569 * the property defaults to anything else.
570 *
571 * This creates a new property describing the blend mode.
572 *
573 * The property exposed to userspace is an enumeration property (see
574 * drm_property_create_enum()) called "pixel blend mode" and has the
575 * following enumeration values:
576 *
577 * "None":
578 * Blend formula that ignores the pixel alpha.
579 *
580 * "Pre-multiplied":
581 * Blend formula that assumes the pixel color values have been already
582 * pre-multiplied with the alpha channel values.
583 *
584 * "Coverage":
585 * Blend formula that assumes the pixel color values have not been
586 * pre-multiplied and will do so when blending them to the background color
587 * values.
588 *
589 * RETURNS:
590 * Zero for success or -errno
591 */
592int drm_plane_create_blend_mode_property(struct drm_plane *plane,
593 unsigned int supported_modes)
594{
595 struct drm_device *dev = plane->dev;
596 struct drm_property *prop;
597 static const struct drm_prop_enum_list props[] = {
598 { DRM_MODE_BLEND_PIXEL_NONE, "None" },
599 { DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" },
600 { DRM_MODE_BLEND_COVERAGE, "Coverage" },
601 };
602 unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
603 BIT(DRM_MODE_BLEND_PREMULTI) |
604 BIT(DRM_MODE_BLEND_COVERAGE);
605 int i;
606
607 if (WARN_ON((supported_modes & ~valid_mode_mask) ||
608 ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0)))
609 return -EINVAL;
610
611 prop = drm_property_create(dev, DRM_MODE_PROP_ENUM,
612 "pixel blend mode",
613 hweight32(supported_modes));
614 if (!prop)
615 return -ENOMEM;
616
617 for (i = 0; i < ARRAY_SIZE(props); i++) {
618 int ret;
619
620 if (!(BIT(props[i].type) & supported_modes))
621 continue;
622
623 ret = drm_property_add_enum(prop, props[i].type,
624 props[i].name);
625
626 if (ret) {
627 drm_property_destroy(dev, prop);
628
629 return ret;
630 }
631 }
632
633 drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI);
634 plane->blend_mode_property = prop;
635
636 return 0;
637}
638EXPORT_SYMBOL(drm_plane_create_blend_mode_property);
639
640/**
641 * drm_crtc_attach_background_color_property - attach background color property
642 * @crtc: drm crtc
643 *
644 * Attaches the background color property to @crtc. The property defaults to
645 * solid black and will accept 64-bit ARGB values in the format generated by
646 * DRM_ARGB64_PREP*() helpers.
647 */
648void drm_crtc_attach_background_color_property(struct drm_crtc *crtc)
649{
650 drm_object_attach_property(&crtc->base,
651 crtc->dev->mode_config.background_color_property,
652 DRM_ARGB64_PREP(0xffff, 0, 0, 0));
653}
654EXPORT_SYMBOL(drm_crtc_attach_background_color_property);