Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1831326imm; Thu, 23 Aug 2018 09:26:30 -0700 (PDT) X-Google-Smtp-Source: ANB0Vday1Mq0hFvwC6A93vj5YEx8t8NCmFXYDSjT+cp+Oj/6Ej/dGJzMPnzlIex6K7urMKovxt38 X-Received: by 2002:a63:c807:: with SMTP id z7-v6mr5003449pgg.77.1535041590572; Thu, 23 Aug 2018 09:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535041590; cv=none; d=google.com; s=arc-20160816; b=lx6sV5keXNNrgCMTAda15xl575StSXeeXLDs4R5iL2zZRy+bWM+3msWWOR1lchhbLu JG5gFKik7joUiEa3g5zXyRMWJ+jcxoPi8t5SzOhyXX0l75dBBVhPDOxIU+oCzjWMLUn+ q83LV6kKLkU1ElzyZOuaQFrn7JgBtumrT1tp7788M7O/T+vIiGqvWno4MDM5p9Iop5Co MR0C9gQhokHcTEKrYgjsgyzcVLRIqDUhZBzyQKK7/oDeehRwSnchd1vQlFsVOeQrDPrT DwGf6lzADG41MZjo2PO1SX3BHXHCcrQXMQ6lNLuFMn1CeeHXHQCUoNaWJnnrdCWptb7n eR/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=88W29AI72il+FA/iFNRnKUVkuihe2MLLK77eUw+823o=; b=ZyU6w6XpewMgnqLW9ckU43ZCBYfZhzGNFJkSuJIFeqHSbCWJMS8mLL8NFzqTPRo6ty rcibP+J3GWpO70nqoC5fA7rB2dP9V2KSj3gkSbImAjzS2EcxcQlR7vdzDBAyZhcTNohh ymTtHzvaMk2mZuEFfH+rh9YBvRdghzVwcVmxoDiYZfEURsv+rpwtfHibp0GLPJPo+TIF 5x2MzfTExoSUKHuMJ0gj4dlNBX3ppj9RSW7EW1MZC/tNSh/yVFqFSr9POurj8Gat4rmL mO7m0eIpFqIHgXx8Q78U+CVJvr67vhSZhlcyEtHolNWeCYCMUANF6aDWZJW5jkj6Ib7W aR3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=IgD3xUIn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15-v6si4237173pga.579.2018.08.23.09.26.14; Thu, 23 Aug 2018 09:26:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=IgD3xUIn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731926AbeHWRpf (ORCPT + 99 others); Thu, 23 Aug 2018 13:45:35 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:46057 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730505AbeHWRpf (ORCPT ); Thu, 23 Aug 2018 13:45:35 -0400 Received: by mail-yw1-f67.google.com with SMTP id p206-v6so1997396ywg.12 for ; Thu, 23 Aug 2018 07:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=88W29AI72il+FA/iFNRnKUVkuihe2MLLK77eUw+823o=; b=IgD3xUInochWJo5QDneIfCUCDLjgWWCvzNLgCwMjHFM7icjPMtT9sLY4+54MJkAnsT qK2spXk5v574udnGSIq/12tMj3yS2RTdLxMJoNkfbjCRH89Y4TDGrp6QhlPwX6CjyFh6 t6sqBamLaYtaSyLiVDLKDt4KK1XzyJEMwvKDIYQFqMhLiYkMYdJT1/4xLt7VYkwRwYTI J4Yd+NWwVm/KY6vXaBXBMx1EBtHgm9QKwT+mBjfMvkOB5Tu7rTbtMh8o2KTwxdjy47Pq IkTafdVWbx/hWRpSX5C3QPsztLLvZtR4AiIFH6zUmlEXPdMLIS3+cv5sc++KWQhlKbuB Q+zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=88W29AI72il+FA/iFNRnKUVkuihe2MLLK77eUw+823o=; b=cnXgg669Zz4AQ2gm+3ONiBqsIkdWCyhC7jIWjtiX5dOm1PUO61efLmFZIrynnfhqRS B2/cNRmBDIBGNbuB+AVnH/BayeTRuuTv3BbJdkbMKdtIfQUOsmgaKvdCZcKJyLvMj7na vm36VtpUxbGV1pWkBcygMCpuo1VIyBg2flor99jmZBhW5r25aVTGhi6nB0wiG6+/Wl+C NbA1T/qvcHl1z3tGntaN+Fa7rusLWT3ht5Df+3bm4R3vyCxVBTblKg1EszVf7Ms03m+K ssOj0b+Q8lsMtjiuZ88sW06OIriV6JjryEn0/YxzjnGOILEFEXuzooSb6ggfky2OOuO8 CoHA== X-Gm-Message-State: APzg51CuYxcefK7gcTy8Ai/kiB1ukzbM8z1OU7qOye4fkPi4Af10fWxO exvVP4Rgj3K7EAlLZlSqp5u0ew== X-Received: by 2002:a81:9a03:: with SMTP id r3-v6mr2833687ywg.87.1535033741826; Thu, 23 Aug 2018 07:15:41 -0700 (PDT) Received: from localhost ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id e126-v6sm1922472ywf.72.2018.08.23.07.15.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Aug 2018 07:15:41 -0700 (PDT) Date: Thu, 23 Aug 2018 10:15:40 -0400 From: Sean Paul To: Lowry Li Cc: liviu.dudau@arm.com, airlied@linux.ie, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, emil.l.velikov@gmail.com, seanpaul@chromium.org, malidp@foss.arm.com, daniel.vetter@intel.com, nd@arm.com Subject: Re: [PATCH v5 1/2] drm: Add per-plane pixel blend mode property Message-ID: <20180823141540.GA45089@art_vandelay> References: <1535013020-23737-1-git-send-email-lowry.li@arm.com> <1535013020-23737-2-git-send-email-lowry.li@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1535013020-23737-2-git-send-email-lowry.li@arm.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 23, 2018 at 04:30:19PM +0800, Lowry Li wrote: > Pixel blend modes represent the alpha blending equation > selection, describing how the pixels from the current > plane are composited with the background. > > Adds a pixel_blend_mode to drm_plane_state and a > blend_mode_property to drm_plane, and related support > functions. > > Defines three blend modes in drm_blend.h. > > Changes since v1: > - Moves the blending equation into the DOC comment > - Refines the comments of drm_plane_create_blend_mode_property to not > enumerate the #defines, but instead the string values > - Uses fg.* instead of pixel.* and plane_alpha instead of plane.alpha > Changes since v2: > - Refines the comments of drm_plane_create_blend_mode_property: > 1) Puts the descriptions (after the ":") on a new line > 2) Adds explaining why @supported_modes need PREMUL as default > Changes since v3: > - Refines drm_plane_create_blend_mode_property(). drm_property_add_enum() > can calculate the index itself just fine, so no point in having the > caller pass it in. > - Since the current DRM assumption is that alpha is premultiplied > as default, define DRM_MODE_BLEND_PREMULTI as 0 will be better. > - Refines some comments. > Changes since v4: > - Adds comments in drm_blend.h. > - Removes setting default value in drm_plane_create_blend_mode_property() > as it is already in __drm_atomic_helper_plane_reset(). > - Fixes to use state->pixel_blend_mode instead of using > plane->state->pixel_blend_mode in reset function. > - Rebases on drm-misc-next. > > Reviewed-by: Liviu Dudau Reviewed-by: Sean Paul I've also Reviewed the userspace component in drm_hwc here: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/merge_requests/16#note_24690 Thanks, Sean > Signed-off-by: Lowry Li > --- > drivers/gpu/drm/drm_atomic.c | 4 ++ > drivers/gpu/drm/drm_atomic_helper.c | 1 + > drivers/gpu/drm/drm_blend.c | 123 ++++++++++++++++++++++++++++++++++++ > include/drm/drm_blend.h | 6 ++ > include/drm/drm_plane.h | 9 +++ > 5 files changed, 143 insertions(+) > > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c > index 3eb061e..d0478ab 100644 > --- a/drivers/gpu/drm/drm_atomic.c > +++ b/drivers/gpu/drm/drm_atomic.c > @@ -895,6 +895,8 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, > state->src_h = val; > } else if (property == plane->alpha_property) { > state->alpha = val; > + } else if (property == plane->blend_mode_property) { > + state->pixel_blend_mode = val; > } else if (property == plane->rotation_property) { > if (!is_power_of_2(val & DRM_MODE_ROTATE_MASK)) { > DRM_DEBUG_ATOMIC("[PLANE:%d:%s] bad rotation bitmask: 0x%llx\n", > @@ -968,6 +970,8 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, > *val = state->src_h; > } else if (property == plane->alpha_property) { > *val = state->alpha; > + } else if (property == plane->blend_mode_property) { > + *val = state->pixel_blend_mode; > } else if (property == plane->rotation_property) { > *val = state->rotation; > } else if (property == plane->zpos_property) { > diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c > index 6dd5036..284a5d2 100644 > --- a/drivers/gpu/drm/drm_atomic_helper.c > +++ b/drivers/gpu/drm/drm_atomic_helper.c > @@ -3569,6 +3569,7 @@ void __drm_atomic_helper_plane_reset(struct drm_plane *plane, > /* Reset the alpha value to fully opaque if it matters */ > if (plane->alpha_property) > state->alpha = plane->alpha_property->values[1]; > + state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI; > > plane->state = state; > } > diff --git a/drivers/gpu/drm/drm_blend.c b/drivers/gpu/drm/drm_blend.c > index a16a74d..402b62d 100644 > --- a/drivers/gpu/drm/drm_blend.c > +++ b/drivers/gpu/drm/drm_blend.c > @@ -107,6 +107,52 @@ > * planes. Without this property the primary plane is always below the cursor > * plane, and ordering between all other planes is undefined. > * > + * pixel blend mode: > + * Pixel blend mode is set up with drm_plane_create_blend_mode_property(). > + * It adds a blend mode for alpha blending equation selection, describing > + * how the pixels from the current plane are composited with the > + * background. > + * > + * Three alpha blending equations are defined: > + * > + * "None": > + * Blend formula that ignores the pixel alpha:: > + * > + * out.rgb = plane_alpha * fg.rgb + > + * (1 - plane_alpha) * bg.rgb > + * > + * "Pre-multiplied": > + * Blend formula that assumes the pixel color values > + * have been already pre-multiplied with the alpha > + * channel values:: > + * > + * out.rgb = plane_alpha * fg.rgb + > + * (1 - (plane_alpha * fg.alpha)) * bg.rgb > + * > + * "Coverage": > + * Blend formula that assumes the pixel color values have not > + * been pre-multiplied and will do so when blending them to the > + * background color values:: > + * > + * out.rgb = plane_alpha * fg.alpha * fg.rgb + > + * (1 - (plane_alpha * fg.alpha)) * bg.rgb > + * > + * Using the following symbols: > + * > + * "fg.rgb": > + * Each of the RGB component values from the plane's pixel > + * "fg.alpha": > + * Alpha component value from the plane's pixel. If the plane's > + * pixel format has no alpha component, then this is assumed to be > + * 1.0. In these cases, this property has no effect, as all three > + * equations become equivalent. > + * "bg.rgb": > + * Each of the RGB component values from the background > + * "plane_alpha": > + * Plane alpha value set by the plane "alpha" property. If the > + * plane does not expose the "alpha" property, then this is > + * assumed to be 1.0 > + * > * Note that all the property extensions described here apply either to the > * plane or the CRTC (e.g. for the background color, which currently is not > * exposed and assumed to be black). > @@ -448,3 +494,80 @@ int drm_atomic_normalize_zpos(struct drm_device *dev, > return 0; > } > EXPORT_SYMBOL(drm_atomic_normalize_zpos); > + > +/** > + * drm_plane_create_blend_mode_property - create a new blend mode property > + * @plane: drm plane > + * @supported_modes: bitmask of supported modes, must include > + * BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is > + * that alpha is premultiplied, and old userspace can break if > + * the property defaults to anything else. > + * > + * This creates a new property describing the blend mode. > + * > + * The property exposed to userspace is an enumeration property (see > + * drm_property_create_enum()) called "pixel blend mode" and has the > + * following enumeration values: > + * > + * "None": > + * Blend formula that ignores the pixel alpha. > + * > + * "Pre-multiplied": > + * Blend formula that assumes the pixel color values have been already > + * pre-multiplied with the alpha channel values. > + * > + * "Coverage": > + * Blend formula that assumes the pixel color values have not been > + * pre-multiplied and will do so when blending them to the background color > + * values. > + * > + * RETURNS: > + * Zero for success or -errno > + */ > +int drm_plane_create_blend_mode_property(struct drm_plane *plane, > + unsigned int supported_modes) > +{ > + struct drm_device *dev = plane->dev; > + struct drm_property *prop; > + static const struct drm_prop_enum_list props[] = { > + { DRM_MODE_BLEND_PIXEL_NONE, "None" }, > + { DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" }, > + { DRM_MODE_BLEND_COVERAGE, "Coverage" }, > + }; > + unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) | > + BIT(DRM_MODE_BLEND_PREMULTI) | > + BIT(DRM_MODE_BLEND_COVERAGE); > + int i; > + > + if (WARN_ON((supported_modes & ~valid_mode_mask) || > + ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0))) > + return -EINVAL; > + > + prop = drm_property_create(dev, DRM_MODE_PROP_ENUM, > + "pixel blend mode", > + hweight32(supported_modes)); > + if (!prop) > + return -ENOMEM; > + > + for (i = 0; i < ARRAY_SIZE(props); i++) { > + int ret; > + > + if (!(BIT(props[i].type) & supported_modes)) > + continue; > + > + ret = drm_property_add_enum(prop, props[i].type, > + props[i].name); > + > + if (ret) { > + drm_property_destroy(dev, prop); > + > + return ret; > + } > + } > + > + drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI); > + plane->blend_mode_property = prop; > + > + return 0; > +} > +EXPORT_SYMBOL(drm_plane_create_blend_mode_property); > diff --git a/include/drm/drm_blend.h b/include/drm/drm_blend.h > index 330c561..88bdfec 100644 > --- a/include/drm/drm_blend.h > +++ b/include/drm/drm_blend.h > @@ -27,6 +27,10 @@ > #include > #include > > +#define DRM_MODE_BLEND_PREMULTI 0 > +#define DRM_MODE_BLEND_COVERAGE 1 > +#define DRM_MODE_BLEND_PIXEL_NONE 2 > + > struct drm_device; > struct drm_atomic_state; > struct drm_plane; > @@ -52,4 +56,6 @@ int drm_plane_create_zpos_immutable_property(struct drm_plane *plane, > unsigned int zpos); > int drm_atomic_normalize_zpos(struct drm_device *dev, > struct drm_atomic_state *state); > +int drm_plane_create_blend_mode_property(struct drm_plane *plane, > + unsigned int supported_modes); > #endif > diff --git a/include/drm/drm_plane.h b/include/drm/drm_plane.h > index 8a152dc..35ef64a 100644 > --- a/include/drm/drm_plane.h > +++ b/include/drm/drm_plane.h > @@ -117,6 +117,7 @@ struct drm_plane_state { > * details. > */ > u16 alpha; > + uint16_t pixel_blend_mode; > > /** > * @rotation: > @@ -659,6 +660,14 @@ struct drm_plane { > * drm_plane_create_rotation_property(). > */ > struct drm_property *rotation_property; > + /** > + * @blend_mode_property: > + * Optional "pixel blend mode" enum property for this plane. > + * Blend mode property represents the alpha blending equation selection, > + * describing how the pixels from the current plane are composited with > + * the background. > + */ > + struct drm_property *blend_mode_property; > > /** > * @color_encoding_property: > -- > 1.9.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Sean Paul, Software Engineer, Google / Chromium OS