os/graphics/graphicsaccelaration/vgi/src/vgi.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsaccelaration/vgi/src/vgi.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,216 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +#include "vg_vgibridge.h"
    1.21 +#include <stdlib.h>
    1.22 +#include <string.h>
    1.23 +#include <VG/openvg.h>
    1.24 +
    1.25 +#define VGI_API_CALL __declspec(dllexport)
    1.26 +
    1.27 +#define VGI_GET_BRIDGE      VGIBridge *bridge = vgiGetBridge(); if(!bridge) return; 
    1.28 +#define VGI_GET_BRIDGE_RET  VGIBridge *bridge = vgiGetBridge(); if(!bridge) return 0; 
    1.29 +
    1.30 +
    1.31 +#if defined __SYMBIAN32__
    1.32 +
    1.33 +static void vgiSetCurrentBridge( VGIBridge* bridge )
    1.34 +{
    1.35 +    Dll::SetTls( bridge );
    1.36 +}
    1.37 +
    1.38 +static VGIBridge* vgiGetCurrentBridge()
    1.39 +{
    1.40 +    return (VGIBridge*)Dll::Tls();
    1.41 +}
    1.42 +
    1.43 +#elif defined WIN32
    1.44 +
    1.45 +#include <windows.h>
    1.46 +
    1.47 +VGIBridge *currBridge = NULL;
    1.48 +
    1.49 +static void vgiSetCurrentBridge( VGIBridge* bridge )
    1.50 +{
    1.51 +    currBridge = bridge;
    1.52 +}
    1.53 +
    1.54 +static VGIBridge* vgiGetCurrentBridge()
    1.55 +{
    1.56 +    return currBridge;
    1.57 +}
    1.58 +
    1.59 +#endif
    1.60 +
    1.61 +static VGIBridge* vgiGetBridge()
    1.62 +{
    1.63 +    VGIBridge *bridge = vgiGetCurrentBridge();
    1.64 +    if( !bridge )
    1.65 +    {
    1.66 +        VGIBridgeFunc vgiVGIBridge = NULL;
    1.67 +
    1.68 +        bridge = (VGIBridge *)malloc( sizeof(VGIBridge) );
    1.69 +        if( !bridge )
    1.70 +            return NULL;
    1.71 +
    1.72 +        memset( bridge, 0, sizeof(VGIBridge) );
    1.73 +
    1.74 +#if defined __SYMBIAN32__
    1.75 +        {
    1.76 +            RLibrary lib;
    1.77 +#ifdef OPENVG_VERSION_1_1
    1.78 +            if( lib.Load( _L("libOpenVG_SW.dll") ) == KErrNone )
    1.79 +                vgiVGIBridge = (VGIBridgeFunc)lib.Lookup( 89 ); // <- 89 is a hardcoded ordinal, refer to libopenvgu.def in bwins and eabi folders
    1.80 +#else // OPENVG_VERSION_1_0 and OPENVG_VERSION_1_0_1
    1.81 +			if( lib.Load( _L("libOpenVG.dll") ) == KErrNone )
    1.82 +                vgiVGIBridge = (VGIBridgeFunc)lib.Lookup( 1 ); // <- 1 is a hardcoded ordinal, refer to libopenvgu.def in bwins and eabi folders
    1.83 +#endif
    1.84 +            bridge->libHandle = lib;
    1.85 +        }
    1.86 +#elif defined WIN32
    1.87 +        {
    1.88 +            HMODULE hModule = LoadLibrary( "libOpenVG.dll" );
    1.89 +            if( hModule )
    1.90 +                vgiVGIBridge = (VGIBridgeFunc)GetProcAddress( hModule, "vgiVGIBridge" );
    1.91 +        }
    1.92 +#endif
    1.93 +
    1.94 +        if( !vgiVGIBridge )
    1.95 +        {
    1.96 +            free( bridge );
    1.97 +            return NULL;
    1.98 +        }
    1.99 +
   1.100 +        vgiVGIBridge( bridge );
   1.101 +        vgiSetCurrentBridge( bridge );
   1.102 +    }
   1.103 +
   1.104 +    return bridge;
   1.105 +}
   1.106 +
   1.107 +VGI_API_CALL int VGIInitialize( int width, int height, VGIColorSpace colorSpace )
   1.108 +{
   1.109 +    VGI_GET_BRIDGE_RET;
   1.110 +
   1.111 +    return bridge->VGIInitialize( width, height, colorSpace );
   1.112 +}
   1.113 +
   1.114 +VGI_API_CALL int VGIInitializeEx( int width, int height, VGIColorSpace colorSpace, int premultiplied, int conformant )
   1.115 +{
   1.116 +    VGI_GET_BRIDGE_RET;
   1.117 +
   1.118 +    return bridge->VGIInitializeEx( width, height, colorSpace, premultiplied, conformant );
   1.119 +}
   1.120 +
   1.121 +VGI_API_CALL int VGICopyToTarget( VGIColorBufferFormat format, int bufferStride, void *buffer, int maskStride, void *mask, VGICopyToTargetHint hint )
   1.122 +{
   1.123 +    VGI_GET_BRIDGE_RET;
   1.124 +
   1.125 +    return bridge->VGICopyToTarget( format, bufferStride, buffer, maskStride, mask, hint );
   1.126 +}
   1.127 +
   1.128 +VGI_API_CALL void VGITerminate( void )
   1.129 +{
   1.130 +    VGI_GET_BRIDGE;
   1.131 +
   1.132 +    bridge->VGITerminate();
   1.133 +
   1.134 +#if defined __SYMBIAN32__
   1.135 +    bridge->libHandle.Close();
   1.136 +#endif
   1.137 +    
   1.138 +    free( bridge );
   1.139 +    vgiSetCurrentBridge( NULL );
   1.140 +}
   1.141 +
   1.142 +VGI_API_CALL int VGIResize( int width, int height )
   1.143 +{
   1.144 +    VGI_GET_BRIDGE_RET;
   1.145 +
   1.146 +    return bridge->VGIResize( width, height );
   1.147 +}
   1.148 +
   1.149 +VGI_API_CALL int VGIBindToImage( VGImage image )
   1.150 +{
   1.151 +    VGI_GET_BRIDGE_RET;
   1.152 +
   1.153 +    return bridge->VGIBindToImage( image );
   1.154 +}
   1.155 +
   1.156 +VGI_API_CALL int VGIUnBindImage( void )
   1.157 +{
   1.158 +    VGI_GET_BRIDGE_RET;
   1.159 +
   1.160 +    return bridge->VGIUnBindImage();
   1.161 +}
   1.162 +
   1.163 +#ifdef __SYMBIAN32__
   1.164 +
   1.165 +EXPORT_C TInt VGISymbianInitialize( TSize aSize, VGIColorSpace aColorSpace )
   1.166 +{
   1.167 +    VGI_GET_BRIDGE_RET;
   1.168 +
   1.169 +    return bridge->VGISymbianInitialize( aSize, aColorSpace );
   1.170 +}
   1.171 +
   1.172 +EXPORT_C TInt VGISymbianInitializeEx( TSize aSize, VGIColorSpace aColorSpace, TBool aPremultiplied, TBool aConformant )
   1.173 +{
   1.174 +    VGI_GET_BRIDGE_RET;
   1.175 +
   1.176 +    return bridge->VGISymbianInitializeEx( aSize, aColorSpace, aPremultiplied, aConformant );
   1.177 +}
   1.178 +
   1.179 +EXPORT_C TInt VGISymbianCopyToBitmap( CFbsBitmap *aBitmap, CFbsBitmap *aMaskBitmap, VGICopyToTargetHint aHint )
   1.180 +{
   1.181 +    VGI_GET_BRIDGE_RET;
   1.182 +
   1.183 +    return bridge->VGISymbianCopyToBitmap( aBitmap, aMaskBitmap, aHint );
   1.184 +}
   1.185 +
   1.186 +EXPORT_C void VGISymbianTerminate()
   1.187 +{
   1.188 +    VGI_GET_BRIDGE;
   1.189 +
   1.190 +    bridge->VGISymbianTerminate();
   1.191 +    
   1.192 +    bridge->libHandle.Close();
   1.193 +
   1.194 +    free( bridge );
   1.195 +    vgiSetCurrentBridge( NULL );
   1.196 +}
   1.197 +
   1.198 +EXPORT_C TInt VGISymbianResize( TSize aSize )
   1.199 +{
   1.200 +    VGI_GET_BRIDGE_RET;
   1.201 +
   1.202 +    return bridge->VGISymbianResize( aSize );
   1.203 +}
   1.204 +
   1.205 +EXPORT_C TInt VGISymbianBindToImage( VGImage aImage )
   1.206 +{
   1.207 +    VGI_GET_BRIDGE_RET;
   1.208 +
   1.209 +    return bridge->VGISymbianBindToImage( aImage );
   1.210 +}
   1.211 +
   1.212 +EXPORT_C TInt VGISymbianUnBindImage()
   1.213 +{
   1.214 +    VGI_GET_BRIDGE_RET;
   1.215 +
   1.216 +    return bridge->VGISymbianUnBindImage();
   1.217 +}
   1.218 +
   1.219 +#endif