1ee7c6486Stsutsui/* $Xorg: sunMultiDepth.c,v 1.4 2001/02/09 02:04:44 xorgcvs Exp $ */ 2ee7c6486Stsutsui/* 3ee7c6486Stsutsui 4ee7c6486StsutsuiCopyright 1992, 1998 The Open Group 5ee7c6486Stsutsui 6ee7c6486StsutsuiPermission to use, copy, modify, distribute, and sell this software and its 7ee7c6486Stsutsuidocumentation for any purpose is hereby granted without fee, provided that 8ee7c6486Stsutsuithe above copyright notice appear in all copies and that both that 9ee7c6486Stsutsuicopyright notice and this permission notice appear in supporting 10ee7c6486Stsutsuidocumentation. 11ee7c6486Stsutsui 12ee7c6486StsutsuiThe above copyright notice and this permission notice shall be included 13ee7c6486Stsutsuiin all copies or substantial portions of the Software. 14ee7c6486Stsutsui 15ee7c6486StsutsuiTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16ee7c6486StsutsuiOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17ee7c6486StsutsuiMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18ee7c6486StsutsuiIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 19ee7c6486StsutsuiOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20ee7c6486StsutsuiARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21ee7c6486StsutsuiOTHER DEALINGS IN THE SOFTWARE. 22ee7c6486Stsutsui 23ee7c6486StsutsuiExcept as contained in this notice, the name of The Open Group shall 24ee7c6486Stsutsuinot be used in advertising or otherwise to promote the sale, use or 25ee7c6486Stsutsuiother dealings in this Software without prior written authorization 26ee7c6486Stsutsuifrom The Open Group. 27ee7c6486Stsutsui 28ee7c6486Stsutsui*/ 29ee7c6486Stsutsui 30ee7c6486Stsutsui/* $XFree86: xc/programs/Xserver/hw/sun/sunMultiDepth.c,v 1.6 2001/12/14 19:59:43 dawes Exp $ */ 31ee7c6486Stsutsui 32ee7c6486Stsutsui#include "sun.h" 33ee7c6486Stsutsui#include <X11/Xmd.h> 34ee7c6486Stsutsui#include "pixmapstr.h" 35ee7c6486Stsutsui#include "mi.h" 36ee7c6486Stsutsui#include "mistruct.h" 37ee7c6486Stsutsui#include "gcstruct.h" 38ee7c6486Stsutsui#include "fb.h" 39ee7c6486Stsutsui 40ee7c6486Stsutsui#ifndef SINGLEDEPTH 41ee7c6486Stsutsui 42ee7c6486Stsutsuistatic Bool 43ee7c6486StsutsuisunCfbCreateGC(GCPtr pGC) 44ee7c6486Stsutsui{ 45ee7c6486Stsutsui if (pGC->depth == 1) 46ee7c6486Stsutsui { 47ee7c6486Stsutsui return mfbCreateGC (pGC); 48ee7c6486Stsutsui } 49ee7c6486Stsutsui else if (pGC->depth <= 8) 50ee7c6486Stsutsui { 51ee7c6486Stsutsui return cfbCreateGC (pGC); 52ee7c6486Stsutsui } 53ee7c6486Stsutsui else if (pGC->depth <= 16) 54ee7c6486Stsutsui { 55ee7c6486Stsutsui return cfb16CreateGC (pGC); 56ee7c6486Stsutsui } 57ee7c6486Stsutsui else if (pGC->depth <= 32) 58ee7c6486Stsutsui { 59ee7c6486Stsutsui return cfb32CreateGC (pGC); 60ee7c6486Stsutsui } 61ee7c6486Stsutsui return FALSE; 62ee7c6486Stsutsui} 63ee7c6486Stsutsui 64ee7c6486Stsutsuistatic void 65ee7c6486StsutsuisunCfbGetSpans( 66ee7c6486Stsutsui DrawablePtr pDrawable, /* drawable from which to get bits */ 67ee7c6486Stsutsui int wMax, /* largest value of all *pwidths */ 68ee7c6486Stsutsui DDXPointPtr ppt, /* points to start copying from */ 69ee7c6486Stsutsui int *pwidth, /* list of number of bits to copy */ 70ee7c6486Stsutsui int nspans, /* number of scanlines to copy */ 71ee7c6486Stsutsui char *pdstStart /* where to put the bits */ 72ee7c6486Stsutsui) 73ee7c6486Stsutsui{ 74ee7c6486Stsutsui switch (pDrawable->bitsPerPixel) { 75ee7c6486Stsutsui case 1: 76ee7c6486Stsutsui mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart); 77ee7c6486Stsutsui break; 78ee7c6486Stsutsui case 8: 79ee7c6486Stsutsui cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart); 80ee7c6486Stsutsui break; 81ee7c6486Stsutsui case 16: 82ee7c6486Stsutsui cfb16GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart); 83ee7c6486Stsutsui break; 84ee7c6486Stsutsui case 32: 85ee7c6486Stsutsui cfb32GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart); 86ee7c6486Stsutsui break; 87ee7c6486Stsutsui } 88ee7c6486Stsutsui return; 89ee7c6486Stsutsui} 90ee7c6486Stsutsui 91ee7c6486Stsutsuistatic void 92ee7c6486StsutsuisunCfbGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char *pdstLine) 93ee7c6486Stsutsui{ 94ee7c6486Stsutsui switch (pDrawable->bitsPerPixel) 95ee7c6486Stsutsui { 96ee7c6486Stsutsui case 1: 97ee7c6486Stsutsui mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine); 98ee7c6486Stsutsui break; 99ee7c6486Stsutsui case 8: 100ee7c6486Stsutsui cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine); 101ee7c6486Stsutsui break; 102ee7c6486Stsutsui case 16: 103ee7c6486Stsutsui cfb16GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine); 104ee7c6486Stsutsui break; 105ee7c6486Stsutsui case 32: 106ee7c6486Stsutsui cfb32GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine); 107ee7c6486Stsutsui break; 108ee7c6486Stsutsui } 109ee7c6486Stsutsui} 110ee7c6486Stsutsui 111ee7c6486StsutsuiBool 112ee7c6486StsutsuisunCfbSetupScreen( 113ee7c6486Stsutsui ScreenPtr pScreen, 114ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 115ee7c6486Stsutsui int xsize, /* in pixels */ 116ee7c6486Stsutsui int ysize, /* in pixels */ 117ee7c6486Stsutsui int dpix, /* dots per inch */ 118ee7c6486Stsutsui int dpiy, /* dots per inch */ 119ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 120ee7c6486Stsutsui int bpp /* bits per pixel of root */ 121ee7c6486Stsutsui) 122ee7c6486Stsutsui{ 123ee7c6486Stsutsui int ret; 124ee7c6486Stsutsui 125ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 1, /* bits per pixel */ 1); 126ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 8, /* bits per pixel */ 8); 127ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 12, /* bits per pixel */ 16); 128ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 24, /* bits per pixel */ 32); 129ee7c6486Stsutsui 130ee7c6486Stsutsui ret = fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp); 131ee7c6486Stsutsui pScreen->CreateGC = sunCfbCreateGC; 132ee7c6486Stsutsui pScreen->GetImage = sunCfbGetImage; 133ee7c6486Stsutsui pScreen->GetSpans = sunCfbGetSpans; 134ee7c6486Stsutsui return ret; 135ee7c6486Stsutsui} 136ee7c6486Stsutsui 137ee7c6486StsutsuiBool 138ee7c6486StsutsuisunCfbFinishScreenInit( 139ee7c6486Stsutsui ScreenPtr pScreen, 140ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 141ee7c6486Stsutsui int xsize, /* in pixels */ 142ee7c6486Stsutsui int ysize, /* in pixels */ 143ee7c6486Stsutsui int dpix, /* dots per inch */ 144ee7c6486Stsutsui int dpiy, /* dots per inch */ 145ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 146ee7c6486Stsutsui int bpp 147ee7c6486Stsutsui) 148ee7c6486Stsutsui{ 149ee7c6486Stsutsui int i; 150ee7c6486Stsutsui VisualPtr visuals; 151ee7c6486Stsutsui int nvisuals; 152ee7c6486Stsutsui DepthPtr depths; 153ee7c6486Stsutsui int ndepths; 154ee7c6486Stsutsui VisualID defaultVisual; 155ee7c6486Stsutsui int rootdepth; 156ee7c6486Stsutsui 157ee7c6486Stsutsui if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, 158ee7c6486Stsutsui &rootdepth, &defaultVisual, 1 << (bpp - 1), 8)) 159ee7c6486Stsutsui return FALSE; 160ee7c6486Stsutsui if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, 161ee7c6486Stsutsui rootdepth, ndepths, depths, 162ee7c6486Stsutsui defaultVisual, nvisuals, visuals)) 163ee7c6486Stsutsui return FALSE; 164ee7c6486Stsutsui pScreen->CloseScreen = fbCloseScreen; 165ee7c6486Stsutsui return TRUE; 166ee7c6486Stsutsui} 167ee7c6486Stsutsui 168ee7c6486Stsutsui 169ee7c6486StsutsuiBool 170ee7c6486StsutsuisunCfbScreenInit( 171ee7c6486Stsutsui ScreenPtr pScreen, 172ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 173ee7c6486Stsutsui int xsize, /* in pixels */ 174ee7c6486Stsutsui int ysize, /* in pixels */ 175ee7c6486Stsutsui int dpix, /* dots per inch */ 176ee7c6486Stsutsui int dpiy, /* dots per inch */ 177ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 178ee7c6486Stsutsui int bpp 179ee7c6486Stsutsui) 180ee7c6486Stsutsui{ 181ee7c6486Stsutsui if (!sunCfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, 182ee7c6486Stsutsui width, bpp)) 183ee7c6486Stsutsui return FALSE; 184ee7c6486Stsutsui return sunCfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, 185ee7c6486Stsutsui dpiy, width, bpp); 186ee7c6486Stsutsui} 187ee7c6486Stsutsui 188ee7c6486Stsutsui 189ee7c6486Stsutsui#else /* SINGLEDEPTH */ 190ee7c6486Stsutsui 191ee7c6486Stsutsui/* stuff for 8-bit only server */ 192ee7c6486Stsutsui 193ee7c6486StsutsuiBool 194ee7c6486StsutsuisunCfbSetupScreen( 195ee7c6486Stsutsui ScreenPtr pScreen, 196ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 197ee7c6486Stsutsui int xsize, /* in pixels */ 198ee7c6486Stsutsui int ysize, /* in pixels */ 199ee7c6486Stsutsui int dpix, /* dots per inch */ 200ee7c6486Stsutsui int dpiy, /* dots per inch */ 201ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 202ee7c6486Stsutsui int bpp /* bits per pixel of root */ 203ee7c6486Stsutsui) 204ee7c6486Stsutsui{ 205ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 1, /* bits per pixel */ 1); 206ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 8, /* bits per pixel */ 8); 207ee7c6486Stsutsui return fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp); 208ee7c6486Stsutsui} 209ee7c6486Stsutsui 210ee7c6486StsutsuiBool 211ee7c6486StsutsuisunCfbFinishScreenInit( 212ee7c6486Stsutsui ScreenPtr pScreen, 213ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 214ee7c6486Stsutsui int xsize, /* in pixels */ 215ee7c6486Stsutsui int ysize, /* in pixels */ 216ee7c6486Stsutsui int dpix, /* dots per inch */ 217ee7c6486Stsutsui int dpiy, /* dots per inch */ 218ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 219ee7c6486Stsutsui int bpp 220ee7c6486Stsutsui) 221ee7c6486Stsutsui{ 222ee7c6486Stsutsui return fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, 223ee7c6486Stsutsui width, bpp); 224ee7c6486Stsutsui} 225ee7c6486Stsutsui 226ee7c6486StsutsuiBool 227ee7c6486StsutsuisunCfbScreenInit( 228ee7c6486Stsutsui ScreenPtr pScreen, 229ee7c6486Stsutsui void *pbits, /* pointer to screen bitmap */ 230ee7c6486Stsutsui int xsize, /* in pixels */ 231ee7c6486Stsutsui int ysize, /* in pixels */ 232ee7c6486Stsutsui int dpix, /* dots per inch */ 233ee7c6486Stsutsui int dpiy, /* dots per inch */ 234ee7c6486Stsutsui int width, /* pixel width of frame buffer */ 235ee7c6486Stsutsui int bpp 236ee7c6486Stsutsui) 237ee7c6486Stsutsui{ 238ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 1, /* bits per pixel */ 1); 239ee7c6486Stsutsui sunRegisterPixmapFormat( /* depth */ 8, /* bits per pixel */ 8); 240ee7c6486Stsutsui return fbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp); 241ee7c6486Stsutsui} 242ee7c6486Stsutsui 243ee7c6486Stsutsui#endif /* SINGLEDEPTH */ 244