Exemplo n.º 1
0
/* Display buffer */
static void PaintDD()
{
    DWORD ddrval;
    if (!IsWindowVisible(hWnd) || !active || !initialized
	|| !BackSurface[0])
	return;
    IDirectDrawSurface_Unlock(BackSurface[0], surface[0].lpSurface);
    IDirectDrawSurface_Unlock(BackSurface[1], surface[1].lpSurface);
    if (directX == DXFULLSCREEN) {
	if (storeddata)
	    free(storeddata), storeddata = NULL;
	storeddata =
	    store(currentbuff ? buffer2 : buffer1, bitDepth, lineSize,
		  displayX, displayY, mouseX, mouseY);
	drawmouse(currentbuff ? buffer2 : buffer1, mousepointer, bitDepth,
		  lineSize, displayX, displayY, mouseX, mouseY);
	ddrval =
	    IDirectDrawSurface_BltFast(lpSurfaces[0], 0, 0,
				       BackSurface[currentbuff], &rcScreen,
				       FALSE);
	restore(currentbuff ? buffer2 : buffer1, storeddata, bitDepth,
		lineSize, displayX, displayY, mouseX, mouseY);
	oldmouseX = mouseX;
	oldmouseY = mouseY;
    } else {
	ddrval = IDirectDrawSurface_Blt(lpSurfaces[0], &rcScreen,
					BackSurface[currentbuff],
					&rcViewport, DDBLT_WAIT, NULL);
    }
    if (ddrval != DD_OK) {
	if ((int) ddrval == (int) DDERR_SURFACELOST) {
	    IDirectDrawSurface_Restore(lpSurfaces[0]);
	    IDirectDrawSurface_Restore(BackSurface[0]);
	    IDirectDrawSurface_Restore(BackSurface[1]);
	    ddrval = IDirectDrawSurface_Blt(lpSurfaces[0], &rcScreen,
					    BackSurface[currentbuff],
					    &rcViewport, DDBLT_WAIT, NULL);
	    //if (ddrval == DDERR_SURFACELOST) resized=1; /*We've lost our fractal*/
	}
    }
    ddrval = IDirectDrawSurface_Lock(BackSurface[0], NULL, &surface[0],
				     DDLOCK_WAIT, NULL);
    ddrval = IDirectDrawSurface_Lock(BackSurface[1], NULL, &surface[1],
				     DDLOCK_WAIT, NULL);
    if (buffer1 != (char *) surface[0].lpSurface ||
	buffer2 != (char *) surface[1].lpSurface) {
	DeInitDD();
	x_fatalerror
	    ("Unexpected event - buffers moved! Please contact authors!");
    }
    needredraw = 0;

}
Exemplo n.º 2
0
static void dx_free_buffers(char *b1, char *b2)
{
    IDirectDrawSurface_Unlock(BackSurface[0], surface[0].lpSurface);
    IDirectDrawSurface_Unlock(BackSurface[1], surface[1].lpSurface);
    if (BackSurface[0])
	IDirectDrawSurface_Release(BackSurface[0]);
    if (BackSurface[1])
	IDirectDrawSurface_Release(BackSurface[1]);
    BackSurface[0] = NULL;
    BackSurface[1] = NULL;
    initialized = 0;
    buffer1 = buffer2 = NULL;
}
Exemplo n.º 3
0
void DDUnlockCanvas(dd_grs_canvas *canvas)
{
	HRESULT ddresult;
	grs_bitmap *bmp;

	bmp = &canvas->canvas.cv_bitmap;
	
	if (canvas->lock_count == 1) {
//		if (canvas->sram && !GRMODEINFO(modex)) {
//			bmp->bm_data = bmp->bm_data - bmp->bm_x;
//			bmp->bm_data = bmp->bm_data - (bmp->bm_y*bmp->bm_rowsize);
//		}
		ddresult = IDirectDrawSurface_Unlock(canvas->lpdds, 
								canvas->canvas.cv_bitmap.bm_data);
		if (ddresult != DD_OK) {	
				Error("Unable to unlock canvas: %x\n", ddresult);
				exit(1);
		}

		canvas->canvas.cv_bitmap.bm_data = NULL;
		canvas->canvas.cv_bitmap.bm_rowsize = 0;
		_DDLockCounter--;
	}
	canvas->lock_count--;
}
Exemplo n.º 4
0
static void UpdateMouseDD()
{
    DDSURFACEDESC m_surface;
    PUCHAR dst;
    DWORD ddrval;
    memset(&m_surface, 0, sizeof(DDSURFACEDESC));
    m_surface.dwSize = sizeof(DDSURFACEDESC);
    ddrval = IDirectDrawSurface_Lock(lpSurfaces[0], NULL, &m_surface,
				     DDLOCK_WAIT, NULL);
    if (ddrval != DD_OK) {
	return;
    }

    dst = (PUCHAR) m_surface.lpSurface;
    if (storeddata) {
	restore(dst, storeddata, bitDepth, m_surface.u1.lPitch, displayX,
		displayY, oldmouseX, oldmouseY);
	free(storeddata);
    }
    storeddata =
	store(dst, bitDepth, m_surface.u1.lPitch, displayX, displayY,
	      mouseX, mouseY);
    drawmouse(dst, mousepointer, bitDepth, m_surface.u1.lPitch, displayX,
	      displayY, mouseX, mouseY);
    oldmouseX = mouseX;
    oldmouseY = mouseY;
    IDirectDrawSurface_Unlock(lpSurfaces[0], m_surface.lpSurface);
}
Exemplo n.º 5
0
Arquivo: init.c Projeto: btb/d2x
static void finiObjects()
{
	if(lpDD!=NULL)
	{
		if(lpDDSPrimary!=NULL)
		{           
			IDirectDrawSurface_Release(lpDDSPrimary);
			lpDDSPrimary=NULL;
		}
		if(lpDDSOne!=NULL)
		{
			IDirectDrawSurface_Unlock(lpDDSOne,NULL);
			IDirectDrawSurface_Release(lpDDSOne);
			lpDDSOne=NULL;
		}
		if(lpDDPal!=NULL)
		{
			IDirectDrawSurface_Release(lpDDPal);
			lpDDPal=NULL;
		}
		IDirectDrawSurface_Release(lpDD);
		lpDD=NULL;
	}
   if(mouse_hidden)
    ShowCursor(TRUE);
} 
Exemplo n.º 6
0
//
// Unlock surface
//
VOID UnlockScreen(VOID)
{
	if (DD_OK != IDirectDrawSurface_Unlock(ScreenVirtual,NULL))
		I_Error("Couldn't UnLock the renderer!");

	ScreenLocked = FALSE;
	ScreenPtr    = NULL;
	ScreenPitch = 0;
}
Exemplo n.º 7
0
static void Unlock( void * surface )
{
  LPDIRECTDRAWSURFACE lock_surface = ( LPDIRECTDRAWSURFACE ) surface;

  if( !surface )
    return;

  IDirectDrawSurface_Unlock( lock_surface, 0 );
}
Exemplo n.º 8
0
static void dctest_sysvidmem(IDirectDrawSurface *surf, int ddsdver) {
    HRESULT hr;
    HDC dc, dc2 = (HDC) 0x1234;
    DDSURFACEDESC ddsd;
    DDSURFACEDESC2 ddsd2;

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    memset(&ddsd2, 0, sizeof(ddsd2));
    ddsd2.dwSize = sizeof(ddsd2);

    hr = IDirectDrawSurface_GetDC(surf, &dc);
    ok(hr == DD_OK, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);

    hr = IDirectDrawSurface_GetDC(surf, &dc2);
    ok(hr == DD_OK, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr);
    ok(dc == dc2, "Got two different DCs\n");

    hr = IDirectDrawSurface_Lock(surf, NULL, ddsdver == 1 ? &ddsd : ((DDSURFACEDESC *) &ddsd2), 0, NULL);
    ok(hr == DD_OK, "IDirectDrawSurface_Lock returned 0x%08x, expected DD_OK\n", hr);

    hr = IDirectDrawSurface_Lock(surf, NULL, ddsdver == 1 ? &ddsd : ((DDSURFACEDESC *) &ddsd2), 0, NULL);
    ok(hr == DDERR_SURFACEBUSY, "IDirectDrawSurface_Lock returned 0x%08x, expected DDERR_SURFACEBUSY\n", hr);

    hr = IDirectDrawSurface_Unlock(surf, NULL);
    ok(hr == DD_OK, "IDirectDrawSurface_Unlock returned 0x%08x, expected DD_OK\n", hr);
    hr = IDirectDrawSurface_Unlock(surf, NULL);
    ok(hr == DDERR_NOTLOCKED, "IDirectDrawSurface_Unlock returned 0x%08x, expected DDERR_NOTLOCKED\n", hr);

    hr = IDirectDrawSurface_ReleaseDC(surf, dc);
    ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr);
    hr = IDirectDrawSurface_ReleaseDC(surf, dc);
    ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr);
    /* That works any number of times... */
    hr = IDirectDrawSurface_ReleaseDC(surf, dc);
    ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr);
}
Exemplo n.º 9
0
static void flip_page(void)
{
    DDSURFACEDESC2 ddsd;
    HRESULT dxresult;

    IDirectDrawSurface_Unlock(g_lpddsBack, NULL);

    if (g_doublebuffer) {
        dxresult = IDirectDrawSurface_Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT);
        if (dxresult == DDERR_SURFACELOST) {
            av_log(NULL, AV_LOG_INFO, "vo_directx: Lost, Restoring Surface\n");
            IDirectDrawSurface_Restore(g_lpddsBack);
            IDirectDrawSurface_Restore(g_lpddsOverlay);
            IDirectDrawSurface_Restore(g_lpddsPrimary);
            dxresult = IDirectDrawSurface_Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT);
        }
        if (dxresult != DD_OK) {
            av_log(NULL, AV_LOG_ERROR, "vo_directx: can not flip page\n");
        }
    } else {
        DDBLTFX ddbltfx;
        memset(&ddbltfx, 0, sizeof(DDBLTFX));
        ddbltfx.dwSize = sizeof(DDBLTFX);
        ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
        IDirectDrawSurface_Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT,
                               &ddbltfx);
    }

    memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
    ddsd.dwSize = sizeof(DDSURFACEDESC2);
    if (IDirectDrawSurface_Lock(g_lpddsBack, NULL, &ddsd,
                                DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) == DD_OK) {
        if (tmp_image) {
            free(tmp_image);
            tmp_image = NULL;
        }
        g_dstride = ddsd.lPitch;
        g_image = ddsd.lpSurface;
    } else {
        if (!tmp_image) {
            av_log(NULL, AV_LOG_INFO,
                   "Locking the surface failed, rendering to a hidden surface!\n");
            tmp_image = g_image = calloc(1, g_image_height * g_dstride * 2);
        }
    }
}
Exemplo n.º 10
0
static void DDCopy(GE2DBitmapType *p)
{
	DDSURFACEDESC Desc;
	memset(&Desc,0,sizeof(DDSURFACEDESC));
	Desc.dwSize = sizeof(DDSURFACEDESC);

	if (IDirectDrawSurface_Lock(DDBuffer,NULL,&Desc,DDLOCK_WAIT,NULL) == DD_OK)
	{
		int y,n;
		uint8_t* i = (uint8_t*)Desc.lpSurface;
		n = Desc.lPitch*p->height;
		for (y=0;y<p->height;++y)
			memcpy(i+y*Desc.lPitch,(char*)p->plane1P+p->pitch*y,p->width);
		for (y=0;y<(p->height/2);++y)
		{
			memcpy(i+n+y*(Desc.lPitch/2),(char*)p->plane2P+p->chromaPitch*y,p->width/2);
			memcpy(i+n+n/4+y*(Desc.lPitch/2),(char*)p->plane3P+p->chromaPitch*y,p->width/2);
		}
		IDirectDrawSurface_Unlock(DDBuffer,NULL);
	}
}
Exemplo n.º 11
0
Arquivo: ddgfx.c Projeto: btb/d2x
int dd_gfx_loadbitmap2D(unsigned short handle, void *buf, int rleflag)
{
	HRESULT ddresult;
	DDSURFACEDESC ddsd;
	char *ptr;
	int pitch, i;
	grs_bitmap tbmp;

	Assert(handle != 0);

	if (!dd_gfx_initialized) return 0;

	handle--;									// Convert to valid handle

RedoLock:

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);

	ddresult = IDirectDrawSurface_Lock(gfxBitmap[handle].lpdds, NULL,	&ddsd, DDLOCK_WAIT, NULL);
	if (ddresult != DD_OK) {
		if (ddresult == DDERR_SURFACELOST) {
			ddresult = IDirectDrawSurface_Restore(gfxBitmap[handle].lpdds);
			if (ddresult != DD_OK) {
				if (ddresult != DDERR_WRONGMODE) {
					logentry("DDGFX::Restore::Surface err: %x\n", ddresult);		
					return 1;
				}
				else {
					LPDIRECTDRAWSURFACE lpdds;
					DDCOLORKEY ddck;

					IDirectDrawSurface_Release(lpdds);
					gfxBitmap[handle].lpdds = NULL;

					memset(&ddsd, 0, sizeof(ddsd));
					ddsd.dwSize = sizeof(ddsd);
					ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
					ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
					ddsd.dwWidth = gfxBitmap[handle].w;
					ddsd.dwHeight = gfxBitmap[handle].h;

					ddresult = IDirectDraw_CreateSurface(_lpDD, &ddsd, &lpdds, NULL);

					if (ddresult != DD_OK) {
						mprintf((0, "DDGFX: Failed to restore vidmem 2d bitmap.\n"));
						return 1;
					}
   				ddck.dwColorSpaceLowValue = TRANSPARENCY_COLOR;
   				ddck.dwColorSpaceHighValue = TRANSPARENCY_COLOR;
   				IDirectDrawSurface_SetColorKey(lpdds, DDCKEY_SRCBLT, &ddck);
					gfxBitmap[handle].lpdds = lpdds;
				}
			}
			
			goto RedoLock;
		}
		else {
			mprintf((0, "DDGFX:Unable to lock surface!!\n"));
			return 1;
		}
	}

//	Locked!
	ptr = ddsd.lpSurface;
	pitch = ddsd.lPitch;	

	gr_init_bitmap(&tbmp, BM_LINEAR, 0,0,gfxBitmap[handle].w, gfxBitmap[handle].h, gfxBitmap[handle].w, buf);
	if (rleflag) tbmp.bm_flags = BM_FLAG_RLE;

	for(i = 0; i < gfxBitmap[handle].h; i++) 
	{
		extern ubyte scale_rle_data[];
		if (rleflag) {
			decode_row(&tbmp,i);
			memcpy(ptr+(i*pitch), scale_rle_data, gfxBitmap[handle].w);
		} 
	  	else memcpy(ptr+(i*pitch), (ubyte*)(buf)+(i*gfxBitmap[handle].w), gfxBitmap[handle].w);
	}
	
	IDirectDrawSurface_Unlock(gfxBitmap[handle].lpdds, ptr);

//	Unlocked...

	return 0;
}
Exemplo n.º 12
0
void VGA_Unlock(void)
{
    IDirectDrawSurface_Unlock(lpddsurf,sdesc.lpSurface);
}