summaryrefslogtreecommitdiff
path: root/src/sna/sna_video_textured.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-04-09 19:13:46 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-05-21 11:14:52 +0100
commit195a51353c3af7bd253227da5f759f06cea01f73 (patch)
treeefd5f87531d8e5355b35be4bce48136061d2b897 /src/sna/sna_video_textured.c
parent8e42637050275945200797538a34c13c90b295cc (diff)
sna/video: Convert to a pure Xv backend
This is to enable feature work which requires access to Client state. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/sna/sna_video_textured.c')
-rw-r--r--src/sna/sna_video_textured.c257
1 files changed, 127 insertions, 130 deletions
diff --git a/src/sna/sna_video_textured.c b/src/sna/sna_video_textured.c
index 8278606c..29f4d9d4 100644
--- a/src/sna/sna_video_textured.c
+++ b/src/sna/sna_video_textured.c
@@ -34,29 +34,21 @@
#include <xf86xv.h>
#include <X11/extensions/Xv.h>
-#ifdef SNA_XVMC
-#define _SNA_XVMC_SERVER_
-#include "sna_video_hwmc.h"
-#endif
-
#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, true)
static Atom xvBrightness, xvContrast, xvSyncToVblank;
-#define NUM_FORMATS 3
-static const XF86VideoFormatRec Formats[NUM_FORMATS] = {
+static const XvFormatRec Formats[] = {
{15, TrueColor}, {16, TrueColor}, {24, TrueColor}
};
-//#define NUM_TEXTURED_ATTRIBUTES 3
-#define NUM_TEXTURED_ATTRIBUTES 1
-static const XF86AttributeRec TexturedAttributes[] = {
+static const XvAttributeRec Attributes[] = {
{XvSettable | XvGettable, -1, 1, "XV_SYNC_TO_VBLANK"},
- {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
- {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
+ //{XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
+ //{XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
};
-static const XF86ImageRec Images[] = {
+static const XvImageRec Images[] = {
XVIMAGE_YUY2,
XVIMAGE_YV12,
XVIMAGE_I420,
@@ -64,30 +56,27 @@ static const XF86ImageRec Images[] = {
XVMC_YUV,
};
-static void sna_video_textured_stop(ScrnInfoPtr scrn,
- pointer data,
- Bool shutdown)
+static int sna_video_textured_stop(ClientPtr client,
+ XvPortPtr port,
+ DrawablePtr draw)
{
- struct sna *sna = to_sna(scrn);
- struct sna_video *video = data;
+ struct sna_video *video = port->devPriv.ptr;
DBG(("%s()\n", __FUNCTION__));
- REGION_EMPTY(scrn->pScreen, &video->clip);
-
- if (!shutdown)
- return;
+ RegionUninit(&video->clip);
+ sna_video_free_buffers(video);
- sna_video_free_buffers(sna, video);
+ return Success;
}
static int
-sna_video_textured_set_attribute(ScrnInfoPtr scrn,
+sna_video_textured_set_attribute(ClientPtr client,
+ XvPortPtr port,
Atom attribute,
- INT32 value,
- pointer data)
+ INT32 value)
{
- struct sna_video *video = data;
+ struct sna_video *video = port->devPriv.ptr;
if (attribute == xvBrightness) {
if (value < -128 || value > 127)
@@ -111,12 +100,12 @@ sna_video_textured_set_attribute(ScrnInfoPtr scrn,
}
static int
-sna_video_textured_get_attribute(ScrnInfoPtr scrn,
+sna_video_textured_get_attribute(ClientPtr client,
+ XvPortPtr port,
Atom attribute,
- INT32 *value,
- pointer data)
+ INT32 *value)
{
- struct sna_video *video = data;
+ struct sna_video *video = port->devPriv.ptr;
if (attribute == xvBrightness)
*value = video->brightness;
@@ -130,14 +119,14 @@ sna_video_textured_get_attribute(ScrnInfoPtr scrn,
return Success;
}
-static void
-sna_video_textured_best_size(ScrnInfoPtr scrn,
- Bool motion,
- short vid_w, short vid_h,
- short drw_w, short drw_h,
+static int
+sna_video_textured_best_size(ClientPtr client,
+ XvPortPtr port,
+ CARD8 motion,
+ CARD16 vid_w, CARD16 vid_h,
+ CARD16 drw_w, CARD16 drw_h,
unsigned int *p_w,
- unsigned int *p_h,
- pointer data)
+ unsigned int *p_h)
{
if (vid_w > (drw_w << 1))
drw_w = vid_w >> 1;
@@ -146,6 +135,8 @@ sna_video_textured_best_size(ScrnInfoPtr scrn,
*p_w = drw_w;
*p_h = drw_h;
+
+ return Success;
}
/*
@@ -162,40 +153,49 @@ sna_video_textured_best_size(ScrnInfoPtr scrn,
* compositing. It's a new argument to the function in the 1.1 server.
*/
static int
-sna_video_textured_put_image(ScrnInfoPtr scrn,
- short src_x, short src_y,
- short drw_x, short drw_y,
- short src_w, short src_h,
- short drw_w, short drw_h,
- int id, unsigned char *buf,
- short width, short height,
- Bool sync, RegionPtr clip, pointer data,
- DrawablePtr drawable)
+sna_video_textured_put_image(ClientPtr client,
+ DrawablePtr draw,
+ XvPortPtr port,
+ GCPtr gc,
+ INT16 src_x, INT16 src_y,
+ CARD16 src_w, CARD16 src_h,
+ INT16 drw_x, INT16 drw_y,
+ CARD16 drw_w, CARD16 drw_h,
+ XvImagePtr format,
+ unsigned char *buf,
+ Bool sync,
+ CARD16 width, CARD16 height)
{
- struct sna *sna = to_sna(scrn);
- struct sna_video *video = data;
+ struct sna_video *video = port->devPriv.ptr;
+ struct sna *sna = video->sna;
struct sna_video_frame frame;
- PixmapPtr pixmap = get_drawable_pixmap(drawable);
+ PixmapPtr pixmap = get_drawable_pixmap(draw);
BoxRec dstBox;
+ RegionRec clip;
xf86CrtcPtr crtc;
bool flush = false;
bool ret;
+ clip.extents.x1 = draw->x + drw_x;
+ clip.extents.y1 = draw->y + drw_y;
+ clip.extents.x2 = clip.extents.x1 + drw_w;
+ clip.extents.y2 = clip.extents.y1 + drw_h;
+ clip.data = NULL;
+
+ RegionIntersect(&clip, &clip, gc->pCompositeClip);
+ if (!RegionNotEmpty(&clip))
+ return Success;
+
DBG(("%s: src=(%d, %d),(%d, %d), dst=(%d, %d),(%d, %d), id=%d, sizep=%dx%d, sync?=%d\n",
__FUNCTION__,
src_x, src_y, src_w, src_h,
drw_x, drw_y, drw_w, drw_h,
- id, width, height, sync));
+ format->id, width, height, sync));
DBG(("%s: region %d:(%d, %d), (%d, %d)\n", __FUNCTION__,
- RegionNumRects(clip),
- clip->extents.x1, clip->extents.y1,
- clip->extents.x2, clip->extents.y2));
-
- if (buf == 0) {
- DBG(("%s: garbage video buffer\n", __FUNCTION__));
- return BadAlloc;
- }
+ RegionNumRects(&clip),
+ clip.extents.x1, clip.extents.y1,
+ clip.extents.x2, clip.extents.y2));
if (!sna_pixmap_move_to_gpu(pixmap, MOVE_READ | MOVE_WRITE)) {
DBG(("%s: attempting to render to a non-GPU pixmap\n",
@@ -203,16 +203,16 @@ sna_video_textured_put_image(ScrnInfoPtr scrn,
return BadAlloc;
}
- sna_video_frame_init(sna, video, id, width, height, &frame);
+ sna_video_frame_init(video, format->id, width, height, &frame);
- if (!sna_video_clip_helper(scrn, video, &frame,
+ if (!sna_video_clip_helper(sna->scrn, video, &frame,
&crtc, &dstBox,
- src_x, src_y, drw_x, drw_y,
+ src_x, src_y, drw_x + draw->x, drw_y + draw->y,
src_w, src_h, drw_w, drw_h,
- clip))
+ &clip))
return Success;
- if (xvmc_passthrough(id)) {
+ if (xvmc_passthrough(format->id)) {
DBG(("%s: using passthough, name=%d\n",
__FUNCTION__, *(uint32_t *)buf));
@@ -228,26 +228,26 @@ sna_video_textured_put_image(ScrnInfoPtr scrn,
frame.image.x2 = frame.width;
frame.image.y2 = frame.height;
} else {
- if (!sna_video_copy_data(sna, video, &frame, buf)) {
+ if (!sna_video_copy_data(video, &frame, buf)) {
DBG(("%s: failed to copy frame\n", __FUNCTION__));
kgem_bo_destroy(&sna->kgem, frame.bo);
return BadAlloc;
}
}
- if (crtc && video->SyncToVblank != 0 &&
+ if (crtc && sync && video->SyncToVblank != 0 &&
sna_pixmap_is_scanout(sna, pixmap)) {
kgem_set_mode(&sna->kgem, KGEM_RENDER, sna_pixmap(pixmap)->gpu_bo);
flush = sna_wait_for_scanline(sna, pixmap, crtc,
- &clip->extents);
+ &clip.extents);
}
ret = Success;
- if (!sna->render.video(sna, video, &frame, clip, pixmap)) {
+ if (!sna->render.video(sna, video, &frame, &clip, pixmap)) {
DBG(("%s: failed to render video\n", __FUNCTION__));
ret = BadAlloc;
} else
- DamageDamageRegion(drawable, clip);
+ DamageDamageRegion(draw, &clip);
kgem_bo_destroy(&sna->kgem, frame.bo);
@@ -257,14 +257,19 @@ sna_video_textured_put_image(ScrnInfoPtr scrn,
if (flush)
kgem_submit(&sna->kgem);
+ RegionUninit(&clip);
+
return ret;
}
static int
-sna_video_textured_query(ScrnInfoPtr scrn,
- int id,
- unsigned short *w, unsigned short *h,
- int *pitches, int *offsets)
+sna_video_textured_query(ClientPtr client,
+ XvPortPtr port,
+ XvImagePtr format,
+ unsigned short *w,
+ unsigned short *h,
+ int *pitches,
+ int *offsets)
{
int size, tmp;
@@ -277,7 +282,7 @@ sna_video_textured_query(ScrnInfoPtr scrn,
if (offsets)
offsets[0] = 0;
- switch (id) {
+ switch (format->id) {
/* IA44 is for XvMC only */
case FOURCC_IA44:
case FOURCC_AI44:
@@ -322,101 +327,93 @@ sna_video_textured_query(ScrnInfoPtr scrn,
return size;
}
-XF86VideoAdaptorPtr sna_video_textured_setup(struct sna *sna,
- ScreenPtr screen)
+void sna_video_textured_setup(struct sna *sna, ScreenPtr screen)
{
- XF86VideoAdaptorPtr adaptor;
- XF86AttributePtr attrs;
+ XvAdaptorPtr adaptor;
struct sna_video *video;
- DevUnion *devUnions;
int nports = 16, i;
if (!sna->render.video) {
- xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+ xf86DrvMsg(sna->scrn->scrnIndex, X_INFO,
"Textured video not supported on this hardware\n");
- return NULL;
+ return;
}
if (wedged(sna)) {
xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
"cannot enable XVideo whilst the GPU is wedged\n");
- return NULL;
+ return;
}
- adaptor = calloc(1, sizeof(XF86VideoAdaptorRec));
+ adaptor = sna_xv_adaptor_alloc(sna);
+ if (adaptor == NULL)
+ return;
+
video = calloc(nports, sizeof(struct sna_video));
- devUnions = calloc(nports, sizeof(DevUnion));
-#if NUM_TEXTURED_ATTRIBUTES
- attrs = calloc(NUM_TEXTURED_ATTRIBUTES, sizeof(XF86AttributeRec));
- if (adaptor == NULL ||
- video == NULL ||
- devUnions == NULL ||
- attrs == NULL) {
- free(adaptor);
- free(video);
- free(devUnions);
- free(attrs);
- return NULL;
- }
-#else
- if (adaptor == NULL || video == NULL || devUnions == NULL) {
- free(adaptor);
- free(video);
- free(devUnions);
- return NULL;
+ if ( video == NULL) {
+ sna->xv.num_adaptors--;
+ return;
}
- attrs = NULL;
-#endif
- adaptor->type = XvWindowMask | XvInputMask | XvImageMask;
- adaptor->flags = 0;
+ adaptor->type = XvInputMask | XvImageMask;
+ adaptor->pScreen = screen;
adaptor->name = "Intel(R) Textured Video";
adaptor->nEncodings = 1;
- adaptor->pEncodings = xnfalloc(sizeof(XF86VideoEncodingRec));
+ adaptor->pEncodings = xnfalloc(sizeof(XvEncodingRec));
adaptor->pEncodings[0].id = 0;
+ adaptor->pEncodings[0].pScreen = screen;
adaptor->pEncodings[0].name = "XV_IMAGE";
adaptor->pEncodings[0].width = sna->render.max_3d_size;
adaptor->pEncodings[0].height = sna->render.max_3d_size;
adaptor->pEncodings[0].rate.numerator = 1;
adaptor->pEncodings[0].rate.denominator = 1;
- adaptor->nFormats = NUM_FORMATS;
- adaptor->pFormats = (XF86VideoFormatPtr)Formats;
- adaptor->nPorts = nports;
- adaptor->pPortPrivates = devUnions;
- adaptor->nAttributes = NUM_TEXTURED_ATTRIBUTES;
- adaptor->pAttributes = attrs;
- memcpy(attrs, TexturedAttributes,
- NUM_TEXTURED_ATTRIBUTES * sizeof(XF86AttributeRec));
+ adaptor->nFormats = ARRAY_SIZE(Formats);
+ adaptor->pFormats = Formats;
+ adaptor->nAttributes = ARRAY_SIZE(Attributes);
+ adaptor->pAttributes = Attributes;
adaptor->nImages = ARRAY_SIZE(Images);
- adaptor->pImages = (XF86ImagePtr)Images;
- adaptor->PutVideo = NULL;
- adaptor->PutStill = NULL;
- adaptor->GetVideo = NULL;
- adaptor->GetStill = NULL;
- adaptor->StopVideo = sna_video_textured_stop;
- adaptor->SetPortAttribute = sna_video_textured_set_attribute;
- adaptor->GetPortAttribute = sna_video_textured_get_attribute;
- adaptor->QueryBestSize = sna_video_textured_best_size;
- adaptor->PutImage = sna_video_textured_put_image;
- adaptor->QueryImageAttributes = sna_video_textured_query;
+ adaptor->pImages = Images;
+ adaptor->ddAllocatePort = sna_xv_alloc_port;
+ adaptor->ddFreePort = sna_xv_free_port;
+ adaptor->ddPutVideo = NULL;
+ adaptor->ddPutStill = NULL;
+ adaptor->ddGetVideo = NULL;
+ adaptor->ddGetStill = NULL;
+ adaptor->ddStopVideo = sna_video_textured_stop;
+ adaptor->ddSetPortAttribute = sna_video_textured_set_attribute;
+ adaptor->ddGetPortAttribute = sna_video_textured_get_attribute;
+ adaptor->ddQueryBestSize = sna_video_textured_best_size;
+ adaptor->ddPutImage = sna_video_textured_put_image;
+ adaptor->ddQueryImageAttributes = sna_video_textured_query;
+ adaptor->nPorts = nports;
+ adaptor->pPorts = calloc(nports, sizeof(XvPortRec));
for (i = 0; i < nports; i++) {
struct sna_video *v = &video[i];
+ XvPortPtr port = &adaptor->pPorts[i];
+ v->sna = sna;
v->textured = true;
v->alignment = 4;
v->rotation = RR_Rotate_0;
v->SyncToVblank = 1;
- /* gotta uninit this someplace, XXX: shouldn't be necessary for textured */
RegionNull(&v->clip);
- adaptor->pPortPrivates[i].ptr = v;
+ port->id = FakeClientID(0);
+ AddResource(port->id, XvGetRTPort(), port);
+
+ port->pAdaptor = adaptor;
+ port->pNotify = NULL;
+ port->pDraw = NULL;
+ port->client = NULL;
+ port->grab.client = NULL;
+ port->time = currentTime;
+ port->devPriv.ptr = v;
}
+ adaptor->base_id = adaptor->pPorts[0].id;
xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
xvContrast = MAKE_ATOM("XV_CONTRAST");
xvSyncToVblank = MAKE_ATOM("XV_SYNC_TO_VBLANK");
-
- return adaptor;
}