Bool KdScreenInit(ScreenPtr pScreen, int argc, char **argv) { KdScreenInfo *screen = kdCurrentScreen; KdCardInfo *card = screen->card; KdPrivScreenPtr pScreenPriv; /* * note that screen->fb is set up for the nominal orientation * of the screen; that means if randr is rotated, the values * there should reflect a rotated frame buffer (or shadow). */ Bool rotated = (screen->randr & (RR_Rotate_90 | RR_Rotate_270)) != 0; int width, height, *width_mmp, *height_mmp; KdAllocatePrivates(pScreen); pScreenPriv = KdGetScreenPriv(pScreen); if (!rotated) { width = screen->width; height = screen->height; width_mmp = &screen->width_mm; height_mmp = &screen->height_mm; } else { width = screen->height; height = screen->width; width_mmp = &screen->height_mm; height_mmp = &screen->width_mm; } screen->pScreen = pScreen; pScreenPriv->screen = screen; pScreenPriv->card = card; pScreenPriv->bytesPerPixel = screen->fb.bitsPerPixel >> 3; pScreenPriv->dpmsState = KD_DPMS_NORMAL; pScreen->x = screen->origin.x; pScreen->y = screen->origin.y; if (!monitorResolution) monitorResolution = 75; /* * This is done in this order so that backing store wraps * our GC functions; fbFinishScreenInit initializes MI * backing store */ if (!fbSetupScreen(pScreen, screen->fb.frameBuffer, width, height, monitorResolution, monitorResolution, screen->fb.pixelStride, screen->fb.bitsPerPixel)) { return FALSE; } /* * Set colormap functions */ pScreen->InstallColormap = KdInstallColormap; pScreen->UninstallColormap = KdUninstallColormap; pScreen->ListInstalledColormaps = KdListInstalledColormaps; pScreen->StoreColors = KdStoreColors; pScreen->SaveScreen = KdSaveScreen; pScreen->CreateWindow = KdCreateWindow; if (!fbFinishScreenInit(pScreen, screen->fb.frameBuffer, width, height, monitorResolution, monitorResolution, screen->fb.pixelStride, screen->fb.bitsPerPixel)) { return FALSE; } /* * Fix screen sizes; for some reason mi takes dpi instead of mm. * Rounding errors are annoying */ if (*width_mmp) pScreen->mmWidth = *width_mmp; else *width_mmp = pScreen->mmWidth; if (*height_mmp) pScreen->mmHeight = *height_mmp; else *height_mmp = pScreen->mmHeight; /* * Plug in our own block/wakeup handlers. * miScreenInit installs NoopDDA in both places */ pScreen->BlockHandler = KdBlockHandler; pScreen->WakeupHandler = KdWakeupHandler; if (!fbPictureInit(pScreen, 0, 0)) return FALSE; if (card->cfuncs->initScreen) if (!(*card->cfuncs->initScreen) (pScreen)) return FALSE; if (!screen->dumb && card->cfuncs->initAccel) if (!(*card->cfuncs->initAccel) (pScreen)) screen->dumb = TRUE; if (card->cfuncs->finishInitScreen) if (!(*card->cfuncs->finishInitScreen) (pScreen)) return FALSE; /* * Wrap CloseScreen, the order now is: * KdCloseScreen * miBSCloseScreen * fbCloseScreen */ pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = KdCloseScreen; pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = KdCreateScreenResources; if (screen->softCursor || !card->cfuncs->initCursor || !(*card->cfuncs->initCursor) (pScreen)) { /* Use MI for cursor display and event queueing. */ screen->softCursor = TRUE; miDCInitialize(pScreen, &kdPointerScreenFuncs); } if (!fbCreateDefColormap(pScreen)) { return FALSE; } KdSetSubpixelOrder(pScreen, screen->randr); /* * Enable the hardware */ if (!kdEnabled) { kdEnabled = TRUE; if (kdOsFuncs->Enable) (*kdOsFuncs->Enable) (); } if (screen->mynum == card->selected) { if (card->cfuncs->preserve) (*card->cfuncs->preserve) (card); if (card->cfuncs->enable) if (!(*card->cfuncs->enable) (pScreen)) return FALSE; pScreenPriv->enabled = TRUE; if (!screen->softCursor && card->cfuncs->enableCursor) (*card->cfuncs->enableCursor) (pScreen); KdEnableColormap(pScreen); if (!screen->dumb && card->cfuncs->enableAccel) (*card->cfuncs->enableAccel) (pScreen); } return TRUE; }
/* 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->pwinAllocateFB) (pScreen)) { ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); return FALSE; } /* * Grab the number of bits that are used to represent color in each pixel. */ if (pScreenInfo->dwBPP == 8) pScreenInfo->dwDepth = 8; else pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) + winCountBits (pScreenPriv->dwGreenMask) + winCountBits (pScreenPriv->dwBlueMask); winErrorFVerb (2, "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 /* * Backing store support should reduce network traffic and increase * performance. */ miInitializeBackingStore (pScreen); /* KDrive does miDCInitialize right after miInitializeBackingStore */ /* Setup the cursor routines */ #if CYGDEBUG winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); #endif miDCInitialize (pScreen, &g_winPointerCursorFuncs); /* KDrive does winCreateDefColormap right after miDCInitialize */ /* Create a default colormap */ #if CYGDEBUG winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); #endif 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 ) { #if CYGDEBUG winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n"); #endif 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_MULTIWINDOWEXTWM || pScreenInfo->fInternalWM #endif ) { #if CYGDEBUG || YES winDebug ("winFinishScreenInitFB - Calling winInitWM.\n"); #endif /* Initialize multi window mode */ if (!winInitWM (&pScreenPriv->pWMInfo, &pScreenPriv->ptWMProc, &pScreenPriv->ptXMsgProc, &pScreenPriv->pmServerStarted, pScreenInfo->dwScreen, (HWND)&pScreenPriv->hwndScreen, #ifdef XWIN_MULTIWINDOWEXTWM 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; #if CYGDEBUG || YES winDebug ("winFinishScreenInitFB - returning\n"); #endif return TRUE; }
Bool KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv) { KdScreenInfo *screen = kdCurrentScreen; KdCardInfo *card = screen->card; KdPrivScreenPtr pScreenPriv; int fb; /* * note that screen->fb is set up for the nominal orientation * of the screen; that means if randr is rotated, the values * there should reflect a rotated frame buffer (or shadow). */ Bool rotated = (screen->randr & (RR_Rotate_90|RR_Rotate_270)) != 0; int width, height, *width_mmp, *height_mmp; KdAllocatePrivates (pScreen); pScreenPriv = KdGetScreenPriv(pScreen); if (!rotated) { width = screen->width; height = screen->height; width_mmp = &screen->width_mm; height_mmp = &screen->height_mm; } else { width = screen->height; height = screen->width; width_mmp = &screen->height_mm; height_mmp = &screen->width_mm; } screen->pScreen = pScreen; pScreenPriv->screen = screen; pScreenPriv->card = card; for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++) pScreenPriv->bytesPerPixel[fb] = screen->fb[fb].bitsPerPixel >> 3; pScreenPriv->dpmsState = KD_DPMS_NORMAL; #ifdef PANORAMIX dixScreenOrigins[pScreen->myNum] = screen->origin; #endif if (!monitorResolution) monitorResolution = 75; /* * This is done in this order so that backing store wraps * our GC functions; fbFinishScreenInit initializes MI * backing store */ if (!fbSetupScreen (pScreen, screen->fb[0].frameBuffer, width, height, monitorResolution, monitorResolution, screen->fb[0].pixelStride, screen->fb[0].bitsPerPixel)) { return FALSE; } /* * Set colormap functions */ pScreen->InstallColormap = KdInstallColormap; pScreen->UninstallColormap = KdUninstallColormap; pScreen->ListInstalledColormaps = KdListInstalledColormaps; pScreen->StoreColors = KdStoreColors; pScreen->SaveScreen = KdSaveScreen; pScreen->CreateWindow = KdCreateWindow; #ifdef FB_OLD_SCREEN pScreenPriv->BackingStoreFuncs.SaveAreas = fbSaveAreas; pScreenPriv->BackingStoreFuncs.RestoreAreas = fbSaveAreas; pScreenPriv->BackingStoreFuncs.SetClipmaskRgn = 0; pScreenPriv->BackingStoreFuncs.GetImagePixmap = 0; pScreenPriv->BackingStoreFuncs.GetSpansPixmap = 0; #endif #if KD_MAX_FB > 1 if (screen->fb[1].depth) { if (!fbOverlayFinishScreenInit (pScreen, screen->fb[0].frameBuffer, screen->fb[1].frameBuffer, width, height, monitorResolution, monitorResolution, screen->fb[0].pixelStride, screen->fb[1].pixelStride, screen->fb[0].bitsPerPixel, screen->fb[1].bitsPerPixel, screen->fb[0].depth, screen->fb[1].depth)) { return FALSE; } } else #endif { if (!fbFinishScreenInit (pScreen, screen->fb[0].frameBuffer, width, height, monitorResolution, monitorResolution, screen->fb[0].pixelStride, screen->fb[0].bitsPerPixel)) { return FALSE; } } /* * Fix screen sizes; for some reason mi takes dpi instead of mm. * Rounding errors are annoying */ if (*width_mmp) pScreen->mmWidth = *width_mmp; else *width_mmp = pScreen->mmWidth; if (*height_mmp) pScreen->mmHeight = *height_mmp; else *height_mmp = pScreen->mmHeight; /* * Plug in our own block/wakeup handlers. * miScreenInit installs NoopDDA in both places */ pScreen->BlockHandler = KdBlockHandler; pScreen->WakeupHandler = KdWakeupHandler; #ifdef RENDER if (!fbPictureInit (pScreen, 0, 0)) return FALSE; #endif if (card->cfuncs->initScreen) if (!(*card->cfuncs->initScreen) (pScreen)) return FALSE; if (!screen->dumb && card->cfuncs->initAccel) if (!(*card->cfuncs->initAccel) (pScreen)) screen->dumb = TRUE; if (screen->off_screen_base < screen->memory_size) KdOffscreenInit (pScreen); #ifdef PSEUDO8 (void) p8Init (pScreen, PSEUDO8_USE_DEFAULT); #endif if (card->cfuncs->finishInitScreen) if (!(*card->cfuncs->finishInitScreen) (pScreen)) return FALSE; #if 0 fbInitValidateTree (pScreen); #endif #if 0 pScreen->backingStoreSupport = Always; #ifdef FB_OLD_SCREEN miInitializeBackingStore (pScreen, &pScreenPriv->BackingStoreFuncs); #else miInitializeBackingStore (pScreen); #endif #endif /* * Wrap CloseScreen, the order now is: * KdCloseScreen * miBSCloseScreen * fbCloseScreen */ pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = KdCloseScreen; pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources; pScreen->CreateScreenResources = KdCreateScreenResources; if (screen->softCursor || !card->cfuncs->initCursor || !(*card->cfuncs->initCursor) (pScreen)) { /* Use MI for cursor display and event queueing. */ screen->softCursor = TRUE; miDCInitialize(pScreen, &kdPointerScreenFuncs); } if (!fbCreateDefColormap (pScreen)) { return FALSE; } KdSetSubpixelOrder (pScreen, screen->randr); /* * Enable the hardware */ if (!kdEnabled) { kdEnabled = TRUE; if(kdOsFuncs->Enable) (*kdOsFuncs->Enable) (); } if (screen->mynum == card->selected) { if(card->cfuncs->preserve) (*card->cfuncs->preserve) (card); if(card->cfuncs->enable) if (!(*card->cfuncs->enable) (pScreen)) return FALSE; pScreenPriv->enabled = TRUE; if (!screen->softCursor && card->cfuncs->enableCursor) (*card->cfuncs->enableCursor) (pScreen); KdEnableColormap (pScreen); if (!screen->dumb && card->cfuncs->enableAccel) (*card->cfuncs->enableAccel) (pScreen); } return TRUE; }