From 9c281c62dd8cd40913fd21ec5857bb55624fed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= Date: Tue, 29 May 2018 21:33:12 +0300 Subject: sna/video/sprite: Query planes for RGB565 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not all sprite planes support RGB565. Insrtead of hardcoding which platforms have it let's ask the kernel instead. Signed-off-by: Ville Syrjälä Reviewed-by: Chris Wilson Signed-off-by: Chris Wilson --- src/sna/sna.h | 1 + src/sna/sna_display.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++ src/sna/sna_video_sprite.c | 2 +- 3 files changed, 78 insertions(+), 1 deletion(-) (limited to 'src/sna') diff --git a/src/sna/sna.h b/src/sna/sna.h index 6fe1f0d2..496460ca 100644 --- a/src/sna/sna.h +++ b/src/sna/sna.h @@ -636,6 +636,7 @@ extern bool sna_crtc_set_sprite_rotation(xf86CrtcPtr crtc, unsigned idx, uint32_ extern void sna_crtc_set_sprite_colorspace(xf86CrtcPtr crtc, unsigned idx, int colorspace); extern uint32_t sna_crtc_to_sprite(xf86CrtcPtr crtc, unsigned idx); extern bool sna_crtc_is_transformed(xf86CrtcPtr crtc); +bool sna_has_sprite_format(struct sna *sna, uint32_t format); #define CRTC_VBLANK 0x7 #define CRTC_ON 0x80000000 diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index 66a941ae..96e7b1bc 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -3560,6 +3560,82 @@ sna_crtc_find_planes(struct sna *sna, struct sna_crtc *crtc) free(planes); } +static bool plane_has_format(const uint32_t formats[], + int count_formats, + uint32_t format) +{ + int i; + + for (i = 0; i < count_formats; i++) { + if (formats[i] == format) + return true; + } + + return false; +} + +bool sna_has_sprite_format(struct sna *sna, uint32_t format) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(sna->scrn); + int i; + + if (sna->mode.num_real_crtc == 0) + return false; + + for (i = 0; i < sna->mode.num_real_crtc; i++) { + struct sna_crtc *sna_crtc = to_sna_crtc(config->crtc[i]); + struct plane *plane; + + list_for_each_entry(plane, &sna_crtc->sprites, link) { + struct local_mode_get_plane p; + uint32_t *formats; + int count_formats; + bool has_format; + + VG_CLEAR(p); + p.plane_id = plane->id; + p.count_format_types = 0; + if (drmIoctl(sna->kgem.fd, + LOCAL_IOCTL_MODE_GETPLANE, + &p)) + continue; + count_formats = p.count_format_types; + + formats = calloc(count_formats, sizeof(formats[0])); + if (!formats) + continue; + + p.count_format_types = count_formats; + p.format_type_ptr = (uintptr_t)formats; + if (drmIoctl(sna->kgem.fd, + LOCAL_IOCTL_MODE_GETPLANE, + &p)) { + free(formats); + continue; + } + + assert(p.count_format_types == count_formats); + + has_format = plane_has_format(formats, + count_formats, + format); + + free(formats); + + /* + * As long as one plane supports the + * format we declare it as supported. + * Not all planes may support it, but + * then the GPU fallback will kick in. + */ + if (has_format) + return true; + } + } + + return false; +} + static void sna_crtc_init__rotation(struct sna *sna, struct sna_crtc *crtc) { diff --git a/src/sna/sna_video_sprite.c b/src/sna/sna_video_sprite.c index 56391aa6..a4f3205b 100644 --- a/src/sna/sna_video_sprite.c +++ b/src/sna/sna_video_sprite.c @@ -754,7 +754,7 @@ void sna_video_sprite_setup(struct sna *sna, ScreenPtr screen) adaptor->pAttributes = (XvAttributeRec *)attribs; adaptor->pImages = (XvImageRec *)images; adaptor->nImages = 3; - if (sna->kgem.gen == 071) + if (sna_has_sprite_format(sna, DRM_FORMAT_RGB565)) adaptor->nImages = 4; #if XORG_XV_VERSION < 2 -- cgit v1.2.3