Commit e33bdb87 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

gdi32: Use NtGdiCreateClientObj for enhmetafile objects.

parent 3d8a8fc1
...@@ -41,13 +41,23 @@ ...@@ -41,13 +41,23 @@
#include "winnls.h" #include "winnls.h"
#include "winerror.h" #include "winerror.h"
#include "ntgdi_private.h" #include "ntgdi_private.h"
#include "gdi_private.h"
#include "wine/debug.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile); WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
static CRITICAL_SECTION enhmetafile_cs;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &enhmetafile_cs,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": enhmetafile_cs") }
};
static CRITICAL_SECTION enhmetafile_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
typedef struct typedef struct
{ {
struct gdi_obj_header obj;
ENHMETAHEADER *emh; ENHMETAHEADER *emh;
BOOL on_disk; /* true if metafile is on disk */ BOOL on_disk; /* true if metafile is on disk */
} ENHMETAFILEOBJ; } ENHMETAFILEOBJ;
...@@ -277,7 +287,9 @@ HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, DWORD filesize, BOOL on ...@@ -277,7 +287,9 @@ HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, DWORD filesize, BOOL on
metaObj->emh = emh; metaObj->emh = emh;
metaObj->on_disk = on_disk; metaObj->on_disk = on_disk;
if (!(hmf = alloc_gdi_handle( &metaObj->obj, NTGDI_OBJ_ENHMETAFILE, NULL ))) if ((hmf = NtGdiCreateClientObj( NTGDI_OBJ_ENHMETAFILE )))
set_gdi_client_ptr( hmf, metaObj );
else
HeapFree( GetProcessHeap(), 0, metaObj ); HeapFree( GetProcessHeap(), 0, metaObj );
return hmf; return hmf;
} }
...@@ -287,15 +299,23 @@ HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, DWORD filesize, BOOL on ...@@ -287,15 +299,23 @@ HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, DWORD filesize, BOOL on
*/ */
static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf ) static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
{ {
ENHMETAFILEOBJ *metaObj = free_gdi_handle( hmf ); ENHMETAFILEOBJ *metafile;
if(!metaObj) return FALSE; EnterCriticalSection( &enhmetafile_cs );
if (!(metafile = get_gdi_client_ptr( hmf, NTGDI_OBJ_ENHMETAFILE )) ||
!NtGdiDeleteClientObj( hmf ))
{
LeaveCriticalSection( &enhmetafile_cs );
SetLastError( ERROR_INVALID_HANDLE );
return FALSE;
}
if(metaObj->on_disk) if (metafile->on_disk)
UnmapViewOfFile( metaObj->emh ); UnmapViewOfFile( metafile->emh );
else else
HeapFree( GetProcessHeap(), 0, metaObj->emh ); HeapFree( GetProcessHeap(), 0, metafile->emh );
HeapFree( GetProcessHeap(), 0, metaObj ); HeapFree( GetProcessHeap(), 0, metafile );
LeaveCriticalSection( &enhmetafile_cs );
return TRUE; return TRUE;
} }
...@@ -307,13 +327,16 @@ static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf ) ...@@ -307,13 +327,16 @@ static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf ) static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
{ {
ENHMETAHEADER *ret = NULL; ENHMETAHEADER *ret = NULL;
ENHMETAFILEOBJ *metaObj = GDI_GetObjPtr( hmf, NTGDI_OBJ_ENHMETAFILE ); ENHMETAFILEOBJ *metafile;
TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
if (metaObj) EnterCriticalSection( &enhmetafile_cs );
if ((metafile = get_gdi_client_ptr( hmf, NTGDI_OBJ_ENHMETAFILE )))
{ {
ret = metaObj->emh; TRACE( "hmf %p -> enhmetafile %p\n", hmf, metafile );
GDI_ReleaseObj( hmf ); ret = metafile->emh;
} }
else SetLastError( ERROR_INVALID_HANDLE );
LeaveCriticalSection( &enhmetafile_cs );
return ret; return ret;
} }
......
...@@ -3137,6 +3137,16 @@ static void test_enhmetafile_file(void) ...@@ -3137,6 +3137,16 @@ static void test_enhmetafile_file(void)
ret = DeleteFileA(mf_name); ret = DeleteFileA(mf_name);
ok(ret, "Could not delete file: %u\n", GetLastError()); ok(ret, "Could not delete file: %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = DeleteEnhMetaFile(ULongToHandle(0xdeadbeef));
ok(!ret, "DeleteEnhMetaFile succeeded\n");
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() = %u\n", GetLastError());
SetLastError(0xdeadbeef);
size = GetEnhMetaFileBits(ULongToHandle(0xdeadbeef), 0, NULL);
ok(!size, "GetEnhMetaFileBitsEx returned %u\n", size);
ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() = %u\n", GetLastError());
} }
static void test_CopyMetaFile(void) static void test_CopyMetaFile(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment