Skip to content

Commit 2e415be

Browse files
chadmedjannau
authored andcommitted
drm: apple: add support for overlay planes
DCP is capable of compositing two surfaces in hardware. This is important for zero-copy video playback, etc. Set up an overlay plane so that userspace can do cool things with it. Signed-off-by: James Calligeros <[email protected]>
1 parent 5228c13 commit 2e415be

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

drivers/gpu/drm/apple/apple_drv.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,19 @@ static const struct drm_plane_funcs apple_plane_funcs = {
160160
* doesn't matter for the primary plane, but cursors/overlays must not
161161
* advertise formats without alpha.
162162
*/
163-
static const u32 dcp_formats[] = {
163+
static const u32 dcp_primary_formats[] = {
164164
DRM_FORMAT_XRGB2101010,
165165
DRM_FORMAT_XRGB8888,
166166
DRM_FORMAT_ARGB8888,
167167
DRM_FORMAT_XBGR8888,
168168
DRM_FORMAT_ABGR8888,
169169
};
170170

171+
static const u32 dcp_overlay_formats[] = {
172+
DRM_FORMAT_ARGB8888,
173+
DRM_FORMAT_ABGR8888,
174+
};
175+
171176
u64 apple_format_modifiers[] = {
172177
DRM_FORMAT_MOD_LINEAR,
173178
DRM_FORMAT_MOD_INVALID
@@ -182,10 +187,24 @@ static struct drm_plane *apple_plane_init(struct drm_device *dev,
182187

183188
plane = kzalloc(sizeof(*plane), GFP_KERNEL);
184189

185-
ret = drm_universal_plane_init(dev, plane, possible_crtcs,
190+
switch (type) {
191+
case DRM_PLANE_TYPE_PRIMARY:
192+
ret = drm_universal_plane_init(dev, plane, possible_crtcs,
186193
&apple_plane_funcs,
187-
dcp_formats, ARRAY_SIZE(dcp_formats),
194+
dcp_primary_formats, ARRAY_SIZE(dcp_primary_formats),
188195
apple_format_modifiers, type, NULL);
196+
break;
197+
case DRM_PLANE_TYPE_OVERLAY:
198+
case DRM_PLANE_TYPE_CURSOR:
199+
ret = drm_universal_plane_init(dev, plane, possible_crtcs,
200+
&apple_plane_funcs,
201+
dcp_overlay_formats, ARRAY_SIZE(dcp_overlay_formats),
202+
apple_format_modifiers, type, NULL);
203+
break;
204+
default:
205+
return NULL;
206+
}
207+
189208
if (ret)
190209
return ERR_PTR(ret);
191210

@@ -389,16 +408,29 @@ static int apple_probe_per_dcp(struct device *dev,
389408
struct apple_crtc *crtc;
390409
struct apple_connector *connector;
391410
struct apple_encoder *enc;
392-
struct drm_plane *primary;
393-
int ret;
411+
struct drm_plane *planes[DCP_MAX_PLANES];
412+
int ret, i;
413+
414+
planes[0] = apple_plane_init(drm, 1U << num, DRM_PLANE_TYPE_PRIMARY);
415+
if (IS_ERR(planes[0]))
416+
return PTR_ERR(planes[0]);
394417

395-
primary = apple_plane_init(drm, 1U << num, DRM_PLANE_TYPE_PRIMARY);
396418

397-
if (IS_ERR(primary))
398-
return PTR_ERR(primary);
419+
/* Set up our other planes */
420+
for (i = 1; i < DCP_MAX_PLANES; i++) {
421+
planes[i] = apple_plane_init(drm, 1U << num, DRM_PLANE_TYPE_OVERLAY);
422+
if (IS_ERR(planes[i]))
423+
return PTR_ERR(planes[i]);
424+
}
399425

426+
/*
427+
* Even though we have an overlay plane, we cannot expose it to legacy
428+
* userspace for cursors as we cannot make the same guarantees as ye olde
429+
* hardware cursor planes such userspace would expect us to. Modern userspace
430+
* knows what to do with overlays.
431+
*/
400432
crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
401-
ret = drm_crtc_init_with_planes(drm, &crtc->base, primary, NULL,
433+
ret = drm_crtc_init_with_planes(drm, &crtc->base, planes[0], NULL,
402434
&apple_crtc_funcs, NULL);
403435
if (ret)
404436
return ret;

0 commit comments

Comments
 (0)