diff options
Diffstat (limited to 'xorg-server/hw/xwin')
-rw-r--r-- | xorg-server/hw/xwin/InitOutput.c | 2240 | ||||
-rw-r--r-- | xorg-server/hw/xwin/man/XWin.man | 795 | ||||
-rw-r--r-- | xorg-server/hw/xwin/win.h | 1 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winclipboardxevents.c | 2 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winmonitors.c | 146 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winmultiwindowicons.c | 5 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winmultiwindowwindow.c | 3 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winmultiwindowwm.c | 1 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winpfbdd.c | 1349 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winscrinit.c | 1516 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winshaddd.c | 2651 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winshadddnl.c | 2719 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winshadgdi.c | 2475 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winvideo.c | 2 | ||||
-rw-r--r-- | xorg-server/hw/xwin/winwin32rootless.c | 10 |
15 files changed, 6961 insertions, 6954 deletions
diff --git a/xorg-server/hw/xwin/InitOutput.c b/xorg-server/hw/xwin/InitOutput.c index 725011ea5..ae56c51fa 100644 --- a/xorg-server/hw/xwin/InitOutput.c +++ b/xorg-server/hw/xwin/InitOutput.c @@ -1,1120 +1,1120 @@ - -/* - -Copyright 1993, 1998 The Open Group -Copyright (C) Colin Harrison 2005-2008 - -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. - -*/ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "winmsg.h" -#include "winconfig.h" -#include "winprefs.h" -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif -#include <locale.h> -#ifdef __CYGWIN__ -#include <mntent.h> -#endif -#if defined(WIN32) -#include "xkbsrv.h" -#endif -#ifdef RELOCATE_PROJECTROOT -#undef Status -#include <shlobj.h> -typedef HRESULT (__stdcall * SHGETFOLDERPATHPROC)( - HWND hwndOwner, - int nFolder, - HANDLE hToken, - DWORD dwFlags, - LPSTR pszPath -); -#endif - -/* - * References to external symbols - */ -#ifdef XWIN_CLIPBOARD -extern Bool g_fUnicodeClipboard; -extern Bool g_fClipboardLaunched; -extern Bool g_fClipboardStarted; -extern pthread_t g_ptClipboardProc; -extern HWND g_hwndClipboard; -extern Bool g_fClipboard; -#endif - - -/* - module handle for dynamically loaded comctl32 library -*/ -static HMODULE g_hmodCommonControls = NULL; - -/* - * Function prototypes - */ - -#ifdef XWIN_CLIPBOARD -static void -winClipboardShutdown (void); -#endif - -#if defined(DDXOSVERRORF) -void -OsVendorVErrorF (const char *pszFormat, va_list va_args); -#endif - -static Bool -winCheckDisplayNumber (void); - -void -winLogCommandLine (int argc, char *argv[]); - -void -winLogVersionInfo (void); - -Bool -winValidateArgs (void); - -#ifdef RELOCATE_PROJECTROOT -const char * -winGetBaseDir(void); -#endif - -/* - * For the depth 24 pixmap we default to 32 bits per pixel, but - * we change this pixmap format later if we detect that the display - * is going to be running at 24 bits per pixel. - * - * FIXME: On second thought, don't DIBs only support 32 bits per pixel? - * DIBs are the underlying bitmap used for DirectDraw surfaces, so it - * seems that all pixmap formats with depth 24 would be 32 bits per pixel. - * Confirm whether depth 24 DIBs can have 24 bits per pixel, then remove/keep - * the bits per pixel adjustment and update this comment to reflect the - * situation. Harold Hunt - 2002/07/02 - */ - -static PixmapFormatRec g_PixmapFormats[] = { - { 1, 1, BITMAP_SCANLINE_PAD }, - { 4, 8, BITMAP_SCANLINE_PAD }, - { 8, 8, BITMAP_SCANLINE_PAD }, - { 15, 16, BITMAP_SCANLINE_PAD }, - { 16, 16, BITMAP_SCANLINE_PAD }, - { 24, 32, BITMAP_SCANLINE_PAD }, - { 32, 32, BITMAP_SCANLINE_PAD } -}; - -const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]); - -#ifdef XWIN_CLIPBOARD -static void -winClipboardShutdown (void) -{ - /* Close down clipboard resources */ - if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) - { - /* Synchronously destroy the clipboard window */ - if (g_hwndClipboard != NULL) - { - g_fClipboardStarted=FALSE; /* This is to avoid dead-locls caused by the clipboard thread still doing some stuff */ - SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0); - /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */ - } - else - return; - - /* Wait for the clipboard thread to exit */ - pthread_join (g_ptClipboardProc, NULL); - - winDebug ("winClipboardShutdown - Clipboard thread has exited.\n"); - } -} -#endif - - -#if defined(DDXBEFORERESET) -/* - * Called right before KillAllClients when the server is going to reset, - * allows us to shutdown our seperate threads cleanly. - */ - -void -ddxBeforeReset (void) -{ - winDebug ("ddxBeforeReset - Hello\n"); - -#ifdef XWIN_CLIPBOARD - winClipboardShutdown (); -#endif -} -#endif - - -/* See Porting Layer Definition - p. 57 */ -void -ddxGiveUp (void) -{ - int i; - - winDebug ("ddxGiveUp\n"); - - /* Perform per-screen deinitialization */ - for (i = 0; i < g_iNumScreens; ++i) - { - /* Delete the tray icon */ - if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen) - winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen)); - } - -#ifdef XWIN_MULTIWINDOW - /* Notify the worker threads we're exiting */ - winDeinitMultiWindowWM (); -#endif - -#ifdef HAS_DEVWINDOWS - /* Close our handle to our message queue */ - if (g_fdMessageQueue != WIN_FD_INVALID) - { - /* Close /dev/windows */ - close (g_fdMessageQueue); - - /* Set the file handle to invalid */ - g_fdMessageQueue = WIN_FD_INVALID; - } -#endif - - if (!g_fLogInited) { - g_pszLogFile = LogInit (g_pszLogFile, NULL); - g_fLogInited = TRUE; - } - LogClose (); - - /* - * At this point we aren't creating any new screens, so - * we are guaranteed to not need the DirectDraw functions. - */ - winReleaseDDProcAddresses(); - - /* Unload our TrackMouseEvent function pointer */ - if (g_hmodCommonControls != NULL) - { - FreeLibrary (g_hmodCommonControls); - g_hmodCommonControls = NULL; - g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - } - - /* Free concatenated command line */ - free(g_pszCommandLine); - g_pszCommandLine = NULL; - - /* Remove our keyboard hook if it is installed */ - winRemoveKeyboardHookLL (); - - /* Tell Windows that we want to end the app */ - PostQuitMessage (0); -} - - -/* See Porting Layer Definition - p. 57 */ -void -AbortDDX (void) -{ - winDebug ("AbortDDX\n"); - ddxGiveUp (); -} - -#ifdef __CYGWIN__ -/* hasmntopt is currently not implemented for cygwin */ -static const char *winCheckMntOpt(const struct mntent *mnt, const char *opt) -{ - const char *s; - size_t len; - if (mnt == NULL) - return NULL; - if (opt == NULL) - return NULL; - if (mnt->mnt_opts == NULL) - return NULL; - - len = strlen(opt); - s = strstr(mnt->mnt_opts, opt); - if (s == NULL) - return NULL; - if ((s == mnt->mnt_opts || *(s-1) == ',') && (s[len] == 0 || s[len] == ',')) - return (char *)opt; - return NULL; -} - -static void -winCheckMount(void) -{ - FILE *mnt; - struct mntent *ent; - - enum { none = 0, sys_root, user_root, sys_tmp, user_tmp } - level = none, curlevel; - BOOL binary = TRUE; - - mnt = setmntent("/etc/mtab", "r"); - if (mnt == NULL) - { - ErrorF("setmntent failed"); - return; - } - - while ((ent = getmntent(mnt)) != NULL) - { - BOOL system = (winCheckMntOpt(ent, "user") != NULL); - BOOL root = (strcmp(ent->mnt_dir, "/") == 0); - BOOL tmp = (strcmp(ent->mnt_dir, "/tmp") == 0); - - if (system) - { - if (root) - curlevel = sys_root; - else if (tmp) - curlevel = sys_tmp; - else - continue; - } - else - { - if (root) - curlevel = user_root; - else if (tmp) - curlevel = user_tmp; - else - continue; - } - - if (curlevel <= level) - continue; - level = curlevel; - - if ((winCheckMntOpt(ent, "binary") == NULL) && - (winCheckMntOpt(ent, "binmode") == NULL)) - binary = FALSE; - else - binary = TRUE; - } - - if (endmntent(mnt) != 1) - { - ErrorF("endmntent failed"); - return; - } - -#ifdef WINDBG - if (!binary) - winDebug("/tmp mounted in textmode\n"); -#endif -} -#else -static void -winCheckMount(void) -{ -} -#endif - -#ifdef RELOCATE_PROJECTROOT -const char * -winGetBaseDir(void) -{ - static BOOL inited = FALSE; - static char buffer[MAX_PATH]; - if (!inited) - { - char *fendptr; - HMODULE module = GetModuleHandle(NULL); - DWORD size = GetModuleFileName(module, buffer, sizeof(buffer)); - if (sizeof(buffer) > 0) - buffer[sizeof(buffer)-1] = 0; - - fendptr = buffer + size; - while (fendptr > buffer) - { - if (*fendptr == '\\' || *fendptr == '/') - { - *fendptr = 0; - break; - } - fendptr--; - } - inited = TRUE; - } - return buffer; -} -#endif - -static void -winFixupPaths (void) -{ - BOOL changed_fontpath = FALSE; - MessageType font_from = X_DEFAULT; -#ifdef RELOCATE_PROJECTROOT - const char *basedir = winGetBaseDir(); - size_t basedirlen = strlen(basedir); -#endif - -#ifdef READ_FONTDIRS - { - /* Open fontpath configuration file */ -#if defined WIN32 && defined __MINGW32__ - static Bool once = False; - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "%s\\font-dirs", basedir); - buffer[sizeof(buffer)-1] = 0; - FILE *fontdirs = fopen(buffer, "rt"); - if (once) fontdirs = NULL; - else once = True; -#else - FILE *fontdirs = fopen(ETCX11DIR "/font-dirs", "rt"); -#endif - if (fontdirs != NULL) - { - char buffer[256]; - int needs_sep = TRUE; - int comment_block = FALSE; - - /* get default fontpath */ - char *fontpath = strdup(defaultFontPath); - size_t size = strlen(fontpath); - - /* read all lines */ - while (!feof(fontdirs)) - { - size_t blen; - char *hashchar; - char *str; - int has_eol = FALSE; - - /* read one line */ - str = fgets(buffer, sizeof(buffer), fontdirs); - if (str == NULL) /* stop on error or eof */ - break; - - if (strchr(str, '\n') != NULL) - has_eol = TRUE; - - /* check if block is continued comment */ - if (comment_block) - { - /* ignore all input */ - *str = 0; - blen = 0; - if (has_eol) /* check if line ended in this block */ - comment_block = FALSE; - } - else - { - /* find comment character. ignore all trailing input */ - hashchar = strchr(str, '#'); - if (hashchar != NULL) - { - *hashchar = 0; - if (!has_eol) /* mark next block as continued comment */ - comment_block = TRUE; - } - } - - /* strip whitespaces from beginning */ - while (*str == ' ' || *str == '\t') - str++; - - /* get size, strip whitespaces from end */ - blen = strlen(str); - while (blen > 0 && (str[blen-1] == ' ' || - str[blen-1] == '\t' || str[blen-1] == '\n')) - { - str[--blen] = 0; - } - - /* still something left to add? */ - if (blen > 0) - { - size_t newsize = size + blen; - /* reserve one character more for ',' */ - if (needs_sep) - newsize++; - - /* allocate memory */ - if (fontpath == NULL) - fontpath = malloc(newsize+1); - else - fontpath = realloc(fontpath, newsize+1); - - /* add separator */ - if (needs_sep) - { - fontpath[size] = ','; - size++; - needs_sep = FALSE; - } - - /* mark next line as new entry */ - if (has_eol) - needs_sep = TRUE; - - /* add block */ - strncpy(fontpath + size, str, blen); - fontpath[newsize] = 0; - size = newsize; - } - } - - /* cleanup */ - fclose(fontdirs); - defaultFontPath = strdup(fontpath); - free(fontpath); - changed_fontpath = TRUE; - font_from = X_CONFIG; - } - } -#endif /* READ_FONTDIRS */ -#ifdef RELOCATE_PROJECTROOT - { - const char *libx11dir = PROJECTROOT "/lib/X11"; - size_t libx11dir_len = strlen(libx11dir); - char *newfp = NULL; - size_t newfp_len = 0; - const char *endptr, *ptr, *oldptr = defaultFontPath; - - endptr = oldptr + strlen(oldptr); - ptr = strchr(oldptr, ','); - if (ptr == NULL) - ptr = endptr; - while (ptr != NULL) - { - size_t oldfp_len = (ptr - oldptr); - size_t newsize = oldfp_len; - char *newpath = malloc(newsize + 1); - strncpy(newpath, oldptr, newsize); - newpath[newsize] = 0; - - - if (strncmp(libx11dir, newpath, libx11dir_len) == 0) - { - char *compose; - newsize = newsize - libx11dir_len + basedirlen; - compose = malloc(newsize + 1); - strcpy(compose, basedir); - strncat(compose, newpath + libx11dir_len, newsize - basedirlen); - compose[newsize] = 0; - free(newpath); - newpath = compose; - } - - oldfp_len = newfp_len; - if (oldfp_len > 0) - newfp_len ++; /* space for separator */ - newfp_len += newsize; - - if (newfp == NULL) - newfp = malloc(newfp_len + 1); - else - newfp = realloc(newfp, newfp_len + 1); - - if (oldfp_len > 0) - { - strcpy(newfp + oldfp_len, ","); - oldfp_len++; - } - strcpy(newfp + oldfp_len, newpath); - - free(newpath); - - if (*ptr == 0) - { - oldptr = ptr; - ptr = NULL; - } else - { - oldptr = ptr + 1; - ptr = strchr(oldptr, ','); - if (ptr == NULL) - ptr = endptr; - } - } - - defaultFontPath = strdup(newfp); - free(newfp); - changed_fontpath = TRUE; - } -#endif /* RELOCATE_PROJECTROOT */ - if (changed_fontpath) - winDebug ("FontPath set to \"%s\"\n", defaultFontPath); - -#ifdef RELOCATE_PROJECTROOT - if (getenv("XKEYSYMDB") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XKEYSYMDB=%s\\XKeysymDB", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XERRORDB") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XERRORDB=%s\\XErrorDB", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XLOCALEDIR") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XLOCALEDIR=%s\\locale", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XHOSTPREFIX") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XHOSTPREFIX=%s\\X", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("HOME") == NULL) - { - HMODULE shfolder; - SHGETFOLDERPATHPROC shgetfolderpath = NULL; - char buffer[MAX_PATH + 5]; - strncpy(buffer, "HOME=", 5); - - /* Try to load SHGetFolderPath from shfolder.dll and shell32.dll */ - - shfolder = LoadLibrary("shfolder.dll"); - /* fallback to shell32.dll */ - if (shfolder == NULL) - shfolder = LoadLibrary("shell32.dll"); - - /* resolve SHGetFolderPath */ - if (shfolder != NULL) - shgetfolderpath = (SHGETFOLDERPATHPROC)GetProcAddress(shfolder, "SHGetFolderPathA"); - - /* query appdata directory */ - if (shgetfolderpath && - shgetfolderpath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, - buffer + 5) == 0) - { - putenv(buffer); - } else - { - ErrorF ("Can not determine HOME directory\n"); - } - if (shfolder != NULL) - FreeLibrary(shfolder); - } - if (!g_fLogFileChanged) { - static char buffer[MAX_PATH]; - DWORD size = GetTempPath(sizeof(buffer), buffer); - if (size && size < sizeof(buffer)) - { - snprintf(buffer + size, sizeof(buffer) - size, - "VCXSrv.%s.log", display); - buffer[sizeof(buffer)-1] = 0; - g_pszLogFile = buffer; - GetLongPathName(buffer, buffer, MAX_PATH); - winDebug ("Logfile set to \"%s\"\n", g_pszLogFile); - } - } - { - static char xkbbasedir[MAX_PATH]; - - snprintf(xkbbasedir, sizeof(xkbbasedir), "%s\\xkbdata", basedir); - if (sizeof(xkbbasedir) > 0) - xkbbasedir[sizeof(xkbbasedir)-1] = 0; - XkbBaseDirectory = xkbbasedir; - XkbBinDirectory = basedir; - } -#endif /* RELOCATE_PROJECTROOT */ -} - -void -OsVendorInit (void) -{ - /* Re-initialize global variables on server reset */ - winInitializeGlobals (); - - winFixupPaths(); - -#ifdef DDXOSVERRORF - if (!OsVendorVErrorFProc) - OsVendorVErrorFProc = OsVendorVErrorF; -#endif - - if (!g_fLogInited) { - /* keep this order. If LogInit fails it calls Abort which then calls - * ddxGiveUp where LogInit is called again and creates an infinite - * recursion. If we set g_fLogInited to TRUE before the init we - * avoid the second call - */ - g_fLogInited = TRUE; - g_pszLogFile = LogInit (g_pszLogFile, NULL); - } - LogSetParameter (XLOG_FLUSH, 1); - LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose); - LogSetParameter (XLOG_FILE_VERBOSITY, g_iLogVerbose); - - /* Log the version information */ - if (serverGeneration == 1) - winLogVersionInfo (); - - winCheckMount(); - - /* Add a default screen if no screens were specified */ - if (g_iNumScreens == 0) - { - winDebug ("OsVendorInit - Creating default screen 0\n"); - - /* - * We need to initialize the default screen 0 if no -screen - * arguments were processed. - * - * Add a screen 0 using the defaults set by winInitializeDefaultScreens() - * and any additional default screen parameters given - */ - winInitializeScreens(1); - - /* We have to flag this as an explicit screen, even though it isn't */ - g_ScreenInfo[0].fExplicitScreen = TRUE; - } -} - - -static void -winUseMsg (void) -{ - ErrorF("\n"); - ErrorF("\n"); - ErrorF(EXECUTABLE_NAME " Device Dependent Usage:\n"); - ErrorF("\n"); - -#ifdef XWIN_CLIPBOARD - ErrorF ("-[no]clipboard\n" - "\tEnable [disable] the clipboard integration. Default is enabled.\n"); - ErrorF ("-[no]clipboardprimary\n" - "\t[Do not] map the PRIMARY selection to the windows clipboard.\n" - "\tThe CLIPBOARD selection is always mapped if -clipboard is enabled.\n" - "\tDefault is mapped.\n"); -#endif - - ErrorF ("-clipupdates num_boxes\n" - "\tUse a clipping region to constrain shadow update blits to\n" - "\tthe updated region when num_boxes, or more, are in the\n" - "\tupdated region.\n"); - -#ifdef XWIN_XF86CONFIG - ErrorF ("-config\n" - "\tSpecify a configuration file.\n"); - - ErrorF ("-configdir\n" - "\tSpecify a configuration directory.\n"); -#endif - - ErrorF ("-depth bits_per_pixel\n" - "\tSpecify an optional bitdepth to use in fullscreen mode\n" - "\twith a DirectDraw engine.\n"); - - ErrorF ("-emulate3buttons [timeout]\n" - "\tEmulate 3 button mouse with an optional timeout in\n" - "\tmilliseconds.\n"); - -#ifdef XWIN_EMULATEPSEUDO - ErrorF ("-emulatepseudo\n" - "\tCreate a depth 8 PseudoColor visual when running in\n" - "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n" - "\tdepths. The PseudoColor visual does not have correct colors,\n" - "\tand it may crash, but it at least allows you to run your\n" - "\tapplication in TrueColor modes.\n"); -#endif - - ErrorF ("-engine engine_type_id\n" - "\tOverride the server's automatically selected engine type:\n" - "\t\t1 - Shadow GDI\n" - "\t\t2 - Shadow DirectDraw\n" - "\t\t4 - Shadow DirectDraw4 Non-Locking\n" -#ifdef XWIN_PRIMARYFB - "\t\t8 - Primary DirectDraw - obsolete\n" -#endif -#ifdef XWIN_NATIVEGDI - "\t\t16 - Native GDI - experimental\n" -#endif - ); - - ErrorF ("-fullscreen\n" - "\tRun the server in fullscreen mode.\n"); - - ErrorF ("-ignoreinput\n" - "\tIgnore keyboard and mouse input.\n"); - -#ifdef XWIN_MULTIWINDOWINTWM - ErrorF ("-internalwm\n" - "\tRun the internal window manager.\n"); -#endif - -#ifdef XWIN_XF86CONFIG - ErrorF ("-keyboard\n" - "\tSpecify a keyboard device from the configuration file.\n"); -#endif - - ErrorF ("-[no]keyhook\n" - "\tGrab special Windows keypresses like Alt-Tab or the Menu " - "key.\n"); - - ErrorF ("-lesspointer\n" - "\tHide the windows mouse pointer when it is over any\n" - "\t" EXECUTABLE_NAME " window. This prevents ghost cursors appearing when\n" - "\tthe Windows cursor is drawn on top of the X cursor\n"); - - ErrorF ("-logfile filename\n" - "\tWrite log messages to <filename>.\n"); - - ErrorF ("-logverbose verbosity\n" - "\tSet the verbosity of log messages. [NOTE: Only a few messages\n" - "\trespect the settings yet]\n" - "\t\t0 - only print fatal error.\n" - "\t\t1 - print additional configuration information.\n" - "\t\t2 - print additional runtime information [default].\n" - "\t\t3 - print debugging and tracing information.\n"); - - ErrorF ("-[no]multimonitors or -[no]multiplemonitors\n" - "\tUse the entire virtual screen if multiple\n" - "\tmonitors are present.\n"); - -#ifdef XWIN_MULTIWINDOW - ErrorF ("-multiwindow\n" - "\tRun the server in multi-window mode.\n"); -#endif - -#ifdef XWIN_MULTIWINDOWEXTWM - ErrorF ("-mwextwm\n" - "\tRun the server in multi-window external window manager mode.\n"); -#endif - - ErrorF ("-nodecoration\n" - "\tDo not draw a window border, title bar, etc. Windowed\n" - "\tmode only.\n"); - -#ifdef XWIN_CLIPBOARD - ErrorF ("-nounicodeclipboard\n" - "\tDo not use Unicode clipboard even if on a NT-based platform.\n"); -#endif - - ErrorF ("-refresh rate_in_Hz\n" - "\tSpecify an optional refresh rate to use in fullscreen mode\n" - "\twith a DirectDraw engine.\n"); - - ErrorF ("-resize=none|scrollbars|randr" - "\tIn windowed mode, [don't] allow resizing of the window. 'scrollbars'\n" - "\tmode gives the window scrollbars as needed, 'randr' mode uses the RANR\n" - "\textension to resize the X screen.\n"); - - ErrorF ("-rootless\n" - "\tRun the server in rootless mode.\n"); - - ErrorF ("-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]\n" - "\tEnable screen scr_num and optionally specify a width and\n" - "\theight and initial position for that screen. Additionally\n" - "\ta monitor number can be specified to start the server on,\n" - "\tat which point, all coordinates become relative to that\n" - "\tmonitor (Not for Windows NT4 and 95). Examples:\n" - "\t -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600\n" - "\t -screen 0 1024x768@3 ; 3rd monitor size 1024x768\n" - "\t -screen 0 @1 ; on 1st monitor using its full resolution (the default)\n"); - - ErrorF ("-silent-dup-error\n" - "\tIf another instance of " EXECUTABLE_NAME " with the same display number is running\n" - "\texit silently and don't display any error message.\n"); - - ErrorF ("-swcursor\n" - "\tDisable the usage of the Windows cursor and use the X11 software\n" - "\tcursor instead.\n"); - - ErrorF ("-[no]trayicon\n" - "\tDo not create a tray icon. Default is to create one\n" - "\ticon per screen. You can globally disable tray icons with\n" - "\t-notrayicon, then enable it for specific screens with\n" - "\t-trayicon for those screens.\n"); - - ErrorF ("-[no]unixkill\n" - "\tCtrl+Alt+Backspace exits the X Server.\n"); - - ErrorF ("-[no]wgl\n" - "\tEnable the GLX extension to use the native Windows WGL interface for accelerated OpenGL\n"); - - ErrorF ("-[no]winkill\n" - "\tAlt+F4 exits the X Server.\n"); - - ErrorF ("-xkblayout XKBLayout\n" - "\tEquivalent to XKBLayout in XF86Config files.\n" - "\tFor example: -xkblayout de\n"); - - ErrorF ("-xkbmodel XKBModel\n" - "\tEquivalent to XKBModel in XF86Config files.\n"); - - ErrorF ("-xkboptions XKBOptions\n" - "\tEquivalent to XKBOptions in XF86Config files.\n"); - - ErrorF ("-xkbrules XKBRules\n" - "\tEquivalent to XKBRules in XF86Config files.\n"); - - ErrorF ("-xkbvariant XKBVariant\n" - "\tEquivalent to XKBVariant in XF86Config files.\n" - "\tFor example: -xkbvariant nodeadkeys\n"); -} - -/* See Porting Layer Definition - p. 57 */ -void -ddxUseMsg(void) -{ - /* Set a flag so that FatalError won't give duplicate warning message */ - g_fSilentFatalError = TRUE; - - winUseMsg(); - - /* Log file will not be opened for UseMsg unless we open it now */ - if (!g_fLogInited) { - g_pszLogFile = LogInit (g_pszLogFile, NULL); - g_fLogInited = TRUE; - } - LogClose (); - - /* Notify user where UseMsg text can be found.*/ - if (!g_fNoHelpMessageBox) - winMessageBoxF ("The " PROJECT_NAME " help text has been printed to " - "%s.\n" - "Please open %s to read the help text.\n", - MB_ICONINFORMATION, g_pszLogFile, g_pszLogFile); -} - -/* See Porting Layer Definition - p. 20 */ -/* - * Do any global initialization, then initialize each screen. - * - * NOTE: We use ddxProcessArgument, so we don't need to touch argc and argv - */ - -void -InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) -{ - int i; - - /* Log the command line */ - winLogCommandLine (argc, argv); - - winDebug ("InitOutput\n"); - - /* Validate command-line arguments */ - if (serverGeneration == 1 && !winValidateArgs ()) - { - FatalError ("InitOutput - Invalid command-line arguments found. " - "Exiting.\n"); - } - - /* Check for duplicate invocation on same display number.*/ - if (serverGeneration == 1 && !winCheckDisplayNumber ()) - { - if (g_fSilentDupError) - g_fSilentFatalError = TRUE; - FatalError ("InitOutput - Duplicate invocation on display " - "number: %s. Exiting.\n", display); - } - -#ifdef XWIN_XF86CONFIG - /* Try to read the xorg.conf-style configuration file */ - if (!winReadConfigfile ()) - ErrorF ("InitOutput - Error reading config file\n"); -#else - winConfigFiles (); -#endif - - /* Load preferences from XWinrc file */ - LoadPreferences(); - - /* Setup global screen info parameters */ - screenInfo->imageByteOrder = IMAGE_BYTE_ORDER; - screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; - screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; - screenInfo->numPixmapFormats = NUMFORMATS; - - /* Describe how we want common pixmap formats padded */ - for (i = 0; i < NUMFORMATS; i++) - { - screenInfo->formats[i] = g_PixmapFormats[i]; - } - - /* Load pointers to DirectDraw functions */ - winGetDDProcAddresses (); - - /* Detect supported engines */ - winDetectSupportedEngines (); - - /* Load common controls library */ - g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0); - - /* Load TrackMouseEvent function pointer */ - g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls, - "_TrackMouseEvent"); - if (g_fpTrackMouseEvent == NULL) - { - ErrorF ("InitOutput - Could not get pointer to function\n" - "\t_TrackMouseEvent in comctl32.dll. Try installing\n" - "\tInternet Explorer 3.0 or greater if you have not\n" - "\talready.\n"); - - /* Free the library since we won't need it */ - FreeLibrary (g_hmodCommonControls); - g_hmodCommonControls = NULL; - - /* Set function pointer to point to no operation function */ - g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - } - - /* Store the instance handle */ - g_hInstance = GetModuleHandle (NULL); - - /* Initialize each screen */ - for (i = 0; i < g_iNumScreens; ++i) - { - /* Initialize the screen */ - if (-1 == AddScreen (winScreenInit, argc, argv)) - { - FatalError ("InitOutput - Couldn't add screen %d", i); - } - } - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - - /* Generate a cookie used by internal clients for authorization */ - if (g_fXdmcpEnabled || g_fAuthEnabled) - winGenerateAuthorization (); - - /* Perform some one time initialization */ - if (1 == serverGeneration) - { - /* - * setlocale applies to all threads in the current process. - * Apply locale specified in LANG environment variable. - */ - if (!setlocale (LC_ALL, "")) - { - ErrorF ("setlocale failed.\n"); - } - - /* See if X supports the current locale */ - if (XSupportsLocale () == FALSE) - { - ErrorF ("Warning: Locale not supported by X, falling back to 'C' locale.\n"); - setlocale(LC_ALL, "C"); - } - - } -#endif - - winDebug ("InitOutput - Returning.\n"); -} - - -/* - * winCheckDisplayNumber - Check if another instance of Cygwin/X is - * already running on the same display number. If no one exists, - * make a mutex to prevent new instances from running on the same display. - * - * return FALSE if the display number is already used. - */ - -static Bool -winCheckDisplayNumber (void) -{ - int nDisp; - HANDLE mutex; - char name[MAX_PATH]; - char * pszPrefix = '\0'; - OSVERSIONINFO osvi = {0}; - - /* Check display range */ - nDisp = atoi (display); - if (nDisp < 0 || nDisp > 59535) - { - ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp); - return FALSE; - } - - /* Set first character of mutex name to null */ - name[0] = '\0'; - - /* Get operating system version information */ - osvi.dwOSVersionInfoSize = sizeof (osvi); - GetVersionEx (&osvi); - - /* Want a mutex shared among all terminals on NT > 4.0 */ - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT - && osvi.dwMajorVersion >= 5) - { - pszPrefix = "Global\\"; - } - - /* Setup Cygwin/X specific part of name */ - snprintf (name, sizeof(name), "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp); - - /* Windows automatically releases the mutex when this process exits */ - mutex = CreateMutex (NULL, FALSE, name); - if (!mutex) - { - LPVOID lpMsgBuf; - - /* Display a fancy error message */ - FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError (), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, NULL); - ErrorF ("winCheckDisplayNumber - CreateMutex failed: %s\n", - (LPSTR)lpMsgBuf); - LocalFree (lpMsgBuf); - - return FALSE; - } - if (GetLastError () == ERROR_ALREADY_EXISTS) - { - ErrorF ("winCheckDisplayNumber - " - "VCXsrv, Xming or Cygwin/X is already running on display %d\n", - nDisp); - return FALSE; - } - - return TRUE; -} +
+/*
+
+Copyright 1993, 1998 The Open Group
+Copyright (C) Colin Harrison 2005-2008
+
+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.
+
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "winmsg.h"
+#include "winconfig.h"
+#include "winprefs.h"
+#ifdef DPMSExtension
+#include "dpmsproc.h"
+#endif
+#include <locale.h>
+#ifdef __CYGWIN__
+#include <mntent.h>
+#endif
+#if defined(WIN32)
+#include "xkbsrv.h"
+#endif
+#ifdef RELOCATE_PROJECTROOT
+#undef Status
+#include <shlobj.h>
+typedef HRESULT (__stdcall * SHGETFOLDERPATHPROC)(
+ HWND hwndOwner,
+ int nFolder,
+ HANDLE hToken,
+ DWORD dwFlags,
+ LPSTR pszPath
+);
+#endif
+
+/*
+ * References to external symbols
+ */
+#ifdef XWIN_CLIPBOARD
+extern Bool g_fUnicodeClipboard;
+extern Bool g_fClipboardLaunched;
+extern Bool g_fClipboardStarted;
+extern pthread_t g_ptClipboardProc;
+extern HWND g_hwndClipboard;
+extern Bool g_fClipboard;
+#endif
+
+
+/*
+ module handle for dynamically loaded comctl32 library
+*/
+static HMODULE g_hmodCommonControls = NULL;
+
+/*
+ * Function prototypes
+ */
+
+#ifdef XWIN_CLIPBOARD
+static void
+winClipboardShutdown (void);
+#endif
+
+#if defined(DDXOSVERRORF)
+void
+OsVendorVErrorF (const char *pszFormat, va_list va_args);
+#endif
+
+static Bool
+winCheckDisplayNumber (void);
+
+void
+winLogCommandLine (int argc, char *argv[]);
+
+void
+winLogVersionInfo (void);
+
+Bool
+winValidateArgs (void);
+
+#ifdef RELOCATE_PROJECTROOT
+const char *
+winGetBaseDir(void);
+#endif
+
+/*
+ * For the depth 24 pixmap we default to 32 bits per pixel, but
+ * we change this pixmap format later if we detect that the display
+ * is going to be running at 24 bits per pixel.
+ *
+ * FIXME: On second thought, don't DIBs only support 32 bits per pixel?
+ * DIBs are the underlying bitmap used for DirectDraw surfaces, so it
+ * seems that all pixmap formats with depth 24 would be 32 bits per pixel.
+ * Confirm whether depth 24 DIBs can have 24 bits per pixel, then remove/keep
+ * the bits per pixel adjustment and update this comment to reflect the
+ * situation. Harold Hunt - 2002/07/02
+ */
+
+static PixmapFormatRec g_PixmapFormats[] = {
+ { 1, 1, BITMAP_SCANLINE_PAD },
+ { 4, 8, BITMAP_SCANLINE_PAD },
+ { 8, 8, BITMAP_SCANLINE_PAD },
+ { 15, 16, BITMAP_SCANLINE_PAD },
+ { 16, 16, BITMAP_SCANLINE_PAD },
+ { 24, 32, BITMAP_SCANLINE_PAD },
+ { 32, 32, BITMAP_SCANLINE_PAD }
+};
+
+const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]);
+
+#ifdef XWIN_CLIPBOARD
+static void
+winClipboardShutdown (void)
+{
+ /* Close down clipboard resources */
+ if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted)
+ {
+ /* Synchronously destroy the clipboard window */
+ if (g_hwndClipboard != NULL)
+ {
+ g_fClipboardStarted=FALSE; /* This is to avoid dead-locls caused by the clipboard thread still doing some stuff */
+ SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0);
+ /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
+ }
+ else
+ return;
+
+ /* Wait for the clipboard thread to exit */
+ pthread_join (g_ptClipboardProc, NULL);
+
+ winDebug ("winClipboardShutdown - Clipboard thread has exited.\n");
+ }
+}
+#endif
+
+
+#if defined(DDXBEFORERESET)
+/*
+ * Called right before KillAllClients when the server is going to reset,
+ * allows us to shutdown our seperate threads cleanly.
+ */
+
+void
+ddxBeforeReset (void)
+{
+ winDebug ("ddxBeforeReset - Hello\n");
+
+#ifdef XWIN_CLIPBOARD
+ winClipboardShutdown ();
+#endif
+}
+#endif
+
+
+/* See Porting Layer Definition - p. 57 */
+void
+ddxGiveUp (void)
+{
+ int i;
+
+ winDebug ("ddxGiveUp\n");
+
+ /* Perform per-screen deinitialization */
+ for (i = 0; i < g_iNumScreens; ++i)
+ {
+ /* Delete the tray icon */
+ if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen)
+ winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen));
+ }
+
+#ifdef XWIN_MULTIWINDOW
+ /* Notify the worker threads we're exiting */
+ winDeinitMultiWindowWM ();
+#endif
+
+#ifdef HAS_DEVWINDOWS
+ /* Close our handle to our message queue */
+ if (g_fdMessageQueue != WIN_FD_INVALID)
+ {
+ /* Close /dev/windows */
+ close (g_fdMessageQueue);
+
+ /* Set the file handle to invalid */
+ g_fdMessageQueue = WIN_FD_INVALID;
+ }
+#endif
+
+ if (!g_fLogInited) {
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ g_fLogInited = TRUE;
+ }
+ LogClose ();
+
+ /*
+ * At this point we aren't creating any new screens, so
+ * we are guaranteed to not need the DirectDraw functions.
+ */
+ winReleaseDDProcAddresses();
+
+ /* Unload our TrackMouseEvent function pointer */
+ if (g_hmodCommonControls != NULL)
+ {
+ FreeLibrary (g_hmodCommonControls);
+ g_hmodCommonControls = NULL;
+ g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
+ }
+
+ /* Free concatenated command line */
+ free(g_pszCommandLine);
+ g_pszCommandLine = NULL;
+
+ /* Remove our keyboard hook if it is installed */
+ winRemoveKeyboardHookLL ();
+
+ /* Tell Windows that we want to end the app */
+ PostQuitMessage (0);
+}
+
+
+/* See Porting Layer Definition - p. 57 */
+void
+AbortDDX (void)
+{
+ winDebug ("AbortDDX\n");
+ ddxGiveUp ();
+}
+
+#ifdef __CYGWIN__
+/* hasmntopt is currently not implemented for cygwin */
+static const char *winCheckMntOpt(const struct mntent *mnt, const char *opt)
+{
+ const char *s;
+ size_t len;
+ if (mnt == NULL)
+ return NULL;
+ if (opt == NULL)
+ return NULL;
+ if (mnt->mnt_opts == NULL)
+ return NULL;
+
+ len = strlen(opt);
+ s = strstr(mnt->mnt_opts, opt);
+ if (s == NULL)
+ return NULL;
+ if ((s == mnt->mnt_opts || *(s-1) == ',') && (s[len] == 0 || s[len] == ','))
+ return (char *)opt;
+ return NULL;
+}
+
+static void
+winCheckMount(void)
+{
+ FILE *mnt;
+ struct mntent *ent;
+
+ enum { none = 0, sys_root, user_root, sys_tmp, user_tmp }
+ level = none, curlevel;
+ BOOL binary = TRUE;
+
+ mnt = setmntent("/etc/mtab", "r");
+ if (mnt == NULL)
+ {
+ ErrorF("setmntent failed");
+ return;
+ }
+
+ while ((ent = getmntent(mnt)) != NULL)
+ {
+ BOOL system = (winCheckMntOpt(ent, "user") != NULL);
+ BOOL root = (strcmp(ent->mnt_dir, "/") == 0);
+ BOOL tmp = (strcmp(ent->mnt_dir, "/tmp") == 0);
+
+ if (system)
+ {
+ if (root)
+ curlevel = sys_root;
+ else if (tmp)
+ curlevel = sys_tmp;
+ else
+ continue;
+ }
+ else
+ {
+ if (root)
+ curlevel = user_root;
+ else if (tmp)
+ curlevel = user_tmp;
+ else
+ continue;
+ }
+
+ if (curlevel <= level)
+ continue;
+ level = curlevel;
+
+ if ((winCheckMntOpt(ent, "binary") == NULL) &&
+ (winCheckMntOpt(ent, "binmode") == NULL))
+ binary = FALSE;
+ else
+ binary = TRUE;
+ }
+
+ if (endmntent(mnt) != 1)
+ {
+ ErrorF("endmntent failed");
+ return;
+ }
+
+#ifdef WINDBG
+ if (!binary)
+ winDebug("/tmp mounted in textmode\n");
+#endif
+}
+#else
+static void
+winCheckMount(void)
+{
+}
+#endif
+
+#ifdef RELOCATE_PROJECTROOT
+const char *
+winGetBaseDir(void)
+{
+ static BOOL inited = FALSE;
+ static char buffer[MAX_PATH];
+ if (!inited)
+ {
+ char *fendptr;
+ HMODULE module = GetModuleHandle(NULL);
+ DWORD size = GetModuleFileName(module, buffer, sizeof(buffer));
+ if (sizeof(buffer) > 0)
+ buffer[sizeof(buffer)-1] = 0;
+
+ fendptr = buffer + size;
+ while (fendptr > buffer)
+ {
+ if (*fendptr == '\\' || *fendptr == '/')
+ {
+ *fendptr = 0;
+ break;
+ }
+ fendptr--;
+ }
+ inited = TRUE;
+ }
+ return buffer;
+}
+#endif
+
+static void
+winFixupPaths (void)
+{
+ BOOL changed_fontpath = FALSE;
+ MessageType font_from = X_DEFAULT;
+#ifdef RELOCATE_PROJECTROOT
+ const char *basedir = winGetBaseDir();
+ size_t basedirlen = strlen(basedir);
+#endif
+
+#ifdef READ_FONTDIRS
+ {
+ /* Open fontpath configuration file */
+#if defined WIN32 && defined __MINGW32__
+ static Bool once = False;
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "%s\\font-dirs", basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ FILE *fontdirs = fopen(buffer, "rt");
+ if (once) fontdirs = NULL;
+ else once = True;
+#else
+ FILE *fontdirs = fopen(ETCX11DIR "/font-dirs", "rt");
+#endif
+ if (fontdirs != NULL)
+ {
+ char buffer[256];
+ int needs_sep = TRUE;
+ int comment_block = FALSE;
+
+ /* get default fontpath */
+ char *fontpath = strdup(defaultFontPath);
+ size_t size = strlen(fontpath);
+
+ /* read all lines */
+ while (!feof(fontdirs))
+ {
+ size_t blen;
+ char *hashchar;
+ char *str;
+ int has_eol = FALSE;
+
+ /* read one line */
+ str = fgets(buffer, sizeof(buffer), fontdirs);
+ if (str == NULL) /* stop on error or eof */
+ break;
+
+ if (strchr(str, '\n') != NULL)
+ has_eol = TRUE;
+
+ /* check if block is continued comment */
+ if (comment_block)
+ {
+ /* ignore all input */
+ *str = 0;
+ blen = 0;
+ if (has_eol) /* check if line ended in this block */
+ comment_block = FALSE;
+ }
+ else
+ {
+ /* find comment character. ignore all trailing input */
+ hashchar = strchr(str, '#');
+ if (hashchar != NULL)
+ {
+ *hashchar = 0;
+ if (!has_eol) /* mark next block as continued comment */
+ comment_block = TRUE;
+ }
+ }
+
+ /* strip whitespaces from beginning */
+ while (*str == ' ' || *str == '\t')
+ str++;
+
+ /* get size, strip whitespaces from end */
+ blen = strlen(str);
+ while (blen > 0 && (str[blen-1] == ' ' ||
+ str[blen-1] == '\t' || str[blen-1] == '\n'))
+ {
+ str[--blen] = 0;
+ }
+
+ /* still something left to add? */
+ if (blen > 0)
+ {
+ size_t newsize = size + blen;
+ /* reserve one character more for ',' */
+ if (needs_sep)
+ newsize++;
+
+ /* allocate memory */
+ if (fontpath == NULL)
+ fontpath = malloc(newsize+1);
+ else
+ fontpath = realloc(fontpath, newsize+1);
+
+ /* add separator */
+ if (needs_sep)
+ {
+ fontpath[size] = ',';
+ size++;
+ needs_sep = FALSE;
+ }
+
+ /* mark next line as new entry */
+ if (has_eol)
+ needs_sep = TRUE;
+
+ /* add block */
+ strncpy(fontpath + size, str, blen);
+ fontpath[newsize] = 0;
+ size = newsize;
+ }
+ }
+
+ /* cleanup */
+ fclose(fontdirs);
+ defaultFontPath = strdup(fontpath);
+ free(fontpath);
+ changed_fontpath = TRUE;
+ font_from = X_CONFIG;
+ }
+ }
+#endif /* READ_FONTDIRS */
+#ifdef RELOCATE_PROJECTROOT
+ {
+ const char *libx11dir = PROJECTROOT "/lib/X11";
+ size_t libx11dir_len = strlen(libx11dir);
+ char *newfp = NULL;
+ size_t newfp_len = 0;
+ const char *endptr, *ptr, *oldptr = defaultFontPath;
+
+ endptr = oldptr + strlen(oldptr);
+ ptr = strchr(oldptr, ',');
+ if (ptr == NULL)
+ ptr = endptr;
+ while (ptr != NULL)
+ {
+ size_t oldfp_len = (ptr - oldptr);
+ size_t newsize = oldfp_len;
+ char *newpath = malloc(newsize + 1);
+ strncpy(newpath, oldptr, newsize);
+ newpath[newsize] = 0;
+
+
+ if (strncmp(libx11dir, newpath, libx11dir_len) == 0)
+ {
+ char *compose;
+ newsize = newsize - libx11dir_len + basedirlen;
+ compose = malloc(newsize + 1);
+ strcpy(compose, basedir);
+ strncat(compose, newpath + libx11dir_len, newsize - basedirlen);
+ compose[newsize] = 0;
+ free(newpath);
+ newpath = compose;
+ }
+
+ oldfp_len = newfp_len;
+ if (oldfp_len > 0)
+ newfp_len ++; /* space for separator */
+ newfp_len += newsize;
+
+ if (newfp == NULL)
+ newfp = malloc(newfp_len + 1);
+ else
+ newfp = realloc(newfp, newfp_len + 1);
+
+ if (oldfp_len > 0)
+ {
+ strcpy(newfp + oldfp_len, ",");
+ oldfp_len++;
+ }
+ strcpy(newfp + oldfp_len, newpath);
+
+ free(newpath);
+
+ if (*ptr == 0)
+ {
+ oldptr = ptr;
+ ptr = NULL;
+ } else
+ {
+ oldptr = ptr + 1;
+ ptr = strchr(oldptr, ',');
+ if (ptr == NULL)
+ ptr = endptr;
+ }
+ }
+
+ defaultFontPath = strdup(newfp);
+ free(newfp);
+ changed_fontpath = TRUE;
+ }
+#endif /* RELOCATE_PROJECTROOT */
+ if (changed_fontpath)
+ winDebug ("FontPath set to \"%s\"\n", defaultFontPath);
+
+#ifdef RELOCATE_PROJECTROOT
+ if (getenv("XKEYSYMDB") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XKEYSYMDB=%s\\XKeysymDB",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XERRORDB") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XERRORDB=%s\\XErrorDB",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XLOCALEDIR") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XLOCALEDIR=%s\\locale",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XHOSTPREFIX") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XHOSTPREFIX=%s\\X",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("HOME") == NULL)
+ {
+ HMODULE shfolder;
+ SHGETFOLDERPATHPROC shgetfolderpath = NULL;
+ char buffer[MAX_PATH + 5];
+ strncpy(buffer, "HOME=", 5);
+
+ /* Try to load SHGetFolderPath from shfolder.dll and shell32.dll */
+
+ shfolder = LoadLibrary("shfolder.dll");
+ /* fallback to shell32.dll */
+ if (shfolder == NULL)
+ shfolder = LoadLibrary("shell32.dll");
+
+ /* resolve SHGetFolderPath */
+ if (shfolder != NULL)
+ shgetfolderpath = (SHGETFOLDERPATHPROC)GetProcAddress(shfolder, "SHGetFolderPathA");
+
+ /* query appdata directory */
+ if (shgetfolderpath &&
+ shgetfolderpath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0,
+ buffer + 5) == 0)
+ {
+ putenv(buffer);
+ } else
+ {
+ ErrorF ("Can not determine HOME directory\n");
+ }
+ if (shfolder != NULL)
+ FreeLibrary(shfolder);
+ }
+ if (!g_fLogFileChanged) {
+ static char buffer[MAX_PATH];
+ DWORD size = GetTempPath(sizeof(buffer), buffer);
+ if (size && size < sizeof(buffer))
+ {
+ snprintf(buffer + size, sizeof(buffer) - size,
+ "VCXSrv.%s.log", display);
+ buffer[sizeof(buffer)-1] = 0;
+ g_pszLogFile = buffer;
+ GetLongPathName(buffer, buffer, MAX_PATH);
+ winDebug ("Logfile set to \"%s\"\n", g_pszLogFile);
+ }
+ }
+ {
+ static char xkbbasedir[MAX_PATH];
+
+ snprintf(xkbbasedir, sizeof(xkbbasedir), "%s\\xkbdata", basedir);
+ if (sizeof(xkbbasedir) > 0)
+ xkbbasedir[sizeof(xkbbasedir)-1] = 0;
+ XkbBaseDirectory = xkbbasedir;
+ XkbBinDirectory = basedir;
+ }
+#endif /* RELOCATE_PROJECTROOT */
+}
+
+void
+OsVendorInit (void)
+{
+ /* Re-initialize global variables on server reset */
+ winInitializeGlobals ();
+
+ winFixupPaths();
+
+#ifdef DDXOSVERRORF
+ if (!OsVendorVErrorFProc)
+ OsVendorVErrorFProc = OsVendorVErrorF;
+#endif
+
+ if (!g_fLogInited) {
+ /* keep this order. If LogInit fails it calls Abort which then calls
+ * ddxGiveUp where LogInit is called again and creates an infinite
+ * recursion. If we set g_fLogInited to TRUE before the init we
+ * avoid the second call
+ */
+ g_fLogInited = TRUE;
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ }
+ LogSetParameter (XLOG_FLUSH, 1);
+ LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose);
+ LogSetParameter (XLOG_FILE_VERBOSITY, g_iLogVerbose);
+
+ /* Log the version information */
+ if (serverGeneration == 1)
+ winLogVersionInfo ();
+
+ winCheckMount();
+
+ /* Add a default screen if no screens were specified */
+ if (g_iNumScreens == 0)
+ {
+ winDebug ("OsVendorInit - Creating default screen 0\n");
+
+ /*
+ * We need to initialize the default screen 0 if no -screen
+ * arguments were processed.
+ *
+ * Add a screen 0 using the defaults set by winInitializeDefaultScreens()
+ * and any additional default screen parameters given
+ */
+ winInitializeScreens(1);
+
+ /* We have to flag this as an explicit screen, even though it isn't */
+ g_ScreenInfo[0].fExplicitScreen = TRUE;
+ }
+}
+
+
+static void
+winUseMsg (void)
+{
+ ErrorF("\n");
+ ErrorF("\n");
+ ErrorF(EXECUTABLE_NAME " Device Dependent Usage:\n");
+ ErrorF("\n");
+
+#ifdef XWIN_CLIPBOARD
+ ErrorF ("-[no]clipboard\n"
+ "\tEnable [disable] the clipboard integration. Default is enabled.\n");
+ ErrorF ("-[no]clipboardprimary\n"
+ "\t[Do not] map the PRIMARY selection to the windows clipboard.\n"
+ "\tThe CLIPBOARD selection is always mapped if -clipboard is enabled.\n"
+ "\tDefault is mapped.\n");
+#endif
+
+ ErrorF ("-clipupdates num_boxes\n"
+ "\tUse a clipping region to constrain shadow update blits to\n"
+ "\tthe updated region when num_boxes, or more, are in the\n"
+ "\tupdated region.\n");
+
+#ifdef XWIN_XF86CONFIG
+ ErrorF ("-config\n"
+ "\tSpecify a configuration file.\n");
+
+ ErrorF ("-configdir\n"
+ "\tSpecify a configuration directory.\n");
+#endif
+
+ ErrorF ("-depth bits_per_pixel\n"
+ "\tSpecify an optional bitdepth to use in fullscreen mode\n"
+ "\twith a DirectDraw engine.\n");
+
+ ErrorF ("-emulate3buttons [timeout]\n"
+ "\tEmulate 3 button mouse with an optional timeout in\n"
+ "\tmilliseconds.\n");
+
+#ifdef XWIN_EMULATEPSEUDO
+ ErrorF ("-emulatepseudo\n"
+ "\tCreate a depth 8 PseudoColor visual when running in\n"
+ "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n"
+ "\tdepths. The PseudoColor visual does not have correct colors,\n"
+ "\tand it may crash, but it at least allows you to run your\n"
+ "\tapplication in TrueColor modes.\n");
+#endif
+
+ ErrorF ("-engine engine_type_id\n"
+ "\tOverride the server's automatically selected engine type:\n"
+ "\t\t1 - Shadow GDI\n"
+ "\t\t2 - Shadow DirectDraw\n"
+ "\t\t4 - Shadow DirectDraw4 Non-Locking\n"
+#ifdef XWIN_PRIMARYFB
+ "\t\t8 - Primary DirectDraw - obsolete\n"
+#endif
+#ifdef XWIN_NATIVEGDI
+ "\t\t16 - Native GDI - experimental\n"
+#endif
+ );
+
+ ErrorF ("-fullscreen\n"
+ "\tRun the server in fullscreen mode.\n");
+
+ ErrorF ("-ignoreinput\n"
+ "\tIgnore keyboard and mouse input.\n");
+
+#ifdef XWIN_MULTIWINDOWINTWM
+ ErrorF ("-internalwm\n"
+ "\tRun the internal window manager.\n");
+#endif
+
+#ifdef XWIN_XF86CONFIG
+ ErrorF ("-keyboard\n"
+ "\tSpecify a keyboard device from the configuration file.\n");
+#endif
+
+ ErrorF ("-[no]keyhook\n"
+ "\tGrab special Windows keypresses like Alt-Tab or the Menu "
+ "key.\n");
+
+ ErrorF ("-lesspointer\n"
+ "\tHide the windows mouse pointer when it is over any\n"
+ "\t" EXECUTABLE_NAME " window. This prevents ghost cursors appearing when\n"
+ "\tthe Windows cursor is drawn on top of the X cursor\n");
+
+ ErrorF ("-logfile filename\n"
+ "\tWrite log messages to <filename>.\n");
+
+ ErrorF ("-logverbose verbosity\n"
+ "\tSet the verbosity of log messages. [NOTE: Only a few messages\n"
+ "\trespect the settings yet]\n"
+ "\t\t0 - only print fatal error.\n"
+ "\t\t1 - print additional configuration information.\n"
+ "\t\t2 - print additional runtime information [default].\n"
+ "\t\t3 - print debugging and tracing information.\n");
+
+ ErrorF ("-[no]multimonitors or -[no]multiplemonitors\n"
+ "\tUse the entire virtual screen if multiple\n"
+ "\tmonitors are present.\n");
+
+#ifdef XWIN_MULTIWINDOW
+ ErrorF ("-multiwindow\n"
+ "\tRun the server in multi-window mode.\n");
+#endif
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ ErrorF ("-mwextwm\n"
+ "\tRun the server in multi-window external window manager mode.\n");
+#endif
+
+ ErrorF ("-nodecoration\n"
+ "\tDo not draw a window border, title bar, etc. Windowed\n"
+ "\tmode only.\n");
+
+#ifdef XWIN_CLIPBOARD
+ ErrorF ("-nounicodeclipboard\n"
+ "\tDo not use Unicode clipboard even if on a NT-based platform.\n");
+#endif
+
+ ErrorF ("-refresh rate_in_Hz\n"
+ "\tSpecify an optional refresh rate to use in fullscreen mode\n"
+ "\twith a DirectDraw engine.\n");
+
+ ErrorF ("-resize=none|scrollbars|randr"
+ "\tIn windowed mode, [don't] allow resizing of the window. 'scrollbars'\n"
+ "\tmode gives the window scrollbars as needed, 'randr' mode uses the RANR\n"
+ "\textension to resize the X screen.\n");
+
+ ErrorF ("-rootless\n"
+ "\tRun the server in rootless mode.\n");
+
+ ErrorF ("-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]\n"
+ "\tEnable screen scr_num and optionally specify a width and\n"
+ "\theight and initial position for that screen. Additionally\n"
+ "\ta monitor number can be specified to start the server on,\n"
+ "\tat which point, all coordinates become relative to that\n"
+ "\tmonitor (Not for Windows NT4 and 95). Examples:\n"
+ "\t -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600\n"
+ "\t -screen 0 1024x768@3 ; 3rd monitor size 1024x768\n"
+ "\t -screen 0 @1 ; on 1st monitor using its full resolution (the default)\n");
+
+ ErrorF ("-silent-dup-error\n"
+ "\tIf another instance of " EXECUTABLE_NAME " with the same display number is running\n"
+ "\texit silently and don't display any error message.\n");
+
+ ErrorF ("-swcursor\n"
+ "\tDisable the usage of the Windows cursor and use the X11 software\n"
+ "\tcursor instead.\n");
+
+ ErrorF ("-[no]trayicon\n"
+ "\tDo not create a tray icon. Default is to create one\n"
+ "\ticon per screen. You can globally disable tray icons with\n"
+ "\t-notrayicon, then enable it for specific screens with\n"
+ "\t-trayicon for those screens.\n");
+
+ ErrorF ("-[no]unixkill\n"
+ "\tCtrl+Alt+Backspace exits the X Server.\n");
+
+ ErrorF ("-[no]wgl\n"
+ "\tEnable the GLX extension to use the native Windows WGL interface for accelerated OpenGL\n");
+
+ ErrorF ("-[no]winkill\n"
+ "\tAlt+F4 exits the X Server.\n");
+
+ ErrorF ("-xkblayout XKBLayout\n"
+ "\tEquivalent to XKBLayout in XF86Config files.\n"
+ "\tFor example: -xkblayout de\n");
+
+ ErrorF ("-xkbmodel XKBModel\n"
+ "\tEquivalent to XKBModel in XF86Config files.\n");
+
+ ErrorF ("-xkboptions XKBOptions\n"
+ "\tEquivalent to XKBOptions in XF86Config files.\n");
+
+ ErrorF ("-xkbrules XKBRules\n"
+ "\tEquivalent to XKBRules in XF86Config files.\n");
+
+ ErrorF ("-xkbvariant XKBVariant\n"
+ "\tEquivalent to XKBVariant in XF86Config files.\n"
+ "\tFor example: -xkbvariant nodeadkeys\n");
+}
+
+/* See Porting Layer Definition - p. 57 */
+void
+ddxUseMsg(void)
+{
+ /* Set a flag so that FatalError won't give duplicate warning message */
+ g_fSilentFatalError = TRUE;
+
+ winUseMsg();
+
+ /* Log file will not be opened for UseMsg unless we open it now */
+ if (!g_fLogInited) {
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ g_fLogInited = TRUE;
+ }
+ LogClose ();
+
+ /* Notify user where UseMsg text can be found.*/
+ if (!g_fNoHelpMessageBox)
+ winMessageBoxF ("The " PROJECT_NAME " help text has been printed to "
+ "%s.\n"
+ "Please open %s to read the help text.\n",
+ MB_ICONINFORMATION, g_pszLogFile, g_pszLogFile);
+}
+
+/* See Porting Layer Definition - p. 20 */
+/*
+ * Do any global initialization, then initialize each screen.
+ *
+ * NOTE: We use ddxProcessArgument, so we don't need to touch argc and argv
+ */
+
+void
+InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
+{
+ int i;
+
+ /* Log the command line */
+ winLogCommandLine (argc, argv);
+
+ winDebug ("InitOutput\n");
+
+ /* Validate command-line arguments */
+ if (serverGeneration == 1 && !winValidateArgs ())
+ {
+ FatalError ("InitOutput - Invalid command-line arguments found. "
+ "Exiting.\n");
+ }
+
+ /* Check for duplicate invocation on same display number.*/
+ if (serverGeneration == 1 && !winCheckDisplayNumber ())
+ {
+ if (g_fSilentDupError)
+ g_fSilentFatalError = TRUE;
+ FatalError ("InitOutput - Duplicate invocation on display "
+ "number: %s. Exiting.\n", display);
+ }
+
+#ifdef XWIN_XF86CONFIG
+ /* Try to read the xorg.conf-style configuration file */
+ if (!winReadConfigfile ())
+ ErrorF ("InitOutput - Error reading config file\n");
+#else
+ winConfigFiles ();
+#endif
+
+ /* Load preferences from XWinrc file */
+ LoadPreferences();
+
+ /* Setup global screen info parameters */
+ screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+ screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+ screenInfo->numPixmapFormats = NUMFORMATS;
+
+ /* Describe how we want common pixmap formats padded */
+ for (i = 0; i < NUMFORMATS; i++)
+ {
+ screenInfo->formats[i] = g_PixmapFormats[i];
+ }
+
+ /* Load pointers to DirectDraw functions */
+ winGetDDProcAddresses ();
+
+ /* Detect supported engines */
+ winDetectSupportedEngines ();
+
+ /* Load common controls library */
+ g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0);
+
+ /* Load TrackMouseEvent function pointer */
+ g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls,
+ "_TrackMouseEvent");
+ if (g_fpTrackMouseEvent == NULL)
+ {
+ ErrorF ("InitOutput - Could not get pointer to function\n"
+ "\t_TrackMouseEvent in comctl32.dll. Try installing\n"
+ "\tInternet Explorer 3.0 or greater if you have not\n"
+ "\talready.\n");
+
+ /* Free the library since we won't need it */
+ FreeLibrary (g_hmodCommonControls);
+ g_hmodCommonControls = NULL;
+
+ /* Set function pointer to point to no operation function */
+ g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
+ }
+
+ /* Store the instance handle */
+ g_hInstance = GetModuleHandle (NULL);
+
+ /* Initialize each screen */
+ for (i = 0; i < g_iNumScreens; ++i)
+ {
+ /* Initialize the screen */
+ if (-1 == AddScreen (winScreenInit, argc, argv))
+ {
+ FatalError ("InitOutput - Couldn't add screen %d", i);
+ }
+ }
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+
+ /* Generate a cookie used by internal clients for authorization */
+ if (g_fXdmcpEnabled || g_fAuthEnabled)
+ winGenerateAuthorization ();
+
+ /* Perform some one time initialization */
+ if (1 == serverGeneration)
+ {
+ /*
+ * setlocale applies to all threads in the current process.
+ * Apply locale specified in LANG environment variable.
+ */
+ if (!setlocale (LC_ALL, ""))
+ {
+ ErrorF ("setlocale failed.\n");
+ }
+
+ /* See if X supports the current locale */
+ if (XSupportsLocale () == FALSE)
+ {
+ ErrorF ("Warning: Locale not supported by X, falling back to 'C' locale.\n");
+ setlocale(LC_ALL, "C");
+ }
+
+ }
+#endif
+
+ winDebug ("InitOutput - Returning.\n");
+}
+
+
+/*
+ * winCheckDisplayNumber - Check if another instance of Cygwin/X is
+ * already running on the same display number. If no one exists,
+ * make a mutex to prevent new instances from running on the same display.
+ *
+ * return FALSE if the display number is already used.
+ */
+
+static Bool
+winCheckDisplayNumber (void)
+{
+ int nDisp;
+ HANDLE mutex;
+ char name[MAX_PATH];
+ char * pszPrefix = '\0';
+ OSVERSIONINFO osvi = {0};
+
+ /* Check display range */
+ nDisp = atoi (display);
+ if (nDisp < 0 || nDisp > 59535)
+ {
+ ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp);
+ return FALSE;
+ }
+
+ /* Set first character of mutex name to null */
+ name[0] = '\0';
+
+ /* Get operating system version information */
+ osvi.dwOSVersionInfoSize = sizeof (osvi);
+ GetVersionEx (&osvi);
+
+ /* Want a mutex shared among all terminals on NT > 4.0 */
+ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT
+ && osvi.dwMajorVersion >= 5)
+ {
+ pszPrefix = "Global\\";
+ }
+
+ /* Setup Cygwin/X specific part of name */
+ snprintf (name, sizeof(name), "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp);
+
+ /* Windows automatically releases the mutex when this process exits */
+ mutex = CreateMutex (NULL, FALSE, name);
+ if (!mutex)
+ {
+ LPVOID lpMsgBuf;
+
+ /* Display a fancy error message */
+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError (),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL);
+ ErrorF ("winCheckDisplayNumber - CreateMutex failed: %s\n",
+ (LPSTR)lpMsgBuf);
+ LocalFree (lpMsgBuf);
+
+ return FALSE;
+ }
+ if (GetLastError () == ERROR_ALREADY_EXISTS)
+ {
+ ErrorF ("winCheckDisplayNumber - "
+ "VCXsrv, Xming or Cygwin/X is already running on display %d\n",
+ nDisp);
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/man/XWin.man b/xorg-server/hw/xwin/man/XWin.man index e7933c9c8..8d8b0a9ab 100644 --- a/xorg-server/hw/xwin/man/XWin.man +++ b/xorg-server/hw/xwin/man/XWin.man @@ -1,397 +1,398 @@ -.TH XWIN 1 __vendorversion__ -.SH NAME -XWin \- X Server for the Cygwin environment on Microsoft Windows - - -.SH SYNOPSIS -.B XWin -[ options ] ... - - -.SH DESCRIPTION -\fIXWin\fP is an X Server for the X Window System on the Cygwin environment -running on Microsoft Windows. - - -.SH MODES -\fIXWin\fP can operate in 3 different modes: -.br -* \fISingle Window\fP: This is the default mode. Each X screen -appears as a single \fIWindows\fP window and all X windows are contained -within this window. -(In X terminology, the \fIWindows\fP window contains the root window for -the screen) -.br -* \fIMulti-Window\fP: In this mode \fIXWin\fP uses its own integrated -window manager in order to handle the top-level X windows, in such a -way that they appear as normal \fIWindows\fP windows. -.br -* \fIRootless\fP: In this mode the X server works in a window -containing the whole screen but this root window (traditionally covered with an X hatch -pattern) is hidden from view, so only top-level X windows are seen. - -.SH OPTIONS -In addition to the normal server options described in the \fIXserver(1)\fP -manual page, \fIXWin\fP accepts the following command line switches, -\fIall\fP of which are optional: - -.SH OPTIONS CONTROLLING WINDOWING MODE -Only one of these options may be specified. -.TP 8 -.B (default) -Windowed or rooted mode. -Each X screen appears as a single \fIWindows\fP window and all X windows are -contained within those windows. -.TP 8 -.B \-multiwindow -Each top-level X window appears in its own \fIWindows\fP window. -Also start the integrated \fIWindows\fP-based window manager. -.TP 8 -.B \-rootless -Run the server in rootless mode. -The X server works on a window covering the whole screen but the root window -is hidden from view. -.TP 8 -.B \-mwextwm -Experimental. -The mode combines \fB\-rootless\fP mode drawing with native \fIWindows\fP -window frames managed by the experimental external window manager \fIxwinwm\fP. -.PP -\fBNOTE:\fP \fI-multiwindow\fP mode uses its own internal window manager. -All other modes require an external window manager in order to move, resize, and perform other -operations on the individual X windows. - -.SH OPTIONS FOR SPECIFYING X SCREENS -An X display may be composed of multiple screens. -The default behaviour is to create a single screen 0 that is roughly the -size of useful area of the primary monitor (allowing for any window -decorations and the task-bar). - -Screen specific parameters, such as \fB\-fullscreen\fP, can be applied as a -default to all screens by placing those screen specific parameters -before any \fB\-screen\fP parameter. Screen specific parameters placed after -the first \fB\-screen\fP parameter will apply only to the immediately -preceeding \fB\-screen\fP parameter. -.TP 8 -.B \-[no]multimonitors or \-[no]multiplemonitors -Create a screen 0 that covers all monitors [the primary monitor] on a system with -multiple monitors. -This option is currently enabled by default in \fB\-multiwindow\fP mode. -.TP 8 -.B "\-screen \fIscreen_number\fP [\fIW\fP \fIH\fP [\fIX\fP \fIY\fP] | [[\fIW\fPx\fIH\fP[+\fIX\fP+\fIY\fP]][@\fIM\fP]] ] " -Create screen number -.I screen_number -and optionally specify it's -.I height, -.I width -and -.I initial position. -Additionally a -.I -monitor number -(which count from 1) can be specified to place the screen on, -at which point, all coordinates become relative to that monitor. -Screen numbers must be contiguous starting from zero and cannot be duplicated. - -Examples: - -.I " -screen 0 @1 ; on 1st monitor using its full resolution (the default)" - -.I " -screen 0 800x600+100+100@2 ; on 2nd monitor offset 100,100 size 800x600" - -.I " -screen 0 1024x768@3 ; on 3rd monitor size 1024x768" - -.SH OPTIONS CONTROLLING THE APPEARANCE OF THE X SCREEN WINDOWS -These parameters only apply to windowed mode screens i.e. not -in \fB-multiwindow\fP or \fB-rootless\fP mode. -.TP 8 -.B "\-fullscreen" -The X server window takes the full screen, covering completely the -\fIWindows\fP desktop. -.TP 8 -.B \-nodecoration -Do not give the Cygwin/X window a \fIWindows\fP window border, title bar, -etc. -This parameter is ignored when the \fB\-fullscreen\fP parameter is specified. -.TP 8 -.B \-scrollbars -Alternative name for \fB\-resize=scrollbars\fP. - -.SH OPTIONS CONTROLLING RESIZE BEHAVIOUR -.TP 8 -.B \-resize[=none|scrollbars|randr] -Select the resize mode of an X screen. - -.RS -.IP \fB\-resize=none\fP 8 -(default). The screen is not resizable. - -In windowed mode, if the window has decorations, a fixed frame is used. - -.IP \fB\-resize=scrollbars\fP 8 -The screen window is resizeable, but the screen is not resizable. - -In windowed mode, if the window has decorations, a resizing frame is used. -Scrollbars are drawn when needed to allow the entire X screen -to viewed by adjusting them. - -This also permits screens bigger than the \fIWindows\fP virtual desktop to be used. - -This parameter is ignored in \fB-multiwindow\fP or \fB-rootless\fP mode. -Alternative name is \fB\-scrollbars\fP. - -.IP \fB\-resize=randr\fP 8 -The screen is resizable and the screen window is resizeable. - -In windowed mode, if the window has decorations, a resizing frame is used. - -Resizing the \fIWindows\fP window will use the RANDR extension to change -the size of the X screen. Likewise, changing the size of -the X screen using the RANDR extension will cause the size -of the \fIWindows\fP window containing the X screen to be changed. - -In \fB-multiwindow\fP or \fB-rootless\fP mode, if the X screen is -of the same dimensions as a Windows monitor or the virtual desktop, -the X server will respond to the WM_DISPLAYCHANGED sent when those -dimensions change by resizing the X screen. Changing the size -of the X screen using the RANDR extension is not permitted. - -The maximum dimensions of the screen are the dimensions of the \fIWindows\fP virtual desktop. - -.IP \fB\--resize\fP 8 -on its own is equivalent to \fB\--resize=randr\fP -.RE - -.SH OPTIONS CONTROLLING WINDOWS INTEGRATION -.TP 8 -.B \-[no]clipboard -Enables [disables] the integration between the Cygwin/X clipboard and -\fIWindows\fP clipboard. The default is enabled. -.TP 8 -.B "\-emulate3buttons [\fItimeout\fP]" -Emulate a three button mouse; pressing both buttons within -.I timeout -milliseconds causes an emulated middle button press. The default -.I timeout -is 50 milliseconds. Note that most mice with scroll wheel have middle -button functionality, usually you will need this option only if you have -a two button mouse without scroll wheel. -.TP 8 -.B \-[no]keyhook -Enable [disable] a low-level keyboard hook for catching -special keypresses like Menu and Alt+Tab and passing them to the X -Server instead of letting \fIWindows\fP handle them. -.TP 8 -.B \-lesspointer -Normally the \fIWindows\fP mouse cursor is hidden when the mouse is -over an active Cygwin/X window. This option causes the mouse cursor -also to be hidden when it is over an inactive Cygwin/X window. This -prevents the \fIWindows\fP mouse cursor from being drawn on top of the X -cursor. -This parameter has no effect unless \fB-swcursor\fP is also specified. -.TP 8 -.B \-swcursor -Disable the usage of the \fIWindows\fP cursor and use the X11 software cursor instead. -.TP 8 -.B \-[no]trayicon -Do not create a tray icon. Default is to create one -icon per screen. You can globally disable tray icons with -\fB\-notrayicon\fP, then enable it for specific screens with -\fB\-trayicon\fP for those screens. -.TP 8 -.B \-nounicodeclipboard -Do not use Unicode clipboard even if on a NT-based platform. -.TP 8 -.B \-[no]unixkill -Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a -signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination -is disabled by default. -.TP 8 -.B \-[no]winkill -Enable or disable the \fIAlt-F4\fP key combination as a signal to exit the -X Server. -The \fIAlt-F4\fP key combination is enabled by default. - -.SH DRAWING ENGINE OPTIONS -.TP 8 -.B "\-clipupdates \fInum_boxes\fP" -Specify an optional threshold, above which the regions in a shadow -update operation will be collected into a GDI clipping region. The -clipping region is then used to do a single bit block transfer that is -constrained to the updated area by the clipping region. There is some -overhead involved in creating, installing, destroying, and removing -the clipping region, thus there may not be much benefit for a small -number of boxes (less than 10). It is even possible that this -functionality does not provide a benefit at any number of boxes; we -can only determine the usefulness of this feature through testing. -This option probably has limited effect on current \fIWindows\fP versions -as they already perform GDI batching. -This parameter works in conjunction with engines 1, 2, and 4 (Shadow -GDI, Shadow DirectDraw, and Shadow DirectDraw Non-Locking, -respectively). -.TP 8 -.B "\-engine \fIengine_type_id\fP" -This option, which is intended for Cygwin/X developers, -overrides the server's automatically selected drawing engine type. This -parameter will be ignored if the specified drawing engine type is not -supported on the current system. - -Default behavior is to select the drawing engine with optimum performance that -supports the specified depth and window configuration. - -The engine type ids are: -.RS -.IP 1 4 -Shadow GDI -.IP 2 4 -Shadow DirectDraw -.IP 4 4 -Shadow DirectDraw Non-Locking -.IP 8 4 -Primary DirectDraw (unsupported, obsolete) -.IP 16 4 -Native GDI (unsupported, experimental and barely functional) -.RE - -.SH FULLSCREEN OPTIONS -.TP 8 -.B "\-depth \fIdepth\fP" -Specify the color depth, in bits per pixel, to use when running in -fullscreen with a DirectDraw engine. This parameter is ignored if -\fB\-fullscreen\fP is not specified. -.TP 8 -.B "\-refresh \fIrate_in_Hz\fP" -Specify an optional refresh rate to use when running in -fullscreen with a DirectDraw engine. This parameter is ignored if -\fB\-fullscreen\fP is not specified. - -.SH MISCELLANEOUS OPTIONS -See also the normal server options described in the \fIXserver(1)\fP -manual page - -.TP 8 -.B \-help -Write a help text listing supported command line options and their description to the console. -.TP 8 -.B \-ignoreinput -Ignore keyboard and mouse input. This is usually only used for testing -and debugging purposes. -.TP 8 -.B "\-logfile \fIfilename\fP" -Change the server log file from the default of \fI -__logdir__/XWin.n.log\fP, -where \fIn\fP is the display number of the XWin server, to \fIfilename\fP. -.TP 8 -.B "\-logverbose \fIlevel\fP" -Control the degree of verbosity of the log messages with the integer -parameter \fIlevel\fP. For \fIlevel\fP=0 only fatal errors are -reported, for \fIlevel\fP=1 simple information about -configuration is also given, for \fIlevel\fP=2 (default) -additional runtime information is recorded -and for \fIlevel\fP=3 detailed log -information (including trace and debug output) is produced. Bigger -values will yield a still more detailed debug output. -.TP 8 -.B \-silent-dup-error -If another instance of \fIXWin\fP with the same display number is found running, -exit silently and don't display any error message. -.TP 8 -.B "\-xkblayout \fIlayout\fP" -.TP 8 -.B "\-xkbmodel \fImodel\fP" -.TP 8 -.B "\-xkboptions \fIoption\fP" -.TP 8 -.B "\-xkbrules \fIrule\fP" -.TP 8 -.B "\-xkbvariant \fIvariant\fp" -These options configure the xkeyboard extension to load -a particular keyboard map as the X server starts. The behavior is similar -to the \fIsetxkbmap\fP program. The layout data is located at \fI -__datadir__/X11/xkb/\fP. Additional information is found in the -README files therein and in the man page of \fIsetxkbmap\fP. For example -in order to load a German layout for a pc105 keyboard one uses -the options: -.br -.I " \-xkblayout de \-xkbmodel pc105" - -Alternatively one may use the \fIsetxkbmap\fP program after \fIXWin\fP is -running. - -The default is to select a configuration matching your current layout as -reported by \fIWindows\fP, if known, or the default X server configuration -if no matching keyboard configuration was found. - -.SH UNDOCUMENTED OPTIONS -These options are undocumented. Do not use them. - -.TP 8 -.B \-emulatepseudo -Create a depth 8 PseudoColor visual when running in depths 15, 16, 24, -or 32, collectively known as TrueColor depths. -Color map manipulation is not supported, so the PseudoColor visual will -not have the correct colors. -This option is intended to allow applications which only work with a depth 8 -visual to operate in TrueColor modes. -.TP 8 -.B \-internalwm -Run the internal window manager. - -.SH LOG FILE -As it runs \fIXWin\fP writes messages indicating the most relevant events -to the console -from which it was called and to a log file that by default is located at \fI -__logdir__/XWin.0.log\fP. This file is mainly for debugging purposes. - - -.SH PREFERENCES FILE -On startup \fIXWin\fP looks for the file \fI$HOME/.XWinrc\fP or, if -the previous file does not exist, \fI -__sysconfdir__/X11/system.XWinrc\fP. \fI.XWinrc\fP allows setting -preferences for the following: -.br -* To include items into the menu associated with the \fIXWin\fP icon -which is in the \fIWindows\fP system tray. This functions in all -modes that have a tray icon. -.br -* To include items in the system menu which is associated with the \fIWindows\fP -window that \fIXWin -multiwindow\fP produces for each top-level X -window, in both the generic case and for particular programs. -.br -* To change the icon that is associated to the \fIWindows\fP window that -\fIXWin -multiwindow\fP produces for each top-level X-window. -.br -* To change the style that is associated to the \fIWindows\fP window that -\fXWin I-multiwindow\fP produces for each top-level X window. -.PP -The format of the \fI.XWinrc\fP file is given in the man page XWinrc(5). - -.SH EXAMPLES -Need some examples - - -.SH "SEE ALSO" -X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1), XWinrc(__filemansuffix__), setxkbmap(1) - - -.SH BUGS -.I XWin -and this man page still have many limitations. - -The \fIXWin\fP software is continuously developing; it is therefore possible that -this man page is not up to date. It is always prudent to -look also at the output of \fIXWin -help\fP in order to -check the options that are operative. - - -.SH AUTHORS -This list is by no means complete, but direct contributors to the -Cygwin/X project include (in alphabetical order by last name): Stuart -Adamson, Michael Bax, Jehan Bing, Lev Bishop, Dr. Peter Busch, Biju G -C, Robert Collins, Nick Crabtree, Early Ehlinger, Christopher Faylor, -John Fortin, Brian Genisio, Fabrizio Gennari, Alexander Gottwald, Ralf -Habacker, Colin Harrison, Matthieu Herrb, Alan Hourihane, Pierre A -Humblet, Harold L Hunt II, Dakshinamurthy Karra, Joe Krahn, -Paul Loewenstein, Kensuke Matsuzaki, -Takuma Murakami, Earle F. Philhower III, Benjamin Riefenstahl, Yaakov Selkowitz, -Suhaib Siddiqi, Jack Tanner, Jon Turney and Nicholas Wourms. +.TH XWIN 1 __vendorversion__
+.SH NAME
+XWin \- X Server for the Cygwin environment on Microsoft Windows
+
+
+.SH SYNOPSIS
+.B XWin
+[ options ] ...
+
+
+.SH DESCRIPTION
+\fIXWin\fP is an X Server for the X Window System on the Cygwin environment
+running on Microsoft Windows.
+
+
+.SH MODES
+\fIXWin\fP can operate in 3 different modes:
+.br
+* \fISingle Window\fP: This is the default mode. Each X screen
+appears as a single \fIWindows\fP window and all X windows are contained
+within this window.
+(In X terminology, the \fIWindows\fP window contains the root window for
+the screen)
+.br
+* \fIMulti-Window\fP: In this mode \fIXWin\fP uses its own integrated
+window manager in order to handle the top-level X windows, in such a
+way that they appear as normal \fIWindows\fP windows.
+.br
+* \fIRootless\fP: In this mode the X server works in a window
+containing the whole screen but this root window (traditionally covered with an X hatch
+pattern) is hidden from view, so only top-level X windows are seen.
+
+.SH OPTIONS
+In addition to the normal server options described in the \fIXserver(1)\fP
+manual page, \fIXWin\fP accepts the following command line switches,
+\fIall\fP of which are optional:
+
+.SH OPTIONS CONTROLLING WINDOWING MODE
+Only one of these options may be specified.
+.TP 8
+.B (default)
+Windowed or rooted mode.
+Each X screen appears as a single \fIWindows\fP window and all X windows are
+contained within those windows.
+.TP 8
+.B \-multiwindow
+Each top-level X window appears in its own \fIWindows\fP window.
+Also start the integrated \fIWindows\fP-based window manager.
+.TP 8
+.B \-rootless
+Run the server in rootless mode.
+The X server works on a window covering the whole screen but the root window
+is hidden from view.
+.TP 8
+.B \-mwextwm
+Experimental.
+The mode combines \fB\-rootless\fP mode drawing with native \fIWindows\fP
+window frames managed by the experimental external window manager \fIxwinwm\fP.
+.PP
+\fBNOTE:\fP \fI-multiwindow\fP mode uses its own internal window manager.
+All other modes require an external window manager in order to move, resize, and perform other
+operations on the individual X windows.
+
+.SH OPTIONS FOR SPECIFYING X SCREENS
+An X display may be composed of multiple screens.
+The default behaviour is to create a single screen 0 that is roughly the
+size of useful area of the primary monitor (allowing for any window
+decorations and the task-bar).
+
+Screen specific parameters can be applied as a
+default to all screens by placing those screen specific parameters
+before any \fB\-screen\fP parameter. Screen specific parameters placed after
+the first \fB\-screen\fP parameter will apply only to the immediately
+preceeding \fB\-screen\fP parameter.
+.TP 8
+.B \-[no]multimonitors or \-[no]multiplemonitors
+Create a screen 0 that covers all monitors [the primary monitor] on a system with
+multiple monitors.
+This option is currently enabled by default in \fB\-multiwindow\fP mode.
+.TP 8
+.B "\-screen \fIscreen_number\fP [\fIW\fP \fIH\fP [\fIX\fP \fIY\fP] | [[\fIW\fPx\fIH\fP[+\fIX\fP+\fIY\fP]][@\fIM\fP]] ] "
+Create screen number
+.I screen_number
+and optionally specify it's
+.I height,
+.I width
+and
+.I initial position.
+Additionally a
+.I
+monitor number
+(which count from 1) can be specified to place the screen on,
+at which point, all coordinates become relative to that monitor.
+Screen numbers must be contiguous starting from zero and cannot be duplicated.
+
+Examples:
+
+.I " -screen 0 @1 ; on 1st monitor using its full resolution (the default)"
+
+.I " -screen 0 800x600+100+100@2 ; on 2nd monitor offset 100,100 size 800x600"
+
+.I " -screen 0 1024x768@3 ; on 3rd monitor size 1024x768"
+
+.SH OPTIONS CONTROLLING THE APPEARANCE OF THE X SCREEN WINDOWS
+These parameters only apply to windowed mode screens i.e. not
+in \fB-multiwindow\fP or \fB-rootless\fP mode.
+.TP 8
+.B "\-fullscreen"
+The X server window takes the full screen, covering completely the
+\fIWindows\fP desktop.
+Currently \fB\-fullscreen\fP may only be applied to one X screen.
+.TP 8
+.B \-nodecoration
+Do not give the Cygwin/X window a \fIWindows\fP window border, title bar,
+etc.
+This parameter is ignored when the \fB\-fullscreen\fP parameter is specified.
+.TP 8
+.B \-scrollbars
+Alternative name for \fB\-resize=scrollbars\fP.
+
+.SH OPTIONS CONTROLLING RESIZE BEHAVIOUR
+.TP 8
+.B \-resize[=none|scrollbars|randr]
+Select the resize mode of an X screen.
+
+.RS
+.IP \fB\-resize=none\fP 8
+(default). The screen is not resizable.
+
+In windowed mode, if the window has decorations, a fixed frame is used.
+
+.IP \fB\-resize=scrollbars\fP 8
+The screen window is resizeable, but the screen is not resizable.
+
+In windowed mode, if the window has decorations, a resizing frame is used.
+Scrollbars are drawn when needed to allow the entire X screen
+to viewed by adjusting them.
+
+This also permits screens bigger than the \fIWindows\fP virtual desktop to be used.
+
+This parameter is ignored in \fB-multiwindow\fP or \fB-rootless\fP mode.
+Alternative name is \fB\-scrollbars\fP.
+
+.IP \fB\-resize=randr\fP 8
+The screen is resizable and the screen window is resizeable.
+
+In windowed mode, if the window has decorations, a resizing frame is used.
+
+Resizing the \fIWindows\fP window will use the RANDR extension to change
+the size of the X screen. Likewise, changing the size of
+the X screen using the RANDR extension will cause the size
+of the \fIWindows\fP window containing the X screen to be changed.
+
+In \fB-multiwindow\fP or \fB-rootless\fP mode, if the X screen is
+of the same dimensions as a Windows monitor or the virtual desktop,
+the X server will respond to the WM_DISPLAYCHANGED sent when those
+dimensions change by resizing the X screen. Changing the size
+of the X screen using the RANDR extension is not permitted.
+
+The maximum dimensions of the screen are the dimensions of the \fIWindows\fP virtual desktop.
+
+.IP \fB\--resize\fP 8
+on its own is equivalent to \fB\--resize=randr\fP
+.RE
+
+.SH OPTIONS CONTROLLING WINDOWS INTEGRATION
+.TP 8
+.B \-[no]clipboard
+Enables [disables] the integration between the Cygwin/X clipboard and
+\fIWindows\fP clipboard. The default is enabled.
+.TP 8
+.B "\-emulate3buttons [\fItimeout\fP]"
+Emulate a three button mouse; pressing both buttons within
+.I timeout
+milliseconds causes an emulated middle button press. The default
+.I timeout
+is 50 milliseconds. Note that most mice with scroll wheel have middle
+button functionality, usually you will need this option only if you have
+a two button mouse without scroll wheel.
+.TP 8
+.B \-[no]keyhook
+Enable [disable] a low-level keyboard hook for catching
+special keypresses like Menu and Alt+Tab and passing them to the X
+Server instead of letting \fIWindows\fP handle them.
+.TP 8
+.B \-lesspointer
+Normally the \fIWindows\fP mouse cursor is hidden when the mouse is
+over an active Cygwin/X window. This option causes the mouse cursor
+also to be hidden when it is over an inactive Cygwin/X window. This
+prevents the \fIWindows\fP mouse cursor from being drawn on top of the X
+cursor.
+This parameter has no effect unless \fB-swcursor\fP is also specified.
+.TP 8
+.B \-swcursor
+Disable the usage of the \fIWindows\fP cursor and use the X11 software cursor instead.
+.TP 8
+.B \-[no]trayicon
+Do not create a tray icon. Default is to create one
+icon per screen. You can globally disable tray icons with
+\fB\-notrayicon\fP, then enable it for specific screens with
+\fB\-trayicon\fP for those screens.
+.TP 8
+.B \-nounicodeclipboard
+Do not use Unicode clipboard even if on a NT-based platform.
+.TP 8
+.B \-[no]unixkill
+Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a
+signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination
+is disabled by default.
+.TP 8
+.B \-[no]winkill
+Enable or disable the \fIAlt-F4\fP key combination as a signal to exit the
+X Server.
+The \fIAlt-F4\fP key combination is enabled by default.
+
+.SH DRAWING ENGINE OPTIONS
+.TP 8
+.B "\-clipupdates \fInum_boxes\fP"
+Specify an optional threshold, above which the regions in a shadow
+update operation will be collected into a GDI clipping region. The
+clipping region is then used to do a single bit block transfer that is
+constrained to the updated area by the clipping region. There is some
+overhead involved in creating, installing, destroying, and removing
+the clipping region, thus there may not be much benefit for a small
+number of boxes (less than 10). It is even possible that this
+functionality does not provide a benefit at any number of boxes; we
+can only determine the usefulness of this feature through testing.
+This option probably has limited effect on current \fIWindows\fP versions
+as they already perform GDI batching.
+This parameter works in conjunction with engines 1, 2, and 4 (Shadow
+GDI, Shadow DirectDraw, and Shadow DirectDraw Non-Locking,
+respectively).
+.TP 8
+.B "\-engine \fIengine_type_id\fP"
+This option, which is intended for Cygwin/X developers,
+overrides the server's automatically selected drawing engine type. This
+parameter will be ignored if the specified drawing engine type is not
+supported on the current system.
+
+Default behavior is to select the drawing engine with optimum performance that
+supports the specified depth and window configuration.
+
+The engine type ids are:
+.RS
+.IP 1 4
+Shadow GDI
+.IP 2 4
+Shadow DirectDraw
+.IP 4 4
+Shadow DirectDraw Non-Locking
+.IP 8 4
+Primary DirectDraw (unsupported, obsolete)
+.IP 16 4
+Native GDI (unsupported, experimental and barely functional)
+.RE
+
+.SH FULLSCREEN OPTIONS
+.TP 8
+.B "\-depth \fIdepth\fP"
+Specify the color depth, in bits per pixel, to use when running in
+fullscreen with a DirectDraw engine. This parameter is ignored if
+\fB\-fullscreen\fP is not specified.
+.TP 8
+.B "\-refresh \fIrate_in_Hz\fP"
+Specify an optional refresh rate to use when running in
+fullscreen with a DirectDraw engine. This parameter is ignored if
+\fB\-fullscreen\fP is not specified.
+
+.SH MISCELLANEOUS OPTIONS
+See also the normal server options described in the \fIXserver(1)\fP
+manual page
+
+.TP 8
+.B \-help
+Write a help text listing supported command line options and their description to the console.
+.TP 8
+.B \-ignoreinput
+Ignore keyboard and mouse input. This is usually only used for testing
+and debugging purposes.
+.TP 8
+.B "\-logfile \fIfilename\fP"
+Change the server log file from the default of \fI
+__logdir__/XWin.n.log\fP,
+where \fIn\fP is the display number of the XWin server, to \fIfilename\fP.
+.TP 8
+.B "\-logverbose \fIlevel\fP"
+Control the degree of verbosity of the log messages with the integer
+parameter \fIlevel\fP. For \fIlevel\fP=0 only fatal errors are
+reported, for \fIlevel\fP=1 simple information about
+configuration is also given, for \fIlevel\fP=2 (default)
+additional runtime information is recorded
+and for \fIlevel\fP=3 detailed log
+information (including trace and debug output) is produced. Bigger
+values will yield a still more detailed debug output.
+.TP 8
+.B \-silent-dup-error
+If another instance of \fIXWin\fP with the same display number is found running,
+exit silently and don't display any error message.
+.TP 8
+.B "\-xkblayout \fIlayout\fP"
+.TP 8
+.B "\-xkbmodel \fImodel\fP"
+.TP 8
+.B "\-xkboptions \fIoption\fP"
+.TP 8
+.B "\-xkbrules \fIrule\fP"
+.TP 8
+.B "\-xkbvariant \fIvariant\fp"
+These options configure the xkeyboard extension to load
+a particular keyboard map as the X server starts. The behavior is similar
+to the \fIsetxkbmap\fP program. The layout data is located at \fI
+__datadir__/X11/xkb/\fP. Additional information is found in the
+README files therein and in the man page of \fIsetxkbmap\fP. For example
+in order to load a German layout for a pc105 keyboard one uses
+the options:
+.br
+.I " \-xkblayout de \-xkbmodel pc105"
+
+Alternatively one may use the \fIsetxkbmap\fP program after \fIXWin\fP is
+running.
+
+The default is to select a configuration matching your current layout as
+reported by \fIWindows\fP, if known, or the default X server configuration
+if no matching keyboard configuration was found.
+
+.SH UNDOCUMENTED OPTIONS
+These options are undocumented. Do not use them.
+
+.TP 8
+.B \-emulatepseudo
+Create a depth 8 PseudoColor visual when running in depths 15, 16, 24,
+or 32, collectively known as TrueColor depths.
+Color map manipulation is not supported, so the PseudoColor visual will
+not have the correct colors.
+This option is intended to allow applications which only work with a depth 8
+visual to operate in TrueColor modes.
+.TP 8
+.B \-internalwm
+Run the internal window manager.
+
+.SH LOG FILE
+As it runs \fIXWin\fP writes messages indicating the most relevant events
+to the console
+from which it was called and to a log file that by default is located at \fI
+__logdir__/XWin.0.log\fP. This file is mainly for debugging purposes.
+
+
+.SH PREFERENCES FILE
+On startup \fIXWin\fP looks for the file \fI$HOME/.XWinrc\fP or, if
+the previous file does not exist, \fI
+__sysconfdir__/X11/system.XWinrc\fP. \fI.XWinrc\fP allows setting
+preferences for the following:
+.br
+* To include items into the menu associated with the \fIXWin\fP icon
+which is in the \fIWindows\fP system tray. This functions in all
+modes that have a tray icon.
+.br
+* To include items in the system menu which is associated with the \fIWindows\fP
+window that \fIXWin -multiwindow\fP produces for each top-level X
+window, in both the generic case and for particular programs.
+.br
+* To change the icon that is associated to the \fIWindows\fP window that
+\fIXWin -multiwindow\fP produces for each top-level X-window.
+.br
+* To change the style that is associated to the \fIWindows\fP window that
+\fXWin I-multiwindow\fP produces for each top-level X window.
+.PP
+The format of the \fI.XWinrc\fP file is given in the man page XWinrc(5).
+
+.SH EXAMPLES
+Need some examples
+
+
+.SH "SEE ALSO"
+X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1), XWinrc(__filemansuffix__), setxkbmap(1)
+
+
+.SH BUGS
+.I XWin
+and this man page still have many limitations.
+
+The \fIXWin\fP software is continuously developing; it is therefore possible that
+this man page is not up to date. It is always prudent to
+look also at the output of \fIXWin -help\fP in order to
+check the options that are operative.
+
+
+.SH AUTHORS
+This list is by no means complete, but direct contributors to the
+Cygwin/X project include (in alphabetical order by last name): Stuart
+Adamson, Michael Bax, Jehan Bing, Lev Bishop, Dr. Peter Busch, Biju G
+C, Robert Collins, Nick Crabtree, Early Ehlinger, Christopher Faylor,
+John Fortin, Brian Genisio, Fabrizio Gennari, Alexander Gottwald, Ralf
+Habacker, Colin Harrison, Matthieu Herrb, Alan Hourihane, Pierre A
+Humblet, Harold L Hunt II, Dakshinamurthy Karra, Joe Krahn,
+Paul Loewenstein, Kensuke Matsuzaki,
+Takuma Murakami, Earle F. Philhower III, Benjamin Riefenstahl, Yaakov Selkowitz,
+Suhaib Siddiqi, Jack Tanner, Jon Turney and Nicholas Wourms.
diff --git a/xorg-server/hw/xwin/win.h b/xorg-server/hw/xwin/win.h index 2dad44778..614c6b23f 100644 --- a/xorg-server/hw/xwin/win.h +++ b/xorg-server/hw/xwin/win.h @@ -170,7 +170,6 @@ typedef int pid_t; #include "input.h"
#include "mipointer.h"
#include "X11/keysym.h"
-#include "mibstore.h"
#include "micoord.h"
#include "dix.h"
#include "miline.h"
diff --git a/xorg-server/hw/xwin/winclipboardxevents.c b/xorg-server/hw/xwin/winclipboardxevents.c index 00bf90a28..b3ed5eba5 100644 --- a/xorg-server/hw/xwin/winclipboardxevents.c +++ b/xorg-server/hw/xwin/winclipboardxevents.c @@ -830,7 +830,7 @@ winClipboardFlushXEvents (HWND hwnd, break;
case MappingNotify:
- XRefreshKeyboardMapping((XMappingEvent *)&event);
+ XRefreshKeyboardMapping((XMappingEvent *)&event);
break;
default:
diff --git a/xorg-server/hw/xwin/winmonitors.c b/xorg-server/hw/xwin/winmonitors.c index 876d23437..f78734b9b 100644 --- a/xorg-server/hw/xwin/winmonitors.c +++ b/xorg-server/hw/xwin/winmonitors.c @@ -1,73 +1,73 @@ -/* - -Copyright 1993, 1998 The Open Group -Copyright (C) Colin Harrison 2005-2008 - -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. - -*/ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif - -#include "win.h" -#define COMPILE_MULTIMON_STUBS -#include <multimon.h> -#include "winmonitors.h" - -/* - * getMonitorInfo - callback function used to return information from the enumeration of monitors attached - */ - -static -wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data) -{ - struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data; - // only get data for monitor number specified in <data> - data->monitorNum++; - if (data->monitorNum == data->requestedMonitor) - { - data->bMonitorSpecifiedExists = TRUE; - data->monitorOffsetX = rect->left; - data->monitorOffsetY = rect->top; - data->monitorHeight = rect->bottom - rect->top; - data->monitorWidth = rect->right - rect->left; - return FALSE; - } - return TRUE; -} - -Bool QueryMonitor(int index, struct GetMonitorInfoData *data) -{ - /* prepare data */ - if (data == NULL) - return FALSE; - memset(data, 0, sizeof(*data)); - data->requestedMonitor = index; - - /* query information */ - xEnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data); - - return TRUE; -} +/*
+
+Copyright 1993, 1998 The Open Group
+Copyright (C) Colin Harrison 2005-2008
+
+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.
+
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include "win.h"
+#define COMPILE_MULTIMON_STUBS
+#include <multimon.h>
+#include "winmonitors.h"
+
+/*
+ * getMonitorInfo - callback function used to return information from the enumeration of monitors attached
+ */
+
+static
+wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data)
+{
+ struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data;
+ // only get data for monitor number specified in <data>
+ data->monitorNum++;
+ if (data->monitorNum == data->requestedMonitor)
+ {
+ data->bMonitorSpecifiedExists = TRUE;
+ data->monitorOffsetX = rect->left;
+ data->monitorOffsetY = rect->top;
+ data->monitorHeight = rect->bottom - rect->top;
+ data->monitorWidth = rect->right - rect->left;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+Bool QueryMonitor(int index, struct GetMonitorInfoData *data)
+{
+ /* prepare data */
+ if (data == NULL)
+ return FALSE;
+ memset(data, 0, sizeof(*data));
+ data->requestedMonitor = index;
+
+ /* query information */
+ xEnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data);
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winmultiwindowicons.c b/xorg-server/hw/xwin/winmultiwindowicons.c index 3186cd7a0..853d63864 100644 --- a/xorg-server/hw/xwin/winmultiwindowicons.c +++ b/xorg-server/hw/xwin/winmultiwindowicons.c @@ -37,8 +37,6 @@ #include "winprefs.h"
#include "propertyst.h"
-
-#include "propertyst.h"
#include "windowstr.h"
@@ -632,6 +630,7 @@ void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon) *pIcon = hIcon;
else
winDestroyIcon(hIcon);
+
if (pSmallIcon)
*pSmallIcon = hSmallIcon;
else
@@ -640,7 +639,7 @@ void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon) void winDestroyIcon(HICON hIcon)
{
- /* Delete the icon if its not the default */
+ /* Delete the icon if its not one of the application defaults or an override */
if (hIcon &&
hIcon != g_hIconX &&
hIcon != g_hSmallIconX &&
diff --git a/xorg-server/hw/xwin/winmultiwindowwindow.c b/xorg-server/hw/xwin/winmultiwindowwindow.c index 1e95fecc4..ceb8dff04 100644 --- a/xorg-server/hw/xwin/winmultiwindowwindow.c +++ b/xorg-server/hw/xwin/winmultiwindowwindow.c @@ -586,7 +586,7 @@ winDestroyWindowsWindow (WindowPtr pWin) BOOL oldstate = winInDestroyWindowsWindow;
HICON hIcon;
HICON hIconSm;
-
+
#if CYGMULTIWINDOW_DEBUG
winDebug ("winDestroyWindowsWindow\n");
#endif
@@ -602,6 +602,7 @@ winDestroyWindowsWindow (WindowPtr pWin) hIconSm = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0);
SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, NULL);
+
/* Destroy the Windows window */
DestroyWindow (pWinPriv->hWnd);
diff --git a/xorg-server/hw/xwin/winmultiwindowwm.c b/xorg-server/hw/xwin/winmultiwindowwm.c index f178967e1..fae132329 100644 --- a/xorg-server/hw/xwin/winmultiwindowwm.c +++ b/xorg-server/hw/xwin/winmultiwindowwm.c @@ -1656,6 +1656,7 @@ winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle) style = STYLE_NONE;
}
}
+
if (style & STYLE_TOPMOST) *zstyle = HWND_TOPMOST;
else if (style & STYLE_MAXIMIZE) maxmin = (hint & ~HINT_MIN) | HINT_MAX;
else if (style & STYLE_MINIMIZE) maxmin = (hint & ~HINT_MAX) | HINT_MIN;
diff --git a/xorg-server/hw/xwin/winpfbdd.c b/xorg-server/hw/xwin/winpfbdd.c index c6d0167ca..02f6ffc1f 100644 --- a/xorg-server/hw/xwin/winpfbdd.c +++ b/xorg-server/hw/xwin/winpfbdd.c @@ -1,674 +1,675 @@ -/* - *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" - - -/* - * Local function prototypes - */ - -static Bool -winAllocateFBPrimaryDD (ScreenPtr pScreen); - -static Bool -winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen); - -static Bool -winInitVisualsPrimaryDD (ScreenPtr pScreen); - -static Bool -winAdjustVideoModePrimaryDD (ScreenPtr pScreen); - -static Bool -winActivateAppPrimaryDD (ScreenPtr pScreen); - -static Bool -winHotKeyAltTabPrimaryDD (ScreenPtr pScreen); - - -/* - * Create a DirectDraw primary surface - */ - -static Bool -winAllocateFBPrimaryDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - HRESULT ddrval = DD_OK; - DDSURFACEDESC ddsd; - DDSURFACEDESC *pddsdPrimary = NULL; - DDSURFACEDESC *pddsdOffscreen = NULL; - RECT rcClient; - - winDebug ("winAllocateFBPrimaryDD\n"); - - /* Get client area location in screen coords */ - GetClientRect (pScreenPriv->hwndScreen, &rcClient); - MapWindowPoints (pScreenPriv->hwndScreen, - HWND_DESKTOP, - (LPPOINT)&rcClient, 2); - - /* Create a DirectDraw object, store the address at lpdd */ - ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL); - if (ddrval != DD_OK) - FatalError ("winAllocateFBPrimaryDD - Could not start DirectDraw\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; - } - - - winDebug ("winAllocateFBPrimaryDD - Created and initialized DD\n"); - - /* Are we windowed or fullscreen? */ - if (pScreenInfo->fFullScreen) - { - /* Full screen mode */ - ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2, - pScreenPriv->hwndScreen, - DDSCL_FULLSCREEN - | DDSCL_EXCLUSIVE); - if (FAILED (ddrval)) - FatalError ("winAllocateFBPrimaryDD - Could not set " - "cooperative level\n"); - - /* Change the video mode to the mode requested */ - ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2, - pScreenInfo->dwWidth, - pScreenInfo->dwHeight, - pScreenInfo->dwBPP, - pScreenInfo->dwRefreshRate, - 0); - if (FAILED (ddrval)) - FatalError ("winAllocateFBPrimaryDD - Could not set " - "full screen display mode\n"); - } - else - { - /* Windowed mode */ - ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2, - pScreenPriv->hwndScreen, - DDSCL_NORMAL); - if (FAILED (ddrval)) - FatalError ("winAllocateFBPrimaryDD - Could not set " - "cooperative level\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 = IDirectDraw2_CreateSurface (pScreenPriv->pdd2, - &ddsd, - &pScreenPriv->pddsPrimary, - NULL); - if (FAILED (ddrval)) - FatalError ("winAllocateFBPrimaryDD - Could not create primary " - "surface %08x\n", (unsigned int) ddrval); - - winDebug ("winAllocateFBPrimaryDD - Created primary\n"); - - /* Allocate a DD surface description for our screen privates */ - pddsdPrimary = pScreenPriv->pddsdPrimary - = malloc (sizeof (DDSURFACEDESC)); - if (pddsdPrimary == NULL) - FatalError ("winAllocateFBPrimaryDD - Could not allocate surface " - "description memory\n"); - ZeroMemory (pddsdPrimary, sizeof (*pddsdPrimary)); - pddsdPrimary->dwSize = sizeof (*pddsdPrimary); - - /* Describe the offscreen 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->pddsOffscreen, - NULL); - if (ddrval != DD_OK) - FatalError ("winAllocateFBPrimaryDD - Could not create shadow " - "surface\n"); - - winDebug ("winAllocateFBPrimaryDD - Created offscreen\n"); - - /* Allocate a DD surface description for our screen privates */ - pddsdOffscreen = pScreenPriv->pddsdOffscreen - = malloc (sizeof (DDSURFACEDESC)); - if (pddsdOffscreen == NULL) - FatalError ("winAllocateFBPrimaryDD - Could not allocate surface " - "description memory\n"); - ZeroMemory (pddsdOffscreen, sizeof (*pddsdOffscreen)); - pddsdOffscreen->dwSize = sizeof (*pddsdOffscreen); - - winDebug ("winAllocateFBPrimaryDD - Locking primary\n"); - - /* Lock the primary surface */ - ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsPrimary, - pScreenInfo->fFullScreen ? NULL:&rcClient, - pddsdPrimary, - DDLOCK_WAIT, - NULL); - if (ddrval != DD_OK || pddsdPrimary->lpSurface == NULL) - FatalError ("winAllocateFBPrimaryDD - Could not lock " - "primary surface\n"); - - winDebug ("winAllocateFBPrimaryDD - Locked primary\n"); - - /* We don't know how to deal with anything other than RGB */ - if (!(pddsdPrimary->ddpfPixelFormat.dwFlags & DDPF_RGB)) - FatalError ("winAllocateFBPrimaryDD - Color format other than RGB\n"); - - /* Grab the pitch from the surface desc */ - pScreenInfo->dwStride = (pddsdPrimary->u1.lPitch * 8) - / pScreenInfo->dwBPP; - - /* Save the pointer to our surface memory */ - pScreenInfo->pfb = pddsdPrimary->lpSurface; - - /* Grab the color depth and masks from the surface description */ - pScreenPriv->dwRedMask = pddsdPrimary->ddpfPixelFormat.u2.dwRBitMask; - pScreenPriv->dwGreenMask = pddsdPrimary->ddpfPixelFormat.u3.dwGBitMask; - pScreenPriv->dwBlueMask = pddsdPrimary->ddpfPixelFormat.u4.dwBBitMask; - - winDebug ("winAllocateFBPrimaryDD - Returning\n"); - - return TRUE; -} - -static void -winFreeFBPrimaryDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Free the offscreen surface, if there is one */ - if (pScreenPriv->pddsOffscreen) - { - IDirectDrawSurface2_Unlock (pScreenPriv->pddsOffscreen, NULL); - IDirectDrawSurface2_Release (pScreenPriv->pddsOffscreen); - pScreenPriv->pddsOffscreen = NULL; - } - - /* Release the primary surface, if there is one */ - if (pScreenPriv->pddsPrimary) - { - IDirectDrawSurface2_Unlock (pScreenPriv->pddsPrimary, NULL); - IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary); - pScreenPriv->pddsPrimary = NULL; - } - - /* Free the DirectDraw object, if there is one */ - if (pScreenPriv->pdd) - { - IDirectDraw2_RestoreDisplayMode (pScreenPriv->pdd); - IDirectDraw2_Release (pScreenPriv->pdd); - pScreenPriv->pdd = NULL; - } - - /* Invalidate the ScreenInfo's fb pointer */ - pScreenInfo->pfb = NULL; -} - -static Bool -winInitScreenPrimaryDD(ScreenPtr pScreen) -{ - return winAllocateFBPrimaryDD(pScreen); -} - -/* - * Call the wrapped CloseScreen function. - * - * Free our resources and private structures. - */ - -static Bool -winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - Bool fReturn; - - ErrorF ("winCloseScreenPrimaryDD - 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); - - /* Delete the window property */ - RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP); - - winFreeFBPrimaryDD(pScreen); - - /* 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; - } - - /* Kill our screeninfo's pointer to the screen */ - pScreenInfo->pScreen = 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 -winInitVisualsPrimaryDD (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 > dwGreenBits && dwRedBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwRedBits; - else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwGreenBits; - else - pScreenPriv->dwBitsPerRGB = dwBlueBits; - - winDebug ("winInitVisualsPrimaryDD - Masks: %08x %08x %08x bpRGB: %d\n", - (unsigned int) pScreenPriv->dwRedMask, - (unsigned int) pScreenPriv->dwGreenMask, - (unsigned int) pScreenPriv->dwBlueMask, - (int) pScreenPriv->dwBitsPerRGB); - - /* Create a single visual according to the Windows screen depth */ - switch (pScreenInfo->dwDepth) - { - case 24: - case 16: - case 15: - if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth, - TrueColorMask, - pScreenPriv->dwBitsPerRGB, - TrueColor, - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask)) - { - ErrorF ("winInitVisualsPrimaryDD - " - "miSetVisualTypesAndMasks failed\n"); - return FALSE; - } - break; - - case 8: - winDebug ("winInitVisuals - Calling miSetVisualTypesAndMasks\n"); - if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth, - PseudoColorMask, - pScreenPriv->dwBitsPerRGB, - PseudoColor, - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask)) - { - ErrorF ("winInitVisualsPrimaryDD - " - "miSetVisualTypesAndMasks failed\n"); - return FALSE; - } - winDebug ("winInitVisualsPrimaryDD - Returned from " - "miSetVisualTypesAndMasks\n"); - break; - - default: - ErrorF ("winInitVisualsPrimaryDD - Unknown screen depth\n"); - return FALSE; - } - - winDebug ("winInitVisualsPrimaryDD - Returning\n"); - - return TRUE; -} - - -static Bool -winAdjustVideoModePrimaryDD (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 ("winAdjustVideoModePrimaryDD - 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->fFullScreen && - (pScreenInfo->dwBPP != WIN_DEFAULT_BPP))) - { - /* Otherwise, We'll use GDI's depth */ - pScreenInfo->dwBPP = dwBPP; - } - - /* Release our DC */ - ReleaseDC (NULL, hdc); - - return TRUE; -} - - -/* - * We need to blit our offscreen fb to - * the screen when we are activated, and we need to point - * the fb code back to the primary surface memory. - */ - -static Bool -winActivateAppPrimaryDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - RECT rcSrc, rcClient; - HRESULT ddrval = DD_OK; - - /* Check for errors */ - if (pScreenPriv == NULL - || pScreenPriv->pddsPrimary == NULL - || pScreenPriv->pddsOffscreen == NULL) - return FALSE; - - /* Check for do-nothing */ - if (!pScreenPriv->fActive) - return TRUE; - - /* We are activating */ - ddrval = IDirectDrawSurface2_IsLost (pScreenPriv->pddsOffscreen); - if (ddrval == DD_OK) - { - IDirectDrawSurface2_Unlock (pScreenPriv->pddsOffscreen, - NULL); - /* - * We don't check for an error from Unlock, because it - * doesn't matter if the Unlock failed. - */ - } - - /* Restore both surfaces, just cause I like it that way */ - IDirectDrawSurface2_Restore (pScreenPriv->pddsOffscreen); - IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary); - - /* Get client area in screen coords */ - GetClientRect (pScreenPriv->hwndScreen, &rcClient); - MapWindowPoints (pScreenPriv->hwndScreen, - HWND_DESKTOP, - (LPPOINT)&rcClient, 2); - - /* Setup a source rectangle */ - rcSrc.left = 0; - rcSrc.top = 0; - rcSrc.right = pScreenInfo->dwWidth; - rcSrc.bottom = pScreenInfo->dwHeight; - - ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary, - &rcClient, - pScreenPriv->pddsOffscreen, - &rcSrc, - DDBLT_WAIT, - NULL); - if (ddrval != DD_OK) - FatalError ("winActivateAppPrimaryDD () - Failed blitting offscreen " - "surface to primary surface %08x\n", (unsigned int) ddrval); - - /* Lock the primary surface */ - ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsPrimary, - &rcClient, - pScreenPriv->pddsdPrimary, - DDLOCK_WAIT, - NULL); - if (ddrval != DD_OK - || pScreenPriv->pddsdPrimary->lpSurface == NULL) - FatalError ("winActivateAppPrimaryDD () - Could not lock " - "primary surface\n"); - - /* Notify FB of the new memory pointer */ - winUpdateFBPointer (pScreen, - pScreenPriv->pddsdPrimary->lpSurface); - - /* - * Register the Alt-Tab combo as a hotkey so we can copy - * the primary framebuffer before the display mode changes - */ - RegisterHotKey (pScreenPriv->hwndScreen, 1, MOD_ALT, 9); - - return TRUE; -} - - -/* - * Handle the Alt+Tab hotkey. - * - * We need to save the primary fb to an offscreen fb when - * we get deactivated, and point the fb code at the offscreen - * fb for the duration of the deactivation. - */ - -static Bool -winHotKeyAltTabPrimaryDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - RECT rcClient, rcSrc; - HRESULT ddrval = DD_OK; - - winDebug ("\nwinHotKeyAltTabPrimaryDD\n\n"); - - /* Alt+Tab was pressed, we will lose focus very soon */ - pScreenPriv->fActive = FALSE; - - /* Check for error conditions */ - if (pScreenPriv->pddsPrimary == NULL - || pScreenPriv->pddsOffscreen == NULL) - return FALSE; - - /* Get client area in screen coords */ - GetClientRect (pScreenPriv->hwndScreen, &rcClient); - MapWindowPoints (pScreenPriv->hwndScreen, - HWND_DESKTOP, - (LPPOINT)&rcClient, 2); - - /* Did we loose the primary surface? */ - ddrval = IDirectDrawSurface2_IsLost (pScreenPriv->pddsPrimary); - if (ddrval == DD_OK) - { - ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsPrimary, - NULL); - if (FAILED (ddrval)) - FatalError ("winHotKeyAltTabPrimaryDD - Failed unlocking primary " - "surface\n"); - } - - /* Setup a source rectangle */ - rcSrc.left = 0; - rcSrc.top = 0; - rcSrc.right = pScreenInfo->dwWidth; - rcSrc.bottom = pScreenInfo->dwHeight; - - /* Blit the primary surface to the offscreen surface */ - ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsOffscreen, - NULL, /* should be rcDest */ - pScreenPriv->pddsPrimary, - NULL, - DDBLT_WAIT, - NULL); - if (ddrval == DDERR_SURFACELOST) - { - IDirectDrawSurface2_Restore (pScreenPriv->pddsOffscreen); - IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary); - - /* Blit the primary surface to the offscreen surface */ - ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsOffscreen, - NULL, - pScreenPriv->pddsPrimary, - NULL, - DDBLT_WAIT, - NULL); - if (FAILED (ddrval)) - FatalError ("winHotKeyAltTabPrimaryDD - Failed blitting primary " - "surface to offscreen surface: %08x\n", - (unsigned int) ddrval); - } - else - { - FatalError ("winHotKeyAltTabPrimaryDD - Unknown error from " - "Blt: %08dx\n", (unsigned int) ddrval); - } - - /* Lock the offscreen surface */ - ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsOffscreen, - NULL, - pScreenPriv->pddsdOffscreen, - DDLOCK_WAIT, - NULL); - if (ddrval != DD_OK - || pScreenPriv->pddsdPrimary->lpSurface == NULL) - FatalError ("winHotKeyAltTabPrimaryDD - Could not lock " - "offscreen surface\n"); - - /* Notify FB of the new memory pointer */ - winUpdateFBPointer (pScreen, - pScreenPriv->pddsdOffscreen->lpSurface); - - /* Unregister our hotkey */ - UnregisterHotKey (pScreenPriv->hwndScreen, 1); - - return TRUE; -} - - -/* Set engine specific functions */ -Bool -winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Set our pointers */ - pScreenPriv->pwinAllocateFB = winAllocateFBPrimaryDD; - pScreenPriv->pwinFreeFB = winFreeFBPrimaryDD; - pScreenPriv->pwinShadowUpdate = (winShadowUpdateProcPtr) (void (*)(void))NoopDDA; - pScreenPriv->pwinInitScreen = winInitScreenPrimaryDD; - pScreenPriv->pwinCloseScreen = winCloseScreenPrimaryDD; - pScreenPriv->pwinInitVisuals = winInitVisualsPrimaryDD; - pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModePrimaryDD; - if (pScreenInfo->fFullScreen) - pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen; - else - pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed; - pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB; - pScreenPriv->pwinBltExposedRegions = (winBltExposedRegionsProcPtr) (void (*)(void))NoopDDA; - pScreenPriv->pwinActivateApp = winActivateAppPrimaryDD; - pScreenPriv->pwinRedrawScreen = NULL; - pScreenPriv->pwinRealizeInstalledPalette = NULL; - pScreenPriv->pwinInstallColormap = NULL; - pScreenPriv->pwinStoreColors = NULL; - pScreenPriv->pwinCreateColormap = NULL; - pScreenPriv->pwinDestroyColormap = NULL; - pScreenPriv->pwinHotKeyAltTab = winHotKeyAltTabPrimaryDD; - pScreenPriv->pwinCreatePrimarySurface = (winCreatePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; - pScreenPriv->pwinReleasePrimarySurface = (winReleasePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; -#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"
+
+
+/*
+ * Local function prototypes
+ */
+
+static Bool
+winAllocateFBPrimaryDD (ScreenPtr pScreen);
+
+static Bool
+winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen);
+
+static Bool
+winInitVisualsPrimaryDD (ScreenPtr pScreen);
+
+static Bool
+winAdjustVideoModePrimaryDD (ScreenPtr pScreen);
+
+static Bool
+winActivateAppPrimaryDD (ScreenPtr pScreen);
+
+static Bool
+winHotKeyAltTabPrimaryDD (ScreenPtr pScreen);
+
+
+/*
+ * Create a DirectDraw primary surface
+ */
+
+static Bool
+winAllocateFBPrimaryDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HRESULT ddrval = DD_OK;
+ DDSURFACEDESC ddsd;
+ DDSURFACEDESC *pddsdPrimary = NULL;
+ DDSURFACEDESC *pddsdOffscreen = NULL;
+ RECT rcClient;
+
+ winDebug ("winAllocateFBPrimaryDD\n");
+
+ /* Get client area location in screen coords */
+ GetClientRect (pScreenPriv->hwndScreen, &rcClient);
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&rcClient, 2);
+
+ /* Create a DirectDraw object, store the address at lpdd */
+ ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL);
+ if (ddrval != DD_OK)
+ FatalError ("winAllocateFBPrimaryDD - Could not start DirectDraw\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;
+ }
+
+
+ winDebug ("winAllocateFBPrimaryDD - Created and initialized DD\n");
+
+ /* Are we windowed or fullscreen? */
+ if (pScreenInfo->fFullScreen)
+ {
+ /* Full screen mode */
+ ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
+ pScreenPriv->hwndScreen,
+ DDSCL_FULLSCREEN
+ | DDSCL_EXCLUSIVE);
+ if (FAILED (ddrval))
+ FatalError ("winAllocateFBPrimaryDD - Could not set "
+ "cooperative level\n");
+
+ /* Change the video mode to the mode requested */
+ ddrval = IDirectDraw2_SetDisplayMode (pScreenPriv->pdd2,
+ pScreenInfo->dwWidth,
+ pScreenInfo->dwHeight,
+ pScreenInfo->dwBPP,
+ pScreenInfo->dwRefreshRate,
+ 0);
+ if (FAILED (ddrval))
+ FatalError ("winAllocateFBPrimaryDD - Could not set "
+ "full screen display mode\n");
+ }
+ else
+ {
+ /* Windowed mode */
+ ddrval = IDirectDraw2_SetCooperativeLevel (pScreenPriv->pdd2,
+ pScreenPriv->hwndScreen,
+ DDSCL_NORMAL);
+ if (FAILED (ddrval))
+ FatalError ("winAllocateFBPrimaryDD - Could not set "
+ "cooperative level\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 = IDirectDraw2_CreateSurface (pScreenPriv->pdd2,
+ &ddsd,
+ &pScreenPriv->pddsPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ FatalError ("winAllocateFBPrimaryDD - Could not create primary "
+ "surface %08x\n", (unsigned int) ddrval);
+
+ winDebug ("winAllocateFBPrimaryDD - Created primary\n");
+
+ /* Allocate a DD surface description for our screen privates */
+ pddsdPrimary = pScreenPriv->pddsdPrimary
+ = malloc (sizeof (DDSURFACEDESC));
+ if (pddsdPrimary == NULL)
+ FatalError ("winAllocateFBPrimaryDD - Could not allocate surface "
+ "description memory\n");
+ ZeroMemory (pddsdPrimary, sizeof (*pddsdPrimary));
+ pddsdPrimary->dwSize = sizeof (*pddsdPrimary);
+
+ /* Describe the offscreen 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->pddsOffscreen,
+ NULL);
+ if (ddrval != DD_OK)
+ FatalError ("winAllocateFBPrimaryDD - Could not create shadow "
+ "surface\n");
+
+ winDebug ("winAllocateFBPrimaryDD - Created offscreen\n");
+
+ /* Allocate a DD surface description for our screen privates */
+ pddsdOffscreen = pScreenPriv->pddsdOffscreen
+ = malloc (sizeof (DDSURFACEDESC));
+ if (pddsdOffscreen == NULL)
+ FatalError ("winAllocateFBPrimaryDD - Could not allocate surface "
+ "description memory\n");
+ ZeroMemory (pddsdOffscreen, sizeof (*pddsdOffscreen));
+ pddsdOffscreen->dwSize = sizeof (*pddsdOffscreen);
+
+ winDebug ("winAllocateFBPrimaryDD - Locking primary\n");
+
+ /* Lock the primary surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsPrimary,
+ pScreenInfo->fFullScreen ? NULL:&rcClient,
+ pddsdPrimary,
+ DDLOCK_WAIT,
+ NULL);
+ if (ddrval != DD_OK || pddsdPrimary->lpSurface == NULL)
+ FatalError ("winAllocateFBPrimaryDD - Could not lock "
+ "primary surface\n");
+
+ winDebug ("winAllocateFBPrimaryDD - Locked primary\n");
+
+ /* We don't know how to deal with anything other than RGB */
+ if (!(pddsdPrimary->ddpfPixelFormat.dwFlags & DDPF_RGB))
+ FatalError ("winAllocateFBPrimaryDD - Color format other than RGB\n");
+
+ /* Grab the pitch from the surface desc */
+ pScreenInfo->dwStride = (pddsdPrimary->u1.lPitch * 8)
+ / pScreenInfo->dwBPP;
+
+ /* Save the pointer to our surface memory */
+ pScreenInfo->pfb = pddsdPrimary->lpSurface;
+
+ /* Grab the color depth and masks from the surface description */
+ pScreenPriv->dwRedMask = pddsdPrimary->ddpfPixelFormat.u2.dwRBitMask;
+ pScreenPriv->dwGreenMask = pddsdPrimary->ddpfPixelFormat.u3.dwGBitMask;
+ pScreenPriv->dwBlueMask = pddsdPrimary->ddpfPixelFormat.u4.dwBBitMask;
+
+ winDebug ("winAllocateFBPrimaryDD - Returning\n");
+
+ return TRUE;
+}
+
+static void
+winFreeFBPrimaryDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Free the offscreen surface, if there is one */
+ if (pScreenPriv->pddsOffscreen)
+ {
+ IDirectDrawSurface2_Unlock (pScreenPriv->pddsOffscreen, NULL);
+ IDirectDrawSurface2_Release (pScreenPriv->pddsOffscreen);
+ pScreenPriv->pddsOffscreen = NULL;
+ }
+
+ /* Release the primary surface, if there is one */
+ if (pScreenPriv->pddsPrimary)
+ {
+ IDirectDrawSurface2_Unlock (pScreenPriv->pddsPrimary, NULL);
+ IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
+ pScreenPriv->pddsPrimary = NULL;
+ }
+
+ /* Free the DirectDraw object, if there is one */
+ if (pScreenPriv->pdd)
+ {
+ IDirectDraw2_RestoreDisplayMode (pScreenPriv->pdd);
+ IDirectDraw2_Release (pScreenPriv->pdd);
+ pScreenPriv->pdd = NULL;
+ }
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+}
+
+static Bool
+winInitScreenPrimaryDD(ScreenPtr pScreen)
+{
+ return winAllocateFBPrimaryDD(pScreen);
+}
+
+/*
+ * Call the wrapped CloseScreen function.
+ *
+ * Free our resources and private structures.
+ */
+
+static Bool
+winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ Bool fReturn;
+
+ ErrorF ("winCloseScreenPrimaryDD - Freeing screen resources\n");
+
+ /* Flag that the screen is closed */
+ pScreenPriv->fClosed = TRUE;
+ pScreenPriv->fActive = FALSE;
+
+ /* Call the wrapped CloseScreen procedure */
+ WIN_UNWRAP(CloseScreen);
+ if (pScreen->CloseScreen)
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ winFreeFBPrimaryDD(pScreen);
+
+ /* 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;
+ }
+
+ /* Kill our screeninfo's pointer to the screen */
+ pScreenInfo->pScreen = 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
+winInitVisualsPrimaryDD (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 > dwGreenBits && dwRedBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwRedBits;
+ else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwGreenBits;
+ else
+ pScreenPriv->dwBitsPerRGB = dwBlueBits;
+
+ winDebug ("winInitVisualsPrimaryDD - Masks: %08x %08x %08x bpRGB: %d\n",
+ (unsigned int) pScreenPriv->dwRedMask,
+ (unsigned int) pScreenPriv->dwGreenMask,
+ (unsigned int) pScreenPriv->dwBlueMask,
+ (int) pScreenPriv->dwBitsPerRGB);
+
+ /* Create a single visual according to the Windows screen depth */
+ switch (pScreenInfo->dwDepth)
+ {
+ case 24:
+ case 16:
+ case 15:
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ TrueColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsPrimaryDD - "
+ "miSetVisualTypesAndMasks failed\n");
+ return FALSE;
+ }
+ break;
+
+ case 8:
+ winDebug ("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ PseudoColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ PseudoColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsPrimaryDD - "
+ "miSetVisualTypesAndMasks failed\n");
+ return FALSE;
+ }
+ winDebug ("winInitVisualsPrimaryDD - Returned from "
+ "miSetVisualTypesAndMasks\n");
+ break;
+
+ default:
+ ErrorF ("winInitVisualsPrimaryDD - Unknown screen depth\n");
+ return FALSE;
+ }
+
+ winDebug ("winInitVisualsPrimaryDD - Returning\n");
+
+ return TRUE;
+}
+
+
+static Bool
+winAdjustVideoModePrimaryDD (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 ("winAdjustVideoModePrimaryDD - 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->fFullScreen &&
+ (pScreenInfo->dwBPP != WIN_DEFAULT_BPP)))
+ {
+ /* Otherwise, We'll use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+
+ return TRUE;
+}
+
+
+/*
+ * We need to blit our offscreen fb to
+ * the screen when we are activated, and we need to point
+ * the fb code back to the primary surface memory.
+ */
+
+static Bool
+winActivateAppPrimaryDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RECT rcSrc, rcClient;
+ HRESULT ddrval = DD_OK;
+
+ /* Check for errors */
+ if (pScreenPriv == NULL
+ || pScreenPriv->pddsPrimary == NULL
+ || pScreenPriv->pddsOffscreen == NULL)
+ return FALSE;
+
+ /* Check for do-nothing */
+ if (!pScreenPriv->fActive)
+ return TRUE;
+
+ /* We are activating */
+ ddrval = IDirectDrawSurface2_IsLost (pScreenPriv->pddsOffscreen);
+ if (ddrval == DD_OK)
+ {
+ IDirectDrawSurface2_Unlock (pScreenPriv->pddsOffscreen,
+ NULL);
+ /*
+ * We don't check for an error from Unlock, because it
+ * doesn't matter if the Unlock failed.
+ */
+ }
+
+ /* Restore both surfaces, just cause I like it that way */
+ IDirectDrawSurface2_Restore (pScreenPriv->pddsOffscreen);
+ IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
+
+ /* Get client area in screen coords */
+ GetClientRect (pScreenPriv->hwndScreen, &rcClient);
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&rcClient, 2);
+
+ /* Setup a source rectangle */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsPrimary,
+ &rcClient,
+ pScreenPriv->pddsOffscreen,
+ &rcSrc,
+ DDBLT_WAIT,
+ NULL);
+ if (ddrval != DD_OK)
+ FatalError ("winActivateAppPrimaryDD () - Failed blitting offscreen "
+ "surface to primary surface %08x\n", (unsigned int) ddrval);
+
+ /* Lock the primary surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsPrimary,
+ &rcClient,
+ pScreenPriv->pddsdPrimary,
+ DDLOCK_WAIT,
+ NULL);
+ if (ddrval != DD_OK
+ || pScreenPriv->pddsdPrimary->lpSurface == NULL)
+ FatalError ("winActivateAppPrimaryDD () - Could not lock "
+ "primary surface\n");
+
+ /* Notify FB of the new memory pointer */
+ winUpdateFBPointer (pScreen,
+ pScreenPriv->pddsdPrimary->lpSurface);
+
+ /*
+ * Register the Alt-Tab combo as a hotkey so we can copy
+ * the primary framebuffer before the display mode changes
+ */
+ RegisterHotKey (pScreenPriv->hwndScreen, 1, MOD_ALT, 9);
+
+ return TRUE;
+}
+
+
+/*
+ * Handle the Alt+Tab hotkey.
+ *
+ * We need to save the primary fb to an offscreen fb when
+ * we get deactivated, and point the fb code at the offscreen
+ * fb for the duration of the deactivation.
+ */
+
+static Bool
+winHotKeyAltTabPrimaryDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RECT rcClient, rcSrc;
+ HRESULT ddrval = DD_OK;
+
+ winDebug ("\nwinHotKeyAltTabPrimaryDD\n\n");
+
+ /* Alt+Tab was pressed, we will lose focus very soon */
+ pScreenPriv->fActive = FALSE;
+
+ /* Check for error conditions */
+ if (pScreenPriv->pddsPrimary == NULL
+ || pScreenPriv->pddsOffscreen == NULL)
+ return FALSE;
+
+ /* Get client area in screen coords */
+ GetClientRect (pScreenPriv->hwndScreen, &rcClient);
+ MapWindowPoints (pScreenPriv->hwndScreen,
+ HWND_DESKTOP,
+ (LPPOINT)&rcClient, 2);
+
+ /* Did we loose the primary surface? */
+ ddrval = IDirectDrawSurface2_IsLost (pScreenPriv->pddsPrimary);
+ if (ddrval == DD_OK)
+ {
+ ddrval = IDirectDrawSurface2_Unlock (pScreenPriv->pddsPrimary,
+ NULL);
+ if (FAILED (ddrval))
+ FatalError ("winHotKeyAltTabPrimaryDD - Failed unlocking primary "
+ "surface\n");
+ }
+
+ /* Setup a source rectangle */
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.right = pScreenInfo->dwWidth;
+ rcSrc.bottom = pScreenInfo->dwHeight;
+
+ /* Blit the primary surface to the offscreen surface */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsOffscreen,
+ NULL, /* should be rcDest */
+ pScreenPriv->pddsPrimary,
+ NULL,
+ DDBLT_WAIT,
+ NULL);
+ if (ddrval == DDERR_SURFACELOST)
+ {
+ IDirectDrawSurface2_Restore (pScreenPriv->pddsOffscreen);
+ IDirectDrawSurface2_Restore (pScreenPriv->pddsPrimary);
+
+ /* Blit the primary surface to the offscreen surface */
+ ddrval = IDirectDrawSurface2_Blt (pScreenPriv->pddsOffscreen,
+ NULL,
+ pScreenPriv->pddsPrimary,
+ NULL,
+ DDBLT_WAIT,
+ NULL);
+ if (FAILED (ddrval))
+ FatalError ("winHotKeyAltTabPrimaryDD - Failed blitting primary "
+ "surface to offscreen surface: %08x\n",
+ (unsigned int) ddrval);
+ }
+ else
+ {
+ FatalError ("winHotKeyAltTabPrimaryDD - Unknown error from "
+ "Blt: %08dx\n", (unsigned int) ddrval);
+ }
+
+ /* Lock the offscreen surface */
+ ddrval = IDirectDrawSurface2_Lock (pScreenPriv->pddsOffscreen,
+ NULL,
+ pScreenPriv->pddsdOffscreen,
+ DDLOCK_WAIT,
+ NULL);
+ if (ddrval != DD_OK
+ || pScreenPriv->pddsdPrimary->lpSurface == NULL)
+ FatalError ("winHotKeyAltTabPrimaryDD - Could not lock "
+ "offscreen surface\n");
+
+ /* Notify FB of the new memory pointer */
+ winUpdateFBPointer (pScreen,
+ pScreenPriv->pddsdOffscreen->lpSurface);
+
+ /* Unregister our hotkey */
+ UnregisterHotKey (pScreenPriv->hwndScreen, 1);
+
+ return TRUE;
+}
+
+
+/* Set engine specific functions */
+Bool
+winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Set our pointers */
+ pScreenPriv->pwinAllocateFB = winAllocateFBPrimaryDD;
+ pScreenPriv->pwinFreeFB = winFreeFBPrimaryDD;
+ pScreenPriv->pwinShadowUpdate = (winShadowUpdateProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinInitScreen = winInitScreenPrimaryDD;
+ pScreenPriv->pwinCloseScreen = winCloseScreenPrimaryDD;
+ pScreenPriv->pwinInitVisuals = winInitVisualsPrimaryDD;
+ pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModePrimaryDD;
+ if (pScreenInfo->fFullScreen)
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
+ else
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
+ pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
+ pScreenPriv->pwinBltExposedRegions = (winBltExposedRegionsProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinActivateApp = winActivateAppPrimaryDD;
+ pScreenPriv->pwinRedrawScreen = NULL;
+ pScreenPriv->pwinRealizeInstalledPalette = NULL;
+ pScreenPriv->pwinInstallColormap = NULL;
+ pScreenPriv->pwinStoreColors = NULL;
+ pScreenPriv->pwinCreateColormap = NULL;
+ pScreenPriv->pwinDestroyColormap = NULL;
+ pScreenPriv->pwinHotKeyAltTab = winHotKeyAltTabPrimaryDD;
+ pScreenPriv->pwinCreatePrimarySurface = (winCreatePrimarySurfaceProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinReleasePrimarySurface = (winReleasePrimarySurfaceProcPtr) (void (*)(void))NoopDDA;
+#ifdef XWIN_MULTIWINDOW
+ pScreenPriv->pwinFinishCreateWindowsWindow =
+ (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA;
+#endif
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winscrinit.c b/xorg-server/hw/xwin/winscrinit.c index c67eb6de8..baa2b7f3a 100644 --- a/xorg-server/hw/xwin/winscrinit.c +++ b/xorg-server/hw/xwin/winscrinit.c @@ -1,756 +1,760 @@ -/* - *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 - * Kensuke Matsuzaki - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "winmsg.h" - - -#ifdef XWIN_MULTIWINDOWEXTWM -static RootlessFrameProcsRec -winMWExtWMProcs = { - winMWExtWMCreateFrame, - winMWExtWMDestroyFrame, - - winMWExtWMMoveFrame, - winMWExtWMResizeFrame, - winMWExtWMRestackFrame, - winMWExtWMReshapeFrame, - winMWExtWMUnmapFrame, - - winMWExtWMStartDrawing, - winMWExtWMStopDrawing, - winMWExtWMUpdateRegion, - winMWExtWMDamageRects, - winMWExtWMRootlessSwitchWindow, - NULL,//winMWExtWMDoReorderWindow, - NULL,//winMWExtWMHideWindow, - NULL,//winMWExtWMUpdateColorMap, - - NULL,//winMWExtWMCopyBytes, - winMWExtWMCopyWindow -}; -#endif - -/* - * Prototypes - */ - -/* - * Local functions - */ - -static Bool -winSaveScreen (ScreenPtr pScreen, int on); - - -/* - * Determine what type of screen we are initializing - * and call the appropriate procedure to intiailize - * that type of screen. - */ - -Bool -winScreenInit (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; - winPrivScreenPtr pScreenPriv; - HDC hdc; - DWORD dwInitialBPP; - - winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n", - pScreenInfo->dwWidth, pScreenInfo->dwHeight); - - /* Allocate privates for this screen */ - if (!winAllocatePrivates (pScreen)) - { - ErrorF ("winScreenInit - Couldn't allocate screen privates\n"); - return FALSE; - } - - /* Get a pointer to the privates structure that was allocated */ - pScreenPriv = winGetScreenPriv (pScreen); - - /* Save a pointer to this screen in the screen info structure */ - pScreenInfo->pScreen = pScreen; - - /* Save a pointer to the screen info in the screen privates structure */ - /* This allows us to get back to the screen info from a screen pointer */ - pScreenPriv->pScreenInfo = pScreenInfo; - - /* - * Determine which engine to use. - * - * NOTE: This is done once per screen because each screen possibly has - * a preferred engine specified on the command line. - */ - if (!winSetEngine (pScreen)) - { - ErrorF ("winScreenInit - winSetEngine () failed\n"); - return FALSE; - } - - /* Horribly misnamed function: Allow engine to adjust BPP for screen */ - dwInitialBPP = pScreenInfo->dwBPP; - - if (pScreenPriv->pwinAdjustVideoMode && !(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) - { - ErrorF ("winScreenInit - winAdjustVideoMode () failed\n"); - return FALSE; - } - - if (dwInitialBPP == WIN_DEFAULT_BPP) - { - /* No -depth parameter was passed, let the user know the depth being used */ - winDebug ("winScreenInit - Using Windows display depth of %d bits per pixel\n", (int) pScreenInfo->dwBPP); - } - else if (dwInitialBPP != pScreenInfo->dwBPP) - { - /* Warn user if engine forced a depth different to -depth parameter */ - winDebug ("winScreenInit - Command line depth of %d bpp overidden by engine, using %d bpp\n", (int) dwInitialBPP, (int) pScreenInfo->dwBPP); - } - else - { - winDebug ("winScreenInit - Using command line depth of %d bpp\n", (int) pScreenInfo->dwBPP); - } - - /* Check for supported display depth */ - if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) - { - ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ - "Change your Windows display depth to 15, 16, 24, or 32 bits " - "per pixel.\n", - (int) pScreenInfo->dwBPP); - ErrorF ("winScreenInit - Supported depths: %08x\n", - WIN_SUPPORTED_BPPS); -#if WIN_CHECK_DEPTH - return FALSE; -#endif - } - - /* - * Check that all monitors have the same display depth if we are using - * multiple monitors - */ - if (pScreenInfo->fMultipleMonitors - && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT)) - { - ErrorF ("winScreenInit - Monitors do not all have same pixel format / " - "display depth.\n"); - if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI) - { - ErrorF ("winScreenInit - Performance may suffer off primary display.\n"); - } - else - { - ErrorF ("winScreenInit - Using primary display only.\n"); - pScreenInfo->fMultipleMonitors = FALSE; - } - } - - /* Create display window */ - if (pScreenPriv->pwinCreateBoundingWindow && !(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) - { - ErrorF ("winScreenInit - pwinCreateBoundingWindow () " - "failed\n"); - return FALSE; - } - - /* Get a device context */ - hdc = GetDC (pScreenPriv->hwndScreen); - - /* Are we using multiple monitors? */ - if (pScreenInfo->fMultipleMonitors) - { - /* - * In this case, some of the defaults set in - * winInitializeScreenDefaults() are not correct ... - */ - if (!pScreenInfo->fUserGaveHeightAndWidth) - { - pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); - pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); - } - } - - /* Release the device context */ - ReleaseDC (pScreenPriv->hwndScreen, hdc); - - /* Clear the visuals list */ - miClearVisualTypes (); - - /* Call the engine dependent screen initialization procedure */ - if (pScreenPriv->pwinFinishScreenInit && !((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) - { - ErrorF ("winScreenInit - winFinishScreenInit () failed\n"); - return FALSE; - } - - if (!g_fSoftwareCursor) - winInitCursor(pScreen); -#ifdef WINDBG - else - winDebug("winScreenInit - Using software cursor\n"); -#endif - - /* - Note the screen origin in a normalized coordinate space where (0,0) is at the top left - of the native virtual desktop area - */ - pScreen->x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN); - pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN); - - winDebug("Screen %d added at virtual desktop coordinate (%d,%d).\n", - index, pScreen->x, pScreen->y); - winDebug ("winScreenInit - returning\n"); - - return TRUE; -} - -static Bool -winCreateScreenResources(ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - Bool result; - - result = pScreenPriv->pwinCreateScreenResources(pScreen); - - /* Now the screen bitmap has been wrapped in a pixmap, - add that to the Shadow framebuffer */ - if (!shadowAdd(pScreen, pScreen->devPrivate, - pScreenPriv->pwinShadowUpdate, NULL, 0, 0)) - { - ErrorF ("winCreateScreenResources - shadowAdd () failed\n"); - return FALSE; - } - - return result; -} - -/* See Porting Layer Definition - p. 20 */ -Bool -winFinishScreenInitFB (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - VisualPtr pVisual = NULL; - char *pbits = NULL; -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - int iReturn; -#endif - - /* Create framebuffer */ - if (!(*pScreenPriv->pwinInitScreen) (pScreen)) - { - ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); - return FALSE; - } - - /* - * Calculate the number of bits that are used to represent color in each pixel, - * the color depth for the screen - */ - if (pScreenInfo->dwBPP == 8) - pScreenInfo->dwDepth = 8; - else - pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) - + winCountBits (pScreenPriv->dwGreenMask) - + winCountBits (pScreenPriv->dwBlueMask); - - winDebug ("winFinishScreenInitFB - Masks: %08x %08x %08x\n", - (unsigned int) pScreenPriv->dwRedMask, - (unsigned int) pScreenPriv->dwGreenMask, - (unsigned int) pScreenPriv->dwBlueMask); - - /* Init visuals */ - if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) - { - ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n"); - return FALSE; - } - - /* Setup a local variable to point to the framebuffer */ - pbits = pScreenInfo->pfb; - - /* Apparently we need this for the render extension */ - miSetPixmapDepths (); - - /* Start fb initialization */ - if (!fbSetupScreen (pScreen, - pScreenInfo->pfb, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - pScreenInfo->dwBPP)) - { - ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n"); - return FALSE; - } - - /* Override default colormap routines if visual class is dynamic */ - if (pScreenInfo->dwDepth == 8 - && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI - || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL - && pScreenInfo->fFullScreen) - || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD - && pScreenInfo->fFullScreen))) - { - winSetColormapFunctions (pScreen); - - /* - * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its - * own colormap, as it cannot allocate 7 planes in the default - * colormap. Setting whitePixel to 1 allows Magic to get 7 - * planes in the default colormap, so it doesn't create its - * own colormap. This latter situation is highly desireable, - * as it keeps the Magic window viewable when switching to - * other X clients that use the default colormap. - */ - pScreen->blackPixel = 0; - pScreen->whitePixel = 1; - } - - /* Place our save screen function */ - pScreen->SaveScreen = winSaveScreen; - - /* Finish fb initialization */ - if (!fbFinishScreenInit (pScreen, - pScreenInfo->pfb, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - pScreenInfo->dwBPP)) - { - ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n"); - return FALSE; - } - - /* Save a pointer to the root visual */ - for (pVisual = pScreen->visuals; - pVisual->vid != pScreen->rootVisual; - pVisual++); - pScreenPriv->pRootVisual = pVisual; - - /* - * Setup points to the block and wakeup handlers. Pass a pointer - * to the current screen as pWakeupdata. - */ - pScreen->BlockHandler = winBlockHandler; - pScreen->WakeupHandler = winWakeupHandler; - pScreen->blockData = pScreen; - pScreen->wakeupData = pScreen; - - /* Render extension initialization, calls miPictureInit */ - if (!fbPictureInit (pScreen, NULL, 0)) - { - ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n"); - return FALSE; - } - -#ifdef RANDR - /* Initialize resize and rotate support */ - if (!winRandRInit (pScreen)) - { - ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); - return FALSE; - } -#endif - - /* Setup the cursor routines */ - winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); - miDCInitialize (pScreen, &g_winPointerCursorFuncs); - - /* KDrive does winCreateDefColormap right after miDCInitialize */ - /* Create a default colormap */ - winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); - if (!winCreateDefColormap (pScreen)) - { - ErrorF ("winFinishScreenInitFB - Could not create colormap\n"); - return FALSE; - } - - /* Initialize the shadow framebuffer layer */ - if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI - || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD - || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) -#ifdef XWIN_MULTIWINDOWEXTWM - && !pScreenInfo->fMWExtWM -#endif - ) - { - winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n"); - if (!shadowSetup(pScreen)) - { - ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n"); - return FALSE; - } - - /* Wrap CreateScreenResources so we can add the screen pixmap - to the Shadow framebuffer after it's been created */ - pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = winCreateScreenResources; - } - -#ifdef XWIN_MULTIWINDOWEXTWM - /* Handle multi-window external window manager mode */ - if (pScreenInfo->fMWExtWM) - { - winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n"); - - RootlessInit(pScreen, &winMWExtWMProcs); - - winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n"); - - rootless_CopyBytes_threshold = 0; - /* FIXME: How many? Profiling needed? */ - rootless_CopyWindow_threshold = 1; - - winWindowsWMExtensionInit (); - } -#endif - - /* Handle rootless mode */ - if (pScreenInfo->fRootless) - { - /* Define the WRAP macro temporarily for local use */ -#define WRAP(a) \ - if (pScreen->a) { \ - pScreenPriv->a = pScreen->a; \ - } else { \ - ErrorF("null screen fn " #a "\n"); \ - pScreenPriv->a = NULL; \ - } - - /* Save a pointer to each lower-level window procedure */ - WRAP(CreateWindow); - WRAP(DestroyWindow); - WRAP(RealizeWindow); - WRAP(UnrealizeWindow); - WRAP(PositionWindow); - WRAP(ChangeWindowAttributes); - WRAP(SetShape); - - /* Assign rootless window procedures to be top level procedures */ - pScreen->CreateWindow = winCreateWindowRootless; - pScreen->DestroyWindow = winDestroyWindowRootless; - pScreen->PositionWindow = winPositionWindowRootless; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/ - pScreen->RealizeWindow = winMapWindowRootless; - pScreen->UnrealizeWindow = winUnmapWindowRootless; - pScreen->SetShape = winSetShapeRootless; - - /* Undefine the WRAP macro, as it is not needed elsewhere */ -#undef WRAP - } - - -#ifdef XWIN_MULTIWINDOW - /* Handle multi window mode */ - else if (pScreenInfo->fMultiWindow) - { - /* Define the WRAP macro temporarily for local use */ -#define WRAP(a) \ - if (pScreen->a) { \ - pScreenPriv->a = pScreen->a; \ - } else { \ - ErrorF("null screen fn " #a "\n"); \ - pScreenPriv->a = NULL; \ - } - - /* Save a pointer to each lower-level window procedure */ - WRAP(CreateWindow); - WRAP(DestroyWindow); - WRAP(RealizeWindow); - WRAP(UnrealizeWindow); - WRAP(PositionWindow); - WRAP(ChangeWindowAttributes); - WRAP(ReparentWindow); - WRAP(RestackWindow); - WRAP(ResizeWindow); - WRAP(MoveWindow); - WRAP(CopyWindow); - WRAP(SetShape); - - /* Assign multi-window window procedures to be top level procedures */ - pScreen->CreateWindow = winCreateWindowMultiWindow; - pScreen->DestroyWindow = winDestroyWindowMultiWindow; - pScreen->PositionWindow = winPositionWindowMultiWindow; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/ - pScreen->RealizeWindow = winMapWindowMultiWindow; - pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; - pScreen->ReparentWindow = winReparentWindowMultiWindow; - pScreen->RestackWindow = winRestackWindowMultiWindow; - pScreen->ResizeWindow = winResizeWindowMultiWindow; - pScreen->MoveWindow = winMoveWindowMultiWindow; - pScreen->CopyWindow = winCopyWindowMultiWindow; - pScreen->SetShape = winSetShapeMultiWindow; - - /* Undefine the WRAP macro, as it is not needed elsewhere */ -#undef WRAP - } -#endif - - /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - /* Create a mutex for modules in separate threads to wait for */ - iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); - if (iReturn != 0) - { - ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n", - iReturn); - return FALSE; - } - - /* Own the mutex for modules in separate threads */ - iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); - if (iReturn != 0) - { - ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n", - iReturn); - return FALSE; - } - - /* Set the ServerStarted flag to false */ - pScreenPriv->fServerStarted = FALSE; -#endif - -#ifdef XWIN_MULTIWINDOWEXTWM - pScreenPriv->fRestacking = FALSE; -#endif - -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (FALSE -#ifdef XWIN_MULTIWINDOW - || pScreenInfo->fMultiWindow -#endif -#ifdef XWIN_MULTIWINDOWINTWM - || pScreenInfo->fInternalWM -#endif - ) - { - winDebug ("winFinishScreenInitFB - Calling winInitWM.\n"); - - /* Initialize multi window mode */ - if (!winInitWM (&pScreenPriv->pWMInfo, - &pScreenPriv->ptWMProc, - &pScreenPriv->ptXMsgProc, - &pScreenPriv->pmServerStarted, - pScreenInfo->dwScreen, - (HWND)&pScreenPriv->hwndScreen, -#ifdef XWIN_MULTIWINDOWINTWM - pScreenInfo->fInternalWM || -#endif - FALSE)) - { - ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n"); - return FALSE; - } - } -#endif - - /* Tell the server that we are enabled */ - pScreenPriv->fEnabled = TRUE; - - /* Tell the server that we have a valid depth */ - pScreenPriv->fBadDepth = FALSE; - - winDebug ("winFinishScreenInitFB - returning\n"); - - return TRUE; -} - -#ifdef XWIN_NATIVEGDI -/* See Porting Layer Definition - p. 20 */ - -Bool -winFinishScreenInitNativeGDI (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenPriv(pScreen); - winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; - VisualPtr pVisuals = NULL; - DepthPtr pDepths = NULL; - VisualID rootVisual = 0; - int nVisuals = 0, nDepths = 0, nRootDepth = 0; - - /* Ignore user input (mouse, keyboard) */ - pScreenInfo->fIgnoreInput = FALSE; - - /* Get device contexts for the screen and shadow bitmap */ - pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); - if (pScreenPriv->hdcScreen == NULL) - FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n"); - - /* Init visuals */ - if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) - { - ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n"); - return FALSE; - } - - /* Initialize the mi visuals */ - if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth, - &rootVisual, - ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8, - TrueColor)) - { - ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n"); - return FALSE; - } - - /* Initialize the CloseScreen procedure pointer */ - pScreen->CloseScreen = NULL; - - /* Initialize the mi code */ - if (!miScreenInit (pScreen, - NULL, /* No framebuffer */ - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - nRootDepth, nDepths, pDepths, rootVisual, - nVisuals, pVisuals)) - { - ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n"); - return FALSE; - } - - pScreen->defColormap = FakeClientID(0); - - /* - * Register our block and wakeup handlers; these procedures - * process messages in our Windows message queue; specifically, - * they process mouse and keyboard input. - */ - pScreen->BlockHandler = winBlockHandler; - pScreen->WakeupHandler = winWakeupHandler; - pScreen->blockData = pScreen; - pScreen->wakeupData = pScreen; - - /* Place our save screen function */ - pScreen->SaveScreen = winSaveScreen; - - /* Pixmaps */ - pScreen->CreatePixmap = winCreatePixmapNativeGDI; - pScreen->DestroyPixmap = winDestroyPixmapNativeGDI; - - /* Other Screen Routines */ - pScreen->QueryBestSize = winQueryBestSizeNativeGDI; - pScreen->SaveScreen = winSaveScreen; - pScreen->GetImage = miGetImage; - pScreen->GetSpans = winGetSpansNativeGDI; - - /* Window Procedures */ - pScreen->CreateWindow = winCreateWindowNativeGDI; - pScreen->DestroyWindow = winDestroyWindowNativeGDI; - pScreen->PositionWindow = winPositionWindowNativeGDI; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/ - pScreen->RealizeWindow = winMapWindowNativeGDI; - pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; - - /* Paint window */ - pScreen->CopyWindow = winCopyWindowNativeGDI; - - /* Fonts */ - pScreen->RealizeFont = winRealizeFontNativeGDI; - pScreen->UnrealizeFont = winUnrealizeFontNativeGDI; - - /* GC */ - pScreen->CreateGC = winCreateGCNativeGDI; - - /* Colormap Routines */ - pScreen->CreateColormap = miInitializeColormap; - pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA; - pScreen->InstallColormap = miInstallColormap; - pScreen->UninstallColormap = miUninstallColormap; - pScreen->ListInstalledColormaps = miListInstalledColormaps; - pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA; - pScreen->ResolveColor = miResolveColor; - - /* Bitmap */ - pScreen->BitmapToRegion = winPixmapToRegionNativeGDI; - - winDebug ("winFinishScreenInitNativeGDI - calling miDCInitialize\n"); - - /* Set the default white and black pixel positions */ - pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0; - - /* Initialize the cursor */ - if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs)) - { - ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n"); - return FALSE; - } - - /* Create a default colormap */ - if (!miCreateDefColormap (pScreen)) - { - ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " - "failed\n"); - return FALSE; - } - - winDebug ("winFinishScreenInitNativeGDI - miCreateDefColormap () " - "returned\n"); - - /* mi doesn't use a CloseScreen procedure, so no need to wrap */ - pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; - - /* Tell the server that we are enabled */ - pScreenPriv->fEnabled = TRUE; - - winDebug ("winFinishScreenInitNativeGDI - Successful addition of " - "screen %08x\n", - (unsigned int) pScreen); - - return TRUE; -} -#endif - - -/* See Porting Layer Definition - p. 33 */ -static Bool -winSaveScreen (ScreenPtr pScreen, int on) -{ - 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
+ * Kensuke Matsuzaki
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "winmsg.h"
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+static RootlessFrameProcsRec
+winMWExtWMProcs = {
+ winMWExtWMCreateFrame,
+ winMWExtWMDestroyFrame,
+
+ winMWExtWMMoveFrame,
+ winMWExtWMResizeFrame,
+ winMWExtWMRestackFrame,
+ winMWExtWMReshapeFrame,
+ winMWExtWMUnmapFrame,
+
+ winMWExtWMStartDrawing,
+ winMWExtWMStopDrawing,
+ winMWExtWMUpdateRegion,
+ winMWExtWMDamageRects,
+ winMWExtWMRootlessSwitchWindow,
+ NULL,//winMWExtWMDoReorderWindow,
+ NULL,//winMWExtWMHideWindow,
+ NULL,//winMWExtWMUpdateColorMap,
+
+ NULL,//winMWExtWMCopyBytes,
+ winMWExtWMCopyWindow
+};
+#endif
+
+/*
+ * Prototypes
+ */
+
+/*
+ * Local functions
+ */
+
+static Bool
+winSaveScreen (ScreenPtr pScreen, int on);
+
+
+/*
+ * Determine what type of screen we are initializing
+ * and call the appropriate procedure to intiailize
+ * that type of screen.
+ */
+
+Bool
+winScreenInit (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
+ winPrivScreenPtr pScreenPriv;
+ HDC hdc;
+ DWORD dwInitialBPP;
+
+ winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight);
+
+ /* Allocate privates for this screen */
+ if (!winAllocatePrivates (pScreen))
+ {
+ ErrorF ("winScreenInit - Couldn't allocate screen privates\n");
+ return FALSE;
+ }
+
+ /* Get a pointer to the privates structure that was allocated */
+ pScreenPriv = winGetScreenPriv (pScreen);
+
+ /* Save a pointer to this screen in the screen info structure */
+ pScreenInfo->pScreen = pScreen;
+
+ /* Save a pointer to the screen info in the screen privates structure */
+ /* This allows us to get back to the screen info from a screen pointer */
+ pScreenPriv->pScreenInfo = pScreenInfo;
+
+ /*
+ * Determine which engine to use.
+ *
+ * NOTE: This is done once per screen because each screen possibly has
+ * a preferred engine specified on the command line.
+ */
+ if (!winSetEngine (pScreen))
+ {
+ ErrorF ("winScreenInit - winSetEngine () failed\n");
+ return FALSE;
+ }
+
+ /* Horribly misnamed function: Allow engine to adjust BPP for screen */
+ dwInitialBPP = pScreenInfo->dwBPP;
+
+ if (pScreenPriv->pwinAdjustVideoMode && !(*pScreenPriv->pwinAdjustVideoMode) (pScreen))
+ {
+ ErrorF ("winScreenInit - winAdjustVideoMode () failed\n");
+ return FALSE;
+ }
+
+ if (dwInitialBPP == WIN_DEFAULT_BPP)
+ {
+ /* No -depth parameter was passed, let the user know the depth being used */
+ winDebug ("winScreenInit - Using Windows display depth of %d bits per pixel\n", (int) pScreenInfo->dwBPP);
+ }
+ else if (dwInitialBPP != pScreenInfo->dwBPP)
+ {
+ /* Warn user if engine forced a depth different to -depth parameter */
+ winDebug ("winScreenInit - Command line depth of %d bpp overidden by engine, using %d bpp\n", (int) dwInitialBPP, (int) pScreenInfo->dwBPP);
+ }
+ else
+ {
+ winDebug ("winScreenInit - Using command line depth of %d bpp\n", (int) pScreenInfo->dwBPP);
+ }
+
+ /* Check for supported display depth */
+ if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1))))
+ {
+ ErrorF ("winScreenInit - Unsupported display depth: %d\n" \
+ "Change your Windows display depth to 15, 16, 24, or 32 bits "
+ "per pixel.\n",
+ (int) pScreenInfo->dwBPP);
+ ErrorF ("winScreenInit - Supported depths: %08x\n",
+ WIN_SUPPORTED_BPPS);
+#if WIN_CHECK_DEPTH
+ return FALSE;
+#endif
+ }
+
+ /*
+ * Check that all monitors have the same display depth if we are using
+ * multiple monitors
+ */
+ if (pScreenInfo->fMultipleMonitors
+ && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT))
+ {
+ ErrorF ("winScreenInit - Monitors do not all have same pixel format / "
+ "display depth.\n");
+ if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI)
+ {
+ ErrorF ("winScreenInit - Performance may suffer off primary display.\n");
+ }
+ else
+ {
+ ErrorF ("winScreenInit - Using primary display only.\n");
+ pScreenInfo->fMultipleMonitors = FALSE;
+ }
+ }
+
+ /* Create display window */
+ if (pScreenPriv->pwinCreateBoundingWindow && !(*pScreenPriv->pwinCreateBoundingWindow) (pScreen))
+ {
+ ErrorF ("winScreenInit - pwinCreateBoundingWindow () "
+ "failed\n");
+ return FALSE;
+ }
+
+ /* Get a device context */
+ hdc = GetDC (pScreenPriv->hwndScreen);
+
+ /* Are we using multiple monitors? */
+ if (pScreenInfo->fMultipleMonitors)
+ {
+ /*
+ * In this case, some of the defaults set in
+ * winInitializeScreenDefaults() are not correct ...
+ */
+ if (!pScreenInfo->fUserGaveHeightAndWidth)
+ {
+ pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
+ pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
+ }
+ }
+
+ /* Release the device context */
+ ReleaseDC (pScreenPriv->hwndScreen, hdc);
+
+ /* Clear the visuals list */
+ miClearVisualTypes ();
+
+ /* Call the engine dependent screen initialization procedure */
+ if (pScreenPriv->pwinFinishScreenInit && !((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv)))
+ {
+ ErrorF ("winScreenInit - winFinishScreenInit () failed\n");
+
+ /* call the engine dependent screen close procedure to clean up from a failure */
+ pScreenPriv->pwinCloseScreen(index, pScreen);
+
+ return FALSE;
+ }
+
+ if (!g_fSoftwareCursor)
+ winInitCursor(pScreen);
+#ifdef WINDBG
+ else
+ winDebug("winScreenInit - Using software cursor\n");
+#endif
+
+ /*
+ Note the screen origin in a normalized coordinate space where (0,0) is at the top left
+ of the native virtual desktop area
+ */
+ pScreen->x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN);
+ pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);
+
+ winDebug("Screen %d added at virtual desktop coordinate (%d,%d).\n",
+ index, pScreen->x, pScreen->y);
+ winDebug ("winScreenInit - returning\n");
+
+ return TRUE;
+}
+
+static Bool
+winCreateScreenResources(ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ Bool result;
+
+ result = pScreenPriv->pwinCreateScreenResources(pScreen);
+
+ /* Now the screen bitmap has been wrapped in a pixmap,
+ add that to the Shadow framebuffer */
+ if (!shadowAdd(pScreen, pScreen->devPrivate,
+ pScreenPriv->pwinShadowUpdate, NULL, 0, 0))
+ {
+ ErrorF ("winCreateScreenResources - shadowAdd () failed\n");
+ return FALSE;
+ }
+
+ return result;
+}
+
+/* See Porting Layer Definition - p. 20 */
+Bool
+winFinishScreenInitFB (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ VisualPtr pVisual = NULL;
+ char *pbits = NULL;
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ int iReturn;
+#endif
+
+ /* Create framebuffer */
+ if (!(*pScreenPriv->pwinInitScreen) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n");
+ return FALSE;
+ }
+
+ /*
+ * Calculate the number of bits that are used to represent color in each pixel,
+ * the color depth for the screen
+ */
+ if (pScreenInfo->dwBPP == 8)
+ pScreenInfo->dwDepth = 8;
+ else
+ pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask)
+ + winCountBits (pScreenPriv->dwGreenMask)
+ + winCountBits (pScreenPriv->dwBlueMask);
+
+ winDebug ("winFinishScreenInitFB - Masks: %08x %08x %08x\n",
+ (unsigned int) pScreenPriv->dwRedMask,
+ (unsigned int) pScreenPriv->dwGreenMask,
+ (unsigned int) pScreenPriv->dwBlueMask);
+
+ /* Init visuals */
+ if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n");
+ return FALSE;
+ }
+
+ /* Setup a local variable to point to the framebuffer */
+ pbits = pScreenInfo->pfb;
+
+ /* Apparently we need this for the render extension */
+ miSetPixmapDepths ();
+
+ /* Start fb initialization */
+ if (!fbSetupScreen (pScreen,
+ pScreenInfo->pfb,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ pScreenInfo->dwBPP))
+ {
+ ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n");
+ return FALSE;
+ }
+
+ /* Override default colormap routines if visual class is dynamic */
+ if (pScreenInfo->dwDepth == 8
+ && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
+ || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
+ && pScreenInfo->fFullScreen)
+ || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
+ && pScreenInfo->fFullScreen)))
+ {
+ winSetColormapFunctions (pScreen);
+
+ /*
+ * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its
+ * own colormap, as it cannot allocate 7 planes in the default
+ * colormap. Setting whitePixel to 1 allows Magic to get 7
+ * planes in the default colormap, so it doesn't create its
+ * own colormap. This latter situation is highly desireable,
+ * as it keeps the Magic window viewable when switching to
+ * other X clients that use the default colormap.
+ */
+ pScreen->blackPixel = 0;
+ pScreen->whitePixel = 1;
+ }
+
+ /* Place our save screen function */
+ pScreen->SaveScreen = winSaveScreen;
+
+ /* Finish fb initialization */
+ if (!fbFinishScreenInit (pScreen,
+ pScreenInfo->pfb,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ pScreenInfo->dwBPP))
+ {
+ ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n");
+ return FALSE;
+ }
+
+ /* Save a pointer to the root visual */
+ for (pVisual = pScreen->visuals;
+ pVisual->vid != pScreen->rootVisual;
+ pVisual++);
+ pScreenPriv->pRootVisual = pVisual;
+
+ /*
+ * Setup points to the block and wakeup handlers. Pass a pointer
+ * to the current screen as pWakeupdata.
+ */
+ pScreen->BlockHandler = winBlockHandler;
+ pScreen->WakeupHandler = winWakeupHandler;
+ pScreen->blockData = pScreen;
+ pScreen->wakeupData = pScreen;
+
+ /* Render extension initialization, calls miPictureInit */
+ if (!fbPictureInit (pScreen, NULL, 0))
+ {
+ ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
+ return FALSE;
+ }
+
+#ifdef RANDR
+ /* Initialize resize and rotate support */
+ if (!winRandRInit (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
+ return FALSE;
+ }
+#endif
+
+ /* Setup the cursor routines */
+ winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
+ miDCInitialize (pScreen, &g_winPointerCursorFuncs);
+
+ /* KDrive does winCreateDefColormap right after miDCInitialize */
+ /* Create a default colormap */
+ winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
+ if (!winCreateDefColormap (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
+ return FALSE;
+ }
+
+ /* Initialize the shadow framebuffer layer */
+ if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
+ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
+ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
+#ifdef XWIN_MULTIWINDOWEXTWM
+ && !pScreenInfo->fMWExtWM
+#endif
+ )
+ {
+ winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n");
+ if (!shadowSetup(pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n");
+ return FALSE;
+ }
+
+ /* Wrap CreateScreenResources so we can add the screen pixmap
+ to the Shadow framebuffer after it's been created */
+ pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources;
+ pScreen->CreateScreenResources = winCreateScreenResources;
+ }
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ /* Handle multi-window external window manager mode */
+ if (pScreenInfo->fMWExtWM)
+ {
+ winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n");
+
+ RootlessInit(pScreen, &winMWExtWMProcs);
+
+ winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n");
+
+ rootless_CopyBytes_threshold = 0;
+ /* FIXME: How many? Profiling needed? */
+ rootless_CopyWindow_threshold = 1;
+
+ winWindowsWMExtensionInit ();
+ }
+#endif
+
+ /* Handle rootless mode */
+ if (pScreenInfo->fRootless)
+ {
+ /* Define the WRAP macro temporarily for local use */
+#define WRAP(a) \
+ if (pScreen->a) { \
+ pScreenPriv->a = pScreen->a; \
+ } else { \
+ ErrorF("null screen fn " #a "\n"); \
+ pScreenPriv->a = NULL; \
+ }
+
+ /* Save a pointer to each lower-level window procedure */
+ WRAP(CreateWindow);
+ WRAP(DestroyWindow);
+ WRAP(RealizeWindow);
+ WRAP(UnrealizeWindow);
+ WRAP(PositionWindow);
+ WRAP(ChangeWindowAttributes);
+ WRAP(SetShape);
+
+ /* Assign rootless window procedures to be top level procedures */
+ pScreen->CreateWindow = winCreateWindowRootless;
+ pScreen->DestroyWindow = winDestroyWindowRootless;
+ pScreen->PositionWindow = winPositionWindowRootless;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/
+ pScreen->RealizeWindow = winMapWindowRootless;
+ pScreen->UnrealizeWindow = winUnmapWindowRootless;
+ pScreen->SetShape = winSetShapeRootless;
+
+ /* Undefine the WRAP macro, as it is not needed elsewhere */
+#undef WRAP
+ }
+
+
+#ifdef XWIN_MULTIWINDOW
+ /* Handle multi window mode */
+ else if (pScreenInfo->fMultiWindow)
+ {
+ /* Define the WRAP macro temporarily for local use */
+#define WRAP(a) \
+ if (pScreen->a) { \
+ pScreenPriv->a = pScreen->a; \
+ } else { \
+ ErrorF("null screen fn " #a "\n"); \
+ pScreenPriv->a = NULL; \
+ }
+
+ /* Save a pointer to each lower-level window procedure */
+ WRAP(CreateWindow);
+ WRAP(DestroyWindow);
+ WRAP(RealizeWindow);
+ WRAP(UnrealizeWindow);
+ WRAP(PositionWindow);
+ WRAP(ChangeWindowAttributes);
+ WRAP(ReparentWindow);
+ WRAP(RestackWindow);
+ WRAP(ResizeWindow);
+ WRAP(MoveWindow);
+ WRAP(CopyWindow);
+ WRAP(SetShape);
+
+ /* Assign multi-window window procedures to be top level procedures */
+ pScreen->CreateWindow = winCreateWindowMultiWindow;
+ pScreen->DestroyWindow = winDestroyWindowMultiWindow;
+ pScreen->PositionWindow = winPositionWindowMultiWindow;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/
+ pScreen->RealizeWindow = winMapWindowMultiWindow;
+ pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
+ pScreen->ReparentWindow = winReparentWindowMultiWindow;
+ pScreen->RestackWindow = winRestackWindowMultiWindow;
+ pScreen->ResizeWindow = winResizeWindowMultiWindow;
+ pScreen->MoveWindow = winMoveWindowMultiWindow;
+ pScreen->CopyWindow = winCopyWindowMultiWindow;
+ pScreen->SetShape = winSetShapeMultiWindow;
+
+ /* Undefine the WRAP macro, as it is not needed elsewhere */
+#undef WRAP
+ }
+#endif
+
+ /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ /* Create a mutex for modules in separate threads to wait for */
+ iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
+ if (iReturn != 0)
+ {
+ ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n",
+ iReturn);
+ return FALSE;
+ }
+
+ /* Own the mutex for modules in separate threads */
+ iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
+ if (iReturn != 0)
+ {
+ ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n",
+ iReturn);
+ return FALSE;
+ }
+
+ /* Set the ServerStarted flag to false */
+ pScreenPriv->fServerStarted = FALSE;
+#endif
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ pScreenPriv->fRestacking = FALSE;
+#endif
+
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (FALSE
+#ifdef XWIN_MULTIWINDOW
+ || pScreenInfo->fMultiWindow
+#endif
+#ifdef XWIN_MULTIWINDOWINTWM
+ || pScreenInfo->fInternalWM
+#endif
+ )
+ {
+ winDebug ("winFinishScreenInitFB - Calling winInitWM.\n");
+
+ /* Initialize multi window mode */
+ if (!winInitWM (&pScreenPriv->pWMInfo,
+ &pScreenPriv->ptWMProc,
+ &pScreenPriv->ptXMsgProc,
+ &pScreenPriv->pmServerStarted,
+ pScreenInfo->dwScreen,
+ (HWND)&pScreenPriv->hwndScreen,
+#ifdef XWIN_MULTIWINDOWINTWM
+ pScreenInfo->fInternalWM ||
+#endif
+ FALSE))
+ {
+ ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
+ return FALSE;
+ }
+ }
+#endif
+
+ /* Tell the server that we are enabled */
+ pScreenPriv->fEnabled = TRUE;
+
+ /* Tell the server that we have a valid depth */
+ pScreenPriv->fBadDepth = FALSE;
+
+ winDebug ("winFinishScreenInitFB - returning\n");
+
+ return TRUE;
+}
+
+#ifdef XWIN_NATIVEGDI
+/* See Porting Layer Definition - p. 20 */
+
+Bool
+winFinishScreenInitNativeGDI (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenPriv(pScreen);
+ winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
+ VisualPtr pVisuals = NULL;
+ DepthPtr pDepths = NULL;
+ VisualID rootVisual = 0;
+ int nVisuals = 0, nDepths = 0, nRootDepth = 0;
+
+ /* Ignore user input (mouse, keyboard) */
+ pScreenInfo->fIgnoreInput = FALSE;
+
+ /* Get device contexts for the screen and shadow bitmap */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+ if (pScreenPriv->hdcScreen == NULL)
+ FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n");
+
+ /* Init visuals */
+ if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n");
+ return FALSE;
+ }
+
+ /* Initialize the mi visuals */
+ if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth,
+ &rootVisual,
+ ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8,
+ TrueColor))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n");
+ return FALSE;
+ }
+
+ /* Initialize the CloseScreen procedure pointer */
+ pScreen->CloseScreen = NULL;
+
+ /* Initialize the mi code */
+ if (!miScreenInit (pScreen,
+ NULL, /* No framebuffer */
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ nRootDepth, nDepths, pDepths, rootVisual,
+ nVisuals, pVisuals))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n");
+ return FALSE;
+ }
+
+ pScreen->defColormap = FakeClientID(0);
+
+ /*
+ * Register our block and wakeup handlers; these procedures
+ * process messages in our Windows message queue; specifically,
+ * they process mouse and keyboard input.
+ */
+ pScreen->BlockHandler = winBlockHandler;
+ pScreen->WakeupHandler = winWakeupHandler;
+ pScreen->blockData = pScreen;
+ pScreen->wakeupData = pScreen;
+
+ /* Place our save screen function */
+ pScreen->SaveScreen = winSaveScreen;
+
+ /* Pixmaps */
+ pScreen->CreatePixmap = winCreatePixmapNativeGDI;
+ pScreen->DestroyPixmap = winDestroyPixmapNativeGDI;
+
+ /* Other Screen Routines */
+ pScreen->QueryBestSize = winQueryBestSizeNativeGDI;
+ pScreen->SaveScreen = winSaveScreen;
+ pScreen->GetImage = miGetImage;
+ pScreen->GetSpans = winGetSpansNativeGDI;
+
+ /* Window Procedures */
+ pScreen->CreateWindow = winCreateWindowNativeGDI;
+ pScreen->DestroyWindow = winDestroyWindowNativeGDI;
+ pScreen->PositionWindow = winPositionWindowNativeGDI;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/
+ pScreen->RealizeWindow = winMapWindowNativeGDI;
+ pScreen->UnrealizeWindow = winUnmapWindowNativeGDI;
+
+ /* Paint window */
+ pScreen->CopyWindow = winCopyWindowNativeGDI;
+
+ /* Fonts */
+ pScreen->RealizeFont = winRealizeFontNativeGDI;
+ pScreen->UnrealizeFont = winUnrealizeFontNativeGDI;
+
+ /* GC */
+ pScreen->CreateGC = winCreateGCNativeGDI;
+
+ /* Colormap Routines */
+ pScreen->CreateColormap = miInitializeColormap;
+ pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA;
+ pScreen->InstallColormap = miInstallColormap;
+ pScreen->UninstallColormap = miUninstallColormap;
+ pScreen->ListInstalledColormaps = miListInstalledColormaps;
+ pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA;
+ pScreen->ResolveColor = miResolveColor;
+
+ /* Bitmap */
+ pScreen->BitmapToRegion = winPixmapToRegionNativeGDI;
+
+ winDebug ("winFinishScreenInitNativeGDI - calling miDCInitialize\n");
+
+ /* Set the default white and black pixel positions */
+ pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0;
+
+ /* Initialize the cursor */
+ if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n");
+ return FALSE;
+ }
+
+ /* Create a default colormap */
+ if (!miCreateDefColormap (pScreen))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
+ "failed\n");
+ return FALSE;
+ }
+
+ winDebug ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
+ "returned\n");
+
+ /* mi doesn't use a CloseScreen procedure, so no need to wrap */
+ pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
+
+ /* Tell the server that we are enabled */
+ pScreenPriv->fEnabled = TRUE;
+
+ winDebug ("winFinishScreenInitNativeGDI - Successful addition of "
+ "screen %08x\n",
+ (unsigned int) pScreen);
+
+ return TRUE;
+}
+#endif
+
+
+/* See Porting Layer Definition - p. 33 */
+static Bool
+winSaveScreen (ScreenPtr pScreen, int on)
+{
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winshaddd.c b/xorg-server/hw/xwin/winshaddd.c index 59530b1ed..0f6afe2f3 100644 --- a/xorg-server/hw/xwin/winshaddd.c +++ b/xorg-server/hw/xwin/winshaddd.c @@ -1,1325 +1,1326 @@ -/* - *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" - - -/* - - -/* - * 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"); - - /* 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; -} - -static void -winFreeFBShadowDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* 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 primary surface, if there is one */ - winReleasePrimarySurfaceShadowDD(pScreen); - - /* Release the clipper object */ - if (pScreenPriv->pddcPrimary) - { - IDirectDrawClipper_Release (pScreenPriv->pddcPrimary); - pScreenPriv->pddcPrimary = 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; - } - - /* Invalidate the ScreenInfo's fb pointer */ - pScreenInfo->pfb = NULL; -} - -/* - * 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 = RegionNumRects (damage); - BoxPtr pBox = RegionRects (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; - - /* Return immediately if we didn't get needed surfaces */ - if (!pScreenPriv->pddsPrimary || !pScreenPriv->pddsShadow) - 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 = RegionExtents(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 */ - winUpdateFBPointer(pScreen, pScreenPriv->pddsdShadow->lpSurface); - } -} - -static Bool -winInitScreenShadowDD (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - - /* Get a device context for the screen */ - pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); - - return winAllocateFBShadowDD(pScreen); -} - -/* - * 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); - - winFreeFBShadowDD(pScreen); - - /* Free the screen DC */ - ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen); - - /* Delete the window property */ - RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP); - - /* 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; - - /* 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: - /* 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 - break; - - case 8: - 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; - } - 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->fFullScreen && - (pScreenInfo->dwBPP != WIN_DEFAULT_BPP))) - { - /* Otherwise, We'll use GDI's depth */ - pScreenInfo->dwBPP = dwBPP; - } - - /* 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->pwinFreeFB = winFreeFBShadowDD; - pScreenPriv->pwinShadowUpdate = winShadowUpdateDD; - pScreenPriv->pwinInitScreen = winInitScreenShadowDD; - 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"
+
+
+/*
+
+
+/*
+ * 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");
+
+ /* 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;
+}
+
+static void
+winFreeFBShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* 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 primary surface, if there is one */
+ winReleasePrimarySurfaceShadowDD(pScreen);
+
+ /* Release the clipper object */
+ if (pScreenPriv->pddcPrimary)
+ {
+ IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
+ pScreenPriv->pddcPrimary = 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;
+ }
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+}
+
+/*
+ * 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 = RegionNumRects (damage);
+ BoxPtr pBox = RegionRects (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;
+
+ /* Return immediately if we didn't get needed surfaces */
+ if (!pScreenPriv->pddsPrimary || !pScreenPriv->pddsShadow)
+ 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 = RegionExtents(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 */
+ winUpdateFBPointer(pScreen, pScreenPriv->pddsdShadow->lpSurface);
+ }
+}
+
+static Bool
+winInitScreenShadowDD (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ /* Get a device context for the screen */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+
+ return winAllocateFBShadowDD(pScreen);
+}
+
+/*
+ * 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);
+ if (pScreen->CloseScreen)
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ winFreeFBShadowDD(pScreen);
+
+ /* Free the screen DC */
+ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ /* 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;
+
+ /* 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:
+ /* 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
+ break;
+
+ case 8:
+ 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;
+ }
+ 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->fFullScreen &&
+ (pScreenInfo->dwBPP != WIN_DEFAULT_BPP)))
+ {
+ /* Otherwise, We'll use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+
+ /* 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->pwinFreeFB = winFreeFBShadowDD;
+ pScreenPriv->pwinShadowUpdate = winShadowUpdateDD;
+ pScreenPriv->pwinInitScreen = winInitScreenShadowDD;
+ 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 4a573470d..da3c56160 100644 --- a/xorg-server/hw/xwin/winshadddnl.c +++ b/xorg-server/hw/xwin/winshadddnl.c @@ -1,1359 +1,1360 @@ -/* - *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" - - -/* - * 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); - -static HRESULT myIDirectDrawSurface4_Blt( ScreenPtr pScreen, RECT *pRect, RECT *prcSrc) -{ - HRESULT ddrval = DD_OK; - unsigned i; - winScreenPriv(pScreen); - - for (i = 0; i < 3; ++i) - { - ddrval = IDirectDrawSurface4_Blt(pScreenPriv->pddsPrimary4, pRect, pScreenPriv->pddsShadow4, prcSrc, DDBLT_WAIT, NULL); - /* Try to regain the primary surface and blit again if we've lost it */ - if (ddrval == DDERR_SURFACELOST) - { - /* Surface was lost */ - ErrorF ("IDirectDrawSurface4_Blt reported that the primary " - "surface was lost, trying to restore, retry: %d\n", i + 1); - - /* Try to restore the surface, once */ - - if (i==1) - { - ErrorF("Recreating DDraw surface because restoring of surface didn't work.\n"); - winAllocateFBShadowDDNL(pScreen); - } - else - { - ddrval = IDirectDraw4_RestoreAllSurfaces (pScreenPriv->pdd4); - ErrorF ("IDirectDraw4_RestoreAllSurfaces 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", ddrval); - } - /* Loop around to try the blit one more time */ - continue; - } - else if (FAILED (ddrval)) - { - ErrorF ("IDirectDrawSurface4_Blt failed, but surface not " - "lost: %08x %d\n", ddrval, ddrval); - } - break; - } - return ddrval; -} - - -/* - * 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; -} - - -static void ClosePrimarySurfaceShadowDDNL (winPrivScreenPtr pScreenPriv) -{ - /* 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; - } - -} - -static void ReleaseDDNL(winPrivScreenPtr pScreenPriv) -{ - /* Release the clipper object */ - if (pScreenPriv->pddcPrimary) - { - IDirectDrawClipper_Release (pScreenPriv->pddcPrimary); - pScreenPriv->pddcPrimary = 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; - } -} - -/* - * Detach the clipper and release the primary surface. - * Called from WM_DISPLAYCHANGE. - */ - -static Bool -winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - - winDebug ("winReleasePrimarySurfaceShadowDDNL - Hello\n"); - - ClosePrimarySurfaceShadowDDNL(pScreenPriv); - - 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); - - /* Set the padded screen width */ - pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth, - pScreenInfo->dwBPP); - - if ( pScreenInfo->pfb) - { - ErrorF("winAllocateFBShadowDDNL calling for the second time, reallocating\n"); - lpSurface=pScreenInfo->pfb; - - if (pScreenPriv->pddsShadow4) - { - IDirectDrawSurface4_Release (pScreenPriv->pddsShadow4); - pScreenPriv->pddsShadow4 = NULL; - } - ClosePrimarySurfaceShadowDDNL(pScreenPriv); - ReleaseDDNL(pScreenPriv); - } - else - { - /* 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"); - - /* 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; -} - -static void -winFreeFBShadowDDNL(ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* 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 primary surface, if there is one */ - winReleasePrimarySurfaceShadowDDNL(pScreen); - - ReleaseDDNL(pScreenPriv); - - /* Invalidate the ScreenInfo's fb pointer */ - pScreenInfo->pfb = NULL; -} - -#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); - RECT rcDest, rcSrc; - POINT ptOrigin; - DWORD dwBox = RegionNumRects (damage); - BoxPtr pBox = RegionRects (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; - - /* Return immediately if we didn't get needed surfaces */ - if (!pScreenPriv->pddsPrimary4 || !pScreenPriv->pddsShadow4) - 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 */ - if (pScreenPriv->pddsPrimary4) - myIDirectDrawSurface4_Blt (pScreen, - &rcDest, - &rcSrc); - - /* Get a pointer to the next box */ - ++pBox; - } - } - else - { - BoxPtr pBoxExtents = RegionExtents(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 */ - myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc); - - /* Reset the clip region */ - SelectClipRgn (pScreenPriv->hdcScreen, NULL); - } -} - -static Bool -winInitScreenShadowDDNL(ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - - /* Get a device context for the screen */ - pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); - - return winAllocateFBShadowDDNL(pScreen); -} - -/* - * 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); - - winFreeFBShadowDDNL(pScreen); - - /* Free the screen DC */ - ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen); - - /* Delete the window property */ - RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP); - - /* 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; - - /* 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: - /* 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 - break; - - case 8: - 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; - } - 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->fFullScreen && - (pScreenInfo->dwBPP != WIN_DEFAULT_BPP))) - { - /* Otherwise, We'll use GDI's depth */ - pScreenInfo->dwBPP = dwBPP; - } - - /* 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; - - /* Our Blt should be clipped to the invalidated region */ - ddrval = myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc); - if (FAILED (ddrval)) - { - fReturn = FALSE; - } - -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; - 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 */ - myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc); - 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->pwinFreeFB = winFreeFBShadowDDNL; - pScreenPriv->pwinShadowUpdate = winShadowUpdateDDNL; - pScreenPriv->pwinInitScreen = winInitScreenShadowDDNL; - 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"
+
+
+/*
+ * 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);
+
+static HRESULT myIDirectDrawSurface4_Blt( ScreenPtr pScreen, RECT *pRect, RECT *prcSrc)
+{
+ HRESULT ddrval = DD_OK;
+ unsigned i;
+ winScreenPriv(pScreen);
+
+ for (i = 0; i < 3; ++i)
+ {
+ ddrval = IDirectDrawSurface4_Blt(pScreenPriv->pddsPrimary4, pRect, pScreenPriv->pddsShadow4, prcSrc, DDBLT_WAIT, NULL);
+ /* Try to regain the primary surface and blit again if we've lost it */
+ if (ddrval == DDERR_SURFACELOST)
+ {
+ /* Surface was lost */
+ ErrorF ("IDirectDrawSurface4_Blt reported that the primary "
+ "surface was lost, trying to restore, retry: %d\n", i + 1);
+
+ /* Try to restore the surface, once */
+
+ if (i==1)
+ {
+ ErrorF("Recreating DDraw surface because restoring of surface didn't work.\n");
+ winAllocateFBShadowDDNL(pScreen);
+ }
+ else
+ {
+ ddrval = IDirectDraw4_RestoreAllSurfaces (pScreenPriv->pdd4);
+ ErrorF ("IDirectDraw4_RestoreAllSurfaces 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", ddrval);
+ }
+ /* Loop around to try the blit one more time */
+ continue;
+ }
+ else if (FAILED (ddrval))
+ {
+ ErrorF ("IDirectDrawSurface4_Blt failed, but surface not "
+ "lost: %08x %d\n", ddrval, ddrval);
+ }
+ break;
+ }
+ return ddrval;
+}
+
+
+/*
+ * 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;
+}
+
+
+static void ClosePrimarySurfaceShadowDDNL (winPrivScreenPtr pScreenPriv)
+{
+ /* 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;
+ }
+
+}
+
+static void ReleaseDDNL(winPrivScreenPtr pScreenPriv)
+{
+ /* Release the clipper object */
+ if (pScreenPriv->pddcPrimary)
+ {
+ IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
+ pScreenPriv->pddcPrimary = 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;
+ }
+}
+
+/*
+ * Detach the clipper and release the primary surface.
+ * Called from WM_DISPLAYCHANGE.
+ */
+
+static Bool
+winReleasePrimarySurfaceShadowDDNL (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ winDebug ("winReleasePrimarySurfaceShadowDDNL - Hello\n");
+
+ ClosePrimarySurfaceShadowDDNL(pScreenPriv);
+
+ 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);
+
+ /* Set the padded screen width */
+ pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth,
+ pScreenInfo->dwBPP);
+
+ if ( pScreenInfo->pfb)
+ {
+ ErrorF("winAllocateFBShadowDDNL calling for the second time, reallocating\n");
+ lpSurface=pScreenInfo->pfb;
+
+ if (pScreenPriv->pddsShadow4)
+ {
+ IDirectDrawSurface4_Release (pScreenPriv->pddsShadow4);
+ pScreenPriv->pddsShadow4 = NULL;
+ }
+ ClosePrimarySurfaceShadowDDNL(pScreenPriv);
+ ReleaseDDNL(pScreenPriv);
+ }
+ else
+ {
+ /* 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");
+
+ /* 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;
+}
+
+static void
+winFreeFBShadowDDNL(ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* 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 primary surface, if there is one */
+ winReleasePrimarySurfaceShadowDDNL(pScreen);
+
+ ReleaseDDNL(pScreenPriv);
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+}
+
+#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);
+ RECT rcDest, rcSrc;
+ POINT ptOrigin;
+ DWORD dwBox = RegionNumRects (damage);
+ BoxPtr pBox = RegionRects (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;
+
+ /* Return immediately if we didn't get needed surfaces */
+ if (!pScreenPriv->pddsPrimary4 || !pScreenPriv->pddsShadow4)
+ 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 */
+ if (pScreenPriv->pddsPrimary4)
+ myIDirectDrawSurface4_Blt (pScreen,
+ &rcDest,
+ &rcSrc);
+
+ /* Get a pointer to the next box */
+ ++pBox;
+ }
+ }
+ else
+ {
+ BoxPtr pBoxExtents = RegionExtents(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 */
+ myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc);
+
+ /* Reset the clip region */
+ SelectClipRgn (pScreenPriv->hdcScreen, NULL);
+ }
+}
+
+static Bool
+winInitScreenShadowDDNL(ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ /* Get a device context for the screen */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+
+ return winAllocateFBShadowDDNL(pScreen);
+}
+
+/*
+ * 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);
+ if (pScreen->CloseScreen)
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ winFreeFBShadowDDNL(pScreen);
+
+ /* Free the screen DC */
+ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ /* 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;
+
+ /* 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:
+ /* 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
+ break;
+
+ case 8:
+ 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;
+ }
+ 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->fFullScreen &&
+ (pScreenInfo->dwBPP != WIN_DEFAULT_BPP)))
+ {
+ /* Otherwise, We'll use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+ }
+
+ /* 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;
+
+ /* Our Blt should be clipped to the invalidated region */
+ ddrval = myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc);
+ if (FAILED (ddrval))
+ {
+ fReturn = FALSE;
+ }
+
+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;
+ 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 */
+ myIDirectDrawSurface4_Blt (pScreen, &rcDest, &rcSrc);
+ 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->pwinFreeFB = winFreeFBShadowDDNL;
+ pScreenPriv->pwinShadowUpdate = winShadowUpdateDDNL;
+ pScreenPriv->pwinInitScreen = winInitScreenShadowDDNL;
+ 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/winshadgdi.c b/xorg-server/hw/xwin/winshadgdi.c index 7d53d4969..bcb2051fc 100644 --- a/xorg-server/hw/xwin/winshadgdi.c +++ b/xorg-server/hw/xwin/winshadgdi.c @@ -1,1237 +1,1238 @@ -/* - *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. - * - * Authors: Harold L Hunt II - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" - - -/* - * Local function prototypes - */ - -#ifdef XWIN_MULTIWINDOW -static wBOOL CALLBACK -winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam); - -static wBOOL CALLBACK -winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam); -#endif - -static Bool -winAllocateFBShadowGDI (ScreenPtr pScreen); - -static void -winShadowUpdateGDI (ScreenPtr pScreen, - shadowBufPtr pBuf); - -static Bool -winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen); - -static Bool -winInitVisualsShadowGDI (ScreenPtr pScreen); - -static Bool -winAdjustVideoModeShadowGDI (ScreenPtr pScreen); - -static Bool -winBltExposedRegionsShadowGDI (ScreenPtr pScreen); - -static Bool -winActivateAppShadowGDI (ScreenPtr pScreen); - -static Bool -winRedrawScreenShadowGDI (ScreenPtr pScreen); - -static Bool -winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen); - -static Bool -winInstallColormapShadowGDI (ColormapPtr pColormap); - -static Bool -winStoreColorsShadowGDI (ColormapPtr pmap, - int ndef, - xColorItem *pdefs); - -static Bool -winCreateColormapShadowGDI (ColormapPtr pColormap); - -static Bool -winDestroyColormapShadowGDI (ColormapPtr pColormap); - - -/* - * Internal function to get the DIB format that is compatible with the screen - */ - -static -Bool -winQueryScreenDIBFormat (ScreenPtr pScreen, BITMAPINFOHEADER *pbmih) -{ - winScreenPriv(pScreen); - HBITMAP hbmp; -#ifdef WINDBG - LPDWORD pdw = NULL; -#endif - - /* Create a memory bitmap compatible with the screen */ - hbmp = CreateCompatibleBitmap (pScreenPriv->hdcScreen, 1, 1); - if (hbmp == NULL) - { - ErrorF ("winQueryScreenDIBFormat - CreateCompatibleBitmap failed\n"); - return FALSE; - } - - /* Initialize our bitmap info header */ - ZeroMemory (pbmih, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD)); - pbmih->biSize = sizeof (BITMAPINFOHEADER); - - /* Get the biBitCount */ - if (!GetDIBits (pScreenPriv->hdcScreen, - hbmp, - 0, 1, - NULL, - (BITMAPINFO*) pbmih, - DIB_RGB_COLORS)) - { - ErrorF ("winQueryScreenDIBFormat - First call to GetDIBits failed\n"); - DeleteObject (hbmp); - return FALSE; - } - -#ifdef WINDBG - /* Get a pointer to bitfields */ - pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); - - winDebug ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n", - pdw[0], pdw[1], pdw[2]); -#endif - - /* Get optimal color table, or the optimal bitfields */ - if (!GetDIBits (pScreenPriv->hdcScreen, - hbmp, - 0, 1, - NULL, - (BITMAPINFO*)pbmih, - DIB_RGB_COLORS)) - { - ErrorF ("winQueryScreenDIBFormat - Second call to GetDIBits " - "failed\n"); - DeleteObject (hbmp); - return FALSE; - } - - /* Free memory */ - DeleteObject (hbmp); - - return TRUE; -} - - -/* - * Internal function to determine the GDI bits per rgb and bit masks - */ - -static -Bool -winQueryRGBBitsAndMasks (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - BITMAPINFOHEADER *pbmih = NULL; - Bool fReturn = TRUE; - LPDWORD pdw = NULL; - DWORD dwRedBits, dwGreenBits, dwBlueBits; - - /* Color masks for 8 bpp are standardized */ - if (GetDeviceCaps (pScreenPriv->hdcScreen, RASTERCAPS) & RC_PALETTE) - { - /* - * RGB BPP for 8 bit palletes is always 8 - * and the color masks are always 0. - */ - pScreenPriv->dwBitsPerRGB = 8; - pScreenPriv->dwRedMask = 0x0L; - pScreenPriv->dwGreenMask = 0x0L; - pScreenPriv->dwBlueMask = 0x0L; - return TRUE; - } - - /* Color masks for 24 bpp are standardized */ - if (GetDeviceCaps (pScreenPriv->hdcScreen, PLANES) - * GetDeviceCaps (pScreenPriv->hdcScreen, BITSPIXEL) == 24) - { - winDebug ("winQueryRGBBitsAndMasks - GetDeviceCaps (BITSPIXEL) " - "returned 24 for the screen. Using default 24bpp masks.\n"); - - /* 8 bits per primary color */ - pScreenPriv->dwBitsPerRGB = 8; - - /* Set screen privates masks */ - pScreenPriv->dwRedMask = WIN_24BPP_MASK_RED; - pScreenPriv->dwGreenMask = WIN_24BPP_MASK_GREEN; - pScreenPriv->dwBlueMask = WIN_24BPP_MASK_BLUE; - - return TRUE; - } - - /* Allocate a bitmap header and color table */ - pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) - + 256 * sizeof (RGBQUAD)); - if (pbmih == NULL) - { - ErrorF ("winQueryRGBBitsAndMasks - malloc failed\n"); - return FALSE; - } - - /* Get screen description */ - if (winQueryScreenDIBFormat (pScreen, pbmih)) - { - /* Get a pointer to bitfields */ - pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); - -#ifdef WINDBG - winDebug ("%s - Masks: %08x %08x %08x\n", __FUNCTION__, - pdw[0], pdw[1], pdw[2]); - winDebug ("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__, - pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount, pbmih->biPlanes); - winDebug ("%s - Compression: %d %s\n", __FUNCTION__, - pbmih->biCompression, - (pbmih->biCompression == BI_RGB?"(BI_RGB)": - (pbmih->biCompression == BI_RLE8?"(BI_RLE8)": - (pbmih->biCompression == BI_RLE4?"(BI_RLE4)": - (pbmih->biCompression == BI_BITFIELDS?"(BI_BITFIELDS)":"" - ))))); -#endif - - /* Handle BI_RGB case, which is returned by Wine */ - if (pbmih->biCompression == BI_RGB) - { - dwRedBits = 5; - dwGreenBits = 5; - dwBlueBits = 5; - - pScreenPriv->dwBitsPerRGB = 5; - - /* Set screen privates masks */ - pScreenPriv->dwRedMask = 0x7c00; - pScreenPriv->dwGreenMask = 0x03e0; - pScreenPriv->dwBlueMask = 0x001f; - } - else - { - /* Count the number of bits in each mask */ - dwRedBits = winCountBits (pdw[0]); - dwGreenBits = winCountBits (pdw[1]); - dwBlueBits = winCountBits (pdw[2]); - - /* Find maximum bits per red, green, blue */ - if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwRedBits; - else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits) - pScreenPriv->dwBitsPerRGB = dwGreenBits; - else - pScreenPriv->dwBitsPerRGB = dwBlueBits; - - /* Set screen privates masks */ - pScreenPriv->dwRedMask = pdw[0]; - pScreenPriv->dwGreenMask = pdw[1]; - pScreenPriv->dwBlueMask = pdw[2]; - } - } - else - { - ErrorF ("winQueryRGBBitsAndMasks - winQueryScreenDIBFormat failed\n"); - free (pbmih); - fReturn = FALSE; - } - - /* Free memory */ - free (pbmih); - - return fReturn; -} - - -#ifdef XWIN_MULTIWINDOW -/* - * Redraw all ---? - */ - -static wBOOL CALLBACK -winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam) -{ - if (hwnd == (HWND)lParam) - return TRUE; - InvalidateRect (hwnd, NULL, FALSE); - UpdateWindow (hwnd); - return TRUE; -} - -static wBOOL CALLBACK -winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam) -{ - BoxPtr pDamage = (BoxPtr)lParam; - RECT rcClient, rcDamage, rcRedraw; - POINT topLeft, bottomRight; - - if (IsIconic (hwnd)) - return TRUE; /* Don't care minimized windows */ - - /* Convert the damaged area from Screen coords to Client coords */ - topLeft.x = pDamage->x1; topLeft.y = pDamage->y1; - bottomRight.x = pDamage->x2; bottomRight.y = pDamage->y2; - topLeft.x += GetSystemMetrics (SM_XVIRTUALSCREEN); - bottomRight.x += GetSystemMetrics (SM_XVIRTUALSCREEN); - topLeft.y += GetSystemMetrics (SM_YVIRTUALSCREEN); - bottomRight.y += GetSystemMetrics (SM_YVIRTUALSCREEN); - ScreenToClient (hwnd, &topLeft); - ScreenToClient (hwnd, &bottomRight); - SetRect (&rcDamage, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); - - GetClientRect (hwnd, &rcClient); - - if (IntersectRect (&rcRedraw, &rcClient, &rcDamage)) - { - InvalidateRect (hwnd, &rcRedraw, FALSE); - UpdateWindow (hwnd); - } - return TRUE; -} -#endif - - -/* - * Allocate a DIB for the shadow framebuffer GDI server - */ - -static Bool -winAllocateFBShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - DIBSECTION dibsection; - Bool fReturn = TRUE; - - /* Describe shadow bitmap to be created */ - pScreenPriv->pbmih->biWidth = pScreenInfo->dwWidth; - pScreenPriv->pbmih->biHeight = -pScreenInfo->dwHeight; - - winDebug ("winAllocateFBShadowGDI - Creating DIB with width: %d height: %d " - "depth: %d\n", - (int) pScreenPriv->pbmih->biWidth, (int) -pScreenPriv->pbmih->biHeight, pScreenPriv->pbmih->biBitCount); - - /* Create a DI shadow bitmap with a bit pointer */ - pScreenPriv->hbmpShadow = CreateDIBSection (pScreenPriv->hdcScreen, - (BITMAPINFO *) pScreenPriv->pbmih, - DIB_RGB_COLORS, - (VOID**) &pScreenInfo->pfb, - NULL, - 0); - if (pScreenPriv->hbmpShadow == NULL || pScreenInfo->pfb == NULL) - { - winW32Error ("winAllocateFBShadowGDI - CreateDIBSection failed:"); - return FALSE; - } - else - { - winDebug ("winAllocateFBShadowGDI - Shadow buffer allocated\n"); - } - - /* Get information about the bitmap that was allocated */ - GetObject (pScreenPriv->hbmpShadow, - sizeof (dibsection), - &dibsection); - - /* Print information about bitmap allocated */ - winDebug ("winAllocateFBShadowGDI - Dibsection width: %d height: %d " - "depth: %d size image: %d\n", - (int) dibsection.dsBmih.biWidth, (int) dibsection.dsBmih.biHeight, - dibsection.dsBmih.biBitCount, - (int) dibsection.dsBmih.biSizeImage); - - /* Select the shadow bitmap into the shadow DC */ - SelectObject (pScreenPriv->hdcShadow, - pScreenPriv->hbmpShadow); - - winDebug ("winAllocateFBShadowGDI - Attempting a shadow blit\n"); - - /* Do a test blit from the shadow to the screen, I think */ - fReturn = BitBlt (pScreenPriv->hdcScreen, - 0, 0, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - pScreenPriv->hdcShadow, - 0, 0, - SRCCOPY); - if (fReturn) - { - winDebug ("winAllocateFBShadowGDI - Shadow blit success\n"); - } - else - { - winW32Error ("winAllocateFBShadowGDI - Shadow blit failure\n"); - /* ago: ignore this error. The blit fails with wine, but does not - * cause any problems later. */ - - fReturn = TRUE; - } - - /* Look for height weirdness */ - if (dibsection.dsBmih.biHeight < 0) - { - dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight; - } - - /* Set screeninfo stride */ - pScreenInfo->dwStride = ((dibsection.dsBmih.biSizeImage - / dibsection.dsBmih.biHeight) - * 8) / pScreenInfo->dwBPP; - - winDebug ("winAllocateFBShadowGDI - Created shadow stride: %d\n", - (int) pScreenInfo->dwStride); - -#ifdef XWIN_MULTIWINDOW - /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) - EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); -#endif - - return fReturn; -} - -static void -winFreeFBShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Free the shadow bitmap */ - DeleteObject (pScreenPriv->hbmpShadow); - - /* Invalidate the ScreenInfo's fb pointer */ - pScreenInfo->pfb = NULL; -} - -/* - * Blit the damaged regions of the shadow fb to the screen - */ - -static void -winShadowUpdateGDI (ScreenPtr pScreen, - shadowBufPtr pBuf) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - RegionPtr damage = shadowDamage(pBuf); - DWORD dwBox = RegionNumRects (damage); - BoxPtr pBox = RegionRects (damage); - int x, y, w, h; - HRGN hrgnTemp = NULL, hrgnCombined = NULL; -#ifdef XWIN_UPDATESTATS - static DWORD s_dwNonUnitRegions = 0; - static DWORD s_dwTotalUpdates = 0; - static DWORD s_dwTotalBoxes = 0; -#endif - BoxPtr pBoxExtents = RegionExtents(damage); - - /* - * 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; - -#ifdef XWIN_UPDATESTATS - ++s_dwTotalUpdates; - s_dwTotalBoxes += dwBox; - - if (dwBox != 1) - { - ++s_dwNonUnitRegions; - winDebug ("winShadowUpdatGDI - dwBox: %d\n", dwBox); - } - - if ((s_dwTotalUpdates % 100) == 0) - { - winDebug ("winShadowUpdateGDI - %d%% non-unity regions, avg boxes: %d " - "nu: %d tu: %d\n", - (s_dwNonUnitRegions * 100) / s_dwTotalUpdates, - s_dwTotalBoxes / s_dwTotalUpdates, - s_dwNonUnitRegions, s_dwTotalUpdates); - } -#endif /* XWIN_UPDATESTATS */ - - /* - * 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->fMultiWindow && - (pScreenInfo->dwClipUpdatesNBoxes == 0 || - dwBox < pScreenInfo->dwClipUpdatesNBoxes)) - { - /* Loop through all boxes in the damaged region */ - while (dwBox--) - { - /* - * Calculate x offset, y offset, width, and height for - * current damage box - */ - x = pBox->x1; - y = pBox->y1; - w = pBox->x2 - pBox->x1; - h = pBox->y2 - pBox->y1; - - BitBlt (pScreenPriv->hdcScreen, - x, y, - w, h, - pScreenPriv->hdcShadow, - x, y, - SRCCOPY); - - /* Get a pointer to the next box */ - ++pBox; - } - } - else if (!pScreenInfo->fMultiWindow) - { - /* 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; - - /* - * Blit the shadow buffer to the screen, - * constrained to the clipping region. - */ - BitBlt (pScreenPriv->hdcScreen, - pBoxExtents->x1, pBoxExtents->y1, - pBoxExtents->x2 - pBoxExtents->x1, - pBoxExtents->y2 - pBoxExtents->y1, - pScreenPriv->hdcShadow, - pBoxExtents->x1, pBoxExtents->y1, - SRCCOPY); - - /* Reset the clip region */ - SelectClipRgn (pScreenPriv->hdcScreen, NULL); - } - -#ifdef XWIN_MULTIWINDOW - /* Redraw all multiwindow windows */ - if (pScreenInfo->fMultiWindow) - EnumThreadWindows (g_dwCurrentThreadID, - winRedrawDamagedWindowShadowGDI, - (LPARAM)pBoxExtents); -#endif -} - - -static Bool -winInitScreenShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - - /* Get device contexts for the screen and shadow bitmap */ - pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); - pScreenPriv->hdcShadow = CreateCompatibleDC (pScreenPriv->hdcScreen); - - /* Allocate bitmap info header */ - pScreenPriv->pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER) - + 256 * sizeof (RGBQUAD)); - if (pScreenPriv->pbmih == NULL) - { - ErrorF ("winInitScreenShadowGDI - malloc () failed\n"); - return FALSE; - } - - /* Query the screen format */ - if (!winQueryScreenDIBFormat (pScreen, pScreenPriv->pbmih)) - { - ErrorF ("winInitScreenShadowGDI - winQueryScreenDIBFormat failed\n"); - return FALSE; - } - - /* Determine our color masks */ - if (!winQueryRGBBitsAndMasks (pScreen)) - { - ErrorF ("winInitScreenShadowGDI - winQueryRGBBitsAndMasks failed\n"); - return FALSE; - } - - return winAllocateFBShadowGDI(pScreen); -} - -/* See Porting Layer Definition - p. 33 */ -/* - * We wrap whatever CloseScreen procedure was specified by fb; - * a pointer to said procedure is stored in our privates. - */ - -static Bool -winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - Bool fReturn; - - winDebug ("winCloseScreenShadowGDI - 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); - - /* Delete the window property */ - RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP); - - /* Free the shadow DC; which allows the bitmap to be freed */ - DeleteDC (pScreenPriv->hdcShadow); - - winFreeFBShadowGDI(pScreen); - - /* Free the screen DC */ - ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen); - - /* 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 - - /* Invalidate our screeninfo's pointer to the screen */ - pScreenInfo->pScreen = 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 -winInitVisualsShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Display debugging information */ - winDebug ("winInitVisualsShadowGDI - 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: - /* Setup the real visual */ - if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth, - TrueColorMask, - pScreenPriv->dwBitsPerRGB, - -1, - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask)) - { - ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks " - "failed\n"); - return FALSE; - } - -#ifdef XWIN_EMULATEPSEUDO - if (!pScreenInfo->fEmulatePseudo) - break; - - /* Setup a pseudocolor visual */ - if (!miSetVisualTypesAndMasks (8, - PseudoColorMask, - 8, - -1, - 0, - 0, - 0)) - { - ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks " - "failed for PseudoColor\n"); - return FALSE; - } -#endif - break; - - case 8: - if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth, - PseudoColorMask, - pScreenPriv->dwBitsPerRGB, - PseudoColor, - pScreenPriv->dwRedMask, - pScreenPriv->dwGreenMask, - pScreenPriv->dwBlueMask)) - { - ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks " - "failed\n"); - return FALSE; - } - break; - - default: - ErrorF ("winInitVisualsShadowGDI - Unknown screen depth\n"); - return FALSE; - } - - winDebug ("winInitVisualsShadowGDI - Returning\n"); - - return TRUE; -} - - -/* - * Adjust the proposed video mode - */ - -static Bool -winAdjustVideoModeShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - HDC hdc; - DWORD dwBPP; - - hdc = GetDC (NULL); - - /* We're in serious trouble if we can't get a DC */ - if (hdc == NULL) - { - ErrorF ("winAdjustVideoModeShadowGDI - GetDC () failed\n"); - return FALSE; - } - - /* Query GDI for current display depth */ - dwBPP = GetDeviceCaps (hdc, BITSPIXEL); - - /* GDI cannot change the screen depth, so always use GDI's depth */ - pScreenInfo->dwBPP = dwBPP; - - /* Release our DC */ - ReleaseDC (NULL, hdc); - hdc = NULL; - - return TRUE; -} - - -/* - * Blt exposed regions to the screen - */ - -static Bool -winBltExposedRegionsShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - winPrivCmapPtr pCmapPriv = NULL; - HDC hdcUpdate; - PAINTSTRUCT ps; - - /* BeginPaint gives us an hdc that clips to the invalidated region */ - hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps); - - /* Realize the palette, if we have one */ - if (pScreenPriv->pcmapInstalled != NULL) - { - pCmapPriv = winGetCmapPriv (pScreenPriv->pcmapInstalled); - - SelectPalette (hdcUpdate, pCmapPriv->hPalette, FALSE); - RealizePalette (hdcUpdate); - } - - /* Our BitBlt will be clipped to the invalidated region */ - BitBlt (hdcUpdate, - 0, 0, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - pScreenPriv->hdcShadow, - 0, 0, - SRCCOPY); - - /* EndPaint frees the DC */ - EndPaint (pScreenPriv->hwndScreen, &ps); - -#ifdef XWIN_MULTIWINDOW - /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) - EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, - (LPARAM)pScreenPriv->hwndScreen); -#endif - - return TRUE; -} - - -/* - * Do any engine-specific appliation-activation processing - */ - -static Bool -winActivateAppShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* - * 2004/04/12 - Harold - We perform the restoring or minimizing - * manually for ShadowGDI in fullscreen modes so that this engine - * will perform just like ShadowDD and ShadowDDNL in fullscreen mode; - * if we do not do this then our fullscreen window will appear in the - * z-order when it is deactivated and it can be uncovered by resizing - * or minimizing another window that is on top of it, which is not how - * the DirectDraw engines work. Therefore we keep this code here to - * make sure that all engines work the same in fullscreen mode. - */ - - /* - * Are we active? - * Are we fullscreen? - */ - if (pScreenPriv->fActive - && pScreenInfo->fFullScreen) - { - /* - * Activating, attempt to bring our window - * to the top of the display - */ - ShowWindow (pScreenPriv->hwndScreen, SW_RESTORE); - } - else if (!pScreenPriv->fActive - && pScreenInfo->fFullScreen) - { - /* - * Deactivating, stuff our window onto the - * task bar. - */ - ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE); - } - - return TRUE; -} - - -/* - * Reblit the shadow framebuffer to the screen. - */ - -static Bool -winRedrawScreenShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Redraw the whole window, to take account for the new colors */ - BitBlt (pScreenPriv->hdcScreen, - 0, 0, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - pScreenPriv->hdcShadow, - 0, 0, - SRCCOPY); - -#ifdef XWIN_MULTIWINDOW - /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) - EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); -#endif - - return TRUE; -} - - - -/* - * Realize the currently installed colormap - */ - -static Bool -winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winPrivCmapPtr pCmapPriv = NULL; - - winDebug ("winRealizeInstalledPaletteShadowGDI\n"); - - /* Don't do anything if there is not a colormap */ - if (pScreenPriv->pcmapInstalled == NULL) - { - winDebug ("winRealizeInstalledPaletteShadowGDI - No colormap " - "installed\n"); - return TRUE; - } - - pCmapPriv = winGetCmapPriv (pScreenPriv->pcmapInstalled); - - /* Realize our palette for the screen */ - if (RealizePalette (pScreenPriv->hdcScreen) == GDI_ERROR) - { - ErrorF ("winRealizeInstalledPaletteShadowGDI - RealizePalette () " - "failed\n"); - return FALSE; - } - - /* Set the DIB color table */ - if (SetDIBColorTable (pScreenPriv->hdcShadow, - 0, - WIN_NUM_PALETTE_ENTRIES, - pCmapPriv->rgbColors) == 0) - { - ErrorF ("winRealizeInstalledPaletteShadowGDI - SetDIBColorTable () " - "failed\n"); - return FALSE; - } - - return TRUE; -} - - -/* - * Install the specified colormap - */ - -static Bool -winInstallColormapShadowGDI (ColormapPtr pColormap) -{ - ScreenPtr pScreen = pColormap->pScreen; - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - winCmapPriv(pColormap); - - /* - * Tell Windows to install the new colormap - */ - if (SelectPalette (pScreenPriv->hdcScreen, - pCmapPriv->hPalette, - FALSE) == NULL) - { - ErrorF ("winInstallColormapShadowGDI - SelectPalette () failed\n"); - return FALSE; - } - - /* Realize the palette */ - if (GDI_ERROR == RealizePalette (pScreenPriv->hdcScreen)) - { - ErrorF ("winInstallColormapShadowGDI - RealizePalette () failed\n"); - return FALSE; - } - - /* Set the DIB color table */ - if (SetDIBColorTable (pScreenPriv->hdcShadow, - 0, - WIN_NUM_PALETTE_ENTRIES, - pCmapPriv->rgbColors) == 0) - { - ErrorF ("winInstallColormapShadowGDI - SetDIBColorTable () failed\n"); - return FALSE; - } - - /* Redraw the whole window, to take account for the new colors */ - BitBlt (pScreenPriv->hdcScreen, - 0, 0, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - pScreenPriv->hdcShadow, - 0, 0, - SRCCOPY); - - /* Save a pointer to the newly installed colormap */ - pScreenPriv->pcmapInstalled = pColormap; - -#ifdef XWIN_MULTIWINDOW - /* Redraw all windows */ - if (pScreenInfo->fMultiWindow) - EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0); -#endif - - return TRUE; -} - - -/* - * Store the specified colors in the specified colormap - */ - -static Bool -winStoreColorsShadowGDI (ColormapPtr pColormap, - int ndef, - xColorItem *pdefs) -{ - ScreenPtr pScreen = pColormap->pScreen; - winScreenPriv(pScreen); - winCmapPriv(pColormap); - ColormapPtr curpmap = pScreenPriv->pcmapInstalled; - - /* Put the X colormap entries into the Windows logical palette */ - if (SetPaletteEntries (pCmapPriv->hPalette, - pdefs[0].pixel, - ndef, - pCmapPriv->peColors + pdefs[0].pixel) == 0) - { - ErrorF ("winStoreColorsShadowGDI - SetPaletteEntries () failed\n"); - return FALSE; - } - - /* Don't install the Windows palette if the colormap is not installed */ - if (pColormap != curpmap) - { - return TRUE; - } - - /* Try to install the newly modified colormap */ - if (!winInstallColormapShadowGDI (pColormap)) - { - ErrorF ("winInstallColormapShadowGDI - winInstallColormapShadowGDI " - "failed\n"); - return FALSE; - } - -#if 0 - /* Tell Windows that the palette has changed */ - RealizePalette (pScreenPriv->hdcScreen); - - /* Set the DIB color table */ - if (SetDIBColorTable (pScreenPriv->hdcShadow, - pdefs[0].pixel, - ndef, - pCmapPriv->rgbColors + pdefs[0].pixel) == 0) - { - ErrorF ("winInstallColormapShadowGDI - SetDIBColorTable () failed\n"); - return FALSE; - } - - /* Save a pointer to the newly installed colormap */ - pScreenPriv->pcmapInstalled = pColormap; -#endif - - return TRUE; -} - - -/* - * Colormap initialization procedure - */ - -static Bool -winCreateColormapShadowGDI (ColormapPtr pColormap) -{ - LPLOGPALETTE lpPaletteNew = NULL; - DWORD dwEntriesMax; - VisualPtr pVisual; - HPALETTE hpalNew = NULL; - winCmapPriv(pColormap); - - /* Get a pointer to the visual that the colormap belongs to */ - pVisual = pColormap->pVisual; - - /* Get the maximum number of palette entries for this visual */ - dwEntriesMax = pVisual->ColormapEntries; - - /* Allocate a Windows logical color palette with max entries */ - lpPaletteNew = malloc (sizeof (LOGPALETTE) - + (dwEntriesMax - 1) * sizeof (PALETTEENTRY)); - if (lpPaletteNew == NULL) - { - ErrorF ("winCreateColormapShadowGDI - Couldn't allocate palette " - "with %d entries\n", - (int) dwEntriesMax); - return FALSE; - } - - /* Zero out the colormap */ - ZeroMemory (lpPaletteNew, sizeof (LOGPALETTE) - + (dwEntriesMax - 1) * sizeof (PALETTEENTRY)); - - /* Set the logical palette structure */ - lpPaletteNew->palVersion = 0x0300; - lpPaletteNew->palNumEntries = dwEntriesMax; - - /* Tell Windows to create the palette */ - hpalNew = CreatePalette (lpPaletteNew); - if (hpalNew == NULL) - { - ErrorF ("winCreateColormapShadowGDI - CreatePalette () failed\n"); - free (lpPaletteNew); - return FALSE; - } - - /* Save the Windows logical palette handle in the X colormaps' privates */ - pCmapPriv->hPalette = hpalNew; - - /* Free the palette initialization memory */ - free (lpPaletteNew); - - return TRUE; -} - - -/* - * Colormap destruction procedure - */ - -static Bool -winDestroyColormapShadowGDI (ColormapPtr pColormap) -{ - winScreenPriv(pColormap->pScreen); - winCmapPriv(pColormap); - - /* - * 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 ("winDestroyColormapShadowGDI - 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 device context */ - SelectPalette (pScreenPriv->hdcScreen, - GetStockObject (DEFAULT_PALETTE), - FALSE); - - /* Clear our private installed colormap pointer */ - pScreenPriv->pcmapInstalled = NULL; - } - - /* Try to delete the logical palette */ - if (DeleteObject (pCmapPriv->hPalette) == 0) - { - ErrorF ("winDestroyColormap - DeleteObject () failed\n"); - return FALSE; - } - - /* Invalidate the colormap privates */ - pCmapPriv->hPalette = NULL; - - return TRUE; -} - - -/* - * Set engine specific funtions - */ - -Bool -winSetEngineFunctionsShadowGDI (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Set our pointers */ - pScreenPriv->pwinAllocateFB = winAllocateFBShadowGDI; - pScreenPriv->pwinFreeFB = winFreeFBShadowGDI; - pScreenPriv->pwinShadowUpdate = winShadowUpdateGDI; - pScreenPriv->pwinInitScreen = winInitScreenShadowGDI; - pScreenPriv->pwinCloseScreen = winCloseScreenShadowGDI; - pScreenPriv->pwinInitVisuals = winInitVisualsShadowGDI; - pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowGDI; - if (pScreenInfo->fFullScreen) - pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen; - else - pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed; - pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB; - pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowGDI; - pScreenPriv->pwinActivateApp = winActivateAppShadowGDI; - pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowGDI; - pScreenPriv->pwinRealizeInstalledPalette = - winRealizeInstalledPaletteShadowGDI; - pScreenPriv->pwinInstallColormap = winInstallColormapShadowGDI; - pScreenPriv->pwinStoreColors = winStoreColorsShadowGDI; - pScreenPriv->pwinCreateColormap = winCreateColormapShadowGDI; - pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowGDI; - pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA; - pScreenPriv->pwinCreatePrimarySurface - = (winCreatePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; - pScreenPriv->pwinReleasePrimarySurface - = (winReleasePrimarySurfaceProcPtr) (void (*)(void))NoopDDA; -#ifdef XWIN_MULTIWINDOW - pScreenPriv->pwinFinishCreateWindowsWindow = - (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA; -#endif - - return TRUE; -} +/*
+ *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+
+/*
+ * Local function prototypes
+ */
+
+#ifdef XWIN_MULTIWINDOW
+static wBOOL CALLBACK
+winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam);
+
+static wBOOL CALLBACK
+winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam);
+#endif
+
+static Bool
+winAllocateFBShadowGDI (ScreenPtr pScreen);
+
+static void
+winShadowUpdateGDI (ScreenPtr pScreen,
+ shadowBufPtr pBuf);
+
+static Bool
+winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen);
+
+static Bool
+winInitVisualsShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winAdjustVideoModeShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winBltExposedRegionsShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winActivateAppShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winRedrawScreenShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen);
+
+static Bool
+winInstallColormapShadowGDI (ColormapPtr pColormap);
+
+static Bool
+winStoreColorsShadowGDI (ColormapPtr pmap,
+ int ndef,
+ xColorItem *pdefs);
+
+static Bool
+winCreateColormapShadowGDI (ColormapPtr pColormap);
+
+static Bool
+winDestroyColormapShadowGDI (ColormapPtr pColormap);
+
+
+/*
+ * Internal function to get the DIB format that is compatible with the screen
+ */
+
+static
+Bool
+winQueryScreenDIBFormat (ScreenPtr pScreen, BITMAPINFOHEADER *pbmih)
+{
+ winScreenPriv(pScreen);
+ HBITMAP hbmp;
+#ifdef WINDBG
+ LPDWORD pdw = NULL;
+#endif
+
+ /* Create a memory bitmap compatible with the screen */
+ hbmp = CreateCompatibleBitmap (pScreenPriv->hdcScreen, 1, 1);
+ if (hbmp == NULL)
+ {
+ ErrorF ("winQueryScreenDIBFormat - CreateCompatibleBitmap failed\n");
+ return FALSE;
+ }
+
+ /* Initialize our bitmap info header */
+ ZeroMemory (pbmih, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD));
+ pbmih->biSize = sizeof (BITMAPINFOHEADER);
+
+ /* Get the biBitCount */
+ if (!GetDIBits (pScreenPriv->hdcScreen,
+ hbmp,
+ 0, 1,
+ NULL,
+ (BITMAPINFO*) pbmih,
+ DIB_RGB_COLORS))
+ {
+ ErrorF ("winQueryScreenDIBFormat - First call to GetDIBits failed\n");
+ DeleteObject (hbmp);
+ return FALSE;
+ }
+
+#ifdef WINDBG
+ /* Get a pointer to bitfields */
+ pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER));
+
+ winDebug ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n",
+ pdw[0], pdw[1], pdw[2]);
+#endif
+
+ /* Get optimal color table, or the optimal bitfields */
+ if (!GetDIBits (pScreenPriv->hdcScreen,
+ hbmp,
+ 0, 1,
+ NULL,
+ (BITMAPINFO*)pbmih,
+ DIB_RGB_COLORS))
+ {
+ ErrorF ("winQueryScreenDIBFormat - Second call to GetDIBits "
+ "failed\n");
+ DeleteObject (hbmp);
+ return FALSE;
+ }
+
+ /* Free memory */
+ DeleteObject (hbmp);
+
+ return TRUE;
+}
+
+
+/*
+ * Internal function to determine the GDI bits per rgb and bit masks
+ */
+
+static
+Bool
+winQueryRGBBitsAndMasks (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ BITMAPINFOHEADER *pbmih = NULL;
+ Bool fReturn = TRUE;
+ LPDWORD pdw = NULL;
+ DWORD dwRedBits, dwGreenBits, dwBlueBits;
+
+ /* Color masks for 8 bpp are standardized */
+ if (GetDeviceCaps (pScreenPriv->hdcScreen, RASTERCAPS) & RC_PALETTE)
+ {
+ /*
+ * RGB BPP for 8 bit palletes is always 8
+ * and the color masks are always 0.
+ */
+ pScreenPriv->dwBitsPerRGB = 8;
+ pScreenPriv->dwRedMask = 0x0L;
+ pScreenPriv->dwGreenMask = 0x0L;
+ pScreenPriv->dwBlueMask = 0x0L;
+ return TRUE;
+ }
+
+ /* Color masks for 24 bpp are standardized */
+ if (GetDeviceCaps (pScreenPriv->hdcScreen, PLANES)
+ * GetDeviceCaps (pScreenPriv->hdcScreen, BITSPIXEL) == 24)
+ {
+ winDebug ("winQueryRGBBitsAndMasks - GetDeviceCaps (BITSPIXEL) "
+ "returned 24 for the screen. Using default 24bpp masks.\n");
+
+ /* 8 bits per primary color */
+ pScreenPriv->dwBitsPerRGB = 8;
+
+ /* Set screen privates masks */
+ pScreenPriv->dwRedMask = WIN_24BPP_MASK_RED;
+ pScreenPriv->dwGreenMask = WIN_24BPP_MASK_GREEN;
+ pScreenPriv->dwBlueMask = WIN_24BPP_MASK_BLUE;
+
+ return TRUE;
+ }
+
+ /* Allocate a bitmap header and color table */
+ pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER)
+ + 256 * sizeof (RGBQUAD));
+ if (pbmih == NULL)
+ {
+ ErrorF ("winQueryRGBBitsAndMasks - malloc failed\n");
+ return FALSE;
+ }
+
+ /* Get screen description */
+ if (winQueryScreenDIBFormat (pScreen, pbmih))
+ {
+ /* Get a pointer to bitfields */
+ pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER));
+
+#ifdef WINDBG
+ winDebug ("%s - Masks: %08x %08x %08x\n", __FUNCTION__,
+ pdw[0], pdw[1], pdw[2]);
+ winDebug ("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__,
+ pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount, pbmih->biPlanes);
+ winDebug ("%s - Compression: %d %s\n", __FUNCTION__,
+ pbmih->biCompression,
+ (pbmih->biCompression == BI_RGB?"(BI_RGB)":
+ (pbmih->biCompression == BI_RLE8?"(BI_RLE8)":
+ (pbmih->biCompression == BI_RLE4?"(BI_RLE4)":
+ (pbmih->biCompression == BI_BITFIELDS?"(BI_BITFIELDS)":""
+ )))));
+#endif
+
+ /* Handle BI_RGB case, which is returned by Wine */
+ if (pbmih->biCompression == BI_RGB)
+ {
+ dwRedBits = 5;
+ dwGreenBits = 5;
+ dwBlueBits = 5;
+
+ pScreenPriv->dwBitsPerRGB = 5;
+
+ /* Set screen privates masks */
+ pScreenPriv->dwRedMask = 0x7c00;
+ pScreenPriv->dwGreenMask = 0x03e0;
+ pScreenPriv->dwBlueMask = 0x001f;
+ }
+ else
+ {
+ /* Count the number of bits in each mask */
+ dwRedBits = winCountBits (pdw[0]);
+ dwGreenBits = winCountBits (pdw[1]);
+ dwBlueBits = winCountBits (pdw[2]);
+
+ /* Find maximum bits per red, green, blue */
+ if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwRedBits;
+ else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
+ pScreenPriv->dwBitsPerRGB = dwGreenBits;
+ else
+ pScreenPriv->dwBitsPerRGB = dwBlueBits;
+
+ /* Set screen privates masks */
+ pScreenPriv->dwRedMask = pdw[0];
+ pScreenPriv->dwGreenMask = pdw[1];
+ pScreenPriv->dwBlueMask = pdw[2];
+ }
+ }
+ else
+ {
+ ErrorF ("winQueryRGBBitsAndMasks - winQueryScreenDIBFormat failed\n");
+ free (pbmih);
+ fReturn = FALSE;
+ }
+
+ /* Free memory */
+ free (pbmih);
+
+ return fReturn;
+}
+
+
+#ifdef XWIN_MULTIWINDOW
+/*
+ * Redraw all ---?
+ */
+
+static wBOOL CALLBACK
+winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam)
+{
+ if (hwnd == (HWND)lParam)
+ return TRUE;
+ InvalidateRect (hwnd, NULL, FALSE);
+ UpdateWindow (hwnd);
+ return TRUE;
+}
+
+static wBOOL CALLBACK
+winRedrawDamagedWindowShadowGDI (HWND hwnd, LPARAM lParam)
+{
+ BoxPtr pDamage = (BoxPtr)lParam;
+ RECT rcClient, rcDamage, rcRedraw;
+ POINT topLeft, bottomRight;
+
+ if (IsIconic (hwnd))
+ return TRUE; /* Don't care minimized windows */
+
+ /* Convert the damaged area from Screen coords to Client coords */
+ topLeft.x = pDamage->x1; topLeft.y = pDamage->y1;
+ bottomRight.x = pDamage->x2; bottomRight.y = pDamage->y2;
+ topLeft.x += GetSystemMetrics (SM_XVIRTUALSCREEN);
+ bottomRight.x += GetSystemMetrics (SM_XVIRTUALSCREEN);
+ topLeft.y += GetSystemMetrics (SM_YVIRTUALSCREEN);
+ bottomRight.y += GetSystemMetrics (SM_YVIRTUALSCREEN);
+ ScreenToClient (hwnd, &topLeft);
+ ScreenToClient (hwnd, &bottomRight);
+ SetRect (&rcDamage, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
+
+ GetClientRect (hwnd, &rcClient);
+
+ if (IntersectRect (&rcRedraw, &rcClient, &rcDamage))
+ {
+ InvalidateRect (hwnd, &rcRedraw, FALSE);
+ UpdateWindow (hwnd);
+ }
+ return TRUE;
+}
+#endif
+
+
+/*
+ * Allocate a DIB for the shadow framebuffer GDI server
+ */
+
+static Bool
+winAllocateFBShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ DIBSECTION dibsection;
+ Bool fReturn = TRUE;
+
+ /* Describe shadow bitmap to be created */
+ pScreenPriv->pbmih->biWidth = pScreenInfo->dwWidth;
+ pScreenPriv->pbmih->biHeight = -pScreenInfo->dwHeight;
+
+ winDebug ("winAllocateFBShadowGDI - Creating DIB with width: %d height: %d "
+ "depth: %d\n",
+ (int) pScreenPriv->pbmih->biWidth, (int) -pScreenPriv->pbmih->biHeight, pScreenPriv->pbmih->biBitCount);
+
+ /* Create a DI shadow bitmap with a bit pointer */
+ pScreenPriv->hbmpShadow = CreateDIBSection (pScreenPriv->hdcScreen,
+ (BITMAPINFO *) pScreenPriv->pbmih,
+ DIB_RGB_COLORS,
+ (VOID**) &pScreenInfo->pfb,
+ NULL,
+ 0);
+ if (pScreenPriv->hbmpShadow == NULL || pScreenInfo->pfb == NULL)
+ {
+ winW32Error ("winAllocateFBShadowGDI - CreateDIBSection failed:");
+ return FALSE;
+ }
+ else
+ {
+ winDebug ("winAllocateFBShadowGDI - Shadow buffer allocated\n");
+ }
+
+ /* Get information about the bitmap that was allocated */
+ GetObject (pScreenPriv->hbmpShadow,
+ sizeof (dibsection),
+ &dibsection);
+
+ /* Print information about bitmap allocated */
+ winDebug ("winAllocateFBShadowGDI - Dibsection width: %d height: %d "
+ "depth: %d size image: %d\n",
+ (int) dibsection.dsBmih.biWidth, (int) dibsection.dsBmih.biHeight,
+ dibsection.dsBmih.biBitCount,
+ (int) dibsection.dsBmih.biSizeImage);
+
+ /* Select the shadow bitmap into the shadow DC */
+ SelectObject (pScreenPriv->hdcShadow,
+ pScreenPriv->hbmpShadow);
+
+ winDebug ("winAllocateFBShadowGDI - Attempting a shadow blit\n");
+
+ /* Do a test blit from the shadow to the screen, I think */
+ fReturn = BitBlt (pScreenPriv->hdcScreen,
+ 0, 0,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ pScreenPriv->hdcShadow,
+ 0, 0,
+ SRCCOPY);
+ if (fReturn)
+ {
+ winDebug ("winAllocateFBShadowGDI - Shadow blit success\n");
+ }
+ else
+ {
+ winW32Error ("winAllocateFBShadowGDI - Shadow blit failure\n");
+ /* ago: ignore this error. The blit fails with wine, but does not
+ * cause any problems later. */
+
+ fReturn = TRUE;
+ }
+
+ /* Look for height weirdness */
+ if (dibsection.dsBmih.biHeight < 0)
+ {
+ dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight;
+ }
+
+ /* Set screeninfo stride */
+ pScreenInfo->dwStride = ((dibsection.dsBmih.biSizeImage
+ / dibsection.dsBmih.biHeight)
+ * 8) / pScreenInfo->dwBPP;
+
+ winDebug ("winAllocateFBShadowGDI - Created shadow stride: %d\n",
+ (int) pScreenInfo->dwStride);
+
+#ifdef XWIN_MULTIWINDOW
+ /* Redraw all windows */
+ if (pScreenInfo->fMultiWindow)
+ EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
+#endif
+
+ return fReturn;
+}
+
+static void
+winFreeFBShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Free the shadow bitmap */
+ DeleteObject (pScreenPriv->hbmpShadow);
+
+ /* Invalidate the ScreenInfo's fb pointer */
+ pScreenInfo->pfb = NULL;
+}
+
+/*
+ * Blit the damaged regions of the shadow fb to the screen
+ */
+
+static void
+winShadowUpdateGDI (ScreenPtr pScreen,
+ shadowBufPtr pBuf)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ RegionPtr damage = shadowDamage(pBuf);
+ DWORD dwBox = RegionNumRects (damage);
+ BoxPtr pBox = RegionRects (damage);
+ int x, y, w, h;
+ HRGN hrgnTemp = NULL, hrgnCombined = NULL;
+#ifdef XWIN_UPDATESTATS
+ static DWORD s_dwNonUnitRegions = 0;
+ static DWORD s_dwTotalUpdates = 0;
+ static DWORD s_dwTotalBoxes = 0;
+#endif
+ BoxPtr pBoxExtents = RegionExtents(damage);
+
+ /*
+ * 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;
+
+#ifdef XWIN_UPDATESTATS
+ ++s_dwTotalUpdates;
+ s_dwTotalBoxes += dwBox;
+
+ if (dwBox != 1)
+ {
+ ++s_dwNonUnitRegions;
+ winDebug ("winShadowUpdatGDI - dwBox: %d\n", dwBox);
+ }
+
+ if ((s_dwTotalUpdates % 100) == 0)
+ {
+ winDebug ("winShadowUpdateGDI - %d%% non-unity regions, avg boxes: %d "
+ "nu: %d tu: %d\n",
+ (s_dwNonUnitRegions * 100) / s_dwTotalUpdates,
+ s_dwTotalBoxes / s_dwTotalUpdates,
+ s_dwNonUnitRegions, s_dwTotalUpdates);
+ }
+#endif /* XWIN_UPDATESTATS */
+
+ /*
+ * 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->fMultiWindow &&
+ (pScreenInfo->dwClipUpdatesNBoxes == 0 ||
+ dwBox < pScreenInfo->dwClipUpdatesNBoxes))
+ {
+ /* Loop through all boxes in the damaged region */
+ while (dwBox--)
+ {
+ /*
+ * Calculate x offset, y offset, width, and height for
+ * current damage box
+ */
+ x = pBox->x1;
+ y = pBox->y1;
+ w = pBox->x2 - pBox->x1;
+ h = pBox->y2 - pBox->y1;
+
+ BitBlt (pScreenPriv->hdcScreen,
+ x, y,
+ w, h,
+ pScreenPriv->hdcShadow,
+ x, y,
+ SRCCOPY);
+
+ /* Get a pointer to the next box */
+ ++pBox;
+ }
+ }
+ else if (!pScreenInfo->fMultiWindow)
+ {
+ /* 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;
+
+ /*
+ * Blit the shadow buffer to the screen,
+ * constrained to the clipping region.
+ */
+ BitBlt (pScreenPriv->hdcScreen,
+ pBoxExtents->x1, pBoxExtents->y1,
+ pBoxExtents->x2 - pBoxExtents->x1,
+ pBoxExtents->y2 - pBoxExtents->y1,
+ pScreenPriv->hdcShadow,
+ pBoxExtents->x1, pBoxExtents->y1,
+ SRCCOPY);
+
+ /* Reset the clip region */
+ SelectClipRgn (pScreenPriv->hdcScreen, NULL);
+ }
+
+#ifdef XWIN_MULTIWINDOW
+ /* Redraw all multiwindow windows */
+ if (pScreenInfo->fMultiWindow)
+ EnumThreadWindows (g_dwCurrentThreadID,
+ winRedrawDamagedWindowShadowGDI,
+ (LPARAM)pBoxExtents);
+#endif
+}
+
+
+static Bool
+winInitScreenShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+
+ /* Get device contexts for the screen and shadow bitmap */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+ pScreenPriv->hdcShadow = CreateCompatibleDC (pScreenPriv->hdcScreen);
+
+ /* Allocate bitmap info header */
+ pScreenPriv->pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER)
+ + 256 * sizeof (RGBQUAD));
+ if (pScreenPriv->pbmih == NULL)
+ {
+ ErrorF ("winInitScreenShadowGDI - malloc () failed\n");
+ return FALSE;
+ }
+
+ /* Query the screen format */
+ if (!winQueryScreenDIBFormat (pScreen, pScreenPriv->pbmih))
+ {
+ ErrorF ("winInitScreenShadowGDI - winQueryScreenDIBFormat failed\n");
+ return FALSE;
+ }
+
+ /* Determine our color masks */
+ if (!winQueryRGBBitsAndMasks (pScreen))
+ {
+ ErrorF ("winInitScreenShadowGDI - winQueryRGBBitsAndMasks failed\n");
+ return FALSE;
+ }
+
+ return winAllocateFBShadowGDI(pScreen);
+}
+
+/* See Porting Layer Definition - p. 33 */
+/*
+ * We wrap whatever CloseScreen procedure was specified by fb;
+ * a pointer to said procedure is stored in our privates.
+ */
+
+static Bool
+winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ Bool fReturn;
+
+ winDebug ("winCloseScreenShadowGDI - Freeing screen resources\n");
+
+ /* Flag that the screen is closed */
+ pScreenPriv->fClosed = TRUE;
+ pScreenPriv->fActive = FALSE;
+
+ /* Call the wrapped CloseScreen procedure */
+ WIN_UNWRAP(CloseScreen);
+ if (pScreen->CloseScreen)
+ fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+
+ /* Delete the window property */
+ RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
+
+ /* Free the shadow DC; which allows the bitmap to be freed */
+ DeleteDC (pScreenPriv->hdcShadow);
+
+ winFreeFBShadowGDI(pScreen);
+
+ /* Free the screen DC */
+ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
+
+ /* 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
+
+ /* Invalidate our screeninfo's pointer to the screen */
+ pScreenInfo->pScreen = 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
+winInitVisualsShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Display debugging information */
+ winDebug ("winInitVisualsShadowGDI - 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:
+ /* Setup the real visual */
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ TrueColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ -1,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ if (!pScreenInfo->fEmulatePseudo)
+ break;
+
+ /* Setup a pseudocolor visual */
+ if (!miSetVisualTypesAndMasks (8,
+ PseudoColorMask,
+ 8,
+ -1,
+ 0,
+ 0,
+ 0))
+ {
+ ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
+ "failed for PseudoColor\n");
+ return FALSE;
+ }
+#endif
+ break;
+
+ case 8:
+ if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
+ PseudoColorMask,
+ pScreenPriv->dwBitsPerRGB,
+ PseudoColor,
+ pScreenPriv->dwRedMask,
+ pScreenPriv->dwGreenMask,
+ pScreenPriv->dwBlueMask))
+ {
+ ErrorF ("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
+ "failed\n");
+ return FALSE;
+ }
+ break;
+
+ default:
+ ErrorF ("winInitVisualsShadowGDI - Unknown screen depth\n");
+ return FALSE;
+ }
+
+ winDebug ("winInitVisualsShadowGDI - Returning\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Adjust the proposed video mode
+ */
+
+static Bool
+winAdjustVideoModeShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ HDC hdc;
+ DWORD dwBPP;
+
+ hdc = GetDC (NULL);
+
+ /* We're in serious trouble if we can't get a DC */
+ if (hdc == NULL)
+ {
+ ErrorF ("winAdjustVideoModeShadowGDI - GetDC () failed\n");
+ return FALSE;
+ }
+
+ /* Query GDI for current display depth */
+ dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
+
+ /* GDI cannot change the screen depth, so always use GDI's depth */
+ pScreenInfo->dwBPP = dwBPP;
+
+ /* Release our DC */
+ ReleaseDC (NULL, hdc);
+ hdc = NULL;
+
+ return TRUE;
+}
+
+
+/*
+ * Blt exposed regions to the screen
+ */
+
+static Bool
+winBltExposedRegionsShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ winPrivCmapPtr pCmapPriv = NULL;
+ HDC hdcUpdate;
+ PAINTSTRUCT ps;
+
+ /* BeginPaint gives us an hdc that clips to the invalidated region */
+ hdcUpdate = BeginPaint (pScreenPriv->hwndScreen, &ps);
+
+ /* Realize the palette, if we have one */
+ if (pScreenPriv->pcmapInstalled != NULL)
+ {
+ pCmapPriv = winGetCmapPriv (pScreenPriv->pcmapInstalled);
+
+ SelectPalette (hdcUpdate, pCmapPriv->hPalette, FALSE);
+ RealizePalette (hdcUpdate);
+ }
+
+ /* Our BitBlt will be clipped to the invalidated region */
+ BitBlt (hdcUpdate,
+ 0, 0,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ pScreenPriv->hdcShadow,
+ 0, 0,
+ SRCCOPY);
+
+ /* EndPaint frees the DC */
+ EndPaint (pScreenPriv->hwndScreen, &ps);
+
+#ifdef XWIN_MULTIWINDOW
+ /* Redraw all windows */
+ if (pScreenInfo->fMultiWindow)
+ EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI,
+ (LPARAM)pScreenPriv->hwndScreen);
+#endif
+
+ return TRUE;
+}
+
+
+/*
+ * Do any engine-specific appliation-activation processing
+ */
+
+static Bool
+winActivateAppShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /*
+ * 2004/04/12 - Harold - We perform the restoring or minimizing
+ * manually for ShadowGDI in fullscreen modes so that this engine
+ * will perform just like ShadowDD and ShadowDDNL in fullscreen mode;
+ * if we do not do this then our fullscreen window will appear in the
+ * z-order when it is deactivated and it can be uncovered by resizing
+ * or minimizing another window that is on top of it, which is not how
+ * the DirectDraw engines work. Therefore we keep this code here to
+ * make sure that all engines work the same in fullscreen mode.
+ */
+
+ /*
+ * Are we active?
+ * Are we fullscreen?
+ */
+ if (pScreenPriv->fActive
+ && pScreenInfo->fFullScreen)
+ {
+ /*
+ * Activating, attempt to bring our window
+ * to the top of the display
+ */
+ ShowWindow (pScreenPriv->hwndScreen, SW_RESTORE);
+ }
+ else if (!pScreenPriv->fActive
+ && pScreenInfo->fFullScreen)
+ {
+ /*
+ * Deactivating, stuff our window onto the
+ * task bar.
+ */
+ ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Reblit the shadow framebuffer to the screen.
+ */
+
+static Bool
+winRedrawScreenShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Redraw the whole window, to take account for the new colors */
+ BitBlt (pScreenPriv->hdcScreen,
+ 0, 0,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ pScreenPriv->hdcShadow,
+ 0, 0,
+ SRCCOPY);
+
+#ifdef XWIN_MULTIWINDOW
+ /* Redraw all windows */
+ if (pScreenInfo->fMultiWindow)
+ EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
+#endif
+
+ return TRUE;
+}
+
+
+
+/*
+ * Realize the currently installed colormap
+ */
+
+static Bool
+winRealizeInstalledPaletteShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winPrivCmapPtr pCmapPriv = NULL;
+
+ winDebug ("winRealizeInstalledPaletteShadowGDI\n");
+
+ /* Don't do anything if there is not a colormap */
+ if (pScreenPriv->pcmapInstalled == NULL)
+ {
+ winDebug ("winRealizeInstalledPaletteShadowGDI - No colormap "
+ "installed\n");
+ return TRUE;
+ }
+
+ pCmapPriv = winGetCmapPriv (pScreenPriv->pcmapInstalled);
+
+ /* Realize our palette for the screen */
+ if (RealizePalette (pScreenPriv->hdcScreen) == GDI_ERROR)
+ {
+ ErrorF ("winRealizeInstalledPaletteShadowGDI - RealizePalette () "
+ "failed\n");
+ return FALSE;
+ }
+
+ /* Set the DIB color table */
+ if (SetDIBColorTable (pScreenPriv->hdcShadow,
+ 0,
+ WIN_NUM_PALETTE_ENTRIES,
+ pCmapPriv->rgbColors) == 0)
+ {
+ ErrorF ("winRealizeInstalledPaletteShadowGDI - SetDIBColorTable () "
+ "failed\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Install the specified colormap
+ */
+
+static Bool
+winInstallColormapShadowGDI (ColormapPtr pColormap)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ winCmapPriv(pColormap);
+
+ /*
+ * Tell Windows to install the new colormap
+ */
+ if (SelectPalette (pScreenPriv->hdcScreen,
+ pCmapPriv->hPalette,
+ FALSE) == NULL)
+ {
+ ErrorF ("winInstallColormapShadowGDI - SelectPalette () failed\n");
+ return FALSE;
+ }
+
+ /* Realize the palette */
+ if (GDI_ERROR == RealizePalette (pScreenPriv->hdcScreen))
+ {
+ ErrorF ("winInstallColormapShadowGDI - RealizePalette () failed\n");
+ return FALSE;
+ }
+
+ /* Set the DIB color table */
+ if (SetDIBColorTable (pScreenPriv->hdcShadow,
+ 0,
+ WIN_NUM_PALETTE_ENTRIES,
+ pCmapPriv->rgbColors) == 0)
+ {
+ ErrorF ("winInstallColormapShadowGDI - SetDIBColorTable () failed\n");
+ return FALSE;
+ }
+
+ /* Redraw the whole window, to take account for the new colors */
+ BitBlt (pScreenPriv->hdcScreen,
+ 0, 0,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ pScreenPriv->hdcShadow,
+ 0, 0,
+ SRCCOPY);
+
+ /* Save a pointer to the newly installed colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+
+#ifdef XWIN_MULTIWINDOW
+ /* Redraw all windows */
+ if (pScreenInfo->fMultiWindow)
+ EnumThreadWindows (g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
+#endif
+
+ return TRUE;
+}
+
+
+/*
+ * Store the specified colors in the specified colormap
+ */
+
+static Bool
+winStoreColorsShadowGDI (ColormapPtr pColormap,
+ int ndef,
+ xColorItem *pdefs)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pColormap);
+ ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
+
+ /* Put the X colormap entries into the Windows logical palette */
+ if (SetPaletteEntries (pCmapPriv->hPalette,
+ pdefs[0].pixel,
+ ndef,
+ pCmapPriv->peColors + pdefs[0].pixel) == 0)
+ {
+ ErrorF ("winStoreColorsShadowGDI - SetPaletteEntries () failed\n");
+ return FALSE;
+ }
+
+ /* Don't install the Windows palette if the colormap is not installed */
+ if (pColormap != curpmap)
+ {
+ return TRUE;
+ }
+
+ /* Try to install the newly modified colormap */
+ if (!winInstallColormapShadowGDI (pColormap))
+ {
+ ErrorF ("winInstallColormapShadowGDI - winInstallColormapShadowGDI "
+ "failed\n");
+ return FALSE;
+ }
+
+#if 0
+ /* Tell Windows that the palette has changed */
+ RealizePalette (pScreenPriv->hdcScreen);
+
+ /* Set the DIB color table */
+ if (SetDIBColorTable (pScreenPriv->hdcShadow,
+ pdefs[0].pixel,
+ ndef,
+ pCmapPriv->rgbColors + pdefs[0].pixel) == 0)
+ {
+ ErrorF ("winInstallColormapShadowGDI - SetDIBColorTable () failed\n");
+ return FALSE;
+ }
+
+ /* Save a pointer to the newly installed colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+#endif
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap initialization procedure
+ */
+
+static Bool
+winCreateColormapShadowGDI (ColormapPtr pColormap)
+{
+ LPLOGPALETTE lpPaletteNew = NULL;
+ DWORD dwEntriesMax;
+ VisualPtr pVisual;
+ HPALETTE hpalNew = NULL;
+ winCmapPriv(pColormap);
+
+ /* Get a pointer to the visual that the colormap belongs to */
+ pVisual = pColormap->pVisual;
+
+ /* Get the maximum number of palette entries for this visual */
+ dwEntriesMax = pVisual->ColormapEntries;
+
+ /* Allocate a Windows logical color palette with max entries */
+ lpPaletteNew = malloc (sizeof (LOGPALETTE)
+ + (dwEntriesMax - 1) * sizeof (PALETTEENTRY));
+ if (lpPaletteNew == NULL)
+ {
+ ErrorF ("winCreateColormapShadowGDI - Couldn't allocate palette "
+ "with %d entries\n",
+ (int) dwEntriesMax);
+ return FALSE;
+ }
+
+ /* Zero out the colormap */
+ ZeroMemory (lpPaletteNew, sizeof (LOGPALETTE)
+ + (dwEntriesMax - 1) * sizeof (PALETTEENTRY));
+
+ /* Set the logical palette structure */
+ lpPaletteNew->palVersion = 0x0300;
+ lpPaletteNew->palNumEntries = dwEntriesMax;
+
+ /* Tell Windows to create the palette */
+ hpalNew = CreatePalette (lpPaletteNew);
+ if (hpalNew == NULL)
+ {
+ ErrorF ("winCreateColormapShadowGDI - CreatePalette () failed\n");
+ free (lpPaletteNew);
+ return FALSE;
+ }
+
+ /* Save the Windows logical palette handle in the X colormaps' privates */
+ pCmapPriv->hPalette = hpalNew;
+
+ /* Free the palette initialization memory */
+ free (lpPaletteNew);
+
+ return TRUE;
+}
+
+
+/*
+ * Colormap destruction procedure
+ */
+
+static Bool
+winDestroyColormapShadowGDI (ColormapPtr pColormap)
+{
+ winScreenPriv(pColormap->pScreen);
+ winCmapPriv(pColormap);
+
+ /*
+ * 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 ("winDestroyColormapShadowGDI - 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 device context */
+ SelectPalette (pScreenPriv->hdcScreen,
+ GetStockObject (DEFAULT_PALETTE),
+ FALSE);
+
+ /* Clear our private installed colormap pointer */
+ pScreenPriv->pcmapInstalled = NULL;
+ }
+
+ /* Try to delete the logical palette */
+ if (DeleteObject (pCmapPriv->hPalette) == 0)
+ {
+ ErrorF ("winDestroyColormap - DeleteObject () failed\n");
+ return FALSE;
+ }
+
+ /* Invalidate the colormap privates */
+ pCmapPriv->hPalette = NULL;
+
+ return TRUE;
+}
+
+
+/*
+ * Set engine specific funtions
+ */
+
+Bool
+winSetEngineFunctionsShadowGDI (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Set our pointers */
+ pScreenPriv->pwinAllocateFB = winAllocateFBShadowGDI;
+ pScreenPriv->pwinFreeFB = winFreeFBShadowGDI;
+ pScreenPriv->pwinShadowUpdate = winShadowUpdateGDI;
+ pScreenPriv->pwinInitScreen = winInitScreenShadowGDI;
+ pScreenPriv->pwinCloseScreen = winCloseScreenShadowGDI;
+ pScreenPriv->pwinInitVisuals = winInitVisualsShadowGDI;
+ pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowGDI;
+ if (pScreenInfo->fFullScreen)
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
+ else
+ pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
+ pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
+ pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowGDI;
+ pScreenPriv->pwinActivateApp = winActivateAppShadowGDI;
+ pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowGDI;
+ pScreenPriv->pwinRealizeInstalledPalette =
+ winRealizeInstalledPaletteShadowGDI;
+ pScreenPriv->pwinInstallColormap = winInstallColormapShadowGDI;
+ pScreenPriv->pwinStoreColors = winStoreColorsShadowGDI;
+ pScreenPriv->pwinCreateColormap = winCreateColormapShadowGDI;
+ pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowGDI;
+ pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinCreatePrimarySurface
+ = (winCreatePrimarySurfaceProcPtr) (void (*)(void))NoopDDA;
+ pScreenPriv->pwinReleasePrimarySurface
+ = (winReleasePrimarySurfaceProcPtr) (void (*)(void))NoopDDA;
+#ifdef XWIN_MULTIWINDOW
+ pScreenPriv->pwinFinishCreateWindowsWindow =
+ (winFinishCreateWindowsWindowProcPtr) (void (*)(void))NoopDDA;
+#endif
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winvideo.c b/xorg-server/hw/xwin/winvideo.c index 998a3face..10f48b564 100644 --- a/xorg-server/hw/xwin/winvideo.c +++ b/xorg-server/hw/xwin/winvideo.c @@ -69,8 +69,6 @@ winInitVideo (ScreenPtr pScreen) #include <X11/extensions/Xv.h>
#endif
-#include "win.h"
-
#if 0
diff --git a/xorg-server/hw/xwin/winwin32rootless.c b/xorg-server/hw/xwin/winwin32rootless.c index e1c2da7f4..2f8ace57a 100644 --- a/xorg-server/hw/xwin/winwin32rootless.c +++ b/xorg-server/hw/xwin/winwin32rootless.c @@ -340,8 +340,8 @@ void winMWExtWMDestroyFrame (RootlessFrameID wid)
{
win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid;
- HICON hiconClass;
- HICON hiconSmClass;
+ HICON hIcon;
+ HICON hIconSm;
HMODULE hInstance;
int iReturn;
char pszClass[CLASS_NAME_LENGTH];
@@ -351,8 +351,8 @@ winMWExtWMDestroyFrame (RootlessFrameID wid) /* Store the info we need to destroy after this window is gone */
hInstance = (HINSTANCE) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HMODULE);
- hiconClass = (HICON) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HICON);
- hiconSmClass = (HICON) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HICONSM);
+ hIcon = (HICON)SendMessage(pRLWinPriv->hWnd, WM_GETICON, ICON_BIG, 0);
+ hIconSm = (HICON)SendMessage(pRLWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0);
iReturn = GetClassName (pRLWinPriv->hWnd, pszClass, CLASS_NAME_LENGTH);
pRLWinPriv->fClose = TRUE;
@@ -367,7 +367,7 @@ winMWExtWMDestroyFrame (RootlessFrameID wid) winDebug ("winMWExtWMDestroyFrame - Unregistering %s: ", pszClass);
iReturn = UnregisterClass (pszClass, hInstance);
- winDebug ("winMWExtWMDestroyFramew - %d Deleting Icon: ", iReturn);
+ winDebug ("winMWExtWMDestroyFramew - Deleting Icon\n");
}
winDestroyIcon(hiconClass);
|