From patchwork Wed Aug 15 06:35:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lowry Li (Arm Technology China)" X-Patchwork-Id: 10566309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A69C513B4 for ; Wed, 15 Aug 2018 06:36:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9430F29E6E for ; Wed, 15 Aug 2018 06:36:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87CF529EAB; Wed, 15 Aug 2018 06:36:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DB5D529E6E for ; Wed, 15 Aug 2018 06:36:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31A186E30F; Wed, 15 Aug 2018 06:36:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70048.outbound.protection.outlook.com [40.107.7.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id B507C6E30C for ; Wed, 15 Aug 2018 06:36:01 +0000 (UTC) Received: from lowry-ThinkStation-P300.shanghai.arm.com (113.29.88.7) by AM0PR08MB3523.eurprd08.prod.outlook.com (2603:10a6:208:dd::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.19; Wed, 15 Aug 2018 06:35:54 +0000 From: Lowry Li To: liviu.dudau@arm.com Subject: [PATCH v4 1/2] drm: Add per-plane pixel blend mode property Date: Wed, 15 Aug 2018 14:35:32 +0800 Message-Id: <1534314933-23182-2-git-send-email-lowry.li@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1534314933-23182-1-git-send-email-lowry.li@arm.com> References: <1534314933-23182-1-git-send-email-lowry.li@arm.com> MIME-Version: 1.0 X-Originating-IP: [113.29.88.7] X-ClientProxiedBy: SG2PR01CA0129.apcprd01.prod.exchangelabs.com (2603:1096:4:40::33) To AM0PR08MB3523.eurprd08.prod.outlook.com (2603:10a6:208:dd::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b44e3a68-0786-4c53-24f7-08d602795cb5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3523; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3523; 3:3rAOsavS7uRA9lhV+4HFQfciefmDS7I5zcOR3Bw3L3GoXGRpxUMZ9pY43i7OKaqZK/akc7ftLxKxNDH2VaetNBp++5xBEnvUEtIihKzZDuo6ulZaswqL4aBjk8lZMySMlg+F8TEEtHRdDC4LJtqA7AuT1zec6o8EWHNGmCdEb5T8rZacNgP4ubck+GKJTgRTlEbYO0bVfqn6D3028RJR2qnXpY4E7kpwzBRE4G8FL5R07z2ZjSMviUpLQxT9k6ja; 25:kQxRJFV3JxxKGLWGOS/uEa09stl52gwUIxsMNZutaC3ElWgQNWQe5Ol06t5RuIeuuolrcXe3YQ3KUtRJvnW7tYAXJ34SKlf/l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2MqjCKS0m28+b+OdWus8h43plxSJ/Fvxm6AA8IqRNho7QFk3sMiuBcYv4uSr9zPgW40Hl4iACa/A1nA8D1aq9hEypNhqPihOUSdR82vsUzBDhANiOqH/VHBzJcs1fKGzK6y3C0VP/KpjUbvG71a8CVyMzgWYcWGNeb8y X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:AM0PR08MB3523; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3523; X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(7736002)(305945005)(16586007)(66066001)(37006003)(3846002)(50466002)(478600001)(72206003)(8936002)(48376002)(68736007)(50226002)(86362001)(39060400002)(316002)(6116002)(5024004)(47776003)(36756003)(97736004)(34206002)(25786009)(2906002)(5660300001)(51416003)(6636002)(2361001)(4326008)(6666003)(44832011)(6486002)(106356001)(81156014)(105586002)(2351001)(11346002)(53936002)(7696005)(956004)(81166006)(386003)(52116002)(446003)(2616005)(486006)(8676002)(26005)(16526019)(476003)(76176011); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB3523; H:lowry-ThinkStation-P300.shanghai.arm.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3523; 23:PuUTOQ5tRb6BzuDAg7byszQSyJbM6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 5:orCSp4s881nh7FDT6om1wuGaaH+hRUVz/tyslYceE8Ch/ffO5+C88Ly+BztHc9VPKm1O2dqoecUTV5ha4NbINlgCth9ep4mw2cHiFcDvOT0GIdkd1eFVTb1LM5fl13LM4+6uKb5dKknw8o3qmiwvTKiXWH+x9TE2BglWX32I3JI=; 7:KbmDBNG7hRqWqC4U306qJ4uspi/9XktVHq93A6mC7Hu2qfxwjkDGiAUM7ODY84Cyies/Dev/TtwVoWDFQSD6nAGZf7o+9nrxUft7/Ob4+SKX9rziE2i2MVzn+xVJXubSWo9HF8UxljbWA+2nr/2KW8PzNTBrI6wz+SDXGUeHqGnxBiaWMGA//Pv+wykRykBk5WewsAcjJClS1g8vSoOX0RlLpXr/ucTKF3ArzvNrK2PMFZsiQKmesNocsudHjgtn SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 06:35:54.5739 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b44e3a68-0786-4c53-24f7-08d602795cb5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3523 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Lowry Li Reviewed-by: Liviu Dudau Reviewed-by: Maarten Lankhorst --- drivers/gpu/drm/drm_atomic.c | 4 ++ drivers/gpu/drm/drm_atomic_helper.c | 1 + drivers/gpu/drm/drm_blend.c | 126 ++++++++++++++++++++++++++++++++++++ include/drm/drm_blend.h | 6 ++ include/drm/drm_plane.h | 2 + 5 files changed, 139 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..563af09 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]; + plane->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..24016c9 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,83 @@ 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; + + if (plane->state) + plane->state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI; + + 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..c52614a 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,7 @@ struct drm_plane { * drm_plane_create_rotation_property(). */ struct drm_property *rotation_property; + struct drm_property *blend_mode_property; /** * @color_encoding_property: From patchwork Wed Aug 15 06:35:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lowry Li (Arm Technology China)" X-Patchwork-Id: 10566311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12C2613B4 for ; Wed, 15 Aug 2018 06:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03EDF29E6E for ; Wed, 15 Aug 2018 06:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC22429EAB; Wed, 15 Aug 2018 06:36:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66C6C29E6E for ; Wed, 15 Aug 2018 06:36:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 305CA6E30D; Wed, 15 Aug 2018 06:36:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70052.outbound.protection.outlook.com [40.107.7.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9FD226E30D for ; Wed, 15 Aug 2018 06:36:06 +0000 (UTC) Received: from lowry-ThinkStation-P300.shanghai.arm.com (113.29.88.7) by AM0PR08MB3523.eurprd08.prod.outlook.com (2603:10a6:208:dd::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.19; Wed, 15 Aug 2018 06:35:59 +0000 From: Lowry Li To: liviu.dudau@arm.com Subject: [PATCH v4 2/2] drm/mali-dp: Implement plane alpha and pixel blend on malidp Date: Wed, 15 Aug 2018 14:35:33 +0800 Message-Id: <1534314933-23182-3-git-send-email-lowry.li@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1534314933-23182-1-git-send-email-lowry.li@arm.com> References: <1534314933-23182-1-git-send-email-lowry.li@arm.com> MIME-Version: 1.0 X-Originating-IP: [113.29.88.7] X-ClientProxiedBy: SG2PR01CA0129.apcprd01.prod.exchangelabs.com (2603:1096:4:40::33) To AM0PR08MB3523.eurprd08.prod.outlook.com (2603:10a6:208:dd::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 17f4ed8f-6cfc-48a9-a1e7-08d602795f9a X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3523; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3523; 3:fRcPkxxngEIBVtsWxb2zkAADyMaLjkw35wYhosmgtNm/PjolYus6kMCZZKLTGpAEOpI9meiG22bkE2UemSJMvW7sioj6nyNGd/uDMYBaviM2CvuWM4WFrxsznJ8auMCLpOJf/z8j8BcIP4+wXDguhBAxhcVre3hW0iUJGIoY5HE+9EKiX30BnUoIdFi2sfsFj4/aRkrDFZmsldQ1dKDg5wBWyyVgj7OC00Y6Wq1/zNgQM7CHAdXNNl+B0cFA9cj8; 25:fqDZknrfm2iWxs9ZPJyzie0eaCyEyvvx0zWMOtGGY5fQxsiVnsyCvhRLLLdoVaLEA6Xx+M6G3gj1344dGfCz/l1z4hZoUXQaR8OpVmFEHQW4jPbxInvFIp6sLD4P+YIDtaoIvEp2fGi3PxNTLEbjhz0chqTyhMtE25tUVmiHt5C89bzBe2m3N15tGTwPdKWlz1OnOsvYseiuWMSGgpJFPcrBehjftCXeUJvksc8hXotn0ieCVawjekKU9d/7OYLhx6iFbeZeCZq3lFq4lahWiBDQtcf9J4N7g564gpi3seBIWOf224YSDC2kzORdbJD6I3mRCAyxKeW+MjlifGZyPg==; 31:+/6czKpyFYCAhqUD3lCJzctAZLyA1z74hcWG4/lIwWw8CbFuAS5HDzbX8iSR028UYx+/cIKx9DzIIC0VshE0FNA/XHfzKxoTMA2mCA51Cb1OHbwW9y7S7JFCLiHmho9vvBA0UYdeGizDRjWgT4DFMnfHBNFmCIESwHz9sOO1q3KbAPvR4QvWjD3tvnnW6rCWOsPDkLYAOKC08vTRFVgNwze4yLZNedaCYVXPpf37r3Q= X-MS-TrafficTypeDiagnostic: AM0PR08MB3523: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3523; 20:Y/xs7k3WFLySXg8rsOEY3pCsXS3jiv30+uIviG1u4LHkXC2pTlOR/8DvcaWCD74QnV1rHk0zXq+NYw1X9Fq5DERTcTzW2kCE95A9kM+m9+jSHfdidwuy+gwjOSrrxqJvgv6x+FZQe0a96ctbbsVBfMuugKzo9RUnfPkOh3FuZcVameWCHEhK0AQoUNlarzWCmzptXMTmIZYJnXVtK7fcqmb9AgwGFinuE8970rjd4N29ebk5HIITSuBxtkynJDFvq1oB2Y/eWk5m8vcFbmX99Wes2gI6C6IVlQYJahiRfdPdB8DkA1eDF6IVvVvvhEBuxew9qFf+gCETHAApeUiLRg==; 4:WUF+XPedkvB0+sAAT4uIizzt2hmb1gA1MB6DxDsn8+39Zg+Dzq9fIdWc6VGDdgDWvig/wZ7LQrYyVeRJ7VVb66VjpDsaa8G9LkDGoxmPQgG1Hjx+B+cdnnYT3ktCA6dpHg1snQc7PWe6RewigIjZaYbvrZ4edAfycqrlx2bJGh6p3Tk5ez4ZM0ELU3R7s/hB+MoAolRKyfOi8JRXC6U3tmgTe0kR3HTkn62W/9Mfxgu5NxzbPdnsxwBc05Hd2qGhk4+slFEXYcqkqVJqoSr4n/WrPlBp9hARdKDERppk6xVb0NRPNln7VYMpMvi65kSa X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:AM0PR08MB3523; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3523; X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(7736002)(305945005)(16586007)(66066001)(37006003)(3846002)(50466002)(45080400002)(478600001)(72206003)(8936002)(48376002)(68736007)(50226002)(86362001)(39060400002)(316002)(6116002)(5024004)(14444005)(47776003)(36756003)(97736004)(34206002)(25786009)(2906002)(5660300001)(51416003)(6636002)(2361001)(4326008)(6666003)(44832011)(6486002)(106356001)(81156014)(105586002)(2351001)(11346002)(53936002)(7696005)(956004)(81166006)(386003)(52116002)(446003)(2616005)(486006)(8676002)(26005)(16526019)(476003)(76176011); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB3523; H:lowry-ThinkStation-P300.shanghai.arm.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3523; 23:KzgH/DmbZN5bxMxWDoCnYzS4FJ/hej0wpIByHxa+Y?= 85tONl/7R1Q210m7akL7ZgIBOlB6f9uYsJ7BqDRAOZGjTk7BVHVI7JQ7rJ8SGSRe6JY190u4JTtHzmdHoE8ESxdzz78rF3QZipUbGQ6JIxNXjmoH/XDsCSzo7M+SCAPo15RZg+4oqf8cSnt8dElfv553hXFBaMIJRAXHw+avBbHRnNTMd+3DiEqXE/4oYdY/0pwb2E6rmMi5q46mv4yvWxEe/dGg5qmYDSBClveD2YuyA6yPBVfLQRmRMpsFlJRPxFeeo55zWLDQQlMFYQzoQfKei2GJpFD2T43L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UGWr35QO1UdcZ/F7MtVg/yZRePsGow2MiYL24xmYsX/TgeUR9F+1PMgrA++Vd+hU4UVOk4DPdvvLqsS3RPuwGdgprbPUckODWMskKpZU3/+XkPmuNjtF5InY2+KNszvytk1oqIP6fef5IJ5Ki5DOIdpcwxeZVdPi25w134ADEisXi2p2l7LbGK/dHSX2yBcJvlG6iJz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 06:35:59.4333 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17f4ed8f-6cfc-48a9-a1e7-08d602795f9a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3523 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Checks the pixel blending mode and plane alpha value when do the plane_check. Mali DP supports blending the current plane with the background either based on the pixel alpha blending mode or by using the layer's alpha value, but not both at the same time. If both case, plane_check will return failed. Sets the HW when doing plane_update accordingly. If plane alpha is the 0xffff, set the pixel blending bits accordingly. If not we'd set ALPHA bit as zero and layer alpha value. Changes since v1: - Introduces to use it in the malidp driver, which depends on the plane alpha patch Changes since v2: - Refines the comments of drm/mali-dp patchset Changes since v3: - Updates on drm/malidp, hardware limitation check only when the format has alpha pixel. Signed-off-by: Lowry Li Acked-by: Liviu Dudau --- drivers/gpu/drm/arm/malidp_planes.c | 74 +++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 49c37f6..17be123 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -36,6 +36,7 @@ #define LAYER_COMP_MASK (0x3 << 12) #define LAYER_COMP_PIXEL (0x3 << 12) #define LAYER_COMP_PLANE (0x2 << 12) +#define LAYER_PMUL_ENABLE (0x1 << 14) #define LAYER_ALPHA_OFFSET (16) #define LAYER_ALPHA_MASK (0xff) #define LAYER_ALPHA(x) (((x) & LAYER_ALPHA_MASK) << LAYER_ALPHA_OFFSET) @@ -180,6 +181,7 @@ static int malidp_de_plane_check(struct drm_plane *plane, struct malidp_plane_state *ms = to_malidp_plane_state(state); bool rotated = state->rotation & MALIDP_ROTATED_MASK; struct drm_framebuffer *fb; + u16 pixel_alpha = state->pixel_blend_mode; int i, ret; if (!state->crtc || !state->fb) @@ -242,6 +244,11 @@ static int malidp_de_plane_check(struct drm_plane *plane, ms->rotmem_size = val; } + /* HW can't support plane + pixel blending */ + if ((state->alpha != DRM_BLEND_ALPHA_OPAQUE) && + (pixel_alpha != DRM_MODE_BLEND_PIXEL_NONE)) + return -EINVAL; + return 0; } @@ -323,17 +330,19 @@ static void malidp_de_plane_update(struct drm_plane *plane, { struct malidp_plane *mp; struct malidp_plane_state *ms = to_malidp_plane_state(plane->state); + struct drm_plane_state *state = plane->state; + u16 pixel_alpha = state->pixel_blend_mode; + u8 plane_alpha = state->alpha >> 8; u32 src_w, src_h, dest_w, dest_h, val; int i; - bool format_has_alpha = plane->state->fb->format->has_alpha; mp = to_malidp_plane(plane); /* convert src values from Q16 fixed point to integer */ - src_w = plane->state->src_w >> 16; - src_h = plane->state->src_h >> 16; - dest_w = plane->state->crtc_w; - dest_h = plane->state->crtc_h; + src_w = state->src_w >> 16; + src_h = state->src_h >> 16; + dest_w = state->crtc_w; + dest_h = state->crtc_h; val = malidp_hw_read(mp->hwdev, mp->layer->base); val = (val & ~LAYER_FORMAT_MASK) | ms->format; @@ -342,14 +351,14 @@ static void malidp_de_plane_update(struct drm_plane *plane, for (i = 0; i < ms->n_planes; i++) { /* calculate the offset for the layer's plane registers */ u16 ptr = mp->layer->ptr + (i << 4); - dma_addr_t fb_addr = drm_fb_cma_get_gem_addr(plane->state->fb, - plane->state, i); + dma_addr_t fb_addr = drm_fb_cma_get_gem_addr(state->fb, + state, i); malidp_hw_write(mp->hwdev, lower_32_bits(fb_addr), ptr); malidp_hw_write(mp->hwdev, upper_32_bits(fb_addr), ptr + 4); } malidp_de_set_plane_pitches(mp, ms->n_planes, - plane->state->fb->pitches); + state->fb->pitches); if ((plane->state->color_encoding != old_state->color_encoding) || (plane->state->color_range != old_state->color_range)) @@ -362,8 +371,8 @@ static void malidp_de_plane_update(struct drm_plane *plane, malidp_hw_write(mp->hwdev, LAYER_H_VAL(dest_w) | LAYER_V_VAL(dest_h), mp->layer->base + MALIDP_LAYER_COMP_SIZE); - malidp_hw_write(mp->hwdev, LAYER_H_VAL(plane->state->crtc_x) | - LAYER_V_VAL(plane->state->crtc_y), + malidp_hw_write(mp->hwdev, LAYER_H_VAL(state->crtc_x) | + LAYER_V_VAL(state->crtc_y), mp->layer->base + MALIDP_LAYER_OFFSET); if (mp->layer->id == DE_SMART) @@ -376,38 +385,35 @@ static void malidp_de_plane_update(struct drm_plane *plane, val &= ~LAYER_ROT_MASK; /* setup the rotation and axis flip bits */ - if (plane->state->rotation & DRM_MODE_ROTATE_MASK) + if (state->rotation & DRM_MODE_ROTATE_MASK) val |= ilog2(plane->state->rotation & DRM_MODE_ROTATE_MASK) << LAYER_ROT_OFFSET; - if (plane->state->rotation & DRM_MODE_REFLECT_X) + if (state->rotation & DRM_MODE_REFLECT_X) val |= LAYER_H_FLIP; - if (plane->state->rotation & DRM_MODE_REFLECT_Y) + if (state->rotation & DRM_MODE_REFLECT_Y) val |= LAYER_V_FLIP; - val &= ~LAYER_COMP_MASK; - if (format_has_alpha) { - - /* - * always enable pixel alpha blending until we have a way - * to change blend modes - */ - val |= LAYER_COMP_PIXEL; - } else { + val &= ~(LAYER_COMP_MASK | LAYER_PMUL_ENABLE | LAYER_ALPHA(0xff)); - /* - * do not enable pixel alpha blending as the color channel - * does not have any alpha information - */ + if (state->alpha != DRM_BLEND_ALPHA_OPAQUE) { val |= LAYER_COMP_PLANE; - - /* Set layer alpha coefficient to 0xff ie fully opaque */ - val |= LAYER_ALPHA(0xff); + } else if (state->fb->format->has_alpha) { + /* We only care about blend mode if the format has alpha */ + switch (pixel_alpha) { + case DRM_MODE_BLEND_PREMULTI: + val |= LAYER_COMP_PIXEL | LAYER_PMUL_ENABLE; + break; + case DRM_MODE_BLEND_COVERAGE: + val |= LAYER_COMP_PIXEL; + break; + } } + val |= LAYER_ALPHA(plane_alpha); val &= ~LAYER_FLOWCFG(LAYER_FLOWCFG_MASK); - if (plane->state->crtc) { + if (state->crtc) { struct malidp_crtc_state *m = - to_malidp_crtc_state(plane->state->crtc->state); + to_malidp_crtc_state(state->crtc->state); if (m->scaler_config.scale_enable && m->scaler_config.plane_src_id == mp->layer->id) @@ -446,6 +452,9 @@ int malidp_de_planes_init(struct drm_device *drm) unsigned long crtcs = 1 << drm->mode_config.num_crtc; unsigned long flags = DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y; + unsigned int blend_caps = BIT(DRM_MODE_BLEND_PIXEL_NONE) | + BIT(DRM_MODE_BLEND_PREMULTI) | + BIT(DRM_MODE_BLEND_COVERAGE); u32 *formats; int ret, i, j, n; @@ -498,6 +507,9 @@ int malidp_de_planes_init(struct drm_device *drm) malidp_hw_write(malidp->dev, MALIDP_ALPHA_LUT, plane->layer->base + MALIDP_LAYER_COMPOSE); + drm_plane_create_alpha_property(&plane->base); + drm_plane_create_blend_mode_property(&plane->base, blend_caps); + /* Attach the YUV->RGB property only to video layers */ if (id & (DE_VIDEO1 | DE_VIDEO2)) { /* default encoding for YUV->RGB is BT601 NARROW */