2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
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.
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.
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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * PURPOSE: GDI EngCopyBits Function
23 * FILE: subsys/win32k/eng/copybits.c
24 * PROGRAMER: Jason Filby
38 EngCopyBits(SURFOBJ
*Dest
,
41 XLATEOBJ
*ColorTranslation
,
50 BITMAPOBJ
*DestObj
= NULL
;
53 ASSERT(Dest
!= NULL
&& Source
!= NULL
&& DestRect
!= NULL
&& SourcePoint
!= NULL
);
55 SourceObj
= CONTAINING_RECORD(Source
, BITMAPOBJ
, SurfObj
);
56 BITMAPOBJ_LockBitmapBits(SourceObj
);
57 MouseSafetyOnDrawStart(Source
, SourcePoint
->x
, SourcePoint
->y
,
58 (SourcePoint
->x
+ abs(DestRect
->right
- DestRect
->left
)),
59 (SourcePoint
->y
+ abs(DestRect
->bottom
- DestRect
->top
)));
62 DestObj
= CONTAINING_RECORD(Dest
, BITMAPOBJ
, SurfObj
);
63 BITMAPOBJ_LockBitmapBits(DestObj
);
65 MouseSafetyOnDrawStart(Dest
, DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
67 // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
68 // mark the copy block function to be DrvCopyBits instead of the
69 // GDI's copy bit function so as to remove clipping from the
70 // driver's responsibility
72 // If one of the surfaces isn't managed by the GDI
73 if((Dest
->iType
!=STYPE_BITMAP
) || (Source
->iType
!=STYPE_BITMAP
))
75 // Destination surface is device managed
76 if(Dest
->iType
!=STYPE_BITMAP
)
78 /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
79 /* FIXME: Remove typecast. */
80 if (((BITMAPOBJ
*)Dest
)->flHooks
& HOOK_COPYBITS
)
82 ret
= GDIDEVFUNCS(Dest
).CopyBits(
83 Dest
, Source
, Clip
, ColorTranslation
, DestRect
, SourcePoint
);
85 MouseSafetyOnDrawEnd(Dest
);
88 BITMAPOBJ_UnlockBitmapBits(DestObj
);
90 MouseSafetyOnDrawEnd(Source
);
91 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
97 // Source surface is device managed
98 if(Source
->iType
!=STYPE_BITMAP
)
100 /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
101 /* FIXME: Remove typecast. */
102 if (((BITMAPOBJ
*)Source
)->flHooks
& HOOK_COPYBITS
)
104 ret
= GDIDEVFUNCS(Source
).CopyBits(
105 Dest
, Source
, Clip
, ColorTranslation
, DestRect
, SourcePoint
);
107 MouseSafetyOnDrawEnd(Dest
);
110 BITMAPOBJ_UnlockBitmapBits(DestObj
);
112 MouseSafetyOnDrawEnd(Source
);
113 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
119 // If CopyBits wasn't hooked, BitBlt must be
120 ret
= IntEngBitBlt(Dest
, Source
,
121 NULL
, Clip
, ColorTranslation
, DestRect
, SourcePoint
,
122 NULL
, NULL
, NULL
, ROP3_TO_ROP4(SRCCOPY
));
124 MouseSafetyOnDrawEnd(Dest
);
127 BITMAPOBJ_UnlockBitmapBits(DestObj
);
129 MouseSafetyOnDrawEnd(Source
);
130 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
135 // Determine clipping type
136 if (Clip
== (CLIPOBJ
*) NULL
)
138 clippingType
= DC_TRIVIAL
;
140 clippingType
= Clip
->iDComplexity
;
143 BltInfo
.DestSurface
= Dest
;
144 BltInfo
.SourceSurface
= Source
;
145 BltInfo
.PatternSurface
= NULL
;
146 BltInfo
.XlateSourceToDest
= ColorTranslation
;
147 BltInfo
.XlatePatternToDest
= NULL
;
148 BltInfo
.Rop4
= SRCCOPY
;
153 BltInfo
.DestRect
= *DestRect
;
154 BltInfo
.SourcePoint
= *SourcePoint
;
156 DibFunctionsForBitmapFormat
[Dest
->iBitmapFormat
].DIB_BitBltSrcCopy(&BltInfo
);
158 MouseSafetyOnDrawEnd(Dest
);
161 BITMAPOBJ_UnlockBitmapBits(DestObj
);
163 MouseSafetyOnDrawEnd(Source
);
164 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
169 // Clip the blt to the clip rectangle
170 EngIntersectRect(&BltInfo
.DestRect
, DestRect
, &Clip
->rclBounds
);
172 BltInfo
.SourcePoint
.x
= SourcePoint
->x
+ BltInfo
.DestRect
.left
- DestRect
->left
;
173 BltInfo
.SourcePoint
.y
= SourcePoint
->y
+ BltInfo
.DestRect
.top
- DestRect
->top
;
175 DibFunctionsForBitmapFormat
[Dest
->iBitmapFormat
].DIB_BitBltSrcCopy(&BltInfo
);
177 MouseSafetyOnDrawEnd(Dest
);
180 BITMAPOBJ_UnlockBitmapBits(DestObj
);
182 MouseSafetyOnDrawEnd(Source
);
183 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
189 CLIPOBJ_cEnumStart(Clip
, FALSE
, CT_RECTANGLES
, CD_ANY
, 0);
192 EnumMore
= CLIPOBJ_bEnum(Clip
,(ULONG
) sizeof(RectEnum
), (PVOID
) &RectEnum
);
196 RECTL
* prclEnd
= &RectEnum
.arcl
[RectEnum
.c
];
197 RECTL
* prcl
= &RectEnum
.arcl
[0];
200 EngIntersectRect(&BltInfo
.DestRect
, prcl
, DestRect
);
202 BltInfo
.SourcePoint
.x
= SourcePoint
->x
+ prcl
->left
- DestRect
->left
;
203 BltInfo
.SourcePoint
.y
= SourcePoint
->y
+ prcl
->top
- DestRect
->top
;
205 if(!DibFunctionsForBitmapFormat
[Dest
->iBitmapFormat
].DIB_BitBltSrcCopy(&BltInfo
))
210 } while (prcl
< prclEnd
);
215 MouseSafetyOnDrawEnd(Dest
);
218 BITMAPOBJ_UnlockBitmapBits(DestObj
);
220 MouseSafetyOnDrawEnd(Source
);
221 BITMAPOBJ_UnlockBitmapBits(SourceObj
);
226 MouseSafetyOnDrawEnd(Dest
);
229 BITMAPOBJ_UnlockBitmapBits(DestObj
);
231 MouseSafetyOnDrawEnd(Source
);
232 BITMAPOBJ_UnlockBitmapBits(SourceObj
);