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