update for HEAD-2003091401
[reactos.git] / subsys / win32k / eng / transblt.c
1 /*
2  *  ReactOS W32 Subsystem
3  *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  * 
21  * COPYRIGHT:        See COPYING in the top level directory
22  * PROJECT:          ReactOS kernel
23  * PURPOSE:          GDI TransparentBlt Function
24  * FILE:             subsys/win32k/eng/transblt.c
25  * PROGRAMER:        Jason Filby
26  * REVISION HISTORY:
27  *        4/6/2001: Created
28  */
29
30 #include <ddk/winddi.h>
31 #include <ddk/ntddk.h>
32 #include <ddk/ntddmou.h>
33 #include <ntos/minmax.h>
34 #include <include/dib.h>
35 #include <include/object.h>
36 #include <include/surface.h>
37
38 #include "brush.h"
39 #include "clip.h"
40 #include "objects.h"
41
42 #include <include/mouse.h>
43
44 BOOL STDCALL
45 EngTransparentBlt(PSURFOBJ Dest,
46                   PSURFOBJ Source,
47                   PCLIPOBJ Clip,
48                   PXLATEOBJ ColorTranslation,
49                   PRECTL DestRect,
50                   PRECTL SourceRect,
51                   ULONG TransparentColor,
52                   ULONG Reserved)
53 {
54   PSURFGDI DestGDI   = (PSURFGDI)AccessInternalObjectFromUserObject(Dest),
55            SourceGDI = (PSURFGDI)AccessInternalObjectFromUserObject(Source);
56   HSURF     hTemp;
57   PSURFOBJ  TempSurf;
58   POINTL    TempPoint, SourcePoint;
59   RECTL     TempRect;
60   SIZEL     TempSize;
61   BOOLEAN   ret;
62   LONG dx, dy, sx, sy;
63
64   dx = abs(DestRect->right  - DestRect->left);
65   dy = abs(DestRect->bottom - DestRect->top);
66
67   sx = abs(SourceRect->right  - SourceRect->left);
68   sy = abs(SourceRect->bottom - SourceRect->top);
69
70   if(sx<dx) dx = sx;
71   if(sy<dy) dy = sy;
72
73   MouseSafetyOnDrawStart(Source, SourceGDI, SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom);
74   MouseSafetyOnDrawStart(Dest, DestGDI, DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
75
76   if(DestGDI->TransparentBlt != NULL)
77   {
78     // The destination is device managed, therefore get the source into a format compatible surface
79     TempPoint.x = 0;
80     TempPoint.y = 0;
81     TempRect.top    = 0;
82     TempRect.left   = 0;
83     TempRect.bottom = dy;
84     TempRect.right  = dx;
85     TempSize.cx = TempRect.right;
86     TempSize.cy = TempRect.bottom;
87
88     hTemp = EngCreateBitmap(TempSize,
89                             DIB_GetDIBWidthBytes(dx, BitsPerFormat(Dest->iBitmapFormat)),
90                             Dest->iBitmapFormat, 0, NULL);
91     TempSurf = (PSURFOBJ)AccessUserObject((ULONG)hTemp);
92
93     SourcePoint.x = SourceRect->left;
94     SourcePoint.y = SourceRect->top;
95
96     // FIXME: Skip creating a TempSurf if we have the same BPP and palette
97     EngBitBlt(TempSurf, Source, NULL, NULL, ColorTranslation, &TempRect, &SourcePoint, NULL, NULL, NULL, 0);
98
99     ret = DestGDI->TransparentBlt(Dest, TempSurf, Clip, NULL, DestRect, SourceRect,
100                                   TransparentColor, Reserved);
101
102     MouseSafetyOnDrawEnd(Source, SourceGDI);
103     MouseSafetyOnDrawEnd(Dest, DestGDI);
104
105     if(EngDeleteSurface(hTemp) == FALSE)
106     {
107       DbgPrint("Win32k: Failed to delete surface: %d\n", hTemp);        
108       return FALSE;
109     }
110
111     return ret;
112   }
113
114   // Simulate a transparent blt
115
116   MouseSafetyOnDrawEnd(Source, SourceGDI);
117   MouseSafetyOnDrawEnd(Dest, DestGDI);
118
119   return TRUE;
120 }
121 /* EOF */