diff mbox

[xf86-video-intel,5/8] sna/video/sprite: Query planes for RGB565

Message ID 20180529183315.9823-5-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ville Syrjälä May 29, 2018, 6:33 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

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ä <ville.syrjala@linux.intel.com>
---
 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(-)
diff mbox

Patch

diff --git a/src/sna/sna.h b/src/sna/sna.h
index 6fe1f0d252e6..496460ca6a84 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 66a941ae7301..96e7b1bc50d3 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 56391aa6f581..a4f3205b6fc9 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