graphicsdeviceinterface/bitgdi/bitgdi_switch/bitgdiswitch.cpp
author Faisal Memon <faisal.memon@nokia.com>
Fri, 14 May 2010 15:41:33 +0100
branchNewGraphicsArchitecture
changeset 64 5c983aa672ea
parent 18 5e30ef2e26cb
permissions -rw-r--r--
Merge 1. Pull in cpp files in the performance enhanced Khronos RI OVG files which are newly added. I've ignored platform-specific cpp files for linux, macosx, and null operating systems because this local solution has its own platform glue (i.e. facility to target Bitmaps but no full windowing support). I've ignored sfEGLInterface.cpp because this is used as a bridge to go from EGL to Nokia's Platsim which offers an EGL service. That's not relevant to this implementation because this is ARM side code, not Intel side. I just left a comment to sfEGLInterface.cpp in case we need to pick up this later on. The current code compiles on winscw. Prior to this fix, the code works on winscw, and can launch the SVG tiger (tiger.exe). That takes about 20 seconds to render. I hope to always be able to show this icon on each commit, and the plan is for the render time to reduce with this series of submissions. On this commit, the tiger renders ok in 20 seconds.

// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// For the Winscw Emulator only, selects between GCE and non-GCE version of Bit Gdi.
// The default is the non-GCE based version.
// To select the GCE version do one of:
// 1. Add a line to the epoc.ini file in \epoc32\data like this:
// symbian_graphics_use_gce ON
// or
// 2. Start epoc.exe with these parameters, (the "--" IS necessary):
// -Dsymbian_graphics_use_gce=ON --
// or
// 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter.
// Progress chaining to the real Bitgdi is logged in epocwind.out.
// 
//



#include <emulator.h>

#include <e32svr.h>
#include <u32hal.h>


extern "C" {

#include "bitgdi_stubs.h"

FARPROC vector[MAX_ORDINAL+1];


#ifdef _DEBUG
void Stop(char* aErrorMessage)
#else
void Stop(char* /*aErrorMessage*/)
#endif
	{
	int err = GetLastError();
#ifdef _DEBUG
	RDebug::Printf("%s, (last error = %i)", aErrorMessage, err);
#endif
	_asm int 3;
	}

void fill_vector(HINSTANCE aDll)
	{
	int i;
	FARPROC address = NULL;
	for (i=1;i<=MAX_ORDINAL;i++)
		{
		address = GetProcAddress(aDll, (LPCSTR)i);
		if (address == NULL)
			{
			Stop("... has too few exported functions");
			}
		vector[i] = address;
		}

	address = GetProcAddress(aDll, (LPCSTR)i);
	if (address != NULL)
		{
		Stop("... has too many exported functions");
		}
	vector[0] = (FARPROC)1;		// initialised
	}

// redirects DLL calls to GCE or non-GCE implementation
void init_vector()
	{
	// ask HAL which configuration to use
	TBool gce = EFalse;
	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty,  (TAny*)"symbian_graphics_use_gce",  &gce);
	const char* library = gce ? "bitgdi_gce.dll" : "bitgdi_nongce.dll";

#ifdef _DEBUG
	RDebug::Printf("Redirecting bitgdi.dll to \"%s\" ...\n", library);
#endif

	Emulator::Escape();		// prevent deadlock between EKA2 scheduler and MS kernel
	// try to load selected DLL
	HINSTANCE instance = LoadLibraryA(library);
	Emulator::Reenter();

	if (instance == NULL)
		{
		Stop("... unable to load");
		}
	else
		{
		fill_vector(instance);
#ifdef _DEBUG
		RDebug::Printf("... DLL loaded successfully");
#endif
		}
	}

__declspec(naked) void common_dispatch()
	{
	_asm cmp	dword ptr vector,0		// initialised?
	_asm je  	do_init_vector
call_though_vector:
	_asm jmp	[vector+eax*4]

do_init_vector:
	_asm push	eax
	_asm push	ecx
	_asm push	edx
	_asm call	init_vector
	_asm pop	edx
	_asm pop 	ecx
	_asm pop 	eax
	_asm jmp	call_though_vector
	}

}