📄 surface_gdi.c
字号:
}
}
return WINED3D_OK;
}
/*****************************************************************************
* _Blt_ColorFill
*
* Helper function that fills a memory area with a specific color
*
* Params:
* buf: memory address to start filling at
* width, height: Dimensions of the area to fill
* bpp: Bit depth of the surface
* lPitch: pitch of the surface
* color: Color to fill with
*
*****************************************************************************/
static HRESULT
_Blt_ColorFill(BYTE *buf,
int width, int height,
int bpp, LONG lPitch,
DWORD color)
{
int x, y;
LPBYTE first;
/* Do first row */
#define COLORFILL_ROW(type) \
{ \
type *d = (type *) buf; \
for (x = 0; x < width; x++) \
d[x] = (type) color; \
break; \
}
switch(bpp)
{
case 1: COLORFILL_ROW(BYTE)
case 2: COLORFILL_ROW(WORD)
case 3:
{
BYTE *d = (BYTE *) buf;
for (x = 0; x < width; x++,d+=3)
{
d[0] = (color ) & 0xFF;
d[1] = (color>> 8) & 0xFF;
d[2] = (color>>16) & 0xFF;
}
break;
}
case 4: COLORFILL_ROW(DWORD)
default:
FIXME("Color fill not implemented for bpp %d!\n", bpp*8);
return WINED3DERR_NOTAVAILABLE;
}
#undef COLORFILL_ROW
/* Now copy first row */
first = buf;
for (y = 1; y < height; y++)
{
buf += lPitch;
memcpy(buf, first, width * bpp);
}
return WINED3D_OK;
}
/*****************************************************************************
* IWineD3DSurface::Blt, GDI version
*
* Performs blits to a surface, eigher from a source of source-less blts
* This is the main functionality of DirectDraw
*
* Params:
* DestRect: Destination rectangle to write to
* SrcSurface: Source surface, can be NULL
* SrcRect: Source rectangle
*****************************************************************************/
HRESULT WINAPI
IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
RECT *DestRect,
IWineD3DSurface *SrcSurface,
RECT *SrcRect,
DWORD Flags,
WINEDDBLTFX *DDBltFx,
WINED3DTEXTUREFILTERTYPE Filter)
{
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
RECT xdst,xsrc;
HRESULT ret = WINED3D_OK;
WINED3DLOCKED_RECT dlock, slock;
WINED3DFORMAT dfmt = WINED3DFMT_UNKNOWN, sfmt = WINED3DFMT_UNKNOWN;
int bpp, srcheight, srcwidth, dstheight, dstwidth, width;
int x, y;
const StaticPixelFormatDesc *sEntry, *dEntry;
LPBYTE dbuf, sbuf;
TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, Src, SrcRect, Flags, DDBltFx);
if (TRACE_ON(d3d_surface))
{
if (DestRect) TRACE("\tdestrect :%dx%d-%dx%d\n",
DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
if (SrcRect) TRACE("\tsrcrect :%dx%d-%dx%d\n",
SrcRect->left, SrcRect->top, SrcRect->right, SrcRect->bottom);
#if 0
TRACE("\tflags: ");
DDRAW_dump_DDBLT(Flags);
if (Flags & WINEDDBLT_DDFX)
{
TRACE("\tblitfx: ");
DDRAW_dump_DDBLTFX(DDBltFx->dwDDFX);
}
#endif
}
if ( (This->Flags & SFLAG_LOCKED) || ((Src != NULL) && (Src->Flags & SFLAG_LOCKED)))
{
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
return WINEDDERR_SURFACEBUSY;
}
if(Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) {
/* Can happen when d3d9 apps do a StretchRect call which isn't handled in gl */
FIXME("Filters not supported in software blit\n");
}
if (Src == This)
{
IWineD3DSurface_LockRect(iface, &dlock, NULL, 0);
dfmt = This->resource.format;
slock = dlock;
sfmt = dfmt;
sEntry = getFormatDescEntry(sfmt, NULL, NULL);
dEntry = sEntry;
}
else
{
if (Src)
{
IWineD3DSurface_LockRect(SrcSurface, &slock, NULL, WINED3DLOCK_READONLY);
sfmt = Src->resource.format;
}
sEntry = getFormatDescEntry(sfmt, NULL, NULL);
dfmt = This->resource.format;
dEntry = getFormatDescEntry(dfmt, NULL, NULL);
IWineD3DSurface_LockRect(iface, &dlock,NULL,0);
}
if (!DDBltFx || !(DDBltFx->dwDDFX)) Flags &= ~WINEDDBLT_DDFX;
if (sEntry->isFourcc && dEntry->isFourcc)
{
if (sfmt != dfmt)
{
FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
ret = WINED3DERR_WRONGTEXTUREFORMAT;
goto release;
}
memcpy(dlock.pBits, slock.pBits, This->resource.size);
goto release;
}
if (sEntry->isFourcc && !dEntry->isFourcc)
{
FIXME("DXTC decompression not supported right now\n");
goto release;
}
if (DestRect)
{
memcpy(&xdst,DestRect,sizeof(xdst));
}
else
{
xdst.top = 0;
xdst.bottom = This->currentDesc.Height;
xdst.left = 0;
xdst.right = This->currentDesc.Width;
}
if (SrcRect)
{
memcpy(&xsrc,SrcRect,sizeof(xsrc));
}
else
{
if (Src)
{
xsrc.top = 0;
xsrc.bottom = Src->currentDesc.Height;
xsrc.left = 0;
xsrc.right = Src->currentDesc.Width;
}
else
{
memset(&xsrc,0,sizeof(xsrc));
}
}
/* First check for the validity of source / destination rectangles. This was
verified using a test application + by MSDN.
*/
if ((Src != NULL) &&
((xsrc.bottom > Src->currentDesc.Height) || (xsrc.bottom < 0) ||
(xsrc.top > Src->currentDesc.Height) || (xsrc.top < 0) ||
(xsrc.left > Src->currentDesc.Width) || (xsrc.left < 0) ||
(xsrc.right > Src->currentDesc.Width) || (xsrc.right < 0) ||
(xsrc.right < xsrc.left) || (xsrc.bottom < xsrc.top)))
{
WARN("Application gave us bad source rectangle for Blt.\n");
ret = WINEDDERR_INVALIDRECT;
goto release;
}
/* For the Destination rect, it can be out of bounds on the condition that a clipper
is set for the given surface.
*/
if ((/*This->clipper == NULL*/ TRUE) &&
((xdst.bottom > This->currentDesc.Height) || (xdst.bottom < 0) ||
(xdst.top > This->currentDesc.Height) || (xdst.top < 0) ||
(xdst.left > This->currentDesc.Width) || (xdst.left < 0) ||
(xdst.right > This->currentDesc.Width) || (xdst.right < 0) ||
(xdst.right < xdst.left) || (xdst.bottom < xdst.top)))
{
WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n");
ret = WINEDDERR_INVALIDRECT;
goto release;
}
/* Now handle negative values in the rectangles. Warning: only supported for now
in the 'simple' cases (ie not in any stretching / rotation cases).
First, the case where nothing is to be done.
*/
if (((xdst.bottom <= 0) || (xdst.right <= 0) ||
(xdst.top >= (int) This->currentDesc.Height) ||
(xdst.left >= (int) This->currentDesc.Width)) ||
((Src != NULL) &&
((xsrc.bottom <= 0) || (xsrc.right <= 0) ||
(xsrc.top >= (int) Src->currentDesc.Height) ||
(xsrc.left >= (int) Src->currentDesc.Width)) ))
{
TRACE("Nothing to be done !\n");
goto release;
}
/* The easy case : the source-less blits.... */
if (Src == NULL)
{
RECT full_rect;
RECT temp_rect; /* No idea if intersect rect can be the same as one of the source rect */
full_rect.left = 0;
full_rect.top = 0;
full_rect.right = This->currentDesc.Width;
full_rect.bottom = This->currentDesc.Height;
IntersectRect(&temp_rect, &full_rect, &xdst);
xdst = temp_rect;
}
else
{
/* Only handle clipping on the destination rectangle */
int clip_horiz = (xdst.left < 0) || (xdst.right > (int) This->currentDesc.Width );
int clip_vert = (xdst.top < 0) || (xdst.bottom > (int) This->currentDesc.Height);
if (clip_vert || clip_horiz)
{
/* Now check if this is a special case or not... */
if ((((xdst.bottom - xdst.top ) != (xsrc.bottom - xsrc.top )) && clip_vert ) ||
(((xdst.right - xdst.left) != (xsrc.right - xsrc.left)) && clip_horiz) ||
(Flags & WINEDDBLT_DDFX))
{
WARN("Out of screen rectangle in special case. Not handled right now.\n");
goto release;
}
if (clip_horiz)
{
if (xdst.left < 0) { xsrc.left -= xdst.left; xdst.left = 0; }
if (xdst.right > This->currentDesc.Width)
{
xsrc.right -= (xdst.right - (int) This->currentDesc.Width);
xdst.right = (int) This->currentDesc.Width;
}
}
if (clip_vert)
{
if (xdst.top < 0)
{
xsrc.top -= xdst.top;
xdst.top = 0;
}
if (xdst.bottom > This->currentDesc.Height)
{
xsrc.bottom -= (xdst.bottom - (int) This->currentDesc.Height);
xdst.bottom = (int) This->currentDesc.Height;
}
}
/* And check if after clipping something is still to be done... */
if ((xdst.bottom <= 0) || (xdst.right <= 0) ||
(xdst.top >= (int) This->currentDesc.Height) ||
(xdst.left >= (int) This->currentDesc.Width) ||
(xsrc.bottom <= 0) || (xsrc.right <= 0) ||
(xsrc.top >= (int) Src->currentDesc.Height) ||
(xsrc.left >= (int) Src->currentDesc.Width))
{
TRACE("Nothing to be done after clipping !\n");
goto release;
}
}
}
bpp = This->bytesPerPixel;
srcheight = xsrc.bottom - xsrc.top;
srcwidth = xsrc.right - xsrc.left;
dstheight = xdst.bottom - xdst.top;
dstwidth = xdst.right - xdst.left;
width = (xdst.right - xdst.left) * bpp;
assert(width <= dlock.Pitch);
dbuf = (BYTE*)dlock.pBits+(xdst.top*dlock.Pitch)+(xdst.left*bpp);
if (Flags & WINEDDBLT_WAIT)
{
Flags &= ~WINEDDBLT_WAIT;
}
if (Flags & WINEDDBLT_ASYNC)
{
static BOOL displayed = FALSE;
if (!displayed)
FIXME("Can't handle WINEDDBLT_ASYNC flag right now.\n");
displayed = TRUE;
Flags &= ~WINEDDBLT_ASYNC;
}
if (Flags & WINEDDBLT_DONOTWAIT)
{
/* WINEDDBLT_DONOTWAIT appeared in DX7 */
static BOOL displayed = FALSE;
if (!displayed)
FIXME("Can't handle WINEDDBLT_DONOTWAIT flag right now.\n");
displayed = TRUE;
Flags &= ~WINEDDBLT_DONOTWAIT;
}
/* First, all the 'source-less' blits */
if (Flags & WINEDDBLT_COLORFILL)
{
ret = _Blt_ColorFill(dbuf, dstwidth, dstheight, bpp,
dlock.Pitch, DDBltFx->u5.dwFillColor);
Flags &= ~WINEDDBLT_COLORFILL;
}
if (Flags & WINEDDBLT_DEPTHFILL)
{
FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
}
if (Flags & WINEDDBLT_ROP)
{
/* Catch some degenerate cases here */
switch(DDBltFx->dwROP)
{
case BLACKNESS:
ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,dlock.Pitch,0);
break;
case 0xAA0029: /* No-op */
break;
case WHITENESS:
ret = _Blt_ColorFill(dbuf,dstwidth,dstheight,bpp,dlock.Pitch,~0);
break;
case SRCCOPY: /* well, we do that below ? */
break;
default:
FIXME("Unsupported raster op: %08x Pattern: %p\n", DDBltFx->dwROP, DDBltFx->u5.lpDDSPattern);
goto error;
}
Flags &= ~WINEDDBLT_ROP;
}
if (Flags & WINEDDBLT_DDROPS)
{
FIXME("\tDdraw Raster Ops: %08x Pattern: %p\n", DDBltFx->dwDDROP, DDBltFx->u5.lpDDSPattern);
}
/* Now the 'with source' blits */
if (Src)
{
LPBYTE sbase;
int sx, xinc, sy, yinc;
if (!dstwidth || !dstheight) /* hmm... stupid program ? */
goto release;
sbase = (BYTE*)slock.pBits+(xsrc.top*slock.Pitch)+xsrc.left*bpp;
xinc = (srcwidth << 16) / dstwidth;
yinc = (srcheight << 16) / dstheight;
if (!Flags)
{
/* No effects, we can cheat here */
if (dstwidth == srcwidth)
{
if (dstheight == srcheight)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -