Commit a1e66a91 authored by Siarhei Siamashka's avatar Siarhei Siamashka
Browse files

DRI2: Rely less on the information from DRI2BufferRec



When moving further to our own DRI2 buffers bookkeeping, we can't
really trust the information from DRI2BufferRec anymore. So just add
a copy of all the missing bits of information to UMPBufferInfoRec
and use it instead.
Signed-off-by: default avatarSiarhei Siamashka <siarhei.siamashka@gmail.com>
parent 92b4c2cb
...@@ -187,9 +187,6 @@ MigratePixmapToUMP(PixmapPtr pPixmap) ...@@ -187,9 +187,6 @@ MigratePixmapToUMP(PixmapPtr pPixmap)
static void UpdateOverlay(ScreenPtr pScreen); static void UpdateOverlay(ScreenPtr pScreen);
typedef UMPBufferInfoRec MaliDRI2BufferPrivateRec;
typedef UMPBufferInfoPtr MaliDRI2BufferPrivatePtr;
static void unref_ump_buffer_info(UMPBufferInfoPtr umpbuf) static void unref_ump_buffer_info(UMPBufferInfoPtr umpbuf)
{ {
if (--umpbuf->refcount <= 0) { if (--umpbuf->refcount <= 0) {
...@@ -207,6 +204,17 @@ static void unref_ump_buffer_info(UMPBufferInfoPtr umpbuf) ...@@ -207,6 +204,17 @@ static void unref_ump_buffer_info(UMPBufferInfoPtr umpbuf)
} }
} }
/* Verify and fixup the DRI2Buffer before returning it to the X server */
static DRI2Buffer2Ptr validate_dri2buf(DRI2Buffer2Ptr dri2buf)
{
UMPBufferInfoPtr umpbuf = (UMPBufferInfoPtr)dri2buf->driverPrivate;
umpbuf->secure_id = dri2buf->name;
umpbuf->pitch = dri2buf->pitch;
umpbuf->cpp = dri2buf->cpp;
umpbuf->offs = dri2buf->flags;
return dri2buf;
}
static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
unsigned int attachment, unsigned int attachment,
unsigned int format) unsigned int format)
...@@ -214,7 +222,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -214,7 +222,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
ScreenPtr pScreen = pDraw->pScreen; ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
DRI2Buffer2Ptr buffer; DRI2Buffer2Ptr buffer;
MaliDRI2BufferPrivatePtr privates; UMPBufferInfoPtr privates;
ump_handle handle; ump_handle handle;
SunxiMaliDRI2 *private = SUNXI_MALI_UMP_DRI2(pScrn); SunxiMaliDRI2 *private = SUNXI_MALI_UMP_DRI2(pScrn);
sunxi_disp_t *disp = SUNXI_DISP(pScrn); sunxi_disp_t *disp = SUNXI_DISP(pScrn);
...@@ -257,7 +265,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -257,7 +265,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
pDraw, buffer, privates, attachment, buffer->name, buffer->flags, pDraw, buffer, privates, attachment, buffer->name, buffer->flags,
privates->width, privates->height, buffer->cpp, privates->depth); privates->width, privates->height, buffer->cpp, privates->depth);
return buffer; return validate_dri2buf(buffer);
} }
if (!(privates = calloc(1, sizeof *privates))) { if (!(privates = calloc(1, sizeof *privates))) {
...@@ -287,7 +295,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -287,7 +295,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
privates->handle = UMP_INVALID_MEMORY_HANDLE; privates->handle = UMP_INVALID_MEMORY_HANDLE;
privates->addr = NULL; privates->addr = NULL;
buffer->name = private->ump_null_secure_id; buffer->name = private->ump_null_secure_id;
return buffer; return validate_dri2buf(buffer);
} }
/* We could not allocate disp layer or get framebuffer secure id */ /* We could not allocate disp layer or get framebuffer secure id */
...@@ -334,7 +342,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -334,7 +342,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
privates->handle = UMP_INVALID_MEMORY_HANDLE; privates->handle = UMP_INVALID_MEMORY_HANDLE;
privates->addr = NULL; privates->addr = NULL;
buffer->name = private->ump_null_secure_id; buffer->name = private->ump_null_secure_id;
return buffer; return validate_dri2buf(buffer);
} }
if (can_use_overlay) { if (can_use_overlay) {
...@@ -369,7 +377,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -369,7 +377,7 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
DebugMsg("Reuse the already allocated UMP buffer %p, ump=%d\n", DebugMsg("Reuse the already allocated UMP buffer %p, ump=%d\n",
privates, buffer->name); privates, buffer->name);
return buffer; return validate_dri2buf(buffer);
} }
/* Allocate UMP memory buffer */ /* Allocate UMP memory buffer */
...@@ -405,25 +413,25 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw, ...@@ -405,25 +413,25 @@ static DRI2Buffer2Ptr MaliDRI2CreateBuffer(DrawablePtr pDraw,
pDraw, buffer, privates, attachment, buffer->name, buffer->flags, pDraw, buffer, privates, attachment, buffer->name, buffer->flags,
privates->width, privates->height, buffer->cpp, privates->depth); privates->width, privates->height, buffer->cpp, privates->depth);
return buffer; return validate_dri2buf(buffer);
} }
static void MaliDRI2DestroyBuffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer) static void MaliDRI2DestroyBuffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer)
{ {
MaliDRI2BufferPrivatePtr privates; UMPBufferInfoPtr privates;
ScreenPtr pScreen = pDraw->pScreen; ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
SunxiMaliDRI2 *drvpriv = SUNXI_MALI_UMP_DRI2(pScrn); SunxiMaliDRI2 *drvpriv = SUNXI_MALI_UMP_DRI2(pScrn);
if (drvpriv->pOverlayDirtyDRI2Buf == buffer) if (drvpriv->pOverlayDirtyUMP == buffer->driverPrivate)
drvpriv->pOverlayDirtyDRI2Buf = NULL; drvpriv->pOverlayDirtyUMP = NULL;
DebugMsg("DRI2DestroyBuffer %s=%p, buf=%p:%p, att=%d\n", DebugMsg("DRI2DestroyBuffer %s=%p, buf=%p:%p, att=%d\n",
pDraw->type == DRAWABLE_WINDOW ? "win" : "pix", pDraw->type == DRAWABLE_WINDOW ? "win" : "pix",
pDraw, buffer, buffer->driverPrivate, buffer->attachment); pDraw, buffer, buffer->driverPrivate, buffer->attachment);
if (buffer != NULL) { if (buffer != NULL) {
privates = (MaliDRI2BufferPrivatePtr)buffer->driverPrivate; privates = (UMPBufferInfoPtr)buffer->driverPrivate;
unref_ump_buffer_info(privates); unref_ump_buffer_info(privates);
free(buffer); free(buffer);
} }
...@@ -432,31 +440,29 @@ static void MaliDRI2DestroyBuffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer) ...@@ -432,31 +440,29 @@ static void MaliDRI2DestroyBuffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer)
/* Do ordinary copy */ /* Do ordinary copy */
static void MaliDRI2CopyRegion_copy(DrawablePtr pDraw, static void MaliDRI2CopyRegion_copy(DrawablePtr pDraw,
RegionPtr pRegion, RegionPtr pRegion,
DRI2BufferPtr pDstBuffer, UMPBufferInfoPtr umpbuf)
DRI2BufferPtr pSrcBuffer)
{ {
GCPtr pGC; GCPtr pGC;
RegionPtr copyRegion; RegionPtr copyRegion;
ScreenPtr pScreen = pDraw->pScreen; ScreenPtr pScreen = pDraw->pScreen;
MaliDRI2BufferPrivatePtr privates; UMPBufferInfoPtr privates;
PixmapPtr pScratchPixmap; PixmapPtr pScratchPixmap;
privates = (MaliDRI2BufferPrivatePtr)pSrcBuffer->driverPrivate;
#ifdef HAVE_LIBUMP_CACHE_CONTROL #ifdef HAVE_LIBUMP_CACHE_CONTROL
if (privates->handle != UMP_INVALID_MEMORY_HANDLE) { if (umpbuf->handle != UMP_INVALID_MEMORY_HANDLE) {
/* That's a normal UMP allocation, not a wrapped framebuffer */ /* That's a normal UMP allocation, not a wrapped framebuffer */
ump_cache_operations_control(UMP_CACHE_OP_START); ump_cache_operations_control(UMP_CACHE_OP_START);
ump_switch_hw_usage_secure_id(pSrcBuffer->name, UMP_USED_BY_CPU); ump_switch_hw_usage_secure_id(umpbuf->secure_id, UMP_USED_BY_CPU);
ump_cache_operations_control(UMP_CACHE_OP_FINISH); ump_cache_operations_control(UMP_CACHE_OP_FINISH);
} }
#endif #endif
pGC = GetScratchGC(pDraw->depth, pScreen); pGC = GetScratchGC(pDraw->depth, pScreen);
pScratchPixmap = GetScratchPixmapHeader(pScreen, pScratchPixmap = GetScratchPixmapHeader(pScreen,
privates->width, privates->height, umpbuf->width, umpbuf->height,
privates->depth, pSrcBuffer->cpp * 8, umpbuf->depth, umpbuf->cpp * 8,
pSrcBuffer->pitch, umpbuf->pitch,
privates->addr + pSrcBuffer->flags); umpbuf->addr + umpbuf->offs);
copyRegion = REGION_CREATE(pScreen, NULL, 0); copyRegion = REGION_CREATE(pScreen, NULL, 0);
REGION_COPY(pScreen, copyRegion, pRegion); REGION_COPY(pScreen, copyRegion, pRegion);
(*pGC->funcs->ChangeClip)(pGC, CT_REGION, copyRegion, 0); (*pGC->funcs->ChangeClip)(pGC, CT_REGION, copyRegion, 0);
...@@ -467,10 +473,10 @@ static void MaliDRI2CopyRegion_copy(DrawablePtr pDraw, ...@@ -467,10 +473,10 @@ static void MaliDRI2CopyRegion_copy(DrawablePtr pDraw,
FreeScratchGC(pGC); FreeScratchGC(pGC);
#ifdef HAVE_LIBUMP_CACHE_CONTROL #ifdef HAVE_LIBUMP_CACHE_CONTROL
if (privates->handle != UMP_INVALID_MEMORY_HANDLE) { if (umpbuf->handle != UMP_INVALID_MEMORY_HANDLE) {
/* That's a normal UMP allocation, not a wrapped framebuffer */ /* That's a normal UMP allocation, not a wrapped framebuffer */
ump_cache_operations_control(UMP_CACHE_OP_START); ump_cache_operations_control(UMP_CACHE_OP_START);
ump_switch_hw_usage_secure_id(pSrcBuffer->name, UMP_USED_BY_MALI); ump_switch_hw_usage_secure_id(umpbuf->secure_id, UMP_USED_BY_MALI);
ump_cache_operations_control(UMP_CACHE_OP_FINISH); ump_cache_operations_control(UMP_CACHE_OP_FINISH);
} }
#endif #endif
...@@ -481,13 +487,12 @@ static void FlushOverlay(ScreenPtr pScreen) ...@@ -481,13 +487,12 @@ static void FlushOverlay(ScreenPtr pScreen)
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
SunxiMaliDRI2 *self = SUNXI_MALI_UMP_DRI2(pScrn); SunxiMaliDRI2 *self = SUNXI_MALI_UMP_DRI2(pScrn);
if (self->pOverlayWin && self->pOverlayDirtyDRI2Buf) { if (self->pOverlayWin && self->pOverlayDirtyUMP) {
DebugMsg("Flushing overlay content from DRI2 buffer to window\n"); DebugMsg("Flushing overlay content from DRI2 buffer to window\n");
MaliDRI2CopyRegion_copy((DrawablePtr)self->pOverlayWin, MaliDRI2CopyRegion_copy((DrawablePtr)self->pOverlayWin,
&pScreen->root->winSize, &pScreen->root->winSize,
self->pOverlayDirtyDRI2Buf, self->pOverlayDirtyUMP);
self->pOverlayDirtyDRI2Buf); self->pOverlayDirtyUMP = NULL;
self->pOverlayDirtyDRI2Buf = NULL;
} }
} }
...@@ -499,7 +504,7 @@ static void MaliDRI2CopyRegion(DrawablePtr pDraw, ...@@ -499,7 +504,7 @@ static void MaliDRI2CopyRegion(DrawablePtr pDraw,
ScreenPtr pScreen = pDraw->pScreen; ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
SunxiMaliDRI2 *drvpriv = SUNXI_MALI_UMP_DRI2(pScrn); SunxiMaliDRI2 *drvpriv = SUNXI_MALI_UMP_DRI2(pScrn);
MaliDRI2BufferPrivatePtr bufpriv = (MaliDRI2BufferPrivatePtr)pSrcBuffer->driverPrivate; UMPBufferInfoPtr bufpriv = (UMPBufferInfoPtr)pSrcBuffer->driverPrivate;
sunxi_disp_t *disp = SUNXI_DISP(xf86Screens[pScreen->myNum]); sunxi_disp_t *disp = SUNXI_DISP(xf86Screens[pScreen->myNum]);
if (!bufpriv->addr) if (!bufpriv->addr)
...@@ -508,13 +513,13 @@ static void MaliDRI2CopyRegion(DrawablePtr pDraw, ...@@ -508,13 +513,13 @@ static void MaliDRI2CopyRegion(DrawablePtr pDraw,
UpdateOverlay(pScreen); UpdateOverlay(pScreen);
if (!drvpriv->bOverlayWinEnabled || bufpriv->handle != UMP_INVALID_MEMORY_HANDLE) { if (!drvpriv->bOverlayWinEnabled || bufpriv->handle != UMP_INVALID_MEMORY_HANDLE) {
MaliDRI2CopyRegion_copy(pDraw, pRegion, pDstBuffer, pSrcBuffer); MaliDRI2CopyRegion_copy(pDraw, pRegion, bufpriv);
drvpriv->pOverlayDirtyDRI2Buf = NULL; drvpriv->pOverlayDirtyUMP = NULL;
return; return;
} }
/* Mark the overlay as "dirty" and remember the last up to date DRI2 buffer */ /* Mark the overlay as "dirty" and remember the last up to date UMP buffer */
drvpriv->pOverlayDirtyDRI2Buf = pSrcBuffer; drvpriv->pOverlayDirtyUMP = bufpriv;
/* Activate the overlay */ /* Activate the overlay */
sunxi_layer_set_output_window(disp, pDraw->x, pDraw->y, pDraw->width, pDraw->height); sunxi_layer_set_output_window(disp, pDraw->x, pDraw->y, pDraw->width, pDraw->height);
...@@ -658,7 +663,7 @@ GetImage(DrawablePtr pDrawable, int x, int y, int w, int h, ...@@ -658,7 +663,7 @@ GetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
SunxiMaliDRI2 *private = SUNXI_MALI_UMP_DRI2(pScrn); SunxiMaliDRI2 *private = SUNXI_MALI_UMP_DRI2(pScrn);
/* FIXME: more precise check */ /* FIXME: more precise check */
if (private->pOverlayDirtyDRI2Buf) if (private->pOverlayDirtyUMP)
FlushOverlay(pScreen); FlushOverlay(pScreen);
if (private->GetImage) { if (private->GetImage) {
......
...@@ -45,6 +45,11 @@ typedef struct ...@@ -45,6 +45,11 @@ typedef struct
int depth; int depth;
size_t width; size_t width;
size_t height; size_t height;
ump_secure_id secure_id;
unsigned int pitch;
unsigned int cpp;
unsigned int offs;
} UMPBufferInfoRec, *UMPBufferInfoPtr; } UMPBufferInfoRec, *UMPBufferInfoPtr;
/* /*
...@@ -87,7 +92,7 @@ typedef struct { ...@@ -87,7 +92,7 @@ typedef struct {
int overlay_y; int overlay_y;
WindowPtr pOverlayWin; WindowPtr pOverlayWin;
void *pOverlayDirtyDRI2Buf; UMPBufferInfoPtr pOverlayDirtyUMP;
Bool bOverlayWinEnabled; Bool bOverlayWinEnabled;
Bool bOverlayWinOverlapped; Bool bOverlayWinOverlapped;
Bool bWalkingAboveOverlayWin; Bool bWalkingAboveOverlayWin;
......
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