drm_blend.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. #include <drm/drmP.h>
  27. #include <drm/drm_atomic.h>
  28. #include <drm/drm_blend.h>
  29. #include <linux/export.h>
  30. #include <linux/slab.h>
  31. #include <linux/sort.h>
  32. #include "drm_crtc_internal.h"
  33. /**
  34. * DOC: overview
  35. *
  36. * The basic plane composition model supported by standard plane properties only
  37. * has a source rectangle (in logical pixels within the &drm_framebuffer), with
  38. * sub-pixel accuracy, which is scaled up to a pixel-aligned destination
  39. * rectangle in the visible area of a &drm_crtc. The visible area of a CRTC is
  40. * defined by the horizontal and vertical visible pixels (stored in @hdisplay
  41. * and @vdisplay) of the requested mode (stored in &drm_crtc_state.mode). These
  42. * two rectangles are both stored in the &drm_plane_state.
  43. *
  44. * For the atomic ioctl the following standard (atomic) properties on the plane object
  45. * encode the basic plane composition model:
  46. *
  47. * SRC_X:
  48. * X coordinate offset for the source rectangle within the
  49. * &drm_framebuffer, in 16.16 fixed point. Must be positive.
  50. * SRC_Y:
  51. * Y coordinate offset for the source rectangle within the
  52. * &drm_framebuffer, in 16.16 fixed point. Must be positive.
  53. * SRC_W:
  54. * Width for the source rectangle within the &drm_framebuffer, in 16.16
  55. * fixed point. SRC_X plus SRC_W must be within the width of the source
  56. * framebuffer. Must be positive.
  57. * SRC_H:
  58. * Height for the source rectangle within the &drm_framebuffer, in 16.16
  59. * fixed point. SRC_Y plus SRC_H must be within the height of the source
  60. * framebuffer. Must be positive.
  61. * CRTC_X:
  62. * X coordinate offset for the destination rectangle. Can be negative.
  63. * CRTC_Y:
  64. * Y coordinate offset for the destination rectangle. Can be negative.
  65. * CRTC_W:
  66. * Width for the destination rectangle. CRTC_X plus CRTC_W can extend past
  67. * the currently visible horizontal area of the &drm_crtc.
  68. * CRTC_H:
  69. * Height for the destination rectangle. CRTC_Y plus CRTC_H can extend past
  70. * the currently visible vertical area of the &drm_crtc.
  71. * FB_ID:
  72. * Mode object ID of the &drm_framebuffer this plane should scan out.
  73. * CRTC_ID:
  74. * Mode object ID of the &drm_crtc this plane should be connected to.
  75. *
  76. * Note that the source rectangle must fully lie within the bounds of the
  77. * &drm_framebuffer. The destination rectangle can lie outside of the visible
  78. * area of the current mode of the CRTC. It must be apprpriately clipped by the
  79. * driver, which can be done by calling drm_plane_helper_check_update(). Drivers
  80. * are also allowed to round the subpixel sampling positions appropriately, but
  81. * only to the next full pixel. No pixel outside of the source rectangle may
  82. * ever be sampled, which is important when applying more sophisticated
  83. * filtering than just a bilinear one when scaling. The filtering mode when
  84. * scaling is unspecified.
  85. *
  86. * On top of this basic transformation additional properties can be exposed by
  87. * the driver:
  88. *
  89. * alpha:
  90. * Alpha is setup with drm_plane_create_alpha_property(). It controls the
  91. * plane-wide opacity, from transparent (0) to opaque (0xffff). It can be
  92. * combined with pixel alpha.
  93. * The pixel values in the framebuffers are expected to not be
  94. * pre-multiplied by the global alpha associated to the plane.
  95. *
  96. * rotation:
  97. * Rotation is set up with drm_plane_create_rotation_property(). It adds a
  98. * rotation and reflection step between the source and destination rectangles.
  99. * Without this property the rectangle is only scaled, but not rotated or
  100. * reflected.
  101. *
  102. * Possbile values:
  103. *
  104. * "rotate-<degrees>":
  105. * Signals that a drm plane is rotated <degrees> degrees in counter
  106. * clockwise direction.
  107. *
  108. * "reflect-<axis>":
  109. * Signals that the contents of a drm plane is reflected along the
  110. * <axis> axis, in the same way as mirroring.
  111. *
  112. * reflect-x::
  113. *
  114. * |o | | o|
  115. * | | -> | |
  116. * | v| |v |
  117. *
  118. * reflect-y::
  119. *
  120. * |o | | ^|
  121. * | | -> | |
  122. * | v| |o |
  123. *
  124. * zpos:
  125. * Z position is set up with drm_plane_create_zpos_immutable_property() and
  126. * drm_plane_create_zpos_property(). It controls the visibility of overlapping
  127. * planes. Without this property the primary plane is always below the cursor
  128. * plane, and ordering between all other planes is undefined.
  129. *
  130. * pixel blend mode:
  131. * Pixel blend mode is set up with drm_plane_create_blend_mode_property().
  132. * It adds a blend mode for alpha blending equation selection, describing
  133. * how the pixels from the current plane are composited with the
  134. * background.
  135. *
  136. * Three alpha blending equations are defined:
  137. *
  138. * "None":
  139. * Blend formula that ignores the pixel alpha::
  140. *
  141. * out.rgb = plane_alpha * fg.rgb +
  142. * (1 - plane_alpha) * bg.rgb
  143. *
  144. * "Pre-multiplied":
  145. * Blend formula that assumes the pixel color values
  146. * have been already pre-multiplied with the alpha
  147. * channel values::
  148. *
  149. * out.rgb = plane_alpha * fg.rgb +
  150. * (1 - (plane_alpha * fg.alpha)) * bg.rgb
  151. *
  152. * "Coverage":
  153. * Blend formula that assumes the pixel color values have not
  154. * been pre-multiplied and will do so when blending them to the
  155. * background color values::
  156. *
  157. * out.rgb = plane_alpha * fg.alpha * fg.rgb +
  158. * (1 - (plane_alpha * fg.alpha)) * bg.rgb
  159. *
  160. * Using the following symbols:
  161. *
  162. * "fg.rgb":
  163. * Each of the RGB component values from the plane's pixel
  164. * "fg.alpha":
  165. * Alpha component value from the plane's pixel. If the plane's
  166. * pixel format has no alpha component, then this is assumed to be
  167. * 1.0. In these cases, this property has no effect, as all three
  168. * equations become equivalent.
  169. * "bg.rgb":
  170. * Each of the RGB component values from the background
  171. * "plane_alpha":
  172. * Plane alpha value set by the plane "alpha" property. If the
  173. * plane does not expose the "alpha" property, then this is
  174. * assumed to be 1.0
  175. *
  176. * Note that all the property extensions described here apply either to the
  177. * plane or the CRTC (e.g. for the background color, which currently is not
  178. * exposed and assumed to be black).
  179. */
  180. /**
  181. * drm_plane_create_alpha_property - create a new alpha property
  182. * @plane: drm plane
  183. *
  184. * This function creates a generic, mutable, alpha property and enables support
  185. * for it in the DRM core. It is attached to @plane.
  186. *
  187. * The alpha property will be allowed to be within the bounds of 0
  188. * (transparent) to 0xffff (opaque).
  189. *
  190. * Returns:
  191. * 0 on success, negative error code on failure.
  192. */
  193. int drm_plane_create_alpha_property(struct drm_plane *plane)
  194. {
  195. struct drm_property *prop;
  196. prop = drm_property_create_range(plane->dev, 0, "alpha",
  197. 0, DRM_BLEND_ALPHA_OPAQUE);
  198. if (!prop)
  199. return -ENOMEM;
  200. drm_object_attach_property(&plane->base, prop, DRM_BLEND_ALPHA_OPAQUE);
  201. plane->alpha_property = prop;
  202. if (plane->state)
  203. plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE;
  204. return 0;
  205. }
  206. EXPORT_SYMBOL(drm_plane_create_alpha_property);
  207. /**
  208. * drm_plane_create_rotation_property - create a new rotation property
  209. * @plane: drm plane
  210. * @rotation: initial value of the rotation property
  211. * @supported_rotations: bitmask of supported rotations and reflections
  212. *
  213. * This creates a new property with the selected support for transformations.
  214. *
  215. * Since a rotation by 180° degress is the same as reflecting both along the x
  216. * and the y axis the rotation property is somewhat redundant. Drivers can use
  217. * drm_rotation_simplify() to normalize values of this property.
  218. *
  219. * The property exposed to userspace is a bitmask property (see
  220. * drm_property_create_bitmask()) called "rotation" and has the following
  221. * bitmask enumaration values:
  222. *
  223. * DRM_MODE_ROTATE_0:
  224. * "rotate-0"
  225. * DRM_MODE_ROTATE_90:
  226. * "rotate-90"
  227. * DRM_MODE_ROTATE_180:
  228. * "rotate-180"
  229. * DRM_MODE_ROTATE_270:
  230. * "rotate-270"
  231. * DRM_MODE_REFLECT_X:
  232. * "reflect-x"
  233. * DRM_MODE_REFLECT_Y:
  234. * "reflect-y"
  235. *
  236. * Rotation is the specified amount in degrees in counter clockwise direction,
  237. * the X and Y axis are within the source rectangle, i.e. the X/Y axis before
  238. * rotation. After reflection, the rotation is applied to the image sampled from
  239. * the source rectangle, before scaling it to fit the destination rectangle.
  240. */
  241. int drm_plane_create_rotation_property(struct drm_plane *plane,
  242. unsigned int rotation,
  243. unsigned int supported_rotations)
  244. {
  245. static const struct drm_prop_enum_list props[] = {
  246. { __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
  247. { __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
  248. { __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
  249. { __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
  250. { __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
  251. { __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
  252. };
  253. struct drm_property *prop;
  254. WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
  255. WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK));
  256. WARN_ON(rotation & ~supported_rotations);
  257. prop = drm_property_create_bitmask(plane->dev, 0, "rotation",
  258. props, ARRAY_SIZE(props),
  259. supported_rotations);
  260. if (!prop)
  261. return -ENOMEM;
  262. drm_object_attach_property(&plane->base, prop, rotation);
  263. if (plane->state)
  264. plane->state->rotation = rotation;
  265. plane->rotation_property = prop;
  266. return 0;
  267. }
  268. EXPORT_SYMBOL(drm_plane_create_rotation_property);
  269. /**
  270. * drm_rotation_simplify() - Try to simplify the rotation
  271. * @rotation: Rotation to be simplified
  272. * @supported_rotations: Supported rotations
  273. *
  274. * Attempt to simplify the rotation to a form that is supported.
  275. * Eg. if the hardware supports everything except DRM_MODE_REFLECT_X
  276. * one could call this function like this:
  277. *
  278. * drm_rotation_simplify(rotation, DRM_MODE_ROTATE_0 |
  279. * DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 |
  280. * DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_Y);
  281. *
  282. * to eliminate the DRM_MODE_ROTATE_X flag. Depending on what kind of
  283. * transforms the hardware supports, this function may not
  284. * be able to produce a supported transform, so the caller should
  285. * check the result afterwards.
  286. */
  287. unsigned int drm_rotation_simplify(unsigned int rotation,
  288. unsigned int supported_rotations)
  289. {
  290. if (rotation & ~supported_rotations) {
  291. rotation ^= DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y;
  292. rotation = (rotation & DRM_MODE_REFLECT_MASK) |
  293. BIT((ffs(rotation & DRM_MODE_ROTATE_MASK) + 1)
  294. % 4);
  295. }
  296. return rotation;
  297. }
  298. EXPORT_SYMBOL(drm_rotation_simplify);
  299. /**
  300. * drm_plane_create_zpos_property - create mutable zpos property
  301. * @plane: drm plane
  302. * @zpos: initial value of zpos property
  303. * @min: minimal possible value of zpos property
  304. * @max: maximal possible value of zpos property
  305. *
  306. * This function initializes generic mutable zpos property and enables support
  307. * for it in drm core. Drivers can then attach this property to planes to enable
  308. * support for configurable planes arrangement during blending operation.
  309. * Drivers that attach a mutable zpos property to any plane should call the
  310. * drm_atomic_normalize_zpos() helper during their implementation of
  311. * &drm_mode_config_funcs.atomic_check(), which will update the normalized zpos
  312. * values and store them in &drm_plane_state.normalized_zpos. Usually min
  313. * should be set to 0 and max to maximal number of planes for given crtc - 1.
  314. *
  315. * If zpos of some planes cannot be changed (like fixed background or
  316. * cursor/topmost planes), driver should adjust min/max values and assign those
  317. * planes immutable zpos property with lower or higher values (for more
  318. * information, see drm_plane_create_zpos_immutable_property() function). In such
  319. * case driver should also assign proper initial zpos values for all planes in
  320. * its plane_reset() callback, so the planes will be always sorted properly.
  321. *
  322. * See also drm_atomic_normalize_zpos().
  323. *
  324. * The property exposed to userspace is called "zpos".
  325. *
  326. * Returns:
  327. * Zero on success, negative errno on failure.
  328. */
  329. int drm_plane_create_zpos_property(struct drm_plane *plane,
  330. unsigned int zpos,
  331. unsigned int min, unsigned int max)
  332. {
  333. struct drm_property *prop;
  334. prop = drm_property_create_range(plane->dev, 0, "zpos", min, max);
  335. if (!prop)
  336. return -ENOMEM;
  337. drm_object_attach_property(&plane->base, prop, zpos);
  338. plane->zpos_property = prop;
  339. if (plane->state) {
  340. plane->state->zpos = zpos;
  341. plane->state->normalized_zpos = zpos;
  342. }
  343. return 0;
  344. }
  345. EXPORT_SYMBOL(drm_plane_create_zpos_property);
  346. /**
  347. * drm_plane_create_zpos_immutable_property - create immuttable zpos property
  348. * @plane: drm plane
  349. * @zpos: value of zpos property
  350. *
  351. * This function initializes generic immutable zpos property and enables
  352. * support for it in drm core. Using this property driver lets userspace
  353. * to get the arrangement of the planes for blending operation and notifies
  354. * it that the hardware (or driver) doesn't support changing of the planes'
  355. * order. For mutable zpos see drm_plane_create_zpos_property().
  356. *
  357. * The property exposed to userspace is called "zpos".
  358. *
  359. * Returns:
  360. * Zero on success, negative errno on failure.
  361. */
  362. int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
  363. unsigned int zpos)
  364. {
  365. struct drm_property *prop;
  366. prop = drm_property_create_range(plane->dev, DRM_MODE_PROP_IMMUTABLE,
  367. "zpos", zpos, zpos);
  368. if (!prop)
  369. return -ENOMEM;
  370. drm_object_attach_property(&plane->base, prop, zpos);
  371. plane->zpos_property = prop;
  372. if (plane->state) {
  373. plane->state->zpos = zpos;
  374. plane->state->normalized_zpos = zpos;
  375. }
  376. return 0;
  377. }
  378. EXPORT_SYMBOL(drm_plane_create_zpos_immutable_property);
  379. static int drm_atomic_state_zpos_cmp(const void *a, const void *b)
  380. {
  381. const struct drm_plane_state *sa = *(struct drm_plane_state **)a;
  382. const struct drm_plane_state *sb = *(struct drm_plane_state **)b;
  383. if (sa->zpos != sb->zpos)
  384. return sa->zpos - sb->zpos;
  385. else
  386. return sa->plane->base.id - sb->plane->base.id;
  387. }
  388. static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc,
  389. struct drm_crtc_state *crtc_state)
  390. {
  391. struct drm_atomic_state *state = crtc_state->state;
  392. struct drm_device *dev = crtc->dev;
  393. int total_planes = dev->mode_config.num_total_plane;
  394. struct drm_plane_state **states;
  395. struct drm_plane *plane;
  396. int i, n = 0;
  397. int ret = 0;
  398. DRM_DEBUG_ATOMIC("[CRTC:%d:%s] calculating normalized zpos values\n",
  399. crtc->base.id, crtc->name);
  400. states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL);
  401. if (!states)
  402. return -ENOMEM;
  403. /*
  404. * Normalization process might create new states for planes which
  405. * normalized_zpos has to be recalculated.
  406. */
  407. drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
  408. struct drm_plane_state *plane_state =
  409. drm_atomic_get_plane_state(state, plane);
  410. if (IS_ERR(plane_state)) {
  411. ret = PTR_ERR(plane_state);
  412. goto done;
  413. }
  414. states[n++] = plane_state;
  415. DRM_DEBUG_ATOMIC("[PLANE:%d:%s] processing zpos value %d\n",
  416. plane->base.id, plane->name,
  417. plane_state->zpos);
  418. }
  419. sort(states, n, sizeof(*states), drm_atomic_state_zpos_cmp, NULL);
  420. for (i = 0; i < n; i++) {
  421. plane = states[i]->plane;
  422. states[i]->normalized_zpos = i;
  423. DRM_DEBUG_ATOMIC("[PLANE:%d:%s] normalized zpos value %d\n",
  424. plane->base.id, plane->name, i);
  425. }
  426. crtc_state->zpos_changed = true;
  427. done:
  428. kfree(states);
  429. return ret;
  430. }
  431. /**
  432. * drm_atomic_normalize_zpos - calculate normalized zpos values for all crtcs
  433. * @dev: DRM device
  434. * @state: atomic state of DRM device
  435. *
  436. * This function calculates normalized zpos value for all modified planes in
  437. * the provided atomic state of DRM device.
  438. *
  439. * For every CRTC this function checks new states of all planes assigned to
  440. * it and calculates normalized zpos value for these planes. Planes are compared
  441. * first by their zpos values, then by plane id (if zpos is equal). The plane
  442. * with lowest zpos value is at the bottom. The &drm_plane_state.normalized_zpos
  443. * is then filled with unique values from 0 to number of active planes in crtc
  444. * minus one.
  445. *
  446. * RETURNS
  447. * Zero for success or -errno
  448. */
  449. int drm_atomic_normalize_zpos(struct drm_device *dev,
  450. struct drm_atomic_state *state)
  451. {
  452. struct drm_crtc *crtc;
  453. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  454. struct drm_plane *plane;
  455. struct drm_plane_state *old_plane_state, *new_plane_state;
  456. int i, ret = 0;
  457. for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
  458. crtc = new_plane_state->crtc;
  459. if (!crtc)
  460. continue;
  461. if (old_plane_state->zpos != new_plane_state->zpos) {
  462. new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
  463. new_crtc_state->zpos_changed = true;
  464. }
  465. }
  466. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  467. if (old_crtc_state->plane_mask != new_crtc_state->plane_mask ||
  468. new_crtc_state->zpos_changed) {
  469. ret = drm_atomic_helper_crtc_normalize_zpos(crtc,
  470. new_crtc_state);
  471. if (ret)
  472. return ret;
  473. }
  474. }
  475. return 0;
  476. }
  477. EXPORT_SYMBOL(drm_atomic_normalize_zpos);
  478. /**
  479. * drm_plane_create_blend_mode_property - create a new blend mode property
  480. * @plane: drm plane
  481. * @supported_modes: bitmask of supported modes, must include
  482. * BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is
  483. * that alpha is premultiplied, and old userspace can break if
  484. * the property defaults to anything else.
  485. *
  486. * This creates a new property describing the blend mode.
  487. *
  488. * The property exposed to userspace is an enumeration property (see
  489. * drm_property_create_enum()) called "pixel blend mode" and has the
  490. * following enumeration values:
  491. *
  492. * "None":
  493. * Blend formula that ignores the pixel alpha.
  494. *
  495. * "Pre-multiplied":
  496. * Blend formula that assumes the pixel color values have been already
  497. * pre-multiplied with the alpha channel values.
  498. *
  499. * "Coverage":
  500. * Blend formula that assumes the pixel color values have not been
  501. * pre-multiplied and will do so when blending them to the background color
  502. * values.
  503. *
  504. * RETURNS:
  505. * Zero for success or -errno
  506. */
  507. int drm_plane_create_blend_mode_property(struct drm_plane *plane,
  508. unsigned int supported_modes)
  509. {
  510. struct drm_device *dev = plane->dev;
  511. struct drm_property *prop;
  512. static const struct drm_prop_enum_list props[] = {
  513. { DRM_MODE_BLEND_PIXEL_NONE, "None" },
  514. { DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" },
  515. { DRM_MODE_BLEND_COVERAGE, "Coverage" },
  516. };
  517. unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
  518. BIT(DRM_MODE_BLEND_PREMULTI) |
  519. BIT(DRM_MODE_BLEND_COVERAGE);
  520. int i;
  521. if (WARN_ON((supported_modes & ~valid_mode_mask) ||
  522. ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0)))
  523. return -EINVAL;
  524. prop = drm_property_create(dev, DRM_MODE_PROP_ENUM,
  525. "pixel blend mode",
  526. hweight32(supported_modes));
  527. if (!prop)
  528. return -ENOMEM;
  529. for (i = 0; i < ARRAY_SIZE(props); i++) {
  530. int ret;
  531. if (!(BIT(props[i].type) & supported_modes))
  532. continue;
  533. ret = drm_property_add_enum(prop, props[i].type,
  534. props[i].name);
  535. if (ret) {
  536. drm_property_destroy(dev, prop);
  537. return ret;
  538. }
  539. }
  540. drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI);
  541. plane->blend_mode_property = prop;
  542. return 0;
  543. }
  544. EXPORT_SYMBOL(drm_plane_create_blend_mode_property);