os/graphics/graphicsdeviceinterface/bitgdi/bitgdi_switch/bitgdiswitch.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/bitgdi/bitgdi_switch/bitgdiswitch.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,126 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// For the Winscw Emulator only, selects between GCE and non-GCE version of Bit Gdi.
    1.18 +// The default is the non-GCE based version.
    1.19 +// To select the GCE version do one of:
    1.20 +// 1. Add a line to the epoc.ini file in \epoc32\data like this:
    1.21 +// symbian_graphics_use_gce ON
    1.22 +// or
    1.23 +// 2. Start epoc.exe with these parameters, (the "--" IS necessary):
    1.24 +// -Dsymbian_graphics_use_gce=ON --
    1.25 +// or
    1.26 +// 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter.
    1.27 +// Progress chaining to the real Bitgdi is logged in epocwind.out.
    1.28 +// 
    1.29 +//
    1.30 +
    1.31 +
    1.32 +
    1.33 +#include <emulator.h>
    1.34 +
    1.35 +#include <e32svr.h>
    1.36 +#include <u32hal.h>
    1.37 +
    1.38 +
    1.39 +extern "C" {
    1.40 +
    1.41 +#include "bitgdi_stubs.h"
    1.42 +
    1.43 +FARPROC vector[MAX_ORDINAL+1];
    1.44 +
    1.45 +
    1.46 +#ifdef _DEBUG
    1.47 +void Stop(char* aErrorMessage)
    1.48 +#else
    1.49 +void Stop(char* /*aErrorMessage*/)
    1.50 +#endif
    1.51 +	{
    1.52 +	int err = GetLastError();
    1.53 +#ifdef _DEBUG
    1.54 +	RDebug::Printf("%s, (last error = %i)", aErrorMessage, err);
    1.55 +#endif
    1.56 +	_asm int 3;
    1.57 +	}
    1.58 +
    1.59 +void fill_vector(HINSTANCE aDll)
    1.60 +	{
    1.61 +	int i;
    1.62 +	FARPROC address = NULL;
    1.63 +	for (i=1;i<=MAX_ORDINAL;i++)
    1.64 +		{
    1.65 +		address = GetProcAddress(aDll, (LPCSTR)i);
    1.66 +		if (address == NULL)
    1.67 +			{
    1.68 +			Stop("... has too few exported functions");
    1.69 +			}
    1.70 +		vector[i] = address;
    1.71 +		}
    1.72 +
    1.73 +	address = GetProcAddress(aDll, (LPCSTR)i);
    1.74 +	if (address != NULL)
    1.75 +		{
    1.76 +		Stop("... has too many exported functions");
    1.77 +		}
    1.78 +	vector[0] = (FARPROC)1;		// initialised
    1.79 +	}
    1.80 +
    1.81 +// redirects DLL calls to GCE or non-GCE implementation
    1.82 +void init_vector()
    1.83 +	{
    1.84 +	// ask HAL which configuration to use
    1.85 +	TBool gce = EFalse;
    1.86 +	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty,  (TAny*)"symbian_graphics_use_gce",  &gce);
    1.87 +	const char* library = gce ? "bitgdi_gce.dll" : "bitgdi_nongce.dll";
    1.88 +
    1.89 +#ifdef _DEBUG
    1.90 +	RDebug::Printf("Redirecting bitgdi.dll to \"%s\" ...\n", library);
    1.91 +#endif
    1.92 +
    1.93 +	Emulator::Escape();		// prevent deadlock between EKA2 scheduler and MS kernel
    1.94 +	// try to load selected DLL
    1.95 +	HINSTANCE instance = LoadLibraryA(library);
    1.96 +	Emulator::Reenter();
    1.97 +
    1.98 +	if (instance == NULL)
    1.99 +		{
   1.100 +		Stop("... unable to load");
   1.101 +		}
   1.102 +	else
   1.103 +		{
   1.104 +		fill_vector(instance);
   1.105 +#ifdef _DEBUG
   1.106 +		RDebug::Printf("... DLL loaded successfully");
   1.107 +#endif
   1.108 +		}
   1.109 +	}
   1.110 +
   1.111 +__declspec(naked) void common_dispatch()
   1.112 +	{
   1.113 +	_asm cmp	dword ptr vector,0		// initialised?
   1.114 +	_asm je  	do_init_vector
   1.115 +call_though_vector:
   1.116 +	_asm jmp	[vector+eax*4]
   1.117 +
   1.118 +do_init_vector:
   1.119 +	_asm push	eax
   1.120 +	_asm push	ecx
   1.121 +	_asm push	edx
   1.122 +	_asm call	init_vector
   1.123 +	_asm pop	edx
   1.124 +	_asm pop 	ecx
   1.125 +	_asm pop 	eax
   1.126 +	_asm jmp	call_though_vector
   1.127 +	}
   1.128 +
   1.129 +}