Commit 06d54f63 authored by Xiang, Haihao's avatar Xiang, Haihao

libva: update DRI2 to support swapbuffer

parent 8af77b87
......@@ -35,6 +35,8 @@ struct dri2_drawable
int front_index;
};
static int gsDRI2SwapAvailable;
static struct dri_drawable *
dri2CreateDrawable(VADriverContextP ctx, XID x_drawable)
{
......@@ -68,15 +70,21 @@ dri2SwapBuffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
XserverRegion region;
if (dri2_drawable->has_backbuffer) {
xrect.x = 0;
xrect.y = 0;
xrect.width = dri2_drawable->width;
xrect.height = dri2_drawable->height;
region = XFixesCreateRegion(ctx->x11_dpy, &xrect, 1);
VA_DRI2CopyRegion(ctx->x11_dpy, dri_drawable->x_drawable, region,
DRI2BufferFrontLeft, DRI2BufferBackLeft);
XFixesDestroyRegion(ctx->x11_dpy, region);
if (gsDRI2SwapAvailable) {
CARD64 ret;
VA_DRI2SwapBuffers(ctx->x11_dpy, dri_drawable->x_drawable, 0, 0,
0, &ret);
} else {
xrect.x = 0;
xrect.y = 0;
xrect.width = dri2_drawable->width;
xrect.height = dri2_drawable->height;
region = XFixesCreateRegion(ctx->x11_dpy, &xrect, 1);
VA_DRI2CopyRegion(ctx->x11_dpy, dri_drawable->x_drawable, region,
DRI2BufferFrontLeft, DRI2BufferBackLeft);
XFixesDestroyRegion(ctx->x11_dpy, region);
}
}
}
......@@ -91,7 +99,6 @@ dri2GetRenderingBuffer(VADriverContextP ctx, struct dri_drawable *dri_drawable)
i = 0;
attachments[i++] = __DRI_BUFFER_BACK_LEFT;
attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
buffers = VA_DRI2GetBuffers(ctx->x11_dpy, dri_drawable->x_drawable,
&dri2_drawable->width, &dri2_drawable->height,
attachments, i, &count);
......@@ -179,6 +186,7 @@ isDRI2Connected(VADriverContextP ctx, char **driver_name)
dri_state->swapBuffer = dri2SwapBuffer;
dri_state->getRenderingBuffer = dri2GetRenderingBuffer;
dri_state->close = dri2Close;
gsDRI2SwapAvailable = (minor >= 2);
return True;
......
......@@ -305,3 +305,45 @@ void VA_DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region,
UnlockDisplay(dpy);
SyncHandle();
}
static void
load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor,
CARD64 remainder)
{
req->target_msc_hi = target >> 32;
req->target_msc_lo = target & 0xffffffff;
req->divisor_hi = divisor >> 32;
req->divisor_lo = divisor & 0xffffffff;
req->remainder_hi = remainder >> 32;
req->remainder_lo = remainder & 0xffffffff;
}
static CARD64
vals_to_card64(CARD32 lo, CARD32 hi)
{
return (CARD64)hi << 32 | lo;
}
void VA_DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc,
CARD64 divisor, CARD64 remainder, CARD64 *count)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2SwapBuffersReq *req;
xDRI2SwapBuffersReply rep;
XextSimpleCheckExtension (dpy, info, va_dri2ExtensionName);
LockDisplay(dpy);
GetReq(DRI2SwapBuffers, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2SwapBuffers;
req->drawable = drawable;
load_swap_req(req, target_msc, divisor, remainder);
_XReply(dpy, (xReply *)&rep, 0, xFalse);
*count = vals_to_card64(rep.swap_lo, rep.swap_hi);
UnlockDisplay(dpy);
SyncHandle();
}
......@@ -33,6 +33,7 @@
#ifndef _VA_DRI2_H_
#define _VA_DRI2_H_
#include <X11/Xproto.h>
#include <X11/extensions/Xfixes.h>
#include <X11/Xfuncproto.h>
#include <xf86drm.h>
......@@ -63,9 +64,10 @@ VA_DRI2GetBuffers(Display *dpy, XID drawable,
int *width, int *height,
unsigned int *attachments, int count,
int *outCount);
#if 0
extern void
VA_DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region,
CARD32 dest, CARD32 src);
#endif
CARD32 dest, CARD32 src);
extern void
VA_DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
CARD64 remainder, CARD64 *count);
#endif
......@@ -35,11 +35,11 @@
#define DRI2_NAME "DRI2"
#define DRI2_MAJOR 1
#define DRI2_MINOR 0
#define DRI2_MINOR 2
#define DRI2NumberErrors 0
#define DRI2NumberEvents 0
#define DRI2NumberRequests 7
#define DRI2NumberEvents 2
#define DRI2NumberRequests 13
#define X_DRI2QueryVersion 0
#define X_DRI2Connect 1
......@@ -48,6 +48,12 @@
#define X_DRI2DestroyDrawable 4
#define X_DRI2GetBuffers 5
#define X_DRI2CopyRegion 6
#define X_DRI2GetBuffersWithFormat 7
#define X_DRI2SwapBuffers 8
#define X_DRI2GetMSC 9
#define X_DRI2WaitMSC 10
#define X_DRI2WaitSBC 11
#define X_DRI2SwapInterval 12
typedef struct {
CARD32 attachment B32;
......@@ -190,4 +196,32 @@ typedef struct {
} xDRI2CopyRegionReply;
#define sz_xDRI2CopyRegionReply 32
typedef struct {
CARD8 reqType;
CARD8 dri2ReqType;
CARD16 length B16;
CARD32 drawable B32;
CARD32 target_msc_hi B32;
CARD32 target_msc_lo B32;
CARD32 divisor_hi B32;
CARD32 divisor_lo B32;
CARD32 remainder_hi B32;
CARD32 remainder_lo B32;
} xDRI2SwapBuffersReq;
#define sz_xDRI2SwapBuffersReq 32
typedef struct {
BYTE type; /* X_Reply */
BYTE pad1;
CARD16 sequenceNumber B16;
CARD32 length B32;
CARD32 swap_hi B32;
CARD32 swap_lo B32;
CARD32 pad2 B32;
CARD32 pad3 B32;
CARD32 pad4 B32;
CARD32 pad5 B32;
} xDRI2SwapBuffersReply;
#define sz_xDRI2SwapBuffersReply 32
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment