code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>xorg-video-v4l</Name>
        <Homepage>http://www.x.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>MIT</License>
        <IsA>driver</IsA>
        <Summary>X.Org v4l video driver</Summary>
        <Description>v4l is an Xorg driver for video4linux cards. It provides a Xvideo extension port for video overlay.</Description>
        <Archive sha1sum="7f2212c529a5bcc34f67858a9d0167a0d4848aaa" type="tarbz2">mirrors://xorg/individual/driver/xf86-video-v4l-0.2.0.tar.bz2</Archive>
        <BuildDependencies>
            <Dependency>xorg-server-devel</Dependency>
        </BuildDependencies>
        <Patches>
            <!--<Patch level="1">git-fixes.patch</Patch>-->
            <Patch level="1">xorg-x11-drv-v4l-support_v4l2_only_drivers.patch</Patch>
            <Patch level="1">xf86-video-v4l-0.2.0-build-fix.patch</Patch>
        </Patches>
    </Source>

    <Package>
        <Name>xorg-video-v4l</Name>
        <RuntimeDependencies>
            <Dependency>xorg-server</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib/xorg</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2017-03-11</Date>
            <Version>0.2.0</Version>
            <Comment>rebuild</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="2">
            <Date>2017-02-16</Date>
            <Version>0.2.0</Version>
            <Comment>Release bump.</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>0.2.0</Version>
            <Comment>Release bump.</Comment>
            <Name>Osman Erkan</Name>
            <Email>osman.erkan@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-05-15</Date>
            <Version>0.2.0</Version>
            <Comment>First release</Comment>
            <Name>Osman Erkan</Name>
            <Email>osman.erkan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>xorg-video-v4l</Name>
        <Summary xml:lang="tr">X.Org v4l ekran kartı sürücüsü</Summary>
        <Description xml:lang="tr">v4l, video4linux kartları için Xorg sürücüsü içerir. Video yerpaylaşımı (overlay) için bir Xvideo kapısı sağlar.</Description>
    </Source>
</PISI>

repo_name: ayhanyalcinsoy/main


code:
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/copyleft/gpl.txt.

from pisi.actionsapi import get
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools

WorkDir = "xf86-video-vesa-%s" % get.srcVERSION()

def setup():
    autotools.configure()

def build():
    autotools.make()

def install():
    autotools.install()
    pisitools.dodoc("COPYING", "ChangeLog", "README")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>xorg-video-vesa</Name>
        <Homepage>http://www.x.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>MIT</License>
        <IsA>driver</IsA>
        <Summary>X.Org vesa video driver</Summary>
        <Description>xorg-input-vesa contains the X.Org driver for Generic VESA cards.</Description>
        <Archive sha1sum="99b69044c34292ba062e365c07dcd024462e794b" type="tarbz2">mirrors://xorg/individual/driver/xf86-video-vesa-2.4.0.tar.bz2</Archive>
        <BuildDependencies>
            <Dependency>xorg-server-devel</Dependency>
            <Dependency>util-macros</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>xorg-video-vesa</Name>
        <RuntimeDependencies>
            <Dependency>xorg-server</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib/xorg</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="6">
            <Date>2018-02-16</Date>
            <Version>2.4.0</Version>
            <Comment>Version bump</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="5">
            <Date>2017-09-09</Date>
            <Version>2.3.4</Version>
            <Comment>rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="4">
            <Date>2017-03-11</Date>
            <Version>2.3.4</Version>
            <Comment>Version bump.</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="3">
            <Date>2017-02-16</Date>
            <Version>2.3.4</Version>
            <Comment>Rebuild.</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>2.3.4</Version>
            <Comment>Version bump</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-05-08</Date>
            <Version>2.3.3</Version>
            <Comment>First release</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>xorg-video-vesa</Name>
        <Summary xml:lang="tr">X.Org vesa ekran kartı sürücüsü</Summary>
        <Description xml:lang="tr">xorg-input-vesa, VESA uyumlu ekran kartları için X.Org sürücüsünü içerir.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/copyleft/gpl.txt.

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools

def setup():
    autotools.configure("--disable-static")

def build():
    autotools.make()

def install():
    autotools.install()
    pisitools.dodoc("COPYING", "ChangeLog", "README")


code:
From 0945bea5fc32eacb7bf42639efbd45dcd43e7ab5 Mon Sep 17 00:00:00 2001
From: Rob Clark <robdclark@gmail.com>
Date: Mon, 10 Jun 2013 13:31:31 -0400
Subject: [PATCH 01/11] vmwgfx: update for XA API changes

Signed-off-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Jakob Bornecrantz <jakob@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Tested-by: Jakob Bornecrantz <jakob@vmware.com>
---
 configure.ac              |  2 +-
 vmwgfx/vmwgfx_dri2.c      |  5 +++--
 vmwgfx/vmwgfx_driver.c    |  3 ++-
 vmwgfx/vmwgfx_saa.c       | 20 ++++++++++++++------
 vmwgfx/vmwgfx_tex_video.c |  5 +++--
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0631bcc..dccfb27 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,7 +118,7 @@ if test x$BUILD_VMWGFX = xyes; then
 	PKG_CHECK_MODULES([LIBDRM], [libdrm],[],[BUILD_VMWGFX=no])
 fi
 if test x$BUILD_VMWGFX = xyes; then
-	PKG_CHECK_MODULES([XATRACKER], [xatracker >= 0.4.0],[],[BUILD_VMWGFX=no])
+	PKG_CHECK_MODULES([XATRACKER], [xatracker >= 2.0.0],[],[BUILD_VMWGFX=no])
 fi

 DRIVER_NAME=vmware
diff --git a/vmwgfx/vmwgfx_dri2.c b/vmwgfx/vmwgfx_dri2.c
index 7de0772..2f007f0 100644
--- a/vmwgfx/vmwgfx_dri2.c
+++ b/vmwgfx/vmwgfx_dri2.c
@@ -201,7 +201,8 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer, unsigned int for
     }

     private->srf = srf;
-    if (xa_surface_handle(srf, &buffer->name, &buffer->pitch) != 0)
+    if (xa_surface_handle(srf, xa_handle_type_shared,
+	    &buffer->name, &buffer->pitch) != 0)
 	return FALSE;

     buffer->cpp = xa_format_depth(xa_surface_format(srf)) / 8;
@@ -222,7 +223,7 @@ dri2_do_destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
     struct vmwgfx_saa_pixmap *vpix = vmwgfx_saa_pixmap(private->pPixmap);

     if (--private->refcount == 0 && srf) {
-	xa_surface_destroy(srf);
+	xa_surface_unref(srf);
     }

     /*
diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index 7863ba2..3002285 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -617,7 +617,8 @@ vmwgfx_scanout_present(ScreenPtr pScreen, int drm_fd,
 	return FALSE;
     }

-    if (xa_surface_handle(vpix->hw, &handle, &dummy) != 0) {
+    if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
+	    &handle, &dummy) != 0) {
 	LogMessage(X_ERROR, "Could not get present surface handle.\n");
 	return FALSE;
     }
diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 63df3a1..ed3c1ee 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -140,7 +140,7 @@ vmwgfx_pixmap_free_storage(struct vmwgfx_saa_pixmap *vpix)
 	vpix->malloc = NULL;
     }
     if (!(vpix->backing & VMWGFX_PIX_SURFACE) && vpix->hw) {
-	xa_surface_destroy(vpix->hw);
+	xa_surface_unref(vpix->hw);
 	vpix->hw = NULL;
     }
     if (!(vpix->backing & VMWGFX_PIX_GMR) && vpix->gmr) {
@@ -286,7 +286,8 @@ vmwgfx_saa_dma(struct vmwgfx_saa *vsaa,
     if (vpix->gmr && vsaa->can_optimize_dma) {
 	uint32_t handle, dummy;

-	if (xa_surface_handle(vpix->hw, &handle, &dummy) != 0)
+	if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
+		 &handle, &dummy) != 0)
 	    goto out_err;
 	if (vmwgfx_dma(0, 0, reg, vpix->gmr, pixmap->devKind, handle,
 		       to_hw) != 0)
@@ -305,6 +306,8 @@ vmwgfx_saa_dma(struct vmwgfx_saa *vsaa,
 			     (int) to_hw,
 			     (struct xa_box *) REGION_RECTS(reg),
 			     REGION_NUM_RECTS(reg));
+	if (to_hw)
+	    xa_context_flush(vsaa->xa_ctx);
 	if (vpix->gmr)
 	    vmwgfx_dmabuf_unmap(vpix->gmr);
 	if (ret)
@@ -441,7 +444,7 @@ vmwgfx_hw_kill(struct vmwgfx_saa *vsaa,
 				 &spix->dirty_hw))
 	return FALSE;

-    xa_surface_destroy(vpix->hw);
+    xa_surface_unref(vpix->hw);
     vpix->hw = NULL;

     /*
@@ -683,7 +686,8 @@ vmwgfx_present_prepare(struct vmwgfx_saa *vsaa,

     (void) pScreen;
     if (src_vpix == dst_vpix || !src_vpix->hw ||
-	xa_surface_handle(src_vpix->hw, &vsaa->src_handle, &dummy) != 0)
+	xa_surface_handle(src_vpix->hw, xa_handle_type_shared,
+		&vsaa->src_handle, &dummy) != 0)
 	return FALSE;

     REGION_NULL(pScreen, &vsaa->present_region);
@@ -784,7 +788,7 @@ vmwgfx_create_hw(struct vmwgfx_saa *vsaa,
     return TRUE;

 out_no_damage:
-    xa_surface_destroy(hw);
+    xa_surface_unref(hw);
     return FALSE;
 }

@@ -929,6 +933,7 @@ vmwgfx_copy_prepare(struct saa_driver *driver,

 	if (!vmwgfx_hw_validate(src_pixmap, src_reg)) {
 	    xa_copy_done(vsaa->xa_ctx);
+	    xa_context_flush(vsaa->xa_ctx);
 	    return FALSE;
 	}

@@ -1029,6 +1034,7 @@ vmwgfx_copy_done(struct saa_driver *driver)
 	return;
     }
     xa_copy_done(vsaa->xa_ctx);
+    xa_context_flush(vsaa->xa_ctx);
 }

 static Bool
@@ -1175,6 +1181,7 @@ vmwgfx_composite_done(struct saa_driver *driver)
    struct vmwgfx_saa *vsaa = to_vmwgfx_saa(driver);

    xa_composite_done(vsaa->xa_ctx);
+   xa_context_flush(vsaa->xa_ctx);
 }

 static void
@@ -1436,7 +1443,8 @@ vmwgfx_scanout_ref(struct vmwgfx_screen_entry  *entry)
 	     */
 	    if (!vmwgfx_hw_accel_validate(pixmap, 0, XA_FLAG_SCANOUT, 0, NULL))
 		goto out_err;
-	    if (xa_surface_handle(vpix->hw, &handle, &dummy) != 0)
+	    if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
+			 &handle, &dummy) != 0)
 		goto out_err;
 	    depth = xa_format_depth(xa_surface_format(vpix->hw));

diff --git a/vmwgfx/vmwgfx_tex_video.c b/vmwgfx/vmwgfx_tex_video.c
index 449266b..2971ed7 100644
--- a/vmwgfx/vmwgfx_tex_video.c
+++ b/vmwgfx/vmwgfx_tex_video.c
@@ -199,7 +199,7 @@ stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)

        for (i=0; i<3; ++i) {
 	   if (priv->yuv[i]) {
-	       xa_surface_destroy(priv->yuv[i]);
+	       xa_surface_unref(priv->yuv[i]);
 	       priv->yuv[i] = NULL;
 	   }
 	   for (j=0; j<2; ++j) {
@@ -539,7 +539,8 @@ copy_packed_data(ScrnInfoPtr pScrn,
 	       REGION_RESET(pScrn->pScreen, &reg, &box);
 	   }

-	   if (xa_surface_handle(srf, &handle, &stride) != 0) {
+	   if (xa_surface_handle(srf, xa_handle_type_shared,
+			&handle, &stride) != 0) {
 	       ret = BadAlloc;
 	       break;
 	   }
--
1.8.5.1

From 835ce4698f916ba080f4132988fd4caf898e0b1e Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Thu, 26 Sep 2013 01:25:33 -0700
Subject: [PATCH 02/11] vmwgfx: Avoid HW operations when not master

Note that for DRI2, a dri2_copy_region becomes a NOP when not master.
Additionally, all dri2 operations that lead to a potential kernel
access will return FALSE.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 vmwgfx/vmwgfx_dri2.c       | 13 +++++++++++++
 vmwgfx/vmwgfx_driver.c     |  3 +++
 vmwgfx/vmwgfx_saa.c        | 44 +++++++++++++++++++++++++++++++++++++++++++-
 vmwgfx/vmwgfx_saa.h        |  8 ++++++++
 vmwgfx/vmwgfx_saa_priv.h   |  2 ++
 vmwgfx/vmwgfx_xa_surface.c |  6 ++++++
 6 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/vmwgfx/vmwgfx_dri2.c b/vmwgfx/vmwgfx_dri2.c
index 2f007f0..57f2d9d 100644
--- a/vmwgfx/vmwgfx_dri2.c
+++ b/vmwgfx/vmwgfx_dri2.c
@@ -138,6 +138,8 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer, unsigned int for
       return TRUE;
     case DRI2BufferStencil:
     case DRI2BufferDepthStencil:
+	if (!pScrn->vtSema)
+	    return FALSE;

 	depth = (format) ? vmwgfx_zs_format_to_depth(format) : 32;

@@ -155,6 +157,9 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer, unsigned int for

        break;
     case DRI2BufferDepth:
+	if (!pScrn->vtSema)
+	    return FALSE;
+
 	depth = (format) ? vmwgfx_z_format_to_depth(format) :
 	    pDraw->bitsPerPixel;

@@ -291,6 +296,14 @@ dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion,
     DrawablePtr dst_draw;
     RegionPtr myClip;
     GCPtr gc;
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+
+    /*
+     * This is a fragile protection against HW operations when not master.
+     * Needs to be blocked higher up in the dri2 code.
+     */
+    if (!pScrn->vtSema)
+	return;

     /*
      * In driCreateBuffers we dewrap windows into the
diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index 3002285..eeaea4b 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -1116,6 +1116,7 @@ drv_leave_vt(VT_FUNC_ARGS_DECL)

     vmwgfx_cursor_bypass(ms->fd, 0, 0);
     vmwgfx_disable_scanout(pScrn);
+    vmwgfx_saa_drop_master(pScrn->pScreen);

     if (drmDropMaster(ms->fd))
 	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
@@ -1136,6 +1137,8 @@ drv_enter_vt(VT_FUNC_ARGS_DECL)
     if (!drv_set_master(pScrn))
 	return FALSE;

+    vmwgfx_saa_set_master(pScrn->pScreen);
+
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;

diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index ed3c1ee..5534ca3 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -423,6 +423,7 @@ vmwgfx_create_pixmap(struct saa_driver *driver, struct saa_pixmap *spix,

     WSBMINITLISTHEAD(&vpix->sync_x_head);
     WSBMINITLISTHEAD(&vpix->scanout_list);
+    WSBMINITLISTHEAD(&vpix->pixmap_list);

     return TRUE;
 }
@@ -499,6 +500,7 @@ vmwgfx_destroy_pixmap(struct saa_driver *driver, PixmapPtr pixmap)
      */

     vmwgfx_pixmap_remove_present(vpix);
+    WSBMLISTDELINIT(&vpix->pixmap_list);
     WSBMLISTDELINIT(&vpix->sync_x_head);

     if (vpix->hw_is_dri2_fronts)
@@ -627,6 +629,8 @@ vmwgfx_modify_pixmap_header (PixmapPtr pixmap, int w, int h, int depth,
 			     int bpp, int devkind, void *pixdata)
 {
     struct vmwgfx_saa_pixmap *vpix = vmwgfx_saa_pixmap(pixmap);
+    ScreenPtr pScreen = pixmap->drawable.pScreen;
+    struct vmwgfx_saa *vsaa = to_vmwgfx_saa(saa_get_driver(pScreen));
     unsigned int old_height;
     unsigned int old_width;
     unsigned int old_pitch;
@@ -670,6 +674,8 @@ vmwgfx_modify_pixmap_header (PixmapPtr pixmap, int w, int h, int depth,

     vmwgfx_pix_resize(pixmap, old_pitch, old_height, old_width);
     vmwgfx_pixmap_free_storage(vpix);
+    WSBMLISTADDTAIL(&vpix->pixmap_list, &vsaa->pixmaps);
+
     return TRUE;

   out_no_modify:
@@ -860,7 +866,7 @@ vmwgfx_copy_prepare(struct saa_driver *driver,
     Bool has_valid_hw;

     if (!vsaa->xat || !SAA_PM_IS_SOLID(&dst_pixmap->drawable, plane_mask) ||
-	alu != GXcopy)
+	alu != GXcopy || !vsaa->is_master)
 	return FALSE;

     src_vpix = vmwgfx_saa_pixmap(src_pixmap);
@@ -1057,6 +1063,9 @@ vmwgfx_composite_prepare(struct saa_driver *driver, CARD8 op,
     RegionRec empty;
     struct xa_composite *xa_comp;

+    if (!vsaa->is_master)
+	return FALSE;
+
     REGION_NULL(pScreen, &empty);

     /*
@@ -1367,7 +1376,9 @@ vmwgfx_saa_init(ScreenPtr pScreen, int drm_fd, struct xa_tracker *xat,
     vsaa->use_present_opt = direct_presents;
     vsaa->only_hw_presents = only_hw_presents;
     vsaa->rendercheck = rendercheck;
+    vsaa->is_master = TRUE;
     WSBMINITLISTHEAD(&vsaa->sync_x_list);
+    WSBMINITLISTHEAD(&vsaa->pixmaps);

     vsaa->driver = vmwgfx_saa_driver;
     vsaa->vcomp = vmwgfx_alloc_composite();
@@ -1518,3 +1529,34 @@ vmwgfx_scanout_unref(struct vmwgfx_screen_entry *entry)
     entry->pixmap = NULL;
     pixmap->drawable.pScreen->DestroyPixmap(pixmap);
 }
+
+void
+vmwgfx_saa_set_master(ScreenPtr pScreen)
+{
+    struct vmwgfx_saa *vsaa = to_vmwgfx_saa(saa_get_driver(pScreen));
+
+    vsaa->is_master = TRUE;
+}
+
+void
+vmwgfx_saa_drop_master(ScreenPtr pScreen)
+{
+    struct vmwgfx_saa *vsaa = to_vmwgfx_saa(saa_get_driver(pScreen));
+    struct _WsbmListHead *list;
+    struct vmwgfx_saa_pixmap *vpix;
+    struct saa_pixmap *spix;
+
+    WSBMLISTFOREACH(list, &vsaa->pixmaps) {
+	vpix = WSBMLISTENTRY(list, struct vmwgfx_saa_pixmap, pixmap_list);
+	spix = &vpix->base;
+
+	if (!vpix->hw)
+	    continue;
+
+	(void) vmwgfx_download_from_hw(&vsaa->driver, spix->pixmap,
+				       &spix->dirty_hw);
+	REGION_EMPTY(draw->pScreen, &spix->dirty_hw);
+    }
+
+    vsaa->is_master = FALSE;
+}
diff --git a/vmwgfx/vmwgfx_saa.h b/vmwgfx/vmwgfx_saa.h
index bb8ec96..d8aa3d3 100644
--- a/vmwgfx/vmwgfx_saa.h
+++ b/vmwgfx/vmwgfx_saa.h
@@ -54,6 +54,7 @@ struct vmwgfx_saa_pixmap {
     int hw_is_dri2_fronts;
     struct _WsbmListHead sync_x_head;
     struct _WsbmListHead scanout_list;
+    struct _WsbmListHead pixmap_list;

     uint32_t xa_flags;
     uint32_t staging_add_flags;
@@ -107,4 +108,11 @@ Bool
 vmwgfx_hw_accel_validate(PixmapPtr pixmap, unsigned int depth,
 			 uint32_t add_flags, uint32_t remove_flags,
 			 RegionPtr region);
+
+void
+vmwgfx_saa_set_master(ScreenPtr pScreen);
+
+void
+vmwgfx_saa_drop_master(ScreenPtr pScreen);
+
 #endif
diff --git a/vmwgfx/vmwgfx_saa_priv.h b/vmwgfx/vmwgfx_saa_priv.h
index 5f46dee..16583b0 100644
--- a/vmwgfx/vmwgfx_saa_priv.h
+++ b/vmwgfx/vmwgfx_saa_priv.h
@@ -54,8 +54,10 @@ struct vmwgfx_saa {
     Bool use_present_opt;
     Bool only_hw_presents;
     Bool rendercheck;
+    Bool is_master;
     void (*present_flush) (ScreenPtr pScreen);
     struct _WsbmListHead sync_x_list;
+    struct _WsbmListHead pixmaps;
     struct vmwgfx_composite *vcomp;
 };

diff --git a/vmwgfx/vmwgfx_xa_surface.c b/vmwgfx/vmwgfx_xa_surface.c
index 8b30e45..2f23c57 100644
--- a/vmwgfx/vmwgfx_xa_surface.c
+++ b/vmwgfx/vmwgfx_xa_surface.c
@@ -362,6 +362,12 @@ vmwgfx_hw_accel_validate(PixmapPtr pixmap, unsigned int depth,
 Bool
 vmwgfx_hw_dri2_validate(PixmapPtr pixmap, unsigned int depth)
 {
+    struct vmwgfx_saa *vsaa =
+	to_vmwgfx_saa(saa_get_driver(pixmap->drawable.pScreen));
+
+    if (!vsaa->is_master)
+	    return FALSE;
+
     return (vmwgfx_hw_dri2_stage(pixmap, depth) &&
 	    vmwgfx_hw_commit(pixmap) &&
 	    vmwgfx_hw_validate(pixmap, NULL));
--
1.8.5.1

From 7192acf9f0bf8e7176ab0b803b861a858623f709 Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Wed, 19 Sep 2012 20:36:57 +0200
Subject: [PATCH 03/11] vmwgfx: Implement textured video completely on top of
 XA.

Remove device-specific hacks. This may increase resource usage a little
on old hardware revisions, but we don't need separate code paths on
different hardware revisions.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Zack Rusin <zackr@vmware.com>
---
 vmwgfx/vmwgfx_tex_video.c | 109 ++++++----------------------------------------
 1 file changed, 14 insertions(+), 95 deletions(-)

diff --git a/vmwgfx/vmwgfx_tex_video.c b/vmwgfx/vmwgfx_tex_video.c
index 2971ed7..a0a4f4a 100644
--- a/vmwgfx/vmwgfx_tex_video.c
+++ b/vmwgfx/vmwgfx_tex_video.c
@@ -111,8 +111,7 @@ struct xorg_xv_port_priv {
     int hue;

     int current_set;
-    struct vmwgfx_dmabuf *bounce[2][3];
-    struct xa_surface *yuv[3];
+    struct xa_surface *yuv[2][3];

     int drm_fd;

@@ -198,14 +197,10 @@ stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
        priv->fence = NULL;

        for (i=0; i<3; ++i) {
-	   if (priv->yuv[i]) {
-	       xa_surface_unref(priv->yuv[i]);
-	       priv->yuv[i] = NULL;
-	   }
 	   for (j=0; j<2; ++j) {
-	       if (priv->bounce[j][i]) {
-		   vmwgfx_dmabuf_destroy(priv->bounce[j][i]);
-		   priv->bounce[0][i] = NULL;
+	       if (priv->yuv[i]) {
+		   xa_surface_unref(priv->yuv[j][i]);
+		   priv->yuv[j][i] = NULL;
 	       }
 	   }
        }
@@ -297,11 +292,9 @@ static int
 check_yuv_surfaces(struct xorg_xv_port_priv *priv,  int id,
 		   int width, int height)
 {
-    struct xa_surface **yuv = priv->yuv;
-    struct vmwgfx_dmabuf **bounce = priv->bounce[priv->current_set];
+    struct xa_surface **yuv = priv->yuv[priv->current_set];
     int ret = 0;
     int i;
-    size_t size;

     for (i=0; i<3; ++i) {

@@ -334,19 +327,6 @@ check_yuv_surfaces(struct xorg_xv_port_priv *priv,  int id,
 	if (ret || !yuv[i])
 	    return BadAlloc;

-	size = width * height;
-
-	if (bounce[i] && (bounce[i]->size < size ||
-			  bounce[i]->size > 2*size)) {
-	    vmwgfx_dmabuf_destroy(bounce[i]);
-	    bounce[i] = NULL;
-	}
-
-	if (!bounce[i]) {
-	    bounce[i] = vmwgfx_dmabuf_alloc(priv->drm_fd, size);
-	    if (!bounce[i])
-		return BadAlloc;
-	}
     }
     return Success;
 }
@@ -413,28 +393,20 @@ copy_packed_data(ScrnInfoPtr pScrn,
                  unsigned short w, unsigned short h)
 {
     int i;
-   struct vmwgfx_dmabuf **bounce = port->bounce[port->current_set];
+   struct xa_surface **yuv = port->yuv[port->current_set];
    char *ymap, *vmap, *umap;
    unsigned char y1, y2, u, v;
    int yidx, uidx, vidx;
    int y_array_size = w * h;
    int ret = BadAlloc;

-   /*
-    * Here, we could use xa_surface_[map|unmap], but given the size of
-    * the yuv textures, that could stress the xa tracker dma buffer pool,
-    * particularaly with multiple videos rendering simultaneously.
-    *
-    * Instead, cheat and allocate vmwgfx dma buffers directly.
-    */
-
-   ymap = (char *)vmwgfx_dmabuf_map(bounce[0]);
+   ymap = xa_surface_map(port->r, yuv[0], XA_MAP_WRITE);
    if (!ymap)
        return BadAlloc;
-   umap = (char *)vmwgfx_dmabuf_map(bounce[1]);
+   umap = xa_surface_map(port->r, yuv[1], XA_MAP_WRITE);
    if (!umap)
        goto out_no_umap;
-   vmap = (char *)vmwgfx_dmabuf_map(bounce[2]);
+   vmap = xa_surface_map(port->r, yuv[2], XA_MAP_WRITE);
    if (!vmap)
        goto out_no_vmap;

@@ -493,65 +465,11 @@ copy_packed_data(ScrnInfoPtr pScrn,
    }

    ret = Success;
-   vmwgfx_dmabuf_unmap(bounce[2]);
+   xa_surface_unmap(yuv[2]);
   out_no_vmap:
-   vmwgfx_dmabuf_unmap(bounce[1]);
+   xa_surface_unmap(yuv[1]);
   out_no_umap:
-   vmwgfx_dmabuf_unmap(bounce[0]);
-
-   if (ret == Success) {
-       struct xa_surface *srf;
-       struct vmwgfx_dmabuf *buf;
-       uint32_t handle;
-       unsigned int stride;
-       BoxRec box;
-       RegionRec reg;
-
-       box.x1 = 0;
-       box.x2 = w;
-       box.y1 = 0;
-       box.y2 = h;
-
-       REGION_INIT(pScrn->pScreen, &reg, &box, 1);
-
-       for (i=0; i<3; ++i) {
-	   srf = port->yuv[i];
-	   buf = bounce[i];
-
-	   if (i == 1) {
-	       switch(id) {
-	       case FOURCC_YV12:
-		   h /= 2;
-		   /* Fall through */
-	       case FOURCC_YUY2:
-	       case FOURCC_UYVY:
-		   w /= 2;
-		   break;
-	       default:
-		   break;
-	       }
-
-	       box.x1 = 0;
-	       box.x2 = w;
-	       box.y1 = 0;
-	       box.y2 = h;
-
-	       REGION_RESET(pScrn->pScreen, &reg, &box);
-	   }
-
-	   if (xa_surface_handle(srf, xa_handle_type_shared,
-			&handle, &stride) != 0) {
-	       ret = BadAlloc;
-	       break;
-	   }
-
-	   if (vmwgfx_dma(0, 0, &reg, buf, w, handle, 1) != 0) {
-	       ret = BadAlloc;
-	       break;
-	   }
-       }
-       REGION_UNINIT(pScrn->pScreen, &reg);
-   }
+   xa_surface_unmap(yuv[0]);

    return ret;
 }
@@ -610,7 +528,8 @@ display_video(ScreenPtr pScreen, struct xorg_xv_port_priv *pPriv, int id,
 				 (struct xa_box *)REGION_RECTS(dstRegion),
 				 REGION_NUM_RECTS(dstRegion),
 				 pPriv->cm,
-				 vpix->hw, pPriv->yuv);
+				 vpix->hw,
+				 pPriv->yuv[pPriv->current_set ]);

    saa_pixmap_dirty(pPixmap, TRUE, dstRegion);
    DamageRegionProcessPending(&pPixmap->drawable);
--
1.8.5.1

From 45b2457516a9db4bd1d60fbb24a1efbe2d9dd932 Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Wed, 19 Sep 2012 21:50:40 +0200
Subject: [PATCH 04/11] vmwgfx: Get rid of device-specific DMA code

It's rarely used and things seem to work well enough on top of XA.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Zack Rusin <zackr@vmware.com>
---
 vmwgfx/vmwgfx_drmi.c     | 103 -----------------------------------------------
 vmwgfx/vmwgfx_drmi.h     |   5 ---
 vmwgfx/vmwgfx_saa.c      |  53 ++++++++++++------------
 vmwgfx/vmwgfx_saa_priv.h |   1 -
 4 files changed, 26 insertions(+), 136 deletions(-)

diff --git a/vmwgfx/vmwgfx_drmi.c b/vmwgfx/vmwgfx_drmi.c
index 496a16b..1e23f4a 100644
--- a/vmwgfx/vmwgfx_drmi.c
+++ b/vmwgfx/vmwgfx_drmi.c
@@ -284,109 +284,6 @@ vmwgfx_dmabuf_destroy(struct vmwgfx_dmabuf *buf)
 }

 int
-vmwgfx_dma(unsigned int host_x, unsigned int host_y,
-	   RegionPtr region, struct vmwgfx_dmabuf *buf,
-	   uint32_t buf_pitch, uint32_t surface_handle, int to_surface)
-{
-    BoxPtr clips = REGION_RECTS(region);
-    unsigned int num_clips = REGION_NUM_RECTS(region);
-    struct drm_vmw_execbuf_arg arg;
-    struct drm_vmw_fence_rep rep;
-    int ret;
-    unsigned int size;
-    unsigned i;
-    SVGA3dCopyBox *cb;
-    SVGA3dCmdSurfaceDMASuffix *suffix;
-    SVGA3dCmdSurfaceDMA *body;
-    struct vmwgfx_int_dmabuf *ibuf = vmwgfx_int_dmabuf(buf);
-
-    struct {
-	SVGA3dCmdHeader header;
-	SVGA3dCmdSurfaceDMA body;
-	SVGA3dCopyBox cb;
-    } *cmd;
-
-    if (num_clips == 0)
-	return 0;
-
-    size = sizeof(*cmd) + (num_clips - 1) * sizeof(cmd->cb) +
-	sizeof(*suffix);
-    cmd = malloc(size);
-    if (!cmd)
-	return -1;
-
-    cmd->header.id = SVGA_3D_CMD_SURFACE_DMA;
-    cmd->header.size = sizeof(cmd->body) + num_clips * sizeof(cmd->cb) +
-	sizeof(*suffix);
-    cb = &cmd->cb;
-
-    suffix = (SVGA3dCmdSurfaceDMASuffix *) &cb[num_clips];
-    suffix->suffixSize = sizeof(*suffix);
-    suffix->maximumOffset = (uint32_t) -1;
-    suffix->flags.discard = 0;
-    suffix->flags.unsynchronized = 0;
-    suffix->flags.reserved = 0;
-
-    body = &cmd->body;
-    body->guest.ptr.gmrId = buf->gmr_id;
-    body->guest.ptr.offset = buf->gmr_offset;
-    body->guest.pitch = buf_pitch;
-    body->host.sid = surface_handle;
-    body->host.face = 0;
-    body->host.mipmap = 0;
-
-    body->transfer =  (to_surface ? SVGA3D_WRITE_HOST_VRAM :
-		       SVGA3D_READ_HOST_VRAM);
-
-
-    for (i=0; i < num_clips; i++, cb++, clips++) {
-	cb->x = (uint16_t) clips->x1 + host_x;
-	cb->y = (uint16_t) clips->y1 + host_y;
-	cb->z = 0;
-	cb->srcx = (uint16_t) clips->x1;
-	cb->srcy = (uint16_t) clips->y1;
-	cb->srcz = 0;
-	cb->w = (uint16_t) (clips->x2 - clips->x1);
-	cb->h = (uint16_t) (clips->y2 - clips->y1);
-	cb->d = 1;
-#if 0
-	LogMessage(X_INFO, "DMA! x: %u y: %u srcx: %u srcy: %u w: %u h: %u %s\n",
-		   cb->x, cb->y, cb->srcx, cb->srcy, cb->w, cb->h,
-		   to_surface ? "to" : "from");
-#endif
-
-    }
-
-    memset(&arg, 0, sizeof(arg));
-    memset(&rep, 0, sizeof(rep));
-
-    rep.error = -EFAULT;
-    arg.fence_rep = ((to_surface) ? 0UL : (unsigned long)&rep);
-    arg.commands = (unsigned long)cmd;
-    arg.command_size = size;
-    arg.throttle_us = 0;
-    arg.version = DRM_VMW_EXECBUF_VERSION;
-
-    ret = drmCommandWrite(ibuf->drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg));
-    if (ret) {
-	LogMessage(X_ERROR, "DMA error %s.\n", strerror(-ret));
-    }
-
-    free(cmd);
-
-    if (rep.error == 0) {
-	ret = vmwgfx_fence_wait(ibuf->drm_fd, rep.handle, TRUE);
-	if (ret) {
-	    LogMessage(X_ERROR, "DMA from host fence wait error %s.\n",
-		       strerror(-ret));
-	    vmwgfx_fence_unref(ibuf->drm_fd, rep.handle);
-	}
-    }
-
-    return 0;
-}
-
-int
 vmwgfx_get_param(int drm_fd, uint32_t param, uint64_t *out)
 {
     struct drm_vmw_getparam_arg gp_arg;
diff --git a/vmwgfx/vmwgfx_drmi.h b/vmwgfx/vmwgfx_drmi.h
index 2435009..fff728a 100644
--- a/vmwgfx/vmwgfx_drmi.h
+++ b/vmwgfx/vmwgfx_drmi.h
@@ -60,11 +60,6 @@ extern void
 vmwgfx_dmabuf_unmap(struct vmwgfx_dmabuf *buf);

 extern int
-vmwgfx_dma(unsigned int host_x, unsigned int host_y,
-	   RegionPtr region, struct vmwgfx_dmabuf *buf,
-	   uint32_t buf_pitch, uint32_t surface_handle, int to_surface);
-
-extern int
 vmwgfx_num_streams(int drm_fd, uint32_t *ntot, uint32_t *nfree);

 extern int
diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 5534ca3..fd80682 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -279,40 +279,40 @@ vmwgfx_saa_dma(struct vmwgfx_saa *vsaa,
 	       Bool to_hw)
 {
     struct vmwgfx_saa_pixmap *vpix = vmwgfx_saa_pixmap(pixmap);
+    void *data = vpix->malloc;
+    int ret;

     if (!vpix->hw || (!vpix->gmr && !vpix->malloc))
 	return TRUE;

-    if (vpix->gmr && vsaa->can_optimize_dma) {
-	uint32_t handle, dummy;

-	if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
-		 &handle, &dummy) != 0)
-	    goto out_err;
-	if (vmwgfx_dma(0, 0, reg, vpix->gmr, pixmap->devKind, handle,
-		       to_hw) != 0)
+    if (vpix->gmr) {
+	data = vmwgfx_dmabuf_map(vpix->gmr);
+	if (!data)
 	    goto out_err;
-    } else {
-	void *data = vpix->malloc;
-	int ret;
+    }

-	if (vpix->gmr) {
-	    data = vmwgfx_dmabuf_map(vpix->gmr);
-	    if (!data)
-		goto out_err;
-	}
+    ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
+			 (int) to_hw,
+			 (struct xa_box *) REGION_RECTS(reg),
+			 REGION_NUM_RECTS(reg));
+    if (vpix->gmr)
+	vmwgfx_dmabuf_unmap(vpix->gmr);
+
+    if (ret)
+	goto out_err;
+
+    ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
+			 (int) to_hw,
+			 (struct xa_box *) REGION_RECTS(reg),
+			 REGION_NUM_RECTS(reg));
+    if (to_hw)
+	xa_context_flush(vsaa->xa_ctx);
+    if (vpix->gmr)
+	vmwgfx_dmabuf_unmap(vpix->gmr);
+    if (ret)
+	goto out_err;

-	ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
-			     (int) to_hw,
-			     (struct xa_box *) REGION_RECTS(reg),
-			     REGION_NUM_RECTS(reg));
-	if (to_hw)
-	    xa_context_flush(vsaa->xa_ctx);
-	if (vpix->gmr)
-	    vmwgfx_dmabuf_unmap(vpix->gmr);
-	if (ret)
-	    goto out_err;
-    }
     return TRUE;
   out_err:
     LogMessage(X_ERROR, "DMA %s surface failed.\n",
@@ -1372,7 +1372,6 @@ vmwgfx_saa_init(ScreenPtr pScreen, int drm_fd, struct xa_tracker *xat,
 	vsaa->xa_ctx = xa_context_default(xat);
     vsaa->drm_fd = drm_fd;
     vsaa->present_flush = present_flush;
-    vsaa->can_optimize_dma = FALSE;
     vsaa->use_present_opt = direct_presents;
     vsaa->only_hw_presents = only_hw_presents;
     vsaa->rendercheck = rendercheck;
diff --git a/vmwgfx/vmwgfx_saa_priv.h b/vmwgfx/vmwgfx_saa_priv.h
index 16583b0..f5f45ba 100644
--- a/vmwgfx/vmwgfx_saa_priv.h
+++ b/vmwgfx/vmwgfx_saa_priv.h
@@ -50,7 +50,6 @@ struct vmwgfx_saa {
     int ydiff;
     RegionRec present_region;
     uint32_t src_handle;
-    Bool can_optimize_dma;
     Bool use_present_opt;
     Bool only_hw_presents;
     Bool rendercheck;
--
1.8.5.1

From e26dec8f5278df74a102493bf6d2d8444dab5d6d Mon Sep 17 00:00:00 2001
From: Gaetan Nadon <memsize@videotron.ca>
Date: Mon, 28 Oct 2013 18:21:29 -0400
Subject: [PATCH 05/11] vmwgfx: handle changes of DamageUnregister API in
 1.14.99.2

Fix is inspired from the intel driver.

Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Signed-off-by: Gaetan Nadon <memsize@videotron.ca>
Signed-off-by: Jakob Bornecrantz <jakob@vmware.com>
---
 vmwgfx/vmwgfx_saa.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index fd80682..346e7f4 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -26,6 +26,7 @@
  */

 #include <xorg-server.h>
+#include <xorgVersion.h>
 #include <mi.h>
 #include <fb.h>
 #include <xf86drmMode.h>
@@ -76,7 +77,12 @@ vmwgfx_pixmap_remove_damage(PixmapPtr pixmap)
     if (!spix->damage || vpix->hw || vpix->gmr || vpix->malloc)
 	return;

+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
+    DamageUnregister(spix->damage);
+#else
     DamageUnregister(&pixmap->drawable, spix->damage);
+#endif
+
     DamageDestroy(spix->damage);
     spix->damage = NULL;
 }
--
1.8.5.1

From 7ac45326eccbf3bea9a4a8f95b9662a36ab58eb0 Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Thu, 28 Nov 2013 02:02:20 -0800
Subject: [PATCH 06/11] vmwgfx: Fix some compilation warnings and indentations

Most of the compilation warnings we're seeing are due to bad xorg headers,
but fix the ones we can fix in the driver. Some indentation fixes as well.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 src/vmware_bootstrap.c    |  2 --
 src/vmwarevideo.c         |  4 ++--
 vmwgfx/vmwgfx_driver.c    |  1 -
 vmwgfx/vmwgfx_output.c    |  2 +-
 vmwgfx/vmwgfx_overlay.c   |  4 ++--
 vmwgfx/vmwgfx_tex_video.c | 26 +++++++++++++-------------
 6 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/vmware_bootstrap.c b/src/vmware_bootstrap.c
index ea5be19..bb58325 100644
--- a/src/vmware_bootstrap.c
+++ b/src/vmware_bootstrap.c
@@ -256,7 +256,6 @@ VMwarePciProbe (DriverPtr           drv,
                 intptr_t            match_data)
 {
     ScrnInfoPtr     scrn = NULL;
-    EntityInfoPtr   entity;

     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, VMWAREPciChipsets,
                                NULL, NULL, NULL, NULL, NULL);
@@ -267,7 +266,6 @@ VMwarePciProbe (DriverPtr           drv,
         scrn->Probe = NULL;
     }

-    entity = xf86GetEntityInfo(entity_num);
     switch (DEVICE_ID(device)) {
     case PCI_DEVICE_ID_VMWARE_SVGA2:
     case PCI_DEVICE_ID_VMWARE_SVGA:
diff --git a/src/vmwarevideo.c b/src/vmwarevideo.c
index 745c71f..8d7d171 100644
--- a/src/vmwarevideo.c
+++ b/src/vmwarevideo.c
@@ -82,7 +82,7 @@
 #define VMWARE_VID_MAX_HEIGHT   2048

 #define VMWARE_VID_NUM_ENCODINGS 1
-static XF86VideoEncodingRec vmwareVideoEncodings[] =
+static const XF86VideoEncodingRec vmwareVideoEncodings[] =
 {
     {
        0,
@@ -108,7 +108,7 @@ static XF86ImageRec vmwareVideoImages[] =
 };

 #define VMWARE_VID_NUM_ATTRIBUTES 2
-static XF86AttributeRec vmwareVideoAttributes[] =
+static const XF86AttributeRec vmwareVideoAttributes[] =
 {
     {
         XvGettable | XvSettable,
diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index eeaea4b..bfc07f8 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -658,7 +658,6 @@ void xorg_flush(ScreenPtr pScreen)
 	if (crtc->enabled) {
 	    pixmap = crtc_get_scanout(crtc);
 	    if (pixmap) {
-		unsigned int j;

 		/*
 		 * Remove duplicates.
diff --git a/vmwgfx/vmwgfx_output.c b/vmwgfx/vmwgfx_output.c
index 4f52f1d..f9e4263 100644
--- a/vmwgfx/vmwgfx_output.c
+++ b/vmwgfx/vmwgfx_output.c
@@ -60,7 +60,7 @@ struct output_private
     Bool is_implicit;
 };

-static char *output_enum_list[] = {
+static const char *output_enum_list[] = {
     "Unknown",
     "VGA",
     "DVI",
diff --git a/vmwgfx/vmwgfx_overlay.c b/vmwgfx/vmwgfx_overlay.c
index 6624a10..986dd06 100644
--- a/vmwgfx/vmwgfx_overlay.c
+++ b/vmwgfx/vmwgfx_overlay.c
@@ -84,7 +84,7 @@ typedef uint8_t uint8;
 #define VMWARE_VID_MAX_HEIGHT   2048

 #define VMWARE_VID_NUM_ENCODINGS 1
-static XF86VideoEncodingRec vmwareVideoEncodings[] =
+static const XF86VideoEncodingRec vmwareVideoEncodings[] =
 {
     {
        0,
@@ -110,7 +110,7 @@ static XF86ImageRec vmwareVideoImages[] =
 };

 #define VMWARE_VID_NUM_ATTRIBUTES 2
-static XF86AttributeRec vmwareVideoAttributes[] =
+static const XF86AttributeRec vmwareVideoAttributes[] =
 {
     {
         XvGettable | XvSettable,
diff --git a/vmwgfx/vmwgfx_tex_video.c b/vmwgfx/vmwgfx_tex_video.c
index a0a4f4a..3ba40ef 100644
--- a/vmwgfx/vmwgfx_tex_video.c
+++ b/vmwgfx/vmwgfx_tex_video.c
@@ -70,11 +70,11 @@ static const float bt_709[] = {
 static Atom xvBrightness, xvContrast, xvSaturation, xvHue;

 #define NUM_TEXTURED_ATTRIBUTES 4
-static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
-   {XvSettable | XvGettable, -1000, 1000, "XV_BRIGHTNESS"},
-   {XvSettable | XvGettable, -1000, 1000, "XV_CONTRAST"},
-   {XvSettable | XvGettable, -1000, 1000, "XV_SATURATION"},
-   {XvSettable | XvGettable, -1000, 1000, "XV_HUE"}
+static const XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
+    {XvSettable | XvGettable, -1000, 1000, "XV_BRIGHTNESS"},
+    {XvSettable | XvGettable, -1000, 1000, "XV_CONTRAST"},
+    {XvSettable | XvGettable, -1000, 1000, "XV_SATURATION"},
+    {XvSettable | XvGettable, -1000, 1000, "XV_HUE"}
 };

 #define NUM_FORMATS 3
@@ -82,7 +82,7 @@ static XF86VideoFormatRec Formats[NUM_FORMATS] = {
    {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
 };

-static XF86VideoEncodingRec DummyEncoding[1] = {
+static const XF86VideoEncodingRec DummyEncoding[1] = {
    {
       0,
       "XV_IMAGE",
@@ -416,16 +416,16 @@ copy_packed_data(ScrnInfoPtr pScrn,
    switch (id) {
    case FOURCC_YV12: {
       int pitches[3], offsets[3];
-      unsigned char *y, *u, *v;
+      unsigned char *yp, *up, *vp;
       query_image_attributes(pScrn, FOURCC_YV12,
                              &w, &h, pitches, offsets);

-      y = buf + offsets[0];
-      v = buf + offsets[1];
-      u = buf + offsets[2];
-      memcpy(ymap, y, w*h);
-      memcpy(vmap, v, w*h/4);
-      memcpy(umap, u, w*h/4);
+      yp = buf + offsets[0];
+      vp = buf + offsets[1];
+      up = buf + offsets[2];
+      memcpy(ymap, yp, w*h);
+      memcpy(vmap, vp, w*h/4);
+      memcpy(umap, up, w*h/4);
       break;
    }
    case FOURCC_UYVY:
--
1.8.5.1

From a40cbd7b4fa19219849b4b0a48f07538772c3e22 Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Thu, 5 Dec 2013 02:58:47 -0800
Subject: [PATCH 07/11] vmwgfx: Support also XA version 1 v2

We need to support also XA version 1, since we want to be backwards
compatible with older mesa releases.
Unfortunately, the intended way of detecting XA major version at
compile-time was broken on mesa 10 so we need a workaround that tests
for XA version 2 at config time.

v2: Update the test for XA version 2.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 configure.ac              | 10 +++++++++-
 vmwgfx/vmwgfx_dri2.c      |  5 ++---
 vmwgfx/vmwgfx_driver.c    |  3 +--
 vmwgfx/vmwgfx_saa.c       | 12 +++++-------
 vmwgfx/vmwgfx_saa.h       | 12 ++++++++++++
 vmwgfx/vmwgfx_tex_video.c |  2 +-
 6 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac
index dccfb27..123356c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,7 +118,15 @@ if test x$BUILD_VMWGFX = xyes; then
 	PKG_CHECK_MODULES([LIBDRM], [libdrm],[],[BUILD_VMWGFX=no])
 fi
 if test x$BUILD_VMWGFX = xyes; then
-	PKG_CHECK_MODULES([XATRACKER], [xatracker >= 2.0.0],[],[BUILD_VMWGFX=no])
+#
+# Early versions of mesa 10 forgot to bump the XA major version number in
+# the xa_tracker.h header
+#
+	PKG_CHECK_MODULES([XATRACKER], [xatracker >= 0.4.0],
+			  [PKG_CHECK_EXISTS([xatracker = 2.0.0],
+	                  [AC_DEFINE([HAVE_XA_2], 1,
+               		  [Has version 2 of XA])])],
+			  [],[BUILD_VMWGFX=no])
 fi

 DRIVER_NAME=vmware
diff --git a/vmwgfx/vmwgfx_dri2.c b/vmwgfx/vmwgfx_dri2.c
index 57f2d9d..4c74a6b 100644
--- a/vmwgfx/vmwgfx_dri2.c
+++ b/vmwgfx/vmwgfx_dri2.c
@@ -206,8 +206,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer, unsigned int for
     }

     private->srf = srf;
-    if (xa_surface_handle(srf, xa_handle_type_shared,
-	    &buffer->name, &buffer->pitch) != 0)
+    if (_xa_surface_handle(srf, &buffer->name, &buffer->pitch) != 0)
 	return FALSE;

     buffer->cpp = xa_format_depth(xa_surface_format(srf)) / 8;
@@ -228,7 +227,7 @@ dri2_do_destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
     struct vmwgfx_saa_pixmap *vpix = vmwgfx_saa_pixmap(private->pPixmap);

     if (--private->refcount == 0 && srf) {
-	xa_surface_unref(srf);
+	xa_surface_destroy(srf);
     }

     /*
diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index bfc07f8..6301c29 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -617,8 +617,7 @@ vmwgfx_scanout_present(ScreenPtr pScreen, int drm_fd,
 	return FALSE;
     }

-    if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
-	    &handle, &dummy) != 0) {
+    if (_xa_surface_handle(vpix->hw, &handle, &dummy) != 0) {
 	LogMessage(X_ERROR, "Could not get present surface handle.\n");
 	return FALSE;
     }
diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 346e7f4..1459933 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -146,7 +146,7 @@ vmwgfx_pixmap_free_storage(struct vmwgfx_saa_pixmap *vpix)
 	vpix->malloc = NULL;
     }
     if (!(vpix->backing & VMWGFX_PIX_SURFACE) && vpix->hw) {
-	xa_surface_unref(vpix->hw);
+	xa_surface_destroy(vpix->hw);
 	vpix->hw = NULL;
     }
     if (!(vpix->backing & VMWGFX_PIX_GMR) && vpix->gmr) {
@@ -451,7 +451,7 @@ vmwgfx_hw_kill(struct vmwgfx_saa *vsaa,
 				 &spix->dirty_hw))
 	return FALSE;

-    xa_surface_unref(vpix->hw);
+    xa_surface_destroy(vpix->hw);
     vpix->hw = NULL;

     /*
@@ -698,8 +698,7 @@ vmwgfx_present_prepare(struct vmwgfx_saa *vsaa,

     (void) pScreen;
     if (src_vpix == dst_vpix || !src_vpix->hw ||
-	xa_surface_handle(src_vpix->hw, xa_handle_type_shared,
-		&vsaa->src_handle, &dummy) != 0)
+	_xa_surface_handle(src_vpix->hw, &vsaa->src_handle, &dummy) != 0)
 	return FALSE;

     REGION_NULL(pScreen, &vsaa->present_region);
@@ -800,7 +799,7 @@ vmwgfx_create_hw(struct vmwgfx_saa *vsaa,
     return TRUE;

 out_no_damage:
-    xa_surface_unref(hw);
+    xa_surface_destroy(hw);
     return FALSE;
 }

@@ -1459,8 +1458,7 @@ vmwgfx_scanout_ref(struct vmwgfx_screen_entry  *entry)
 	     */
 	    if (!vmwgfx_hw_accel_validate(pixmap, 0, XA_FLAG_SCANOUT, 0, NULL))
 		goto out_err;
-	    if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
-			 &handle, &dummy) != 0)
+	    if (_xa_surface_handle(vpix->hw, &handle, &dummy) != 0)
 		goto out_err;
 	    depth = xa_format_depth(xa_surface_format(vpix->hw));

diff --git a/vmwgfx/vmwgfx_saa.h b/vmwgfx/vmwgfx_saa.h
index d8aa3d3..5e1f40c 100644
--- a/vmwgfx/vmwgfx_saa.h
+++ b/vmwgfx/vmwgfx_saa.h
@@ -115,4 +115,16 @@ vmwgfx_saa_set_master(ScreenPtr pScreen);
 void
 vmwgfx_saa_drop_master(ScreenPtr pScreen);

+#if (XA_TRACKER_VERSION_MAJOR <= 1) && !defined(HAVE_XA_2)
+
+#define _xa_surface_handle(_a, _b, _c) xa_surface_handle(_a, _b, _c)
+#define xa_context_flush(_a)
+
+#else
+
+#define xa_surface_destroy(_a) xa_surface_unref(_a)
+#define _xa_surface_handle(_a, _b, _c)		\
+    xa_surface_handle(_a, xa_handle_type_shared, _b, _c)
+
+#endif /*  (XA_TRACKER_VERSION_MAJOR <= 1) */
 #endif
diff --git a/vmwgfx/vmwgfx_tex_video.c b/vmwgfx/vmwgfx_tex_video.c
index 3ba40ef..9fd8f22 100644
--- a/vmwgfx/vmwgfx_tex_video.c
+++ b/vmwgfx/vmwgfx_tex_video.c
@@ -199,7 +199,7 @@ stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
        for (i=0; i<3; ++i) {
 	   for (j=0; j<2; ++j) {
 	       if (priv->yuv[i]) {
-		   xa_surface_unref(priv->yuv[j][i]);
+		   xa_surface_destroy(priv->yuv[j][i]);
 		   priv->yuv[j][i] = NULL;
 	       }
 	   }
--
1.8.5.1

From c36cbcefb8526944141eb431e1e736dc4485a36e Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Mon, 9 Dec 2013 00:19:55 -0800
Subject: [PATCH 08/11] vmwgfx: Remove stray 1

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 vmwgfx/vmwgfx_saa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 1459933..28819c1 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -1230,7 +1230,7 @@ vmwgfx_operation_complete(struct saa_driver *driver,
      */

     if (vpix->hw && vpix->hw_is_dri2_fronts) {
-	if (1 && pScrn->vtSema &&
+	if (pScrn->vtSema &&
 	    vmwgfx_upload_to_hw(driver, pixmap, &spix->dirty_shadow)) {

 	    REGION_EMPTY(vsaa->pScreen, &spix->dirty_shadow);
--
1.8.5.1

From 4af6062ce281a7f4aaa50985fe757e9569208ee1 Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Wed, 11 Dec 2013 04:59:49 -0800
Subject: [PATCH 09/11] Revert "vmwgfx: Get rid of device-specific DMA code"

This reverts commit 45b2457516a9db4bd1d60fbb24a1efbe2d9dd932.

Reverting this because using direct DMA for shared pixmaps should
boost performance. It should be usable both in a composited environment
and when running hosted. Need to retest the DMA flaws I saw before disabling
this code.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 vmwgfx/vmwgfx_drmi.c     | 103 +++++++++++++++++++++++++++++++++++++++++++++++
 vmwgfx/vmwgfx_drmi.h     |   5 +++
 vmwgfx/vmwgfx_saa.c      |  53 ++++++++++++------------
 vmwgfx/vmwgfx_saa_priv.h |   1 +
 4 files changed, 136 insertions(+), 26 deletions(-)

diff --git a/vmwgfx/vmwgfx_drmi.c b/vmwgfx/vmwgfx_drmi.c
index 1e23f4a..496a16b 100644
--- a/vmwgfx/vmwgfx_drmi.c
+++ b/vmwgfx/vmwgfx_drmi.c
@@ -284,6 +284,109 @@ vmwgfx_dmabuf_destroy(struct vmwgfx_dmabuf *buf)
 }

 int
+vmwgfx_dma(unsigned int host_x, unsigned int host_y,
+	   RegionPtr region, struct vmwgfx_dmabuf *buf,
+	   uint32_t buf_pitch, uint32_t surface_handle, int to_surface)
+{
+    BoxPtr clips = REGION_RECTS(region);
+    unsigned int num_clips = REGION_NUM_RECTS(region);
+    struct drm_vmw_execbuf_arg arg;
+    struct drm_vmw_fence_rep rep;
+    int ret;
+    unsigned int size;
+    unsigned i;
+    SVGA3dCopyBox *cb;
+    SVGA3dCmdSurfaceDMASuffix *suffix;
+    SVGA3dCmdSurfaceDMA *body;
+    struct vmwgfx_int_dmabuf *ibuf = vmwgfx_int_dmabuf(buf);
+
+    struct {
+	SVGA3dCmdHeader header;
+	SVGA3dCmdSurfaceDMA body;
+	SVGA3dCopyBox cb;
+    } *cmd;
+
+    if (num_clips == 0)
+	return 0;
+
+    size = sizeof(*cmd) + (num_clips - 1) * sizeof(cmd->cb) +
+	sizeof(*suffix);
+    cmd = malloc(size);
+    if (!cmd)
+	return -1;
+
+    cmd->header.id = SVGA_3D_CMD_SURFACE_DMA;
+    cmd->header.size = sizeof(cmd->body) + num_clips * sizeof(cmd->cb) +
+	sizeof(*suffix);
+    cb = &cmd->cb;
+
+    suffix = (SVGA3dCmdSurfaceDMASuffix *) &cb[num_clips];
+    suffix->suffixSize = sizeof(*suffix);
+    suffix->maximumOffset = (uint32_t) -1;
+    suffix->flags.discard = 0;
+    suffix->flags.unsynchronized = 0;
+    suffix->flags.reserved = 0;
+
+    body = &cmd->body;
+    body->guest.ptr.gmrId = buf->gmr_id;
+    body->guest.ptr.offset = buf->gmr_offset;
+    body->guest.pitch = buf_pitch;
+    body->host.sid = surface_handle;
+    body->host.face = 0;
+    body->host.mipmap = 0;
+
+    body->transfer =  (to_surface ? SVGA3D_WRITE_HOST_VRAM :
+		       SVGA3D_READ_HOST_VRAM);
+
+
+    for (i=0; i < num_clips; i++, cb++, clips++) {
+	cb->x = (uint16_t) clips->x1 + host_x;
+	cb->y = (uint16_t) clips->y1 + host_y;
+	cb->z = 0;
+	cb->srcx = (uint16_t) clips->x1;
+	cb->srcy = (uint16_t) clips->y1;
+	cb->srcz = 0;
+	cb->w = (uint16_t) (clips->x2 - clips->x1);
+	cb->h = (uint16_t) (clips->y2 - clips->y1);
+	cb->d = 1;
+#if 0
+	LogMessage(X_INFO, "DMA! x: %u y: %u srcx: %u srcy: %u w: %u h: %u %s\n",
+		   cb->x, cb->y, cb->srcx, cb->srcy, cb->w, cb->h,
+		   to_surface ? "to" : "from");
+#endif
+
+    }
+
+    memset(&arg, 0, sizeof(arg));
+    memset(&rep, 0, sizeof(rep));
+
+    rep.error = -EFAULT;
+    arg.fence_rep = ((to_surface) ? 0UL : (unsigned long)&rep);
+    arg.commands = (unsigned long)cmd;
+    arg.command_size = size;
+    arg.throttle_us = 0;
+    arg.version = DRM_VMW_EXECBUF_VERSION;
+
+    ret = drmCommandWrite(ibuf->drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg));
+    if (ret) {
+	LogMessage(X_ERROR, "DMA error %s.\n", strerror(-ret));
+    }
+
+    free(cmd);
+
+    if (rep.error == 0) {
+	ret = vmwgfx_fence_wait(ibuf->drm_fd, rep.handle, TRUE);
+	if (ret) {
+	    LogMessage(X_ERROR, "DMA from host fence wait error %s.\n",
+		       strerror(-ret));
+	    vmwgfx_fence_unref(ibuf->drm_fd, rep.handle);
+	}
+    }
+
+    return 0;
+}
+
+int
 vmwgfx_get_param(int drm_fd, uint32_t param, uint64_t *out)
 {
     struct drm_vmw_getparam_arg gp_arg;
diff --git a/vmwgfx/vmwgfx_drmi.h b/vmwgfx/vmwgfx_drmi.h
index fff728a..2435009 100644
--- a/vmwgfx/vmwgfx_drmi.h
+++ b/vmwgfx/vmwgfx_drmi.h
@@ -60,6 +60,11 @@ extern void
 vmwgfx_dmabuf_unmap(struct vmwgfx_dmabuf *buf);

 extern int
+vmwgfx_dma(unsigned int host_x, unsigned int host_y,
+	   RegionPtr region, struct vmwgfx_dmabuf *buf,
+	   uint32_t buf_pitch, uint32_t surface_handle, int to_surface);
+
+extern int
 vmwgfx_num_streams(int drm_fd, uint32_t *ntot, uint32_t *nfree);

 extern int
diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 28819c1..96275a5 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -285,40 +285,40 @@ vmwgfx_saa_dma(struct vmwgfx_saa *vsaa,
 	       Bool to_hw)
 {
     struct vmwgfx_saa_pixmap *vpix = vmwgfx_saa_pixmap(pixmap);
-    void *data = vpix->malloc;
-    int ret;

     if (!vpix->hw || (!vpix->gmr && !vpix->malloc))
 	return TRUE;

+    if (vpix->gmr && vsaa->can_optimize_dma) {
+	uint32_t handle, dummy;

-    if (vpix->gmr) {
-	data = vmwgfx_dmabuf_map(vpix->gmr);
-	if (!data)
+	if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
+		 &handle, &dummy) != 0)
 	    goto out_err;
-    }
-
-    ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
-			 (int) to_hw,
-			 (struct xa_box *) REGION_RECTS(reg),
-			 REGION_NUM_RECTS(reg));
-    if (vpix->gmr)
-	vmwgfx_dmabuf_unmap(vpix->gmr);
-
-    if (ret)
-	goto out_err;
+	if (vmwgfx_dma(0, 0, reg, vpix->gmr, pixmap->devKind, handle,
+		       to_hw) != 0)
+	    goto out_err;
+    } else {
+	void *data = vpix->malloc;
+	int ret;

-    ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
-			 (int) to_hw,
-			 (struct xa_box *) REGION_RECTS(reg),
-			 REGION_NUM_RECTS(reg));
-    if (to_hw)
-	xa_context_flush(vsaa->xa_ctx);
-    if (vpix->gmr)
-	vmwgfx_dmabuf_unmap(vpix->gmr);
-    if (ret)
-	goto out_err;
+	if (vpix->gmr) {
+	    data = vmwgfx_dmabuf_map(vpix->gmr);
+	    if (!data)
+		goto out_err;
+	}

+	ret = xa_surface_dma(vsaa->xa_ctx, vpix->hw, data, pixmap->devKind,
+			     (int) to_hw,
+			     (struct xa_box *) REGION_RECTS(reg),
+			     REGION_NUM_RECTS(reg));
+	if (to_hw)
+	    xa_context_flush(vsaa->xa_ctx);
+	if (vpix->gmr)
+	    vmwgfx_dmabuf_unmap(vpix->gmr);
+	if (ret)
+	    goto out_err;
+    }
     return TRUE;
   out_err:
     LogMessage(X_ERROR, "DMA %s surface failed.\n",
@@ -1377,6 +1377,7 @@ vmwgfx_saa_init(ScreenPtr pScreen, int drm_fd, struct xa_tracker *xat,
 	vsaa->xa_ctx = xa_context_default(xat);
     vsaa->drm_fd = drm_fd;
     vsaa->present_flush = present_flush;
+    vsaa->can_optimize_dma = FALSE;
     vsaa->use_present_opt = direct_presents;
     vsaa->only_hw_presents = only_hw_presents;
     vsaa->rendercheck = rendercheck;
diff --git a/vmwgfx/vmwgfx_saa_priv.h b/vmwgfx/vmwgfx_saa_priv.h
index f5f45ba..16583b0 100644
--- a/vmwgfx/vmwgfx_saa_priv.h
+++ b/vmwgfx/vmwgfx_saa_priv.h
@@ -50,6 +50,7 @@ struct vmwgfx_saa {
     int ydiff;
     RegionRec present_region;
     uint32_t src_handle;
+    Bool can_optimize_dma;
     Bool use_present_opt;
     Bool only_hw_presents;
     Bool rendercheck;
--
1.8.5.1

From 93228f3dd3355a25583d22dbb96791678b93be3e Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Wed, 11 Dec 2013 06:54:02 -0800
Subject: [PATCH 10/11] vmwgfx: Really allow XA version 2.

When XA starts to correctly advertise version 2, we didn't allow it.
Fix this.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
---
 vmwgfx/vmwgfx_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vmwgfx/vmwgfx_driver.c b/vmwgfx/vmwgfx_driver.c
index 6301c29..4e28097 100644
--- a/vmwgfx/vmwgfx_driver.c
+++ b/vmwgfx/vmwgfx_driver.c
@@ -79,7 +79,7 @@ typedef uint8_t uint8;

 #define XA_VERSION_MINOR_REQUIRED 0
 #define XA_VERSION_MAJOR_REQUIRED 1
-#define XA_VERSION_MAJOR_COMPAT 1
+#define XA_VERSION_MAJOR_COMPAT 2

 #define DRM_VERSION_MAJOR_REQUIRED 2
 #define DRM_VERSION_MINOR_REQUIRED 3
--
1.8.5.1

From f45a551e9b70ccec8f92df02747d4e2af299cf8c Mon Sep 17 00:00:00 2001
From: Thomas Hellstrom <thellstrom@vmware.com>
Date: Mon, 16 Dec 2013 10:38:21 +0100
Subject: [PATCH 11/11] vmwgfx: Fix compile breakage on XA version 1.

A recent revert brought back code that assumed XA version 2.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: trivial
---
 vmwgfx/vmwgfx_saa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/vmwgfx/vmwgfx_saa.c b/vmwgfx/vmwgfx_saa.c
index 96275a5..e76bd09 100644
--- a/vmwgfx/vmwgfx_saa.c
+++ b/vmwgfx/vmwgfx_saa.c
@@ -292,8 +292,7 @@ vmwgfx_saa_dma(struct vmwgfx_saa *vsaa,
     if (vpix->gmr && vsaa->can_optimize_dma) {
 	uint32_t handle, dummy;

-	if (xa_surface_handle(vpix->hw, xa_handle_type_shared,
-		 &handle, &dummy) != 0)
+	if (_xa_surface_handle(vpix->hw, &handle, &dummy) != 0)
 	    goto out_err;
 	if (vmwgfx_dma(0, 0, reg, vpix->gmr, pixmap->devKind, handle,
 		       to_hw) != 0)
--
1.8.5.1


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>xorg-video-vmware</Name>
        <Homepage>http://www.x.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>MIT</License>
        <IsA>driver</IsA>
        <Summary>X.Org vmware video driver</Summary>
        <Description>xorg-video-vmware contains the X.Org driver for VMWare virtual machines.</Description>
        <Archive sha1sum="eb4909a61bb45e1c88ea66f968bc79e55b1239c4" type="tarbz2">mirrors://xorg/individual/driver/xf86-video-vmware-13.2.1.tar.bz2</Archive>
        <BuildDependencies>
            <Dependency>xorg-server-devel</Dependency>
            <Dependency>util-macros</Dependency>
        </BuildDependencies>
        <Patches>
<!--             <Patch level="1">xatracker-v2-fixes.patch</Patch> -->
        </Patches>
    </Source>

    <Package>
        <Name>xorg-video-vmware</Name>
        <RuntimeDependencies>
          <Dependency>mesa</Dependency>
          <Dependency>libdrm</Dependency>
            <Dependency>xorg-server</Dependency>
        </RuntimeDependencies>
        <Files>
            <!--<Path fileType="executable">/usr/bin</Path>-->
            <Path fileType="library">/usr/lib/xorg</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="5">
            <Date>2017-09-09</Date>
            <Version>13.2.1</Version>
            <Comment>rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="4">
            <Date>2017-03-11</Date>
            <Version>13.2.1</Version>
            <Comment>rebuild</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="3">
            <Date>2017-02-16</Date>
            <Version>13.2.1</Version>
            <Comment>Version bump</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>13.1.0</Version>
            <Comment>Release bump</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-05-08</Date>
            <Version>13.1.0</Version>
            <Comment>First release</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>xorg-video-vmware</Name>
        <Summary xml:lang="tr">X.Org vmware ekran kartı sürücüsü</Summary>
        <Description xml:lang="tr">xorg-video-vmware, VMWare sanal makineleri için X.Org sürücüsünü içerir.</Description>
    </Source>
</PISI>


code:
--- xf86-video-voodoo-1.2.5.orig/src/voodoo.h	2012-07-17 08:21:17.000000000 +0300
+++ xf86-video-voodoo-1.2.5/src/voodoo.h	2015-05-10 17:57:53.748577130 +0300
@@ -23,7 +23,9 @@

   Bool		      Voodoo2;		/* Set if Voodoo2 */
   pciVideoPtr	      PciInfo;		/* PCI data */
+#ifndef XSERVER_LIBPCIACCESS
   PCITAG	      PciTag;
+#endif
   CARD32	      PhysBase;

   CARD32	      Width;		/* Current width */


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>xorg-video-voodoo</Name>
        <Homepage>http://www.x.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>MIT</License>
        <IsA>driver</IsA>
        <Summary>X.Org voodoo video driver</Summary>
        <Description>xorg-video-voodoo contains the X.Org driver for Voodoo1 and Voodoo2 video adapters.</Description>
        <Archive sha1sum="7316df33814694ad2fb1617bcd92e6e42c3d184f" type="tarbz2">mirrors://xorg/individual/driver/xf86-video-voodoo-1.2.5.tar.bz2</Archive>
        <BuildDependencies>
            <Dependency>xorg-server-devel</Dependency>
            <Dependency>util-macros</Dependency>
        </BuildDependencies>
         <Patches>
           <Patch level="1">git-fixes.patch</Patch>
       </Patches>
    </Source>

    <Package>
        <Name>xorg-video-voodoo</Name>
        <RuntimeDependencies>
            <Dependency>xorg-server</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib/xorg</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="5">
            <Date>2017-09-09</Date>
            <Version>1.2.5</Version>
            <Comment>rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="4">
            <Date>2017-03-11</Date>
            <Version>1.2.5</Version>
            <Comment>rebuild</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="3">
            <Date>2017-02-16</Date>
            <Version>1.2.5</Version>
            <Comment>Release bump</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>1.2.5</Version>
            <Comment>Release bump</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-05-10</Date>
            <Version>1.2.5</Version>
            <Comment>First release</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>xorg-video-voodoo</Name>
        <Summary xml:lang="tr">X.Org voodoo ekran kartı sürücüsü</Summary>
        <Description xml:lang="tr">xorg-video-voodoo, Voodoo1 ve Voodoo2 video bağdaştırıcıları için X.Org sürücüsünü içerir.</Description>
    </Source>
</PISI>


code:
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import pisitools
from pisi.actionsapi import get

WorkDir = "%s-%s.%s" % (get.srcNAME(), get.srcVERSION(), get.ARCH())

def install():
    if get.buildTYPE() == "emul32":
        pisitools.insinto("/usr/lib32", "../%s-%s.i686/usr/lib/*" % (get.srcNAME(), get.srcVERSION()))
        return
    else:
        pisitools.insinto("/usr/lib", "usr/lib/*")

    pisitools.dodoc("AUTHORS", "COPYING", "NEWS", "README")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>xvba-video</Name>
        <Homepage>http://www.splitted-desktop.com/~gbeauchesne/xvba-video/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>freedist</License>
        <IsA>driver</IsA>
        XvBA backend for VA API
        <Description>xvba-video is a backend for the VA API in order to use XvBA video acceleration drivers available for some ATI cards.</Description>
        <Archive sha1sum="730f6729079f9ee91f4b00fd301ee92069178782" type="targz">http://source.pisilinux.org/1.0/xvba-video-0.7.8.i686.tar.gz</Archive>
        <Archive sha1sum="d2e56349563a0d35096fc8a7e030ebdd7bddad73" type="targz">http://source.pisilinux.org/1.0/xvba-video-0.7.8.x86_64.tar.gz</Archive>
    </Source>

    <Package>
        <Name>xvba-video</Name>
        <RuntimeDependencies>
            <Dependency>libva</Dependency>
            <Dependency>libXext</Dependency>
            <Dependency>mesa</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
        </Files>
    </Package>

    <Package>
        <Name>xvba-video-32bit</Name>
        <PartOf>emul32</PartOf>
        32-bit shared libraries for xvba-video
        <BuildType>emul32</BuildType>
        <BuildDependencies>
            <Dependency>mesa-32bit</Dependency>
            <Dependency>libX11-32bit</Dependency>
            <Dependency>libXext-32bit</Dependency>
        </BuildDependencies>
        <RuntimeDependencies>
            <Dependency>mesa-32bit</Dependency>
            <Dependency release="current">xvba-video</Dependency>
            <Dependency>libX11-32bit</Dependency>
            <Dependency>libXext-32bit</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib32</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2017-03-11</Date>
            <Version>0.7.8</Version>
            <Comment>rebuild</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="3">
            <Date>2017-02-16</Date>
            <Version>0.7.8</Version>
            <Comment>Rebuild</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>0.7.8</Version>
            <Comment>Rebuild</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-05-08</Date>
            <Version>0.7.8</Version>
            <Comment>First release</Comment>
            <Name>Burak Ertürk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>xvba-video</Name>
        VA API için XvBA arka ucu
        <Description xml:lang="tr">xvba-video, bazı ATI kartlar için mevcut olan XvBA video hızlandırma sürücülerini kullanmak için bir VA API arka ucudur.</Description>
    </Source>

    <Package>
        <Name>xvba-video-32bit</Name>
        xvba-video için 32-bit paylaşımlı kitaplıklar
    </Package>
</PISI>


code:
<PISI>
    <Name>x11.im</Name>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import get

def setup():
    pisitools.dosed("configure.ac", "(SCIM_HAS_CLUTTER=)yes", "\\1no")
    autotools.autoreconf("-vfi")
    shelltools.system("intltoolize --force")
    autotools.configure("\
                         --with-x \
                         --disable-static \
                         --enable-ld-version-script \
                         --x-includes=/usr/include/X11 \
                         --x-libraries=/usr/lib \
                         --disable-clutter-immodule \
                        ")
                         #--disable-panel-gtk \
                         #--disable-setup-ui")

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())

    #Remove scim-setup related stuff
    #pisitools.removeDir("/usr/share/pixmaps")
    #pisitools.removeDir("/usr/share/applications")
    #pisitools.removeDir("/usr/share/control-center-2.0")

    pisitools.dodoc("AUTHORS", "NEWS", "README*", "TODO", "THANKS")


code:
--- configs/global~	2008-11-09 07:17:11.000000000 +0100
+++ configs/global	2008-11-09 07:19:44.000000000 +0100
@@ -1,4 +1,4 @@
-/SupportedUnicodeLocales = en_US.UTF-8
+/SupportedUnicodeLocales = en_US.UTF-8,zh_CN.UTF-8,zh_HK.UTF-8,zh_TW.UTF-8,jp_JP.UTF-8,ko_KR.UTF-8
 /DefaultPanelProgram = scim-panel-gtk
 /DefaultConfigModule = simple
 /DefaultSocketFrontEndAddress = local:/tmp/scim-socket-frontend


code:
--- scim-1.4.2/src/scim-restart.in.1-restart	2005-09-02 12:05:35.000000000 +0900
+++ scim-1.4.2/src/scim-restart.in	2005-08-25 22:52:29.000000000 +0900
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+SOCKET_CMD="@SCIM_LIBEXECDIR@/scim-launcher -d -c `scim-config-agent -c global -g /DefaultConfigModule` -e all -f socket --no-stay"
+XIM_CMD="@SCIM_LIBEXECDIR@/scim-launcher -d -c socket -e socket -f x11"
+
+OPT="-u `id -u`"
+
+pkill ${OPT} -f "${SOCKET_CMD}" && ${SOCKET_CMD}
+pkill ${OPT} -f "${XIM_CMD}" && ${XIM_CMD}
+pkill ${OPT} scim-bridge
--- scim-1.4.2/src/Makefile.am.1-restart	2005-07-10 22:32:23.000000000 +0900
+++ scim-1.4.2/src/Makefile.am	2005-09-02 11:42:57.000000000 +0900
@@ -141,6 +141,7 @@

 bin_PROGRAMS		= scim scim-config-agent
+bin_SCRIPTS		= scim-restart

 scim_SOURCES	 	= scim.cpp
 scim_LDADD		= libscim-1.0.la
--- scim-1.4.2/configure.ac.1-restart	2005-08-16 15:56:59.000000000 +0900
+++ scim-1.4.2/configure.ac	2005-09-02 11:42:57.000000000 +0900
@@ -516,6 +516,7 @@
 		 intl/Makefile
 		 po/Makefile.in
 		 src/Makefile
+		 src/scim-restart
 		 src/scim_types.h
 		 utils/Makefile
 		 data/Makefile


code:
--- scim-1.4.5/src/scim_hotkey.cpp.8-hotkey~	2005-06-18 23:19:35.000000000 +1000
+++ scim-1.4.5/src/scim_hotkey.cpp	2007-04-17 10:15:41.000000000 +1000
@@ -362,11 +362,26 @@
     if (config.null () || !config->valid ()) return;

     KeyEventList keys;
+    String lang = scim_get_locale_language (scim_get_current_locale ());
+    String userconf = scim_get_user_data_dir () + String (SCIM_PATH_DELIM_STRING) + String ("config");
+    bool userconf_exist = true;
+
+    //If this is the first time to run scim on a machine.
+    if (access (userconf.c_str (), R_OK) !=0)
+        userconf_exist = false;

     // Load the least important hotkeys first.
     for (int i = SCIM_FRONTEND_HOTKEY_SHOW_FACTORY_MENU; i >= SCIM_FRONTEND_HOTKEY_TRIGGER; --i) {
-        if (scim_string_to_key_list (keys, config->read (String (__scim_frontend_hotkey_config_paths [i]), String (__scim_frontend_hotkey_defaults [i]))))
-            m_impl->m_matcher.add_hotkeys (keys, i);
+        if (userconf_exist == false ) {
+            String config_paths = String (__scim_frontend_hotkey_config_paths [i]) + "/" + lang;
+            if (scim_string_to_key_list (keys, config->read (config_paths, String (__scim_frontend_hotkey_defaults [i]))))
+                m_impl->m_matcher.add_hotkeys (keys, i);
+            config->write (String (__scim_frontend_hotkey_config_paths [i]),
+                    config->read (config_paths, String (__scim_frontend_hotkey_defaults [i])));
+        } else {
+            if (scim_string_to_key_list (keys, config->read (String (__scim_frontend_hotkey_config_paths [i]), String (__scim_frontend_hotkey_defaults [i]))))
+                m_impl->m_matcher.add_hotkeys (keys, i);
+        }
     }
 }


code:
# This file is encoded in UTF-8 encoding.
/DefaultIMEngineFactory/si_LK = IMEngine-M17N-si-wijesekera
/DefaultIMEngineFactory/ta_IN = IMEngine-M17N-ta-tamil99
# scim-python pinyin
/DefaultIMEngineFactory/zh_CN = 29ab338a-5a27-46b8-96cd-abbe86f17132
/DefaultIMEngineFactory/zh_SG = 05235cfc-43ce-490c-b1b1-c5a2185276ae
# CangJie3
/DefaultIMEngineFactory/zh_HK = 5da9d4ff-ccdd-45af-b1a5-7bd4ac0aeb5f
# chewing
/DefaultIMEngineFactory/zh_TW = fcff66b6-4d3e-4cf2-833c-01ef66ac6025
/FrontEnd/OnTheSpot = true
/FrontEnd/Socket/ConfigReadOnly = false
/FrontEnd/Socket/MaxClients = 512
/FrontEnd/X11/BrokenWchar = true
/FrontEnd/X11/Dynamic = false
/FrontEnd/X11/OnTheSpot = true
/FrontEnd/X11/ServerName = SCIM
/Hotkeys/FrontEnd/NextFactory =
/Hotkeys/FrontEnd/NextFactory/zh_CN = Control+Alt+Down,Shift+Control+KeyRelease+Shift_L,Shift+Control+KeyRelease+Shift_R
/Hotkeys/FrontEnd/NextFactory/zh_HK = Control+Alt+Down,Shift+Control+KeyRelease+Shift_L,Shift+Control+KeyRelease+Shift_R
/Hotkeys/FrontEnd/NextFactory/zh_SG = Control+Alt+Down,Shift+Control+KeyRelease+Shift_L,Shift+Control+KeyRelease+Shift_R
/Hotkeys/FrontEnd/NextFactory/zh_TW = Control+Alt+Down,Shift+Control+KeyRelease+Shift_L,Shift+Control+KeyRelease+Shift_R
/Hotkeys/FrontEnd/PreviousFactory =
/Hotkeys/FrontEnd/PreviousFactory/zh_CN = Control+Alt+Up,Shift+Control+KeyRelease+Control_L,Shift+Control+KeyRelease+Control_R
/Hotkeys/FrontEnd/PreviousFactory/zh_HK = Control+Alt+Up,Shift+Control+KeyRelease+Control_L,Shift+Control+KeyRelease+Control_R
/Hotkeys/FrontEnd/PreviousFactory/zh_SG = Control+Alt+Up,Shift+Control+KeyRelease+Control_L,Shift+Control+KeyRelease+Control_R
/Hotkeys/FrontEnd/PreviousFactory/zh_TW = Control+Alt+Up,Shift+Control+KeyRelease+Control_L,Shift+Control+KeyRelease+Control_R
/Hotkeys/FrontEnd/ShowFactoryMenu =
# disable trigger hotkey by default, except for the locale below:
/Hotkeys/FrontEnd/Trigger = Control+space
/Hotkeys/FrontEnd/Trigger/ja_JP = Zenkaku_Hankaku,Alt+grave,Control+space
/Hotkeys/FrontEnd/Trigger/ko_KR = Alt+Alt_L+KeyRelease,Shift+space,Control+space,Hangul
/Hotkeys/FrontEnd/ValidKeyMask = Shift+Control+Alt+Meta+Super+Hyper+CapsLock
/Panel/Gtk/Color/ActiveBackground = light sky blue
/Panel/Gtk/Color/ActiveText = black
/Panel/Gtk/Color/NormalBackground = #F7F3F7
/Panel/Gtk/Color/NormalText = black
/Panel/Gtk/Font = default
/Panel/Gtk/DefaultSticked = false
/Panel/Gtk/LookupTableEmbedded = true
/Panel/Gtk/LookupTableVertical = true
/Panel/Gtk/ShowStatusBox = false
/Panel/Gtk/ShowTrayIcon = true
/Panel/Gtk/ToolBar/AlwaysShow = false
/Panel/Gtk/ToolBar/AutoSnap = true
/Panel/Gtk/ToolBar/HideTimeout = 2
/Panel/Gtk/ToolBar/POS_X = -1
/Panel/Gtk/ToolBar/POS_Y = -1
/Panel/Gtk/ToolBar/ShowHelpIcon = true
/Panel/Gtk/ToolBar/ShowFactoryIcon = true
/Panel/Gtk/ToolBar/ShowFactoryName = true
/Panel/Gtk/ToolBar/ShowMenuIcon = true
/Panel/Gtk/ToolBar/ShowSetupIcon = true
/Panel/Gtk/ToolBar/ShowStickIcon = false
/IMEngine/RawCode/Locales = default


code:
/SupportedUnicodeLocales = en_US.UTF-8
/DefaultPanelProgram = scim-panel-gtk
/DefaultConfigModule = simple
/DefaultSocketFrontEndAddress = local:/tmp/scim-socket-frontend
/DefaultSocketIMEngineAddress = local:/tmp/scim-socket-frontend
/DefaultSocketConfigAddress = local:/tmp/scim-socket-frontend
/DefaultPanelSocketAddress = local:/tmp/scim-panel-socket
/DefaultHelperManagerSocketAddress = local:/tmp/scim-helper-manager-socket
/DefaultSocketTimeout = 5000


code:
XMODIFIERS="@im=SCIM"
export GTK_IM_MODULE="xim"
export QT_IM_MODULE="xim"
export XIM_PROGRAM="scim -d"


code:
##start the servers
/usr/lib/scim-1.0/scim-launcher -d -c simple -e all -f socket -v 100 -m all -o /tmp/scim.main.log --no-stay --no-socket
/usr/lib/scim-1.0/scim-launcher -d -c socket -e all -f x11 -v 100 -m all -o /tmp/scim.x11.log


code:
diff -u scim-1.4.5/extras/panel/scim_panel_gtk.cpp.12-workarea-xprop scim-1.4.5/extras/panel/scim_panel_gtk.cpp
--- scim-1.4.5/extras/panel/scim_panel_gtk.cpp.12-workarea-xprop	2006-11-15 11:25:48.000000000 +1000
+++ scim-1.4.5/extras/panel/scim_panel_gtk.cpp	2006-11-15 11:25:48.000000000 +1000
@@ -3658,6 +3694,11 @@
     return 0;
 }

+// set Emacs cc-mode style
+// Local variables:
+// c-file-style: "cc-mode"
+// End:
+
 /*
 vi:ts=4:nowrap:expandtab
 */


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>scim</Name>
        <Homepage>http://www.scim-im.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>LGPLv2.1</License>
        <IsA>library</IsA>
        Smart Common Input Method - framework for Input Methods
        <Description>Smart Common Input Method (SCIM) is a framework for Input Methods. It is a modular and flexible approach for authoring and using Input Methods for X11 platform.</Description>
        <Archive sha1sum="fd5a1078cb6c8d67f8bbf79969b8c5db033a0cda" type="targz">mirrors://sourceforge/scim/scim-1.4.17.tar.gz</Archive>
        <AdditionalFiles>
            <AdditionalFile permission="0644" target="configs/config">scim-system-config</AdditionalFile>
            <AdditionalFile permission="0644" target="configs/global">scim-system-global</AdditionalFile>
        </AdditionalFiles>
        <BuildDependencies>

            <Dependency>libXt-devel</Dependency>
            <Dependency>libX11-devel</Dependency>
            <Dependency>intltool</Dependency>

        </BuildDependencies>
        <Patches>
            <Patch level="1">scim-1.4.14-compile.patch</Patch>
            <Patch level="0">scim-1.4.7-support-more-utf8-locales.patch</Patch>
            <Patch level="1">scim-initial-locale-hotkey-20070922.patch</Patch>

            <Patch level="1">scim_panel_gtk-emacs-cc-style.patch</Patch>
            <Patch level="1">scim-add-restart.patch</Patch>
        </Patches>
    </Source>

    <Package>
        <Name>scim-core</Name>
        Core of SCIM for users
        <RuntimeDependencies>
            <Dependency>libX11</Dependency>
            <Dependency>libgcc</Dependency>
            <Dependency>scim-libs</Dependency>
            <Dependency>gtk3</Dependency>
            <Dependency>gtk2</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>glib2</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="config">/etc</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="data">/usr/share</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
        </Files>
        <AdditionalFiles>
            <AdditionalFile target="/etc/X11/Xsession.d/91-scim.sh" permission="0644" owner="root">scim.session</AdditionalFile>
            <AdditionalFile target="/etc/env.d/03scim" permission="0644" owner="root">scim.env</AdditionalFile>
        </AdditionalFiles>
    </Package>

    <Package>
        <Name>scim-libs</Name>
        Libraries of SCIM
        <RuntimeDependencies>
            <Dependency>cairo</Dependency>
            <Dependency>libtool-ltdl</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib/libscim-*</Path>
            <Path fileType="library">/usr/lib/scim-1.0/*/Config</Path>
            <Path fileType="library">/usr/lib/scim-1.0/*/IMEngine</Path>
        </Files>
    </Package>

    <Package>
        <Name>scim-devel</Name>
        Includes and pkgconfig for scim development
        <RuntimeDependencies>
            <Dependency release="current">scim-core</Dependency>

        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="library">/usr/lib/pkgconfig</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2017-02-16</Date>
            <Version>1.4.17</Version>
            <Comment>Rebuild.</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2016-11-03</Date>
            <Version>1.4.17</Version>
            <Comment>Version bump</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-02</Date>
            <Version>1.4.16</Version>
            <Comment>Version bump</Comment>
            <Name>Burak Erturk</Name>
            <Email>burakerturk@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-05-16</Date>
            <Version>1.4.14</Version>
            <Comment>First release</Comment>
            <Name>Marcin Bojara</Name>
            <Email>marcin@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>scim</Name>
        Smart Common Input Method - Girdi Metodları sistemi
        Smart Common Input Method – ogólna metoda wprowadzania
        <Description xml:lang="tr">Smart Common Input Method (SCIM), X11 platformu için  Girdi Metodlarının yönetilmesi ve kullanılması için modüler ve esnek Girdi Metodları sistemi</Description>
        <Description xml:lang="fr">Smart Common Input Method (SCIM - Méthode commune intelligente d'entrée) est un framework (cadre de développement) pour méthodes d'entrée. Il s'agit d'une approche modulaire et flexible pour créer ou utiliser des méthodes d'entrée pour la plateforme X11.</Description>
        <Description xml:lang="pl">scim to główny pakiet projektu SCIM, udostępniający podstawowe funkcje i typy danych.</Description>
    </Source>

    <Package>
        <Name>scim-immodule-gtk2</Name>
        GTK2 uygulamaları için IM Modülü
        Moduł IM GTK+ 2.x oparty na SCIM
    </Package>

    <Package>
        <Name>scim-immodule-gtk3</Name>
        GTK3 uygulamaları için IM Modülü
        Moduł IM GTK+ 3.x oparty na SCIM
    </Package>

    <Package>
        <Name>scim-immodule-qt</Name>
        Qt uygulamaları için IM Modülü
        Moduł IM Qt oparty na SCIM
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import get
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools

def setup():
    autotools.autoreconf("-vif")
    autotools.configure("--prefix=/usr \
                         --disable-static \
                         --enable-arrow-scrollbars \
                         --enable-gray-stipples \
                         --enable-multiplane-bitmaps")

def build():
    autotools.make()

def install():
    autotools.rawInstall("DESTDIR=%s install" % get.installDIR())

    pisitools.dodoc("ChangeLog","COPYING","README","src/README.XAW3D")


code:
diff -up libXaw3d-1.6.1/src/Label.c.3Dlabel libXaw3d-1.6.1/src/Label.c
--- libXaw3d-1.6.1/src/Label.c.3Dlabel	2011-09-19 15:42:36.000000000 -0600
+++ libXaw3d-1.6.1/src/Label.c	2012-02-25 14:44:33.766774776 -0700
@@ -416,9 +416,16 @@ GetgrayGC(LabelWidget lw)
 static void
 compute_bitmap_offsets (LabelWidget lw)
 {
-    if (lw->label.lbm_height != 0)
-	lw->label.lbm_y = (lw->core.height - lw->label.lbm_height) / 2;
-    else
+    /*
+     * bitmap will be eventually be displayed at
+     * (internal_width, internal_height + lbm_y)
+     */
+    if (lw->label.lbm_height != 0) {
+	lw->label.lbm_y = (lw->core.height -
+			   (lw->threeD.shadow_width * 2 +
+			    lw->label.internal_height * 2 +
+			    lw->label.lbm_height)) / 2;
+    } else
 	lw->label.lbm_y = 0;
 }

@@ -444,9 +451,11 @@ Initialize(Widget request, Widget new, A
 {
     LabelWidget lw = (LabelWidget) new;

+#if 0
     /* disable shadows if we're not a subclass of Command */
     if (!XtIsSubclass(new, commandWidgetClass))
 	lw->threeD.shadow_width = 0;
+#endif

     if (lw->label.label == NULL)
         lw->label.label = XtNewString(lw->core.name);
@@ -460,18 +469,20 @@ Initialize(Widget request, Widget new, A

     if (lw->core.height == 0)
 	lw->core.height = lw->label.label_height +
-				2 * lw->label.internal_height;
+			  2 * lw->label.internal_height +
+			  2 * lw->threeD.shadow_width;

     set_bitmap_info(lw);  /* req's core.height, sets label.lbm_* */

     if (lw->label.lbm_height > lw->label.label_height)
 	lw->core.height = lw->label.lbm_height +
-				2 * lw->label.internal_height;
+			  2 * lw->label.internal_height;

     if (lw->core.width == 0)
         lw->core.width = lw->label.label_width +
-				2 * lw->label.internal_width +
-				LEFT_OFFSET(lw);  /* req's label.lbm_width */
+			 2 * lw->label.internal_width +
+			 2 * lw->threeD.shadow_width +
+			 LEFT_OFFSET(lw);	/* req's label.lbm_width */

     lw->label.label_x = lw->label.label_y = 0;
     (*XtClass(new)->core_class.resize) ((Widget)lw);
@@ -549,14 +560,16 @@ Redisplay(Widget gw, XEvent *event, Regi
 	    if (w->label.depth == 1)
 		XCopyPlane(XtDisplay(gw), pm, XtWindow(gw), gc, 0, 0,
 			   w->label.lbm_width, w->label.lbm_height,
-			   (int) w->label.internal_width,
-			   (int) w->label.lbm_y,
+			   (int) w->label.internal_width + w->threeD.shadow_width,
+			   (int) w->label.internal_height + w->threeD.shadow_width
+				 + w->label.lbm_y,
 			   (unsigned long) 1L);
 	    else
 		XCopyArea(XtDisplay(gw), pm, XtWindow(gw), gc, 0, 0,
 			  w->label.lbm_width, w->label.lbm_height,
-			  (int) w->label.internal_width,
-			  (int) w->label.lbm_y);
+			  (int) w->label.internal_width + w->threeD.shadow_width,
+			  (int) w->label.internal_height + w->threeD.shadow_width
+				+ w->label.lbm_y);
 	}

 #ifdef XAW_INTERNATIONALIZATION
@@ -646,14 +659,17 @@ _Reposition(LabelWidget lw, Dimension wi
             Position *dx, Position *dy)
 {
     Position newPos;
-    Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw);
+    Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw) +
+			lw->threeD.shadow_width;
+

     switch (lw->label.justify) {
 	case XtJustifyLeft:
 	    newPos = leftedge;
 	    break;
 	case XtJustifyRight:
-	    newPos = width - lw->label.label_width - lw->label.internal_width;
+	    newPos = width - (lw->label.label_width + lw->label.internal_width +
+			      lw->threeD.shadow_width);
 	    break;
 	case XtJustifyCenter:
 	default:
@@ -745,17 +761,20 @@ SetValues(Widget current, Widget request
     if (newlw->label.resize && was_resized) {
 	if (curlw->core.height == reqlw->core.height && !checks[HEIGHT])
 	    newlw->core.height = newlw->label.label_height +
-				2 * newlw->label.internal_height;
+				 2 * newlw->label.internal_height +
+				 2 * newlw->threeD.shadow_width;

 	set_bitmap_info (newlw);  /* req's core.height, sets label.lbm_* */

 	if (newlw->label.lbm_height > newlw->label.label_height)
 	    newlw->core.height = newlw->label.lbm_height +
-					2 * newlw->label.internal_height;
+				 2 * newlw->label.internal_height +
+				 2 * newlw->threeD.shadow_width;

 	if (curlw->core.width == reqlw->core.width && !checks[WIDTH])
 	    newlw->core.width = newlw->label.label_width +
 				2 * newlw->label.internal_width +
+				2 * newlw->threeD.shadow_width +
 				LEFT_OFFSET(newlw);  /* req's label.lbm_width */
     }

@@ -764,15 +783,20 @@ SetValues(Widget current, Widget request
 	if (checks[HEIGHT]) {
 	    if (newlw->label.label_height > newlw->label.lbm_height)
 		i = newlw->label.label_height +
-			2 * newlw->label.internal_height;
+		    2 * newlw->label.internal_height +
+		    2 * newlw->threeD.shadow_width;
 	    else
-		i = newlw->label.lbm_height + 2 * newlw->label.internal_height;
+		i = newlw->label.lbm_height +
+		    2 * newlw->label.internal_height +
+		    2 * newlw->threeD.shadow_width;
 	    if (i > newlw->core.height)
 		newlw->core.height = i;
 	}
 	if (checks[WIDTH]) {
-	    i = newlw->label.label_width + 2 * newlw->label.internal_width +
-			LEFT_OFFSET(newlw);  /* req's label.lbm_width */
+	    i = newlw->label.label_width +
+		2 * newlw->label.internal_width +
+		2 * newlw->threeD.shadow_width +
+		LEFT_OFFSET(newlw);		    /* req's label.lbm_width */
 	    if (i > newlw->core.width)
 		newlw->core.width = i;
 	}
@@ -843,9 +867,11 @@ QueryGeometry(Widget w, XtWidgetGeometry
     preferred->request_mode = CWWidth | CWHeight;
     preferred->width = (lw->label.label_width +
 			    2 * lw->label.internal_width +
+			    2 * lw->threeD.shadow_width +
 			    LEFT_OFFSET(lw));
     preferred->height = lw->label.label_height +
-			    2 * lw->label.internal_height;
+			    2 * lw->label.internal_height +
+			    2 * lw->threeD.shadow_width;
     if (  ((intended->request_mode & (CWWidth | CWHeight))
 	   	== (CWWidth | CWHeight)) &&
 	  intended->width == preferred->width &&


code:
diff -up libXaw3d-1.6.1/src/AsciiSink.c.fontset libXaw3d-1.6.1/src/AsciiSink.c
--- libXaw3d-1.6.1/src/AsciiSink.c.fontset	2012-02-01 12:24:00.000000000 -0700
+++ libXaw3d-1.6.1/src/AsciiSink.c	2012-02-25 14:52:46.802779081 -0700
@@ -513,6 +513,8 @@ Initialize(Widget request, Widget new, A
 {
     AsciiSinkObject sink = (AsciiSinkObject) new;

+    if (!sink->ascii_sink.font) XtError("Aborting: no font found\n");
+
     GetGC(sink);

     sink->ascii_sink.insertCursorOn= CreateInsertCursor(XtScreenOfObject(new));
diff -up libXaw3d-1.6.1/src/Command.c.fontset libXaw3d-1.6.1/src/Command.c
--- libXaw3d-1.6.1/src/Command.c.fontset	2011-09-19 15:42:36.000000000 -0600
+++ libXaw3d-1.6.1/src/Command.c	2012-02-25 14:51:26.075372823 -0700
@@ -218,6 +218,8 @@ Initialize(Widget request, Widget new, A
   CommandWidget cbw = (CommandWidget) new;
   int shape_event_base, shape_error_base;

+  if (!cbw->label.font) XtError("Aborting: no font found\n");
+
   if (cbw->command.shape_style != XawShapeRectangle
       && !XShapeQueryExtension(XtDisplay(new), &shape_event_base,
 			       &shape_error_base))
diff -up libXaw3d-1.6.1/src/List.c.fontset libXaw3d-1.6.1/src/List.c
--- libXaw3d-1.6.1/src/List.c.fontset	2011-10-09 12:01:20.000000000 -0600
+++ libXaw3d-1.6.1/src/List.c	2012-02-25 14:53:16.327465260 -0700
@@ -362,6 +362,8 @@ Initialize(Widget junk, Widget new, ArgL
 {
     ListWidget lw = (ListWidget) new;

+    if (!lw->list.font) XtError("Aborting: no font found\n");
+
 /*
  * Initialize all private resources.
  */
diff -up libXaw3d-1.6.1/src/SmeBSB.c.fontset libXaw3d-1.6.1/src/SmeBSB.c
--- libXaw3d-1.6.1/src/SmeBSB.c.fontset	2011-09-19 15:42:36.000000000 -0600
+++ libXaw3d-1.6.1/src/SmeBSB.c	2012-02-25 14:50:19.056358107 -0700
@@ -207,6 +207,8 @@ Initialize(Widget request, Widget new, A
     else
 	entry->sme_bsb.label = XtNewString( entry->sme_bsb.label );

+    if (!entry->sme_bsb.font) XtError("Aborting: no font found\n");
+
     CreateGCs(new);

     GetBitmapInfo(new, TRUE);	/* Left Bitmap Info */
diff -up libXaw3d-1.6.1/src/Tip.c.fontset libXaw3d-1.6.1/src/Tip.c
--- libXaw3d-1.6.1/src/Tip.c.fontset	2012-02-15 12:10:38.000000000 -0700
+++ libXaw3d-1.6.1/src/Tip.c	2012-02-25 14:50:19.058358017 -0700
@@ -248,6 +248,8 @@ XawTipInitialize(Widget req, Widget w, A
     TipWidget tip = (TipWidget)w;
     XGCValues values;

+    if (!tip->tip.font) XtError("Aborting: no font found\n");
+
     tip->tip.timer = 0;

     values.foreground = tip->tip.foreground;


code:
diff -up libXaw3d-1.6.1/src/Text.c.hsbar libXaw3d-1.6.1/src/Text.c
--- libXaw3d-1.6.1/src/Text.c.hsbar	2011-10-06 13:17:19.000000000 -0600
+++ libXaw3d-1.6.1/src/Text.c	2012-02-25 14:54:41.996656624 -0700
@@ -495,8 +495,10 @@ CreateHScrollBar(TextWidget ctx)
 		    (XtPointer) NULL);

 /**/
-  ctx->text.r_margin.bottom += hbar->core.height + hbar->core.border_width;
-  ctx->text.margin.bottom = ctx->text.r_margin.bottom;
+  if (ctx->text.scroll_vert == XawtextScrollAlways) {
+    ctx->text.r_margin.bottom += hbar->core.height + hbar->core.border_width;
+    ctx->text.margin.bottom = ctx->text.r_margin.bottom;
+  }
 /**/
   PositionHScrollBar(ctx);
   if (XtIsRealized((Widget)ctx)) {
@@ -519,8 +521,10 @@ DestroyHScrollBar(TextWidget ctx)
   if (hbar == NULL) return;

 /**/
-  ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width;
-  ctx->text.margin.bottom = ctx->text.r_margin.bottom;
+  if (ctx->text.scroll_vert == XawtextScrollAlways) {
+    ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width;
+    ctx->text.margin.bottom = ctx->text.r_margin.bottom;
+  }
 /**/
   if (ctx->text.vbar == NULL)
       XtRemoveCallback((Widget) ctx, XtNunrealizeCallback, UnrealizeScrollbars,
diff -up libXaw3d-1.6.1/src/Viewport.c.hsbar libXaw3d-1.6.1/src/Viewport.c
--- libXaw3d-1.6.1/src/Viewport.c.hsbar	2012-01-24 14:56:03.000000000 -0700
+++ libXaw3d-1.6.1/src/Viewport.c	2012-02-25 14:58:18.474098582 -0700
@@ -244,7 +244,7 @@ Initialize(Widget request, Widget new, A
     XtVaGetValues((Widget)(w->viewport.threeD), XtNshadowWidth, &sw, NULL);
     if (sw)
     {
-	pad = 2;
+	pad = 2 * sw;

 	arg_cnt = 0;
 	XtSetArg(threeD_args[arg_cnt], XtNborderWidth, 0); arg_cnt++;
@@ -262,8 +262,8 @@ Initialize(Widget request, Widget new, A
     XtSetArg(clip_args[arg_cnt], XtNright, XtChainRight); arg_cnt++;
     XtSetArg(clip_args[arg_cnt], XtNtop, XtChainTop); arg_cnt++;
     XtSetArg(clip_args[arg_cnt], XtNbottom, XtChainBottom); arg_cnt++;
-    XtSetArg(clip_args[arg_cnt], XtNwidth, w->core.width - 2 * sw); arg_cnt++;
-    XtSetArg(clip_args[arg_cnt], XtNheight, w->core.height - 2 * sw); arg_cnt++;
+    XtSetArg(clip_args[arg_cnt], XtNwidth, w->core.width - pad); arg_cnt++;
+    XtSetArg(clip_args[arg_cnt], XtNheight, w->core.height - pad); arg_cnt++;

     w->viewport.clip = XtCreateManagedWidget("clip", widgetClass, new,
 					     clip_args, arg_cnt);
@@ -283,8 +283,8 @@ Initialize(Widget request, Widget new, A
  * Set the clip widget to the correct height.
  */

-    clip_width = w->core.width - 2 * sw;
-    clip_height = w->core.height - 2 * sw;
+    clip_width = w->core.width - pad;
+    clip_height = w->core.height - pad;

     if ( (h_bar != NULL) &&
 	 ((int)w->core.width >
@@ -509,23 +509,13 @@ ComputeLayout(Widget widget, Boolean que
     XtWidgetGeometry intended;
     Dimension pad = 0, sw = 0;

-    /*
-     * I've made two optimizations here. The first does away with the
-     * loop, and the second defers setting the child dimensions to the
-     * clip if smaller until after adjusting for possible scrollbars.
-     * If you find that these go too far, define the identifiers here
-     * as required.  -- djhjr
-     */
-#define NEED_LAYOUT_LOOP
-#undef PREP_CHILD_TO_CLIP
-
     if (child == (Widget) NULL) return;

     XtVaGetValues(threeD, XtNshadowWidth, &sw, NULL);
-    if (sw) pad = 2;
+    if (sw) pad = 2 * sw;

-    clip_width = w->core.width - 2 * sw;
-    clip_height = w->core.height - 2 * sw;
+    clip_width = w->core.width - pad;
+    clip_height = w->core.height - pad;
     intended.request_mode = CWBorderWidth;
     intended.border_width = 0;

@@ -536,10 +526,8 @@ ComputeLayout(Widget widget, Boolean que
 			     &clip_width, &clip_height);
     }
     else {
-#ifdef NEED_LAYOUT_LOOP
         Dimension prev_width, prev_height;
 	XtGeometryMask prev_mode;
-#endif
 	XtWidgetGeometry preferred;

 	needshoriz = needsvert = False;
@@ -553,31 +541,25 @@ ComputeLayout(Widget widget, Boolean que
 	if (!w->viewport.allowhoriz)
 	    intended.request_mode |= CWWidth;

-#ifdef PREP_CHILD_TO_CLIP
-	if ((int)child->core.width < clip_width)
-	    intended.width = clip_width;
+	if ((int)child->core.width < clip_width + pad)
+	    intended.width = clip_width + pad;
 	else
-#endif
 	    intended.width = child->core.width;

-	if (!w->viewport.allowvert)
-	    intended.request_mode |= CWHeight;
-
-#ifdef PREP_CHILD_TO_CLIP
-	if ((int)child->core.height < clip_height)
-	    intended.height = clip_height;
+	if ((int)child->core.height < clip_height + pad)
+	    intended.height = clip_height + pad;
 	else
-#endif
 	    intended.height = child->core.height;

+	if (!w->viewport.allowvert)
+	    intended.request_mode |= CWHeight;
+
 	if (!query) {
 	    preferred.width = child->core.width;
 	    preferred.height = child->core.height;
 	}

-#ifdef NEED_LAYOUT_LOOP
 	do { /* while intended != prev */
-#endif
 	    if (query) {
 	        (void) XtQueryGeometry( child, &intended, &preferred );
 		if ( !(preferred.request_mode & CWWidth) )
@@ -585,12 +567,9 @@ ComputeLayout(Widget widget, Boolean que
 		if ( !(preferred.request_mode & CWHeight) )
 		    preferred.height = intended.height;
 	    }
-
-#ifdef NEED_LAYOUT_LOOP
 	    prev_width = intended.width;
 	    prev_height = intended.height;
 	    prev_mode = intended.request_mode;
-#endif

 	    /*
 	     * Note that having once decided to turn on either bar
@@ -600,7 +579,7 @@ ComputeLayout(Widget widget, Boolean que

 #define CheckHoriz()							\
 	    if (w->viewport.allowhoriz &&				\
-		    (int)preferred.width > clip_width + 2 * sw) {	\
++		    (int)preferred.width > clip_width + pad) {		\
 		if (!needshoriz) {					\
 		    Widget horiz_bar = w->viewport.horiz_bar;		\
 		    needshoriz = True;					\
@@ -615,7 +594,7 @@ ComputeLayout(Widget widget, Boolean que
 /* enddef */
 	    CheckHoriz();
 	    if (w->viewport.allowvert &&
-		    (int)preferred.height > clip_height + 2 * sw) {
+		    (int)preferred.height > clip_height + pad) {
 		if (!needsvert) {
 		    Widget vert_bar = w->viewport.vert_bar;
 		    needsvert = True;
@@ -629,38 +608,22 @@ ComputeLayout(Widget widget, Boolean que
 		intended.height = preferred.height;
 	    }

-#ifdef PREP_CHILD_TO_CLIP
 	    if (!w->viewport.allowhoriz ||
-		    (int)preferred.width < clip_width) {
-	        intended.width = clip_width;
+		    (int)preferred.width < clip_width + pad) {
+	        intended.width = clip_width + pad;
 		intended.request_mode |= CWWidth;
 	    }
 	    if (!w->viewport.allowvert ||
-		    (int)preferred.height < clip_height) {
-	        intended.height = clip_height;
+		    (int)preferred.height < clip_height + pad) {
+	        intended.height = clip_height + pad;
 		intended.request_mode |= CWHeight;
 	    }
-#endif
-#ifdef NEED_LAYOUT_LOOP
+
 	} while ( intended.request_mode != prev_mode ||
 		  (intended.request_mode & CWWidth &&
 			intended.width != prev_width) ||
 		  (intended.request_mode & CWHeight &&
 			intended.height != prev_height) );
-#endif
-
-#ifndef PREP_CHILD_TO_CLIP
-	if (!w->viewport.allowhoriz ||
-		(int)preferred.width < clip_width) {
-	    intended.width = clip_width;
-	    intended.request_mode |= CWWidth;
-	}
-	if (!w->viewport.allowvert ||
-		(int)preferred.height < clip_height) {
-	    intended.height = clip_height;
-	    intended.request_mode |= CWHeight;
-	}
-#endif
     }

     bar_width = bar_height = 0;
@@ -705,7 +668,7 @@ ComputeLayout(Widget widget, Boolean que
 	else {
 	    int bw = bar->core.border_width;
 	    XtResizeWidget( bar,
-			    (Dimension)(clip_width + 2 * sw), bar->core.height,
+			    (Dimension)(clip_width + pad), bar->core.height,
 			    (Dimension)bw );
 	    XtMoveWidget( bar,
 			  (Position)((needsvert && !w->viewport.useright)
@@ -730,7 +693,7 @@ ComputeLayout(Widget widget, Boolean que
 	else {
 	    int bw = bar->core.border_width;
 	    XtResizeWidget( bar,
-			    bar->core.width, (Dimension)(clip_height + 2 * sw),
+			    bar->core.width, (Dimension)(clip_height + pad),
 			    (Dimension)bw );
 	    XtMoveWidget( bar,
 			  (Position)(w->viewport.useright
@@ -780,7 +743,7 @@ ComputeWithForceBars(Widget widget, Bool
  */

     XtVaGetValues((Widget)(w->viewport.threeD), XtNshadowWidth, &sw, NULL);
-    if (sw) pad = 2;
+    if (sw) pad = 2 * sw;

     if (w->viewport.allowvert) {
 	if (w->viewport.vert_bar == NULL)
@@ -926,7 +889,7 @@ GeometryRequestPlusScrollbar(ViewportWid
   Dimension pad = 0, sw = 0;

   XtVaGetValues((Widget)(w->viewport.threeD), XtNshadowWidth, &sw, NULL);
-  if (sw) pad = 2;
+  if (sw) pad = 2 * sw;

   plusScrollbars = *request;
   if ((bar = w->viewport.horiz_bar) == (Widget)NULL)
@@ -997,7 +960,7 @@ GeometryManager(Widget child, XtWidgetGe
 	return XtGeometryNo;

     XtVaGetValues((Widget)(w->viewport.threeD), XtNshadowWidth, &sw, NULL);
-    if (sw) pad = 2;
+    if (sw) pad = 2 * sw;

     allowed = *request;