Synched vfbAllocateFramebufferMemory with modern InitOutput.c.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@220 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/xc/programs/Xserver/vnc/Xvnc/xvnc.cc b/xc/programs/Xserver/vnc/Xvnc/xvnc.cc
index 0dd0a03..c11a2f6 100644
--- a/xc/programs/Xserver/vnc/Xvnc/xvnc.cc
+++ b/xc/programs/Xserver/vnc/Xvnc/xvnc.cc
@@ -736,50 +736,67 @@
     return TRUE;
 }
 
-static char* vfbAllocateFramebufferMemory(vfbScreenInfoPtr pvfb)
+static char *
+vfbAllocateFramebufferMemory(vfbScreenInfoPtr pvfb)
 {
-  if (pvfb->pfbMemory) return pvfb->pfbMemory; /* already done */
+    if (pvfb->pfbMemory) return pvfb->pfbMemory; /* already done */
 
-  pvfb->sizeInBytes = pvfb->paddedBytesWidth * pvfb->height;
+    pvfb->sizeInBytes = pvfb->paddedBytesWidth * pvfb->height;
 
-  /* Calculate how many entries in colormap.  This is rather bogus, because
-   * the visuals haven't even been set up yet, but we need to know because we
-   * have to allocate space in the file for the colormap.  The number 10
-   * below comes from the MAX_PSEUDO_DEPTH define in cfbcmap.c.
-   */
+    /* Calculate how many entries in colormap.  This is rather bogus, because
+     * the visuals haven't even been set up yet, but we need to know because we
+     * have to allocate space in the file for the colormap.  The number 10
+     * below comes from the MAX_PSEUDO_DEPTH define in cfbcmap.c.
+     */
 
-  if (pvfb->depth <= 10)
-  { /* single index colormaps */
-    pvfb->ncolors = 1 << pvfb->depth;
-  }
-  else
-  { /* decomposed colormaps */
-    int nplanes_per_color_component = pvfb->depth / 3;
-    if (pvfb->depth % 3) nplanes_per_color_component++;
-    pvfb->ncolors = 1 << nplanes_per_color_component;
-  }
+    if (pvfb->depth <= 10)
+    { /* single index colormaps */
+	pvfb->ncolors = 1 << pvfb->depth;
+    }
+    else
+    { /* decomposed colormaps */
+	int nplanes_per_color_component = pvfb->depth / 3;
+	if (pvfb->depth % 3) nplanes_per_color_component++;
+	pvfb->ncolors = 1 << nplanes_per_color_component;
+    }
 
-  /* add extra bytes for XWDFileHeader, window name, and colormap */
+    /* add extra bytes for XWDFileHeader, window name, and colormap */
 
-  pvfb->sizeInBytes += SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN +
-    pvfb->ncolors * SIZEOF(XWDColor);
+    pvfb->sizeInBytes += SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN +
+		    pvfb->ncolors * SIZEOF(XWDColor);
 
-  pvfb->pXWDHeader = NULL; 
-  pvfb->pXWDHeader = (XWDFileHeader *)Xalloc(pvfb->sizeInBytes);
+    pvfb->pXWDHeader = NULL; 
+    switch (fbmemtype)
+    {
+#ifdef HAS_MMAP
+    case MMAPPED_FILE_FB:  vfbAllocateMmappedFramebuffer(pvfb); break;
+#else
+    case MMAPPED_FILE_FB: break;
+#endif
 
-  if (pvfb->pXWDHeader)
-  {
-    pvfb->pXWDCmap = (XWDColor *)((char *)pvfb->pXWDHeader
-                                  + SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN);
-    pvfb->pfbMemory = (char *)(pvfb->pXWDCmap + pvfb->ncolors);
-    memset(pvfb->pfbMemory, 0, pvfb->paddedBytesWidth * pvfb->height);
-    return pvfb->pfbMemory;
-  }
-  else
-    return NULL;
+#ifdef HAS_SHM
+    case SHARED_MEMORY_FB: vfbAllocateSharedMemoryFramebuffer(pvfb); break;
+#else
+    case SHARED_MEMORY_FB: break;
+#endif
+
+    case NORMAL_MEMORY_FB:
+	pvfb->pXWDHeader = (XWDFileHeader *)Xalloc(pvfb->sizeInBytes);
+	break;
+    }
+
+    if (pvfb->pXWDHeader)
+    {
+	pvfb->pXWDCmap = (XWDColor *)((char *)pvfb->pXWDHeader
+				+ SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN);
+	pvfb->pfbMemory = (char *)(pvfb->pXWDCmap + pvfb->ncolors);
+
+	return pvfb->pfbMemory;
+    }
+    else
+	return NULL;
 }
 
-
 static void vfbWriteXWDFileHeader(ScreenPtr pScreen)
 {
   vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];