xref: /OK3568_Linux_fs/external/xserver/hw/xwin/winmisc.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *Permission is hereby granted, free of charge, to any person obtaining
5*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
6*4882a593Smuzhiyun  *"Software"), to deal in the Software without restriction, including
7*4882a593Smuzhiyun  *without limitation the rights to use, copy, modify, merge, publish,
8*4882a593Smuzhiyun  *distribute, sublicense, and/or sell copies of the Software, and to
9*4882a593Smuzhiyun  *permit persons to whom the Software is furnished to do so, subject to
10*4882a593Smuzhiyun  *the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *The above copyright notice and this permission notice shall be
13*4882a593Smuzhiyun  *included in all copies or substantial portions of the Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*4882a593Smuzhiyun  *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*4882a593Smuzhiyun  *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*4882a593Smuzhiyun  *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19*4882a593Smuzhiyun  *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20*4882a593Smuzhiyun  *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21*4882a593Smuzhiyun  *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  *Except as contained in this notice, the name of Harold L Hunt II
24*4882a593Smuzhiyun  *shall not be used in advertising or otherwise to promote the sale, use
25*4882a593Smuzhiyun  *or other dealings in this Software without prior written authorization
26*4882a593Smuzhiyun  *from Harold L Hunt II.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * Authors:	Harold L Hunt II
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
32*4882a593Smuzhiyun #include <xwin-config.h>
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun #include "win.h"
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * Count the number of one bits in a color mask.
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun CARD8
winCountBits(DWORD dw)41*4882a593Smuzhiyun winCountBits(DWORD dw)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun     DWORD dwBits = 0;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun     while (dw) {
46*4882a593Smuzhiyun         dwBits += (dw & 1);
47*4882a593Smuzhiyun         dw >>= 1;
48*4882a593Smuzhiyun     }
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun     return dwBits;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  * Modify the screen pixmap to point to the new framebuffer address
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun Bool
winUpdateFBPointer(ScreenPtr pScreen,void * pbits)58*4882a593Smuzhiyun winUpdateFBPointer(ScreenPtr pScreen, void *pbits)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun     winScreenPriv(pScreen);
61*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun     /* Location of shadow framebuffer has changed */
64*4882a593Smuzhiyun     pScreenInfo->pfb = pbits;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun     /* Update the screen pixmap */
67*4882a593Smuzhiyun     if (!(*pScreen->ModifyPixmapHeader) (pScreen->devPrivate,
68*4882a593Smuzhiyun                                          pScreen->width,
69*4882a593Smuzhiyun                                          pScreen->height,
70*4882a593Smuzhiyun                                          pScreen->rootDepth,
71*4882a593Smuzhiyun                                          BitsPerPixel(pScreen->rootDepth),
72*4882a593Smuzhiyun                                          PixmapBytePad(pScreenInfo->dwStride,
73*4882a593Smuzhiyun                                                        pScreenInfo->dwBPP),
74*4882a593Smuzhiyun                                          pScreenInfo->pfb)) {
75*4882a593Smuzhiyun         FatalError("winUpdateFramebufferPointer - Failed modifying "
76*4882a593Smuzhiyun                    "screen pixmap\n");
77*4882a593Smuzhiyun     }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun     return TRUE;
80*4882a593Smuzhiyun }
81