static void * Lock( win32_driver_t * win32_driver, void * surface ) { LPDIRECTDRAWSURFACE lock_surface = ( LPDIRECTDRAWSURFACE ) surface; HRESULT result; if( !surface ) return 0; memset( &win32_driver->ddsd, 0, sizeof( win32_driver->ddsd ) ); win32_driver->ddsd.dwSize = sizeof( win32_driver->ddsd ); result = IDirectDrawSurface_Lock( lock_surface, 0, &win32_driver->ddsd, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, 0 ); if( result == DDERR_SURFACELOST ) { IDirectDrawSurface_Restore( lock_surface ); result = IDirectDrawSurface_Lock( lock_surface, 0, &win32_driver->ddsd, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, 0 ); if( result != DD_OK ) return 0; } else if( result != DD_OK ) { if( result == DDERR_GENERIC ) { Error( 0, "surface->Lock : error, DDERR_GENERIC" ); exit( 1 ); } } return win32_driver->ddsd.lpSurface; }
/* 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; }
static void dctest_surf(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, &dc); ok(hr == DDERR_DCALREADYCREATED, "IDirectDrawSurface_GetDC failed: 0x%08x\n", hr); ok(dc2 == (HDC) 0x1234, "The failed GetDC call changed the dc: %p\n", dc2); 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_ReleaseDC(surf, dc); ok(hr == DD_OK, "IDirectDrawSurface_ReleaseDC failed: 0x%08x\n", hr); hr = IDirectDrawSurface_ReleaseDC(surf, dc); ok(hr == DDERR_NODC, "IDirectDrawSurface_ReleaseDC returned 0x%08x, expected DDERR_NODC\n", hr); }
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); }
// // Lock surface before multiple drawings by hand, for speed // boolean LockScreen(VOID) { DDSURFACEDESC ddsd; HRESULT ddrval; ZeroMemory(&ddsd, sizeof (ddsd)); ddsd.dwSize = sizeof (ddsd); // attempt to Lock the surface ddrval = IDirectDrawSurface_Lock(ScreenVirtual, NULL, &ddsd, DDLOCK_WAIT, NULL); // Always, always check for errors with DirectX! // If the surface was lost, restore it. if (ddrval == DDERR_SURFACELOST) { ddrval = IDirectDrawSurface_Restore(ScreenReal); // now retry to get the lock ddrval = IDirectDrawSurface_Lock(ScreenVirtual, NULL, &ddsd, DDLOCK_WAIT, NULL); } if (ddrval == DD_OK) { ScreenLocked = TRUE; ScreenPtr = (LPBYTE)ddsd.lpSurface; ScreenPitch = ddsd. #ifdef DUMMYUNIONNAMEN DUMMYUNIONNAMEN(1). #endif lPitch; } else { ScreenLocked = FALSE; ScreenPtr = NULL; ScreenPitch = 0; //I_Error("LockScreen() : couldn't restore the surface."); return false; } return true; }
LPSTR VGA_Lock(unsigned*Pitch,unsigned*Height,unsigned*Width,unsigned*Depth) { if (!lpddraw) return NULL; if (!lpddsurf) return NULL; if (IDirectDrawSurface_Lock(lpddsurf,NULL,&sdesc,0,0)) { ERR("could not lock surface!\n"); return NULL; } if (Pitch) *Pitch=sdesc.u1.lPitch; if (Height) *Height=sdesc.dwHeight; if (Width) *Width=sdesc.dwWidth; if (Depth) *Depth=sdesc.ddpfPixelFormat.u1.dwRGBBitCount; return sdesc.lpSurface; }
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); }
void DDLockCanvas(dd_grs_canvas *canvas) { HRESULT ddresult; DDSURFACEDESC ddsd; RECT rect; grs_bitmap *bmp; bmp = &canvas->canvas.cv_bitmap; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); if (canvas->lock_count == 0) { // Obtain info about a rectangle on the surface SetRect(&rect, bmp->bm_x, bmp->bm_y, bmp->bm_x+bmp->bm_w, bmp->bm_y+bmp->bm_h); RetryLock: ddresult = IDirectDrawSurface_Lock(canvas->lpdds, &rect, &ddsd, DDLOCK_WAIT, NULL); if (ddresult != DD_OK) { if (ddresult == DDERR_SURFACELOST) { if (!DDRestoreCanvas(canvas)) Error("Unable to restore surface for lock:"); else goto RetryLock; } else { while (canvas->lock_count) DDUnlockCanvas(canvas); Error("Unable to lock canvas: %x\n", ddresult); } } bmp->bm_data = (unsigned char *)ddsd.lpSurface; bmp->bm_rowsize = (short)ddsd.lPitch; // if (canvas->sram && !GRMODEINFO(modex)) { // // Manually calculate? // bmp->bm_data = bmp->bm_data + (bmp->bm_y*bmp->bm_rowsize); // bmp->bm_data += bmp->bm_x; // } _DDLockCounter++; } canvas->lock_count++; }
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); } } }
static int dx_alloc_buffers(char **b1, char **b2) { DWORD ddrval; DDSURFACEDESC ddsd; int i; currentbuff = 0; memset(surface, 0, sizeof(DDSURFACEDESC) * 2); memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); if (IDirectDrawSurface_GetSurfaceDesc(lpSurfaces[0], &ddsd) != DD_OK) { DeInitDD(); x_error("Failed to get pixel format"); return 0; } for (i = 0; i < 2; i++) { ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.dwWidth = displayX; ddsd.dwHeight = displayY; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddrval = IDirectDraw_CreateSurface(lpDD, &ddsd, &BackSurface[i], NULL); if (ddrval != DD_OK) { DeInitDD(); x_error("Failed to create back surface"); return 0; } } for (i = 0; i < 2; i++) { surface[i].dwSize = sizeof(DDSURFACEDESC); ddrval = IDirectDrawSurface_Lock(BackSurface[i], NULL, surface + i, DDLOCK_WAIT, NULL); if (ddrval != DD_OK) { DeInitDD(); x_fatalerror("Failed to lock offscreen surfaces"); } } buffer1 = *b1 = (char *) surface[0].lpSurface; buffer2 = *b2 = (char *) surface[1].lpSurface; lineSize = surface[0].u1.lPitch; initialized = 1; return lineSize; }
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); } }
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; }
static int vo_dx_init(void) { DDSURFACEDESC2 ddsd; dw = g_image_width = dlpctxp->pwidth; dh = g_image_height = dlpctxp->pheight; g_screen_width = GetSystemMetrics(SM_CXSCREEN); g_screen_height = GetSystemMetrics(SM_CYSCREEN); dx = (g_screen_width - dw) / 2; dy = (g_screen_height - dh) / 2; if (FALSE == DxCreateWindow()) { av_log(NULL, AV_LOG_ERROR, "DxCreateWindow step\n"); return -1; } if (FALSE == DxInitDirectDraw()) { av_log(NULL, AV_LOG_ERROR, "DxInitDirectDraw step\n"); return -1; } if (FALSE == DxCreatePrimarySurface()) { av_log(NULL, AV_LOG_ERROR, "DxCreatePrimarySurface step\n"); return -1; } if (FALSE == DxCreateOverlay()) { av_log(NULL, AV_LOG_ERROR, "DxCreateOverlay step\n"); if (FALSE == DxCreateOffbuffer()) { av_log(NULL, AV_LOG_ERROR, "DxCreateOffbuffer step\n"); return -1; } } if (FALSE == DxGetCaps()) { av_log(NULL, AV_LOG_ERROR, "DxGetCaps step\n"); return -1; } if (FALSE == DxManageOverlay()) { av_log(NULL, AV_LOG_ERROR, "DxManageOverlay step\n"); return -1; } memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); if (IDirectDrawSurface_Lock(g_lpddsBack, NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) != DD_OK) { av_log(NULL, AV_LOG_ERROR, "Lock Back Buffer step\n"); return -1; } g_dstride = ddsd.lPitch; g_image = ddsd.lpSurface; av_log(NULL, AV_LOG_ERROR, "vo dx init ok\n"); /* -------- create picture ----------------- */ my_pic = av_mallocz(sizeof(AVPicture)); if (-1 == avpicture_alloc(my_pic, g_image_format, g_image_width, g_image_height)) { av_log(NULL, AV_LOG_ERROR, "avpicture alloc error\n"); return -1; } g_inited = 1; return 0; }