static HRESULT WINAPI IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc, LPDIRECTDRAWSURFACE *ppSurface, IUnknown *pUnkOuter) { LPDIRECTDRAWSURFACE7 pSurface7; IDirectDrawSurfaceImpl *impl; HRESULT hr; /* Remove front buffer flag, this causes failure in v7, and its added to normal * primaries anyway */ pSDesc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok, * since the data layout is the same */ hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw1(This), (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter); if (FAILED(hr)) { *ppSurface = NULL; return hr; } impl = (IDirectDrawSurfaceImpl *)pSurface7; *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl; set_surf_version(impl, 1); IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This)); impl->ifaceToRelease = NULL; return hr; }
static HRESULT WINAPI IDirectDraw3Impl_CreateSurface(LPDIRECTDRAW3 This, LPDDSURFACEDESC pSDesc, LPDIRECTDRAWSURFACE *ppSurface, IUnknown *pUnkOuter) { LPDIRECTDRAWSURFACE7 pSurface7; IDirectDrawSurfaceImpl *impl; HRESULT hr; hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw3(This), (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter); if (FAILED(hr)) { *ppSurface = NULL; return hr; } impl = (IDirectDrawSurfaceImpl *)pSurface7; *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl; set_surf_version(impl, 3); IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw3(This)); IDirectDraw3_AddRef(This); impl->ifaceToRelease = (IUnknown *) This; return hr; }
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; }
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 WINAPI IDirectDraw2Impl_CreatePalette(LPDIRECTDRAW2 This, DWORD dwFlags, LPPALETTEENTRY pEntries, LPDIRECTDRAWPALETTE *ppPalette, IUnknown *pUnkOuter) { HRESULT hr; hr = IDirectDraw7_CreatePalette((IDirectDraw7 *)ddraw_from_ddraw2(This), dwFlags, pEntries, ppPalette, pUnkOuter); if(SUCCEEDED(hr) && *ppPalette) { IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette; IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw2(This)); impl->ifaceToRelease = NULL; } return hr; }
static ULONG WINAPI DirectDrawMediaStreamImpl_IAMMediaStream_Release(IAMMediaStream *iface) { DirectDrawMediaStreamImpl *This = impl_from_DirectDrawMediaStream_IAMMediaStream(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p/%p)->(): new ref = %u\n", iface, This, ref); if (!ref) { if (This->ddraw) IDirectDraw7_Release(This->ddraw); HeapFree(GetProcessHeap(), 0, This); } return ref; }
void renderer_dd::ddraw_delete() { // free surfaces ddraw_delete_surfaces(); // restore resolutions if (ddraw != NULL) IDirectDraw7_RestoreDisplayMode(ddraw); // reset cooperative level if (ddraw != NULL && window().m_hwnd != NULL) IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_NORMAL); // release the DirectDraw object itself if (ddraw != NULL) IDirectDraw7_Release(ddraw); ddraw = NULL; }
// Destroy Surface void DDrawDestroy(void) { if (hSurfaceCounter > 0) { fprintf(stderr, "Destroy DirectDraw before release the surfaces\n"); fflush(stderr); } if (lpDirectDraw7 != NULL) { IDirectDraw7_Release(lpDirectDraw7); lpDirectDraw7 = NULL; } hDirectDrawWnd = NULL; if (hDDrawDLL) { FreeLibrary(hDDrawDLL); hDDrawDLL = NULL; } }
static HRESULT WINAPI IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc, LPDIRECTDRAWSURFACE4 *ppSurface, IUnknown *pUnkOuter) { HRESULT hr; IDirectDrawSurfaceImpl *impl; hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw4(This), pSDesc, (LPDIRECTDRAWSURFACE7 *)ppSurface, pUnkOuter); impl = (IDirectDrawSurfaceImpl *)*ppSurface; if(SUCCEEDED(hr) && impl) { set_surf_version(impl, 4); IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw4(This)); IDirectDraw4_AddRef(This); impl->ifaceToRelease = (IUnknown *) This; } return hr; }
static void ddraw_delete(win_window_info *window) { dd_info *dd = window->drawdata; // free surfaces ddraw_delete_surfaces(window); // restore resolutions if (dd->ddraw != NULL) IDirectDraw7_RestoreDisplayMode(dd->ddraw); // reset cooperative level if (dd->ddraw != NULL && window->hwnd != NULL) IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->hwnd, DDSCL_NORMAL); // release the DirectDraw object itself if (dd->ddraw != NULL) IDirectDraw7_Release(dd->ddraw); dd->ddraw = NULL; }
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 test_coop_level_create_device_window(void) { HWND focus_window, device_window; IDirectDraw7 *ddraw; HRESULT hr; focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); if (!(ddraw = create_ddraw())) { skip("Failed to create a 3D device, skipping test.\n"); DestroyWindow(focus_window); return; } hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW); ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL); ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN); ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */ if (broken(hr == DDERR_INVALIDPARAMS)) { win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n"); IDirectDraw7_Release(ddraw); DestroyWindow(focus_window); return; } hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!!device_window, "Device window not found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!!device_window, "Device window not found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!device_window, "Unexpected device window found.\n"); hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr); device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd"); ok(!!device_window, "Device window not found.\n"); IDirectDraw7_Release(ddraw); DestroyWindow(focus_window); }
static int config_adapter_mode(win_window_info *window) { DDDEVICEIDENTIFIER2 identifier; dd_info *dd = window->drawdata; HRESULT result; // choose the monitor number get_adapter_for_monitor(dd, window->monitor); // create a temporary DirectDraw object result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, &IID_IDirectDraw7, NULL); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result); return 1; } // get the identifier result = IDirectDraw7_GetDeviceIdentifier(dd->ddraw, &identifier, 0); if (result != DD_OK) { mame_printf_error("Error getting identifier for device\n"); return 1; } mame_printf_verbose("DirectDraw: Configuring device %s\n", identifier.szDescription); // get the current display mode memset(&dd->origmode, 0, sizeof(dd->origmode)); dd->origmode.dwSize = sizeof(dd->origmode); result = IDirectDraw7_GetDisplayMode(dd->ddraw, &dd->origmode); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X getting current display mode\n", (int)result); IDirectDraw7_Release(dd->ddraw); return 1; } // choose a resolution: full screen mode case if (window->fullscreen) { // default to the current mode exactly dd->width = dd->origmode.dwWidth; dd->height = dd->origmode.dwHeight; dd->refresh = dd->origmode.dwRefreshRate; // if we're allowed to switch resolutions, override with something better if (video_config.switchres) pick_best_mode(window); } // release the DirectDraw object IDirectDraw7_Release(dd->ddraw); dd->ddraw = NULL; // if we're not changing resolutions, make sure we have a resolution we can handle if (!window->fullscreen || !video_config.switchres) { switch (dd->origmode.ddpfPixelFormat.dwRBitMask) { case 0x00ff0000: case 0x000000ff: case 0xf800: case 0x7c00: break; default: mame_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->origmode.ddpfPixelFormat.dwRBitMask, (int)dd->origmode.ddpfPixelFormat.dwGBitMask, (int)dd->origmode.ddpfPixelFormat.dwBBitMask); return 1; } } return 0; }
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; }
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); }
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_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_iface_refcnt(void) { HRESULT hr; IDirectDraw *DDraw1; IDirectDraw2 *DDraw2; IDirectDraw4 *DDraw4; IDirectDraw7 *DDraw7; IDirect3D7 *D3D7; IDirect3D3 *D3D3; IDirect3D2 *D3D2; IDirect3D *D3D1; long ref; 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; } ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 1, "Initial IDirectDraw7 reference count is %ld\n", ref); 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_QueryInterf&ace returned %08x\n", hr); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirectDraw, (void **) &DDraw1); ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr); /* All interfaces now have refcount 1! */ ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 1, "IDirectDraw7 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw4); ok(ref == 1, "IDirectDraw4 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw2); ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw1); ok(ref == 1, "IDirectDraw reference count is %ld\n", ref); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D7, (void **) &D3D7); ok(hr == DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr); /* Apparently IDirectDrawX and IDirect3DX are linked together */ ref = getRefcount( (IUnknown *) D3D7); ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); IDirectDraw7_AddRef(DDraw7); ref = getRefcount( (IUnknown *) D3D7); ok(ref == 3, "IDirect3D7 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 3, "IDirectDraw7 reference count is %ld\n", ref); IDirect3D7_Release(D3D7); ref = getRefcount( (IUnknown *) D3D7); ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); /* Can't get older d3d interfaces. WHY????? */ hr = IDirectDraw7_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3); hr = IDirectDraw4_QueryInterface(DDraw4, &IID_IDirect3D3, (void **) &D3D3); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw4_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D3) IDirect3D3_Release(D3D3); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D2, (void **) &D3D2); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2); hr = IDirectDraw2_QueryInterface(DDraw2, &IID_IDirect3D2, (void **) &D3D2); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw2_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D2) IDirect3D2_Release(D3D2); hr = IDirectDraw7_QueryInterface(DDraw7, &IID_IDirect3D, (void **) &D3D1); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw7_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1); hr = IDirectDraw_QueryInterface(DDraw1, &IID_IDirect3D, (void **) &D3D1); todo_wine ok(hr == E_NOINTERFACE, "IDirectDraw_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1); hr = IDirect3D7_QueryInterface(D3D7, &IID_IDirect3D, (void **) &D3D1); todo_wine ok(hr == E_NOINTERFACE, "IDirect3D7_QueryInterface returned %08x\n", hr); if(hr == DD_OK && D3D1) IDirect3D_Release(D3D1); /* Try an AddRef, it only affects the AddRefed interface */ IDirectDraw4_AddRef(DDraw4); ref = getRefcount( (IUnknown *) DDraw7); ok(ref == 2, "IDirectDraw7 reference count is %ld\n", ref); /* <-- From the d3d query */ ref = getRefcount( (IUnknown *) DDraw4); ok(ref == 2, "IDirectDraw4 reference count is %ld\n", ref); /* <-- The AddRef call */ ref = getRefcount( (IUnknown *) DDraw2); ok(ref == 1, "IDirectDraw2 reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) DDraw1); ok(ref == 1, "IDirectDraw reference count is %ld\n", ref); ref = getRefcount( (IUnknown *) D3D7); ok(ref == 2, "IDirect3D7 reference count is %ld\n", ref); /* <-- From the d3d query */ IDirectDraw4_Release(DDraw4); /* Make sure that they are one object, not different ones */ hr = IDirectDraw4_SetCooperativeLevel(DDraw4, GetDesktopWindow(), DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); ok(hr == DD_OK, "IDirectDraw4::SetCooperativeLevel returned %08x\n", hr); /* After an window has been set, DDSCL_SETFOCUSWINDOW should return DDERR_HWNDALREADYSET, see the mode test */ hr = IDirectDraw7_SetCooperativeLevel(DDraw7, NULL, DDSCL_SETFOCUSWINDOW); ok(hr == DDERR_HWNDALREADYSET, "IDirectDraw7::SetCooperativeLevel returned %08x\n", hr); /* All done, release all interfaces */ IDirectDraw7_Release(DDraw7); IDirectDraw4_Release(DDraw4); IDirectDraw2_Release(DDraw2); IDirectDraw_Release(DDraw1); IDirect3D7_Release(D3D7); }
static void release_directdraw(void) { IDirectDrawSurface7_Release(pdds7); IDirectDraw7_Release(pdd7); }
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); }