]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/omapdrmtest.git/blobdiff - util/util.h
add video buffer lock/unlock API
[glsdk/omapdrmtest.git] / util / util.h
index 33af61deb06f963f724fefffdcbcd8cdd0a235bc..720c11b802cb77f5dddf2a36d00e8095ec62d6eb 100644 (file)
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <omap_drm.h>
 #include <omap_drmif.h>
 
+typedef enum {
+       false = 0,
+       true = 1
+} bool;
+
+#include "list.h"
 
 /* Display Interface:
  *
  */
 
 struct buffer {
-       uint32_t fourcc, width, height, stride;
-       struct omap_bo *bo;
+       uint32_t fourcc, width, height;
+       int nbo;
+       struct omap_bo *bo[4];
+       uint32_t pitches[4];
+       struct list unlocked;
 };
 
 struct display {
        int fd;
        uint32_t width, height;
        struct omap_device *dev;
+       struct list unlocked;
 
        struct buffer ** (*get_buffers)(struct display *disp, uint32_t n);
        struct buffer ** (*get_vid_buffers)(struct display *disp,
                        uint32_t n, uint32_t fourcc, uint32_t w, uint32_t h);
        int (*post_buffer)(struct display *disp, struct buffer *buf);
+       int (*post_vid_buffer)(struct display *disp, struct buffer *buf,
+                       uint32_t x, uint32_t y, uint32_t w, uint32_t h);
 };
 
 /* Print display related help */
@@ -70,12 +83,8 @@ disp_get_buffers(struct display *disp, uint32_t n)
 }
 
 /* Get video/overlay buffers (ie. can be YUV, scaled, etc) */
-static inline struct buffer **
-disp_get_vid_buffers(struct display *disp, uint32_t n,
-               uint32_t fourcc, uint32_t w, uint32_t h)
-{
-       return disp->get_vid_buffers(disp, n, fourcc, w, h);
-}
+struct buffer ** disp_get_vid_buffers(struct display *disp, uint32_t n,
+               uint32_t fourcc, uint32_t w, uint32_t h);
 
 /* flip to / post the specified buffer */
 static inline int
@@ -84,6 +93,25 @@ disp_post_buffer(struct display *disp, struct buffer *buf)
        return disp->post_buffer(disp, buf);
 }
 
+/* flip to / post the specified video buffer */
+static inline int
+disp_post_vid_buffer(struct display *disp, struct buffer *buf,
+               uint32_t x, uint32_t y, uint32_t w, uint32_t h)
+{
+       return disp->post_vid_buffer(disp, buf, x, y, w, h);
+}
+
+/* allocate a buffer from pool created by disp_get_vid_buffers() */
+struct buffer * disp_get_vid_buffer(struct display *disp);
+/* free to video buffer pool */
+void disp_put_vid_buffer(struct display *disp, struct buffer *buf);
+
+/* helper to setup the display for apps that just need video with
+ * no flipchain on the GUI layer
+ */
+struct buffer * disp_get_fb(struct display *disp);
+
+
 /* V4L2 utilities:
  */
 
@@ -93,7 +121,8 @@ struct v4l2;
 void v4l2_usage(void);
 
 /* Open v4l2 (and media0??) XXX */
-struct v4l2 * v4l2_open(int argc, char **argv);
+struct v4l2 * v4l2_open(int argc, char **argv, uint32_t *fourcc,
+               uint32_t *width, uint32_t *height);
 
 /* Share the buffers w/ v4l2 via dmabuf */
 int v4l2_reqbufs(struct v4l2 *v4l2, struct buffer **bufs, uint32_t n);
@@ -127,9 +156,27 @@ void fill(struct buffer *buf, int i);
     (type *)((char *)(ptr) - (char *) &((type *)0)->member)
 #endif
 
-typedef enum {
-       false = 0,
-       true = 1
-} bool;
+#ifndef MIN
+#  define MIN(a,b)     (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#  define MAX(a,b)     (((a) > (b)) ? (a) : (b))
+#endif
+
+/* align x to next highest multiple of 2^n */
+#define ALIGN2(x,n)   (((x) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
+
+#include <sys/time.h>
+static inline long
+mark(long *last)
+{
+       struct timeval t;
+       gettimeofday(&t, NULL);
+       if (last) {
+               return t.tv_usec - *last;
+       }
+       return t.tv_usec;
+}
 
 #endif /* UTIL_H_ */