void renderer_dd::ddraw_delete_surfaces() { // release the gamma control if (gamma != NULL) IDirectDrawGammaControl_Release(gamma); gamma = NULL; // release the clipper if (clipper != NULL) IDirectDrawClipper_Release(clipper); clipper = NULL; // free the memory buffer global_free_array(membuffer); membuffer = NULL; membuffersize = 0; // release the blit surface if (blit != NULL) IDirectDrawSurface7_Release(blit); blit = NULL; // release the back surface if (back != NULL) IDirectDrawSurface7_Release(back); back = NULL; // release the primary surface if (primary != NULL) IDirectDrawSurface7_Release(primary); primary = NULL; }
static void ddraw_delete_surfaces(win_window_info *window) { dd_info *dd = window->drawdata; // release the gamma control if (dd->gamma != NULL) IDirectDrawGammaControl_Release(dd->gamma); dd->gamma = NULL; // release the clipper if (dd->clipper != NULL) IDirectDrawClipper_Release(dd->clipper); dd->clipper = NULL; // free the memory buffer if (dd->membuffer != NULL) free(dd->membuffer); dd->membuffer = NULL; dd->membuffersize = 0; // release the blit surface if (dd->blit != NULL) IDirectDrawSurface7_Release(dd->blit); dd->blit = NULL; // release the back surface if (dd->back != NULL) IDirectDrawSurface7_Release(dd->back); dd->back = NULL; // release the primary surface if (dd->primary != NULL) IDirectDrawSurface7_Release(dd->primary); dd->primary = NULL; }
static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level) { IDirect3DDevice7 *device = NULL; IDirectDrawSurface7 *surface; DDSURFACEDESC2 surface_desc; IDirectDraw7 *ddraw; IDirect3D7 *d3d7; HRESULT hr; if (!(ddraw = create_ddraw())) return NULL; hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level); ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; surface_desc.dwWidth = 640; surface_desc.dwHeight = 480; hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL); ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr); if (coop_level & DDSCL_NORMAL) { IDirectDrawClipper *clipper; hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL); ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawSurface7_SetClipper(surface, clipper); ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr); IDirectDrawClipper_Release(clipper); } hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7); IDirectDraw7_Release(ddraw); if (FAILED(hr)) { IDirectDrawSurface7_Release(surface); return NULL; } hr = IDirect3D7_CreateDevice(d3d7, &IID_IDirect3DTnLHalDevice, surface, &device); IDirect3D7_Release(d3d7); IDirectDrawSurface7_Release(surface); if (FAILED(hr)) return NULL; return device; }
static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type) { HRESULT result; // create the surface as requested result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type); return result; } // get a description of the primary surface result = IDirectDrawSurface7_GetSurfaceDesc(*surface, desc); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X getting %s surface desciption\n", (int)result, type); IDirectDrawSurface7_Release(*surface); *surface = NULL; return result; } // print out the good stuff mame_printf_verbose("DirectDraw: %s surface created: %dx%dx%d (R=%08X G=%08X B=%08X)\n", type, (int)desc->dwWidth, (int)desc->dwHeight, (int)desc->ddpfPixelFormat.dwRGBBitCount, (UINT32)desc->ddpfPixelFormat.dwRBitMask, (UINT32)desc->ddpfPixelFormat.dwGBitMask, (UINT32)desc->ddpfPixelFormat.dwBBitMask); return result; }
void Destroy( win32_driver_t * win32_driver ) { if( win32_driver->ddclipper ) IDirectDrawClipper_Release( win32_driver->ddclipper ); if( win32_driver->primary ) IDirectDrawSurface7_Release( win32_driver->primary ); if( win32_driver->secondary ) IDirectDrawSurface7_Release( win32_driver->secondary ); if( win32_driver->ddobj ) IDirectDraw_Release( win32_driver->ddobj ); free( win32_driver ); }
// 删除表面 void DDrawSurfaceRelease(CSURFACE *surface) { assert(surface); if (surface->clip) { IDirectDrawClipper_Release(surface->clip); surface->clip = NULL; } if (surface->lpDDS) { if (surface->lock) { IDirectDrawSurface7_Unlock(surface->lpDDS, NULL); surface->lock = 0; } if (IDirectDrawSurface7_IsLost(surface->lpDDS) != DD_OK) { IDirectDrawSurface7_Restore(surface->lpDDS); } IDirectDrawSurface7_Release(surface->lpDDS); surface->lpDDS = NULL; hSurfaceCounter--; } if (surface->primary) { if (lpDirectDraw7 && hFullScreenMode) { IDirectDraw7_RestoreDisplayMode(lpDirectDraw7); } hFullScreenMode = 0; } memset(surface, 0, sizeof(CSURFACE)); free(surface); assert(hSurfaceCounter >= 0); }
static void yv12_test(void) { HRESULT hr; DDSURFACEDESC2 desc; IDirectDrawSurface7 *surface; surface = create_overlay(256, 256, MAKEFOURCC('Y','V','1','2')); if(!surface) { skip("YV12 surfaces not available\n"); return; } memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); hr = IDirectDrawSurface7_Lock(surface, NULL, &desc, 0, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_Lock returned 0x%08x, expected DD_OK\n", hr); ok(desc.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_PITCH), "Unexpected desc.dwFlags 0x%08x\n", desc.dwFlags); ok(desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM) || desc.ddsCaps.dwCaps == (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_HWCODEC), "Unexpected desc.ddsCaps.dwCaps 0x%08x\n", desc.ddsCaps.dwCaps); ok(desc.dwWidth == 256 && desc.dwHeight == 256, "Expected size 256x256, got %ux%u\n", desc.dwWidth, desc.dwHeight); /* The overlay pitch seems to have 256 byte alignment */ ok((U1(desc).lPitch & 0xff) == 0, "Expected 256 byte aligned pitch, got %u\n", U1(desc).lPitch); hr = IDirectDrawSurface7_Unlock(surface, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_Unlock returned 0x%08x, expected DD_OK\n", hr); IDirectDrawSurface7_Release(surface); }
static ULONG WINAPI Thunk_IDirect3DTextureImpl_2_Release(IDirect3DTexture2 *iface) { ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface); TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", This); return IDirectDrawSurface7_Release(ICOM_INTERFACE(This, IDirectDrawSurface7)); }
static void rectangle_settings(void) { IDirectDrawSurface7 *overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')); HRESULT hr, hr2; RECT rect = {0, 0, 64, 64}; LONG posx, posy; /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is used. This is not true * in Windows Vista and earlier, but changed in Win7 */ hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_HIDE, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, DDOVER_SHOW, NULL); ok(hr == DD_OK || hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); /* Show that the overlay position is the (top, left) coordinate of the dest rectangle */ rect.top += 16; rect.left += 32; rect.bottom += 16; rect.right += 32; hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_SHOW, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); posx = -1; posy = -1; hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); ok(hr == DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); ok(posx == rect.left && posy == rect.top, "Overlay position is (%d, %d), expected (%d, %d)\n", posx, posy, rect.left, rect.top); /* Passing a NULL dest rect sets the position to 0/0 . Visually it can be seen that the overlay overlays the whole primary(==screen)*/ hr2 = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, NULL, 0, NULL); ok(hr2 == DD_OK || hr2 == DDERR_INVALIDPARAMS || hr2 == DDERR_OUTOFCAPS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr2); hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); ok(hr == DD_OK, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); if (SUCCEEDED(hr2)) { ok(posx == 0 && posy == 0, "Overlay position is (%d, %d), expected (%d, %d)\n", posx, posy, 0, 0); } else { /* Otherwise the position remains untouched */ ok(posx == 32 && posy == 16, "Overlay position is (%d, %d), expected (%d, %d)\n", posx, posy, 32, 16); } /* The position cannot be retrieved when the overlay is not shown */ hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, primary, &rect, DDOVER_HIDE, NULL); ok(hr == DD_OK, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); posx = -1; posy = -1; hr = IDirectDrawSurface7_GetOverlayPosition(overlay, &posx, &posy); ok(hr == DDERR_OVERLAYNOTVISIBLE, "IDirectDrawSurface7_GetOverlayPosition failed with hr=0x%08x\n", hr); ok(posx == 0 && posy == 0, "Overlay position is (%d, %d), expected (%d, %d)\n", posx, posy, 0, 0); IDirectDrawSurface7_Release(overlay); }
static void offscreen_test(void) { IDirectDrawSurface7 *overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')), *offscreen = NULL; HRESULT hr; DDSURFACEDESC2 ddsd; /* Try to overlay a NULL surface */ hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_SHOW, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, NULL, NULL, DDOVER_HIDE, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); /* Try to overlay an offscreen surface */ memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.dwWidth = 64; ddsd.dwHeight = 64; U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat); U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB; U4(ddsd).ddpfPixelFormat.dwFourCC = 0; U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16; U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800; U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07e0; U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &offscreen, NULL); ok(hr == DD_OK, "IDirectDraw7_CreateSurface failed with hr=0x%08x\n", hr); hr = IDirectDrawSurface7_UpdateOverlay(overlay, NULL, offscreen, NULL, DDOVER_SHOW, NULL); ok(hr == DD_OK || broken(hr == E_NOTIMPL), "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); /* Try to overlay the primary with a non-overlay surface */ hr = IDirectDrawSurface7_UpdateOverlay(offscreen, NULL, primary, NULL, DDOVER_SHOW, NULL); ok(hr == DDERR_NOTAOVERLAYSURFACE, "IDirectDrawSurface7_UpdateOverlay failed with hr=0x%08x\n", hr); IDirectDrawSurface7_Release(offscreen); IDirectDrawSurface7_Release(overlay); }
static BOOL CreateDirectDraw(void) { HRESULT hr; DDSURFACEDESC2 ddsd; IDirectDrawSurface7 *overlay = NULL; HMODULE hmod = GetModuleHandleA("ddraw.dll"); pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx"); if (!pDirectDrawCreateEx) { win_skip("DirectDrawCreateEx is not available\n"); return FALSE; } hr = pDirectDrawCreateEx(NULL, (void**)&ddraw, &IID_IDirectDraw7, NULL); ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr); if (!ddraw) { trace("DirectDrawCreateEx() failed with an error %x\n", hr); return FALSE; } hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "SetCooperativeLevel returned: %x\n", hr ); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL); if (FAILED(hr)) { IDirectDraw7_Release(ddraw); trace("IDirectDraw7_CreateSurface() failed with an error %x\n", hr); return FALSE; } overlay = create_overlay(64, 64, MAKEFOURCC('U','Y','V','Y')); if (!overlay) { IDirectDrawSurface7_Release(primary); IDirectDraw7_Release(ddraw); skip("Failed to create an overlay - assuming not supported\n"); return FALSE; } IDirectDraw7_Release(overlay); return TRUE; }
/***************************************************************************** * get_sub_mimaplevel * * Helper function that returns the next mipmap level * * tex_ptr: Surface of which to return the next level * *****************************************************************************/ static IDirectDrawSurfaceImpl * get_sub_mimaplevel(IDirectDrawSurfaceImpl *tex_ptr) { /* Now go down the mipmap chain to the next surface */ static const DDSCAPS2 mipmap_caps = { DDSCAPS_MIPMAP | DDSCAPS_TEXTURE, 0, 0, 0 }; LPDIRECTDRAWSURFACE7 next_level; IDirectDrawSurfaceImpl *surf_ptr; HRESULT hr; hr = IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(tex_ptr, IDirectDrawSurface7), (DDSCAPS2 *) &mipmap_caps, &next_level); if (FAILED(hr)) return NULL; surf_ptr = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, next_level); IDirectDrawSurface7_Release(next_level); return surf_ptr; }
static int create_directdraw(void) { HRESULT hr; IDirectDraw* pdd = NULL; DDSURFACEDESC2 ddsd; hr = DirectDrawCreate(NULL, &pdd, NULL); ok(hr==DD_OK, "DirectDrawCreate returned: %x\n", hr); if (hr != DD_OK) goto error; hr = IDirectDraw_QueryInterface(pdd, &IID_IDirectDraw7, (LPVOID*)&pdd7); ok(hr==DD_OK, "QueryInterface returned: %x\n", hr); if (hr != DD_OK) goto error; hr = IDirectDraw7_SetCooperativeLevel(pdd7, GetDesktopWindow(), DDSCL_NORMAL); ok(hr==DD_OK, "SetCooperativeLevel returned: %x\n", hr); ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; hr = IDirectDraw7_CreateSurface(pdd7, &ddsd, &pdds7, NULL); ok(hr==DD_OK, "CreateSurface returned: %x\n", hr); return TRUE; error: if (pdds7) IDirectDrawSurface7_Release(pdds7); if (pdd7) IDirectDraw7_Release(pdd7); if (pdd) IDirectDraw_Release(pdd); return FALSE; }
static void release_directdraw(void) { IDirectDrawSurface7_Release(pdds7); IDirectDraw7_Release(pdd7); }
int main(int argc, char **argv) { WNDCLASS wc; RECT rect; HINSTANCE hinstance; MSG msg; HWND window; LPDIRECTDRAW object; LPDIRECTDRAWSURFACE surface_primary; LPDIRECTDRAWSURFACE surface_back; int depth; int running; int pause_me = 0; hinstance = GetModuleHandle(0); wc.style = 0; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE); wc.lpszMenuName = NULL; wc.lpszClassName = "Evas_Software_DDraw_Test"; if(!RegisterClass(&wc)) return EXIT_FAILURE; rect.left = 0; rect.top = 0; rect.right = win_w; rect.bottom = win_h; AdjustWindowRect (&rect, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, FALSE); window = CreateWindowEx(0, "Evas_Software_DDraw_Test", "Evas_Software_DDraw_Test", WS_OVERLAPPEDWINDOW | WS_SIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hinstance, NULL); if (!window) return EXIT_FAILURE; if (!_directdraw_init(window, &object, &surface_primary, &surface_back, &depth, win_w, win_h)) return EXIT_FAILURE; ShowWindow(window, SW_SHOWDEFAULT); UpdateWindow(window); /* test evas_free.... :) */ evas_init(); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("software_ddraw")); evas_output_size_set(evas, win_w, win_h); evas_output_viewport_set(evas, 0, 0, win_w, win_h); { Evas_Engine_Info_Software_DDraw *einfo; einfo = (Evas_Engine_Info_Software_DDraw *)evas_engine_info_get(evas); /* the following is specific to the engine */ einfo->info.window = window; einfo->info.object = object; einfo->info.surface_primary = surface_primary; einfo->info.surface_back = surface_back; einfo->info.depth = depth; einfo->info.rotation = 0; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); printf("################ evas free\n"); setdown(); evas_free(evas); printf("evas freed. DONE\n"); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("software_ddraw")); evas_output_size_set(evas, win_w, win_h); evas_output_viewport_set(evas, 0, 0, win_w, win_h); { Evas_Engine_Info_Software_DDraw *einfo; einfo = (Evas_Engine_Info_Software_DDraw *) evas_engine_info_get(evas); /* the following is specific to the engine */ einfo->info.window = window; einfo->info.object = object; einfo->info.surface_primary = surface_primary; einfo->info.surface_back = surface_back; einfo->info.depth = depth; einfo->info.rotation = 0; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); printf("################ evas free\n"); setdown(); evas_free(evas); printf("evas freed. DONE\n"); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("software_ddraw")); evas_output_size_set(evas, win_w, win_h); evas_output_viewport_set(evas, 0, 0, win_w, win_h); { Evas_Engine_Info_Software_DDraw *einfo; einfo = (Evas_Engine_Info_Software_DDraw *) evas_engine_info_get(evas); /* the following is specific to the engine */ einfo->info.window = window; einfo->info.object = object; einfo->info.surface_primary = surface_primary; einfo->info.surface_back = surface_back; einfo->info.depth = depth; einfo->info.rotation = 0; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); printf("################ evas free\n"); setdown(); evas_free(evas); printf("evas freed. DONE\n"); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("software_ddraw")); evas_output_size_set(evas, win_w, win_h); evas_output_viewport_set(evas, 0, 0, win_w, win_h); { Evas_Engine_Info_Software_DDraw *einfo; einfo = (Evas_Engine_Info_Software_DDraw *) evas_engine_info_get(evas); /* the following is specific to the engine */ einfo->info.window = window; einfo->info.object = object; einfo->info.surface_primary = surface_primary; einfo->info.surface_back = surface_back; einfo->info.depth = depth; einfo->info.rotation = 0; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); printf("################ evas free\n"); setdown(); evas_free(evas); printf("evas freed. DONE\n"); evas = evas_new(); evas_output_method_set(evas, evas_render_method_lookup("software_ddraw")); evas_output_size_set(evas, win_w, win_h); evas_output_viewport_set(evas, 0, 0, win_w, win_h); { Evas_Engine_Info_Software_DDraw *einfo; einfo = (Evas_Engine_Info_Software_DDraw *) evas_engine_info_get(evas); /* the following is specific to the engine */ einfo->info.window = window; einfo->info.object = object; einfo->info.surface_primary = surface_primary; einfo->info.surface_back = surface_back; einfo->info.depth = depth; einfo->info.rotation = 0; evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); } setup(); orig_start_time = start_time = get_time(); running = 1; while (running) { while (PeekMessage (&msg, window, 0, 0, PM_NOREMOVE)) { int res; res = GetMessage (&msg, NULL, 0, 0); TranslateMessage (&msg); DispatchMessage (&msg); if (res == 0) running = 0; } if (!(pause_me == 1)) { loop(); evas_render(evas); } } exit: setdown(); evas_free(evas); if (surface_primary) IDirectDrawSurface7_Release (surface_primary); if (object) IDirectDraw7_Release (object); evas_shutdown(); return EXIT_SUCCESS; }
boolean CreateSecondary( win32_driver_t * win32_driver, int width, int height, int format ) { DDSURFACEDESC2 ddsd; if( format == XINE_IMGFMT_YV12 ) printf( "vo_out_directx : switching to YV12 overlay type\n" ); if( format == XINE_IMGFMT_YUY2 ) printf( "vo_out_directx : switching to YUY2 overlay type\n" ); #if RGB_SUPPORT if( format == IMGFMT_RGB ) printf( "vo_out_directx : switching to RGB overlay type\n" ); #endif if( !win32_driver->ddobj ) return FALSE; // store our reqested format, // width and height win32_driver->req_format = format; win32_driver->width = width; win32_driver->height = height; // if we already have a secondary // surface then release it if( win32_driver->secondary ) IDirectDrawSurface7_Release( win32_driver->secondary ); memset( &ddsd, 0, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwWidth = width; ddsd.dwHeight = height; if( format == XINE_IMGFMT_YV12 ) { // the requested format is XINE_IMGFMT_YV12 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwYUVBitCount = 16; ddsd.ddpfPixelFormat.dwFourCC = mmioFOURCC( 'Y', 'V', '1', '2' ); #ifdef LOG printf("CreateSecondary() - act_format = (YV12) %d\n", XINE_IMGFMT_YV12); #endif win32_driver->act_format = XINE_IMGFMT_YV12; } if( format == XINE_IMGFMT_YUY2 ) { // the requested format is XINE_IMGFMT_YUY2 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwYUVBitCount = 16; ddsd.ddpfPixelFormat.dwFourCC = mmioFOURCC( 'Y', 'U', 'Y', '2' ); #ifdef LOG printf("CreateSecondary() - act_format = (YUY2) %d\n", XINE_IMGFMT_YUY2); #endif win32_driver->act_format = XINE_IMGFMT_YUY2; } #if RGB_SUPPORT if( format == IMGFMT_RGB ) { // the requested format is IMGFMT_RGB ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; ddsd.ddpfPixelFormat.dwYUVBitCount = 24; ddsd.ddpfPixelFormat.dwRBitMask = 0xff0000; ddsd.ddpfPixelFormat.dwGBitMask = 0x00ff00; ddsd.ddpfPixelFormat.dwBBitMask = 0x0000ff; #ifdef LOG printf("CreateSecondary() - act_format = (RGB) %d\n", IMGFMT_RGB); #endif win32_driver->act_format = IMGFMT_RGB; } #endif /* RGB_SUPPORT */ #ifdef LOG printf("CreateSecondary() - IDirectDraw7_CreateSurface()\n"); #endif if( IDirectDraw7_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->secondary, 0 ) == DD_OK ) return TRUE; // Our fallback method is to create a back buffer // with the same image format as the primary surface #ifdef LOG printf("CreateSecondary() - Falling back to back buffer same as primary\n"); #endif ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; #ifdef LOG printf("CreateSecondary() - act_format = (NATIVE) %d\n", IMGFMT_NATIVE); #endif win32_driver->act_format = IMGFMT_NATIVE; if( IDirectDraw7_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->secondary, 0 ) == DD_OK ) return TRUE; // This is bad. We cant even create a surface with // the same format as the primary surface. Error( 0, "CreateSurface ( Secondary ) : unable to create a suitable rendering surface" ); return FALSE; }
static int _directdraw_init (HWND window, LPDIRECTDRAW *object, LPDIRECTDRAWSURFACE *surface_primary, LPDIRECTDRAWSURFACE *surface_back, int *depth, int width, int height) { DDSURFACEDESC2 surface_desc; DDPIXELFORMAT pixel_format; LPDIRECTDRAWCLIPPER clipper; LPDIRECTDRAW o; DDSURFACEDESC2 *sd; HRESULT res; res = DirectDrawCreateEx (NULL, (void **)&o, &IID_IDirectDraw7, NULL); if (FAILED(res)) return 0; res = IDirectDraw7_SetCooperativeLevel (o, window, DDSCL_NORMAL); if (FAILED(res)) { IDirectDraw7_Release (o); return 0; } res = IDirectDraw7_CreateClipper (o, 0, &clipper, NULL); if (FAILED(res)) { IDirectDraw7_Release (o); return 0; } res = IDirectDrawClipper_SetHWnd (clipper, 0, window); if (FAILED(res)) { IDirectDrawClipper_Release (clipper); IDirectDraw7_Release (o); return 0; } memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS; surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; sd=&surface_desc; res = IDirectDraw7_CreateSurface (o, &surface_desc, surface_primary, NULL); if (FAILED(res)) { IDirectDrawClipper_Release (clipper); IDirectDraw7_Release (o); return 0; } res = IDirectDrawSurface7_SetClipper (*surface_primary, clipper); if (FAILED(res)) { IDirectDrawClipper_Release (clipper); IDirectDrawSurface7_Release (*surface_primary); IDirectDraw7_Release (o); return 0; } memset (&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; surface_desc.dwWidth = width; surface_desc.dwHeight = height; sd=&surface_desc; res = IDirectDraw7_CreateSurface (o, (DDSURFACEDESC *)sd, surface_back, NULL); if (FAILED(res)) { IDirectDrawClipper_Release (clipper); IDirectDrawSurface7_Release (*surface_primary); IDirectDraw7_Release (o); return 0; } ZeroMemory(&pixel_format, sizeof(pixel_format)); pixel_format.dwSize = sizeof(pixel_format); IDirectDrawSurface7_GetPixelFormat(*surface_primary, &pixel_format); *object = o; *depth = pixel_format.dwRGBBitCount; return 1; }
static void test_clipper_blt(void) { IDirectDrawSurface7 *src_surface, *dst_surface; RECT client_rect, src_rect, *rect; IDirectDrawClipper *clipper; DDSURFACEDESC2 surface_desc; unsigned int i, j, x, y; IDirectDraw7 *ddraw; RGNDATA *rgn_data; D3DCOLOR color; HRGN r1, r2; HWND window; DDBLTFX fx; HRESULT hr; DWORD ret; static const D3DCOLOR expected1[] = { 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff, 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff, }; static const D3DCOLOR expected2[] = { 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, 0x00000000, 0x00000000, 0x000000ff, 0x000000ff, }; window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, 0, 0, 0, 0); ShowWindow(window, SW_SHOW); if (!(ddraw = create_ddraw())) { skip("Failed to create a ddraw object, skipping test.\n"); DestroyWindow(window); return; } ret = GetClientRect(window, &client_rect); ok(ret, "Failed to get client rect.\n"); ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2); ok(ret, "Failed to map client rect.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL); ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); rgn_data = HeapAlloc(GetProcessHeap(), 0, ret); hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret); ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr); ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize); ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType); ok(rgn_data->rdh.nCount == 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount); ok(rgn_data->rdh.nRgnSize == 16, "Got unexpected region size %u.\n", rgn_data->rdh.nRgnSize); ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect), "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top, rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); rect = (RECT *)&rgn_data->Buffer[0]; ok(EqualRect(rect, &client_rect), "Got unexpected clip rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n", rect->left, rect->top, rect->right, rect->bottom, client_rect.left, client_rect.top, client_rect.right, client_rect.bottom); HeapFree(GetProcessHeap(), 0, rgn_data); r1 = CreateRectRgn(0, 0, 320, 240); ok(!!r1, "Failed to create region.\n"); r2 = CreateRectRgn(320, 240, 640, 480); ok(!!r2, "Failed to create region.\n"); CombineRgn(r1, r1, r2, RGN_OR); ret = GetRegionData(r1, 0, NULL); rgn_data = HeapAlloc(GetProcessHeap(), 0, ret); ret = GetRegionData(r1, ret, rgn_data); ok(!!ret, "Failed to get region data.\n"); DeleteObject(r2); DeleteObject(r1); hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0); ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0); ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, rgn_data); memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; surface_desc.dwWidth = 640; surface_desc.dwHeight = 480; U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat); U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32; U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000; U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00; U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff; hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL); ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr); hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL); ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr); memset(&fx, 0, sizeof(fx)); fx.dwSize = sizeof(fx); hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL); ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr); ((DWORD *)surface_desc.lpSurface)[0] = 0xff0000ff; ((DWORD *)surface_desc.lpSurface)[1] = 0xff00ff00; ((DWORD *)surface_desc.lpSurface)[2] = 0xffff0000; ((DWORD *)surface_desc.lpSurface)[3] = 0xffffffff; hr = IDirectDrawSurface7_Unlock(src_surface, NULL); ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr); hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper); ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr); SetRect(&src_rect, 0, 0, 4, 1); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL); ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr); for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) { x = 80 * ((2 * j) + 1); y = 60 * ((2 * i) + 1); color = get_surface_color(dst_surface, x, y); ok(compare_color(color, expected1[i * 4 + j], 1), "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color); } } U5(fx).dwFillColor = 0xff0000ff; hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr); for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) { x = 80 * ((2 * j) + 1); y = 60 * ((2 * i) + 1); color = get_surface_color(dst_surface, x, y); ok(compare_color(color, expected2[i * 4 + j], 1), "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color); } } hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT); ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); DestroyWindow(window); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL); ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr); hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0); ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr); hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx); ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr); IDirectDrawSurface7_Release(dst_surface); IDirectDrawSurface7_Release(src_surface); IDirectDrawClipper_Release(clipper); IDirectDraw7_Release(ddraw); }
static void test_ddraw_objects(void) { HRESULT hr; unsigned long ref; IDirectDraw7 *DDraw7; IDirectDraw4 *DDraw4; IDirectDraw2 *DDraw2; IDirectDraw *DDraw1; IDirectDrawPalette *palette; IDirectDrawSurface7 *surface; IDirectDrawSurface *surface1; IDirectDrawSurface4 *surface4; PALETTEENTRY Table[256]; DDSURFACEDESC2 ddsd; hr = pDirectDrawCreateEx(NULL, (void **) &DDraw7, &IID_IDirectDraw7, NULL); ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", hr); if(!DDraw7) { trace("Couldn't create DDraw interface, skipping tests\n"); return; } hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw4, (void **) &DDraw4); ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw2, (void **) &DDraw2); ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1); ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); /* Fails without a cooplevel */ hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL); ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08x\n", hr); /* This check is before the cooplevel check */ hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef); ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08x\n", hr); hr = IDirectDraw7_SetCooperativeLevel(DDraw7, 0, DDSCL_NORMAL); ok(hr == DD_OK, "SetCooperativeLevel failed with %08x\n", hr); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; ddsd.dwWidth = 64; ddsd.dwHeight = 64; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat); U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB; U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 8; hr = IDirectDraw7_CreateSurface(DDraw7, &ddsd, &surface, NULL); ok(hr == DD_OK, "CreateSurface failed with %08x\n", hr); /* DDraw refcount increased by 1 */ ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 2, "Got refcount %ld, expected 2\n", ref); /* Surface refcount starts with 1 */ ref = getRefcount( (IUnknown *) surface); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); hr = IDirectDraw7_CreatePalette(DDraw7, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL); ok(hr == DD_OK, "CreatePalette returned %08x\n", hr); /* DDraw refcount increased by 1 */ ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 3, "Got refcount %ld, expected 3\n", ref); /* Palette starts with 1 */ ref = getRefcount( (IUnknown *) palette); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); /* Test attaching a palette to a surface */ hr = IDirectDrawSurface7_SetPalette(surface, palette); ok(hr == DD_OK, "IDirectDrawSurface_SetPalette failed with %08x\n", hr); /* Palette refcount increased, surface stays the same */ ref = getRefcount( (IUnknown *) palette); ok(ref == 2, "Got refcount %ld, expected 2\n", ref); ref = getRefcount( (IUnknown *) surface); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawSurface7_Release(surface); /* Increased before - decrease now */ ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 2, "Got refcount %ld, expected 2\n", ref); /* Releasing the surface detaches the palette */ ref = getRefcount( (IUnknown *) palette); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawPalette_Release(palette); /* Increased before - decrease now */ ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); /* Not all interfaces are AddRefed when a palette is created */ hr = IDirectDraw4_CreatePalette(DDraw4, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL); ok(hr == DD_OK, "CreatePalette returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw4); ok(ref == 2, "Got refcount %ld, expected 2\n", ref); IDirectDrawPalette_Release(palette); /* No addref here */ hr = IDirectDraw2_CreatePalette(DDraw2, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL); ok(hr == DD_OK, "CreatePalette returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw2); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawPalette_Release(palette); /* No addref here */ hr = IDirectDraw_CreatePalette(DDraw1, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL); ok(hr == DD_OK, "CreatePalette returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw1); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawPalette_Release(palette); /* Similar for surfaces */ hr = IDirectDraw4_CreateSurface(DDraw4, &ddsd, &surface4, NULL); ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw4); ok(ref == 2, "Got refcount %ld, expected 2\n", ref); IDirectDrawSurface4_Release(surface4); ddsd.dwSize = sizeof(DDSURFACEDESC); hr = IDirectDraw2_CreateSurface(DDraw2, (DDSURFACEDESC *) &ddsd, &surface1, NULL); ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw2); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawSurface_Release(surface1); hr = IDirectDraw_CreateSurface(DDraw1, (DDSURFACEDESC *) &ddsd, &surface1, NULL); ok(hr == DD_OK, "CreateSurface returned %08x\n", hr); ref = getRefcount( (IUnknown *) DDraw1); ok(ref == 1, "Got refcount %ld, expected 1\n", ref); IDirectDrawSurface_Release(surface1); IDirectDraw7_Release(DDraw7); IDirectDraw4_Release(DDraw4); IDirectDraw2_Release(DDraw2); IDirectDraw_Release(DDraw1); }
static void test_IDirectDrawStreamSample(void) { DDSURFACEDESC desc = { sizeof(desc) }; IAMMultiMediaStream *pams; HRESULT hr; IMediaStream *pvidstream = NULL; IDirectDrawMediaStream *pddstream = NULL; IDirectDrawStreamSample *pddsample = NULL; IDirectDrawSurface7 *surface7; IDirectDrawSurface *surface, *surface2; IDirectDraw *ddraw, *ddraw2; IDirectDraw7 *ddraw7; RECT rect; if (!(pams = create_ammultimediastream())) return; if (!create_directdraw()) { IAMMultiMediaStream_Release(pams); return; } hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IAMMultiMediaStream_GetMediaStream(pams, &MSPID_PrimaryVideo, &pvidstream); ok(hr == S_OK, "got 0x%08x\n", hr); if (FAILED(hr)) goto error; hr = IMediaStream_QueryInterface(pvidstream, &IID_IDirectDrawMediaStream, (LPVOID*)&pddstream); ok(hr == S_OK, "got 0x%08x\n", hr); if (FAILED(hr)) goto error; hr = IDirectDrawMediaStream_GetDirectDraw(pddstream, &ddraw); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDirectDrawMediaStream_GetDirectDraw(pddstream, &ddraw2); ok(hr == S_OK, "got 0x%08x\n", hr); ok(ddraw == ddraw2, "got %p, %p\n", ddraw, ddraw2); hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw7, (void**)&ddraw7); ok(hr == S_OK, "got 0x%08x\n", hr); IDirectDraw7_Release(ddraw7); IDirectDraw_Release(ddraw2); IDirectDraw_Release(ddraw); hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample); ok(hr == S_OK, "got 0x%08x\n", hr); surface = NULL; hr = IDirectDrawStreamSample_GetSurface(pddsample, &surface, &rect); ok(hr == S_OK, "got 0x%08x\n", hr); ok(surface != NULL, "got %p\n", surface); hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void**)&surface7); ok(hr == S_OK, "got 0x%08x\n", hr); IDirectDrawSurface7_Release(surface7); hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc); ok(hr == S_OK, "got 0x%08x\n", hr); ok(desc.dwWidth == 100, "width %d\n", desc.dwWidth); ok(desc.dwHeight == 100, "height %d\n", desc.dwHeight); ok(desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "format flags %08x\n", desc.ddpfPixelFormat.dwFlags); ok(desc.ddpfPixelFormat.dwRGBBitCount, "dwRGBBitCount %d\n", desc.ddpfPixelFormat.dwRGBBitCount); IDirectDrawSurface_Release(surface); IDirectDrawStreamSample_Release(pddsample); hr = IDirectDrawSurface7_QueryInterface(pdds7, &IID_IDirectDrawSurface, (void**)&surface); ok(hr == S_OK, "got 0x%08x\n", hr); EXPECT_REF(surface, 1); hr = IDirectDrawMediaStream_CreateSample(pddstream, surface, NULL, 0, &pddsample); ok(hr == S_OK, "got 0x%08x\n", hr); EXPECT_REF(surface, 2); surface2 = NULL; memset(&rect, 0, sizeof(rect)); hr = IDirectDrawStreamSample_GetSurface(pddsample, &surface2, &rect); ok(hr == S_OK, "got 0x%08x\n", hr); ok(surface == surface2, "got %p\n", surface2); ok(rect.right > 0 && rect.bottom > 0, "got %d, %d\n", rect.right, rect.bottom); EXPECT_REF(surface, 3); IDirectDrawSurface_Release(surface2); hr = IDirectDrawStreamSample_GetSurface(pddsample, NULL, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); IDirectDrawStreamSample_Release(pddsample); IDirectDrawSurface_Release(surface); error: if (pddstream) IDirectDrawMediaStream_Release(pddstream); if (pvidstream) IMediaStream_Release(pvidstream); release_directdraw(); IAMMultiMediaStream_Release(pams); }
void release_ddraw_surface_pointers ( void ) { // // Free up the previous video mode's pointers // if ( ddraw.lpZBuffer ) { if ( ddraw.lpRenderBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_DeleteAttachedSurface ( ddraw.lpRenderBuffer, 0, ddraw.lpZBuffer ); #endif } #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpZBuffer ); #endif ddraw.lpZBuffer = NULL; } if ( ddraw.lpFrontBuffer ) { if ( ddraw.use_double_buffer ) { if ( ddraw.lpBackBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpBackBuffer ); #endif ddraw.lpBackBuffer = NULL; } if ( ddraw.lpBackBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpBackBuffer ); #endif ddraw.lpBackBuffer = NULL; } } if ( ddraw.lpFrontBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpFrontBuffer ); #endif ddraw.lpFrontBuffer = NULL; } if ( ddraw.lpFrontBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpFrontBuffer ); #endif ddraw.lpFrontBuffer = NULL; } } if ( ddraw.use_system_memory ) { if ( ddraw.lpRenderBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpRenderBuffer ); #endif } if ( ddraw.lpRenderBuffer ) { #ifdef _WIN32 IDirectDrawSurface7_Release ( ddraw.lpRenderBuffer ); #endif } } ddraw.lpRenderBuffer = NULL; ddraw.lpRenderBuffer = NULL; }
// create surface from DDSURFACEDESC2 CSURFACE *DDrawCreateFromDesc(const DDSURFACEDESC2 *desc, HRESULT *hr) { LPDIRECTDRAWSURFACE7 lpDDS; DDSURFACEDESC2 ddsd; CSURFACE *surface; HRESULT result; if (lpDirectDraw7 == NULL) { if (DDrawInit() != 0) return NULL; } surface = (CSURFACE*)malloc(sizeof(CSURFACE)); assert(surface); ddsd = *desc; result = IDirectDraw7_CreateSurface(lpDirectDraw7, &ddsd, &lpDDS, NULL); if (hr) *hr = result; if (result != DD_OK) { free(surface); return NULL; } result = IDirectDrawSurface7_GetSurfaceDesc(lpDDS, &ddsd); if (hr) *hr = result; if (result != DD_OK) { IDirectDrawSurface7_Release(lpDDS); free(surface); return NULL; } surface->lpDDS = lpDDS; surface->ddsd = ddsd; surface->w = ddsd.dwWidth; surface->h = ddsd.dwHeight; surface->bpp = ddsd.ddpfPixelFormat.dwRGBBitCount; if (surface->bpp == 8) surface->pixfmt = PIXFMT_8; else if (surface->bpp == 15) surface->pixfmt = PIXFMT_RGB15; else if (surface->bpp == 16) surface->pixfmt = PIXFMT_RGB16; else if (surface->bpp == 24) surface->pixfmt = PIXFMT_RGB24; else if (surface->bpp == 32) { if (ddsd.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS) { surface->pixfmt = PIXFMT_ARGB32; } else { surface->pixfmt = PIXFMT_RGB32; } } surface->pitch = ddsd.dwLinearSize; surface->bits = (unsigned char*)ddsd.lpSurface; surface->mask = 0; surface->lock = 0; surface->clip = NULL; surface->primary = 0; surface->hWnd = NULL; hSurfaceCounter++; return surface; }