summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2014-08-04 16:14:51 +0100
committerThomas Wood <thomas.wood@intel.com>2014-09-05 16:52:51 +0100
commit4cb194669782d759e60bad3fa61e3efc0ee7c7ec (patch)
tree7994d1fbceab1fad45f74859770e29691d8d29b0 /lib
parenta124b1a430bf47f31fcff0614dbc00dbe2794dcf (diff)
lib: move create_stereo_fb from testdisplay to igt_fb
Move create_stereo_fb from testdisplay to igt_create_stereo_fb in igt_fb so that it can be used in other tests. v2: update for new igt_create_fb API add parameters for format and tiling remove some old debug code Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/igt_fb.c100
-rw-r--r--lib/igt_fb.h2
3 files changed, 105 insertions, 1 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 001ecab3..36cf2d3f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,7 +7,9 @@ noinst_LTLIBRARIES = libintel_tools.la
noinst_HEADERS = check-ndebug.h
AM_CPPFLAGS = -I$(top_srcdir)
-AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)
+AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
+ -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\"
+
LDADD = $(CAIRO_LIBS)
AM_CFLAGS += $(CAIRO_CFLAGS)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 71d9a26a..f9f5de2a 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -502,6 +502,106 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
return fb_id;
}
+struct box {
+ int x, y, width, height;
+};
+
+struct stereo_fb_layout {
+ int fb_width, fb_height;
+ struct box left, right;
+};
+
+static void box_init(struct box *box, int x, int y, int bwidth, int bheight)
+{
+ box->x = x;
+ box->y = y;
+ box->width = bwidth;
+ box->height = bheight;
+}
+
+
+static void stereo_fb_layout_from_mode(struct stereo_fb_layout *layout,
+ drmModeModeInfo *mode)
+{
+ unsigned int format = mode->flags & DRM_MODE_FLAG_3D_MASK;
+ const int hdisplay = mode->hdisplay, vdisplay = mode->vdisplay;
+ int middle;
+
+ switch (format) {
+ case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
+ layout->fb_width = hdisplay;
+ layout->fb_height = vdisplay;
+
+ middle = vdisplay / 2;
+ box_init(&layout->left, 0, 0, hdisplay, middle);
+ box_init(&layout->right,
+ 0, middle, hdisplay, vdisplay - middle);
+ break;
+ case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
+ layout->fb_width = hdisplay;
+ layout->fb_height = vdisplay;
+
+ middle = hdisplay / 2;
+ box_init(&layout->left, 0, 0, middle, vdisplay);
+ box_init(&layout->right,
+ middle, 0, hdisplay - middle, vdisplay);
+ break;
+ case DRM_MODE_FLAG_3D_FRAME_PACKING:
+ {
+ int vactive_space = mode->vtotal - vdisplay;
+
+ layout->fb_width = hdisplay;
+ layout->fb_height = 2 * vdisplay + vactive_space;
+
+ box_init(&layout->left,
+ 0, 0, hdisplay, vdisplay);
+ box_init(&layout->right,
+ 0, vdisplay + vactive_space, hdisplay, vdisplay);
+ break;
+ }
+ default:
+ igt_assert(0);
+ }
+}
+
+/**
+ * igt_create_stereo_fb:
+ * @drm_fd: open i915 drm file descriptor
+ * @mode: A stereo 3D mode.
+ * @format: drm fourcc pixel format code
+ * @tiling: tiling layout of the framebuffer
+ *
+ * Create a framebuffer for use with the stereo 3D mode specified by @mode.
+ *
+ * Returns:
+ * The kms id of the created framebuffer on success or a negative error code on
+ * failure.
+ */
+unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
+ uint32_t format, unsigned int tiling)
+{
+ struct stereo_fb_layout layout;
+ cairo_t *cr;
+ uint32_t fb_id;
+ struct igt_fb fb;
+
+ stereo_fb_layout_from_mode(&layout, mode);
+ fb_id = igt_create_fb(drm_fd, layout.fb_width, layout.fb_height, format,
+ tiling, &fb);
+ cr = igt_get_cairo_ctx(drm_fd, &fb);
+
+ igt_paint_image(cr, IGT_DATADIR"/1080p-left.png",
+ layout.left.x, layout.left.y,
+ layout.left.width, layout.left.height);
+ igt_paint_image(cr, IGT_DATADIR"/1080p-right.png",
+ layout.right.x, layout.right.y,
+ layout.right.width, layout.right.height);
+
+ cairo_destroy(cr);
+
+ return fb_id;
+}
+
static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
{
struct format_desc_struct *f;
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 4295df9a..e6f72e95 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -75,6 +75,8 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
uint32_t format, unsigned int tiling,
double r, double g, double b,
struct igt_fb *fb /* out */);
+unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
+ uint32_t format, unsigned int tiling);
void igt_remove_fb(int fd, struct igt_fb *fb);
/* cairo-based painting */