Add reference counting to omap_bo
Add reference counting to omap_bo to avoid freeing a buffer object
during page flip.
diff --git a/src/omap_dri2.c b/src/omap_dri2.c
index 2645aef..8e0f39f 100644
--- a/src/omap_dri2.c
+++ b/src/omap_dri2.c
@@ -362,11 +362,18 @@
OMAPPtr pOMAP = OMAPPTR(pScrn);
DrawablePtr pDraw = NULL;
int status;
- OMAPPixmapPrivPtr dst_priv;
+ OMAPPixmapPrivPtr src_priv, dst_priv;
+ struct omap_bo *old_src_bo, *old_dst_bo;
if (--cmd->swapCount > 0)
return;
+ /* Save the old source bo for unreference below */
+ src_priv = exaGetPixmapDriverPrivate(OMAPBUF(cmd->pSrcBuffer)->pPixmap);
+ dst_priv = exaGetPixmapDriverPrivate(OMAPBUF(cmd->pDstBuffer)->pPixmap);
+ old_src_bo = src_priv->bo;
+ old_dst_bo = dst_priv->bo;
+
if ((cmd->flags & OMAP_SWAP_FAIL) == 0) {
DEBUG_MSG("%s complete: %d -> %d", swap_names[cmd->type],
cmd->pSrcBuffer->attachment, cmd->pDstBuffer->attachment);
@@ -395,6 +402,8 @@
*/
OMAPDRI2DestroyBuffer(pDraw, cmd->pSrcBuffer);
OMAPDRI2DestroyBuffer(pDraw, cmd->pDstBuffer);
+ omap_bo_unreference(old_src_bo);
+ omap_bo_unreference(old_dst_bo);
pOMAP->pending_flips--;
free(cmd);
@@ -476,6 +485,8 @@
src->previous_canflip = new_canflip;
dst->previous_canflip = new_canflip;
+ omap_bo_reference(src_priv->bo);
+ omap_bo_reference(dst_priv->bo);
if (src_fb_id && dst_fb_id && canflip(pDraw) && !(pOMAP->has_resized)) {
/* has_resized: On hotplug the fb size and crtc sizes arent updated
* hence on this event we do a copyb but flip from the next frame