aboutsummaryrefslogtreecommitdiff
path: root/xorg-server
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server')
-rw-r--r--xorg-server/dix/registry.c674
-rw-r--r--xorg-server/glx/glxscreens.c4
-rw-r--r--xorg-server/hw/xwin/InitOutput.c7
-rw-r--r--xorg-server/hw/xwin/Makefile.am445
-rw-r--r--xorg-server/hw/xwin/glx/indirect.c72
-rw-r--r--xorg-server/hw/xwin/glx/winpriv.h41
-rw-r--r--xorg-server/hw/xwin/win.h2
-rw-r--r--xorg-server/hw/xwin/winauth.c2
-rw-r--r--xorg-server/hw/xwin/winclipboardthread.c2
-rw-r--r--xorg-server/hw/xwin/winconfig.c2
-rw-r--r--xorg-server/hw/xwin/winkeybd.c2
-rw-r--r--xorg-server/hw/xwin/winmouse.c4
-rw-r--r--xorg-server/hw/xwin/winmultiwindowwm.c8
-rw-r--r--xorg-server/hw/xwin/winscrinit.c2
-rw-r--r--xorg-server/hw/xwin/winshaddd.c2826
-rw-r--r--xorg-server/hw/xwin/winshadddnl.c2882
-rw-r--r--xorg-server/hw/xwin/winwindowswm.c2
-rw-r--r--xorg-server/mi/mieq.c977
-rw-r--r--xorg-server/os/osdep.h564
19 files changed, 4271 insertions, 4247 deletions
diff --git a/xorg-server/dix/registry.c b/xorg-server/dix/registry.c
index 9aa73d11d..d5c801321 100644
--- a/xorg-server/dix/registry.c
+++ b/xorg-server/dix/registry.c
@@ -1,337 +1,337 @@
-/************************************************************
-
-Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-this permission notice appear in supporting documentation. This permission
-notice shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-********************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifdef XREGISTRY
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "resource.h"
-#include "registry.h"
-
-#define BASE_SIZE 16
-#define CORE "X11"
-#define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
-
-#define PROT_COMMENT '#'
-#define PROT_REQUEST 'R'
-#define PROT_EVENT 'V'
-#define PROT_ERROR 'E'
-
-static FILE *fh;
-
-static char ***requests, **events, **errors, **resources;
-static unsigned nmajor, *nminor, nevent, nerror, nresource;
-
-/*
- * File parsing routines
- */
-static int double_size(void *p, unsigned n, unsigned size)
-{
- char **ptr = (char **)p;
- unsigned s, f;
-
- if (n) {
- s = n * size;
- n *= 2 * size;
- f = n;
- } else {
- s = 0;
- n = f = BASE_SIZE * size;
- }
-
- *ptr = xrealloc(*ptr, n);
- if (!*ptr) {
- dixResetRegistry();
- return FALSE;
- }
- memset(*ptr + s, 0, f - s);
- return TRUE;
-}
-
-static void
-RegisterRequestName(unsigned major, unsigned minor, char *name)
-{
- while (major >= nmajor) {
- if (!double_size(&requests, nmajor, sizeof(char **)))
- return;
- if (!double_size(&nminor, nmajor, sizeof(unsigned)))
- return;
- nmajor = nmajor ? nmajor * 2 : BASE_SIZE;
- }
- while (minor >= nminor[major]) {
- if (!double_size(requests+major, nminor[major], sizeof(char *)))
- return;
- nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE;
- }
-
- free(requests[major][minor]);
- requests[major][minor] = name;
-}
-
-static void
-RegisterEventName(unsigned event, char *name) {
- while (event >= nevent) {
- if (!double_size(&events, nevent, sizeof(char *)))
- return;
- nevent = nevent ? nevent * 2 : BASE_SIZE;
- }
-
- free(events[event]);
- events[event] = name;
-}
-
-static void
-RegisterErrorName(unsigned error, char *name) {
- while (error >= nerror) {
- if (!double_size(&errors, nerror, sizeof(char *)))
- return;
- nerror = nerror ? nerror * 2 : BASE_SIZE;
- }
-
- free(errors[error]);
- errors[error] = name;
-}
-
-void
-RegisterExtensionNames(ExtensionEntry *extEntry)
-{
- char buf[256], *lineobj, *ptr;
- unsigned offset;
-
- if (fh == NULL)
- return;
-
- rewind(fh);
-
- while (fgets(buf, sizeof(buf), fh)) {
- lineobj = NULL;
- ptr = strchr(buf, '\n');
- if (ptr)
- *ptr = 0;
-
- /* Check for comments or empty lines */
- switch (buf[0]) {
- case PROT_REQUEST:
- case PROT_EVENT:
- case PROT_ERROR:
- break;
- case PROT_COMMENT:
- case '\0':
- continue;
- default:
- goto invalid;
- }
-
- /* Check for space character in the fifth position */
- ptr = strchr(buf, ' ');
- if (!ptr || ptr != buf + 4)
- goto invalid;
-
- /* Duplicate the string after the space */
- lineobj = strdup(ptr + 1);
- if (!lineobj)
- continue;
-
- /* Check for a colon somewhere on the line */
- ptr = strchr(buf, ':');
- if (!ptr)
- goto invalid;
-
- /* Compare the part before colon with the target extension name */
- *ptr = 0;
- if (strcmp(buf + 5, extEntry->name))
- goto skip;
-
- /* Get the opcode for the request, event, or error */
- offset = strtol(buf + 1, &ptr, 10);
- if (offset == 0 && ptr == buf + 1)
- goto invalid;
-
- /* Save the strdup result in the registry */
- switch(buf[0]) {
- case PROT_REQUEST:
- if (extEntry->base)
- RegisterRequestName(extEntry->base, offset, lineobj);
- else
- RegisterRequestName(offset, 0, lineobj);
- continue;
- case PROT_EVENT:
- RegisterEventName(extEntry->eventBase + offset, lineobj);
- continue;
- case PROT_ERROR:
- RegisterErrorName(extEntry->errorBase + offset, lineobj);
- continue;
- }
-
- invalid:
- LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
- skip:
- free(lineobj);
- }
-}
-
-/*
- * Registration functions
- */
-
-void
-RegisterResourceName(RESTYPE resource, char *name)
-{
- resource &= TypeMask;
-
- while (resource >= nresource) {
- if (!double_size(&resources, nresource, sizeof(char *)))
- return;
- nresource = nresource ? nresource * 2 : BASE_SIZE;
- }
-
- resources[resource] = name;
-}
-
-/*
- * Lookup functions
- */
-
-const char *
-LookupRequestName(int major, int minor)
-{
- if (major >= nmajor)
- return XREGISTRY_UNKNOWN;
- if (minor >= nminor[major])
- return XREGISTRY_UNKNOWN;
-
- return requests[major][minor] ? requests[major][minor] : XREGISTRY_UNKNOWN;
-}
-
-const char *
-LookupMajorName(int major)
-{
- if (major < 128) {
- const char *retval;
-
- if (major >= nmajor)
- return XREGISTRY_UNKNOWN;
- if (0 >= nminor[major])
- return XREGISTRY_UNKNOWN;
-
- retval = requests[major][0];
- return retval ? retval + sizeof(CORE) : XREGISTRY_UNKNOWN;
- } else {
- ExtensionEntry *extEntry = GetExtensionEntry(major);
- return extEntry ? extEntry->name : XREGISTRY_UNKNOWN;
- }
-}
-
-const char *
-LookupEventName(int event)
-{
- event &= 127;
- if (event >= nevent)
- return XREGISTRY_UNKNOWN;
-
- return events[event] ? events[event] : XREGISTRY_UNKNOWN;
-}
-
-const char *
-LookupErrorName(int error)
-{
- if (error >= nerror)
- return XREGISTRY_UNKNOWN;
-
- return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
-}
-
-const char *
-LookupResourceName(RESTYPE resource)
-{
- resource &= TypeMask;
- if (resource >= nresource)
- return XREGISTRY_UNKNOWN;
-
- return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
-}
-
-/*
- * Setup and teardown
- */
-void
-dixResetRegistry(void)
-{
- ExtensionEntry extEntry;
-
- /* Free all memory */
- while (nmajor--) {
- while (nminor[nmajor])
- free(requests[nmajor][--nminor[nmajor]]);
- xfree(requests[nmajor]);
- }
- xfree(requests);
- xfree(nminor);
-
- while (nevent--)
- free(events[nevent]);
- xfree(events);
-
- while (nerror--)
- free(errors[nerror]);
- xfree(errors);
-
- xfree(resources);
-
- requests = NULL;
- nminor = NULL;
- events = NULL;
- errors = NULL;
- resources = NULL;
-
- nmajor = nevent = nerror = nresource = 0;
-
- /* Open the protocol file */
- if (fh)
- fclose(fh);
- fh = fopen(FILENAME, "r");
- if (!fh)
- LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME);
-
- /* Add built-in resources */
- RegisterResourceName(RT_NONE, "NONE");
- RegisterResourceName(RT_WINDOW, "WINDOW");
- RegisterResourceName(RT_PIXMAP, "PIXMAP");
- RegisterResourceName(RT_GC, "GC");
- RegisterResourceName(RT_FONT, "FONT");
- RegisterResourceName(RT_CURSOR, "CURSOR");
- RegisterResourceName(RT_COLORMAP, "COLORMAP");
- RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
- RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
- RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
-
- /* Add the core protocol */
- memset(&extEntry, 0, sizeof(extEntry));
- extEntry.name = CORE;
- RegisterExtensionNames(&extEntry);
-}
-
-#endif /* XREGISTRY */
+/************************************************************
+
+Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation. This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifdef XREGISTRY
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "resource.h"
+#include "registry.h"
+
+#define BASE_SIZE 16
+#define CORE "X11"
+#define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
+
+#define PROT_COMMENT '#'
+#define PROT_REQUEST 'R'
+#define PROT_EVENT 'V'
+#define PROT_ERROR 'E'
+
+static FILE *fh;
+
+static char ***requests, **events, **errors, **resources;
+static unsigned nmajor, *nminor, nevent, nerror, nresource;
+
+/*
+ * File parsing routines
+ */
+static int double_size(void *p, unsigned n, unsigned size)
+{
+ char **ptr = (char **)p;
+ unsigned s, f;
+
+ if (n) {
+ s = n * size;
+ n *= 2 * size;
+ f = n;
+ } else {
+ s = 0;
+ n = f = BASE_SIZE * size;
+ }
+
+ *ptr = xrealloc(*ptr, n);
+ if (!*ptr) {
+ dixResetRegistry();
+ return FALSE;
+ }
+ memset(*ptr + s, 0, f - s);
+ return TRUE;
+}
+
+static void
+RegisterRequestName(unsigned major, unsigned minor, char *name)
+{
+ while (major >= nmajor) {
+ if (!double_size(&requests, nmajor, sizeof(char **)))
+ return;
+ if (!double_size(&nminor, nmajor, sizeof(unsigned)))
+ return;
+ nmajor = nmajor ? nmajor * 2 : BASE_SIZE;
+ }
+ while (minor >= nminor[major]) {
+ if (!double_size(requests+major, nminor[major], sizeof(char *)))
+ return;
+ nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE;
+ }
+
+ free(requests[major][minor]);
+ requests[major][minor] = name;
+}
+
+static void
+RegisterEventName(unsigned event, char *name) {
+ while (event >= nevent) {
+ if (!double_size(&events, nevent, sizeof(char *)))
+ return;
+ nevent = nevent ? nevent * 2 : BASE_SIZE;
+ }
+
+ free(events[event]);
+ events[event] = name;
+}
+
+static void
+RegisterErrorName(unsigned error, char *name) {
+ while (error >= nerror) {
+ if (!double_size(&errors, nerror, sizeof(char *)))
+ return;
+ nerror = nerror ? nerror * 2 : BASE_SIZE;
+ }
+
+ free(errors[error]);
+ errors[error] = name;
+}
+
+void
+RegisterExtensionNames(ExtensionEntry *extEntry)
+{
+ char buf[256], *lineobj, *ptr;
+ unsigned offset;
+
+ if (fh == NULL)
+ return;
+
+ rewind(fh);
+
+ while (fgets(buf, sizeof(buf), fh)) {
+ lineobj = NULL;
+ ptr = strchr(buf, '\n');
+ if (ptr)
+ *ptr = 0;
+
+ /* Check for comments or empty lines */
+ switch (buf[0]) {
+ case PROT_REQUEST:
+ case PROT_EVENT:
+ case PROT_ERROR:
+ break;
+ case PROT_COMMENT:
+ case '\0':
+ continue;
+ default:
+ goto invalid;
+ }
+
+ /* Check for space character in the fifth position */
+ ptr = strchr(buf, ' ');
+ if (!ptr || ptr != buf + 4)
+ goto invalid;
+
+ /* Duplicate the string after the space */
+ lineobj = strdup(ptr + 1);
+ if (!lineobj)
+ continue;
+
+ /* Check for a colon somewhere on the line */
+ ptr = strchr(buf, ':');
+ if (!ptr)
+ goto invalid;
+
+ /* Compare the part before colon with the target extension name */
+ *ptr = 0;
+ if (strcmp(buf + 5, extEntry->name))
+ goto skip;
+
+ /* Get the opcode for the request, event, or error */
+ offset = strtol(buf + 1, &ptr, 10);
+ if (offset == 0 && ptr == buf + 1)
+ goto invalid;
+
+ /* Save the strdup result in the registry */
+ switch(buf[0]) {
+ case PROT_REQUEST:
+ if (extEntry->base)
+ RegisterRequestName(extEntry->base, offset, lineobj);
+ else
+ RegisterRequestName(offset, 0, lineobj);
+ continue;
+ case PROT_EVENT:
+ RegisterEventName(extEntry->eventBase + offset, lineobj);
+ continue;
+ case PROT_ERROR:
+ RegisterErrorName(extEntry->errorBase + offset, lineobj);
+ continue;
+ }
+
+ invalid:
+ LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
+ skip:
+ free(lineobj);
+ }
+}
+
+/*
+ * Registration functions
+ */
+
+void
+RegisterResourceName(RESTYPE resource, char *name)
+{
+ resource &= TypeMask;
+
+ while (resource >= nresource) {
+ if (!double_size(&resources, nresource, sizeof(char *)))
+ return;
+ nresource = nresource ? nresource * 2 : BASE_SIZE;
+ }
+
+ resources[resource] = name;
+}
+
+/*
+ * Lookup functions
+ */
+
+const char *
+LookupRequestName(int major, int minor)
+{
+ if (major >= nmajor)
+ return XREGISTRY_UNKNOWN;
+ if (minor >= nminor[major])
+ return XREGISTRY_UNKNOWN;
+
+ return requests[major][minor] ? requests[major][minor] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupMajorName(int major)
+{
+ if (major < 128) {
+ const char *retval;
+
+ if (major >= nmajor)
+ return XREGISTRY_UNKNOWN;
+ if (0 >= nminor[major])
+ return XREGISTRY_UNKNOWN;
+
+ retval = requests[major][0];
+ return retval ? retval + sizeof(CORE) : XREGISTRY_UNKNOWN;
+ } else {
+ ExtensionEntry *extEntry = GetExtensionEntry(major);
+ return extEntry ? extEntry->name : XREGISTRY_UNKNOWN;
+ }
+}
+
+const char *
+LookupEventName(int event)
+{
+ event &= 127;
+ if (event >= nevent)
+ return XREGISTRY_UNKNOWN;
+
+ return events[event] ? events[event] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupErrorName(int error)
+{
+ if (error >= nerror)
+ return XREGISTRY_UNKNOWN;
+
+ return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupResourceName(RESTYPE resource)
+{
+ resource &= TypeMask;
+ if (resource >= nresource)
+ return XREGISTRY_UNKNOWN;
+
+ return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
+}
+
+/*
+ * Setup and teardown
+ */
+void
+dixResetRegistry(void)
+{
+ ExtensionEntry extEntry;
+
+ /* Free all memory */
+ while (nmajor--) {
+ while (nminor[nmajor])
+ free(requests[nmajor][--nminor[nmajor]]);
+ xfree(requests[nmajor]);
+ }
+ xfree(requests);
+ xfree(nminor);
+
+ while (nevent--)
+ free(events[nevent]);
+ xfree(events);
+
+ while (nerror--)
+ free(errors[nerror]);
+ xfree(errors);
+
+ xfree(resources);
+
+ requests = NULL;
+ nminor = NULL;
+ events = NULL;
+ errors = NULL;
+ resources = NULL;
+
+ nmajor = nevent = nerror = nresource = 0;
+
+ /* Open the protocol file */
+ if (fh)
+ fclose(fh);
+ fh = fopen(FILENAME, "r");
+ if (!fh)
+ LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME "\n");
+
+ /* Add built-in resources */
+ RegisterResourceName(RT_NONE, "NONE");
+ RegisterResourceName(RT_WINDOW, "WINDOW");
+ RegisterResourceName(RT_PIXMAP, "PIXMAP");
+ RegisterResourceName(RT_GC, "GC");
+ RegisterResourceName(RT_FONT, "FONT");
+ RegisterResourceName(RT_CURSOR, "CURSOR");
+ RegisterResourceName(RT_COLORMAP, "COLORMAP");
+ RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
+ RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
+ RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
+
+ /* Add the core protocol */
+ memset(&extEntry, 0, sizeof(extEntry));
+ extEntry.name = CORE;
+ RegisterExtensionNames(&extEntry);
+}
+
+#endif /* XREGISTRY */
diff --git a/xorg-server/glx/glxscreens.c b/xorg-server/glx/glxscreens.c
index b2d1f8741..5f9b072b7 100644
--- a/xorg-server/glx/glxscreens.c
+++ b/xorg-server/glx/glxscreens.c
@@ -454,6 +454,10 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
if (i == pScreen->numVisuals)
continue;
+ /* Make sure the FBconfig supports window drawables */
+ if (!(config->drawableType & GLX_WINDOW_BIT))
+ continue;
+
/* Create a new X visual for our FBconfig. */
visual = AddScreenVisuals(pScreen, 1, depth);
if (visual == NULL)
diff --git a/xorg-server/hw/xwin/InitOutput.c b/xorg-server/hw/xwin/InitOutput.c
index d05a76320..d86711100 100644
--- a/xorg-server/hw/xwin/InitOutput.c
+++ b/xorg-server/hw/xwin/InitOutput.c
@@ -1,3 +1,4 @@
+
/*
Copyright 1993, 1998 The Open Group
@@ -359,11 +360,11 @@ winCheckMount(void)
continue;
level = curlevel;
- if ((winCheckMntOpt(ent, "binary") == NULL) ||
+ if ((winCheckMntOpt(ent, "binary") == NULL) &&
(winCheckMntOpt(ent, "binmode") == NULL))
- binary = 0;
+ binary = FALSE;
else
- binary = 1;
+ binary = TRUE;
}
if (endmntent(mnt) != 1)
diff --git a/xorg-server/hw/xwin/Makefile.am b/xorg-server/hw/xwin/Makefile.am
index 8b6b6a06d..ba16d3764 100644
--- a/xorg-server/hw/xwin/Makefile.am
+++ b/xorg-server/hw/xwin/Makefile.am
@@ -1,223 +1,222 @@
-bin_PROGRAMS = XWin
-
-if XWIN_CLIPBOARD
-SRCS_CLIPBOARD = \
- winclipboardinit.c \
- winclipboardtextconv.c \
- winclipboardthread.c \
- winclipboardunicode.c \
- winclipboardwndproc.c \
- winclipboardwrappers.c \
- winclipboardxevents.c
-DEFS_CLIPBOARD = -DXWIN_CLIPBOARD
-endif
-
-if XWIN_GLX_WINDOWS
-GLX_DIR = glx
-DEFS_GLX_WINDOWS = -DXWIN_GLX_WINDOWS
-XWIN_GLX_LIBS = $(top_builddir)/hw/xwin/glx/libXwinGLX.la
-XWIN_GLX_LINK_FLAGS = -lopengl32
-endif
-
-if XWIN_MULTIWINDOW
-SRCS_MULTIWINDOW = \
- winmultiwindowshape.c \
- winmultiwindowwindow.c \
- winmultiwindowwm.c \
- winmultiwindowwndproc.c
-DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
-endif
-
-if XWIN_MULTIWINDOWEXTWM
-SRCS_MULTIWINDOWEXTWM = \
- winwin32rootless.c \
- winwin32rootlesswindow.c \
- winwin32rootlesswndproc.c \
- winwindowswm.c
-DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM
-MULTIWINDOWEXTWM_LIBS = $(top_builddir)/miext/rootless/librootless.la
-endif
-
-if XWIN_NATIVEGDI
-SRCS_NATIVEGDI = \
- winclip.c \
- winfillsp.c \
- winfont.c \
- wingc.c \
- wingetsp.c \
- winnativegdi.c \
- winpixmap.c \
- winpolyline.c \
- winrop.c \
- winsetsp.c
-DEFS_NATIVEGDI = -DXWIN_NATIVEGDI
-endif
-
-if XWIN_PRIMARYFB
-SRCS_PRIMARYFB = \
- winpfbdd.c
-DEFS_PRIMARYFB = -DXWIN_PRIMARYFB
-endif
-
-if XWIN_RANDR
-SRCS_RANDR = \
- winrandr.c
-DEFS_RANDR = -DXWIN_RANDR
-endif
-
-if XWIN_XV
-SRCS_XV = \
- winvideo.c
-DEFS_XV = -DXWIN_XV
-endif
-
-SRCS = InitInput.c \
- InitOutput.c \
- winallpriv.c \
- winauth.c \
- winblock.c \
- wincmap.c \
- winconfig.c \
- wincreatewnd.c \
- wincursor.c \
- windialogs.c \
- winengine.c \
- winerror.c \
- winglobals.c \
- winkeybd.c \
- winkeyhook.c \
- winmisc.c \
- winmouse.c \
- winmsg.c \
- winmultiwindowclass.c \
- winmultiwindowicons.c \
- winprefs.c \
- winprefsyacc.y \
- winprefslex.l \
- winprocarg.c \
- winregistry.c \
- winscrinit.c \
- winshaddd.c \
- winshadddnl.c \
- winshadgdi.c \
- wintrayicon.c \
- winvalargs.c \
- winwakeup.c \
- winwindow.c \
- winwndproc.c \
- ddraw.h \
- winclipboard.h \
- winconfig.h \
- win.h \
- winkeybd.h \
- winkeymap.h \
- winkeynames.h \
- winlayouts.h \
- winmessages.h \
- winmsg.h \
- winms.h \
- winmultiwindowclass.h \
- winprefs.h \
- winpriv.h \
- winresource.h \
- winwindow.h \
- windisplay.c \
- XWin.rc \
- $(top_srcdir)/Xext/dpmsstubs.c \
- $(top_srcdir)/Xi/stubs.c \
- $(top_srcdir)/mi/miinitext.c \
- $(top_srcdir)/fb/fbcmap_mi.c \
- $(SRCS_CLIPBOARD) \
- $(SRCS_MULTIWINDOW) \
- $(SRCS_MULTIWINDOWEXTWM) \
- $(SRCS_NATIVEGDI) \
- $(SRCS_PRIMARYFB) \
- $(SRCS_RANDR) \
- $(SRCS_XV)
-
- DEFS = $(DEFS_CLIPBOARD) \
- $(DEFS_GLX_WINDOWS) \
- $(DEFS_MULTIWINDOW) \
- $(DEFS_MULTIWINDOWEXTWM) \
- $(DEFS_NATIVEGDI) \
- $(DEFS_PRIMARYFB) \
- $(DEFS_RANDR) \
- $(DEFS_XV)
-
-XWin_SOURCES = $(SRCS)
-
-INCLUDES = -I$(top_srcdir)/miext/rootless
-
-XWin_DEPENDENCIES = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS)
-XWin_LDADD = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_GLX_LINK_FLAGS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XWIN_SYS_LIBS)
-XWin_LDFLAGS = -mwindows
-
-.rc.o:
- $(WINDRES) --use-temp-file -i $< --input-format=rc -o $@ -O coff -I $(top_builddir)/include
-
-winprefsyacc.h: winprefsyacc.c
-winprefslex.c: winprefslex.l winprefsyacc.c winprefsyacc.h
-
-BUILT_SOURCES = winprefsyacc.h winprefsyacc.c winprefslex.c
-CLEANFILES = $(BUILT_SOURCES) $(appman_DATA) $(fileman_DATA) XWin.man XWinrc.man
-
-AM_YFLAGS = -d
-AM_LFLAGS = -i
-AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \
- $(XWINMODULES_CFLAGS) \
- -DXFree86Server \
- -I$(top_srcdir)
-
-MAN_SRCS = XWin.man.pre XWinrc.man.pre
-
-appmandir = $(APP_MAN_DIR)
-appman_DATA = XWin.$(APP_MAN_SUFFIX)
-
-filemandir = $(FILE_MAN_DIR)
-fileman_DATA = XWinrc.$(FILE_MAN_SUFFIX)
-
-XWin.$(APP_MAN_SUFFIX): XWin.man
- -rm -f XWin.$(APP_MAN_SUFFIX)
- $(LN_S) XWin.man XWin.$(APP_MAN_SUFFIX)
-
-XWinrc.$(FILE_MAN_SUFFIX): XWinrc.man
- -rm -f XWinrc.$(FILE_MAN_SUFFIX)
- $(LN_S) XWinrc.man XWinrc.$(FILE_MAN_SUFFIX)
-
-EXTRAMANDEFS = -D__logdir__=$(logdir) -D__sysconfdir__=$(sysconfdir) -D__datadir__=$(datadir)
-
-xwinconfigdir = $(sysconfdir)/X11
-xwinconfig_DATA = system.XWinrc
-
-include $(top_srcdir)/cpprules.in
-
-EXTRA_DIST = \
- $(MAN_SRCS) \
- X.ico \
- XWin.rc \
- xlaunch/config.cc \
- xlaunch/COPYING \
- xlaunch/main.cc \
- xlaunch/resources/dialog.rc \
- xlaunch/resources/fullscreen.bmp \
- xlaunch/resources/images.rc \
- xlaunch/resources/multiwindow.bmp \
- xlaunch/resources/nodecoration.bmp \
- xlaunch/resources/resources.h \
- xlaunch/resources/resources.rc \
- xlaunch/resources/strings.rc \
- xlaunch/resources/windowed.bmp \
- xlaunch/window/dialog.cc \
- xlaunch/window/dialog.h \
- xlaunch/window/util.cc \
- xlaunch/window/util.h \
- xlaunch/window/window.cc \
- xlaunch/window/window.h \
- xlaunch/window/wizard.cc \
- xlaunch/window/wizard.h
-
-relink:
- rm -f XWin$(EXEEXT) && $(MAKE) XWin$(EXEEXT)
-
-SUBDIRS = $(GLX_DIR) .
-DIST_SUBDIRS = glx .
+bin_PROGRAMS = XWin
+
+if XWIN_CLIPBOARD
+SRCS_CLIPBOARD = \
+ winclipboardinit.c \
+ winclipboardtextconv.c \
+ winclipboardthread.c \
+ winclipboardunicode.c \
+ winclipboardwndproc.c \
+ winclipboardwrappers.c \
+ winclipboardxevents.c
+DEFS_CLIPBOARD = -DXWIN_CLIPBOARD
+endif
+
+if XWIN_GLX_WINDOWS
+GLX_DIR = glx
+DEFS_GLX_WINDOWS = -DXWIN_GLX_WINDOWS
+XWIN_GLX_LIBS = $(top_builddir)/hw/xwin/glx/libXwinGLX.la
+XWIN_GLX_LINK_FLAGS = -lopengl32
+endif
+
+if XWIN_MULTIWINDOW
+SRCS_MULTIWINDOW = \
+ winmultiwindowshape.c \
+ winmultiwindowwindow.c \
+ winmultiwindowwm.c \
+ winmultiwindowwndproc.c
+DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
+endif
+
+if XWIN_MULTIWINDOWEXTWM
+SRCS_MULTIWINDOWEXTWM = \
+ winwin32rootless.c \
+ winwin32rootlesswindow.c \
+ winwin32rootlesswndproc.c \
+ winwindowswm.c
+DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM
+MULTIWINDOWEXTWM_LIBS = $(top_builddir)/miext/rootless/librootless.la
+endif
+
+if XWIN_NATIVEGDI
+SRCS_NATIVEGDI = \
+ winclip.c \
+ winfillsp.c \
+ winfont.c \
+ wingc.c \
+ wingetsp.c \
+ winnativegdi.c \
+ winpixmap.c \
+ winpolyline.c \
+ winrop.c \
+ winsetsp.c
+DEFS_NATIVEGDI = -DXWIN_NATIVEGDI
+endif
+
+if XWIN_PRIMARYFB
+SRCS_PRIMARYFB = \
+ winpfbdd.c
+DEFS_PRIMARYFB = -DXWIN_PRIMARYFB
+endif
+
+if XWIN_RANDR
+SRCS_RANDR = \
+ winrandr.c
+DEFS_RANDR = -DXWIN_RANDR
+endif
+
+if XWIN_XV
+SRCS_XV = \
+ winvideo.c
+DEFS_XV = -DXWIN_XV
+endif
+
+SRCS = InitInput.c \
+ InitOutput.c \
+ winallpriv.c \
+ winauth.c \
+ winblock.c \
+ wincmap.c \
+ winconfig.c \
+ wincreatewnd.c \
+ wincursor.c \
+ windialogs.c \
+ winengine.c \
+ winerror.c \
+ winglobals.c \
+ winkeybd.c \
+ winkeyhook.c \
+ winmisc.c \
+ winmouse.c \
+ winmsg.c \
+ winmultiwindowclass.c \
+ winmultiwindowicons.c \
+ winprefs.c \
+ winprefsyacc.y \
+ winprefslex.l \
+ winprocarg.c \
+ winregistry.c \
+ winscrinit.c \
+ winshaddd.c \
+ winshadddnl.c \
+ winshadgdi.c \
+ wintrayicon.c \
+ winvalargs.c \
+ winwakeup.c \
+ winwindow.c \
+ winwndproc.c \
+ ddraw.h \
+ winclipboard.h \
+ winconfig.h \
+ win.h \
+ winkeybd.h \
+ winkeynames.h \
+ winlayouts.h \
+ winmessages.h \
+ winmsg.h \
+ winms.h \
+ winmultiwindowclass.h \
+ winprefs.h \
+ winpriv.h \
+ winresource.h \
+ winwindow.h \
+ windisplay.c \
+ XWin.rc \
+ $(top_srcdir)/Xext/dpmsstubs.c \
+ $(top_srcdir)/Xi/stubs.c \
+ $(top_srcdir)/mi/miinitext.c \
+ $(top_srcdir)/fb/fbcmap_mi.c \
+ $(SRCS_CLIPBOARD) \
+ $(SRCS_MULTIWINDOW) \
+ $(SRCS_MULTIWINDOWEXTWM) \
+ $(SRCS_NATIVEGDI) \
+ $(SRCS_PRIMARYFB) \
+ $(SRCS_RANDR) \
+ $(SRCS_XV)
+
+ DEFS = $(DEFS_CLIPBOARD) \
+ $(DEFS_GLX_WINDOWS) \
+ $(DEFS_MULTIWINDOW) \
+ $(DEFS_MULTIWINDOWEXTWM) \
+ $(DEFS_NATIVEGDI) \
+ $(DEFS_PRIMARYFB) \
+ $(DEFS_RANDR) \
+ $(DEFS_XV)
+
+XWin_SOURCES = $(SRCS)
+
+INCLUDES = -I$(top_srcdir)/miext/rootless
+
+XWin_DEPENDENCIES = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS)
+XWin_LDADD = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_GLX_LINK_FLAGS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XWIN_SYS_LIBS)
+XWin_LDFLAGS = -mwindows
+
+.rc.o:
+ $(WINDRES) --use-temp-file -i $< --input-format=rc -o $@ -O coff -I $(top_builddir)/include
+
+winprefsyacc.h: winprefsyacc.c
+winprefslex.c: winprefslex.l winprefsyacc.c winprefsyacc.h
+
+BUILT_SOURCES = winprefsyacc.h winprefsyacc.c winprefslex.c
+CLEANFILES = $(BUILT_SOURCES) $(appman_DATA) $(fileman_DATA) XWin.man XWinrc.man
+
+AM_YFLAGS = -d
+AM_LFLAGS = -i
+AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \
+ $(XWINMODULES_CFLAGS) \
+ -DXFree86Server \
+ -I$(top_srcdir)
+
+MAN_SRCS = XWin.man.pre XWinrc.man.pre
+
+appmandir = $(APP_MAN_DIR)
+appman_DATA = XWin.$(APP_MAN_SUFFIX)
+
+filemandir = $(FILE_MAN_DIR)
+fileman_DATA = XWinrc.$(FILE_MAN_SUFFIX)
+
+XWin.$(APP_MAN_SUFFIX): XWin.man
+ -rm -f XWin.$(APP_MAN_SUFFIX)
+ $(LN_S) XWin.man XWin.$(APP_MAN_SUFFIX)
+
+XWinrc.$(FILE_MAN_SUFFIX): XWinrc.man
+ -rm -f XWinrc.$(FILE_MAN_SUFFIX)
+ $(LN_S) XWinrc.man XWinrc.$(FILE_MAN_SUFFIX)
+
+EXTRAMANDEFS = -D__logdir__=$(logdir) -D__sysconfdir__=$(sysconfdir)
+
+xwinconfigdir = $(sysconfdir)/X11
+xwinconfig_DATA = system.XWinrc
+
+include $(top_srcdir)/cpprules.in
+
+EXTRA_DIST = \
+ $(MAN_SRCS) \
+ X.ico \
+ XWin.rc \
+ xlaunch/config.cc \
+ xlaunch/COPYING \
+ xlaunch/main.cc \
+ xlaunch/resources/dialog.rc \
+ xlaunch/resources/fullscreen.bmp \
+ xlaunch/resources/images.rc \
+ xlaunch/resources/multiwindow.bmp \
+ xlaunch/resources/nodecoration.bmp \
+ xlaunch/resources/resources.h \
+ xlaunch/resources/resources.rc \
+ xlaunch/resources/strings.rc \
+ xlaunch/resources/windowed.bmp \
+ xlaunch/window/dialog.cc \
+ xlaunch/window/dialog.h \
+ xlaunch/window/util.cc \
+ xlaunch/window/util.h \
+ xlaunch/window/window.cc \
+ xlaunch/window/window.h \
+ xlaunch/window/wizard.cc \
+ xlaunch/window/wizard.h
+
+relink:
+ rm -f XWin$(EXEEXT) && $(MAKE) XWin$(EXEEXT)
+
+SUBDIRS = $(GLX_DIR) .
+DIST_SUBDIRS = glx .
diff --git a/xorg-server/hw/xwin/glx/indirect.c b/xorg-server/hw/xwin/glx/indirect.c
index 7e88c9a40..7247992dc 100644
--- a/xorg-server/hw/xwin/glx/indirect.c
+++ b/xorg-server/hw/xwin/glx/indirect.c
@@ -489,32 +489,52 @@ static LRESULT CALLBACK GlxWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
+/*
+ Report the extensions split and formatted to avoid overflowing a line
+ */
static void
-glxLogExtensions (char *extensions)
+glxLogExtensions(const char *prefix, const char *extensions)
{
- int i = 0;
- char *strl;
- char *str = xalloc(strlen(extensions) + 1);
+ int length = 0;
+ char *strl;
+ char *str = xalloc(strlen(extensions) + 1);
- if (str == NULL)
+ if (str == NULL)
{
- winDebug("\nglxLogExtensions: xalloc error\n");
- return;
+ ErrorF("glxLogExtensions: xalloc error\n");
+ return;
}
- str[strlen(extensions)] = '\0';
- strncpy (str, extensions, strlen(extensions));
- strl = strtok(str, " ");
- winDebug("%s", strl);
- while (1)
+ str[strlen(extensions)] = '\0';
+ strncpy (str, extensions, strlen(extensions));
+
+ strl = strtok(str, " ");
+ winDebug("%s%s", prefix, strl);
+ length = strlen(prefix) + strlen(strl);
+
+ while (1)
{
- strl = strtok(NULL, " ");
- if (strl == NULL) break;
- if (++i%5 == 0) ErrorF("\n\t\t");
- winDebug(" %s", strl);
+ strl = strtok(NULL, " ");
+ if (strl == NULL) break;
+
+ if (length + strlen(strl) + 1 > 120)
+ {
+ winDebug("\n%s",prefix);
+ length = strlen(prefix);
+ }
+ else
+ {
+ winDebug(" ");
+ length++;
+ }
+
+ winDebug("%s", strl);
+ length = length + strlen(strl);
}
- winDebug("\n");
- xfree(str);
+
+ winDebug("\n");
+
+ xfree(str);
}
/* This is called by GlxExtensionInit() asking the GLX provider if it can handle the screen... */
@@ -604,16 +624,14 @@ glxWinScreenProbe(ScreenPtr pScreen)
// (but we need to have a current context for them to be resolvable)
wglResolveExtensionProcs();
- winDebug("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION));
- winDebug("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
- winDebug("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER));
+ winDebug("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION));
+ winDebug("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
+ winDebug("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER));
gl_extensions = (const char *)glGetStringWrapperNonstatic(GL_EXTENSIONS);
- winDebug("GL_EXTENSIONS: ");
- glxLogExtensions(gl_extensions);
+ glxLogExtensions("GL_EXTENSIONS: ", gl_extensions);
wgl_extensions = wglGetExtensionsStringARBWrapper(hdc);
if (!wgl_extensions) wgl_extensions = "";
- winDebug("WGL_EXTENSIONS:");
- glxLogExtensions(wgl_extensions);
+ glxLogExtensions("WGL_EXTENSIONS: ", wgl_extensions);
// Can you see the problem here? The extensions string is DC specific
// Different DCs for windows on a multimonitor system driven by multiple cards
@@ -751,11 +769,13 @@ glxWinScreenProbe(ScreenPtr pScreen)
if (screen->has_WGL_ARB_multisample)
{
screen->base.GLXversion = xstrdup("1.4");
+ screen->base.GLXmajor = 1;
screen->base.GLXminor = 4;
}
else
{
screen->base.GLXversion = xstrdup("1.3");
+ screen->base.GLXmajor = 1;
screen->base.GLXminor = 3;
}
LogMessage(X_INFO, "AIGLX: Set GLX version to %s\n", screen->base.GLXversion);
@@ -956,7 +976,7 @@ glxWinDrawableCopySubBuffer(__GLXdrawable *drawable,
int x, int y, int w, int h)
{
glAddSwapHintRectWINWrapperNonstatic(x, y, w, h);
- glxWinDrawableSwapBuffers(NULL,drawable);
+ glxWinDrawableSwapBuffers(NULL, drawable);
}
static void
diff --git a/xorg-server/hw/xwin/glx/winpriv.h b/xorg-server/hw/xwin/glx/winpriv.h
index b3a2c606b..0b19c8c3f 100644
--- a/xorg-server/hw/xwin/glx/winpriv.h
+++ b/xorg-server/hw/xwin/glx/winpriv.h
@@ -1,21 +1,20 @@
-/*
- * Export window information for the Windows-OpenGL GLX implementation.
- *
- * Authors: Alexander Gottwald
- */
-
-#include <X11/Xwindows.h>
-#include <windowstr.h>
-
-#define WIN_GL_WINDOW_CLASS "XWinGLTest"
-
-typedef struct
-{
- HWND hwnd;
- HRGN hrgn;
- RECT rect;
-} winWindowInfoRec, *winWindowInfoPtr;
-
-void winGetWindowInfo(WindowPtr pWin, winWindowInfoPtr pWinInfo);
-Bool winCheckScreenAiglxIsSupported(ScreenPtr pScreen);
-
+/*
+ * Export window information for the Windows-OpenGL GLX implementation.
+ *
+ * Authors: Alexander Gottwald
+ */
+
+#include <X11/Xwindows.h>
+#include <windowstr.h>
+
+#define WIN_GL_WINDOW_CLASS "XWinGLTest"
+
+typedef struct
+{
+ HWND hwnd;
+ HRGN hrgn;
+ RECT rect;
+} winWindowInfoRec, *winWindowInfoPtr;
+
+void winGetWindowInfo(WindowPtr pWin, winWindowInfoPtr pWinInfo);
+Bool winCheckScreenAiglxIsSupported(ScreenPtr pScreen);
diff --git a/xorg-server/hw/xwin/win.h b/xorg-server/hw/xwin/win.h
index c60dd9fe0..3672c135e 100644
--- a/xorg-server/hw/xwin/win.h
+++ b/xorg-server/hw/xwin/win.h
@@ -194,7 +194,7 @@ typedef int pid_t;
* Windows headers
*/
#include "winms.h"
-#include "./winresource.h"
+#include "winresource.h"
/*
diff --git a/xorg-server/hw/xwin/winauth.c b/xorg-server/hw/xwin/winauth.c
index fca6da086..581098694 100644
--- a/xorg-server/hw/xwin/winauth.c
+++ b/xorg-server/hw/xwin/winauth.c
@@ -134,7 +134,7 @@ GenerateAuthorization(
*/
Bool
-winGenerateAuthorization ()
+winGenerateAuthorization (void)
{
Bool fFreeAuth = FALSE;
SecurityAuthorizationPtr pAuth = NULL;
diff --git a/xorg-server/hw/xwin/winclipboardthread.c b/xorg-server/hw/xwin/winclipboardthread.c
index e08e7acd0..5359c18ac 100644
--- a/xorg-server/hw/xwin/winclipboardthread.c
+++ b/xorg-server/hw/xwin/winclipboardthread.c
@@ -492,7 +492,7 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr)
static int
winClipboardIOErrorHandler (Display *pDisplay)
{
- ErrorF ("\nwinClipboardIOErrorHandler!\n\n");
+ ErrorF ("winClipboardIOErrorHandler!\n\n");
/* Restart at the main entry point */
longjmp (g_jmpEntry, WIN_JMP_ERROR_IO);
diff --git a/xorg-server/hw/xwin/winconfig.c b/xorg-server/hw/xwin/winconfig.c
index c2a0ef7ec..c3b9dcc35 100644
--- a/xorg-server/hw/xwin/winconfig.c
+++ b/xorg-server/hw/xwin/winconfig.c
@@ -328,7 +328,7 @@ winConfigKeyboard (DeviceIntPtr pDevice)
const char regtempl[] =
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\";
char *regpath;
- char lname[256];
+ unsigned char lname[256];
DWORD namesize = sizeof(lname);
regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1);
diff --git a/xorg-server/hw/xwin/winkeybd.c b/xorg-server/hw/xwin/winkeybd.c
index ad5df404c..a339afa90 100644
--- a/xorg-server/hw/xwin/winkeybd.c
+++ b/xorg-server/hw/xwin/winkeybd.c
@@ -486,7 +486,7 @@ winSendKeyEvent (DWORD dwKey, Bool fDown)
nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE);
for (i = 0; i < nevents; i++)
- mieqEnqueue(g_pwinKeyboard, (InternalEvent*)(events + i)->event);
+ mieqEnqueue(g_pwinKeyboard, (InternalEvent*)events[i].event);
winDebug("winSendKeyEvent: dwKey: %d, fDown: %d, nEvents %d\n",
dwKey, fDown, nevents);
diff --git a/xorg-server/hw/xwin/winmouse.c b/xorg-server/hw/xwin/winmouse.c
index c5069d630..1280e6b05 100644
--- a/xorg-server/hw/xwin/winmouse.c
+++ b/xorg-server/hw/xwin/winmouse.c
@@ -250,7 +250,7 @@ winMouseButtonsSendEvent (int iEventType, int iButton)
POINTER_RELATIVE, 0, 0, NULL);
for (i = 0; i < nevents; i++)
- mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event);
+ mieqEnqueue(g_pwinPointer, (InternalEvent*)events[i].event);
winDebug("winMouseButtonsSendEvent: iEventType: %d, iButton: %d, nEvents %d\n",
iEventType, iButton, nevents);
@@ -381,5 +381,5 @@ void winEnqueueMotion(int x, int y)
POINTER_ABSOLUTE | POINTER_SCREEN, 0, 2, valuators);
for (i = 0; i < nevents; i++)
- mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event);
+ mieqEnqueue(g_pwinPointer, (InternalEvent*)events[i].event);
}
diff --git a/xorg-server/hw/xwin/winmultiwindowwm.c b/xorg-server/hw/xwin/winmultiwindowwm.c
index 781abf32c..ea1ff517d 100644
--- a/xorg-server/hw/xwin/winmultiwindowwm.c
+++ b/xorg-server/hw/xwin/winmultiwindowwm.c
@@ -853,7 +853,7 @@ winMultiWindowXMsgProc (void *pArg)
if (pProcArg->pDisplay == NULL)
{
winDebug ("winMultiWindowXMsgProc - Could not open display, try: %d, "
- "sleeping: %d\n\f",
+ "sleeping: %d\n",
iRetries + 1, WIN_CONNECT_DELAY);
++iRetries;
sleep (WIN_CONNECT_DELAY);
@@ -1223,7 +1223,7 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
if (pWMInfo->pDisplay == NULL)
{
ErrorF ("winInitMultiWindowWM - Could not open display, try: %d, "
- "sleeping: %d\n\f",
+ "sleeping: %d\n",
iRetries + 1, WIN_CONNECT_DELAY);
++iRetries;
sleep (WIN_CONNECT_DELAY);
@@ -1335,7 +1335,7 @@ winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr)
static int
winMultiWindowWMIOErrorHandler (Display *pDisplay)
{
- ErrorF ("\nwinMultiWindowWMIOErrorHandler!\n\n");
+ ErrorF ("winMultiWindowWMIOErrorHandler!\n\n");
if (g_shutdown)
pthread_exit(NULL);
@@ -1384,7 +1384,7 @@ winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr)
static int
winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay)
{
- ErrorF ("\nwinMultiWindowXMsgProcIOErrorHandler!\n\n");
+ ErrorF ("winMultiWindowXMsgProcIOErrorHandler!\n\n");
/* Restart at the main entry point */
longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO);
diff --git a/xorg-server/hw/xwin/winscrinit.c b/xorg-server/hw/xwin/winscrinit.c
index db65a5eed..992b277e7 100644
--- a/xorg-server/hw/xwin/winscrinit.c
+++ b/xorg-server/hw/xwin/winscrinit.c
@@ -246,7 +246,7 @@ winScreenInit (int index,
dixScreenOrigins[index].x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN);
dixScreenOrigins[index].y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);
- winDebug("Screen %d added at XINERAMA coordinate (%d,%d).\n",
+ winDebug("Screen %d added at virtual desktop coordinate (%d,%d).\n",
index, dixScreenOrigins[index].x, dixScreenOrigins[index].y);
winDebug ("winScreenInit - returning\n");
diff --git a/xorg-server/hw/xwin/winshaddd.c b/xorg-server/hw/xwin/winshaddd.c
index a7ee92802..435901b29 100644
--- a/xorg-server/hw/xwin/winshaddd.c
+++ b/xorg-server/hw/xwin/winshaddd.c
@@ -1,1413 +1,1413 @@
-/*
- *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the name of the XFree86 Project
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from the XFree86 Project.
- *
- * Authors: Dakshinamurthy Karra
- * Suhaib M Siddiqi
- * Peter Busch
- * Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-
-/*
- * External symbols
- */
-
-extern HWND g_hDlgExit;
-extern const char *g_pszLogFile;
-
-
-
-/*
- * Local prototypes
- */
-
-static Bool
-winAllocateFBShadowDD (ScreenPtr pScreen);
-
-static void
-winShadowUpdateDD (ScreenPtr pScreen,
- shadowBufPtr pBuf);
-
-static Bool
-winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen);
-
-static Bool
-winInitVisualsShadowDD (ScreenPtr pScreen);
-
-static Bool
-winAdjustVideoModeShadowDD (ScreenPtr pScreen);
-
-static Bool
-winBltExposedRegionsShadowDD (ScreenPtr pScreen);
-
-static Bool
-winActivateAppShadowDD (ScreenPtr pScreen);
-
-static Bool
-winRedrawScreenShadowDD (ScreenPtr pScreen);
-
-static Bool
-winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen);
-
-static Bool
-winInstallColormapShadowDD (ColormapPtr pColormap);
-
-static Bool
-winStoreColorsShadowDD (ColormapPtr pmap,
- int ndef,
- xColorItem *pdefs);
-
-static Bool
-winCreateColormapShadowDD (ColormapPtr pColormap);
-
-static Bool
-winDestroyColormapShadowDD (ColormapPtr pColormap);
-
-static Bool
-winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen);
-
-static Bool
-winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen);
-
-
-/*
- * Create the primary surface and attach the clipper.
- * Used for both the initial surface creation and during
- * WM_DISPLAYCHANGE messages.
- */
-
-static Bool
-winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- HRESULT ddrval = DD_OK;
- DDSURFACEDESC ddsd;
-
- /* Describe the primary surface */
- ZeroMemory (&ddsd, sizeof (ddsd));
- ddsd.dwSize = sizeof (ddsd);
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
-
- /* Create the primary surface */
- ddrval = IDirectDraw2_CreateSurface (pScreenPriv->pdd2,
- &ddsd,
- &pScreenPriv->pddsPrimary,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winCreatePrimarySurfaceShadowDD - Could not create primary "
- "surface: %08x\n", (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winCreatePrimarySurfaceShadowDD - Created primary surface\n");
-
- /*
- * Attach a clipper to the primary surface that will clip our blits to our
- * display window.
- */
- ddrval = IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
- pScreenPriv->pddcPrimary);
- if (FAILED (ddrval))
- {
- ErrorF ("winCreatePrimarySurfaceShadowDD - Primary attach clipper "
- "failed: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winCreatePrimarySurfaceShadowDD - Attached clipper to "
- "primary surface\n");
-
- /* Everything was correct */
- return TRUE;
-}
-
-
-/*
- * Detach the clipper and release the primary surface.
- * Called from WM_DISPLAYCHANGE.
- */
-
-static Bool
-winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
-
- winDebug ("winReleasePrimarySurfaceShadowDD - Hello\n");
-
- /* Release the primary surface and clipper, if they exist */
- if (pScreenPriv->pddsPrimary)
- {
- /*
- * Detach the clipper from the primary surface.
- * NOTE: We do this explicity for clarity. The Clipper is not released.
- */
- IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
- NULL);
-
- winDebug ("winReleasePrimarySurfaceShadowDD - Detached clipper\n");
-
- /* Release the primary surface */
- IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
- pScreenPriv->pddsPrimary = NULL;
- }
-
- winDebug ("winReleasePrimarySurfaceShadowDD - Released primary surface\n");
-
- return TRUE;
-}
-
-
-/*
- * Create a DirectDraw surface for the shadow framebuffer; also create
- * a primary surface object so we can blit to the display.
- *
- * Install a DirectDraw clipper on our primary surface object
- * that clips our blits to the unobscured client area of our display window.
- */
-
-static Bool
-winAllocateFBShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HRESULT ddrval = DD_OK;
- DDSURFACEDESC ddsd;
- DDSURFACEDESC *pddsdShadow = NULL;
-
- winDebug ("winAllocateFBShadowDD\n");
-
- /* Create a clipper */
- ddrval = (*g_fpDirectDrawCreateClipper) (0,
- &pScreenPriv->pddcPrimary,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not create clipper: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDD - Created a clipper\n");
-
- /* Get a device context for the screen */
- pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
-
- /* Attach the clipper to our display window */
- ddrval = IDirectDrawClipper_SetHWnd (pScreenPriv->pddcPrimary,
- 0,
- pScreenPriv->hwndScreen);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Clipper not attached to "
- "window: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDD - Attached clipper to window\n");
-
- /* Create a DirectDraw object, store the address at lpdd */
- ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not start DirectDraw: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDD () - Created and initialized DD\n");
-
- /* Get a DirectDraw2 interface pointer */
- ddrval = IDirectDraw_QueryInterface (pScreenPriv->pdd,
- &IID_IDirectDraw2,
- (LPVOID*) &pScreenPriv->pdd2);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Failed DD2 query: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- /* Are we full screen? */
- if (pScreenInfo->fFullScreen)
- {
- DDSURFACEDESC ddsdCurrent;
- DWORD dwRefreshRateCurrent = 0;
- HDC hdc = NULL;
-
- /* Set the cooperative level to full screen */
- ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
- pScreenPriv->hwndScreen,
- DDSCL_EXCLUSIVE
- | DDSCL_FULLSCREEN);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not set "
- "cooperative level: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- /*
- * We only need to get the current refresh rate for comparison
- * if a refresh rate has been passed on the command line.
- */
- if (pScreenInfo->dwRefreshRate != 0)
- {
- ZeroMemory (&ddsdCurrent, sizeof (ddsdCurrent));
- ddsdCurrent.dwSize = sizeof (ddsdCurrent);
-
- /* Get information about current display settings */
- ddrval = IDirectDraw2_GetDisplayMode (pScreenPriv->pdd2,
- &ddsdCurrent);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not get current "
- "refresh rate: %08x. Continuing.\n",
- (unsigned int) ddrval);
- dwRefreshRateCurrent = 0;
- }
- else
- {
- /* Grab the current refresh rate */
- dwRefreshRateCurrent = ddsdCurrent.u2.dwRefreshRate;
- }
- }
-
- /* Clean up the refresh rate */
- if (dwRefreshRateCurrent == pScreenInfo->dwRefreshRate)
- {
- /*
- * Refresh rate is non-specified or equal to current.
- */
- pScreenInfo->dwRefreshRate = 0;
- }
-
- /* Grab a device context for the screen */
- hdc = GetDC (NULL);
- if (hdc == NULL)
- {
- ErrorF ("winAllocateFBShadowDD - GetDC () failed\n");
- return FALSE;
- }
-
- /* Only change the video mode when different than current mode */
- if (!pScreenInfo->fMultipleMonitors
- && (pScreenInfo->dwWidth != GetSystemMetrics (SM_CXSCREEN)
- || pScreenInfo->dwHeight != GetSystemMetrics (SM_CYSCREEN)
- || pScreenInfo->dwBPP != GetDeviceCaps (hdc, BITSPIXEL)
- || pScreenInfo->dwRefreshRate != 0))
- {
- winDebug ("winAllocateFBShadowDD - Changing video mode\n");
-
- /* Change the video mode to the mode requested, and use the driver default refresh rate on failure */
- ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2,
- pScreenInfo->dwWidth,
- pScreenInfo->dwHeight,
- pScreenInfo->dwBPP,
- pScreenInfo->dwRefreshRate,
- 0);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not set "\
- "full screen display mode: %08x\n",
- (unsigned int) ddrval);
- ErrorF ("winAllocateFBShadowDD - Using default driver refresh rate\n");
- ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2,
- pScreenInfo->dwWidth,
- pScreenInfo->dwHeight,
- pScreenInfo->dwBPP,
- 0,
- 0);
- if (FAILED(ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not set default refresh rate "
- "full screen display mode: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
- }
- }
- else
- {
- winDebug ("winAllocateFBShadowDD - Not changing video mode\n");
- }
-
- /* Release our DC */
- ReleaseDC (NULL, hdc);
- hdc = NULL;
- }
- else
- {
- /* Set the cooperative level for windowed mode */
- ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
- pScreenPriv->hwndScreen,
- DDSCL_NORMAL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not set "\
- "cooperative level: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
- }
-
- /* Create the primary surface */
- if (!winCreatePrimarySurfaceShadowDD (pScreen))
- {
- ErrorF ("winAllocateFBShadowDD - winCreatePrimarySurfaceShadowDD "
- "failed\n");
- return FALSE;
- }
-
- /* Describe the shadow surface to be created */
- /* NOTE: Do not use a DDSCAPS_VIDEOMEMORY surface,
- * as drawing, locking, and unlocking take forever
- * with video memory surfaces. In addition,
- * video memory is a somewhat scarce resource,
- * so you shouldn't be allocating video memory when
- * you have the option of using system memory instead.
- */
- ZeroMemory (&ddsd, sizeof (ddsd));
- ddsd.dwSize = sizeof (ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
- ddsd.dwHeight = pScreenInfo->dwHeight;
- ddsd.dwWidth = pScreenInfo->dwWidth;
-
- /* Create the shadow surface */
- ddrval = IDirectDraw2_CreateSurface (pScreenPriv->pdd2,
- &ddsd,
- &pScreenPriv->pddsShadow,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDD - Could not create shadow "\
- "surface: %08x\n", (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDD - Created shadow\n");
-
- /* Allocate a DD surface description for our screen privates */
- pddsdShadow = pScreenPriv->pddsdShadow = malloc (sizeof (DDSURFACEDESC));
- if (pddsdShadow == NULL)
- {
- ErrorF ("winAllocateFBShadowDD - Could not allocate surface "\
- "description memory\n");
- return FALSE;
- }
- ZeroMemory (pddsdShadow, sizeof (*pddsdShadow));
- pddsdShadow->dwSize = sizeof (*pddsdShadow);
-
- winDebug ("winAllocateFBShadowDD - Locking shadow\n");
-
- /* Lock the shadow surface */
- ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
- NULL,
- pddsdShadow,
- DDLOCK_WAIT,
- NULL);
- if (FAILED (ddrval) || pddsdShadow->lpSurface == NULL)
- {
- ErrorF ("winAllocateFBShadowDD - Could not lock shadow "\
- "surface: %08x\n", (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDD - Locked shadow\n");
-
- /* We don't know how to deal with anything other than RGB */
- if (!(pddsdShadow->ddpfPixelFormat.dwFlags & DDPF_RGB))
- {
- ErrorF ("winAllocateFBShadowDD - Color format other than RGB\n");
- return FALSE;
- }
-
- /* Grab the pitch from the surface desc */
- pScreenInfo->dwStride = (pddsdShadow->u1.lPitch * 8)
- / pScreenInfo->dwBPP;
-
- /* Save the pointer to our surface memory */
- pScreenInfo->pfb = pddsdShadow->lpSurface;
-
- /* Grab the color depth and masks from the surface description */
- pScreenPriv->dwRedMask = pddsdShadow->ddpfPixelFormat.u2.dwRBitMask;
- pScreenPriv->dwGreenMask = pddsdShadow->ddpfPixelFormat.u3.dwGBitMask;
- pScreenPriv->dwBlueMask = pddsdShadow->ddpfPixelFormat.u4.dwBBitMask;
-
- winDebug ("winAllocateFBShadowDD - Returning\n");
-
- return TRUE;
-}
-
-
-/*
- * Transfer the damaged regions of the shadow framebuffer to the display.
- */
-
-static void
-winShadowUpdateDD (ScreenPtr pScreen,
- shadowBufPtr pBuf)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- RegionPtr damage = shadowDamage(pBuf);
- HRESULT ddrval = DD_OK;
- RECT rcDest, rcSrc;
- POINT ptOrigin;
- DWORD dwBox = REGION_NUM_RECTS (damage);
- BoxPtr pBox = REGION_RECTS (damage);
- HRGN hrgnTemp = NULL, hrgnCombined = NULL;
-
- /*
- * Return immediately if the app is not active
- * and we are fullscreen, or if we have a bad display depth
- */
- if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen)
- || pScreenPriv->fBadDepth) return;
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
-
- /* Unlock the shadow surface, so we can blit */
- ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winShadowUpdateDD - Unlock failed\n");
- return;
- }
-
- /*
- * Handle small regions with multiple blits,
- * handle large regions by creating a clipping region and
- * doing a single blit constrained to that clipping region.
- */
- if (pScreenInfo->dwClipUpdatesNBoxes == 0
- || dwBox < pScreenInfo->dwClipUpdatesNBoxes)
- {
- /* Loop through all boxes in the damaged region */
- while (dwBox--)
- {
- /* Assign damage box to source rectangle */
- rcSrc.left = pBox->x1;
- rcSrc.top = pBox->y1;
- rcSrc.right = pBox->x2;
- rcSrc.bottom = pBox->y2;
-
- /* Calculate destination rectange */
- rcDest.left = ptOrigin.x + rcSrc.left;
- rcDest.top = ptOrigin.y + rcSrc.top;
- rcDest.right = ptOrigin.x + rcSrc.right;
- rcDest.bottom = ptOrigin.y + rcSrc.bottom;
-
- /* Blit the damaged areas */
- ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
- &rcDest,
- pScreenPriv->pddsShadow,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
-
- /* Get a pointer to the next box */
- ++pBox;
- }
- }
- else
- {
- BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage);
-
- /* Compute a GDI region from the damaged region */
- hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
- dwBox--;
- pBox++;
- while (dwBox--)
- {
- hrgnTemp = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
- CombineRgn (hrgnCombined, hrgnCombined, hrgnTemp, RGN_OR);
- DeleteObject (hrgnTemp);
- pBox++;
- }
-
- /* Install the GDI region as a clipping region */
- SelectClipRgn (pScreenPriv->hdcScreen, hrgnCombined);
- DeleteObject (hrgnCombined);
- hrgnCombined = NULL;
-
- /* Calculating a bounding box for the source is easy */
- rcSrc.left = pBoxExtents->x1;
- rcSrc.top = pBoxExtents->y1;
- rcSrc.right = pBoxExtents->x2;
- rcSrc.bottom = pBoxExtents->y2;
-
- /* Calculating a bounding box for the destination is trickier */
- rcDest.left = ptOrigin.x + rcSrc.left;
- rcDest.top = ptOrigin.y + rcSrc.top;
- rcDest.right = ptOrigin.x + rcSrc.right;
- rcDest.bottom = ptOrigin.y + rcSrc.bottom;
-
- /* Our Blt should be clipped to the invalidated region */
- ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
- &rcDest,
- pScreenPriv->pddsShadow,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
-
- /* Reset the clip region */
- SelectClipRgn (pScreenPriv->hdcScreen, NULL);
- }
-
- /* Relock the shadow surface */
- ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
- NULL,
- pScreenPriv->pddsdShadow,
- DDLOCK_WAIT,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winShadowUpdateDD - Lock failed\n");
- return;
- }
-
- /* Has our memory pointer changed? */
- if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
- {
- extern const char *g_pszLogFile;
- ErrorF ("winShadowUpdateDD - Memory location of the shadow "
- "surface has changed, trying to update the root window "
- "pixmap header to point to the new address. If you get "
- "this message and "PROJECT_NAME" freezes or crashes "
- "after this message then send a problem report and your "
- "%s file to " BUILDERADDR, g_pszLogFile);
-
- /* Location of shadow framebuffer has changed */
- pScreenInfo->pfb = pScreenPriv->pddsdShadow->lpSurface;
-
- /* Update the screen pixmap */
- if (!(*pScreen->ModifyPixmapHeader)(pScreen->devPrivate,
- pScreen->width,
- pScreen->height,
- pScreen->rootDepth,
- BitsPerPixel (pScreen->rootDepth),
- PixmapBytePad (pScreenInfo->dwStride,
- pScreenInfo->dwBPP),
- pScreenInfo->pfb))
- {
- ErrorF ("winShadowUpdateDD - Bits changed, could not "
- "notify fb.\n");
- return;
- }
- }
-}
-
-
-/*
- * Call the wrapped CloseScreen function.
- *
- * Free our resources and private structures.
- */
-
-static Bool
-winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- Bool fReturn;
-
- winDebug ("winCloseScreenShadowDD - Freeing screen resources\n");
-
- /* Flag that the screen is closed */
- pScreenPriv->fClosed = TRUE;
- pScreenPriv->fActive = FALSE;
-
- /* Call the wrapped CloseScreen procedure */
- WIN_UNWRAP(CloseScreen);
- fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
-
- /* Free the screen DC */
- ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
-
- /* Delete the window property */
- RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
-
- /* Free the shadow surface, if there is one */
- if (pScreenPriv->pddsShadow)
- {
- IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
- IDirectDrawSurface2_Release (pScreenPriv->pddsShadow);
- pScreenPriv->pddsShadow = NULL;
- }
-
- /* Detach the clipper from the primary surface and release the clipper. */
- if (pScreenPriv->pddcPrimary)
- {
- /* Detach the clipper */
- IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
- NULL);
-
- /* Release the clipper object */
- IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
- pScreenPriv->pddcPrimary = NULL;
- }
-
- /* Release the primary surface, if there is one */
- if (pScreenPriv->pddsPrimary)
- {
- IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
- pScreenPriv->pddsPrimary = NULL;
- }
-
- /* Free the DirectDraw2 object, if there is one */
- if (pScreenPriv->pdd2)
- {
- IDirectDraw2_RestoreDisplayMode (pScreenPriv->pdd2);
- IDirectDraw2_Release (pScreenPriv->pdd2);
- pScreenPriv->pdd2 = NULL;
- }
-
- /* Free the DirectDraw object, if there is one */
- if (pScreenPriv->pdd)
- {
- IDirectDraw_Release (pScreenPriv->pdd);
- pScreenPriv->pdd = NULL;
- }
-
- /* Delete tray icon, if we have one */
- if (!pScreenInfo->fNoTrayIcon)
- winDeleteNotifyIcon (pScreenPriv);
-
- /* Free the exit confirmation dialog box, if it exists */
- if (g_hDlgExit != NULL)
- {
- DestroyWindow (g_hDlgExit);
- g_hDlgExit = NULL;
- }
-
- /* Kill our window */
- if (pScreenPriv->hwndScreen)
- {
- DestroyWindow (pScreenPriv->hwndScreen);
- pScreenPriv->hwndScreen = NULL;
- }
-
-#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
- /* Destroy the thread startup mutex */
- pthread_mutex_destroy (&pScreenPriv->pmServerStarted);
-#endif
-
- /* Kill our screeninfo's pointer to the screen */
- pScreenInfo->pScreen = NULL;
-
- /* Invalidate the ScreenInfo's fb pointer */
- pScreenInfo->pfb = NULL;
-
- /* Free the screen privates for this screen */
- free ((pointer) pScreenPriv);
-
- return fReturn;
-}
-
-
-/*
- * Tell mi what sort of visuals we need.
- *
- * Generally we only need one visual, as our screen can only
- * handle one format at a time, I believe. You may want
- * to verify that last sentence.
- */
-
-static Bool
-winInitVisualsShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- DWORD dwRedBits, dwGreenBits, dwBlueBits;
-
- /* Count the number of ones in each color mask */
- dwRedBits = winCountBits (pScreenPriv->dwRedMask);
- dwGreenBits = winCountBits (pScreenPriv->dwGreenMask);
- dwBlueBits = winCountBits (pScreenPriv->dwBlueMask);
-
- /* Store the maximum number of ones in a color mask as the bitsPerRGB */
- if (dwRedBits == 0 || dwGreenBits == 0 || dwBlueBits == 0)
- pScreenPriv->dwBitsPerRGB = 8;
- else if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
- pScreenPriv->dwBitsPerRGB = dwRedBits;
- else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
- pScreenPriv->dwBitsPerRGB = dwGreenBits;
- else
- pScreenPriv->dwBitsPerRGB = dwBlueBits;
-
- winDebug ("winInitVisualsShadowDD - Masks %08x %08x %08x BPRGB %d d %d "
- "bpp %d\n",
- (unsigned int) pScreenPriv->dwRedMask,
- (unsigned int) pScreenPriv->dwGreenMask,
- (unsigned int) pScreenPriv->dwBlueMask,
- (int) pScreenPriv->dwBitsPerRGB,
- (int) pScreenInfo->dwDepth,
- (int) pScreenInfo->dwBPP);
-
- /* Create a single visual according to the Windows screen depth */
- switch (pScreenInfo->dwDepth)
- {
- case 24:
- case 16:
- case 15:
-#if defined(XFree86Server)
- /* Create the real visual */
- if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- TrueColorMask,
- pScreenPriv->dwBitsPerRGB,
- TrueColor,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
- "failed for TrueColor\n");
- return FALSE;
- }
-
-#ifdef XWIN_EMULATEPSEUDO
- if (!pScreenInfo->fEmulatePseudo)
- break;
-
- /* Setup a pseudocolor visual */
- if (!miSetVisualTypesAndMasks (8,
- PseudoColorMask,
- 8,
- -1,
- 0,
- 0,
- 0))
- {
- ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
- "failed for PseudoColor\n");
- return FALSE;
- }
-#endif
-#else /* XFree86Server */
- /* Create the real visual */
- if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- TrueColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
- "failed for TrueColor\n");
- return FALSE;
- }
-
-#ifdef XWIN_EMULATEPSEUDO
- if (!pScreenInfo->fEmulatePseudo)
- break;
-
- /* Setup a pseudocolor visual */
- if (!fbSetVisualTypesAndMasks (8,
- PseudoColorMask,
- 8,
- 0,
- 0,
- 0))
- {
- ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
- "failed for PseudoColor\n");
- return FALSE;
- }
-#endif
-#endif /* XFree86Server */
- break;
-
- case 8:
-#if defined(XFree86Server)
- if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- pScreenInfo->fFullScreen
- ? PseudoColorMask : StaticColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenInfo->fFullScreen
- ? PseudoColor : StaticColor,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
- "failed\n");
- return FALSE;
- }
-#else /* XFree86Server */
- if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- pScreenInfo->fFullScreen
- ? PseudoColorMask : StaticColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
- "failed\n");
- return FALSE;
- }
-#endif /* XFree86Server */
- break;
-
- default:
- ErrorF ("winInitVisualsShadowDD - Unknown screen depth\n");
- return FALSE;
- }
-
- winDebug ("winInitVisualsShadowDD - Returning\n");
-
- return TRUE;
-}
-
-
-/*
- * Adjust the user proposed video mode
- */
-
-static Bool
-winAdjustVideoModeShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HDC hdc = NULL;
- DWORD dwBPP;
-
- /* We're in serious trouble if we can't get a DC */
- hdc = GetDC (NULL);
- if (hdc == NULL)
- {
- ErrorF ("winAdjustVideoModeShadowDD - GetDC () failed\n");
- return FALSE;
- }
-
- /* Query GDI for current display depth */
- dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
-
- /* DirectDraw can only change the depth in fullscreen mode */
- if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
- {
- /* No -depth parameter passed, let the user know the depth being used */
- winDebug ("winAdjustVideoModeShadowDD - Using Windows display "
- "depth of %d bits per pixel\n", (int) dwBPP);
-
- /* Use GDI's depth */
- pScreenInfo->dwBPP = dwBPP;
- }
- else if (pScreenInfo->fFullScreen
- && pScreenInfo->dwBPP != dwBPP)
- {
- /* FullScreen, and GDI depth differs from -depth parameter */
- winDebug ("winAdjustVideoModeShadowDD - FullScreen, using command line "
- "bpp: %d\n", (int) pScreenInfo->dwBPP);
- }
- else if (dwBPP != pScreenInfo->dwBPP)
- {
- /* Windowed, and GDI depth differs from -depth parameter */
- winDebug ("winAdjustVideoModeShadowDD - Windowed, command line bpp: "
- "%d, using bpp: %d\n", (int) pScreenInfo->dwBPP, (int) dwBPP);
-
- /* We'll use GDI's depth */
- pScreenInfo->dwBPP = dwBPP;
- }
-
- /* See if the shadow bitmap will be larger than the DIB size limit */
- if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP
- >= WIN_DIB_MAXIMUM_SIZE)
- {
- ErrorF ("winAdjustVideoModeShadowDD - Requested DirectDraw surface "
- "will be larger than %d MB. The surface may fail to be "
- "allocated on Windows 95, 98, or Me, due to a %d MB limit in "
- "DIB size. This limit does not apply to Windows NT/2000, and "
- "this message may be ignored on those platforms.\n",
- WIN_DIB_MAXIMUM_SIZE_MB, WIN_DIB_MAXIMUM_SIZE_MB);
- }
-
- /* Release our DC */
- ReleaseDC (NULL, hdc);
- return TRUE;
-}
-
-
-/*
- * Blt exposed regions to the screen
- */
-
-static Bool
-winBltExposedRegionsShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- RECT rcSrc, rcDest;
- POINT ptOrigin;
- HDC hdcUpdate = NULL;
- PAINTSTRUCT ps;
- HRESULT ddrval = DD_OK;
- Bool fReturn = TRUE;
- Bool fLocked = TRUE;
- int i;
-
- /* BeginPaint gives us an hdc that clips to the invalidated region */
- hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
- if (hdcUpdate == NULL)
- {
- ErrorF ("winBltExposedRegionsShadowDD - BeginPaint () returned "
- "a NULL device context handle. Aborting blit attempt.\n");
- return FALSE;
- }
-
- /* Unlock the shadow surface, so we can blit */
- ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
- if (FAILED (ddrval))
- {
- fReturn = FALSE;
- goto winBltExposedRegionsShadowDD_Exit;
- }
- else
- {
- /* Flag that we have unlocked the shadow surface */
- fLocked = FALSE;
- }
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
-
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
- rcDest.left = ptOrigin.x;
- rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
- rcDest.top = ptOrigin.y;
- rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
-
- /* Source can be enter shadow surface, as Blt should clip */
- rcSrc.left = 0;
- rcSrc.top = 0;
- rcSrc.right = pScreenInfo->dwWidth;
- rcSrc.bottom = pScreenInfo->dwHeight;
-
- /* Try to regain the primary surface and blit again if we've lost it */
- for (i = 0; i <= WIN_REGAIN_SURFACE_RETRIES; ++i)
- {
- /* Our Blt should be clipped to the invalidated region */
- ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
- &rcDest,
- pScreenPriv->pddsShadow,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
- if (ddrval == DDERR_SURFACELOST)
- {
- /* Surface was lost */
- ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Blt "
- "reported that the primary surface was lost, "
- "trying to restore, retry: %d\n", i + 1);
-
- /* Try to restore the surface, once */
- ddrval = IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
- ErrorF ("winBltExposedRegionsShadowDD - "
- "IDirectDrawSurface2_Restore returned: ");
- if (ddrval == DD_OK)
- ErrorF ("DD_OK\n");
- else if (ddrval == DDERR_WRONGMODE)
- ErrorF ("DDERR_WRONGMODE\n");
- else if (ddrval == DDERR_INCOMPATIBLEPRIMARY)
- ErrorF ("DDERR_INCOMPATIBLEPRIMARY\n");
- else if (ddrval == DDERR_UNSUPPORTED)
- ErrorF ("DDERR_UNSUPPORTED\n");
- else if (ddrval == DDERR_INVALIDPARAMS)
- ErrorF ("DDERR_INVALIDPARAMS\n");
- else if (ddrval == DDERR_INVALIDOBJECT)
- ErrorF ("DDERR_INVALIDOBJECT\n");
- else
- ErrorF ("unknown error: %08x\n", (unsigned int) ddrval);
-
- /* Loop around to try the blit one more time */
- continue;
- }
- else if (FAILED (ddrval))
- {
- fReturn = FALSE;
- ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Blt "
- "failed, but surface not lost: %08x %d\n",
- (unsigned int) ddrval, (int) ddrval);
- goto winBltExposedRegionsShadowDD_Exit;
- }
- else
- {
- /* Success, stop looping */
- break;
- }
- }
-
- /* Relock the shadow surface */
- ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
- NULL,
- pScreenPriv->pddsdShadow,
- DDLOCK_WAIT,
- NULL);
- if (FAILED (ddrval))
- {
- fReturn = FALSE;
- ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Lock "
- "failed\n");
- goto winBltExposedRegionsShadowDD_Exit;
- }
- else
- {
- /* Indicate that we have relocked the shadow surface */
- fLocked = TRUE;
- }
-
- /* Has our memory pointer changed? */
- if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
- winUpdateFBPointer (pScreen,
- pScreenPriv->pddsdShadow->lpSurface);
-
- winBltExposedRegionsShadowDD_Exit:
- /* EndPaint frees the DC */
- if (hdcUpdate != NULL)
- EndPaint (pScreenPriv->hwndScreen, &ps);
-
- /*
- * Relock the surface if it is not locked. We don't care if locking fails,
- * as it will cause the server to shutdown within a few more operations.
- */
- if (!fLocked)
- {
- IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
- NULL,
- pScreenPriv->pddsdShadow,
- DDLOCK_WAIT,
- NULL);
-
- /* Has our memory pointer changed? */
- if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
- winUpdateFBPointer (pScreen,
- pScreenPriv->pddsdShadow->lpSurface);
-
- fLocked = TRUE;
- }
- return fReturn;
-}
-
-
-/*
- * Do any engine-specific appliation-activation processing
- */
-
-static Bool
-winActivateAppShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
-
- /*
- * Do we have a surface?
- * Are we active?
- * Are we fullscreen?
- */
- if (pScreenPriv != NULL
- && pScreenPriv->pddsPrimary != NULL
- && pScreenPriv->fActive)
- {
- /* Primary surface was lost, restore it */
- IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
- }
-
- return TRUE;
-}
-
-
-/*
- * Reblit the shadow framebuffer to the screen.
- */
-
-static Bool
-winRedrawScreenShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HRESULT ddrval = DD_OK;
- RECT rcSrc, rcDest;
- POINT ptOrigin;
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
- rcDest.left = ptOrigin.x;
- rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
- rcDest.top = ptOrigin.y;
- rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
-
- /* Source can be entire shadow surface, as Blt should clip for us */
- rcSrc.left = 0;
- rcSrc.top = 0;
- rcSrc.right = pScreenInfo->dwWidth;
- rcSrc.bottom = pScreenInfo->dwHeight;
-
- /* Redraw the whole window, to take account for the new colors */
- ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
- &rcDest,
- pScreenPriv->pddsShadow,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winRedrawScreenShadowDD - IDirectDrawSurface_Blt () "
- "failed: %08x\n",
- (unsigned int) ddrval);
- }
-
- return TRUE;
-}
-
-
-/*
- * Realize the currently installed colormap
- */
-
-static Bool
-winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen)
-{
- return TRUE;
-}
-
-
-/*
- * Install the specified colormap
- */
-
-static Bool
-winInstallColormapShadowDD (ColormapPtr pColormap)
-{
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
- HRESULT ddrval = DD_OK;
-
- /* Install the DirectDraw palette on the primary surface */
- ddrval = IDirectDrawSurface2_SetPalette (pScreenPriv->pddsPrimary,
- pCmapPriv->lpDDPalette);
- if (FAILED (ddrval))
- {
- ErrorF ("winInstallColormapShadowDD - Failed installing the "
- "DirectDraw palette.\n");
- return FALSE;
- }
-
- /* Save a pointer to the newly installed colormap */
- pScreenPriv->pcmapInstalled = pColormap;
-
- return TRUE;
-}
-
-
-/*
- * Store the specified colors in the specified colormap
- */
-
-static Bool
-winStoreColorsShadowDD (ColormapPtr pColormap,
- int ndef,
- xColorItem *pdefs)
-{
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
- ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
- HRESULT ddrval = DD_OK;
-
- /* Put the X colormap entries into the Windows logical palette */
- ddrval = IDirectDrawPalette_SetEntries (pCmapPriv->lpDDPalette,
- 0,
- pdefs[0].pixel,
- ndef,
- pCmapPriv->peColors
- + pdefs[0].pixel);
- if (FAILED (ddrval))
- {
- ErrorF ("winStoreColorsShadowDD - SetEntries () failed\n");
- return FALSE;
- }
-
- /* Don't install the DirectDraw palette if the colormap is not installed */
- if (pColormap != curpmap)
- {
- return TRUE;
- }
-
- if (!winInstallColormapShadowDD (pColormap))
- {
- ErrorF ("winStoreColorsShadowDD - Failed installing colormap\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * Colormap initialization procedure
- */
-
-static Bool
-winCreateColormapShadowDD (ColormapPtr pColormap)
-{
- HRESULT ddrval = DD_OK;
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
-
- /* Create a DirectDraw palette */
- ddrval = IDirectDraw2_CreatePalette (pScreenPriv->pdd,
- DDPCAPS_8BIT | DDPCAPS_ALLOW256,
- pCmapPriv->peColors,
- &pCmapPriv->lpDDPalette,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winCreateColormapShadowDD - CreatePalette failed\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * Colormap destruction procedure
- */
-
-static Bool
-winDestroyColormapShadowDD (ColormapPtr pColormap)
-{
- winScreenPriv(pColormap->pScreen);
- winCmapPriv(pColormap);
- HRESULT ddrval = DD_OK;
-
- /*
- * Is colormap to be destroyed the default?
- *
- * Non-default colormaps should have had winUninstallColormap
- * called on them before we get here. The default colormap
- * will not have had winUninstallColormap called on it. Thus,
- * we need to handle the default colormap in a special way.
- */
- if (pColormap->flags & IsDefault)
- {
- winDebug ("winDestroyColormapShadowDD - Destroying default "
- "colormap\n");
-
- /*
- * FIXME: Walk the list of all screens, popping the default
- * palette out of each screen device context.
- */
-
- /* Pop the palette out of the primary surface */
- ddrval = IDirectDrawSurface2_SetPalette (pScreenPriv->pddsPrimary,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winDestroyColormapShadowDD - Failed freeing the "
- "default colormap DirectDraw palette.\n");
- return FALSE;
- }
-
- /* Clear our private installed colormap pointer */
- pScreenPriv->pcmapInstalled = NULL;
- }
-
- /* Release the palette */
- IDirectDrawPalette_Release (pCmapPriv->lpDDPalette);
-
- /* Invalidate the colormap privates */
- pCmapPriv->lpDDPalette = NULL;
-
- return TRUE;
-}
-
-
-/*
- * Set engine specific functions
- */
-
-Bool
-winSetEngineFunctionsShadowDD (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
- /* Set our pointers */
- pScreenPriv->pwinAllocateFB = winAllocateFBShadowDD;
- pScreenPriv->pwinShadowUpdate = winShadowUpdateDD;
- pScreenPriv->pwinCloseScreen = winCloseScreenShadowDD;
- pScreenPriv->pwinInitVisuals = winInitVisualsShadowDD;
- pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowDD;
- if (pScreenInfo->fFullScreen)
- pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
- else
- pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
- pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
- pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowDD;
- pScreenPriv->pwinActivateApp = winActivateAppShadowDD;
- pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowDD;
- pScreenPriv->pwinRealizeInstalledPalette
- = winRealizeInstalledPaletteShadowDD;
- pScreenPriv->pwinInstallColormap = winInstallColormapShadowDD;
- pScreenPriv->pwinStoreColors = winStoreColorsShadowDD;
- pScreenPriv->pwinCreateColormap = winCreateColormapShadowDD;
- pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDD;
- pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
- pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDD;
- pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDD;
-#ifdef XWIN_MULTIWINDOW
- pScreenPriv->pwinFinishCreateWindowsWindow =
- (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA;
-#endif
-
- return TRUE;
-}
+/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+
+/*
+ * External symbols
+ */
+
+extern HWND g_hDlgExit;
+extern const char *g_pszLogFile;
+
+
+
+/*
+ * Local prototypes
+ */
+
+static Bool
+winAllocateFBShadowDD (ScreenPtr pScreen);
+
+static void
+winShadowUpdateDD (ScreenPtr pScreen,
+ shadowBufPtr pBuf);
+
+static Bool
+winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen);
+
+static Bool
+winInitVisualsShadowDD (ScreenPtr pScreen);
+
+static Bool
+winAdjustVideoModeShadowDD (ScreenPtr pScreen);
+
+static Bool
+winBltExposedRegionsShadowDD (ScreenPtr pScreen);
+
+static Bool
+winActivateAppShadowDD (ScreenPtr pScreen);
+
+static Bool
+winRedrawScreenShadowDD (ScreenPtr pScreen);
+
+static Bool
+winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen);
+
+static Bool
+winInstallColormapShadowDD (ColormapPtr pColormap);
+
+static Bool
+winStoreColorsShadowDD (ColormapPtr pmap,
+ int ndef,
+ xColorItem *pdefs);
+
+static Bool
+winCreateColormapShadowDD (ColormapPtr pColormap);
+
+static Bool
+winDestroyColormapShadowDD (ColormapPtr pColormap);
+
+static Bool
+winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen);
+
+static Bool
+winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen);
+
+
+/*
+ * Create the primary surface and attach the clipper.
+ * Used for both the initial surface creation and during
+ * WM_DISPLAYCHANGE messages.
+ */
+
+static Bool
+winCreatePrimarySurfaceShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC ddsd;
+
+ /* Describe the primary surface */
+ ZeroMemory (&ddsd, sizeof (ddsd));
+ ddsd.dwSize = sizeof (ddsd);
+ ddsd.dwFlags = DDSD_CAPS;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+ /* Create the primary surface */
+ ddrval = IDirectDraw2_CreateSurface (pScreenPriv->pdd2,
+ &ddsd,
+ &pScreenPriv->pddsPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winCreatePrimarySurfaceShadowDD - Could not create primary "
+ "surface: %08x\n", (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winCreatePrimarySurfaceShadowDD - Created primary surface\n");
+
+ /*
+ * Attach a clipper to the primary surface that will clip our blits to our
+ * display window.
+ */
+ ddrval = IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
+ pScreenPriv->pddcPrimary);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winCreatePrimarySurfaceShadowDD - Primary attach clipper "
+ "failed: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winCreatePrimarySurfaceShadowDD - Attached clipper to "
+ "primary surface\n");
+
+ /* Everything was correct */
+ return TRUE;
+}
+
+
+/*
+ * Detach the clipper and release the primary surface.
+ * Called from WM_DISPLAYCHANGE.
+ */
+
+static Bool
+winReleasePrimarySurfaceShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ winDebug ("winReleasePrimarySurfaceShadowDD - Hello\n");
+
+ /* Release the primary surface and clipper, if they exist */
+ if (pScreenPriv->pddsPrimary)
+ {
+ /*
+ * Detach the clipper from the primary surface.
+ * NOTE: We do this explicity for clarity. The Clipper is not released.
+ */
+ IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
+ NULL);
+
+ winDebug ("winReleasePrimarySurfaceShadowDD - Detached clipper\n");
+
+ /* Release the primary surface */
+ IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
+ pScreenPriv->pddsPrimary = NULL;
+ }
+
+ winDebug ("winReleasePrimarySurfaceShadowDD - Released primary surface\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Create a DirectDraw surface for the shadow framebuffer; also create
+ * a primary surface object so we can blit to the display.
+ *
+ * Install a DirectDraw clipper on our primary surface object
+ * that clips our blits to the unobscured client area of our display window.
+ */
+
+static Bool
+winAllocateFBShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC ddsd;
+ DDSURFACEDESC *pddsdShadow = NULL;
+
+ winDebug ("winAllocateFBShadowDD\n");
+
+ /* Create a clipper */
+ ddrval = (*g_fpDirectDrawCreateClipper) (0,
+ &pScreenPriv->pddcPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not create clipper: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDD - Created a clipper\n");
+
+ /* Get a device context for the screen */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+
+ /* Attach the clipper to our display window */
+ ddrval = IDirectDrawClipper_SetHWnd (pScreenPriv->pddcPrimary,
+ 0,
+ pScreenPriv->hwndScreen);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Clipper not attached to "
+ "window: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDD - Attached clipper to window\n");
+
+ /* Create a DirectDraw object, store the address at lpdd */
+ ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not start DirectDraw: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDD () - Created and initialized DD\n");
+
+ /* Get a DirectDraw2 interface pointer */
+ ddrval = IDirectDraw_QueryInterface (pScreenPriv->pdd,
+ &IID_IDirectDraw2,
+ (LPVOID*) &pScreenPriv->pdd2);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Failed DD2 query: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ /* Are we full screen? */
+ if (pScreenInfo->fFullScreen)
+ {
+ DDSURFACEDESC ddsdCurrent;
+ DWORD dwRefreshRateCurrent = 0;
+ HDC hdc = NULL;
+
+ /* Set the cooperative level to full screen */
+ ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
+ pScreenPriv->hwndScreen,
+ DDSCL_EXCLUSIVE
+ | DDSCL_FULLSCREEN);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not set "
+ "cooperative level: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ /*
+ * We only need to get the current refresh rate for comparison
+ * if a refresh rate has been passed on the command line.
+ */
+ if (pScreenInfo->dwRefreshRate != 0)
+ {
+ ZeroMemory (&ddsdCurrent, sizeof (ddsdCurrent));
+ ddsdCurrent.dwSize = sizeof (ddsdCurrent);
+
+ /* Get information about current display settings */
+ ddrval = IDirectDraw2_GetDisplayMode (pScreenPriv->pdd2,
+ &ddsdCurrent);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not get current "
+ "refresh rate: %08x. Continuing.\n",
+ (unsigned int) ddrval);
+ dwRefreshRateCurrent = 0;
+ }
+ else
+ {
+ /* Grab the current refresh rate */
+ dwRefreshRateCurrent = ddsdCurrent.u2.dwRefreshRate;
+ }
+ }
+
+ /* Clean up the refresh rate */
+ if (dwRefreshRateCurrent == pScreenInfo->dwRefreshRate)
+ {
+ /*
+ * Refresh rate is non-specified or equal to current.
+ */
+ pScreenInfo->dwRefreshRate = 0;
+ }
+
+ /* Grab a device context for the screen */
+ hdc = GetDC (NULL);
+ if (hdc == NULL)
+ {
+ ErrorF ("winAllocateFBShadowDD - GetDC () failed\n");
+ return FALSE;
+ }
+
+ /* Only change the video mode when different than current mode */
+ if (!pScreenInfo->fMultipleMonitors
+ && (pScreenInfo->dwWidth != GetSystemMetrics (SM_CXSCREEN)
+ || pScreenInfo->dwHeight != GetSystemMetrics (SM_CYSCREEN)
+ || pScreenInfo->dwBPP != GetDeviceCaps (hdc, BITSPIXEL)
+ || pScreenInfo->dwRefreshRate != 0))
+ {
+ winDebug ("winAllocateFBShadowDD - Changing video mode\n");
+
+ /* Change the video mode to the mode requested, and use the driver default refresh rate on failure */
+ ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2,
+ pScreenInfo->dwWidth,
+ pScreenInfo->dwHeight,
+ pScreenInfo->dwBPP,
+ pScreenInfo->dwRefreshRate,
+ 0);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not set "\
+ "full screen display mode: %08x\n",
+ (unsigned int) ddrval);
+ ErrorF ("winAllocateFBShadowDD - Using default driver refresh rate\n");
+ ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2,
+ pScreenInfo->dwWidth,
+ pScreenInfo->dwHeight,
+ pScreenInfo->dwBPP,
+ 0,
+ 0);
+ if (FAILED(ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not set default refresh rate "
+ "full screen display mode: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ winDebug ("winAllocateFBShadowDD - Not changing video mode\n");
+ }
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+ hdc = NULL;
+ }
+ else
+ {
+ /* Set the cooperative level for windowed mode */
+ ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
+ pScreenPriv->hwndScreen,
+ DDSCL_NORMAL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not set "\
+ "cooperative level: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+ }
+
+ /* Create the primary surface */
+ if (!winCreatePrimarySurfaceShadowDD (pScreen))
+ {
+ ErrorF ("winAllocateFBShadowDD - winCreatePrimarySurfaceShadowDD "
+ "failed\n");
+ return FALSE;
+ }
+
+ /* Describe the shadow surface to be created */
+ /* NOTE: Do not use a DDSCAPS_VIDEOMEMORY surface,
+ * as drawing, locking, and unlocking take forever
+ * with video memory surfaces. In addition,
+ * video memory is a somewhat scarce resource,
+ * so you shouldn't be allocating video memory when
+ * you have the option of using system memory instead.
+ */
+ ZeroMemory (&ddsd, sizeof (ddsd));
+ ddsd.dwSize = sizeof (ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+ ddsd.dwHeight = pScreenInfo->dwHeight;
+ ddsd.dwWidth = pScreenInfo->dwWidth;
+
+ /* Create the shadow surface */
+ ddrval = IDirectDraw2_CreateSurface (pScreenPriv->pdd2,
+ &ddsd,
+ &pScreenPriv->pddsShadow,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not create shadow "\
+ "surface: %08x\n", (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDD - Created shadow\n");
+
+ /* Allocate a DD surface description for our screen privates */
+ pddsdShadow = pScreenPriv->pddsdShadow = malloc (sizeof (DDSURFACEDESC));
+ if (pddsdShadow == NULL)
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not allocate surface "\
+ "description memory\n");
+ return FALSE;
+ }
+ ZeroMemory (pddsdShadow, sizeof (*pddsdShadow));
+ pddsdShadow->dwSize = sizeof (*pddsdShadow);
+
+ winDebug ("winAllocateFBShadowDD - Locking shadow\n");
+
+ /* Lock the shadow surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
+ NULL,
+ pddsdShadow,
+ DDLOCK_WAIT,
+ NULL);
+ if (FAILED (ddrval) || pddsdShadow->lpSurface == NULL)
+ {
+ ErrorF ("winAllocateFBShadowDD - Could not lock shadow "\
+ "surface: %08x\n", (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDD - Locked shadow\n");
+
+ /* We don't know how to deal with anything other than RGB */
+ if (!(pddsdShadow->ddpfPixelFormat.dwFlags & DDPF_RGB))
+ {
+ ErrorF ("winAllocateFBShadowDD - Color format other than RGB\n");
+ return FALSE;
+ }
+
+ /* Grab the pitch from the surface desc */
+ pScreenInfo->dwStride = (pddsdShadow->u1.lPitch * 8)
+ / pScreenInfo->dwBPP;
+
+ /* Save the pointer to our surface memory */
+ pScreenInfo->pfb = pddsdShadow->lpSurface;
+
+ /* Grab the color depth and masks from the surface description */
+ pScreenPriv->dwRedMask = pddsdShadow->ddpfPixelFormat.u2.dwRBitMask;
+ pScreenPriv->dwGreenMask = pddsdShadow->ddpfPixelFormat.u3.dwGBitMask;
+ pScreenPriv->dwBlueMask = pddsdShadow->ddpfPixelFormat.u4.dwBBitMask;
+
+ winDebug ("winAllocateFBShadowDD - Returning\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Transfer the damaged regions of the shadow framebuffer to the display.
+ */
+
+static void
+winShadowUpdateDD (ScreenPtr pScreen,
+ shadowBufPtr pBuf)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RegionPtr damage = shadowDamage(pBuf);
+ HRESULT ddrval = DD_OK;
+ RECT rcDest, rcSrc;
+ POINT ptOrigin;
+ DWORD dwBox = REGION_NUM_RECTS (damage);
+ BoxPtr pBox = REGION_RECTS (damage);
+ HRGN hrgnTemp = NULL, hrgnCombined = NULL;
+
+ /*
+ * Return immediately if the app is not active
+ * and we are fullscreen, or if we have a bad display depth
+ */
+ if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen)
+ || pScreenPriv->fBadDepth) return;
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+
+ /* Unlock the shadow surface, so we can blit */
+ ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winShadowUpdateDD - Unlock failed\n");
+ return;
+ }
+
+ /*
+ * Handle small regions with multiple blits,
+ * handle large regions by creating a clipping region and
+ * doing a single blit constrained to that clipping region.
+ */
+ if (pScreenInfo->dwClipUpdatesNBoxes == 0
+ || dwBox < pScreenInfo->dwClipUpdatesNBoxes)
+ {
+ /* Loop through all boxes in the damaged region */
+ while (dwBox--)
+ {
+ /* Assign damage box to source rectangle */
+ rcSrc.left = pBox->x1;
+ rcSrc.top = pBox->y1;
+ rcSrc.right = pBox->x2;
+ rcSrc.bottom = pBox->y2;
+
+ /* Calculate destination rectange */
+ rcDest.left = ptOrigin.x + rcSrc.left;
+ rcDest.top = ptOrigin.y + rcSrc.top;
+ rcDest.right = ptOrigin.x + rcSrc.right;
+ rcDest.bottom = ptOrigin.y + rcSrc.bottom;
+
+ /* Blit the damaged areas */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
+ &rcDest,
+ pScreenPriv->pddsShadow,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+
+ /* Get a pointer to the next box */
+ ++pBox;
+ }
+ }
+ else
+ {
+ BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage);
+
+ /* Compute a GDI region from the damaged region */
+ hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
+ dwBox--;
+ pBox++;
+ while (dwBox--)
+ {
+ hrgnTemp = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
+ CombineRgn (hrgnCombined, hrgnCombined, hrgnTemp, RGN_OR);
+ DeleteObject (hrgnTemp);
+ pBox++;
+ }
+
+ /* Install the GDI region as a clipping region */
+ SelectClipRgn (pScreenPriv->hdcScreen, hrgnCombined);
+ DeleteObject (hrgnCombined);
+ hrgnCombined = NULL;
+
+ /* Calculating a bounding box for the source is easy */
+ rcSrc.left = pBoxExtents->x1;
+ rcSrc.top = pBoxExtents->y1;
+ rcSrc.right = pBoxExtents->x2;
+ rcSrc.bottom = pBoxExtents->y2;
+
+ /* Calculating a bounding box for the destination is trickier */
+ rcDest.left = ptOrigin.x + rcSrc.left;
+ rcDest.top = ptOrigin.y + rcSrc.top;
+ rcDest.right = ptOrigin.x + rcSrc.right;
+ rcDest.bottom = ptOrigin.y + rcSrc.bottom;
+
+ /* Our Blt should be clipped to the invalidated region */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
+ &rcDest,
+ pScreenPriv->pddsShadow,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+
+ /* Reset the clip region */
+ SelectClipRgn (pScreenPriv->hdcScreen, NULL);
+ }
+
+ /* Relock the shadow surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
+ NULL,
+ pScreenPriv->pddsdShadow,
+ DDLOCK_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winShadowUpdateDD - Lock failed\n");
+ return;
+ }
+
+ /* Has our memory pointer changed? */
+ if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
+ {
+ extern const char *g_pszLogFile;
+ ErrorF ("winShadowUpdateDD - Memory location of the shadow "
+ "surface has changed, trying to update the root window "
+ "pixmap header to point to the new address. If you get "
+ "this message and "PROJECT_NAME" freezes or crashes "
+ "after this message then send a problem report and your "
+ "%s file to " BUILDERADDR "\n", g_pszLogFile);
+
+ /* Location of shadow framebuffer has changed */
+ pScreenInfo->pfb = pScreenPriv->pddsdShadow->lpSurface;
+
+ /* Update the screen pixmap */
+ if (!(*pScreen->ModifyPixmapHeader)(pScreen->devPrivate,
+ pScreen->width,
+ pScreen->height,
+ pScreen->rootDepth,
+ BitsPerPixel (pScreen->rootDepth),
+ PixmapBytePad (pScreenInfo->dwStride,
+ pScreenInfo->dwBPP),
+ pScreenInfo->pfb))
+ {
+ ErrorF ("winShadowUpdateDD - Bits changed, could not "
+ "notify fb.\n");
+ return;
+ }
+ }
+}
+
+
+/*
+ * Call the wrapped CloseScreen function.
+ *
+ * Free our resources and private structures.
+ */
+
+static Bool
+winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ Bool fReturn;
+
+ winDebug ("winCloseScreenShadowDD - Freeing screen resources\n");
+
+ /* Flag that the screen is closed */
+ pScreenPriv->fClosed = TRUE;
+ pScreenPriv->fActive = FALSE;
+
+ /* Call the wrapped CloseScreen procedure */
+ WIN_UNWRAP(CloseScreen);
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ /* Free the screen DC */
+ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ /* Free the shadow surface, if there is one */
+ if (pScreenPriv->pddsShadow)
+ {
+ IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
+ IDirectDrawSurface2_Release (pScreenPriv->pddsShadow);
+ pScreenPriv->pddsShadow = NULL;
+ }
+
+ /* Detach the clipper from the primary surface and release the clipper. */
+ if (pScreenPriv->pddcPrimary)
+ {
+ /* Detach the clipper */
+ IDirectDrawSurface2_SetClipper (pScreenPriv->pddsPrimary,
+ NULL);
+
+ /* Release the clipper object */
+ IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
+ pScreenPriv->pddcPrimary = NULL;
+ }
+
+ /* Release the primary surface, if there is one */
+ if (pScreenPriv->pddsPrimary)
+ {
+ IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
+ pScreenPriv->pddsPrimary = NULL;
+ }
+
+ /* Free the DirectDraw2 object, if there is one */
+ if (pScreenPriv->pdd2)
+ {
+ IDirectDraw2_RestoreDisplayMode (pScreenPriv->pdd2);
+ IDirectDraw2_Release (pScreenPriv->pdd2);
+ pScreenPriv->pdd2 = NULL;
+ }
+
+ /* Free the DirectDraw object, if there is one */
+ if (pScreenPriv->pdd)
+ {
+ IDirectDraw_Release (pScreenPriv->pdd);
+ pScreenPriv->pdd = NULL;
+ }
+
+ /* Delete tray icon, if we have one */
+ if (!pScreenInfo->fNoTrayIcon)
+ winDeleteNotifyIcon (pScreenPriv);
+
+ /* Free the exit confirmation dialog box, if it exists */
+ if (g_hDlgExit != NULL)
+ {
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+ }
+
+ /* Kill our window */
+ if (pScreenPriv->hwndScreen)
+ {
+ DestroyWindow (pScreenPriv->hwndScreen);
+ pScreenPriv->hwndScreen = NULL;
+ }
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ /* Destroy the thread startup mutex */
+ pthread_mutex_destroy (&pScreenPriv->pmServerStarted);
+#endif
+
+ /* Kill our screeninfo's pointer to the screen */
+ pScreenInfo->pScreen = NULL;
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+
+ /* Free the screen privates for this screen */
+ free ((pointer) pScreenPriv);
+
+ return fReturn;
+}
+
+
+/*
+ * Tell mi what sort of visuals we need.
+ *
+ * Generally we only need one visual, as our screen can only
+ * handle one format at a time, I believe. You may want
+ * to verify that last sentence.
+ */
+
+static Bool
+winInitVisualsShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ DWORD dwRedBits, dwGreenBits, dwBlueBits;
+
+ /* Count the number of ones in each color mask */
+ dwRedBits = winCountBits (pScreenPriv->dwRedMask);
+ dwGreenBits = winCountBits (pScreenPriv->dwGreenMask);
+ dwBlueBits = winCountBits (pScreenPriv->dwBlueMask);
+
+ /* Store the maximum number of ones in a color mask as the bitsPerRGB */
+ if (dwRedBits == 0 || dwGreenBits == 0 || dwBlueBits == 0)
+ pScreenPriv->dwBitsPerRGB = 8;
+ else if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwRedBits;
+ else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwGreenBits;
+ else
+ pScreenPriv->dwBitsPerRGB = dwBlueBits;
+
+ winDebug ("winInitVisualsShadowDD - Masks %08x %08x %08x BPRGB %d d %d "
+ "bpp %d\n",
+ (unsigned int) pScreenPriv->dwRedMask,
+ (unsigned int) pScreenPriv->dwGreenMask,
+ (unsigned int) pScreenPriv->dwBlueMask,
+ (int) pScreenPriv->dwBitsPerRGB,
+ (int) pScreenInfo->dwDepth,
+ (int) pScreenInfo->dwBPP);
+
+ /* Create a single visual according to the Windows screen depth */
+ switch (pScreenInfo->dwDepth)
+ {
+ case 24:
+ case 16:
+ case 15:
+#if defined(XFree86Server)
+ /* Create the real visual */
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ TrueColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
+ "failed for TrueColor\n");
+ return FALSE;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ if (!pScreenInfo->fEmulatePseudo)
+ break;
+
+ /* Setup a pseudocolor visual */
+ if (!miSetVisualTypesAndMasks (8,
+ PseudoColorMask,
+ 8,
+ -1,
+ 0,
+ 0,
+ 0))
+ {
+ ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
+ "failed for PseudoColor\n");
+ return FALSE;
+ }
+#endif
+#else /* XFree86Server */
+ /* Create the real visual */
+ if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
+ "failed for TrueColor\n");
+ return FALSE;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ if (!pScreenInfo->fEmulatePseudo)
+ break;
+
+ /* Setup a pseudocolor visual */
+ if (!fbSetVisualTypesAndMasks (8,
+ PseudoColorMask,
+ 8,
+ 0,
+ 0,
+ 0))
+ {
+ ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
+ "failed for PseudoColor\n");
+ return FALSE;
+ }
+#endif
+#endif /* XFree86Server */
+ break;
+
+ case 8:
+#if defined(XFree86Server)
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ pScreenInfo->fFullScreen
+ ? PseudoColorMask : StaticColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenInfo->fFullScreen
+ ? PseudoColor : StaticColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDD - miSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+#else /* XFree86Server */
+ if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ pScreenInfo->fFullScreen
+ ? PseudoColorMask : StaticColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDD - fbSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+#endif /* XFree86Server */
+ break;
+
+ default:
+ ErrorF ("winInitVisualsShadowDD - Unknown screen depth\n");
+ return FALSE;
+ }
+
+ winDebug ("winInitVisualsShadowDD - Returning\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Adjust the user proposed video mode
+ */
+
+static Bool
+winAdjustVideoModeShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HDC hdc = NULL;
+ DWORD dwBPP;
+
+ /* We're in serious trouble if we can't get a DC */
+ hdc = GetDC (NULL);
+ if (hdc == NULL)
+ {
+ ErrorF ("winAdjustVideoModeShadowDD - GetDC () failed\n");
+ return FALSE;
+ }
+
+ /* Query GDI for current display depth */
+ dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
+
+ /* DirectDraw can only change the depth in fullscreen mode */
+ if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
+ {
+ /* No -depth parameter passed, let the user know the depth being used */
+ winDebug ("winAdjustVideoModeShadowDD - Using Windows display "
+ "depth of %d bits per pixel\n", (int) dwBPP);
+
+ /* Use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+ else if (pScreenInfo->fFullScreen
+ && pScreenInfo->dwBPP != dwBPP)
+ {
+ /* FullScreen, and GDI depth differs from -depth parameter */
+ winDebug ("winAdjustVideoModeShadowDD - FullScreen, using command line "
+ "bpp: %d\n", (int) pScreenInfo->dwBPP);
+ }
+ else if (dwBPP != pScreenInfo->dwBPP)
+ {
+ /* Windowed, and GDI depth differs from -depth parameter */
+ winDebug ("winAdjustVideoModeShadowDD - Windowed, command line bpp: "
+ "%d, using bpp: %d\n", (int) pScreenInfo->dwBPP, (int) dwBPP);
+
+ /* We'll use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+
+ /* See if the shadow bitmap will be larger than the DIB size limit */
+ if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP
+ >= WIN_DIB_MAXIMUM_SIZE)
+ {
+ ErrorF ("winAdjustVideoModeShadowDD - Requested DirectDraw surface "
+ "will be larger than %d MB. The surface may fail to be "
+ "allocated on Windows 95, 98, or Me, due to a %d MB limit in "
+ "DIB size. This limit does not apply to Windows NT/2000, and "
+ "this message may be ignored on those platforms.\n",
+ WIN_DIB_MAXIMUM_SIZE_MB, WIN_DIB_MAXIMUM_SIZE_MB);
+ }
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+ return TRUE;
+}
+
+
+/*
+ * Blt exposed regions to the screen
+ */
+
+static Bool
+winBltExposedRegionsShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RECT rcSrc, rcDest;
+ POINT ptOrigin;
+ HDC hdcUpdate = NULL;
+ PAINTSTRUCT ps;
+ HRESULT ddrval = DD_OK;
+ Bool fReturn = TRUE;
+ Bool fLocked = TRUE;
+ int i;
+
+ /* BeginPaint gives us an hdc that clips to the invalidated region */
+ hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
+ if (hdcUpdate == NULL)
+ {
+ ErrorF ("winBltExposedRegionsShadowDD - BeginPaint () returned "
+ "a NULL device context handle. Aborting blit attempt.\n");
+ return FALSE;
+ }
+
+ /* Unlock the shadow surface, so we can blit */
+ ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsShadow, NULL);
+ if (FAILED (ddrval))
+ {
+ fReturn = FALSE;
+ goto winBltExposedRegionsShadowDD_Exit;
+ }
+ else
+ {
+ /* Flag that we have unlocked the shadow surface */
+ fLocked = FALSE;
+ }
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+ rcDest.left = ptOrigin.x;
+ rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
+ rcDest.top = ptOrigin.y;
+ rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
+
+ /* Source can be enter shadow surface, as Blt should clip */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ /* Try to regain the primary surface and blit again if we've lost it */
+ for (i = 0; i <= WIN_REGAIN_SURFACE_RETRIES; ++i)
+ {
+ /* Our Blt should be clipped to the invalidated region */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
+ &rcDest,
+ pScreenPriv->pddsShadow,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (ddrval == DDERR_SURFACELOST)
+ {
+ /* Surface was lost */
+ ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Blt "
+ "reported that the primary surface was lost, "
+ "trying to restore, retry: %d\n", i + 1);
+
+ /* Try to restore the surface, once */
+ ddrval = IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
+ ErrorF ("winBltExposedRegionsShadowDD - "
+ "IDirectDrawSurface2_Restore returned: ");
+ if (ddrval == DD_OK)
+ ErrorF ("DD_OK\n");
+ else if (ddrval == DDERR_WRONGMODE)
+ ErrorF ("DDERR_WRONGMODE\n");
+ else if (ddrval == DDERR_INCOMPATIBLEPRIMARY)
+ ErrorF ("DDERR_INCOMPATIBLEPRIMARY\n");
+ else if (ddrval == DDERR_UNSUPPORTED)
+ ErrorF ("DDERR_UNSUPPORTED\n");
+ else if (ddrval == DDERR_INVALIDPARAMS)
+ ErrorF ("DDERR_INVALIDPARAMS\n");
+ else if (ddrval == DDERR_INVALIDOBJECT)
+ ErrorF ("DDERR_INVALIDOBJECT\n");
+ else
+ ErrorF ("unknown error: %08x\n", (unsigned int) ddrval);
+
+ /* Loop around to try the blit one more time */
+ continue;
+ }
+ else if (FAILED (ddrval))
+ {
+ fReturn = FALSE;
+ ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Blt "
+ "failed, but surface not lost: %08x %d\n",
+ (unsigned int) ddrval, (int) ddrval);
+ goto winBltExposedRegionsShadowDD_Exit;
+ }
+ else
+ {
+ /* Success, stop looping */
+ break;
+ }
+ }
+
+ /* Relock the shadow surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
+ NULL,
+ pScreenPriv->pddsdShadow,
+ DDLOCK_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ fReturn = FALSE;
+ ErrorF ("winBltExposedRegionsShadowDD - IDirectDrawSurface2_Lock "
+ "failed\n");
+ goto winBltExposedRegionsShadowDD_Exit;
+ }
+ else
+ {
+ /* Indicate that we have relocked the shadow surface */
+ fLocked = TRUE;
+ }
+
+ /* Has our memory pointer changed? */
+ if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
+ winUpdateFBPointer (pScreen,
+ pScreenPriv->pddsdShadow->lpSurface);
+
+ winBltExposedRegionsShadowDD_Exit:
+ /* EndPaint frees the DC */
+ if (hdcUpdate != NULL)
+ EndPaint (pScreenPriv->hwndScreen, &ps);
+
+ /*
+ * Relock the surface if it is not locked. We don't care if locking fails,
+ * as it will cause the server to shutdown within a few more operations.
+ */
+ if (!fLocked)
+ {
+ IDirectDrawSurface2_Lock (pScreenPriv->pddsShadow,
+ NULL,
+ pScreenPriv->pddsdShadow,
+ DDLOCK_WAIT,
+ NULL);
+
+ /* Has our memory pointer changed? */
+ if (pScreenInfo->pfb != pScreenPriv->pddsdShadow->lpSurface)
+ winUpdateFBPointer (pScreen,
+ pScreenPriv->pddsdShadow->lpSurface);
+
+ fLocked = TRUE;
+ }
+ return fReturn;
+}
+
+
+/*
+ * Do any engine-specific appliation-activation processing
+ */
+
+static Bool
+winActivateAppShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ /*
+ * Do we have a surface?
+ * Are we active?
+ * Are we fullscreen?
+ */
+ if (pScreenPriv != NULL
+ && pScreenPriv->pddsPrimary != NULL
+ && pScreenPriv->fActive)
+ {
+ /* Primary surface was lost, restore it */
+ IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Reblit the shadow framebuffer to the screen.
+ */
+
+static Bool
+winRedrawScreenShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HRESULT ddrval = DD_OK;
+ RECT rcSrc, rcDest;
+ POINT ptOrigin;
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+ rcDest.left = ptOrigin.x;
+ rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
+ rcDest.top = ptOrigin.y;
+ rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
+
+ /* Source can be entire shadow surface, as Blt should clip for us */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ /* Redraw the whole window, to take account for the new colors */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
+ &rcDest,
+ pScreenPriv->pddsShadow,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winRedrawScreenShadowDD - IDirectDrawSurface_Blt () "
+ "failed: %08x\n",
+ (unsigned int) ddrval);
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Realize the currently installed colormap
+ */
+
+static Bool
+winRealizeInstalledPaletteShadowDD (ScreenPtr pScreen)
+{
+ return TRUE;
+}
+
+
+/*
+ * Install the specified colormap
+ */
+
+static Bool
+winInstallColormapShadowDD (ColormapPtr pColormap)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+ HRESULT ddrval = DD_OK;
+
+ /* Install the DirectDraw palette on the primary surface */
+ ddrval = IDirectDrawSurface2_SetPalette (pScreenPriv->pddsPrimary,
+ pCmapPriv->lpDDPalette);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winInstallColormapShadowDD - Failed installing the "
+ "DirectDraw palette.\n");
+ return FALSE;
+ }
+
+ /* Save a pointer to the newly installed colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+
+ return TRUE;
+}
+
+
+/*
+ * Store the specified colors in the specified colormap
+ */
+
+static Bool
+winStoreColorsShadowDD (ColormapPtr pColormap,
+ int ndef,
+ xColorItem *pdefs)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+ ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
+ HRESULT ddrval = DD_OK;
+
+ /* Put the X colormap entries into the Windows logical palette */
+ ddrval = IDirectDrawPalette_SetEntries (pCmapPriv->lpDDPalette,
+ 0,
+ pdefs[0].pixel,
+ ndef,
+ pCmapPriv->peColors
+ + pdefs[0].pixel);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winStoreColorsShadowDD - SetEntries () failed\n");
+ return FALSE;
+ }
+
+ /* Don't install the DirectDraw palette if the colormap is not installed */
+ if (pColormap != curpmap)
+ {
+ return TRUE;
+ }
+
+ if (!winInstallColormapShadowDD (pColormap))
+ {
+ ErrorF ("winStoreColorsShadowDD - Failed installing colormap\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap initialization procedure
+ */
+
+static Bool
+winCreateColormapShadowDD (ColormapPtr pColormap)
+{
+ HRESULT ddrval = DD_OK;
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+
+ /* Create a DirectDraw palette */
+ ddrval = IDirectDraw2_CreatePalette (pScreenPriv->pdd,
+ DDPCAPS_8BIT | DDPCAPS_ALLOW256,
+ pCmapPriv->peColors,
+ &pCmapPriv->lpDDPalette,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winCreateColormapShadowDD - CreatePalette failed\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap destruction procedure
+ */
+
+static Bool
+winDestroyColormapShadowDD (ColormapPtr pColormap)
+{
+ winScreenPriv(pColormap->pScreen);
+ winCmapPriv(pColormap);
+ HRESULT ddrval = DD_OK;
+
+ /*
+ * Is colormap to be destroyed the default?
+ *
+ * Non-default colormaps should have had winUninstallColormap
+ * called on them before we get here. The default colormap
+ * will not have had winUninstallColormap called on it. Thus,
+ * we need to handle the default colormap in a special way.
+ */
+ if (pColormap->flags & IsDefault)
+ {
+ winDebug ("winDestroyColormapShadowDD - Destroying default "
+ "colormap\n");
+
+ /*
+ * FIXME: Walk the list of all screens, popping the default
+ * palette out of each screen device context.
+ */
+
+ /* Pop the palette out of the primary surface */
+ ddrval = IDirectDrawSurface2_SetPalette (pScreenPriv->pddsPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winDestroyColormapShadowDD - Failed freeing the "
+ "default colormap DirectDraw palette.\n");
+ return FALSE;
+ }
+
+ /* Clear our private installed colormap pointer */
+ pScreenPriv->pcmapInstalled = NULL;
+ }
+
+ /* Release the palette */
+ IDirectDrawPalette_Release (pCmapPriv->lpDDPalette);
+
+ /* Invalidate the colormap privates */
+ pCmapPriv->lpDDPalette = NULL;
+
+ return TRUE;
+}
+
+
+/*
+ * Set engine specific functions
+ */
+
+Bool
+winSetEngineFunctionsShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Set our pointers */
+ pScreenPriv->pwinAllocateFB = winAllocateFBShadowDD;
+ pScreenPriv->pwinShadowUpdate = winShadowUpdateDD;
+ pScreenPriv->pwinCloseScreen = winCloseScreenShadowDD;
+ pScreenPriv->pwinInitVisuals = winInitVisualsShadowDD;
+ pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowDD;
+ if (pScreenInfo->fFullScreen)
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
+ else
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
+ pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
+ pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowDD;
+ pScreenPriv->pwinActivateApp = winActivateAppShadowDD;
+ pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowDD;
+ pScreenPriv->pwinRealizeInstalledPalette
+ = winRealizeInstalledPaletteShadowDD;
+ pScreenPriv->pwinInstallColormap = winInstallColormapShadowDD;
+ pScreenPriv->pwinStoreColors = winStoreColorsShadowDD;
+ pScreenPriv->pwinCreateColormap = winCreateColormapShadowDD;
+ pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDD;
+ pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDD;
+ pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDD;
+#ifdef XWIN_MULTIWINDOW
+ pScreenPriv->pwinFinishCreateWindowsWindow =
+ (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA;
+#endif
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winshadddnl.c b/xorg-server/hw/xwin/winshadddnl.c
index b8d6222ac..af7b989df 100644
--- a/xorg-server/hw/xwin/winshadddnl.c
+++ b/xorg-server/hw/xwin/winshadddnl.c
@@ -1,1441 +1,1441 @@
-/*
- *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the name of the XFree86 Project
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from the XFree86 Project.
- *
- * Authors: Dakshinamurthy Karra
- * Suhaib M Siddiqi
- * Peter Busch
- * Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-
-/*
- * External symbols
- */
-
-extern HWND g_hDlgExit;
-
-
-/*
- * FIXME: Headers are broken, DEFINE_GUID doesn't work correctly,
- * so we have to redefine it here.
- */
-#ifndef _MSC_VER
-#ifdef DEFINE_GUID
-#undef DEFINE_GUID
-#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
-#endif /* DEFINE_GUID */
-#endif
-
-/*
- * FIXME: Headers are broken, IID_IDirectDraw4 has to be defined
- * here manually. Should be handled by ddraw.h
- */
-#ifndef IID_IDirectDraw4
-DEFINE_GUID( IID_IDirectDraw4, 0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f,0xd9,0x30,0xc5 );
-#endif /* IID_IDirectDraw4 */
-
-#define FAIL_MSG_MAX_BLT 10
-
-
-/*
- * Local prototypes
- */
-
-static Bool
-winAllocateFBShadowDDNL (ScreenPtr pScreen);
-
-static void
-winShadowUpdateDDNL (ScreenPtr pScreen,
- shadowBufPtr pBuf);
-
-static Bool
-winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen);
-
-static Bool
-winInitVisualsShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winAdjustVideoModeShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winBltExposedRegionsShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winActivateAppShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winRedrawScreenShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winInstallColormapShadowDDNL (ColormapPtr pColormap);
-
-static Bool
-winStoreColorsShadowDDNL (ColormapPtr pmap,
- int ndef,
- xColorItem *pdefs);
-
-static Bool
-winCreateColormapShadowDDNL (ColormapPtr pColormap);
-
-static Bool
-winDestroyColormapShadowDDNL (ColormapPtr pColormap);
-
-static Bool
-winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen);
-
-static Bool
-winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen);
-
-
-/*
- * Create the primary surface and attach the clipper.
- * Used for both the initial surface creation and during
- * WM_DISPLAYCHANGE messages.
- */
-
-static Bool
-winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- HRESULT ddrval = DD_OK;
- DDSURFACEDESC2 ddsd;
-
- winDebug ("winCreatePrimarySurfaceShadowDDNL - Creating primary surface\n");
-
- /* Describe the primary surface */
- ZeroMemory (&ddsd, sizeof (ddsd));
- ddsd.dwSize = sizeof (ddsd);
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
-
- /* Create the primary surface */
- ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
- &ddsd,
- &pScreenPriv->pddsPrimary4,
- NULL);
- pScreenPriv->fRetryCreateSurface = FALSE;
- if (FAILED (ddrval))
- {
- if (ddrval == DDERR_NOEXCLUSIVEMODE)
- {
- /* Recreating the surface failed. Mark screen to retry later */
- pScreenPriv->fRetryCreateSurface = TRUE;
- winDebug ("winCreatePrimarySurfaceShadowDDNL - Could not create "
- "primary surface: DDERR_NOEXCLUSIVEMODE\n");
- }
- else
- {
- ErrorF ("winCreatePrimarySurfaceShadowDDNL - Could not create "
- "primary surface: %08x\n", (unsigned int) ddrval);
- }
- return FALSE;
- }
-
- winDebug ("winCreatePrimarySurfaceShadowDDNL - Created primary surface\n");
-
- /* Attach our clipper to our primary surface handle */
- ddrval = IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
- pScreenPriv->pddcPrimary);
- if (FAILED (ddrval))
- {
- ErrorF ("winCreatePrimarySurfaceShadowDDNL - Primary attach clipper "
- "failed: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winCreatePrimarySurfaceShadowDDNL - Attached clipper to primary "
- "surface\n");
-
- /* Everything was correct */
- return TRUE;
-}
-
-
-/*
- * Detach the clipper and release the primary surface.
- * Called from WM_DISPLAYCHANGE.
- */
-
-static Bool
-winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
-
- winDebug ("winReleasePrimarySurfaceShadowDDNL - Hello\n");
-
- /* Release the primary surface and clipper, if they exist */
- if (pScreenPriv->pddsPrimary4)
- {
- /*
- * Detach the clipper from the primary surface.
- * NOTE: We do this explicity for clarity. The Clipper is not released.
- */
- IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
- NULL);
-
- winDebug ("winReleasePrimarySurfaceShadowDDNL - Detached clipper\n");
-
- /* Release the primary surface */
- IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4);
- pScreenPriv->pddsPrimary4 = NULL;
- }
-
- winDebug ("winReleasePrimarySurfaceShadowDDNL - Released primary surface\n");
-
- return TRUE;
-}
-
-
-/*
- * Create a DirectDraw surface for the shadow framebuffer; also create
- * a primary surface object so we can blit to the display.
- *
- * Install a DirectDraw clipper on our primary surface object
- * that clips our blits to the unobscured client area of our display window.
- */
-
-Bool
-winAllocateFBShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HRESULT ddrval = DD_OK;
- DDSURFACEDESC2 ddsdShadow;
- char *lpSurface = NULL;
- DDPIXELFORMAT ddpfPrimary;
-
- winDebug ("winAllocateFBShadowDDNL - w %d h %d d %d\n",
- pScreenInfo->dwWidth, pScreenInfo->dwHeight, pScreenInfo->dwDepth);
-
- /* Allocate memory for our shadow surface */
- lpSurface = malloc (pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
- if (lpSurface == NULL)
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not allocate bits\n");
- return FALSE;
- }
-
- /*
- * Initialize the framebuffer memory so we don't get a
- * strange display at startup
- */
- ZeroMemory (lpSurface, pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
-
- /* Create a clipper */
- ddrval = (*g_fpDirectDrawCreateClipper) (0,
- &pScreenPriv->pddcPrimary,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not attach clipper: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDDNL - Created a clipper\n");
-
- /* Get a device context for the screen */
- pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
-
- /* Attach the clipper to our display window */
- ddrval = IDirectDrawClipper_SetHWnd (pScreenPriv->pddcPrimary,
- 0,
- pScreenPriv->hwndScreen);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Clipper not attached "
- "to window: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDDNL - Attached clipper to window\n");
-
- /* Create a DirectDraw object, store the address at lpdd */
- ddrval = (*g_fpDirectDrawCreate) (NULL,
- (LPDIRECTDRAW*) &pScreenPriv->pdd,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not start "
- "DirectDraw: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDDNL - Created and initialized DD\n");
-
- /* Get a DirectDraw4 interface pointer */
- ddrval = IDirectDraw_QueryInterface (pScreenPriv->pdd,
- &IID_IDirectDraw4,
- (LPVOID*) &pScreenPriv->pdd4);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Failed DD4 query: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- /* Are we full screen? */
- if (pScreenInfo->fFullScreen)
- {
- DDSURFACEDESC2 ddsdCurrent;
- DWORD dwRefreshRateCurrent = 0;
- HDC hdc = NULL;
-
- /* Set the cooperative level to full screen */
- ddrval = IDirectDraw4_SetCooperativeLevel (pScreenPriv->pdd4,
- pScreenPriv->hwndScreen,
- DDSCL_EXCLUSIVE
- | DDSCL_FULLSCREEN);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not set "
- "cooperative level: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- /*
- * We only need to get the current refresh rate for comparison
- * if a refresh rate has been passed on the command line.
- */
- if (pScreenInfo->dwRefreshRate != 0)
- {
- ZeroMemory (&ddsdCurrent, sizeof (ddsdCurrent));
- ddsdCurrent.dwSize = sizeof (ddsdCurrent);
-
- /* Get information about current display settings */
- ddrval = IDirectDraw4_GetDisplayMode (pScreenPriv->pdd4,
- &ddsdCurrent);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not get current "
- "refresh rate: %08x. Continuing.\n",
- (unsigned int) ddrval);
- dwRefreshRateCurrent = 0;
- }
- else
- {
- /* Grab the current refresh rate */
- dwRefreshRateCurrent = ddsdCurrent.u2.dwRefreshRate;
- }
- }
-
- /* Clean up the refresh rate */
- if (dwRefreshRateCurrent == pScreenInfo->dwRefreshRate)
- {
- /*
- * Refresh rate is non-specified or equal to current.
- */
- pScreenInfo->dwRefreshRate = 0;
- }
-
- /* Grab a device context for the screen */
- hdc = GetDC (NULL);
- if (hdc == NULL)
- {
- ErrorF ("winAllocateFBShadowDDNL - GetDC () failed\n");
- return FALSE;
- }
-
- /* Only change the video mode when different than current mode */
- if (!pScreenInfo->fMultipleMonitors
- && (pScreenInfo->dwWidth != GetSystemMetrics (SM_CXSCREEN)
- || pScreenInfo->dwHeight != GetSystemMetrics (SM_CYSCREEN)
- || pScreenInfo->dwBPP != GetDeviceCaps (hdc, BITSPIXEL)
- || pScreenInfo->dwRefreshRate != 0))
- {
- winDebug ("winAllocateFBShadowDDNL - Changing video mode\n");
-
- /* Change the video mode to the mode requested, and use the driver default refresh rate on failure */
- ddrval = IDirectDraw4_SetDisplayMode (pScreenPriv->pdd4,
- pScreenInfo->dwWidth,
- pScreenInfo->dwHeight,
- pScreenInfo->dwBPP,
- pScreenInfo->dwRefreshRate,
- 0);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not set "
- "full screen display mode: %08x\n",
- (unsigned int) ddrval);
- ErrorF ("winAllocateFBShadowDDNL - Using default driver refresh rate\n");
- ddrval = IDirectDraw4_SetDisplayMode (pScreenPriv->pdd4,
- pScreenInfo->dwWidth,
- pScreenInfo->dwHeight,
- pScreenInfo->dwBPP,
- 0,
- 0);
- if (FAILED(ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not set default refresh rate "
- "full screen display mode: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
- }
- }
- else
- {
- winDebug ("winAllocateFBShadowDDNL - Not changing video mode\n");
- }
-
- /* Release our DC */
- ReleaseDC (NULL, hdc);
- hdc = NULL;
- }
- else
- {
- /* Set the cooperative level for windowed mode */
- ddrval = IDirectDraw4_SetCooperativeLevel (pScreenPriv->pdd4,
- pScreenPriv->hwndScreen,
- DDSCL_NORMAL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not set "
- "cooperative level: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
- }
-
- /* Create the primary surface */
- if (!winCreatePrimarySurfaceShadowDDNL (pScreen))
- {
- ErrorF ("winAllocateFBShadowDDNL - winCreatePrimarySurfaceShadowDDNL "
- "failed\n");
- return FALSE;
- }
-
- /* Get primary surface's pixel format */
- ZeroMemory (&ddpfPrimary, sizeof (ddpfPrimary));
- ddpfPrimary.dwSize = sizeof (ddpfPrimary);
- ddrval = IDirectDrawSurface4_GetPixelFormat (pScreenPriv->pddsPrimary4,
- &ddpfPrimary);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not get primary "
- "pixformat: %08x\n",
- (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDDNL - Primary masks: %08x %08x %08x "
- "dwRGBBitCount: %d\n",
- ddpfPrimary.u2.dwRBitMask,
- ddpfPrimary.u3.dwGBitMask,
- ddpfPrimary.u4.dwBBitMask,
- ddpfPrimary.u1.dwRGBBitCount);
-
- /* Describe the shadow surface to be created */
- /*
- * NOTE: Do not use a DDSCAPS_VIDEOMEMORY surface,
- * as drawing, locking, and unlocking take forever
- * with video memory surfaces. In addition,
- * video memory is a somewhat scarce resource,
- * so you shouldn't be allocating video memory when
- * you have the option of using system memory instead.
- */
- ZeroMemory (&ddsdShadow, sizeof (ddsdShadow));
- ddsdShadow.dwSize = sizeof (ddsdShadow);
- ddsdShadow.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH
- | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT;
- ddsdShadow.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
- ddsdShadow.dwHeight = pScreenInfo->dwHeight;
- ddsdShadow.dwWidth = pScreenInfo->dwWidth;
- ddsdShadow.u1.lPitch = pScreenInfo->dwPaddedWidth;
- ddsdShadow.lpSurface = lpSurface;
- ddsdShadow.u4.ddpfPixelFormat = ddpfPrimary;
-
- winDebug ("winAllocateFBShadowDDNL - lPitch: %d\n",
- (int) pScreenInfo->dwPaddedWidth);
-
- /* Create the shadow surface */
- ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
- &ddsdShadow,
- &pScreenPriv->pddsShadow4,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winAllocateFBShadowDDNL - Could not create shadow "
- "surface: %08x\n", (unsigned int) ddrval);
- return FALSE;
- }
-
- winDebug ("winAllocateFBShadowDDNL - Created shadow pitch: %d\n",
- (int) ddsdShadow.u1.lPitch);
-
- /* Grab the pitch from the surface desc */
- pScreenInfo->dwStride = (ddsdShadow.u1.lPitch * 8)
- / pScreenInfo->dwBPP;
-
- winDebug ("winAllocateFBShadowDDNL - Created shadow stride: %d\n",
- (int) pScreenInfo->dwStride);
-
- /* Save the pointer to our surface memory */
- pScreenInfo->pfb = lpSurface;
-
- /* Grab the masks from the surface description */
- pScreenPriv->dwRedMask = ddsdShadow.u4.ddpfPixelFormat.u2.dwRBitMask;
- pScreenPriv->dwGreenMask = ddsdShadow.u4.ddpfPixelFormat.u3.dwGBitMask;
- pScreenPriv->dwBlueMask = ddsdShadow.u4.ddpfPixelFormat.u4.dwBBitMask;
-
- winDebug ("winAllocateFBShadowDDNL - Returning\n");
-
- return TRUE;
-}
-
-
-#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
-/*
- * Create a DirectDraw surface for the new multi-window window
- */
-
-static
-Bool
-winFinishCreateWindowsWindowDDNL (WindowPtr pWin)
-{
- winWindowPriv(pWin);
- winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv;
- HRESULT ddrval = DD_OK;
- DDSURFACEDESC2 ddsd;
- int iWidth, iHeight;
- int iX, iY;
-
- winDebug ("\nwinFinishCreateWindowsWindowDDNL!\n\n");
-
- iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN);
- iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN);
-
- iWidth = pWin->drawable.width;
- iHeight = pWin->drawable.height;
-
- /* Describe the primary surface */
- ZeroMemory (&ddsd, sizeof (ddsd));
- ddsd.dwSize = sizeof (ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- ddsd.dwHeight = iHeight;
- ddsd.dwWidth = iWidth;
-
- /* Create the primary surface */
- ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
- &ddsd,
- &pWinPriv->pddsPrimary4,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winFinishCreateWindowsWindowDDNL - Could not create primary "
- "surface: %08x\n",
- (unsigned int)ddrval);
- return FALSE;
- }
- return TRUE;
-}
-#endif
-
-
-/*
- * Transfer the damaged regions of the shadow framebuffer to the display.
- */
-
-static void
-winShadowUpdateDDNL (ScreenPtr pScreen,
- shadowBufPtr pBuf)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- RegionPtr damage = shadowDamage(pBuf);
- HRESULT ddrval = DD_OK;
- RECT rcDest, rcSrc;
- POINT ptOrigin;
- DWORD dwBox = REGION_NUM_RECTS (damage);
- BoxPtr pBox = REGION_RECTS (damage);
- HRGN hrgnTemp = NULL, hrgnCombined = NULL;
-
- /*
- * Return immediately if the app is not active
- * and we are fullscreen, or if we have a bad display depth
- */
- if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen)
- || pScreenPriv->fBadDepth) return;
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
-
- /*
- * Handle small regions with multiple blits,
- * handle large regions by creating a clipping region and
- * doing a single blit constrained to that clipping region.
- */
- if (pScreenInfo->dwClipUpdatesNBoxes == 0
- || dwBox < pScreenInfo->dwClipUpdatesNBoxes)
- {
- /* Loop through all boxes in the damaged region */
- while (dwBox--)
- {
- /* Assign damage box to source rectangle */
- rcSrc.left = pBox->x1;
- rcSrc.top = pBox->y1;
- rcSrc.right = pBox->x2;
- rcSrc.bottom = pBox->y2;
-
- /* Calculate destination rectangle */
- rcDest.left = ptOrigin.x + rcSrc.left;
- rcDest.top = ptOrigin.y + rcSrc.top;
- rcDest.right = ptOrigin.x + rcSrc.right;
- rcDest.bottom = ptOrigin.y + rcSrc.bottom;
-
- /* Blit the damaged areas */
- ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
- &rcDest,
- pScreenPriv->pddsShadow4,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
- if (FAILED (ddrval))
- {
- static int s_iFailCount = 0;
-
- if (s_iFailCount < FAIL_MSG_MAX_BLT)
- {
- ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt () "
- "failed: %08x\n",
- (unsigned int) ddrval);
-
- ++s_iFailCount;
-
- if (s_iFailCount == FAIL_MSG_MAX_BLT)
- {
- ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt "
- "failure message maximum (%d) reached. No "
- "more failure messages will be printed.\n",
- FAIL_MSG_MAX_BLT);
- }
- }
- }
-
- /* Get a pointer to the next box */
- ++pBox;
- }
- }
- else
- {
- BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage);
-
- /* Compute a GDI region from the damaged region */
- hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
- dwBox--;
- pBox++;
- while (dwBox--)
- {
- hrgnTemp = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
- CombineRgn (hrgnCombined, hrgnCombined, hrgnTemp, RGN_OR);
- DeleteObject (hrgnTemp);
- pBox++;
- }
-
- /* Install the GDI region as a clipping region */
- SelectClipRgn (pScreenPriv->hdcScreen, hrgnCombined);
- DeleteObject (hrgnCombined);
- hrgnCombined = NULL;
-
- winDebug ("winShadowUpdateDDNL - be x1 %d y1 %d x2 %d y2 %d\n",
- pBoxExtents->x1, pBoxExtents->y1,
- pBoxExtents->x2, pBoxExtents->y2);
-
- /* Calculating a bounding box for the source is easy */
- rcSrc.left = pBoxExtents->x1;
- rcSrc.top = pBoxExtents->y1;
- rcSrc.right = pBoxExtents->x2;
- rcSrc.bottom = pBoxExtents->y2;
-
- /* Calculating a bounding box for the destination is trickier */
- rcDest.left = ptOrigin.x + rcSrc.left;
- rcDest.top = ptOrigin.y + rcSrc.top;
- rcDest.right = ptOrigin.x + rcSrc.right;
- rcDest.bottom = ptOrigin.y + rcSrc.bottom;
-
- /* Our Blt should be clipped to the invalidated region */
- ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
- &rcDest,
- pScreenPriv->pddsShadow4,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
-
- /* Reset the clip region */
- SelectClipRgn (pScreenPriv->hdcScreen, NULL);
- }
-}
-
-
-/*
- * Call the wrapped CloseScreen function.
- *
- * Free our resources and private structures.
- */
-
-static Bool
-winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- Bool fReturn;
-
- winDebug ("winCloseScreenShadowDDNL - Freeing screen resources\n");
-
- /* Flag that the screen is closed */
- pScreenPriv->fClosed = TRUE;
- pScreenPriv->fActive = FALSE;
-
- /* Call the wrapped CloseScreen procedure */
- WIN_UNWRAP(CloseScreen);
- fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
-
- /* Free the screen DC */
- ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
-
- /* Delete the window property */
- RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
-
- /* Free the shadow surface, if there is one */
- if (pScreenPriv->pddsShadow4)
- {
- IDirectDrawSurface4_Release (pScreenPriv->pddsShadow4);
- free (pScreenInfo->pfb);
- pScreenInfo->pfb = NULL;
- pScreenPriv->pddsShadow4 = NULL;
- }
-
- /* Detach the clipper from the primary surface and release the clipper. */
- if (pScreenPriv->pddcPrimary)
- {
- /* Detach the clipper */
- IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
- NULL);
-
- /* Release the clipper object */
- IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
- pScreenPriv->pddcPrimary = NULL;
- }
-
- /* Release the primary surface, if there is one */
- if (pScreenPriv->pddsPrimary4)
- {
- IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4);
- pScreenPriv->pddsPrimary4 = NULL;
- }
-
- /* Free the DirectDraw4 object, if there is one */
- if (pScreenPriv->pdd4)
- {
- IDirectDraw4_RestoreDisplayMode (pScreenPriv->pdd4);
- IDirectDraw4_Release (pScreenPriv->pdd4);
- pScreenPriv->pdd4 = NULL;
- }
-
- /* Free the DirectDraw object, if there is one */
- if (pScreenPriv->pdd)
- {
- IDirectDraw_Release (pScreenPriv->pdd);
- pScreenPriv->pdd = NULL;
- }
-
- /* Delete tray icon, if we have one */
- if (!pScreenInfo->fNoTrayIcon)
- winDeleteNotifyIcon (pScreenPriv);
-
- /* Free the exit confirmation dialog box, if it exists */
- if (g_hDlgExit != NULL)
- {
- DestroyWindow (g_hDlgExit);
- g_hDlgExit = NULL;
- }
-
- /* Kill our window */
- if (pScreenPriv->hwndScreen)
- {
- DestroyWindow (pScreenPriv->hwndScreen);
- pScreenPriv->hwndScreen = NULL;
- }
-
-#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
- /* Destroy the thread startup mutex */
- pthread_mutex_destroy (&pScreenPriv->pmServerStarted);
-#endif
-
- /* Kill our screeninfo's pointer to the screen */
- pScreenInfo->pScreen = NULL;
-
- /* Invalidate the ScreenInfo's fb pointer */
- pScreenInfo->pfb = NULL;
-
- /* Free the screen privates for this screen */
- free ((pointer) pScreenPriv);
-
- return fReturn;
-}
-
-
-/*
- * Tell mi what sort of visuals we need.
- *
- * Generally we only need one visual, as our screen can only
- * handle one format at a time, I believe. You may want
- * to verify that last sentence.
- */
-
-static Bool
-winInitVisualsShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- DWORD dwRedBits, dwGreenBits, dwBlueBits;
-
- /* Count the number of ones in each color mask */
- dwRedBits = winCountBits (pScreenPriv->dwRedMask);
- dwGreenBits = winCountBits (pScreenPriv->dwGreenMask);
- dwBlueBits = winCountBits (pScreenPriv->dwBlueMask);
-
- /* Store the maximum number of ones in a color mask as the bitsPerRGB */
- if (dwRedBits == 0 || dwGreenBits == 0 || dwBlueBits == 0)
- pScreenPriv->dwBitsPerRGB = 8;
- else if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
- pScreenPriv->dwBitsPerRGB = dwRedBits;
- else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
- pScreenPriv->dwBitsPerRGB = dwGreenBits;
- else
- pScreenPriv->dwBitsPerRGB = dwBlueBits;
-
- winDebug ("winInitVisualsShadowDDNL - Masks %08x %08x %08x BPRGB %d d %d "
- "bpp %d\n",
- (unsigned int) pScreenPriv->dwRedMask,
- (unsigned int) pScreenPriv->dwGreenMask,
- (unsigned int) pScreenPriv->dwBlueMask,
- (int) pScreenPriv->dwBitsPerRGB,
- (int) pScreenInfo->dwDepth,
- (int) pScreenInfo->dwBPP);
-
- /* Create a single visual according to the Windows screen depth */
- switch (pScreenInfo->dwDepth)
- {
- case 24:
- case 16:
- case 15:
-#if defined(XFree86Server)
- /* Setup the real visual */
- if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- TrueColorMask,
- pScreenPriv->dwBitsPerRGB,
- -1,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
- "failed for TrueColor\n");
- return FALSE;
- }
-
-#ifdef XWIN_EMULATEPSEUDO
- if (!pScreenInfo->fEmulatePseudo)
- break;
-
- /* Setup a pseudocolor visual */
- if (!miSetVisualTypesAndMasks (8,
- PseudoColorMask,
- 8,
- -1,
- 0,
- 0,
- 0))
- {
- ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
- "failed for PseudoColor\n");
- return FALSE;
- }
-#endif
-#else /* XFree86Server */
- /* Setup the real visual */
- if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- TrueColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
- "failed for TrueColor\n");
- return FALSE;
- }
-
-#ifdef XWIN_EMULATEPSEUDO
- if (!pScreenInfo->fEmulatePseudo)
- break;
-
- /* Setup a pseudocolor visual */
- if (!fbSetVisualTypesAndMasks (8,
- PseudoColorMask,
- 8,
- 0,
- 0,
- 0))
- {
- ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
- "failed for PseudoColor\n");
- return FALSE;
- }
-#endif
-#endif /* XFree86Server */
- break;
-
- case 8:
-#if defined(XFree86Server)
- if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- pScreenInfo->fFullScreen
- ? PseudoColorMask : StaticColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenInfo->fFullScreen
- ? PseudoColor : StaticColor,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
- "failed\n");
- return FALSE;
- }
-#else /* XFree86Server */
- if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
- pScreenInfo->fFullScreen
- ? PseudoColorMask : StaticColorMask,
- pScreenPriv->dwBitsPerRGB,
- pScreenPriv->dwRedMask,
- pScreenPriv->dwGreenMask,
- pScreenPriv->dwBlueMask))
- {
- ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
- "failed\n");
- return FALSE;
- }
-#endif /* XFree86Server */
- break;
-
- default:
- ErrorF ("winInitVisualsShadowDDNL - Unknown screen depth\n");
- return FALSE;
- }
-
- winDebug ("winInitVisualsShadowDDNL - Returning\n");
-
- return TRUE;
-}
-
-
-/*
- * Adjust the user proposed video mode
- */
-
-static Bool
-winAdjustVideoModeShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HDC hdc = NULL;
- DWORD dwBPP;
-
- /* We're in serious trouble if we can't get a DC */
- hdc = GetDC (NULL);
- if (hdc == NULL)
- {
- ErrorF ("winAdjustVideoModeShadowDDNL - GetDC () failed\n");
- return FALSE;
- }
-
- /* Query GDI for current display depth */
- dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
-
- /* DirectDraw can only change the depth in fullscreen mode */
- if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
- {
- /* No -depth parameter passed, let the user know the depth being used */
- winDebug ("winAdjustVideoModeShadowDDNL - Using Windows display "
- "depth of %d bits per pixel\n", (int) dwBPP);
-
- /* Use GDI's depth */
- pScreenInfo->dwBPP = dwBPP;
- }
- else if (pScreenInfo->fFullScreen
- && pScreenInfo->dwBPP != dwBPP)
- {
- /* FullScreen, and GDI depth differs from -depth parameter */
- winDebug ("winAdjustVideoModeShadowDDNL - FullScreen, using command "
- "line bpp: %d\n", (int) pScreenInfo->dwBPP);
- }
- else if (dwBPP != pScreenInfo->dwBPP)
- {
- /* Windowed, and GDI depth differs from -depth parameter */
- winDebug ("winAdjustVideoModeShadowDDNL - Windowed, command line "
- "bpp: %d, using bpp: %d\n",
- (int) pScreenInfo->dwBPP, (int) dwBPP);
-
- /* We'll use GDI's depth */
- pScreenInfo->dwBPP = dwBPP;
- }
-
- /* See if the shadow bitmap will be larger than the DIB size limit */
- if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP
- >= WIN_DIB_MAXIMUM_SIZE)
- {
- ErrorF ("winAdjustVideoModeShadowDDNL - Requested DirectDraw surface "
- "will be larger than %d MB. The surface may fail to be "
- "allocated on Windows 95, 98, or Me, due to a %d MB limit in "
- "DIB size. This limit does not apply to Windows NT/2000, and "
- "this message may be ignored on those platforms.\n",
- WIN_DIB_MAXIMUM_SIZE_MB, WIN_DIB_MAXIMUM_SIZE_MB);
- }
-
- /* Release our DC */
- ReleaseDC (NULL, hdc);
-
- return TRUE;
-}
-
-
-/*
- * Blt exposed regions to the screen
- */
-
-static Bool
-winBltExposedRegionsShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- RECT rcSrc, rcDest;
- POINT ptOrigin;
- HDC hdcUpdate;
- PAINTSTRUCT ps;
- HRESULT ddrval = DD_OK;
- Bool fReturn = TRUE;
- int i;
-
- /* Quite common case. The primary surface was lost (maybe because of depth
- * change). Try to create a new primary surface. Bail out if this fails */
- if (pScreenPriv->pddsPrimary4 == NULL && pScreenPriv->fRetryCreateSurface &&
- !winCreatePrimarySurfaceShadowDDNL(pScreen))
- {
- Sleep(100);
- return FALSE;
- }
- if (pScreenPriv->pddsPrimary4 == NULL)
- return FALSE;
-
- /* BeginPaint gives us an hdc that clips to the invalidated region */
- hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
- if (hdcUpdate == NULL)
- {
- fReturn = FALSE;
- ErrorF ("winBltExposedRegionsShadowDDNL - BeginPaint () returned "
- "a NULL device context handle. Aborting blit attempt.\n");
- goto winBltExposedRegionsShadowDDNL_Exit;
- }
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
-
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
- rcDest.left = ptOrigin.x;
- rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
- rcDest.top = ptOrigin.y;
- rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
-
- /* Source can be entire shadow surface, as Blt should clip for us */
- rcSrc.left = 0;
- rcSrc.top = 0;
- rcSrc.right = pScreenInfo->dwWidth;
- rcSrc.bottom = pScreenInfo->dwHeight;
-
- /* Try to regain the primary surface and blit again if we've lost it */
- for (i = 0; i <= WIN_REGAIN_SURFACE_RETRIES; ++i)
- {
- /* Our Blt should be clipped to the invalidated region */
- ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
- &rcDest,
- pScreenPriv->pddsShadow4,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
- if (ddrval == DDERR_SURFACELOST)
- {
- /* Surface was lost */
- ErrorF ("winBltExposedRegionsShadowDDNL - "
- "IDirectDrawSurface4_Blt reported that the primary "
- "surface was lost, trying to restore, retry: %d\n", i + 1);
-
- /* Try to restore the surface, once */
-
- ddrval = IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4);
- winDebug ("winBltExposedRegionsShadowDDNL - "
- "IDirectDrawSurface4_Restore returned: ");
- if (ddrval == DD_OK)
- winDebug ("DD_OK\n");
- else if (ddrval == DDERR_WRONGMODE)
- winDebug ("DDERR_WRONGMODE\n");
- else if (ddrval == DDERR_INCOMPATIBLEPRIMARY)
- winDebug ("DDERR_INCOMPATIBLEPRIMARY\n");
- else if (ddrval == DDERR_UNSUPPORTED)
- winDebug ("DDERR_UNSUPPORTED\n");
- else if (ddrval == DDERR_INVALIDPARAMS)
- winDebug ("DDERR_INVALIDPARAMS\n");
- else if (ddrval == DDERR_INVALIDOBJECT)
- winDebug ("DDERR_INVALIDOBJECT\n");
- else
- winDebug ("unknown error: %08x\n", (unsigned int) ddrval);
-
- /* Loop around to try the blit one more time */
- continue;
- }
- else if (FAILED (ddrval))
- {
- fReturn = FALSE;
- ErrorF ("winBltExposedRegionsShadowDDNL - "
- "IDirectDrawSurface4_Blt failed, but surface not "
- "lost: %08x %d\n",
- (unsigned int) ddrval, (int) ddrval);
- goto winBltExposedRegionsShadowDDNL_Exit;
- }
- else
- {
- /* Success, stop looping */
- break;
- }
- }
-
- winBltExposedRegionsShadowDDNL_Exit:
- /* EndPaint frees the DC */
- if (hdcUpdate != NULL)
- EndPaint (pScreenPriv->hwndScreen, &ps);
- return fReturn;
-}
-
-
-/*
- * Do any engine-specific application-activation processing
- */
-
-static Bool
-winActivateAppShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
-
- /*
- * Do we have a surface?
- * Are we active?
- * Are we full screen?
- */
- if (pScreenPriv != NULL
- && pScreenPriv->pddsPrimary4 != NULL
- && pScreenPriv->fActive)
- {
- /* Primary surface was lost, restore it */
- IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4);
- }
-
- return TRUE;
-}
-
-
-/*
- * Reblit the shadow framebuffer to the screen.
- */
-
-static Bool
-winRedrawScreenShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
- HRESULT ddrval = DD_OK;
- RECT rcSrc, rcDest;
- POINT ptOrigin;
-
- /* Get the origin of the window in the screen coords */
- ptOrigin.x = pScreenInfo->dwXOffset;
- ptOrigin.y = pScreenInfo->dwYOffset;
- MapWindowPoints (pScreenPriv->hwndScreen,
- HWND_DESKTOP,
- (LPPOINT)&ptOrigin, 1);
- rcDest.left = ptOrigin.x;
- rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
- rcDest.top = ptOrigin.y;
- rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
-
- /* Source can be entire shadow surface, as Blt should clip for us */
- rcSrc.left = 0;
- rcSrc.top = 0;
- rcSrc.right = pScreenInfo->dwWidth;
- rcSrc.bottom = pScreenInfo->dwHeight;
-
- /* Redraw the whole window, to take account for the new colors */
- ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
- &rcDest,
- pScreenPriv->pddsShadow4,
- &rcSrc,
- DDBLT_WAIT,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winRedrawScreenShadowDDNL - IDirectDrawSurface4_Blt () "
- "failed: %08x\n",
- (unsigned int) ddrval);
- }
-
- return TRUE;
-}
-
-
-/*
- * Realize the currently installed colormap
- */
-
-static Bool
-winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen)
-{
- return TRUE;
-}
-
-
-/*
- * Install the specified colormap
- */
-
-static Bool
-winInstallColormapShadowDDNL (ColormapPtr pColormap)
-{
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
- HRESULT ddrval = DD_OK;
-
- /* Install the DirectDraw palette on the primary surface */
- ddrval = IDirectDrawSurface4_SetPalette (pScreenPriv->pddsPrimary4,
- pCmapPriv->lpDDPalette);
- if (FAILED (ddrval))
- {
- ErrorF ("winInstallColormapShadowDDNL - Failed installing the "
- "DirectDraw palette.\n");
- return FALSE;
- }
-
- /* Save a pointer to the newly installed colormap */
- pScreenPriv->pcmapInstalled = pColormap;
-
- return TRUE;
-}
-
-
-/*
- * Store the specified colors in the specified colormap
- */
-
-static Bool
-winStoreColorsShadowDDNL (ColormapPtr pColormap,
- int ndef,
- xColorItem *pdefs)
-{
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
- ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
- HRESULT ddrval = DD_OK;
-
- /* Put the X colormap entries into the Windows logical palette */
- ddrval = IDirectDrawPalette_SetEntries (pCmapPriv->lpDDPalette,
- 0,
- pdefs[0].pixel,
- ndef,
- pCmapPriv->peColors
- + pdefs[0].pixel);
- if (FAILED (ddrval))
- {
- ErrorF ("winStoreColorsShadowDDNL - SetEntries () failed: %08x\n", (unsigned int) ddrval);
- return FALSE;
- }
-
- /* Don't install the DirectDraw palette if the colormap is not installed */
- if (pColormap != curpmap)
- {
- return TRUE;
- }
-
- if (!winInstallColormapShadowDDNL (pColormap))
- {
- ErrorF ("winStoreColorsShadowDDNL - Failed installing colormap\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * Colormap initialization procedure
- */
-
-static Bool
-winCreateColormapShadowDDNL (ColormapPtr pColormap)
-{
- HRESULT ddrval = DD_OK;
- ScreenPtr pScreen = pColormap->pScreen;
- winScreenPriv(pScreen);
- winCmapPriv(pColormap);
-
- /* Create a DirectDraw palette */
- ddrval = IDirectDraw4_CreatePalette (pScreenPriv->pdd4,
- DDPCAPS_8BIT | DDPCAPS_ALLOW256,
- pCmapPriv->peColors,
- &pCmapPriv->lpDDPalette,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winCreateColormapShadowDDNL - CreatePalette failed\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * Colormap destruction procedure
- */
-
-static Bool
-winDestroyColormapShadowDDNL (ColormapPtr pColormap)
-{
- winScreenPriv(pColormap->pScreen);
- winCmapPriv(pColormap);
- HRESULT ddrval = DD_OK;
-
- /*
- * Is colormap to be destroyed the default?
- *
- * Non-default colormaps should have had winUninstallColormap
- * called on them before we get here. The default colormap
- * will not have had winUninstallColormap called on it. Thus,
- * we need to handle the default colormap in a special way.
- */
- if (pColormap->flags & IsDefault)
- {
- winDebug ("winDestroyColormapShadowDDNL - Destroying default colormap\n");
-
- /*
- * FIXME: Walk the list of all screens, popping the default
- * palette out of each screen device context.
- */
-
- /* Pop the palette out of the primary surface */
- ddrval = IDirectDrawSurface4_SetPalette (pScreenPriv->pddsPrimary4,
- NULL);
- if (FAILED (ddrval))
- {
- ErrorF ("winDestroyColormapShadowDDNL - Failed freeing the "
- "default colormap DirectDraw palette.\n");
- return FALSE;
- }
-
- /* Clear our private installed colormap pointer */
- pScreenPriv->pcmapInstalled = NULL;
- }
-
- /* Release the palette */
- IDirectDrawPalette_Release (pCmapPriv->lpDDPalette);
-
- /* Invalidate the colormap privates */
- pCmapPriv->lpDDPalette = NULL;
-
- return TRUE;
-}
-
-
-/*
- * Set pointers to our engine specific functions
- */
-
-Bool
-winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen)
-{
- winScreenPriv(pScreen);
- winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
- /* Set our pointers */
- pScreenPriv->pwinAllocateFB = winAllocateFBShadowDDNL;
- pScreenPriv->pwinShadowUpdate = winShadowUpdateDDNL;
- pScreenPriv->pwinCloseScreen = winCloseScreenShadowDDNL;
- pScreenPriv->pwinInitVisuals = winInitVisualsShadowDDNL;
- pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowDDNL;
- if (pScreenInfo->fFullScreen)
- pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
- else
- pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
- pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
- pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowDDNL;
- pScreenPriv->pwinActivateApp = winActivateAppShadowDDNL;
- pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowDDNL;
- pScreenPriv->pwinRealizeInstalledPalette
- = winRealizeInstalledPaletteShadowDDNL;
- pScreenPriv->pwinInstallColormap = winInstallColormapShadowDDNL;
- pScreenPriv->pwinStoreColors = winStoreColorsShadowDDNL;
- pScreenPriv->pwinCreateColormap = winCreateColormapShadowDDNL;
- pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDDNL;
- pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
- pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDDNL;
- pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDDNL;
-#ifdef XWIN_MULTIWINDOW
- pScreenPriv->pwinFinishCreateWindowsWindow
- = winFinishCreateWindowsWindowDDNL;
-#endif
-
- return TRUE;
-}
+/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+
+/*
+ * External symbols
+ */
+
+extern HWND g_hDlgExit;
+
+
+/*
+ * FIXME: Headers are broken, DEFINE_GUID doesn't work correctly,
+ * so we have to redefine it here.
+ */
+#ifndef _MSC_VER
+#ifdef DEFINE_GUID
+#undef DEFINE_GUID
+#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
+#endif /* DEFINE_GUID */
+#endif
+
+/*
+ * FIXME: Headers are broken, IID_IDirectDraw4 has to be defined
+ * here manually. Should be handled by ddraw.h
+ */
+#ifndef IID_IDirectDraw4
+DEFINE_GUID( IID_IDirectDraw4, 0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f,0xd9,0x30,0xc5 );
+#endif /* IID_IDirectDraw4 */
+
+#define FAIL_MSG_MAX_BLT 10
+
+
+/*
+ * Local prototypes
+ */
+
+static Bool
+winAllocateFBShadowDDNL (ScreenPtr pScreen);
+
+static void
+winShadowUpdateDDNL (ScreenPtr pScreen,
+ shadowBufPtr pBuf);
+
+static Bool
+winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen);
+
+static Bool
+winInitVisualsShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winAdjustVideoModeShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winBltExposedRegionsShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winActivateAppShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winRedrawScreenShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winInstallColormapShadowDDNL (ColormapPtr pColormap);
+
+static Bool
+winStoreColorsShadowDDNL (ColormapPtr pmap,
+ int ndef,
+ xColorItem *pdefs);
+
+static Bool
+winCreateColormapShadowDDNL (ColormapPtr pColormap);
+
+static Bool
+winDestroyColormapShadowDDNL (ColormapPtr pColormap);
+
+static Bool
+winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen);
+
+static Bool
+winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen);
+
+
+/*
+ * Create the primary surface and attach the clipper.
+ * Used for both the initial surface creation and during
+ * WM_DISPLAYCHANGE messages.
+ */
+
+static Bool
+winCreatePrimarySurfaceShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC2 ddsd;
+
+ winDebug ("winCreatePrimarySurfaceShadowDDNL - Creating primary surface\n");
+
+ /* Describe the primary surface */
+ ZeroMemory (&ddsd, sizeof (ddsd));
+ ddsd.dwSize = sizeof (ddsd);
+ ddsd.dwFlags = DDSD_CAPS;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+ /* Create the primary surface */
+ ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
+ &ddsd,
+ &pScreenPriv->pddsPrimary4,
+ NULL);
+ pScreenPriv->fRetryCreateSurface = FALSE;
+ if (FAILED (ddrval))
+ {
+ if (ddrval == DDERR_NOEXCLUSIVEMODE)
+ {
+ /* Recreating the surface failed. Mark screen to retry later */
+ pScreenPriv->fRetryCreateSurface = TRUE;
+ winDebug ("winCreatePrimarySurfaceShadowDDNL - Could not create "
+ "primary surface: DDERR_NOEXCLUSIVEMODE\n");
+ }
+ else
+ {
+ ErrorF ("winCreatePrimarySurfaceShadowDDNL - Could not create "
+ "primary surface: %08x\n", (unsigned int) ddrval);
+ }
+ return FALSE;
+ }
+
+ winDebug ("winCreatePrimarySurfaceShadowDDNL - Created primary surface\n");
+
+ /* Attach our clipper to our primary surface handle */
+ ddrval = IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
+ pScreenPriv->pddcPrimary);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winCreatePrimarySurfaceShadowDDNL - Primary attach clipper "
+ "failed: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winCreatePrimarySurfaceShadowDDNL - Attached clipper to primary "
+ "surface\n");
+
+ /* Everything was correct */
+ return TRUE;
+}
+
+
+/*
+ * Detach the clipper and release the primary surface.
+ * Called from WM_DISPLAYCHANGE.
+ */
+
+static Bool
+winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ winDebug ("winReleasePrimarySurfaceShadowDDNL - Hello\n");
+
+ /* Release the primary surface and clipper, if they exist */
+ if (pScreenPriv->pddsPrimary4)
+ {
+ /*
+ * Detach the clipper from the primary surface.
+ * NOTE: We do this explicity for clarity. The Clipper is not released.
+ */
+ IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
+ NULL);
+
+ winDebug ("winReleasePrimarySurfaceShadowDDNL - Detached clipper\n");
+
+ /* Release the primary surface */
+ IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4);
+ pScreenPriv->pddsPrimary4 = NULL;
+ }
+
+ winDebug ("winReleasePrimarySurfaceShadowDDNL - Released primary surface\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Create a DirectDraw surface for the shadow framebuffer; also create
+ * a primary surface object so we can blit to the display.
+ *
+ * Install a DirectDraw clipper on our primary surface object
+ * that clips our blits to the unobscured client area of our display window.
+ */
+
+Bool
+winAllocateFBShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC2 ddsdShadow;
+ char *lpSurface = NULL;
+ DDPIXELFORMAT ddpfPrimary;
+
+ winDebug ("winAllocateFBShadowDDNL - w %d h %d d %d\n",
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight, pScreenInfo->dwDepth);
+
+ /* Allocate memory for our shadow surface */
+ lpSurface = malloc (pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
+ if (lpSurface == NULL)
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not allocate bits\n");
+ return FALSE;
+ }
+
+ /*
+ * Initialize the framebuffer memory so we don't get a
+ * strange display at startup
+ */
+ ZeroMemory (lpSurface, pScreenInfo->dwPaddedWidth * pScreenInfo->dwHeight);
+
+ /* Create a clipper */
+ ddrval = (*g_fpDirectDrawCreateClipper) (0,
+ &pScreenPriv->pddcPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not attach clipper: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDDNL - Created a clipper\n");
+
+ /* Get a device context for the screen */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+
+ /* Attach the clipper to our display window */
+ ddrval = IDirectDrawClipper_SetHWnd (pScreenPriv->pddcPrimary,
+ 0,
+ pScreenPriv->hwndScreen);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Clipper not attached "
+ "to window: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDDNL - Attached clipper to window\n");
+
+ /* Create a DirectDraw object, store the address at lpdd */
+ ddrval = (*g_fpDirectDrawCreate) (NULL,
+ (LPDIRECTDRAW*) &pScreenPriv->pdd,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not start "
+ "DirectDraw: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDDNL - Created and initialized DD\n");
+
+ /* Get a DirectDraw4 interface pointer */
+ ddrval = IDirectDraw_QueryInterface (pScreenPriv->pdd,
+ &IID_IDirectDraw4,
+ (LPVOID*) &pScreenPriv->pdd4);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Failed DD4 query: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ /* Are we full screen? */
+ if (pScreenInfo->fFullScreen)
+ {
+ DDSURFACEDESC2 ddsdCurrent;
+ DWORD dwRefreshRateCurrent = 0;
+ HDC hdc = NULL;
+
+ /* Set the cooperative level to full screen */
+ ddrval = IDirectDraw4_SetCooperativeLevel (pScreenPriv->pdd4,
+ pScreenPriv->hwndScreen,
+ DDSCL_EXCLUSIVE
+ | DDSCL_FULLSCREEN);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not set "
+ "cooperative level: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ /*
+ * We only need to get the current refresh rate for comparison
+ * if a refresh rate has been passed on the command line.
+ */
+ if (pScreenInfo->dwRefreshRate != 0)
+ {
+ ZeroMemory (&ddsdCurrent, sizeof (ddsdCurrent));
+ ddsdCurrent.dwSize = sizeof (ddsdCurrent);
+
+ /* Get information about current display settings */
+ ddrval = IDirectDraw4_GetDisplayMode (pScreenPriv->pdd4,
+ &ddsdCurrent);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not get current "
+ "refresh rate: %08x. Continuing.\n",
+ (unsigned int) ddrval);
+ dwRefreshRateCurrent = 0;
+ }
+ else
+ {
+ /* Grab the current refresh rate */
+ dwRefreshRateCurrent = ddsdCurrent.u2.dwRefreshRate;
+ }
+ }
+
+ /* Clean up the refresh rate */
+ if (dwRefreshRateCurrent == pScreenInfo->dwRefreshRate)
+ {
+ /*
+ * Refresh rate is non-specified or equal to current.
+ */
+ pScreenInfo->dwRefreshRate = 0;
+ }
+
+ /* Grab a device context for the screen */
+ hdc = GetDC (NULL);
+ if (hdc == NULL)
+ {
+ ErrorF ("winAllocateFBShadowDDNL - GetDC () failed\n");
+ return FALSE;
+ }
+
+ /* Only change the video mode when different than current mode */
+ if (!pScreenInfo->fMultipleMonitors
+ && (pScreenInfo->dwWidth != GetSystemMetrics (SM_CXSCREEN)
+ || pScreenInfo->dwHeight != GetSystemMetrics (SM_CYSCREEN)
+ || pScreenInfo->dwBPP != GetDeviceCaps (hdc, BITSPIXEL)
+ || pScreenInfo->dwRefreshRate != 0))
+ {
+ winDebug ("winAllocateFBShadowDDNL - Changing video mode\n");
+
+ /* Change the video mode to the mode requested, and use the driver default refresh rate on failure */
+ ddrval = IDirectDraw4_SetDisplayMode (pScreenPriv->pdd4,
+ pScreenInfo->dwWidth,
+ pScreenInfo->dwHeight,
+ pScreenInfo->dwBPP,
+ pScreenInfo->dwRefreshRate,
+ 0);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not set "
+ "full screen display mode: %08x\n",
+ (unsigned int) ddrval);
+ ErrorF ("winAllocateFBShadowDDNL - Using default driver refresh rate\n");
+ ddrval = IDirectDraw4_SetDisplayMode (pScreenPriv->pdd4,
+ pScreenInfo->dwWidth,
+ pScreenInfo->dwHeight,
+ pScreenInfo->dwBPP,
+ 0,
+ 0);
+ if (FAILED(ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not set default refresh rate "
+ "full screen display mode: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ winDebug ("winAllocateFBShadowDDNL - Not changing video mode\n");
+ }
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+ hdc = NULL;
+ }
+ else
+ {
+ /* Set the cooperative level for windowed mode */
+ ddrval = IDirectDraw4_SetCooperativeLevel (pScreenPriv->pdd4,
+ pScreenPriv->hwndScreen,
+ DDSCL_NORMAL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not set "
+ "cooperative level: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+ }
+
+ /* Create the primary surface */
+ if (!winCreatePrimarySurfaceShadowDDNL (pScreen))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - winCreatePrimarySurfaceShadowDDNL "
+ "failed\n");
+ return FALSE;
+ }
+
+ /* Get primary surface's pixel format */
+ ZeroMemory (&ddpfPrimary, sizeof (ddpfPrimary));
+ ddpfPrimary.dwSize = sizeof (ddpfPrimary);
+ ddrval = IDirectDrawSurface4_GetPixelFormat (pScreenPriv->pddsPrimary4,
+ &ddpfPrimary);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not get primary "
+ "pixformat: %08x\n",
+ (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDDNL - Primary masks: %08x %08x %08x "
+ "dwRGBBitCount: %d\n",
+ ddpfPrimary.u2.dwRBitMask,
+ ddpfPrimary.u3.dwGBitMask,
+ ddpfPrimary.u4.dwBBitMask,
+ ddpfPrimary.u1.dwRGBBitCount);
+
+ /* Describe the shadow surface to be created */
+ /*
+ * NOTE: Do not use a DDSCAPS_VIDEOMEMORY surface,
+ * as drawing, locking, and unlocking take forever
+ * with video memory surfaces. In addition,
+ * video memory is a somewhat scarce resource,
+ * so you shouldn't be allocating video memory when
+ * you have the option of using system memory instead.
+ */
+ ZeroMemory (&ddsdShadow, sizeof (ddsdShadow));
+ ddsdShadow.dwSize = sizeof (ddsdShadow);
+ ddsdShadow.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH
+ | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT;
+ ddsdShadow.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
+ ddsdShadow.dwHeight = pScreenInfo->dwHeight;
+ ddsdShadow.dwWidth = pScreenInfo->dwWidth;
+ ddsdShadow.u1.lPitch = pScreenInfo->dwPaddedWidth;
+ ddsdShadow.lpSurface = lpSurface;
+ ddsdShadow.u4.ddpfPixelFormat = ddpfPrimary;
+
+ winDebug ("winAllocateFBShadowDDNL - lPitch: %d\n",
+ (int) pScreenInfo->dwPaddedWidth);
+
+ /* Create the shadow surface */
+ ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
+ &ddsdShadow,
+ &pScreenPriv->pddsShadow4,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winAllocateFBShadowDDNL - Could not create shadow "
+ "surface: %08x\n", (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ winDebug ("winAllocateFBShadowDDNL - Created shadow pitch: %d\n",
+ (int) ddsdShadow.u1.lPitch);
+
+ /* Grab the pitch from the surface desc */
+ pScreenInfo->dwStride = (ddsdShadow.u1.lPitch * 8)
+ / pScreenInfo->dwBPP;
+
+ winDebug ("winAllocateFBShadowDDNL - Created shadow stride: %d\n",
+ (int) pScreenInfo->dwStride);
+
+ /* Save the pointer to our surface memory */
+ pScreenInfo->pfb = lpSurface;
+
+ /* Grab the masks from the surface description */
+ pScreenPriv->dwRedMask = ddsdShadow.u4.ddpfPixelFormat.u2.dwRBitMask;
+ pScreenPriv->dwGreenMask = ddsdShadow.u4.ddpfPixelFormat.u3.dwGBitMask;
+ pScreenPriv->dwBlueMask = ddsdShadow.u4.ddpfPixelFormat.u4.dwBBitMask;
+
+ winDebug ("winAllocateFBShadowDDNL - Returning\n");
+
+ return TRUE;
+}
+
+
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+/*
+ * Create a DirectDraw surface for the new multi-window window
+ */
+
+static
+Bool
+winFinishCreateWindowsWindowDDNL (WindowPtr pWin)
+{
+ winWindowPriv(pWin);
+ winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv;
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC2 ddsd;
+ int iWidth, iHeight;
+ int iX, iY;
+
+ winDebug ("winFinishCreateWindowsWindowDDNL!\n\n");
+
+ iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN);
+ iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN);
+
+ iWidth = pWin->drawable.width;
+ iHeight = pWin->drawable.height;
+
+ /* Describe the primary surface */
+ ZeroMemory (&ddsd, sizeof (ddsd));
+ ddsd.dwSize = sizeof (ddsd);
+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+ ddsd.dwHeight = iHeight;
+ ddsd.dwWidth = iWidth;
+
+ /* Create the primary surface */
+ ddrval = IDirectDraw4_CreateSurface (pScreenPriv->pdd4,
+ &ddsd,
+ &pWinPriv->pddsPrimary4,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winFinishCreateWindowsWindowDDNL - Could not create primary "
+ "surface: %08x\n",
+ (unsigned int)ddrval);
+ return FALSE;
+ }
+ return TRUE;
+}
+#endif
+
+
+/*
+ * Transfer the damaged regions of the shadow framebuffer to the display.
+ */
+
+static void
+winShadowUpdateDDNL (ScreenPtr pScreen,
+ shadowBufPtr pBuf)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RegionPtr damage = shadowDamage(pBuf);
+ HRESULT ddrval = DD_OK;
+ RECT rcDest, rcSrc;
+ POINT ptOrigin;
+ DWORD dwBox = REGION_NUM_RECTS (damage);
+ BoxPtr pBox = REGION_RECTS (damage);
+ HRGN hrgnTemp = NULL, hrgnCombined = NULL;
+
+ /*
+ * Return immediately if the app is not active
+ * and we are fullscreen, or if we have a bad display depth
+ */
+ if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen)
+ || pScreenPriv->fBadDepth) return;
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+
+ /*
+ * Handle small regions with multiple blits,
+ * handle large regions by creating a clipping region and
+ * doing a single blit constrained to that clipping region.
+ */
+ if (pScreenInfo->dwClipUpdatesNBoxes == 0
+ || dwBox < pScreenInfo->dwClipUpdatesNBoxes)
+ {
+ /* Loop through all boxes in the damaged region */
+ while (dwBox--)
+ {
+ /* Assign damage box to source rectangle */
+ rcSrc.left = pBox->x1;
+ rcSrc.top = pBox->y1;
+ rcSrc.right = pBox->x2;
+ rcSrc.bottom = pBox->y2;
+
+ /* Calculate destination rectangle */
+ rcDest.left = ptOrigin.x + rcSrc.left;
+ rcDest.top = ptOrigin.y + rcSrc.top;
+ rcDest.right = ptOrigin.x + rcSrc.right;
+ rcDest.bottom = ptOrigin.y + rcSrc.bottom;
+
+ /* Blit the damaged areas */
+ ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
+ &rcDest,
+ pScreenPriv->pddsShadow4,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ static int s_iFailCount = 0;
+
+ if (s_iFailCount < FAIL_MSG_MAX_BLT)
+ {
+ ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt () "
+ "failed: %08x\n",
+ (unsigned int) ddrval);
+
+ ++s_iFailCount;
+
+ if (s_iFailCount == FAIL_MSG_MAX_BLT)
+ {
+ ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt "
+ "failure message maximum (%d) reached. No "
+ "more failure messages will be printed.\n",
+ FAIL_MSG_MAX_BLT);
+ }
+ }
+ }
+
+ /* Get a pointer to the next box */
+ ++pBox;
+ }
+ }
+ else
+ {
+ BoxPtr pBoxExtents = REGION_EXTENTS (pScreen, damage);
+
+ /* Compute a GDI region from the damaged region */
+ hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
+ dwBox--;
+ pBox++;
+ while (dwBox--)
+ {
+ hrgnTemp = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
+ CombineRgn (hrgnCombined, hrgnCombined, hrgnTemp, RGN_OR);
+ DeleteObject (hrgnTemp);
+ pBox++;
+ }
+
+ /* Install the GDI region as a clipping region */
+ SelectClipRgn (pScreenPriv->hdcScreen, hrgnCombined);
+ DeleteObject (hrgnCombined);
+ hrgnCombined = NULL;
+
+ winDebug ("winShadowUpdateDDNL - be x1 %d y1 %d x2 %d y2 %d\n",
+ pBoxExtents->x1, pBoxExtents->y1,
+ pBoxExtents->x2, pBoxExtents->y2);
+
+ /* Calculating a bounding box for the source is easy */
+ rcSrc.left = pBoxExtents->x1;
+ rcSrc.top = pBoxExtents->y1;
+ rcSrc.right = pBoxExtents->x2;
+ rcSrc.bottom = pBoxExtents->y2;
+
+ /* Calculating a bounding box for the destination is trickier */
+ rcDest.left = ptOrigin.x + rcSrc.left;
+ rcDest.top = ptOrigin.y + rcSrc.top;
+ rcDest.right = ptOrigin.x + rcSrc.right;
+ rcDest.bottom = ptOrigin.y + rcSrc.bottom;
+
+ /* Our Blt should be clipped to the invalidated region */
+ ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
+ &rcDest,
+ pScreenPriv->pddsShadow4,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+
+ /* Reset the clip region */
+ SelectClipRgn (pScreenPriv->hdcScreen, NULL);
+ }
+}
+
+
+/*
+ * Call the wrapped CloseScreen function.
+ *
+ * Free our resources and private structures.
+ */
+
+static Bool
+winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ Bool fReturn;
+
+ winDebug ("winCloseScreenShadowDDNL - Freeing screen resources\n");
+
+ /* Flag that the screen is closed */
+ pScreenPriv->fClosed = TRUE;
+ pScreenPriv->fActive = FALSE;
+
+ /* Call the wrapped CloseScreen procedure */
+ WIN_UNWRAP(CloseScreen);
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ /* Free the screen DC */
+ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ /* Free the shadow surface, if there is one */
+ if (pScreenPriv->pddsShadow4)
+ {
+ IDirectDrawSurface4_Release (pScreenPriv->pddsShadow4);
+ free (pScreenInfo->pfb);
+ pScreenInfo->pfb = NULL;
+ pScreenPriv->pddsShadow4 = NULL;
+ }
+
+ /* Detach the clipper from the primary surface and release the clipper. */
+ if (pScreenPriv->pddcPrimary)
+ {
+ /* Detach the clipper */
+ IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
+ NULL);
+
+ /* Release the clipper object */
+ IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
+ pScreenPriv->pddcPrimary = NULL;
+ }
+
+ /* Release the primary surface, if there is one */
+ if (pScreenPriv->pddsPrimary4)
+ {
+ IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4);
+ pScreenPriv->pddsPrimary4 = NULL;
+ }
+
+ /* Free the DirectDraw4 object, if there is one */
+ if (pScreenPriv->pdd4)
+ {
+ IDirectDraw4_RestoreDisplayMode (pScreenPriv->pdd4);
+ IDirectDraw4_Release (pScreenPriv->pdd4);
+ pScreenPriv->pdd4 = NULL;
+ }
+
+ /* Free the DirectDraw object, if there is one */
+ if (pScreenPriv->pdd)
+ {
+ IDirectDraw_Release (pScreenPriv->pdd);
+ pScreenPriv->pdd = NULL;
+ }
+
+ /* Delete tray icon, if we have one */
+ if (!pScreenInfo->fNoTrayIcon)
+ winDeleteNotifyIcon (pScreenPriv);
+
+ /* Free the exit confirmation dialog box, if it exists */
+ if (g_hDlgExit != NULL)
+ {
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+ }
+
+ /* Kill our window */
+ if (pScreenPriv->hwndScreen)
+ {
+ DestroyWindow (pScreenPriv->hwndScreen);
+ pScreenPriv->hwndScreen = NULL;
+ }
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ /* Destroy the thread startup mutex */
+ pthread_mutex_destroy (&pScreenPriv->pmServerStarted);
+#endif
+
+ /* Kill our screeninfo's pointer to the screen */
+ pScreenInfo->pScreen = NULL;
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+
+ /* Free the screen privates for this screen */
+ free ((pointer) pScreenPriv);
+
+ return fReturn;
+}
+
+
+/*
+ * Tell mi what sort of visuals we need.
+ *
+ * Generally we only need one visual, as our screen can only
+ * handle one format at a time, I believe. You may want
+ * to verify that last sentence.
+ */
+
+static Bool
+winInitVisualsShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ DWORD dwRedBits, dwGreenBits, dwBlueBits;
+
+ /* Count the number of ones in each color mask */
+ dwRedBits = winCountBits (pScreenPriv->dwRedMask);
+ dwGreenBits = winCountBits (pScreenPriv->dwGreenMask);
+ dwBlueBits = winCountBits (pScreenPriv->dwBlueMask);
+
+ /* Store the maximum number of ones in a color mask as the bitsPerRGB */
+ if (dwRedBits == 0 || dwGreenBits == 0 || dwBlueBits == 0)
+ pScreenPriv->dwBitsPerRGB = 8;
+ else if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwRedBits;
+ else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwGreenBits;
+ else
+ pScreenPriv->dwBitsPerRGB = dwBlueBits;
+
+ winDebug ("winInitVisualsShadowDDNL - Masks %08x %08x %08x BPRGB %d d %d "
+ "bpp %d\n",
+ (unsigned int) pScreenPriv->dwRedMask,
+ (unsigned int) pScreenPriv->dwGreenMask,
+ (unsigned int) pScreenPriv->dwBlueMask,
+ (int) pScreenPriv->dwBitsPerRGB,
+ (int) pScreenInfo->dwDepth,
+ (int) pScreenInfo->dwBPP);
+
+ /* Create a single visual according to the Windows screen depth */
+ switch (pScreenInfo->dwDepth)
+ {
+ case 24:
+ case 16:
+ case 15:
+#if defined(XFree86Server)
+ /* Setup the real visual */
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ -1,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
+ "failed for TrueColor\n");
+ return FALSE;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ if (!pScreenInfo->fEmulatePseudo)
+ break;
+
+ /* Setup a pseudocolor visual */
+ if (!miSetVisualTypesAndMasks (8,
+ PseudoColorMask,
+ 8,
+ -1,
+ 0,
+ 0,
+ 0))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
+ "failed for PseudoColor\n");
+ return FALSE;
+ }
+#endif
+#else /* XFree86Server */
+ /* Setup the real visual */
+ if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
+ "failed for TrueColor\n");
+ return FALSE;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ if (!pScreenInfo->fEmulatePseudo)
+ break;
+
+ /* Setup a pseudocolor visual */
+ if (!fbSetVisualTypesAndMasks (8,
+ PseudoColorMask,
+ 8,
+ 0,
+ 0,
+ 0))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
+ "failed for PseudoColor\n");
+ return FALSE;
+ }
+#endif
+#endif /* XFree86Server */
+ break;
+
+ case 8:
+#if defined(XFree86Server)
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ pScreenInfo->fFullScreen
+ ? PseudoColorMask : StaticColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenInfo->fFullScreen
+ ? PseudoColor : StaticColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - miSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+#else /* XFree86Server */
+ if (!fbSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ pScreenInfo->fFullScreen
+ ? PseudoColorMask : StaticColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowDDNL - fbSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+#endif /* XFree86Server */
+ break;
+
+ default:
+ ErrorF ("winInitVisualsShadowDDNL - Unknown screen depth\n");
+ return FALSE;
+ }
+
+ winDebug ("winInitVisualsShadowDDNL - Returning\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Adjust the user proposed video mode
+ */
+
+static Bool
+winAdjustVideoModeShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HDC hdc = NULL;
+ DWORD dwBPP;
+
+ /* We're in serious trouble if we can't get a DC */
+ hdc = GetDC (NULL);
+ if (hdc == NULL)
+ {
+ ErrorF ("winAdjustVideoModeShadowDDNL - GetDC () failed\n");
+ return FALSE;
+ }
+
+ /* Query GDI for current display depth */
+ dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
+
+ /* DirectDraw can only change the depth in fullscreen mode */
+ if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
+ {
+ /* No -depth parameter passed, let the user know the depth being used */
+ winDebug ("winAdjustVideoModeShadowDDNL - Using Windows display "
+ "depth of %d bits per pixel\n", (int) dwBPP);
+
+ /* Use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+ else if (pScreenInfo->fFullScreen
+ && pScreenInfo->dwBPP != dwBPP)
+ {
+ /* FullScreen, and GDI depth differs from -depth parameter */
+ winDebug ("winAdjustVideoModeShadowDDNL - FullScreen, using command "
+ "line bpp: %d\n", (int) pScreenInfo->dwBPP);
+ }
+ else if (dwBPP != pScreenInfo->dwBPP)
+ {
+ /* Windowed, and GDI depth differs from -depth parameter */
+ winDebug ("winAdjustVideoModeShadowDDNL - Windowed, command line "
+ "bpp: %d, using bpp: %d\n",
+ (int) pScreenInfo->dwBPP, (int) dwBPP);
+
+ /* We'll use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+
+ /* See if the shadow bitmap will be larger than the DIB size limit */
+ if (pScreenInfo->dwWidth * pScreenInfo->dwHeight * pScreenInfo->dwBPP
+ >= WIN_DIB_MAXIMUM_SIZE)
+ {
+ ErrorF ("winAdjustVideoModeShadowDDNL - Requested DirectDraw surface "
+ "will be larger than %d MB. The surface may fail to be "
+ "allocated on Windows 95, 98, or Me, due to a %d MB limit in "
+ "DIB size. This limit does not apply to Windows NT/2000, and "
+ "this message may be ignored on those platforms.\n",
+ WIN_DIB_MAXIMUM_SIZE_MB, WIN_DIB_MAXIMUM_SIZE_MB);
+ }
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+
+ return TRUE;
+}
+
+
+/*
+ * Blt exposed regions to the screen
+ */
+
+static Bool
+winBltExposedRegionsShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RECT rcSrc, rcDest;
+ POINT ptOrigin;
+ HDC hdcUpdate;
+ PAINTSTRUCT ps;
+ HRESULT ddrval = DD_OK;
+ Bool fReturn = TRUE;
+ int i;
+
+ /* Quite common case. The primary surface was lost (maybe because of depth
+ * change). Try to create a new primary surface. Bail out if this fails */
+ if (pScreenPriv->pddsPrimary4 == NULL && pScreenPriv->fRetryCreateSurface &&
+ !winCreatePrimarySurfaceShadowDDNL(pScreen))
+ {
+ Sleep(100);
+ return FALSE;
+ }
+ if (pScreenPriv->pddsPrimary4 == NULL)
+ return FALSE;
+
+ /* BeginPaint gives us an hdc that clips to the invalidated region */
+ hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
+ if (hdcUpdate == NULL)
+ {
+ fReturn = FALSE;
+ ErrorF ("winBltExposedRegionsShadowDDNL - BeginPaint () returned "
+ "a NULL device context handle. Aborting blit attempt.\n");
+ goto winBltExposedRegionsShadowDDNL_Exit;
+ }
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+ rcDest.left = ptOrigin.x;
+ rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
+ rcDest.top = ptOrigin.y;
+ rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
+
+ /* Source can be entire shadow surface, as Blt should clip for us */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ /* Try to regain the primary surface and blit again if we've lost it */
+ for (i = 0; i <= WIN_REGAIN_SURFACE_RETRIES; ++i)
+ {
+ /* Our Blt should be clipped to the invalidated region */
+ ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
+ &rcDest,
+ pScreenPriv->pddsShadow4,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (ddrval == DDERR_SURFACELOST)
+ {
+ /* Surface was lost */
+ ErrorF ("winBltExposedRegionsShadowDDNL - "
+ "IDirectDrawSurface4_Blt reported that the primary "
+ "surface was lost, trying to restore, retry: %d\n", i + 1);
+
+ /* Try to restore the surface, once */
+
+ ddrval = IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4);
+ winDebug ("winBltExposedRegionsShadowDDNL - "
+ "IDirectDrawSurface4_Restore returned: ");
+ if (ddrval == DD_OK)
+ winDebug ("DD_OK\n");
+ else if (ddrval == DDERR_WRONGMODE)
+ winDebug ("DDERR_WRONGMODE\n");
+ else if (ddrval == DDERR_INCOMPATIBLEPRIMARY)
+ winDebug ("DDERR_INCOMPATIBLEPRIMARY\n");
+ else if (ddrval == DDERR_UNSUPPORTED)
+ winDebug ("DDERR_UNSUPPORTED\n");
+ else if (ddrval == DDERR_INVALIDPARAMS)
+ winDebug ("DDERR_INVALIDPARAMS\n");
+ else if (ddrval == DDERR_INVALIDOBJECT)
+ winDebug ("DDERR_INVALIDOBJECT\n");
+ else
+ winDebug ("unknown error: %08x\n", (unsigned int) ddrval);
+
+ /* Loop around to try the blit one more time */
+ continue;
+ }
+ else if (FAILED (ddrval))
+ {
+ fReturn = FALSE;
+ ErrorF ("winBltExposedRegionsShadowDDNL - "
+ "IDirectDrawSurface4_Blt failed, but surface not "
+ "lost: %08x %d\n",
+ (unsigned int) ddrval, (int) ddrval);
+ goto winBltExposedRegionsShadowDDNL_Exit;
+ }
+ else
+ {
+ /* Success, stop looping */
+ break;
+ }
+ }
+
+ winBltExposedRegionsShadowDDNL_Exit:
+ /* EndPaint frees the DC */
+ if (hdcUpdate != NULL)
+ EndPaint (pScreenPriv->hwndScreen, &ps);
+ return fReturn;
+}
+
+
+/*
+ * Do any engine-specific application-activation processing
+ */
+
+static Bool
+winActivateAppShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ /*
+ * Do we have a surface?
+ * Are we active?
+ * Are we full screen?
+ */
+ if (pScreenPriv != NULL
+ && pScreenPriv->pddsPrimary4 != NULL
+ && pScreenPriv->fActive)
+ {
+ /* Primary surface was lost, restore it */
+ IDirectDrawSurface4_Restore (pScreenPriv->pddsPrimary4);
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Reblit the shadow framebuffer to the screen.
+ */
+
+static Bool
+winRedrawScreenShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HRESULT ddrval = DD_OK;
+ RECT rcSrc, rcDest;
+ POINT ptOrigin;
+
+ /* Get the origin of the window in the screen coords */
+ ptOrigin.x = pScreenInfo->dwXOffset;
+ ptOrigin.y = pScreenInfo->dwYOffset;
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&ptOrigin, 1);
+ rcDest.left = ptOrigin.x;
+ rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
+ rcDest.top = ptOrigin.y;
+ rcDest.bottom = ptOrigin.y + pScreenInfo->dwHeight;
+
+ /* Source can be entire shadow surface, as Blt should clip for us */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ /* Redraw the whole window, to take account for the new colors */
+ ddrval = IDirectDrawSurface4_Blt (pScreenPriv->pddsPrimary4,
+ &rcDest,
+ pScreenPriv->pddsShadow4,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winRedrawScreenShadowDDNL - IDirectDrawSurface4_Blt () "
+ "failed: %08x\n",
+ (unsigned int) ddrval);
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Realize the currently installed colormap
+ */
+
+static Bool
+winRealizeInstalledPaletteShadowDDNL (ScreenPtr pScreen)
+{
+ return TRUE;
+}
+
+
+/*
+ * Install the specified colormap
+ */
+
+static Bool
+winInstallColormapShadowDDNL (ColormapPtr pColormap)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+ HRESULT ddrval = DD_OK;
+
+ /* Install the DirectDraw palette on the primary surface */
+ ddrval = IDirectDrawSurface4_SetPalette (pScreenPriv->pddsPrimary4,
+ pCmapPriv->lpDDPalette);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winInstallColormapShadowDDNL - Failed installing the "
+ "DirectDraw palette.\n");
+ return FALSE;
+ }
+
+ /* Save a pointer to the newly installed colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+
+ return TRUE;
+}
+
+
+/*
+ * Store the specified colors in the specified colormap
+ */
+
+static Bool
+winStoreColorsShadowDDNL (ColormapPtr pColormap,
+ int ndef,
+ xColorItem *pdefs)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+ ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
+ HRESULT ddrval = DD_OK;
+
+ /* Put the X colormap entries into the Windows logical palette */
+ ddrval = IDirectDrawPalette_SetEntries (pCmapPriv->lpDDPalette,
+ 0,
+ pdefs[0].pixel,
+ ndef,
+ pCmapPriv->peColors
+ + pdefs[0].pixel);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winStoreColorsShadowDDNL - SetEntries () failed: %08x\n", (unsigned int) ddrval);
+ return FALSE;
+ }
+
+ /* Don't install the DirectDraw palette if the colormap is not installed */
+ if (pColormap != curpmap)
+ {
+ return TRUE;
+ }
+
+ if (!winInstallColormapShadowDDNL (pColormap))
+ {
+ ErrorF ("winStoreColorsShadowDDNL - Failed installing colormap\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap initialization procedure
+ */
+
+static Bool
+winCreateColormapShadowDDNL (ColormapPtr pColormap)
+{
+ HRESULT ddrval = DD_OK;
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+
+ /* Create a DirectDraw palette */
+ ddrval = IDirectDraw4_CreatePalette (pScreenPriv->pdd4,
+ DDPCAPS_8BIT | DDPCAPS_ALLOW256,
+ pCmapPriv->peColors,
+ &pCmapPriv->lpDDPalette,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winCreateColormapShadowDDNL - CreatePalette failed\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap destruction procedure
+ */
+
+static Bool
+winDestroyColormapShadowDDNL (ColormapPtr pColormap)
+{
+ winScreenPriv(pColormap->pScreen);
+ winCmapPriv(pColormap);
+ HRESULT ddrval = DD_OK;
+
+ /*
+ * Is colormap to be destroyed the default?
+ *
+ * Non-default colormaps should have had winUninstallColormap
+ * called on them before we get here. The default colormap
+ * will not have had winUninstallColormap called on it. Thus,
+ * we need to handle the default colormap in a special way.
+ */
+ if (pColormap->flags & IsDefault)
+ {
+ winDebug ("winDestroyColormapShadowDDNL - Destroying default colormap\n");
+
+ /*
+ * FIXME: Walk the list of all screens, popping the default
+ * palette out of each screen device context.
+ */
+
+ /* Pop the palette out of the primary surface */
+ ddrval = IDirectDrawSurface4_SetPalette (pScreenPriv->pddsPrimary4,
+ NULL);
+ if (FAILED (ddrval))
+ {
+ ErrorF ("winDestroyColormapShadowDDNL - Failed freeing the "
+ "default colormap DirectDraw palette.\n");
+ return FALSE;
+ }
+
+ /* Clear our private installed colormap pointer */
+ pScreenPriv->pcmapInstalled = NULL;
+ }
+
+ /* Release the palette */
+ IDirectDrawPalette_Release (pCmapPriv->lpDDPalette);
+
+ /* Invalidate the colormap privates */
+ pCmapPriv->lpDDPalette = NULL;
+
+ return TRUE;
+}
+
+
+/*
+ * Set pointers to our engine specific functions
+ */
+
+Bool
+winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Set our pointers */
+ pScreenPriv->pwinAllocateFB = winAllocateFBShadowDDNL;
+ pScreenPriv->pwinShadowUpdate = winShadowUpdateDDNL;
+ pScreenPriv->pwinCloseScreen = winCloseScreenShadowDDNL;
+ pScreenPriv->pwinInitVisuals = winInitVisualsShadowDDNL;
+ pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowDDNL;
+ if (pScreenInfo->fFullScreen)
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
+ else
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
+ pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
+ pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowDDNL;
+ pScreenPriv->pwinActivateApp = winActivateAppShadowDDNL;
+ pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowDDNL;
+ pScreenPriv->pwinRealizeInstalledPalette
+ = winRealizeInstalledPaletteShadowDDNL;
+ pScreenPriv->pwinInstallColormap = winInstallColormapShadowDDNL;
+ pScreenPriv->pwinStoreColors = winStoreColorsShadowDDNL;
+ pScreenPriv->pwinCreateColormap = winCreateColormapShadowDDNL;
+ pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowDDNL;
+ pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinCreatePrimarySurface = winCreatePrimarySurfaceShadowDDNL;
+ pScreenPriv->pwinReleasePrimarySurface = winReleasePrimarySurfaceShadowDDNL;
+#ifdef XWIN_MULTIWINDOW
+ pScreenPriv->pwinFinishCreateWindowsWindow
+ = winFinishCreateWindowsWindowDDNL;
+#endif
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winwindowswm.c b/xorg-server/hw/xwin/winwindowswm.c
index cfac71d82..d0c6de9bc 100644
--- a/xorg-server/hw/xwin/winwindowswm.c
+++ b/xorg-server/hw/xwin/winwindowswm.c
@@ -81,7 +81,7 @@ make_box (int x, int y, int w, int h)
}
void
-winWindowsWMExtensionInit ()
+winWindowsWMExtensionInit (void)
{
ExtensionEntry* extEntry;
diff --git a/xorg-server/mi/mieq.c b/xorg-server/mi/mieq.c
index 2d5f23ea6..01b4ae2a3 100644
--- a/xorg-server/mi/mieq.c
+++ b/xorg-server/mi/mieq.c
@@ -1,488 +1,489 @@
-/*
- *
-Copyright 1990, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
- *
- * Author: Keith Packard, MIT X Consortium
- */
-
-/*
- * mieq.c
- *
- * Machine independent event queue
- *
- */
-
-#if HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-# include <X11/X.h>
-# include <X11/Xmd.h>
-# include <X11/Xproto.h>
-# include "misc.h"
-# include "windowstr.h"
-# include "pixmapstr.h"
-# include "inputstr.h"
-# include "mi.h"
-# include "mipointer.h"
-# include "scrnintstr.h"
-# include <X11/extensions/XI.h>
-# include <X11/extensions/XIproto.h>
-# include <X11/extensions/geproto.h>
-# include "extinit.h"
-# include "exglobals.h"
-# include "eventstr.h"
-
-#ifdef DPMSExtension
-# include "dpmsproc.h"
-# include <X11/extensions/dpmsconst.h>
-#endif
-
-#define QUEUE_SIZE 512
-
-#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
-#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen
-
-typedef struct _Event {
- EventListPtr events;
- ScreenPtr pScreen;
- DeviceIntPtr pDev; /* device this event _originated_ from */
-} EventRec, *EventPtr;
-
-typedef struct _EventQueue {
- HWEventQueueType head, tail; /* long for SetInputCheck */
- CARD32 lastEventTime; /* to avoid time running backwards */
- int lastMotion; /* device ID if last event motion? */
- EventRec events[QUEUE_SIZE]; /* static allocation for signals */
- mieqHandler handlers[128]; /* custom event handler */
-} EventQueueRec, *EventQueuePtr;
-
-static EventQueueRec miEventQueue;
-
-#ifdef XQUARTZ
-#include <pthread.h>
-static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
-
-extern BOOL serverInitComplete;
-extern pthread_mutex_t serverInitCompleteMutex;
-extern pthread_cond_t serverInitCompleteCond;
-
-static inline void wait_for_server_init(void) {
- /* If the server hasn't finished initializing, wait for it... */
- if(!serverInitComplete) {
- pthread_mutex_lock(&serverInitCompleteMutex);
- while(!serverInitComplete)
- pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
- pthread_mutex_unlock(&serverInitCompleteMutex);
- }
-}
-#endif
-
-Bool
-mieqInit(void)
-{
- int i;
-
- miEventQueue.head = miEventQueue.tail = 0;
- miEventQueue.lastEventTime = GetTimeInMillis ();
- miEventQueue.lastMotion = FALSE;
- for (i = 0; i < 128; i++)
- miEventQueue.handlers[i] = NULL;
- for (i = 0; i < QUEUE_SIZE; i++)
- {
- if (miEventQueue.events[i].events == NULL) {
- EventListPtr evlist = InitEventList(1);
- if (!evlist)
- FatalError("Could not allocate event queue.\n");
- miEventQueue.events[i].events = evlist;
- }
- }
-
- SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
- return TRUE;
-}
-
-void
-mieqFini(void)
-{
- int i;
- for (i = 0; i < QUEUE_SIZE; i++)
- {
- if (miEventQueue.events[i].events != NULL) {
- FreeEventList(miEventQueue.events[i].events, 1);
- miEventQueue.events[i].events = NULL;
- }
- }
-}
-
-/*
- * Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue
- * will never be interrupted. If this is called from both signal
- * handlers and regular code, make sure the signal is suspended when
- * called from regular code.
- */
-
-void
-mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
-{
- unsigned int oldtail = miEventQueue.tail;
- EventListPtr evt;
- int isMotion = 0;
- int evlen;
- Time time;
-
-#ifdef XQUARTZ
- wait_for_server_init();
- pthread_mutex_lock(&miEventQueueMutex);
-#endif
-
- CHECKEVENT(e);
-
- /* avoid merging events from different devices */
- if (e->any.type == ET_Motion)
- isMotion = pDev->id;
-
- if (isMotion && isMotion == miEventQueue.lastMotion &&
- oldtail != miEventQueue.head) {
- oldtail = (oldtail - 1) % QUEUE_SIZE;
- }
- else {
- static int stuck = 0;
- /* Toss events which come in late. Usually this means your server's
- * stuck in an infinite loop somewhere, but SIGIO is still getting
- * handled. */
- if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
- if (!stuck) {
- ErrorF("[mi] EQ overflowing. The server is probably stuck "
- "in an infinite loop.\n");
- xorg_backtrace();
- stuck = 1;
- }
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
- return;
- }
- stuck = 0;
- }
-
- evlen = e->any.length;
- evt = miEventQueue.events[oldtail].events;
- if (evt->evlen < evlen)
- {
- evt->evlen = evlen;
- evt->event = xrealloc(evt->event, evt->evlen);
- if (!evt->event)
- {
- ErrorF("[mi] Running out of memory. Tossing event.\n");
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
- return;
- }
- }
-
- memcpy(evt->event, e, evlen);
-
- time = e->any.time;
- /* Make sure that event times don't go backwards - this
- * is "unnecessary", but very useful. */
- if (time < miEventQueue.lastEventTime &&
- miEventQueue.lastEventTime - time < 10000)
- e->any.time = miEventQueue.lastEventTime;
-
- miEventQueue.lastEventTime = ((InternalEvent*)evt->event)->any.time;
- miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL;
- miEventQueue.events[oldtail].pDev = pDev;
-
- miEventQueue.lastMotion = isMotion;
- miEventQueue.tail = (oldtail + 1) % QUEUE_SIZE;
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
-}
-
-void
-mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
-{
-#ifdef XQUARTZ
- pthread_mutex_lock(&miEventQueueMutex);
-#endif
- EnqueueScreen(pDev) = pScreen;
- if (fromDIX)
- DequeueScreen(pDev) = pScreen;
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
-}
-
-void
-mieqSetHandler(int event, mieqHandler handler)
-{
-#ifdef XQUARTZ
- pthread_mutex_lock(&miEventQueueMutex);
-#endif
- if (handler && miEventQueue.handlers[event])
- ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for "
- "event %d\n", miEventQueue.handlers[event], handler, event);
-
- miEventQueue.handlers[event] = handler;
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
-}
-
-/**
- * Change the device id of the given event to the given device's id.
- */
-static void
-ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
-{
- switch(event->any.type)
- {
- case ET_Motion:
- case ET_KeyPress:
- case ET_KeyRelease:
- case ET_ButtonPress:
- case ET_ButtonRelease:
- case ET_ProximityIn:
- case ET_ProximityOut:
- case ET_Hierarchy:
- case ET_DeviceChanged:
- event->device_event.deviceid = dev->id;
- break;
-#if XFreeXDGA
- case ET_DGAEvent:
- break;
-#endif
- case ET_RawKeyPress:
- case ET_RawKeyRelease:
- case ET_RawButtonPress:
- case ET_RawButtonRelease:
- case ET_RawMotion:
- event->raw_event.deviceid = dev->id;
- break;
- default:
- ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
- event->any.type);
- }
-}
-
-static void
-FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
- InternalEvent* original, InternalEvent *master)
-{
- CHECKEVENT(original);
- CHECKEVENT(master);
- /* Ensure chained button mappings, i.e. that the detail field is the
- * value of the mapped button on the SD, not the physical button */
- if (original->any.type == ET_ButtonPress ||
- original->any.type == ET_ButtonRelease)
- {
- int btn = original->device_event.detail.button;
- if (!sdev->button)
- return; /* Should never happen */
-
- master->device_event.detail.button = sdev->button->map[btn];
- }
-}
-
-/**
- * Copy the given event into master.
- * @param sdev The slave device the original event comes from
- * @param original The event as it came from the EQ
- * @param copy The event after being copied
- * @return The master device or NULL if the device is a floating slave.
- */
-DeviceIntPtr
-CopyGetMasterEvent(DeviceIntPtr sdev,
- InternalEvent* original, InternalEvent *copy)
-{
- DeviceIntPtr mdev;
- int len = original->any.length;
-
- CHECKEVENT(original);
-
- /* ET_XQuartz has sdev == NULL */
- if (!sdev || !sdev->u.master)
- return NULL;
-
- switch(original->any.type)
- {
- case ET_KeyPress:
- case ET_KeyRelease:
- mdev = GetMaster(sdev, MASTER_KEYBOARD);
- break;
- case ET_ButtonPress:
- case ET_ButtonRelease:
- case ET_Motion:
- case ET_ProximityIn:
- case ET_ProximityOut:
- mdev = GetMaster(sdev, MASTER_POINTER);
- break;
- default:
- mdev = sdev->u.master;
- break;
- }
-
- memcpy(copy, original, len);
- ChangeDeviceID(mdev, copy);
- FixUpEventForMaster(mdev, sdev, original, copy);
-
- return mdev;
-}
-
-
-/**
- * Post the given @event through the device hierarchy, as appropriate.
- * Use this function if an event must be posted for a given device during the
- * usual event processing cycle.
- */
-void
-mieqProcessDeviceEvent(DeviceIntPtr dev,
- InternalEvent *event,
- ScreenPtr screen)
-{
- mieqHandler handler;
- int x = 0, y = 0;
- DeviceIntPtr master;
- InternalEvent mevent; /* master event */
-
- CHECKEVENT(event);
-
- /* Custom event handler */
- handler = miEventQueue.handlers[event->any.type];
-
- switch (event->any.type) {
- /* Catch events that include valuator information and check if they
- * are changing the screen */
- case ET_Motion:
- case ET_KeyPress:
- case ET_KeyRelease:
- case ET_ButtonPress:
- case ET_ButtonRelease:
- if (dev && screen && screen != DequeueScreen(dev) && !handler) {
- DequeueScreen(dev) = screen;
- x = event->device_event.root_x;
- y = event->device_event.root_y;
- NewCurrentScreen (dev, DequeueScreen(dev), x, y);
- }
- break;
- default:
- break;
- }
- master = CopyGetMasterEvent(dev, event, &mevent);
-
- if (master)
- master->u.lastSlave = dev;
-
- /* If someone's registered a custom event handler, let them
- * steal it. */
- if (handler)
- {
- int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
- handler(screenNum, event, dev);
- /* Check for the SD's master in case the device got detached
- * during event processing */
- if (master && dev->u.master)
- handler(screenNum, &mevent, master);
- } else
- {
- /* process slave first, then master */
- dev->public.processInputProc(event, dev);
-
- /* Check for the SD's master in case the device got detached
- * during event processing */
- if (master && dev->u.master)
- master->public.processInputProc(&mevent, master);
- }
-}
-
-/* Call this from ProcessInputEvents(). */
-void
-mieqProcessInputEvents(void)
-{
- EventRec *e = NULL;
- int evlen;
- ScreenPtr screen;
- static InternalEvent *event = NULL;
- static size_t event_size = 0;
- DeviceIntPtr dev = NULL,
- master = NULL;
-
-#ifdef XQUARTZ
- pthread_mutex_lock(&miEventQueueMutex);
-#endif
-
- while (miEventQueue.head != miEventQueue.tail) {
- e = &miEventQueue.events[miEventQueue.head];
-
- evlen = e->events->evlen;
- if(evlen > event_size)
- {
- event_size=evlen;
- event = xrealloc(event, evlen);
- if (!event)
- FatalError("[mi] No memory left for event processing.\n");
- }
-
-
- memcpy(event, e->events->event, evlen);
-
-
- dev = e->pDev;
- screen = e->pScreen;
-
- miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE;
-
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
-
- master = (dev && !IsMaster(dev) && dev->u.master) ? dev->u.master : NULL;
-
- if (screenIsSaved == SCREEN_SAVER_ON)
- dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
-#ifdef DPMSExtension
- else if (DPMSPowerLevel != DPMSModeOn)
- SetScreenSaverTimer();
-
- if (DPMSPowerLevel != DPMSModeOn)
- DPMSSet(serverClient, DPMSModeOn);
-#endif
-
- mieqProcessDeviceEvent(dev, event, screen);
-
- /* Update the sprite now. Next event may be from different device. */
- if (event->any.type == ET_Motion && master)
- miPointerUpdateSprite(dev);
-
-#ifdef XQUARTZ
- pthread_mutex_lock(&miEventQueueMutex);
-#endif
- }
-#ifdef XQUARTZ
- pthread_mutex_unlock(&miEventQueueMutex);
-#endif
-}
-
+/*
+ *
+Copyright 1990, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Keith Packard, MIT X Consortium
+ */
+
+/*
+ * mieq.c
+ *
+ * Machine independent event queue
+ *
+ */
+
+#if HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+# include <X11/X.h>
+# include <X11/Xmd.h>
+# include <X11/Xproto.h>
+# include "misc.h"
+# include "windowstr.h"
+# include "pixmapstr.h"
+# include "inputstr.h"
+# include "mi.h"
+# include "mipointer.h"
+# include "scrnintstr.h"
+# include <X11/extensions/XI.h>
+# include <X11/extensions/XIproto.h>
+# include <X11/extensions/geproto.h>
+# include "extinit.h"
+# include "exglobals.h"
+# include "eventstr.h"
+
+#ifdef DPMSExtension
+# include "dpmsproc.h"
+# include <X11/extensions/dpmsconst.h>
+#endif
+
+#define QUEUE_SIZE 512
+
+#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
+#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen
+
+typedef struct _Event {
+ EventListPtr events;
+ ScreenPtr pScreen;
+ DeviceIntPtr pDev; /* device this event _originated_ from */
+} EventRec, *EventPtr;
+
+typedef struct _EventQueue {
+ HWEventQueueType head, tail; /* long for SetInputCheck */
+ CARD32 lastEventTime; /* to avoid time running backwards */
+ int lastMotion; /* device ID if last event motion? */
+ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
+ mieqHandler handlers[128]; /* custom event handler */
+} EventQueueRec, *EventQueuePtr;
+
+static EventQueueRec miEventQueue;
+
+#ifdef XQUARTZ
+#include <pthread.h>
+static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
+
+extern BOOL serverInitComplete;
+extern pthread_mutex_t serverInitCompleteMutex;
+extern pthread_cond_t serverInitCompleteCond;
+
+static inline void wait_for_server_init(void) {
+ /* If the server hasn't finished initializing, wait for it... */
+ if(!serverInitComplete) {
+ pthread_mutex_lock(&serverInitCompleteMutex);
+ while(!serverInitComplete)
+ pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
+ pthread_mutex_unlock(&serverInitCompleteMutex);
+ }
+}
+#endif
+
+Bool
+mieqInit(void)
+{
+ int i;
+
+ miEventQueue.head = miEventQueue.tail = 0;
+ miEventQueue.lastEventTime = GetTimeInMillis ();
+ miEventQueue.lastMotion = FALSE;
+ for (i = 0; i < 128; i++)
+ miEventQueue.handlers[i] = NULL;
+ for (i = 0; i < QUEUE_SIZE; i++)
+ {
+ if (miEventQueue.events[i].events == NULL) {
+ EventListPtr evlist = InitEventList(1);
+ if (!evlist)
+ FatalError("Could not allocate event queue.\n");
+ miEventQueue.events[i].events = evlist;
+ }
+ }
+
+ SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
+ return TRUE;
+}
+
+void
+mieqFini(void)
+{
+ int i;
+ for (i = 0; i < QUEUE_SIZE; i++)
+ {
+ if (miEventQueue.events[i].events != NULL) {
+ FreeEventList(miEventQueue.events[i].events, 1);
+ miEventQueue.events[i].events = NULL;
+ }
+ }
+}
+
+/*
+ * Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue
+ * will never be interrupted. If this is called from both signal
+ * handlers and regular code, make sure the signal is suspended when
+ * called from regular code.
+ */
+
+void
+mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
+{
+ unsigned int oldtail = miEventQueue.tail;
+ EventListPtr evt;
+ int isMotion = 0;
+ int evlen;
+ Time time;
+
+#ifdef XQUARTZ
+ wait_for_server_init();
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+
+ CHECKEVENT(e);
+
+ /* avoid merging events from different devices */
+ if (e->any.type == ET_Motion)
+ isMotion = pDev->id;
+
+ if (isMotion && isMotion == miEventQueue.lastMotion &&
+ oldtail != miEventQueue.head) {
+ oldtail = (oldtail - 1) % QUEUE_SIZE;
+ }
+ else {
+ static int stuck = 0;
+ /* Toss events which come in late. Usually this means your server's
+ * stuck in an infinite loop somewhere, but SIGIO is still getting
+ * handled. */
+ if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
+ if (!stuck) {
+ ErrorF("[mi] EQ overflowing. The server is probably stuck "
+ "in an infinite loop.\n");
+ xorg_backtrace();
+ stuck = 1;
+ }
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+ return;
+ }
+ stuck = 0;
+ }
+
+ evlen = e->any.length;
+ evt = miEventQueue.events[oldtail].events;
+ if (evt->evlen < evlen)
+ {
+ evt->evlen = evlen;
+ evt->event = xrealloc(evt->event, evt->evlen);
+ if (!evt->event)
+ {
+ ErrorF("[mi] Running out of memory. Tossing event.\n");
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+ return;
+ }
+ }
+
+ memcpy(evt->event, e, evlen);
+
+ time = e->any.time;
+ /* Make sure that event times don't go backwards - this
+ * is "unnecessary", but very useful. */
+ if (time < miEventQueue.lastEventTime &&
+ miEventQueue.lastEventTime - time < 10000)
+ e->any.time = miEventQueue.lastEventTime;
+
+ miEventQueue.lastEventTime = ((InternalEvent*)evt->event)->any.time;
+ miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL;
+ miEventQueue.events[oldtail].pDev = pDev;
+
+ miEventQueue.lastMotion = isMotion;
+ miEventQueue.tail = (oldtail + 1) % QUEUE_SIZE;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+void
+mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
+{
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ EnqueueScreen(pDev) = pScreen;
+ if (fromDIX)
+ DequeueScreen(pDev) = pScreen;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+void
+mieqSetHandler(int event, mieqHandler handler)
+{
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ if (handler && miEventQueue.handlers[event])
+ ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for "
+ "event %d\n", miEventQueue.handlers[event], handler, event);
+
+ miEventQueue.handlers[event] = handler;
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
+/**
+ * Change the device id of the given event to the given device's id.
+ */
+static void
+ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
+{
+ switch(event->any.type)
+ {
+ case ET_Motion:
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ case ET_ProximityIn:
+ case ET_ProximityOut:
+ case ET_Hierarchy:
+ case ET_DeviceChanged:
+ event->device_event.deviceid = dev->id;
+ break;
+#if XFreeXDGA
+ case ET_DGAEvent:
+ break;
+#endif
+ case ET_RawKeyPress:
+ case ET_RawKeyRelease:
+ case ET_RawButtonPress:
+ case ET_RawButtonRelease:
+ case ET_RawMotion:
+ event->raw_event.deviceid = dev->id;
+ break;
+ default:
+ ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
+ event->any.type);
+ }
+}
+
+static void
+FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
+ InternalEvent* original, InternalEvent *master)
+{
+ CHECKEVENT(original);
+ CHECKEVENT(master);
+ /* Ensure chained button mappings, i.e. that the detail field is the
+ * value of the mapped button on the SD, not the physical button */
+ if (original->any.type == ET_ButtonPress ||
+ original->any.type == ET_ButtonRelease)
+ {
+ int btn = original->device_event.detail.button;
+ if (!sdev->button)
+ return; /* Should never happen */
+
+ master->device_event.detail.button = sdev->button->map[btn];
+ }
+}
+
+/**
+ * Copy the given event into master.
+ * @param sdev The slave device the original event comes from
+ * @param original The event as it came from the EQ
+ * @param copy The event after being copied
+ * @return The master device or NULL if the device is a floating slave.
+ */
+DeviceIntPtr
+CopyGetMasterEvent(DeviceIntPtr sdev,
+ InternalEvent* original, InternalEvent *copy)
+{
+ DeviceIntPtr mdev;
+ int len = original->any.length;
+
+ CHECKEVENT(original);
+
+ /* ET_XQuartz has sdev == NULL */
+ if (!sdev || !sdev->u.master)
+ return NULL;
+
+ switch(original->any.type)
+ {
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ mdev = GetMaster(sdev, MASTER_KEYBOARD);
+ break;
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ case ET_Motion:
+ case ET_ProximityIn:
+ case ET_ProximityOut:
+ mdev = GetMaster(sdev, MASTER_POINTER);
+ break;
+ default:
+ mdev = sdev->u.master;
+ break;
+ }
+
+ memcpy(copy, original, len);
+ ChangeDeviceID(mdev, copy);
+ FixUpEventForMaster(mdev, sdev, original, copy);
+
+ return mdev;
+}
+
+
+/**
+ * Post the given @event through the device hierarchy, as appropriate.
+ * Use this function if an event must be posted for a given device during the
+ * usual event processing cycle.
+ */
+void
+mieqProcessDeviceEvent(DeviceIntPtr dev,
+ InternalEvent *event,
+ ScreenPtr screen)
+{
+ mieqHandler handler;
+ int x = 0, y = 0;
+ DeviceIntPtr master;
+ InternalEvent mevent; /* master event */
+
+ CHECKEVENT(event);
+
+ /* Custom event handler */
+ handler = miEventQueue.handlers[event->any.type];
+
+ switch (event->any.type) {
+ /* Catch events that include valuator information and check if they
+ * are changing the screen */
+ case ET_Motion:
+ case ET_KeyPress:
+ case ET_KeyRelease:
+ case ET_ButtonPress:
+ case ET_ButtonRelease:
+ if (dev && screen && screen != DequeueScreen(dev) && !handler) {
+ DequeueScreen(dev) = screen;
+ x = event->device_event.root_x;
+ y = event->device_event.root_y;
+ NewCurrentScreen (dev, DequeueScreen(dev), x, y);
+ }
+ break;
+ default:
+ break;
+ }
+ master = CopyGetMasterEvent(dev, event, &mevent);
+
+ if (master)
+ master->u.lastSlave = dev;
+
+ /* If someone's registered a custom event handler, let them
+ * steal it. */
+ if (handler)
+ {
+ int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
+ handler(screenNum, event, dev);
+ /* Check for the SD's master in case the device got detached
+ * during event processing */
+ if (master && dev->u.master)
+ handler(screenNum, &mevent, master);
+ } else
+ {
+ /* process slave first, then master */
+ dev->public.processInputProc(event, dev);
+
+ /* Check for the SD's master in case the device got detached
+ * during event processing */
+ if (master && dev->u.master)
+ master->public.processInputProc(&mevent, master);
+ }
+}
+
+/* Call this from ProcessInputEvents(). */
+void
+mieqProcessInputEvents(void)
+{
+ EventRec *e = NULL;
+ int evlen;
+ ScreenPtr screen;
+ static InternalEvent *event = NULL;
+ static size_t event_size = 0;
+ DeviceIntPtr dev = NULL,
+ master = NULL;
+
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+
+ while (miEventQueue.head != miEventQueue.tail) {
+ e = &miEventQueue.events[miEventQueue.head];
+
+ evlen = e->events->evlen;
+ if(evlen > event_size)
+ {
+ event = xrealloc(event, evlen);
+ event_size=evlen;
+
+ if (!event)
+ FatalError("[mi] No memory left for event processing.\n");
+ }
+
+
+ memcpy(event, e->events->event, evlen);
+
+
+ dev = e->pDev;
+ screen = e->pScreen;
+
+ miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE;
+
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+
+ master = (dev && !IsMaster(dev) && dev->u.master) ? dev->u.master : NULL;
+
+ if (screenIsSaved == SCREEN_SAVER_ON)
+ dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+#ifdef DPMSExtension
+ else if (DPMSPowerLevel != DPMSModeOn)
+ SetScreenSaverTimer();
+
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(serverClient, DPMSModeOn);
+#endif
+
+ mieqProcessDeviceEvent(dev, event, screen);
+
+ /* Update the sprite now. Next event may be from different device. */
+ if (event->any.type == ET_Motion && master)
+ miPointerUpdateSprite(dev);
+
+#ifdef XQUARTZ
+ pthread_mutex_lock(&miEventQueueMutex);
+#endif
+ }
+#ifdef XQUARTZ
+ pthread_mutex_unlock(&miEventQueueMutex);
+#endif
+}
+
diff --git a/xorg-server/os/osdep.h b/xorg-server/os/osdep.h
index 3d75bbaab..fda1edf72 100644
--- a/xorg-server/os/osdep.h
+++ b/xorg-server/os/osdep.h
@@ -1,282 +1,282 @@
-/***********************************************************
-
-Copyright 1987, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef _OSDEP_H_
-#define _OSDEP_H_ 1
-
-#define BOTIMEOUT 200 /* in milliseconds */
-#define BUFSIZE 4096
-#define BUFWATERMARK 8192
-
-#if defined(XDMCP) || defined(HASXDMAUTH)
-#include <X11/Xdmcp.h>
-#endif
-
-#ifdef _POSIX_SOURCE
-#include <limits.h>
-#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-
-#ifndef OPEN_MAX
-#ifdef SVR4
-#define OPEN_MAX 256
-#else
-#include <sys/param.h>
-#ifndef OPEN_MAX
-#if defined(NOFILE) && !defined(NOFILES_MAX)
-#define OPEN_MAX NOFILE
-#else
-#if !defined(WIN32)
-#define OPEN_MAX NOFILES_MAX
-#else
-#define OPEN_MAX 256
-#endif
-#endif
-#endif
-#endif
-#endif
-
-#include <X11/Xpoll.h>
-
-/*
- * MAXSOCKS is used only for initialising MaxClients when no other method
- * like sysconf(_SC_OPEN_MAX) is not supported.
- */
-
-#if OPEN_MAX <= 256
-#define MAXSOCKS (OPEN_MAX - 1)
-#else
-#define MAXSOCKS 256
-#endif
-
-/* MAXSELECT is the number of fds that select() can handle */
-#define MAXSELECT (sizeof(fd_set) * NBBY)
-
-#ifndef HAS_GETDTABLESIZE
-#if !defined(SVR4) && !defined(SYSV)
-#define HAS_GETDTABLESIZE
-#endif
-#endif
-
-#include <stddef.h>
-
-#if defined(XDMCP) || defined(HASXDMAUTH)
-typedef Bool (*ValidatorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
-typedef Bool (*GeneratorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
-typedef Bool (*AddAuthorFunc)(unsigned name_length, char *name, unsigned data_length, char *data);
-#endif
-
-typedef struct _connectionInput {
- struct _connectionInput *next;
- char *buffer; /* contains current client input */
- char *bufptr; /* pointer to current start of data */
- int bufcnt; /* count of bytes in buffer */
- int lenLastReq;
- int size;
-} ConnectionInput, *ConnectionInputPtr;
-
-typedef struct _connectionOutput {
- struct _connectionOutput *next;
- int size;
- unsigned char *buf;
- int count;
-} ConnectionOutput, *ConnectionOutputPtr;
-
-struct _osComm;
-
-#define AuthInitArgs void
-typedef void (*AuthInitFunc) (AuthInitArgs);
-
-#define AuthAddCArgs unsigned short data_length, char *data, XID id
-typedef int (*AuthAddCFunc) (AuthAddCArgs);
-
-#define AuthCheckArgs unsigned short data_length, char *data, ClientPtr client, char **reason
-typedef XID (*AuthCheckFunc) (AuthCheckArgs);
-
-#define AuthFromIDArgs XID id, unsigned short *data_lenp, char **datap
-typedef int (*AuthFromIDFunc) (AuthFromIDArgs);
-
-#define AuthGenCArgs unsigned data_length, char *data, XID id, unsigned *data_length_return, char **data_return
-typedef XID (*AuthGenCFunc) (AuthGenCArgs);
-
-#define AuthRemCArgs unsigned short data_length, char *data
-typedef int (*AuthRemCFunc) (AuthRemCArgs);
-
-#define AuthRstCArgs void
-typedef int (*AuthRstCFunc) (AuthRstCArgs);
-
-#define AuthToIDArgs unsigned short data_length, char *data
-typedef XID (*AuthToIDFunc) (AuthToIDArgs);
-
-typedef void (*OsCloseFunc)(ClientPtr);
-
-typedef int (*OsFlushFunc)(ClientPtr who, struct _osComm * oc, char* extraBuf, int extraCount);
-
-typedef struct _osComm {
- int fd;
- ConnectionInputPtr input;
- ConnectionOutputPtr output;
- XID auth_id; /* authorization id */
- CARD32 conn_time; /* timestamp if not established, else 0 */
- struct _XtransConnInfo *trans_conn; /* transport connection object */
-} OsCommRec, *OsCommPtr;
-
-extern int FlushClient(
- ClientPtr /*who*/,
- OsCommPtr /*oc*/,
- const void * /*extraBuf*/,
- int /*extraCount*/
-);
-
-extern void FreeOsBuffers(
- OsCommPtr /*oc*/
-);
-
-#include "dix.h"
-
-extern fd_set AllSockets;
-extern fd_set AllClients;
-extern fd_set LastSelectMask;
-extern fd_set WellKnownConnections;
-extern fd_set EnabledDevices;
-extern fd_set ClientsWithInput;
-extern fd_set ClientsWriteBlocked;
-extern fd_set OutputPending;
-extern fd_set IgnoredClientsWithInput;
-
-#ifndef WIN32
-extern int *ConnectionTranslation;
-#else
-extern int GetConnectionTranslation(int conn);
-extern void SetConnectionTranslation(int conn, int client);
-extern void ClearConnectionTranslation();
-#endif
-
-extern Bool NewOutputPending;
-extern Bool AnyClientsWriteBlocked;
-
-extern WorkQueuePtr workQueue;
-
-/* in WaitFor.c */
-#ifdef WIN32
-typedef long int fd_mask;
-#endif
-#define ffs mffs
-extern int mffs(fd_mask);
-
-/* in auth.c */
-extern void GenerateRandomData (int len, char *buf);
-
-/* in mitauth.c */
-extern XID MitCheckCookie (AuthCheckArgs);
-extern XID MitGenerateCookie (AuthGenCArgs);
-extern XID MitToID (AuthToIDArgs);
-extern int MitAddCookie (AuthAddCArgs);
-extern int MitFromID (AuthFromIDArgs);
-extern int MitRemoveCookie (AuthRemCArgs);
-extern int MitResetCookie (AuthRstCArgs);
-
-/* in xdmauth.c */
-#ifdef HASXDMAUTH
-extern XID XdmCheckCookie (AuthCheckArgs);
-extern XID XdmToID (AuthToIDArgs);
-extern int XdmAddCookie (AuthAddCArgs);
-extern int XdmFromID (AuthFromIDArgs);
-extern int XdmRemoveCookie (AuthRemCArgs);
-extern int XdmResetCookie (AuthRstCArgs);
-#endif
-
-/* in rpcauth.c */
-#ifdef SECURE_RPC
-extern void SecureRPCInit (AuthInitArgs);
-extern XID SecureRPCCheck (AuthCheckArgs);
-extern XID SecureRPCToID (AuthToIDArgs);
-extern int SecureRPCAdd (AuthAddCArgs);
-extern int SecureRPCFromID (AuthFromIDArgs);
-extern int SecureRPCRemove (AuthRemCArgs);
-extern int SecureRPCReset (AuthRstCArgs);
-#endif
-
-#ifdef XDMCP
-/* in xdmcp.c */
-extern void XdmcpUseMsg (void);
-extern int XdmcpOptions(int argc, char **argv, int i);
-extern void XdmcpRegisterConnection (
- int type,
- char *address,
- int addrlen);
-extern void XdmcpRegisterAuthorizations (void);
-extern void XdmcpRegisterAuthorization (char *name, int namelen);
-extern void XdmcpInit (void);
-extern void XdmcpReset (void);
-extern void XdmcpOpenDisplay(int sock);
-extern void XdmcpCloseDisplay(int sock);
-extern void XdmcpRegisterAuthentication (
- char *name,
- int namelen,
- char *data,
- int datalen,
- ValidatorFunc Validator,
- GeneratorFunc Generator,
- AddAuthorFunc AddAuth);
-
-struct sockaddr_in;
-extern void XdmcpRegisterBroadcastAddress (struct sockaddr_in *addr);
-#endif
-
-#ifdef HASXDMAUTH
-extern void XdmAuthenticationInit (char *cookie, int cookie_length);
-#endif
-
-#endif /* _OSDEP_H_ */
+/***********************************************************
+
+Copyright 1987, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _OSDEP_H_
+#define _OSDEP_H_ 1
+
+#define BOTIMEOUT 200 /* in milliseconds */
+#define BUFSIZE 4096
+#define BUFWATERMARK 8192
+
+#if defined(XDMCP) || defined(HASXDMAUTH)
+#include <X11/Xdmcp.h>
+#endif
+
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+
+#ifndef OPEN_MAX
+#ifdef SVR4
+#define OPEN_MAX 256
+#else
+#include <sys/param.h>
+#ifndef OPEN_MAX
+#if defined(NOFILE) && !defined(NOFILES_MAX)
+#define OPEN_MAX NOFILE
+#else
+#if !defined(WIN32)
+#define OPEN_MAX NOFILES_MAX
+#else
+#define OPEN_MAX 256
+#endif
+#endif
+#endif
+#endif
+#endif
+
+#include <X11/Xpoll.h>
+
+/*
+ * MAXSOCKS is used only for initialising MaxClients when no other method
+ * like sysconf(_SC_OPEN_MAX) is not supported.
+ */
+
+#if OPEN_MAX <= 256
+#define MAXSOCKS (OPEN_MAX - 1)
+#else
+#define MAXSOCKS 256
+#endif
+
+/* MAXSELECT is the number of fds that select() can handle */
+#define MAXSELECT (sizeof(fd_set) * NBBY)
+
+#ifndef HAS_GETDTABLESIZE
+#if !defined(SVR4) && !defined(SYSV)
+#define HAS_GETDTABLESIZE
+#endif
+#endif
+
+#include <stddef.h>
+
+#if defined(XDMCP) || defined(HASXDMAUTH)
+typedef Bool (*ValidatorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
+typedef Bool (*GeneratorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
+typedef Bool (*AddAuthorFunc)(unsigned name_length, char *name, unsigned data_length, char *data);
+#endif
+
+typedef struct _connectionInput {
+ struct _connectionInput *next;
+ char *buffer; /* contains current client input */
+ char *bufptr; /* pointer to current start of data */
+ int bufcnt; /* count of bytes in buffer */
+ int lenLastReq;
+ int size;
+} ConnectionInput, *ConnectionInputPtr;
+
+typedef struct _connectionOutput {
+ struct _connectionOutput *next;
+ int size;
+ unsigned char *buf;
+ int count;
+} ConnectionOutput, *ConnectionOutputPtr;
+
+struct _osComm;
+
+#define AuthInitArgs void
+typedef void (*AuthInitFunc) (AuthInitArgs);
+
+#define AuthAddCArgs unsigned short data_length, char *data, XID id
+typedef int (*AuthAddCFunc) (AuthAddCArgs);
+
+#define AuthCheckArgs unsigned short data_length, char *data, ClientPtr client, char **reason
+typedef XID (*AuthCheckFunc) (AuthCheckArgs);
+
+#define AuthFromIDArgs XID id, unsigned short *data_lenp, char **datap
+typedef int (*AuthFromIDFunc) (AuthFromIDArgs);
+
+#define AuthGenCArgs unsigned data_length, char *data, XID id, unsigned *data_length_return, char **data_return
+typedef XID (*AuthGenCFunc) (AuthGenCArgs);
+
+#define AuthRemCArgs unsigned short data_length, char *data
+typedef int (*AuthRemCFunc) (AuthRemCArgs);
+
+#define AuthRstCArgs void
+typedef int (*AuthRstCFunc) (AuthRstCArgs);
+
+#define AuthToIDArgs unsigned short data_length, char *data
+typedef XID (*AuthToIDFunc) (AuthToIDArgs);
+
+typedef void (*OsCloseFunc)(ClientPtr);
+
+typedef int (*OsFlushFunc)(ClientPtr who, struct _osComm * oc, char* extraBuf, int extraCount);
+
+typedef struct _osComm {
+ int fd;
+ ConnectionInputPtr input;
+ ConnectionOutputPtr output;
+ XID auth_id; /* authorization id */
+ CARD32 conn_time; /* timestamp if not established, else 0 */
+ struct _XtransConnInfo *trans_conn; /* transport connection object */
+} OsCommRec, *OsCommPtr;
+
+extern int FlushClient(
+ ClientPtr /*who*/,
+ OsCommPtr /*oc*/,
+ const void * /*extraBuf*/,
+ int /*extraCount*/
+);
+
+extern void FreeOsBuffers(
+ OsCommPtr /*oc*/
+);
+
+#include "dix.h"
+
+extern fd_set AllSockets;
+extern fd_set AllClients;
+extern fd_set LastSelectMask;
+extern fd_set WellKnownConnections;
+extern fd_set EnabledDevices;
+extern fd_set ClientsWithInput;
+extern fd_set ClientsWriteBlocked;
+extern fd_set OutputPending;
+extern fd_set IgnoredClientsWithInput;
+
+#ifndef WIN32
+extern int *ConnectionTranslation;
+#else
+extern int GetConnectionTranslation(int conn);
+extern void SetConnectionTranslation(int conn, int client);
+extern void ClearConnectionTranslation(void);
+#endif
+
+extern Bool NewOutputPending;
+extern Bool AnyClientsWriteBlocked;
+
+extern WorkQueuePtr workQueue;
+
+/* in WaitFor.c */
+#ifdef WIN32
+typedef long int fd_mask;
+#endif
+#define ffs mffs
+extern int mffs(fd_mask);
+
+/* in auth.c */
+extern void GenerateRandomData (int len, char *buf);
+
+/* in mitauth.c */
+extern XID MitCheckCookie (AuthCheckArgs);
+extern XID MitGenerateCookie (AuthGenCArgs);
+extern XID MitToID (AuthToIDArgs);
+extern int MitAddCookie (AuthAddCArgs);
+extern int MitFromID (AuthFromIDArgs);
+extern int MitRemoveCookie (AuthRemCArgs);
+extern int MitResetCookie (AuthRstCArgs);
+
+/* in xdmauth.c */
+#ifdef HASXDMAUTH
+extern XID XdmCheckCookie (AuthCheckArgs);
+extern XID XdmToID (AuthToIDArgs);
+extern int XdmAddCookie (AuthAddCArgs);
+extern int XdmFromID (AuthFromIDArgs);
+extern int XdmRemoveCookie (AuthRemCArgs);
+extern int XdmResetCookie (AuthRstCArgs);
+#endif
+
+/* in rpcauth.c */
+#ifdef SECURE_RPC
+extern void SecureRPCInit (AuthInitArgs);
+extern XID SecureRPCCheck (AuthCheckArgs);
+extern XID SecureRPCToID (AuthToIDArgs);
+extern int SecureRPCAdd (AuthAddCArgs);
+extern int SecureRPCFromID (AuthFromIDArgs);
+extern int SecureRPCRemove (AuthRemCArgs);
+extern int SecureRPCReset (AuthRstCArgs);
+#endif
+
+#ifdef XDMCP
+/* in xdmcp.c */
+extern void XdmcpUseMsg (void);
+extern int XdmcpOptions(int argc, char **argv, int i);
+extern void XdmcpRegisterConnection (
+ int type,
+ char *address,
+ int addrlen);
+extern void XdmcpRegisterAuthorizations (void);
+extern void XdmcpRegisterAuthorization (char *name, int namelen);
+extern void XdmcpInit (void);
+extern void XdmcpReset (void);
+extern void XdmcpOpenDisplay(int sock);
+extern void XdmcpCloseDisplay(int sock);
+extern void XdmcpRegisterAuthentication (
+ char *name,
+ int namelen,
+ char *data,
+ int datalen,
+ ValidatorFunc Validator,
+ GeneratorFunc Generator,
+ AddAuthorFunc AddAuth);
+
+struct sockaddr_in;
+extern void XdmcpRegisterBroadcastAddress (struct sockaddr_in *addr);
+#endif
+
+#ifdef HASXDMAUTH
+extern void XdmAuthenticationInit (char *cookie, int cookie_length);
+#endif
+
+#endif /* _OSDEP_H_ */