1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/egl/eglswitch/src/eglswitch.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,150 @@
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 REF, GCE and non-GCE version of EGL.
1.18 +// Notes:
1.19 +// The default is the non-GCE based version.
1.20 +// To use the REF version GCE needs to be enabled.
1.21 +//
1.22 +// To select the GCE version do one of:
1.23 +// 1. Add a line to the epoc.ini file in \epoc32\data like this:
1.24 +// symbian_graphics_use_gce ON
1.25 +// or
1.26 +// 2. Start epoc.exe with these parameters, (the "--" IS necessary):
1.27 +// -Dsymbian_graphics_use_gce=ON --
1.28 +// or
1.29 +// 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter.
1.30 +// Progress chaining to the real libEGL is logged in epocwind.out.
1.31 +//
1.32 +// To select the REF version do one of the steps above, adding
1.33 +// symbian_graphics_use_egl_ref in addition to symbian_graphics_use_gce.
1.34 +//
1.35 +//
1.36 +
1.37 +
1.38 +#include <emulator.h>
1.39 +#include <e32svr.h>
1.40 +#include <u32hal.h>
1.41 +
1.42 +
1.43 +extern "C" {
1.44 +
1.45 +#include "egl_stubs.h"
1.46 +
1.47 +FARPROC vector[MAX_ORDINAL+1]; // 1 additional entry: vector[0] to set the initialised state
1.48 +
1.49 +
1.50 +#ifdef _DEBUG
1.51 +void Stop(char* aErrorMessage)
1.52 +#else
1.53 +void Stop(char* /*aErrorMessage*/)
1.54 +#endif
1.55 + {
1.56 + int err = GetLastError();
1.57 +#ifdef _DEBUG
1.58 + RDebug::Printf("%S, (last error = %i)", aErrorMessage, err);
1.59 +#endif
1.60 + _asm int 3;
1.61 + }
1.62 +
1.63 +void fill_vector(HINSTANCE aDll)
1.64 + {
1.65 + FARPROC address = NULL;
1.66 + for (int i=1;i<=MAX_ORDINAL;i++)
1.67 + {
1.68 + address = GetProcAddress(aDll, (LPCSTR)i);
1.69 + if (address == NULL)
1.70 + {
1.71 + Stop("... has too few exported functions");
1.72 + }
1.73 + vector[i] = address;
1.74 + }
1.75 +
1.76 + // There's an additional _E32Dll entry point after last ordinal position.
1.77 + // Read it, but no need to store it
1.78 + address = GetProcAddress(aDll, (LPCSTR)(MAX_ORDINAL+1));
1.79 + if (address == NULL)
1.80 + {
1.81 + Stop("... has too few exported functions");
1.82 + }
1.83 +
1.84 + // next position should be empty
1.85 + address = GetProcAddress(aDll, (LPCSTR)(MAX_ORDINAL+2));
1.86 + if (address != NULL)
1.87 + {
1.88 + Stop("... has too many exported functions");
1.89 + }
1.90 + // Set initialised
1.91 + vector[0] = (FARPROC)1;
1.92 + }
1.93 +
1.94 +// redirects DLL calls to GCE or non-GCE implementation
1.95 +void init_vector()
1.96 + {
1.97 + // ask HAL which configuration to use
1.98 + TBool gce = EFalse;
1.99 + UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty, (TAny*)"symbian_graphics_use_gce", &gce);
1.100 + const char* library = "";
1.101 + if (gce)
1.102 + {
1.103 + // reference EGL is for NGA only
1.104 + TBool ref = EFalse;
1.105 + UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty, (TAny*)"symbian_graphics_use_egl_ref", &ref);
1.106 + library = ref ? "libegl_ref.dll" : "libegl_gce.dll";
1.107 + }
1.108 + else
1.109 + {
1.110 + library = "libegl_nongce.dll";
1.111 + }
1.112 +
1.113 +#ifdef _DEBUG
1.114 + RDebug::Printf("Redirecting libEGL.dll to \"%s\" ...\n", library);
1.115 +#endif
1.116 +
1.117 + Emulator::Escape(); // prevent deadlock between EKA2 scheduler and MS kernel
1.118 + // try to load selected DLL
1.119 + HINSTANCE instance = LoadLibraryA(library);
1.120 + Emulator::Reenter();
1.121 +
1.122 + if (instance == NULL)
1.123 + {
1.124 + Stop("... unable to load");
1.125 + }
1.126 + else
1.127 + {
1.128 + fill_vector(instance);
1.129 +#ifdef _DEBUG
1.130 + RDebug::Printf("... DLL loaded successfully");
1.131 +#endif
1.132 + }
1.133 + }
1.134 +
1.135 +__declspec(naked) void common_dispatch()
1.136 + {
1.137 + _asm cmp dword ptr vector,0 // initialised?
1.138 + _asm je do_init_vector
1.139 +call_though_vector:
1.140 + _asm jmp [vector+eax*4]
1.141 +
1.142 +do_init_vector:
1.143 + _asm push eax
1.144 + _asm push ecx
1.145 + _asm push edx
1.146 + _asm call init_vector
1.147 + _asm pop edx
1.148 + _asm pop ecx
1.149 + _asm pop eax
1.150 + _asm jmp call_though_vector
1.151 + }
1.152 +
1.153 +}