2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI EngCopyBits Function
5 * FILE: subsys/win32k/eng/copybits.c
6 * PROGRAMER: Jason Filby
11 #include <ddk/winddi.h>
14 #include "../dib/dib.h"
15 #include <include/mouse.h>
16 #include <include/object.h>
17 #include <include/eng.h>
19 BOOLEAN
CopyBitsCopy(SURFOBJ
*DestSurf
, SURFOBJ
*SourceSurf
,
20 SURFGDI
*DestGDI
, SURFGDI
*SourceGDI
,
21 PRECTL DestRect
, POINTL
*SourcePoint
,
22 LONG Delta
, XLATEOBJ
*ColorTranslation
)
24 LONG DestWidth
, DestHeight
, CurrentDestLine
, CurrentSourceLine
, CurrentDestCol
, CurrentSourceCol
, i
, TranslationPixel
;
26 PFN_DIB_GetPixel Source_DIB_GetPixel
;
27 PFN_DIB_PutPixel Dest_DIB_PutPixel
;
29 DestWidth
= DestRect
->right
- DestRect
->left
;
30 DestHeight
= DestRect
->bottom
- DestRect
->top
;
31 CurrentSourceCol
= SourcePoint
->x
;
32 CurrentSourceLine
= SourcePoint
->y
;
34 // Assign GetPixel DIB function according to bytes per pixel
35 switch(DestGDI
->BitsPerPixel
)
38 return DIB_To_1BPP_Bitblt(DestSurf
, SourceSurf
, DestGDI
, SourceGDI
,
39 DestRect
, SourcePoint
, Delta
, ColorTranslation
);
43 return DIB_To_4BPP_Bitblt(DestSurf
, SourceSurf
, DestGDI
, SourceGDI
,
44 DestRect
, SourcePoint
, Delta
, ColorTranslation
);
48 return DIB_To_24BPP_Bitblt(DestSurf
, SourceSurf
, DestGDI
, SourceGDI
,
49 DestRect
, SourcePoint
, Delta
, ColorTranslation
);
60 EngCopyBits(SURFOBJ
*Dest
,
63 XLATEOBJ
*ColorTranslation
,
68 SURFGDI
*DestGDI
, *SourceGDI
;
75 MouseSafetyOnDrawStart(Source
, SourceGDI
, SourcePoint
->x
, SourcePoint
->y
,
76 (SourcePoint
->x
+ abs(DestRect
->right
- DestRect
->left
)),
77 (SourcePoint
->y
+ abs(DestRect
->bottom
- DestRect
->top
)));
78 MouseSafetyOnDrawStart(Dest
, DestGDI
, DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
80 // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
81 // mark the copy block function to be DrvCopyBits instead of the
82 // GDI's copy bit function so as to remove clipping from the
83 // driver's responsibility
85 // If one of the surfaces isn't managed by the GDI
86 if((Dest
->iType
!=STYPE_BITMAP
) || (Source
->iType
!=STYPE_BITMAP
))
88 // Destination surface is device managed
89 if(Dest
->iType
!=STYPE_BITMAP
)
91 DestGDI
= (PSURFGDI
)AccessInternalObjectFromUserObject(Dest
);
93 if (DestGDI
->CopyBits
!=NULL
)
95 ret
= DestGDI
->CopyBits(Dest
, Source
, Clip
, ColorTranslation
, DestRect
, SourcePoint
);
97 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
98 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
104 // Source surface is device managed
105 if(Source
->iType
!=STYPE_BITMAP
)
107 SourceGDI
= (PSURFGDI
)AccessInternalObjectFromUserObject(Source
);
109 if (SourceGDI
->CopyBits
!=NULL
)
111 ret
= SourceGDI
->CopyBits(Dest
, Source
, Clip
, ColorTranslation
, DestRect
, SourcePoint
);
113 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
114 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
120 // If CopyBits wasn't hooked, BitBlt must be
121 ret
= EngBitBlt(Dest
, Source
,
122 NULL
, Clip
, ColorTranslation
, DestRect
, SourcePoint
,
123 NULL
, NULL
, NULL
, 0);
125 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
126 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
131 // Determine clipping type
132 if (Clip
== (CLIPOBJ
*) NULL
)
134 clippingType
= DC_TRIVIAL
;
136 clippingType
= Clip
->iDComplexity
;
139 // We only handle XO_TABLE translations at the momement
140 if ((ColorTranslation
== NULL
) || (ColorTranslation
->flXlate
& XO_TRIVIAL
) ||
141 (ColorTranslation
->flXlate
& XO_TABLE
))
143 SourceGDI
= (PSURFGDI
)AccessInternalObjectFromUserObject(Source
);
144 DestGDI
= (PSURFGDI
)AccessInternalObjectFromUserObject(Dest
);
149 CopyBitsCopy(Dest
, Source
, DestGDI
, SourceGDI
, DestRect
, SourcePoint
, Source
->lDelta
, ColorTranslation
);
151 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
152 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
157 // Clip the blt to the clip rectangle
158 EngIntersectRect(&rclTmp
, DestRect
, &Clip
->rclBounds
);
160 ptlTmp
.x
= SourcePoint
->x
+ rclTmp
.left
- DestRect
->left
;
161 ptlTmp
.y
= SourcePoint
->y
+ rclTmp
.top
- DestRect
->top
;
163 CopyBitsCopy(Dest
, Source
, DestGDI
, SourceGDI
, &rclTmp
, &ptlTmp
, Source
->lDelta
, ColorTranslation
);
165 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
166 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
172 CLIPOBJ_cEnumStart(Clip
, FALSE
, CT_RECTANGLES
, CD_ANY
, ENUM_RECT_LIMIT
);
175 EnumMore
= CLIPOBJ_bEnum(Clip
,(ULONG
) sizeof(RectEnum
), (PVOID
) &RectEnum
);
179 RECTL
* prclEnd
= &RectEnum
.arcl
[RectEnum
.c
];
180 RECTL
* prcl
= &RectEnum
.arcl
[0];
183 EngIntersectRect(prcl
, prcl
, DestRect
);
185 ptlTmp
.x
= SourcePoint
->x
+ prcl
->left
- DestRect
->left
;
186 ptlTmp
.y
= SourcePoint
->y
+ prcl
->top
- DestRect
->top
;
188 if(!CopyBitsCopy(Dest
, Source
, DestGDI
, SourceGDI
,
189 prcl
, &ptlTmp
, Source
->lDelta
, ColorTranslation
)) return FALSE
;
193 } while (prcl
< prclEnd
);
198 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
199 MouseSafetyOnDrawEnd(Dest
, DestGDI
);
205 MouseSafetyOnDrawEnd(Source
, SourceGDI
);
206 MouseSafetyOnDrawEnd(Dest
, DestGDI
);