ddraw: Palette refcounting fixes + tests.

This commit is contained in:
Stefan Dösinger 2006-06-17 15:47:52 +02:00 committed by Alexandre Julliard
parent e4b51580e1
commit 01273e7eb6
6 changed files with 174 additions and 3 deletions

View File

@ -2950,13 +2950,29 @@ IDirectDrawImpl_CreatePalette(IDirectDraw7 *iface,
HRESULT hr = DDERR_GENERIC;
TRACE("(%p)->(%lx,%p,%p,%p)\n", This, Flags, ColorTable, Palette, pUnkOuter);
if(pUnkOuter != NULL) return CLASS_E_NOAGGREGATION; /* unchecked */
if(pUnkOuter != NULL)
{
WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter);
return CLASS_E_NOAGGREGATION;
}
/* The refcount test shows that a cooplevel is required for this */
if(!This->cooperative_level)
{
WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
return DDERR_NOCOOPERATIVELEVELSET;
}
object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl));
if(!object) return E_OUTOFMEMORY;
if(!object)
{
ERR("Out of memory when allocating memory for a palette implementation\n");
return E_OUTOFMEMORY;
}
ICOM_INIT_INTERFACE(object, IDirectDrawPalette, IDirectDrawPalette_Vtbl);
object->ref = 1;
object->ddraw_owner = This;
hr = IWineD3DDevice_CreatePalette(This->wineD3DDevice, Flags, ColorTable, &object->wineD3DPalette, (IUnknown *) ICOM_INTERFACE(object, IDirectDrawPalette) );
if(hr != DD_OK)
@ -2965,6 +2981,7 @@ IDirectDrawImpl_CreatePalette(IDirectDraw7 *iface,
return hr;
}
IDirectDraw7_AddRef(iface);
*Palette = ICOM_INTERFACE(object, IDirectDrawPalette);
return DD_OK;
}

View File

@ -104,6 +104,7 @@ IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
if (ref == 0)
{
IWineD3DPalette_Release(This->wineD3DPalette);
IDirectDraw7_Release(ICOM_INTERFACE(This->ddraw_owner, IDirectDraw7));
HeapFree(GetProcessHeap(), 0, This);
}

View File

@ -360,6 +360,10 @@ IDirectDrawSurfaceImpl_Release(IDirectDrawSurface7 *iface)
}
}
/* The refcount test shows that the palette is detached when the surface is destroyed */
IDirectDrawSurface7_SetPalette(ICOM_INTERFACE(This, IDirectDrawSurface7),
NULL);
/* Loop through all complex attached surfaces,
* and destroy them
*/

View File

@ -2,4 +2,5 @@ Makefile
d3d.ok
ddrawmodes.ok
dsurface.ok
refcount.ok
testlist.c

View File

@ -9,7 +9,8 @@ EXTRALIBS = -ldxguid
CTESTS = \
d3d.c \
ddrawmodes.c \
dsurface.c
dsurface.c \
refcount.c
@MAKE_TEST_RULES@

147
dlls/ddraw/tests/refcount.c Normal file
View File

@ -0,0 +1,147 @@
/*
* Some unit tests for ddraw reference counting
*
* Copyright (C) 2006 Stefan Dösinger
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include <assert.h>
#include "wine/test.h"
#include "ddraw.h"
#include "d3d.h"
#include "unknwn.h"
static HRESULT (WINAPI *pDirectDrawCreateEx)(LPGUID,LPVOID*,REFIID,LPUNKNOWN);
static void init_function_pointers(void)
{
HMODULE hmod = GetModuleHandleA("ddraw.dll");
if(hmod)
{
pDirectDrawCreateEx = (void*)GetProcAddress(hmod, "DirectDrawCreateEx");
}
}
unsigned long getRefcount(IUnknown *iface)
{
IUnknown_AddRef(iface);
return IUnknown_Release(iface);
}
static void test_ddraw(void)
{
HRESULT hr;
unsigned long ref;
IDirectDraw7 *DDraw;
IDirectDrawPalette *palette;
IDirectDrawSurface7 *surface;
PALETTEENTRY Table[256];
DDSURFACEDESC2 ddsd;
hr = pDirectDrawCreateEx(NULL, (void **) &DDraw, &IID_IDirectDraw7, NULL);
ok(hr == DD_OK || hr==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %lx\n", hr);
if(!DDraw)
{
trace("Couldn't create DDraw interface, skipping tests\n");
return;
}
ref = getRefcount( (IUnknown *) DDraw);
ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
/* Fails without a cooplevel */
hr = IDirectDraw7_CreatePalette(DDraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
ok(hr == DDERR_NOCOOPERATIVELEVELSET, "CreatePalette returned %08lx\n", hr);
/* This check is before the cooplevel check */
hr = IDirectDraw7_CreatePalette(DDraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, (void *) 0xdeadbeef);
ok(hr == CLASS_E_NOAGGREGATION, "CreatePalette returned %08lx\n", hr);
hr = IDirectDraw7_SetCooperativeLevel(DDraw, 0, DDSCL_NORMAL);
ok(hr == DD_OK, "SetCooperativeLevel failed with %08lx\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;
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
ddsd.ddpfPixelFormat.dwRGBBitCount = 8;
hr = IDirectDraw7_CreateSurface(DDraw, &ddsd, &surface, NULL);
ok(hr == DD_OK, "CreateSurface failed with %08lx\n", hr);
/* DDraw refcount increased by 1 */
ref = getRefcount( (IUnknown *) DDraw);
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(DDraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
ok(hr == DD_OK, "CreatePalette returned %08lx\n", hr);
/* DDraw refcount increased by 1 */
ref = getRefcount( (IUnknown *) DDraw);
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 %08lx\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);
/* Incresed before - decrease now */
ref = getRefcount( (IUnknown *) DDraw);
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);
/* Incresed before - decrease now */
ref = getRefcount( (IUnknown *) DDraw);
ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
IDirectDraw7_Release(DDraw);
}
START_TEST(refcount)
{
init_function_pointers();
if(!pDirectDrawCreateEx)
{
trace("function DirectDrawCreateEx not available, skipping tests\n");
return;
}
test_ddraw();
}