os/graphics/graphicsdeviceinterface/bitgdi/bitgdi_switch/bitgdiswitch.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// For the Winscw Emulator only, selects between GCE and non-GCE version of Bit Gdi.
sl@0
    15
// The default is the non-GCE based version.
sl@0
    16
// To select the GCE version do one of:
sl@0
    17
// 1. Add a line to the epoc.ini file in \epoc32\data like this:
sl@0
    18
// symbian_graphics_use_gce ON
sl@0
    19
// or
sl@0
    20
// 2. Start epoc.exe with these parameters, (the "--" IS necessary):
sl@0
    21
// -Dsymbian_graphics_use_gce=ON --
sl@0
    22
// or
sl@0
    23
// 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter.
sl@0
    24
// Progress chaining to the real Bitgdi is logged in epocwind.out.
sl@0
    25
// 
sl@0
    26
//
sl@0
    27
sl@0
    28
sl@0
    29
sl@0
    30
#include <emulator.h>
sl@0
    31
sl@0
    32
#include <e32svr.h>
sl@0
    33
#include <u32hal.h>
sl@0
    34
sl@0
    35
sl@0
    36
extern "C" {
sl@0
    37
sl@0
    38
#include "bitgdi_stubs.h"
sl@0
    39
sl@0
    40
FARPROC vector[MAX_ORDINAL+1];
sl@0
    41
sl@0
    42
sl@0
    43
#ifdef _DEBUG
sl@0
    44
void Stop(char* aErrorMessage)
sl@0
    45
#else
sl@0
    46
void Stop(char* /*aErrorMessage*/)
sl@0
    47
#endif
sl@0
    48
	{
sl@0
    49
	int err = GetLastError();
sl@0
    50
#ifdef _DEBUG
sl@0
    51
	RDebug::Printf("%s, (last error = %i)", aErrorMessage, err);
sl@0
    52
#endif
sl@0
    53
	_asm int 3;
sl@0
    54
	}
sl@0
    55
sl@0
    56
void fill_vector(HINSTANCE aDll)
sl@0
    57
	{
sl@0
    58
	int i;
sl@0
    59
	FARPROC address = NULL;
sl@0
    60
	for (i=1;i<=MAX_ORDINAL;i++)
sl@0
    61
		{
sl@0
    62
		address = GetProcAddress(aDll, (LPCSTR)i);
sl@0
    63
		if (address == NULL)
sl@0
    64
			{
sl@0
    65
			Stop("... has too few exported functions");
sl@0
    66
			}
sl@0
    67
		vector[i] = address;
sl@0
    68
		}
sl@0
    69
sl@0
    70
	address = GetProcAddress(aDll, (LPCSTR)i);
sl@0
    71
	if (address != NULL)
sl@0
    72
		{
sl@0
    73
		Stop("... has too many exported functions");
sl@0
    74
		}
sl@0
    75
	vector[0] = (FARPROC)1;		// initialised
sl@0
    76
	}
sl@0
    77
sl@0
    78
// redirects DLL calls to GCE or non-GCE implementation
sl@0
    79
void init_vector()
sl@0
    80
	{
sl@0
    81
	// ask HAL which configuration to use
sl@0
    82
	TBool gce = EFalse;
sl@0
    83
	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty,  (TAny*)"symbian_graphics_use_gce",  &gce);
sl@0
    84
	const char* library = gce ? "bitgdi_gce.dll" : "bitgdi_nongce.dll";
sl@0
    85
sl@0
    86
#ifdef _DEBUG
sl@0
    87
	RDebug::Printf("Redirecting bitgdi.dll to \"%s\" ...\n", library);
sl@0
    88
#endif
sl@0
    89
sl@0
    90
	Emulator::Escape();		// prevent deadlock between EKA2 scheduler and MS kernel
sl@0
    91
	// try to load selected DLL
sl@0
    92
	HINSTANCE instance = LoadLibraryA(library);
sl@0
    93
	Emulator::Reenter();
sl@0
    94
sl@0
    95
	if (instance == NULL)
sl@0
    96
		{
sl@0
    97
		Stop("... unable to load");
sl@0
    98
		}
sl@0
    99
	else
sl@0
   100
		{
sl@0
   101
		fill_vector(instance);
sl@0
   102
#ifdef _DEBUG
sl@0
   103
		RDebug::Printf("... DLL loaded successfully");
sl@0
   104
#endif
sl@0
   105
		}
sl@0
   106
	}
sl@0
   107
sl@0
   108
__declspec(naked) void common_dispatch()
sl@0
   109
	{
sl@0
   110
	_asm cmp	dword ptr vector,0		// initialised?
sl@0
   111
	_asm je  	do_init_vector
sl@0
   112
call_though_vector:
sl@0
   113
	_asm jmp	[vector+eax*4]
sl@0
   114
sl@0
   115
do_init_vector:
sl@0
   116
	_asm push	eax
sl@0
   117
	_asm push	ecx
sl@0
   118
	_asm push	edx
sl@0
   119
	_asm call	init_vector
sl@0
   120
	_asm pop	edx
sl@0
   121
	_asm pop 	ecx
sl@0
   122
	_asm pop 	eax
sl@0
   123
	_asm jmp	call_though_vector
sl@0
   124
	}
sl@0
   125
sl@0
   126
}