Skip to content

Commit 4225d5d

Browse files
Hsiao Chien SungChun-Kuang Hu
authored andcommitted
drm/mediatek: Support alpha blending in display driver
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips by adding correct blend mode property when the planes init. Before this patch, only the "Coverage" mode (default) is supported. For more information, there are three pixel blend modes in DRM driver: "None", "Pre-multiplied", and "Coverage". To understand the difference between these modes, let's take a look at the following two approaches to do alpha blending: 1. Straight: dst.RGB = src.RGB * src.A + dst.RGB * (1 - src.A) This is straightforward and easy to understand, when the source layer is compositing with the destination layer, it's alpha will affect the result. This is also known as "post-multiplied", or "Coverage" mode. 2. Pre-multiplied: dst.RGB = src.RGB + dst.RGB * (1 - src.A) Since the source RGB have already multiplied its alpha, only destination RGB need to multiply it. This is the "Pre-multiplied" mode in DRM. For the "None" blend mode in DRM, it means the pixel alpha is ignored when compositing the layers, only the constant alpha for the composited layer will take effects. Reviewed-by: CK Hu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Hsiao Chien Sung <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 59e9d9d commit 4225d5d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/gpu/drm/mediatek/mtk_plane.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
346346
DRM_INFO("Create rotation property failed\n");
347347
}
348348

349+
err = drm_plane_create_alpha_property(plane);
350+
if (err)
351+
DRM_ERROR("failed to create property: alpha\n");
352+
353+
err = drm_plane_create_blend_mode_property(plane,
354+
BIT(DRM_MODE_BLEND_PREMULTI) |
355+
BIT(DRM_MODE_BLEND_COVERAGE) |
356+
BIT(DRM_MODE_BLEND_PIXEL_NONE));
357+
if (err)
358+
DRM_ERROR("failed to create property: blend_mode\n");
359+
349360
drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
350361

351362
return 0;

0 commit comments

Comments
 (0)