wined3d: Move PARAM C[] program.env[] into baseshader and out of vertex shaders.
[wine] / dlls / gdi / mfdrv / bitblt.c
1 /*
2  * GDI bit-blit operations
3  *
4  * Copyright 1993, 1994  Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <string.h>
22
23 #include "gdi.h"
24 #include "mfdrv/metafiledrv.h"
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
28
29 /***********************************************************************
30  *           MFDRV_PatBlt
31  */
32 BOOL MFDRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
33 {
34     MFDRV_MetaParam6( dev, META_PATBLT, left, top, width, height, HIWORD(rop), LOWORD(rop) );
35     return TRUE;
36 }
37
38
39 /***********************************************************************
40  *           MFDRV_BitBlt
41  */
42 BOOL MFDRV_BitBlt( PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
43                    PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop )
44 {
45     return MFDRV_StretchBlt(devDst, xDst, yDst, width, height, devSrc,
46                             xSrc, ySrc, width, height, rop);
47 }
48
49
50
51 /***********************************************************************
52  *           MFDRV_StretchBlt
53  * this function contains TWO ways for procesing StretchBlt in metafiles,
54  * decide between rdFunction values  META_STRETCHBLT or META_DIBSTRETCHBLT
55  * via #define STRETCH_VIA_DIB
56  */
57 #define STRETCH_VIA_DIB
58
59 BOOL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
60                        INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
61                        INT widthSrc, INT heightSrc, DWORD rop )
62 {
63     BOOL ret;
64     DWORD len;
65     METARECORD *mr;
66     BITMAP BM;
67     METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
68 #ifdef STRETCH_VIA_DIB
69     LPBITMAPINFOHEADER lpBMI;
70     WORD nBPP;
71 #endif
72     HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);
73
74     if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP))
75     {
76         WARN("bad bitmap object %p passed for hdc %p\n", hBitmap, physDevSrc->hdc);
77         return FALSE;
78     }
79 #ifdef STRETCH_VIA_DIB
80     nBPP = BM.bmPlanes * BM.bmBitsPixel;
81     if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
82     len = sizeof(METARECORD) + 10 * sizeof(INT16)
83             + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
84               + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
85     if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
86         return FALSE;
87     mr->rdFunction = META_DIBSTRETCHBLT;
88     lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
89     lpBMI->biSize      = sizeof(BITMAPINFOHEADER);
90     lpBMI->biWidth     = BM.bmWidth;
91     lpBMI->biHeight    = BM.bmHeight;
92     lpBMI->biPlanes    = 1;
93     lpBMI->biBitCount  = nBPP;
94     lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
95     lpBMI->biClrUsed   = nBPP <= 8 ? 1 << nBPP : 0;
96     lpBMI->biCompression = BI_RGB;
97     lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
98     lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
99     lpBMI->biClrImportant  = 0;                          /* 1 meter  = 39.37 inch */
100
101     TRACE("MF_StretchBltViaDIB->len = %ld  rop=%lx  PixYPM=%ld Caps=%d\n",
102           len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(physDevSrc->hdc, LOGPIXELSY));
103
104     if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight,
105                   (LPSTR)lpBMI + DIB_BitmapInfoSize( (BITMAPINFO *)lpBMI,
106                                                      DIB_RGB_COLORS ),
107                   (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
108 #else
109     len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
110     if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
111         return FALSE;
112     mr->rdFunction = META_STRETCHBLT;
113     *(mr->rdParm +10) = BM.bmWidth;
114     *(mr->rdParm +11) = BM.bmHeight;
115     *(mr->rdParm +12) = BM.bmWidthBytes;
116     *(mr->rdParm +13) = BM.bmPlanes;
117     *(mr->rdParm +14) = BM.bmBitsPixel;
118     TRACE("len = %ld  rop=%lx\n", len, rop);
119     if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))
120 #endif
121     {
122       mr->rdSize = len / sizeof(INT16);
123       *(mr->rdParm) = LOWORD(rop);
124       *(mr->rdParm + 1) = HIWORD(rop);
125       *(mr->rdParm + 2) = heightSrc;
126       *(mr->rdParm + 3) = widthSrc;
127       *(mr->rdParm + 4) = ySrc;
128       *(mr->rdParm + 5) = xSrc;
129       *(mr->rdParm + 6) = heightDst;
130       *(mr->rdParm + 7) = widthDst;
131       *(mr->rdParm + 8) = yDst;
132       *(mr->rdParm + 9) = xDst;
133       ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
134     }
135     else
136         ret = FALSE;
137     HeapFree( GetProcessHeap(), 0, mr);
138     return ret;
139 }
140
141
142 /***********************************************************************
143  *           MFDRV_StretchDIBits
144  */
145 INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
146                          INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
147                          INT heightSrc, const void *bits,
148                          const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
149 {
150     DWORD len, infosize, imagesize;
151     METARECORD *mr;
152
153     infosize = DIB_BitmapInfoSize(info, wUsage);
154     imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
155                                       info->bmiHeader.biHeight,
156                                       info->bmiHeader.biBitCount );
157
158     len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
159     mr = HeapAlloc( GetProcessHeap(), 0, len );
160     if(!mr) return 0;
161
162     mr->rdSize = len / 2;
163     mr->rdFunction = META_STRETCHDIB;
164     mr->rdParm[0] = LOWORD(dwRop);
165     mr->rdParm[1] = HIWORD(dwRop);
166     mr->rdParm[2] = wUsage;
167     mr->rdParm[3] = (INT16)heightSrc;
168     mr->rdParm[4] = (INT16)widthSrc;
169     mr->rdParm[5] = (INT16)ySrc;
170     mr->rdParm[6] = (INT16)xSrc;
171     mr->rdParm[7] = (INT16)heightDst;
172     mr->rdParm[8] = (INT16)widthDst;
173     mr->rdParm[9] = (INT16)yDst;
174     mr->rdParm[10] = (INT16)xDst;
175     memcpy(mr->rdParm + 11, info, infosize);
176     memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
177     MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
178     HeapFree( GetProcessHeap(), 0, mr );
179     return heightSrc;
180 }
181
182
183 /***********************************************************************
184  *           MFDRV_SetDIBitsToDeivce
185  */
186 INT MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
187                              DWORD cy, INT xSrc, INT ySrc, UINT startscan,
188                              UINT lines, LPCVOID bits, const BITMAPINFO *info,
189                              UINT coloruse )
190
191 {
192     DWORD len, infosize, imagesize;
193     METARECORD *mr;
194
195     infosize = DIB_BitmapInfoSize(info, coloruse);
196     imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
197                                       info->bmiHeader.biHeight,
198                                       info->bmiHeader.biBitCount );
199
200     len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
201     mr = HeapAlloc( GetProcessHeap(), 0, len );
202     if(!mr) return 0;
203
204     mr->rdSize = len / 2;
205     mr->rdFunction = META_SETDIBTODEV;
206     mr->rdParm[0] = coloruse;
207     mr->rdParm[1] = lines;
208     mr->rdParm[2] = startscan;
209     mr->rdParm[3] = (INT16)ySrc;
210     mr->rdParm[4] = (INT16)xSrc;
211     mr->rdParm[5] = (INT16)cy;
212     mr->rdParm[6] = (INT16)cx;
213     mr->rdParm[7] = (INT16)yDst;
214     mr->rdParm[8] = (INT16)xDst;
215     memcpy(mr->rdParm + 9, info, infosize);
216     memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
217     MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
218     HeapFree( GetProcessHeap(), 0, mr );
219     return lines;
220 }