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 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); }