| 1 | /* $Id: initterm.cpp,v 1.21 2002-07-29 11:26:49 sandervl Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * GDI32 DLL entry point | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998 Sander van Leeuwen | 
|---|
| 6 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 7 | * | 
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 | #define  INCL_DOSMODULEMGR | 
|---|
| 12 | #define  INCL_DOSPROCESS | 
|---|
| 13 | #define  INCL_GPI | 
|---|
| 14 | #include <os2wrap.h>    //Odin32 OS/2 api wrappers | 
|---|
| 15 | #include <stdlib.h> | 
|---|
| 16 | #include <stdio.h> | 
|---|
| 17 | #include <string.h> | 
|---|
| 18 | #include <odin.h> | 
|---|
| 19 | #include <win32api.h> | 
|---|
| 20 | #include <winconst.h> | 
|---|
| 21 | #include <odinlx.h> | 
|---|
| 22 | #include <cpuhlp.h> | 
|---|
| 23 | #include <dbglog.h> | 
|---|
| 24 | #include <initdll.h> | 
|---|
| 25 | #include <stats.h> | 
|---|
| 26 | #include <exitlist.h> | 
|---|
| 27 |  | 
|---|
| 28 | #include "region.h" | 
|---|
| 29 | #include "dibsect.h" | 
|---|
| 30 | #include "rgbcvt.h" | 
|---|
| 31 |  | 
|---|
| 32 | #define DBG_LOCALLOG    DBG_initterm | 
|---|
| 33 | #include "dbglocal.h" | 
|---|
| 34 |  | 
|---|
| 35 | // Win32 resource table (produced by wrc) | 
|---|
| 36 | extern DWORD gdi32_PEResTab; | 
|---|
| 37 |  | 
|---|
| 38 | static HMODULE dllHandle = 0; | 
|---|
| 39 | void (_Optlink *pRGB555to565)(WORD *dest, WORD *src, ULONG num) = NULL; | 
|---|
| 40 | void (_Optlink *pRGB565to555)(WORD *dest, WORD *src, ULONG num) = NULL; | 
|---|
| 41 |  | 
|---|
| 42 | BOOL WINAPI GdiLibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) | 
|---|
| 43 | { | 
|---|
| 44 | switch (fdwReason) | 
|---|
| 45 | { | 
|---|
| 46 | case DLL_PROCESS_ATTACH: | 
|---|
| 47 | return TRUE; | 
|---|
| 48 |  | 
|---|
| 49 | case DLL_THREAD_ATTACH: | 
|---|
| 50 | case DLL_THREAD_DETACH: | 
|---|
| 51 | return TRUE; | 
|---|
| 52 |  | 
|---|
| 53 | case DLL_PROCESS_DETACH: | 
|---|
| 54 | STATS_DumpStatsGDI32(); | 
|---|
| 55 | return TRUE; | 
|---|
| 56 | } | 
|---|
| 57 | return FALSE; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | ULONG SYSTEM DLL_InitGdi32(ULONG hModule) | 
|---|
| 61 | { | 
|---|
| 62 | STATS_InitializeGDI32 (); | 
|---|
| 63 |  | 
|---|
| 64 | ParseLogStatusGDI32(); | 
|---|
| 65 |  | 
|---|
| 66 | if (!InitializeKernel32()) | 
|---|
| 67 | return -1; | 
|---|
| 68 |  | 
|---|
| 69 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/ | 
|---|
| 70 | if (InitRegionSpace() == FALSE) | 
|---|
| 71 | return -1; | 
|---|
| 72 |  | 
|---|
| 73 | DIBSection::initDIBSection(); | 
|---|
| 74 | if (CPUFeatures & CPUID_MMX) | 
|---|
| 75 | { | 
|---|
| 76 | pRGB555to565 = RGB555to565MMX; | 
|---|
| 77 | pRGB565to555 = RGB565to555MMX; | 
|---|
| 78 | } | 
|---|
| 79 | else | 
|---|
| 80 | { | 
|---|
| 81 | pRGB555to565 = RGB555to565; | 
|---|
| 82 | pRGB565to555 = RGB565to555; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | dllHandle = RegisterLxDll(hModule, GdiLibMain, (PVOID)&gdi32_PEResTab, | 
|---|
| 86 | GDI32_MAJORIMAGE_VERSION, GDI32_MINORIMAGE_VERSION, | 
|---|
| 87 | IMAGE_SUBSYSTEM_NATIVE); | 
|---|
| 88 | if (dllHandle == 0) | 
|---|
| 89 | return -1; | 
|---|
| 90 |  | 
|---|
| 91 | dprintf(("gdi32 init %s %s (%x)", __DATE__, __TIME__, DLL_InitGdi32)); | 
|---|
| 92 |  | 
|---|
| 93 | RasEntry (RAS_EVENT_Gdi32InitComplete, &dllHandle, sizeof (dllHandle)); | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | return EXITLIST_GDI32; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | void SYSTEM DLL_TermGdi32(ULONG hModule) | 
|---|
| 100 | { | 
|---|
| 101 | dprintf(("gdi32 exit")); | 
|---|
| 102 |  | 
|---|
| 103 | if (dllHandle) | 
|---|
| 104 | { | 
|---|
| 105 | DestroyRegionSpace(); | 
|---|
| 106 | UnregisterLxDll(dllHandle); | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | STATS_UninitializeGDI32(); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | ULONG SYSTEM DLL_Init(ULONG hModule) | 
|---|
| 113 | { | 
|---|
| 114 | if (DLL_InitDefault(hModule) == -1) | 
|---|
| 115 | return -1; | 
|---|
| 116 | return DLL_InitGdi32(hModule); | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | void SYSTEM DLL_Term(ULONG hModule) | 
|---|
| 120 | { | 
|---|
| 121 | DLL_TermGdi32(hModule); | 
|---|
| 122 | DLL_TermDefault(hModule); | 
|---|
| 123 | } | 
|---|