<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Michel,</p>
<p><br>
</p>
<p>Grep [yuq].</p>
<p><br>
</p>
<p>Regards,</p>
<p>Qiang</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr style="display:inline-block; width:98%" tabindex="-1">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Michel Dänzer <michel@daenzer.net><br>
<b>Sent:</b> Wednesday, June 8, 2016 4:45 PM<br>
<b>To:</b> xorg-driver-ati@lists.x.org<br>
<b>Cc:</b> Yu, Qiang<br>
<b>Subject:</b> [PATCH xf86-video-amdgpu 5/6] Move DRI2's local fixup_glamor helper to amdgpu_glamor_set_pixmap_bo</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">From: Michel Dänzer <michel.daenzer@amd.com><br>
<br>
So it can be used outside of the DRI2 code.<br>
<br>
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com><br>
---<br>
 src/amdgpu_dri2.c   | 50 +-------------------------------------------------<br>
 src/amdgpu_glamor.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++<br>
 src/amdgpu_glamor.h |  1 +<br>
 3 files changed, 51 insertions(+), 49 deletions(-)<br>
<br>
diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c<br>
index 5f978c9..ec63904 100644<br>
--- a/src/amdgpu_dri2.c<br>
+++ b/src/amdgpu_dri2.c<br>
@@ -98,54 +98,6 @@ amdgpu_get_flink_name(AMDGPUEntPtr pAMDGPUEnt, PixmapPtr pixmap, uint32_t *name)<br>
         return TRUE;<br>
 }<br>
 <br>
-static PixmapPtr fixup_glamor(DrawablePtr drawable, PixmapPtr pixmap)<br>
-{<br>
-       PixmapPtr old = get_drawable_pixmap(drawable);<br>
-       ScreenPtr screen = drawable->pScreen;<br>
-       struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);<br>
-       GCPtr gc;<br>
-<br>
-       /* With a glamor pixmap, 2D pixmaps are created in texture<br>
-        * and without a static BO attached to it. To support DRI,<br>
-        * we need to create a new textured-drm pixmap and<br>
-        * need to copy the original content to this new textured-drm<br>
-        * pixmap, and then convert the old pixmap to a coherent<br>
-        * textured-drm pixmap which has a valid BO attached to it<br>
-        * and also has a valid texture, thus both glamor and DRI2<br>
-        * can access it.<br>
-        *<br>
-        */<br>
-<br>
-       /* Copy the current contents of the pixmap to the bo. */<br>
-       gc = GetScratchGC(drawable->depth, screen);<br>
-       if (gc) {<br>
-               ValidateGC(&pixmap->drawable, gc);<br>
-               gc->ops->CopyArea(&old->drawable, &pixmap->drawable,<br>
-                                 gc,<br>
-                                 0, 0,<br>
-                                 old->drawable.width,<br>
-                                 old->drawable.height, 0, 0);<br>
-               FreeScratchGC(gc);<br>
-       }<br>
-<br>
-       amdgpu_set_pixmap_private(pixmap, NULL);<br>
-<br>
-       /* And redirect the pixmap to the new bo (for 3D). */<br>
-       glamor_egl_exchange_buffers(old, pixmap);<br>
-       amdgpu_set_pixmap_private(old, priv);<br>
-       old->refcnt++;<br>
-<br>
-       screen->ModifyPixmapHeader(old,<br>
-                                  old->drawable.width,<br>
-                                  old->drawable.height,<br>
-                                  0, 0, pixmap->devKind, NULL);<br>
-       old->devPrivate.ptr = NULL;<br>
-<br>
-       screen->DestroyPixmap(pixmap);<br>
-<br>
-       return old;<br>
-}<br>
-<br>
 static BufferPtr<br>
 amdgpu_dri2_create_buffer2(ScreenPtr pScreen,<br>
                            DrawablePtr drawable,<br>
@@ -218,7 +170,7 @@ amdgpu_dri2_create_buffer2(ScreenPtr pScreen,<br>
 <br>
         if (pixmap) {<br>
                 if (is_glamor_pixmap)<br>
-                       pixmap = fixup_glamor(drawable, pixmap);<br>
+                       pixmap = amdgpu_glamor_set_pixmap_bo(drawable, pixmap);<br>
 <br>
                 if (!amdgpu_get_flink_name(pAMDGPUEnt, pixmap, &buffers->name))<br>
                         goto error;<br>
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c<br>
index b6ec98f..1159e29 100644<br>
--- a/src/amdgpu_glamor.c<br>
+++ b/src/amdgpu_glamor.c<br>
@@ -272,6 +272,55 @@ fallback_pixmap:<br>
                 return fbCreatePixmap(screen, w, h, depth, usage);<br>
 }<br>
 <br>
+PixmapPtr<br>
+amdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap)<br>
+{<br>
+       PixmapPtr old = get_drawable_pixmap(drawable);<br>
+       ScreenPtr screen = drawable->pScreen;<br>
+       struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);<br>
+       GCPtr gc;<br>
+<br>
+       /* With a glamor pixmap, 2D pixmaps are created in texture<br>
+        * and without a static BO attached to it. To support DRI,<br>
+        * we need to create a new textured-drm pixmap and<br>
+        * need to copy the original content to this new textured-drm<br>
+        * pixmap, and then convert the old pixmap to a coherent<br>
+        * textured-drm pixmap which has a valid BO attached to it<br>
+        * and also has a valid texture, thus both glamor and DRI2<br>
+        * can access it.<br>
+        *<br>
+        */<br>
+<br>
+       /* Copy the current contents of the pixmap to the bo. */<br>
+       gc = GetScratchGC(drawable->depth, screen);<br>
+       if (gc) {<br>
+               ValidateGC(&pixmap->drawable, gc);<br>
+               gc->ops->CopyArea(&old->drawable, &pixmap->drawable,<br>
+                                 gc,<br>
+                                 0, 0,<br>
+                                 old->drawable.width,<br>
+                                 old->drawable.height, 0, 0);<br>
+               FreeScratchGC(gc);<br>
+       }<br>
+<br>
+       amdgpu_set_pixmap_private(pixmap, NULL);<br>
+<br>
+       /* And redirect the pixmap to the new bo (for 3D). */<br>
+       glamor_egl_exchange_buffers(old, pixmap);<br>
+       amdgpu_set_pixmap_private(old, priv);</div>
<div class="PlainText">[yuq] this set the old pixmap with new priv, but the old priv is not freed. We can</div>
<div class="PlainText">also switch the priv to make it freed in the DestroyPixmap callback.</div>
<div class="PlainText"><br>
+       old->refcnt++;</div>
<div class="PlainText">[yuq] Why increase the refcnt of the old pixmap?</div>
<div class="PlainText"><br>
+<br>
+       screen->ModifyPixmapHeader(old,<br>
+                                  old->drawable.width,<br>
+                                  old->drawable.height,<br>
+                                  0, 0, pixmap->devKind, NULL);<br>
+       old->devPrivate.ptr = NULL;<br>
+<br>
+       screen->DestroyPixmap(pixmap);<br>
+<br>
+       return old;<br>
+}<br>
+<br>
 #ifdef AMDGPU_PIXMAP_SHARING<br>
 <br>
 static Bool<br>
diff --git a/src/amdgpu_glamor.h b/src/amdgpu_glamor.h<br>
index 77e0c21..05ca5cf 100644<br>
--- a/src/amdgpu_glamor.h<br>
+++ b/src/amdgpu_glamor.h<br>
@@ -71,6 +71,7 @@ void amdgpu_glamor_finish(ScrnInfoPtr pScrn);<br>
 Bool<br>
 amdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_pixmap *priv);<br>
 void amdgpu_glamor_exchange_buffers(PixmapPtr src, PixmapPtr dst);<br>
+PixmapPtr amdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap);<br>
 <br>
 XF86VideoAdaptorPtr amdgpu_glamor_xv_init(ScreenPtr pScreen, int num_adapt);<br>
 <br>
-- <br>
2.8.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>