|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // For the Winscw Emulator only, selects between REF, GCE and non-GCE version of EGL. |
|
15 // Notes: |
|
16 // The default is the non-GCE based version. |
|
17 // To use the REF version GCE needs to be enabled. |
|
18 // |
|
19 // To select the GCE version do one of: |
|
20 // 1. Add a line to the epoc.ini file in \epoc32\data like this: |
|
21 // symbian_graphics_use_gce ON |
|
22 // or |
|
23 // 2. Start epoc.exe with these parameters, (the "--" IS necessary): |
|
24 // -Dsymbian_graphics_use_gce=ON -- |
|
25 // or |
|
26 // 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter. |
|
27 // Progress chaining to the real libEGL is logged in epocwind.out. |
|
28 // |
|
29 // To select the REF version do one of the steps above, adding |
|
30 // symbian_graphics_use_egl_ref in addition to symbian_graphics_use_gce. |
|
31 // |
|
32 // |
|
33 |
|
34 |
|
35 #include <emulator.h> |
|
36 #include <e32svr.h> |
|
37 #include <u32hal.h> |
|
38 |
|
39 |
|
40 extern "C" { |
|
41 |
|
42 #include "egl_stubs.h" |
|
43 |
|
44 FARPROC vector[MAX_ORDINAL+1]; // 1 additional entry: vector[0] to set the initialised state |
|
45 |
|
46 |
|
47 void Stop(char* aErrorMessage) |
|
48 { |
|
49 int err = GetLastError(); |
|
50 RDebug::Printf("%S, (last error = %i)", aErrorMessage, err); |
|
51 _asm int 3; |
|
52 } |
|
53 |
|
54 void fill_vector(HINSTANCE aDll) |
|
55 { |
|
56 FARPROC address = NULL; |
|
57 for (int i=1;i<=MAX_ORDINAL;i++) |
|
58 { |
|
59 address = GetProcAddress(aDll, (LPCSTR)i); |
|
60 if (address == NULL) |
|
61 { |
|
62 Stop("... has too few exported functions"); |
|
63 } |
|
64 vector[i] = address; |
|
65 } |
|
66 |
|
67 // There's an additional _E32Dll entry point after last ordinal position. |
|
68 // Read it, but no need to store it |
|
69 address = GetProcAddress(aDll, (LPCSTR)(MAX_ORDINAL+1)); |
|
70 if (address == NULL) |
|
71 { |
|
72 Stop("... has too few exported functions"); |
|
73 } |
|
74 |
|
75 // next position should be empty |
|
76 address = GetProcAddress(aDll, (LPCSTR)(MAX_ORDINAL+2)); |
|
77 if (address != NULL) |
|
78 { |
|
79 Stop("... has too many exported functions"); |
|
80 } |
|
81 |
|
82 // Set initialised |
|
83 vector[0] = (FARPROC)1; |
|
84 } |
|
85 |
|
86 // redirects DLL calls to GCE or non-GCE implementation |
|
87 void init_vector() |
|
88 { |
|
89 // ask HAL which configuration to use |
|
90 TBool gce = EFalse; |
|
91 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty, (TAny*)"symbian_graphics_use_gce", &gce); |
|
92 const char* library = ""; |
|
93 if (gce) |
|
94 { |
|
95 // reference EGL is for NGA only |
|
96 TBool ref = EFalse; |
|
97 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty, (TAny*)"symbian_graphics_use_egl_ref", &ref); |
|
98 library = ref ? "libegl_ref.dll" : "libegl_gce.dll"; |
|
99 } |
|
100 else |
|
101 { |
|
102 library = "libegl_nongce.dll"; |
|
103 } |
|
104 |
|
105 RDebug::Printf("Redirecting libEGL.dll to \"%s\" ...\n", library); |
|
106 |
|
107 Emulator::Escape(); // prevent deadlock between EKA2 scheduler and MS kernel |
|
108 // try to load selected DLL |
|
109 HINSTANCE instance = LoadLibraryA(library); |
|
110 Emulator::Reenter(); |
|
111 |
|
112 if (instance == NULL) |
|
113 { |
|
114 Stop("... unable to load"); |
|
115 } |
|
116 else |
|
117 { |
|
118 fill_vector(instance); |
|
119 RDebug::Printf("... DLL loaded successfully"); |
|
120 } |
|
121 } |
|
122 |
|
123 __declspec(naked) void common_dispatch() |
|
124 { |
|
125 _asm cmp dword ptr vector,0 // initialised? |
|
126 _asm je do_init_vector |
|
127 call_though_vector: |
|
128 _asm jmp [vector+eax*4] |
|
129 |
|
130 do_init_vector: |
|
131 _asm push eax |
|
132 _asm push ecx |
|
133 _asm push edx |
|
134 _asm call init_vector |
|
135 _asm pop edx |
|
136 _asm pop ecx |
|
137 _asm pop eax |
|
138 _asm jmp call_though_vector |
|
139 } |
|
140 |
|
141 } |