winscrinit.c revision 4642e01f
1/*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3 *
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
11 *
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
14 *
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
27 *
28 * Authors:	Dakshinamurthy Karra
29 *		Suhaib M Siddiqi
30 *		Peter Busch
31 *		Harold L Hunt II
32 *		Kensuke Matsuzaki
33 */
34
35#ifdef HAVE_XWIN_CONFIG_H
36#include <xwin-config.h>
37#endif
38#include "win.h"
39#include "winmsg.h"
40#include "safeAlpha.h"
41
42
43#ifdef XWIN_MULTIWINDOWEXTWM
44static RootlessFrameProcsRec
45winMWExtWMProcs = {
46  winMWExtWMCreateFrame,
47  winMWExtWMDestroyFrame,
48
49  winMWExtWMMoveFrame,
50  winMWExtWMResizeFrame,
51  winMWExtWMRestackFrame,
52  winMWExtWMReshapeFrame,
53  winMWExtWMUnmapFrame,
54
55  winMWExtWMStartDrawing,
56  winMWExtWMStopDrawing,
57  winMWExtWMUpdateRegion,
58#ifndef ROOTLESS_TRACK_DAMAGE
59  winMWExtWMDamageRects,
60#endif
61  winMWExtWMRootlessSwitchWindow,
62  NULL,//winWMExtWMDoReorderWindow,
63
64  NULL,//winMWExtWMCopyBytes,
65  NULL,//winMWExtWMFillBytes,
66  NULL,//winMWExtWMCompositePixels,
67  winMWExtWMCopyWindow
68};
69#endif
70
71
72/*
73 * References to external symbols
74 */
75
76extern Bool                     g_fSoftwareCursor;
77
78
79/*
80 * Prototypes
81 */
82
83Bool
84winRandRInit (ScreenPtr pScreen);
85
86
87/*
88 * Local functions
89 */
90
91static Bool
92winSaveScreen (ScreenPtr pScreen, int on);
93
94
95/*
96 * Determine what type of screen we are initializing
97 * and call the appropriate procedure to intiailize
98 * that type of screen.
99 */
100
101Bool
102winScreenInit (int index,
103	       ScreenPtr pScreen,
104	       int argc, char **argv)
105{
106  winScreenInfoPtr      pScreenInfo = &g_ScreenInfo[index];
107  winPrivScreenPtr	pScreenPriv;
108  HDC			hdc;
109
110#if CYGDEBUG || YES
111  winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
112	  pScreenInfo->dwWidth, pScreenInfo->dwHeight);
113#endif
114
115  /* Allocate privates for this screen */
116  if (!winAllocatePrivates (pScreen))
117    {
118      ErrorF ("winScreenInit - Couldn't allocate screen privates\n");
119      return FALSE;
120    }
121
122  /* Get a pointer to the privates structure that was allocated */
123  pScreenPriv = winGetScreenPriv (pScreen);
124
125  /* Save a pointer to this screen in the screen info structure */
126  pScreenInfo->pScreen = pScreen;
127
128  /* Save a pointer to the screen info in the screen privates structure */
129  /* This allows us to get back to the screen info from a screen pointer */
130  pScreenPriv->pScreenInfo = pScreenInfo;
131
132  /*
133   * Determine which engine to use.
134   *
135   * NOTE: This is done once per screen because each screen possibly has
136   * a preferred engine specified on the command line.
137   */
138  if (!winSetEngine (pScreen))
139    {
140      ErrorF ("winScreenInit - winSetEngine () failed\n");
141      return FALSE;
142    }
143
144  /* Adjust the video mode for our engine type */
145  if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen))
146    {
147      ErrorF ("winScreenInit - winAdjustVideoMode () failed\n");
148      return FALSE;
149    }
150
151  /* Check for supported display depth */
152  if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1))))
153    {
154      ErrorF ("winScreenInit - Unsupported display depth: %d\n" \
155	      "Change your Windows display depth to 15, 16, 24, or 32 bits "
156	      "per pixel.\n",
157	      (int) pScreenInfo->dwBPP);
158      ErrorF ("winScreenInit - Supported depths: %08x\n",
159	      WIN_SUPPORTED_BPPS);
160#if WIN_CHECK_DEPTH
161      return FALSE;
162#endif
163    }
164
165  /*
166   * Check that all monitors have the same display depth if we are using
167   * multiple monitors
168   */
169  if (pScreenInfo->fMultipleMonitors
170      && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT))
171    {
172      ErrorF ("winScreenInit - Monitors do not all have same pixel format / "
173	      "display depth.\n"
174	      "Using primary display only.\n");
175      pScreenInfo->fMultipleMonitors = FALSE;
176    }
177
178  /* Create display window */
179  if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen))
180    {
181      ErrorF ("winScreenInit - pwinCreateBoundingWindow () "
182	      "failed\n");
183      return FALSE;
184    }
185
186  /* Get a device context */
187  hdc = GetDC (pScreenPriv->hwndScreen);
188
189  /* Store the initial height, width, and depth of the display */
190  /* Are we using multiple monitors? */
191  if (pScreenInfo->fMultipleMonitors)
192    {
193      pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
194      pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
195
196      /*
197       * In this case, some of the defaults set in
198       * winInitializeDefaultScreens () are not correct ...
199       */
200      if (!pScreenInfo->fUserGaveHeightAndWidth)
201	{
202	  pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
203	  pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
204	  pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth /
205				     WIN_DEFAULT_DPI) * 25.4;
206	  pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight /
207				      WIN_DEFAULT_DPI) * 25.4;
208	}
209    }
210  else
211    {
212      pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN);
213      pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN);
214    }
215
216  /* Save the original bits per pixel */
217  pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL);
218
219  /* Release the device context */
220  ReleaseDC (pScreenPriv->hwndScreen, hdc);
221
222  /* Clear the visuals list */
223  miClearVisualTypes ();
224
225  /* Set the padded screen width */
226  pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth,
227					      pScreenInfo->dwBPP);
228
229  /* Call the engine dependent screen initialization procedure */
230  if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv)))
231    {
232      ErrorF ("winScreenInit - winFinishScreenInit () failed\n");
233      return FALSE;
234    }
235
236  if (!g_fSoftwareCursor)
237    winInitCursor(pScreen);
238  else
239    winErrorFVerb(2, "winScreenInit - Using software cursor\n");
240
241#if CYGDEBUG || YES
242  winDebug ("winScreenInit - returning\n");
243#endif
244
245  return TRUE;
246}
247
248
249/* See Porting Layer Definition - p. 20 */
250Bool
251winFinishScreenInitFB (int index,
252		       ScreenPtr pScreen,
253		       int argc, char **argv)
254{
255  winScreenPriv(pScreen);
256  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
257  VisualPtr		pVisual = NULL;
258  char			*pbits = NULL;
259#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
260  int			iReturn;
261#endif
262
263  /* Create framebuffer */
264  if (!(*pScreenPriv->pwinAllocateFB) (pScreen))
265    {
266      ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n");
267      return FALSE;
268    }
269
270  /*
271   * Grab the number of bits that are used to represent color in each pixel.
272   */
273  if (pScreenInfo->dwBPP == 8)
274    pScreenInfo->dwDepth = 8;
275  else
276    pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask)
277      + winCountBits (pScreenPriv->dwGreenMask)
278      + winCountBits (pScreenPriv->dwBlueMask);
279
280  winErrorFVerb (2, "winFinishScreenInitFB - Masks: %08x %08x %08x\n",
281	  (unsigned int) pScreenPriv->dwRedMask,
282	  (unsigned int) pScreenPriv->dwGreenMask,
283	  (unsigned int) pScreenPriv->dwBlueMask);
284
285  /* Init visuals */
286  if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
287    {
288      ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n");
289      return FALSE;
290    }
291
292  /* Setup a local variable to point to the framebuffer */
293  pbits = pScreenInfo->pfb;
294
295  /* Apparently we need this for the render extension */
296  miSetPixmapDepths ();
297
298  /* Start fb initialization */
299  if (!fbSetupScreen (pScreen,
300		      pScreenInfo->pfb,
301		      pScreenInfo->dwWidth, pScreenInfo->dwHeight,
302		      monitorResolution, monitorResolution,
303		      pScreenInfo->dwStride,
304		      pScreenInfo->dwBPP))
305    {
306      ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n");
307      return FALSE;
308    }
309
310  /* Override default colormap routines if visual class is dynamic */
311  if (pScreenInfo->dwDepth == 8
312      && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
313	  || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
314	      && pScreenInfo->fFullScreen)
315	  || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
316	      && pScreenInfo->fFullScreen)))
317    {
318      winSetColormapFunctions (pScreen);
319
320      /*
321       * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its
322       * own colormap, as it cannot allocate 7 planes in the default
323       * colormap.  Setting whitePixel to 1 allows Magic to get 7
324       * planes in the default colormap, so it doesn't create its
325       * own colormap.  This latter situation is highly desireable,
326       * as it keeps the Magic window viewable when switching to
327       * other X clients that use the default colormap.
328       */
329      pScreen->blackPixel = 0;
330      pScreen->whitePixel = 1;
331    }
332
333  /* Place our save screen function */
334  pScreen->SaveScreen = winSaveScreen;
335
336  /* Finish fb initialization */
337  if (!fbFinishScreenInit (pScreen,
338			   pScreenInfo->pfb,
339			   pScreenInfo->dwWidth, pScreenInfo->dwHeight,
340			   monitorResolution, monitorResolution,
341			   pScreenInfo->dwStride,
342			   pScreenInfo->dwBPP))
343    {
344      ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n");
345      return FALSE;
346    }
347
348  /* Save a pointer to the root visual */
349  for (pVisual = pScreen->visuals;
350       pVisual->vid != pScreen->rootVisual;
351       pVisual++);
352  pScreenPriv->pRootVisual = pVisual;
353
354  /*
355   * Setup points to the block and wakeup handlers.  Pass a pointer
356   * to the current screen as pWakeupdata.
357   */
358  pScreen->BlockHandler = winBlockHandler;
359  pScreen->WakeupHandler = winWakeupHandler;
360  pScreen->blockData = pScreen;
361  pScreen->wakeupData = pScreen;
362
363#ifdef XWIN_MULTIWINDOWEXTWM
364  /*
365   * Setup acceleration for multi-window external window manager mode.
366   * To be compatible with the Damage extension, this must be done
367   * before calling miDCInitialize, which calls DamageSetup.
368   */
369  if (pScreenInfo->fMWExtWM)
370    {
371      if (!RootlessAccelInit (pScreen))
372        {
373          ErrorF ("winFinishScreenInitFB - RootlessAccelInit () failed\n");
374          return FALSE;
375        }
376    }
377#endif
378
379#ifdef RENDER
380  /* Render extension initialization, calls miPictureInit */
381  if (!fbPictureInit (pScreen, NULL, 0))
382    {
383      ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
384      return FALSE;
385    }
386#endif
387
388#ifdef RANDR
389  /* Initialize resize and rotate support */
390  if (!winRandRInit (pScreen))
391    {
392      ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
393      return FALSE;
394    }
395#endif
396
397  /*
398   * Backing store support should reduce network traffic and increase
399   * performance.
400   */
401  miInitializeBackingStore (pScreen);
402
403  /* KDrive does miDCInitialize right after miInitializeBackingStore */
404  /* Setup the cursor routines */
405#if CYGDEBUG
406  winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
407#endif
408  miDCInitialize (pScreen, &g_winPointerCursorFuncs);
409
410  /* KDrive does winCreateDefColormap right after miDCInitialize */
411  /* Create a default colormap */
412#if CYGDEBUG
413  winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
414#endif
415  if (!winCreateDefColormap (pScreen))
416    {
417      ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
418      return FALSE;
419    }
420
421  /* Initialize the shadow framebuffer layer */
422  if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
423       || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
424       || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
425#ifdef XWIN_MULTIWINDOWEXTWM
426      && !pScreenInfo->fMWExtWM
427#endif
428      )
429    {
430#if CYGDEBUG
431      winDebug ("winFinishScreenInitFB - Calling shadowInit ()\n");
432#endif
433      if (!shadowInit (pScreen,
434		       pScreenPriv->pwinShadowUpdate,
435		       NULL))
436	{
437	  ErrorF ("winFinishScreenInitFB - shadowInit () failed\n");
438	  return FALSE;
439	}
440    }
441
442#ifdef XWIN_MULTIWINDOWEXTWM
443  /* Handle multi-window external window manager mode */
444  if (pScreenInfo->fMWExtWM)
445    {
446      winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n");
447
448      RootlessInit(pScreen, &winMWExtWMProcs);
449
450      winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n");
451
452      rootless_CopyBytes_threshold = 0;
453      rootless_FillBytes_threshold = 0;
454      rootless_CompositePixels_threshold = 0;
455      /* FIXME: How many? Profiling needed? */
456      rootless_CopyWindow_threshold = 1;
457
458      winWindowsWMExtensionInit ();
459    }
460#endif
461
462  /* Handle rootless mode */
463  if (pScreenInfo->fRootless)
464    {
465      /* Define the WRAP macro temporarily for local use */
466#define WRAP(a) \
467    if (pScreen->a) { \
468        pScreenPriv->a = pScreen->a; \
469    } else { \
470        ErrorF("null screen fn " #a "\n"); \
471        pScreenPriv->a = NULL; \
472    }
473
474      /* Save a pointer to each lower-level window procedure */
475      WRAP(CreateWindow);
476      WRAP(DestroyWindow);
477      WRAP(RealizeWindow);
478      WRAP(UnrealizeWindow);
479      WRAP(PositionWindow);
480      WRAP(ChangeWindowAttributes);
481      WRAP(SetShape);
482
483      /* Assign rootless window procedures to be top level procedures */
484      pScreen->CreateWindow = winCreateWindowRootless;
485      pScreen->DestroyWindow = winDestroyWindowRootless;
486      pScreen->PositionWindow = winPositionWindowRootless;
487      /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/
488      pScreen->RealizeWindow = winMapWindowRootless;
489      pScreen->UnrealizeWindow = winUnmapWindowRootless;
490      pScreen->SetShape = winSetShapeRootless;
491
492      /* Undefine the WRAP macro, as it is not needed elsewhere */
493#undef WRAP
494    }
495
496
497#ifdef XWIN_MULTIWINDOW
498  /* Handle multi window mode */
499  else if (pScreenInfo->fMultiWindow)
500    {
501      /* Define the WRAP macro temporarily for local use */
502#define WRAP(a) \
503    if (pScreen->a) { \
504        pScreenPriv->a = pScreen->a; \
505    } else { \
506        ErrorF("null screen fn " #a "\n"); \
507        pScreenPriv->a = NULL; \
508    }
509
510      /* Save a pointer to each lower-level window procedure */
511      WRAP(CreateWindow);
512      WRAP(DestroyWindow);
513      WRAP(RealizeWindow);
514      WRAP(UnrealizeWindow);
515      WRAP(PositionWindow);
516      WRAP(ChangeWindowAttributes);
517      WRAP(ReparentWindow);
518      WRAP(RestackWindow);
519      WRAP(ResizeWindow);
520      WRAP(MoveWindow);
521      WRAP(CopyWindow);
522      WRAP(SetShape);
523
524      /* Assign multi-window window procedures to be top level procedures */
525      pScreen->CreateWindow = winCreateWindowMultiWindow;
526      pScreen->DestroyWindow = winDestroyWindowMultiWindow;
527      pScreen->PositionWindow = winPositionWindowMultiWindow;
528      /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/
529      pScreen->RealizeWindow = winMapWindowMultiWindow;
530      pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
531      pScreen->ReparentWindow = winReparentWindowMultiWindow;
532      pScreen->RestackWindow = winRestackWindowMultiWindow;
533      pScreen->ResizeWindow = winResizeWindowMultiWindow;
534      pScreen->MoveWindow = winMoveWindowMultiWindow;
535      pScreen->CopyWindow = winCopyWindowMultiWindow;
536      pScreen->SetShape = winSetShapeMultiWindow;
537
538      /* Undefine the WRAP macro, as it is not needed elsewhere */
539#undef WRAP
540    }
541#endif
542
543  /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */
544  pScreenPriv->CloseScreen = pScreen->CloseScreen;
545  pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
546
547#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
548  /* Create a mutex for modules in separate threads to wait for */
549  iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
550  if (iReturn != 0)
551    {
552      ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n",
553	      iReturn);
554      return FALSE;
555    }
556
557  /* Own the mutex for modules in separate threads */
558  iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
559  if (iReturn != 0)
560    {
561      ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n",
562	      iReturn);
563      return FALSE;
564    }
565
566  /* Set the ServerStarted flag to false */
567  pScreenPriv->fServerStarted = FALSE;
568#endif
569
570#ifdef XWIN_MULTIWINDOWEXTWM
571  pScreenPriv->fRestacking = FALSE;
572#endif
573
574#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
575  if (FALSE
576#ifdef XWIN_MULTIWINDOW
577      || pScreenInfo->fMultiWindow
578#endif
579#ifdef XWIN_MULTIWINDOWEXTWM
580      || pScreenInfo->fInternalWM
581#endif
582      )
583    {
584#if CYGDEBUG || YES
585      winDebug ("winFinishScreenInitFB - Calling winInitWM.\n");
586#endif
587
588      /* Initialize multi window mode */
589      if (!winInitWM (&pScreenPriv->pWMInfo,
590		      &pScreenPriv->ptWMProc,
591		      &pScreenPriv->ptXMsgProc,
592		      &pScreenPriv->pmServerStarted,
593		      pScreenInfo->dwScreen,
594		      (HWND)&pScreenPriv->hwndScreen,
595#ifdef XWIN_MULTIWINDOWEXTWM
596		      pScreenInfo->fInternalWM ||
597#endif
598		      FALSE))
599        {
600          ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
601          return FALSE;
602        }
603    }
604#endif
605
606  /* Tell the server that we are enabled */
607  pScreenPriv->fEnabled = TRUE;
608
609  /* Tell the server that we have a valid depth */
610  pScreenPriv->fBadDepth = FALSE;
611
612#if CYGDEBUG || YES
613  winDebug ("winFinishScreenInitFB - returning\n");
614#endif
615
616  return TRUE;
617}
618
619#ifdef XWIN_NATIVEGDI
620/* See Porting Layer Definition - p. 20 */
621
622Bool
623winFinishScreenInitNativeGDI (int index,
624			      ScreenPtr pScreen,
625			      int argc, char **argv)
626{
627  winScreenPriv(pScreen);
628  winScreenInfoPtr      pScreenInfo = &g_ScreenInfo[index];
629  VisualPtr		pVisuals = NULL;
630  DepthPtr		pDepths = NULL;
631  VisualID		rootVisual = 0;
632  int			nVisuals = 0, nDepths = 0, nRootDepth = 0;
633
634  /* Ignore user input (mouse, keyboard) */
635  pScreenInfo->fIgnoreInput = FALSE;
636
637  /* Get device contexts for the screen and shadow bitmap */
638  pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
639  if (pScreenPriv->hdcScreen == NULL)
640    FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n");
641
642  /* Init visuals */
643  if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
644    {
645      ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n");
646      return FALSE;
647    }
648
649  /* Initialize the mi visuals */
650  if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth,
651		      &rootVisual,
652		      ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8,
653		      TrueColor))
654    {
655      ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n");
656      return FALSE;
657    }
658
659  /* Initialize the CloseScreen procedure pointer */
660  pScreen->CloseScreen = NULL;
661
662  /* Initialize the mi code */
663  if (!miScreenInit (pScreen,
664		     NULL, /* No framebuffer */
665		     pScreenInfo->dwWidth, pScreenInfo->dwHeight,
666		     monitorResolution, monitorResolution,
667		     pScreenInfo->dwStride,
668		     nRootDepth, nDepths, pDepths, rootVisual,
669		     nVisuals, pVisuals))
670    {
671      ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n");
672      return FALSE;
673    }
674
675  pScreen->defColormap = FakeClientID(0);
676
677  /*
678   * Register our block and wakeup handlers; these procedures
679   * process messages in our Windows message queue; specifically,
680   * they process mouse and keyboard input.
681   */
682  pScreen->BlockHandler = winBlockHandler;
683  pScreen->WakeupHandler = winWakeupHandler;
684  pScreen->blockData = pScreen;
685  pScreen->wakeupData = pScreen;
686
687  /* Place our save screen function */
688  pScreen->SaveScreen = winSaveScreen;
689
690  /* Pixmaps */
691  pScreen->CreatePixmap = winCreatePixmapNativeGDI;
692  pScreen->DestroyPixmap = winDestroyPixmapNativeGDI;
693
694  /* Other Screen Routines */
695  pScreen->QueryBestSize = winQueryBestSizeNativeGDI;
696  pScreen->SaveScreen = winSaveScreen;
697  pScreen->GetImage = miGetImage;
698  pScreen->GetSpans = winGetSpansNativeGDI;
699
700  /* Window Procedures */
701  pScreen->CreateWindow = winCreateWindowNativeGDI;
702  pScreen->DestroyWindow = winDestroyWindowNativeGDI;
703  pScreen->PositionWindow = winPositionWindowNativeGDI;
704  /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/
705  pScreen->RealizeWindow = winMapWindowNativeGDI;
706  pScreen->UnrealizeWindow = winUnmapWindowNativeGDI;
707
708  /* Paint window */
709  pScreen->CopyWindow = winCopyWindowNativeGDI;
710
711  /* Fonts */
712  pScreen->RealizeFont = winRealizeFontNativeGDI;
713  pScreen->UnrealizeFont = winUnrealizeFontNativeGDI;
714
715  /* GC */
716  pScreen->CreateGC = winCreateGCNativeGDI;
717
718  /* Colormap Routines */
719  pScreen->CreateColormap = miInitializeColormap;
720  pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA;
721  pScreen->InstallColormap = miInstallColormap;
722  pScreen->UninstallColormap = miUninstallColormap;
723  pScreen->ListInstalledColormaps = miListInstalledColormaps;
724  pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA;
725  pScreen->ResolveColor = miResolveColor;
726
727  /* Bitmap */
728  pScreen->BitmapToRegion = winPixmapToRegionNativeGDI;
729
730  ErrorF ("winFinishScreenInitNativeGDI - calling miDCInitialize\n");
731
732  /* Set the default white and black pixel positions */
733  pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0;
734
735  /* Initialize the cursor */
736  if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs))
737    {
738      ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n");
739      return FALSE;
740    }
741
742  /* Create a default colormap */
743  if (!miCreateDefColormap (pScreen))
744    {
745        ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
746		"failed\n");
747	return FALSE;
748    }
749
750  ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
751	  "returned\n");
752
753  /* mi doesn't use a CloseScreen procedure, so no need to wrap */
754  pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
755
756  /* Tell the server that we are enabled */
757  pScreenPriv->fEnabled = TRUE;
758
759  ErrorF ("winFinishScreenInitNativeGDI - Successful addition of "
760	  "screen %08x\n",
761	  (unsigned int) pScreen);
762
763  return TRUE;
764}
765#endif
766
767
768/* See Porting Layer Definition - p. 33 */
769static Bool
770winSaveScreen (ScreenPtr pScreen, int on)
771{
772  return TRUE;
773}
774