File Index
Files and directories
Sign in
FILE

drm_blend.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/drm_blend.c C
  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 * Note that all the property extensions described here apply either to the
195 * plane or the CRTC (e.g. for the background color, which currently is not
196 * exposed and assumed to be black).
197 *
198 * SCALING_FILTER:
199 *     Indicates scaling filter to be used for plane scaler
200 *
201 *     The value of this property can be one of the following:
202 *
203 *     Default:
204 *             Driver's default scaling filter
205 *     Nearest Neighbor:
206 *             Nearest Neighbor scaling filter
207 *
208 * Drivers can set up this property for a plane by calling
209 * drm_plane_create_scaling_filter_property
210 */
211
212/**
213 * drm_plane_create_alpha_property - create a new alpha property
214 * @plane: drm plane
215 *
216 * This function creates a generic, mutable, alpha property and enables support
217 * for it in the DRM core. It is attached to @plane.
218 *
219 * The alpha property will be allowed to be within the bounds of 0
220 * (transparent) to 0xffff (opaque).
221 *
222 * Returns:
223 * 0 on success, negative error code on failure.
224 */
225int drm_plane_create_alpha_property(struct drm_plane *plane)
226{
227	struct drm_property *prop;
228
229	prop = drm_property_create_range(plane->dev, 0, "alpha",
230					 0, DRM_BLEND_ALPHA_OPAQUE);
231	if (!prop)
232		return -ENOMEM;
233
234	drm_object_attach_property(&plane->base, prop, DRM_BLEND_ALPHA_OPAQUE);
235	plane->alpha_property = prop;
236
237	if (plane->state)
238		plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE;
239
240	return 0;
241}
242EXPORT_SYMBOL(drm_plane_create_alpha_property);
243
244/**
245 * drm_plane_create_rotation_property - create a new rotation property
246 * @plane: drm plane
247 * @rotation: initial value of the rotation property
248 * @supported_rotations: bitmask of supported rotations and reflections
249 *
250 * This creates a new property with the selected support for transformations.
251 *
252 * Since a rotation by 180° degress is the same as reflecting both along the x
253 * and the y axis the rotation property is somewhat redundant. Drivers can use
254 * drm_rotation_simplify() to normalize values of this property.
255 *
256 * The property exposed to userspace is a bitmask property (see
257 * drm_property_create_bitmask()) called "rotation" and has the following
258 * bitmask enumaration values:
259 *
260 * DRM_MODE_ROTATE_0:
261 * 	"rotate-0"
262 * DRM_MODE_ROTATE_90:
263 * 	"rotate-90"
264 * DRM_MODE_ROTATE_180:
265 * 	"rotate-180"
266 * DRM_MODE_ROTATE_270:
267 * 	"rotate-270"
268 * DRM_MODE_REFLECT_X:
269 * 	"reflect-x"
270 * DRM_MODE_REFLECT_Y:
271 * 	"reflect-y"
272 *
273 * Rotation is the specified amount in degrees in counter clockwise direction,
274 * the X and Y axis are within the source rectangle, i.e.  the X/Y axis before
275 * rotation. After reflection, the rotation is applied to the image sampled from
276 * the source rectangle, before scaling it to fit the destination rectangle.
277 */
278int drm_plane_create_rotation_property(struct drm_plane *plane,
279				       unsigned int rotation,
280				       unsigned int supported_rotations)
281{
282	static const struct drm_prop_enum_list props[] = {
283		{ __builtin_ffs(DRM_MODE_ROTATE_0) - 1,   "rotate-0" },
284		{ __builtin_ffs(DRM_MODE_ROTATE_90) - 1,  "rotate-90" },
285		{ __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
286		{ __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
287		{ __builtin_ffs(DRM_MODE_REFLECT_X) - 1,  "reflect-x" },
288		{ __builtin_ffs(DRM_MODE_REFLECT_Y) - 1,  "reflect-y" },
289	};
290	struct drm_property *prop;
291
292	WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
293	WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK));
294	WARN_ON(rotation & ~supported_rotations);
295
296	prop = drm_property_create_bitmask(plane->dev, 0, "rotation",
297					   props, ARRAY_SIZE(props),
298					   supported_rotations);
299	if (!prop)
300		return -ENOMEM;
301
302	drm_object_attach_property(&plane->base, prop, rotation);
303
304	if (plane->state)
305		plane->state->rotation = rotation;
306
307	plane->rotation_property = prop;
308
309	return 0;
310}
311EXPORT_SYMBOL(drm_plane_create_rotation_property);
312
313/**
314 * drm_rotation_simplify() - Try to simplify the rotation
315 * @rotation: Rotation to be simplified
316 * @supported_rotations: Supported rotations
317 *
318 * Attempt to simplify the rotation to a form that is supported.
319 * Eg. if the hardware supports everything except DRM_MODE_REFLECT_X
320 * one could call this function like this:
321 *
322 * drm_rotation_simplify(rotation, DRM_MODE_ROTATE_0 |
323 *                       DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 |
324 *                       DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_Y);
325 *
326 * to eliminate the DRM_MODE_REFLECT_X flag. Depending on what kind of
327 * transforms the hardware supports, this function may not
328 * be able to produce a supported transform, so the caller should
329 * check the result afterwards.
330 */
331unsigned int drm_rotation_simplify(unsigned int rotation,
332				   unsigned int supported_rotations)
333{
334	if (rotation & ~supported_rotations) {
335		rotation ^= DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y;
336		rotation = (rotation & DRM_MODE_REFLECT_MASK) |
337			    BIT((ffs(rotation & DRM_MODE_ROTATE_MASK) + 1)
338			    % 4);
339	}
340
341	return rotation;
342}
343EXPORT_SYMBOL(drm_rotation_simplify);
344
345/**
346 * drm_plane_create_zpos_property - create mutable zpos property
347 * @plane: drm plane
348 * @zpos: initial value of zpos property
349 * @min: minimal possible value of zpos property
350 * @max: maximal possible value of zpos property
351 *
352 * This function initializes generic mutable zpos property and enables support
353 * for it in drm core. Drivers can then attach this property to planes to enable
354 * support for configurable planes arrangement during blending operation.
355 * Drivers that attach a mutable zpos property to any plane should call the
356 * drm_atomic_normalize_zpos() helper during their implementation of
357 * &drm_mode_config_funcs.atomic_check(), which will update the normalized zpos
358 * values and store them in &drm_plane_state.normalized_zpos. Usually min
359 * should be set to 0 and max to maximal number of planes for given crtc - 1.
360 *
361 * If zpos of some planes cannot be changed (like fixed background or
362 * cursor/topmost planes), drivers shall adjust the min/max values and assign
363 * those planes immutable zpos properties with lower or higher values (for more
364 * information, see drm_plane_create_zpos_immutable_property() function). In such
365 * case drivers shall also assign proper initial zpos values for all planes in
366 * its plane_reset() callback, so the planes will be always sorted properly.
367 *
368 * See also drm_atomic_normalize_zpos().
369 *
370 * The property exposed to userspace is called "zpos".
371 *
372 * Returns:
373 * Zero on success, negative errno on failure.
374 */
375int drm_plane_create_zpos_property(struct drm_plane *plane,
376				   unsigned int zpos,
377				   unsigned int min, unsigned int max)
378{
379	struct drm_property *prop;
380
381	prop = drm_property_create_range(plane->dev, 0, "zpos", min, max);
382	if (!prop)
383		return -ENOMEM;
384
385	drm_object_attach_property(&plane->base, prop, zpos);
386
387	plane->zpos_property = prop;
388
389	if (plane->state) {
390		plane->state->zpos = zpos;
391		plane->state->normalized_zpos = zpos;
392	}
393
394	return 0;
395}
396EXPORT_SYMBOL(drm_plane_create_zpos_property);
397
398/**
399 * drm_plane_create_zpos_immutable_property - create immuttable zpos property
400 * @plane: drm plane
401 * @zpos: value of zpos property
402 *
403 * This function initializes generic immutable zpos property and enables
404 * support for it in drm core. Using this property driver lets userspace
405 * to get the arrangement of the planes for blending operation and notifies
406 * it that the hardware (or driver) doesn't support changing of the planes'
407 * order. For mutable zpos see drm_plane_create_zpos_property().
408 *
409 * The property exposed to userspace is called "zpos".
410 *
411 * Returns:
412 * Zero on success, negative errno on failure.
413 */
414int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
415					     unsigned int zpos)
416{
417	struct drm_property *prop;
418
419	prop = drm_property_create_range(plane->dev, DRM_MODE_PROP_IMMUTABLE,
420					 "zpos", zpos, zpos);
421	if (!prop)
422		return -ENOMEM;
423
424	drm_object_attach_property(&plane->base, prop, zpos);
425
426	plane->zpos_property = prop;
427
428	if (plane->state) {
429		plane->state->zpos = zpos;
430		plane->state->normalized_zpos = zpos;
431	}
432
433	return 0;
434}
435EXPORT_SYMBOL(drm_plane_create_zpos_immutable_property);
436
437static int drm_atomic_state_zpos_cmp(const void *a, const void *b)
438{
439	const struct drm_plane_state *sa = *(struct drm_plane_state **)a;
440	const struct drm_plane_state *sb = *(struct drm_plane_state **)b;
441
442	if (sa->zpos != sb->zpos)
443		return sa->zpos - sb->zpos;
444	else
445		return sa->plane->base.id - sb->plane->base.id;
446}
447
448static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc,
449					  struct drm_crtc_state *crtc_state)
450{
451	struct drm_atomic_state *state = crtc_state->state;
452	struct drm_device *dev = crtc->dev;
453	int total_planes = dev->mode_config.num_total_plane;
454	struct drm_plane_state **states;
455	struct drm_plane *plane;
456	int i, n = 0;
457	int ret = 0;
458
459	drm_dbg_atomic(dev, "[CRTC:%d:%s] calculating normalized zpos values\n",
460		       crtc->base.id, crtc->name);
461
462	states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL);
463	if (!states)
464		return -ENOMEM;
465
466	/*
467	 * Normalization process might create new states for planes which
468	 * normalized_zpos has to be recalculated.
469	 */
470	drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
471		struct drm_plane_state *plane_state =
472			drm_atomic_get_plane_state(state, plane);
473		if (IS_ERR(plane_state)) {
474			ret = PTR_ERR(plane_state);
475			goto done;
476		}
477		states[n++] = plane_state;
478		drm_dbg_atomic(dev, "[PLANE:%d:%s] processing zpos value %d\n",
479			       plane->base.id, plane->name, plane_state->zpos);
480	}
481
482	sort(states, n, sizeof(*states), drm_atomic_state_zpos_cmp, NULL);
483
484	for (i = 0; i < n; i++) {
485		plane = states[i]->plane;
486
487		states[i]->normalized_zpos = i;
488		drm_dbg_atomic(dev, "[PLANE:%d:%s] normalized zpos value %d\n",
489			       plane->base.id, plane->name, i);
490	}
491	crtc_state->zpos_changed = true;
492
493done:
494	kfree(states);
495	return ret;
496}
497
498/**
499 * drm_atomic_normalize_zpos - calculate normalized zpos values for all crtcs
500 * @dev: DRM device
501 * @state: atomic state of DRM device
502 *
503 * This function calculates normalized zpos value for all modified planes in
504 * the provided atomic state of DRM device.
505 *
506 * For every CRTC this function checks new states of all planes assigned to
507 * it and calculates normalized zpos value for these planes. Planes are compared
508 * first by their zpos values, then by plane id (if zpos is equal). The plane
509 * with lowest zpos value is at the bottom. The &drm_plane_state.normalized_zpos
510 * is then filled with unique values from 0 to number of active planes in crtc
511 * minus one.
512 *
513 * RETURNS
514 * Zero for success or -errno
515 */
516int drm_atomic_normalize_zpos(struct drm_device *dev,
517			      struct drm_atomic_state *state)
518{
519	struct drm_crtc *crtc;
520	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
521	struct drm_plane *plane;
522	struct drm_plane_state *old_plane_state, *new_plane_state;
523	int i, ret = 0;
524
525	for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
526		crtc = new_plane_state->crtc;
527		if (!crtc)
528			continue;
529		if (old_plane_state->zpos != new_plane_state->zpos) {
530			new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
531			new_crtc_state->zpos_changed = true;
532		}
533	}
534
535	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
536		if (old_crtc_state->plane_mask != new_crtc_state->plane_mask ||
537		    new_crtc_state->zpos_changed) {
538			ret = drm_atomic_helper_crtc_normalize_zpos(crtc,
539								    new_crtc_state);
540			if (ret)
541				return ret;
542		}
543	}
544	return 0;
545}
546EXPORT_SYMBOL(drm_atomic_normalize_zpos);
547
548/**
549 * drm_plane_create_blend_mode_property - create a new blend mode property
550 * @plane: drm plane
551 * @supported_modes: bitmask of supported modes, must include
552 *		     BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is
553 *		     that alpha is premultiplied, and old userspace can break if
554 *		     the property defaults to anything else.
555 *
556 * This creates a new property describing the blend mode.
557 *
558 * The property exposed to userspace is an enumeration property (see
559 * drm_property_create_enum()) called "pixel blend mode" and has the
560 * following enumeration values:
561 *
562 * "None":
563 *	Blend formula that ignores the pixel alpha.
564 *
565 * "Pre-multiplied":
566 *	Blend formula that assumes the pixel color values have been already
567 *	pre-multiplied with the alpha channel values.
568 *
569 * "Coverage":
570 *	Blend formula that assumes the pixel color values have not been
571 *	pre-multiplied and will do so when blending them to the background color
572 *	values.
573 *
574 * RETURNS:
575 * Zero for success or -errno
576 */
577int drm_plane_create_blend_mode_property(struct drm_plane *plane,
578					 unsigned int supported_modes)
579{
580	struct drm_device *dev = plane->dev;
581	struct drm_property *prop;
582	static const struct drm_prop_enum_list props[] = {
583		{ DRM_MODE_BLEND_PIXEL_NONE, "None" },
584		{ DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" },
585		{ DRM_MODE_BLEND_COVERAGE, "Coverage" },
586	};
587	unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
588				       BIT(DRM_MODE_BLEND_PREMULTI)   |
589				       BIT(DRM_MODE_BLEND_COVERAGE);
590	int i;
591
592	if (WARN_ON((supported_modes & ~valid_mode_mask) ||
593		    ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0)))
594		return -EINVAL;
595
596	prop = drm_property_create(dev, DRM_MODE_PROP_ENUM,
597				   "pixel blend mode",
598				   hweight32(supported_modes));
599	if (!prop)
600		return -ENOMEM;
601
602	for (i = 0; i < ARRAY_SIZE(props); i++) {
603		int ret;
604
605		if (!(BIT(props[i].type) & supported_modes))
606			continue;
607
608		ret = drm_property_add_enum(prop, props[i].type,
609					    props[i].name);
610
611		if (ret) {
612			drm_property_destroy(dev, prop);
613
614			return ret;
615		}
616	}
617
618	drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI);
619	plane->blend_mode_property = prop;
620
621	return 0;
622}
623EXPORT_SYMBOL(drm_plane_create_blend_mode_property);
~/ Read-only file preview.