Release 970202
[wine/multimedia.git] / graphics / driver.c
blobe26b2c30b1717df3365e01fa57b81a910d6a1f4a
1 /*
2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include "gdi.h"
9 #include "heap.h"
11 typedef struct tagGRAPHICS_DRIVER
13 struct tagGRAPHICS_DRIVER *next;
14 LPSTR name;
15 const DC_FUNCTIONS *funcs;
16 } GRAPHICS_DRIVER;
18 static GRAPHICS_DRIVER *firstDriver = NULL;
19 static GRAPHICS_DRIVER *genericDriver = NULL;
21 /**********************************************************************
22 * DRIVER_RegisterDriver
24 BOOL32 DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs )
26 GRAPHICS_DRIVER *driver = HeapAlloc( SystemHeap, 0, sizeof(*driver) );
27 if (!driver) return FALSE;
28 driver->funcs = funcs;
29 if (name)
31 driver->name = HEAP_strdupA( SystemHeap, 0, name );
32 driver->next = firstDriver;
33 firstDriver = driver;
34 return TRUE;
36 /* No name -> it's the generic driver */
37 if (genericDriver)
39 fprintf( stderr, "DRIVER_RegisterDriver: already a generic driver\n" );
40 HeapFree( SystemHeap, 0, driver );
41 return FALSE;
43 driver->name = NULL;
44 genericDriver = driver;
45 return TRUE;
49 /**********************************************************************
50 * DRIVER_FindDriver
52 const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name )
54 GRAPHICS_DRIVER *driver = firstDriver;
55 while (driver)
57 if (!lstrcmpi32A( driver->name, name )) return driver->funcs;
58 driver = driver->next;
60 return genericDriver ? genericDriver->funcs : NULL;
64 /**********************************************************************
65 * DRIVER_UnregisterDriver
67 BOOL32 DRIVER_UnregisterDriver( LPCSTR name )
69 if (name)
71 GRAPHICS_DRIVER **ppDriver = &firstDriver;
72 while (*ppDriver)
74 if (!lstrcmpi32A( (*ppDriver)->name, name ))
76 GRAPHICS_DRIVER *driver = *ppDriver;
77 (*ppDriver) = driver->next;
78 HeapFree( SystemHeap, 0, driver->name );
79 HeapFree( SystemHeap, 0, driver );
80 return TRUE;
82 ppDriver = &(*ppDriver)->next;
84 return FALSE;
86 else
88 if (!genericDriver) return FALSE;
89 HeapFree( SystemHeap, 0, genericDriver );
90 genericDriver = NULL;
91 return TRUE;