sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
#include "vg_vgibridge.h"
|
sl@0
|
18 |
#include <stdlib.h>
|
sl@0
|
19 |
#include <string.h>
|
sl@0
|
20 |
#include <VG/openvg.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#define VGI_API_CALL __declspec(dllexport)
|
sl@0
|
23 |
|
sl@0
|
24 |
#define VGI_GET_BRIDGE VGIBridge *bridge = vgiGetBridge(); if(!bridge) return;
|
sl@0
|
25 |
#define VGI_GET_BRIDGE_RET VGIBridge *bridge = vgiGetBridge(); if(!bridge) return 0;
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
#if defined __SYMBIAN32__
|
sl@0
|
29 |
|
sl@0
|
30 |
static void vgiSetCurrentBridge( VGIBridge* bridge )
|
sl@0
|
31 |
{
|
sl@0
|
32 |
Dll::SetTls( bridge );
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
static VGIBridge* vgiGetCurrentBridge()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
return (VGIBridge*)Dll::Tls();
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
#elif defined WIN32
|
sl@0
|
41 |
|
sl@0
|
42 |
#include <windows.h>
|
sl@0
|
43 |
|
sl@0
|
44 |
VGIBridge *currBridge = NULL;
|
sl@0
|
45 |
|
sl@0
|
46 |
static void vgiSetCurrentBridge( VGIBridge* bridge )
|
sl@0
|
47 |
{
|
sl@0
|
48 |
currBridge = bridge;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
static VGIBridge* vgiGetCurrentBridge()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
return currBridge;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
#endif
|
sl@0
|
57 |
|
sl@0
|
58 |
static VGIBridge* vgiGetBridge()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
VGIBridge *bridge = vgiGetCurrentBridge();
|
sl@0
|
61 |
if( !bridge )
|
sl@0
|
62 |
{
|
sl@0
|
63 |
VGIBridgeFunc vgiVGIBridge = NULL;
|
sl@0
|
64 |
|
sl@0
|
65 |
bridge = (VGIBridge *)malloc( sizeof(VGIBridge) );
|
sl@0
|
66 |
if( !bridge )
|
sl@0
|
67 |
return NULL;
|
sl@0
|
68 |
|
sl@0
|
69 |
memset( bridge, 0, sizeof(VGIBridge) );
|
sl@0
|
70 |
|
sl@0
|
71 |
#if defined __SYMBIAN32__
|
sl@0
|
72 |
{
|
sl@0
|
73 |
RLibrary lib;
|
sl@0
|
74 |
#ifdef OPENVG_VERSION_1_1
|
sl@0
|
75 |
if( lib.Load( _L("libOpenVG_SW.dll") ) == KErrNone )
|
sl@0
|
76 |
vgiVGIBridge = (VGIBridgeFunc)lib.Lookup( 89 ); // <- 89 is a hardcoded ordinal, refer to libopenvgu.def in bwins and eabi folders
|
sl@0
|
77 |
#else // OPENVG_VERSION_1_0 and OPENVG_VERSION_1_0_1
|
sl@0
|
78 |
if( lib.Load( _L("libOpenVG.dll") ) == KErrNone )
|
sl@0
|
79 |
vgiVGIBridge = (VGIBridgeFunc)lib.Lookup( 1 ); // <- 1 is a hardcoded ordinal, refer to libopenvgu.def in bwins and eabi folders
|
sl@0
|
80 |
#endif
|
sl@0
|
81 |
bridge->libHandle = lib;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
#elif defined WIN32
|
sl@0
|
84 |
{
|
sl@0
|
85 |
HMODULE hModule = LoadLibrary( "libOpenVG.dll" );
|
sl@0
|
86 |
if( hModule )
|
sl@0
|
87 |
vgiVGIBridge = (VGIBridgeFunc)GetProcAddress( hModule, "vgiVGIBridge" );
|
sl@0
|
88 |
}
|
sl@0
|
89 |
#endif
|
sl@0
|
90 |
|
sl@0
|
91 |
if( !vgiVGIBridge )
|
sl@0
|
92 |
{
|
sl@0
|
93 |
free( bridge );
|
sl@0
|
94 |
return NULL;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
vgiVGIBridge( bridge );
|
sl@0
|
98 |
vgiSetCurrentBridge( bridge );
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
return bridge;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
VGI_API_CALL int VGIInitialize( int width, int height, VGIColorSpace colorSpace )
|
sl@0
|
105 |
{
|
sl@0
|
106 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
107 |
|
sl@0
|
108 |
return bridge->VGIInitialize( width, height, colorSpace );
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
VGI_API_CALL int VGIInitializeEx( int width, int height, VGIColorSpace colorSpace, int premultiplied, int conformant )
|
sl@0
|
112 |
{
|
sl@0
|
113 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
114 |
|
sl@0
|
115 |
return bridge->VGIInitializeEx( width, height, colorSpace, premultiplied, conformant );
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
VGI_API_CALL int VGICopyToTarget( VGIColorBufferFormat format, int bufferStride, void *buffer, int maskStride, void *mask, VGICopyToTargetHint hint )
|
sl@0
|
119 |
{
|
sl@0
|
120 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
121 |
|
sl@0
|
122 |
return bridge->VGICopyToTarget( format, bufferStride, buffer, maskStride, mask, hint );
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
VGI_API_CALL void VGITerminate( void )
|
sl@0
|
126 |
{
|
sl@0
|
127 |
VGI_GET_BRIDGE;
|
sl@0
|
128 |
|
sl@0
|
129 |
bridge->VGITerminate();
|
sl@0
|
130 |
|
sl@0
|
131 |
#if defined __SYMBIAN32__
|
sl@0
|
132 |
bridge->libHandle.Close();
|
sl@0
|
133 |
#endif
|
sl@0
|
134 |
|
sl@0
|
135 |
free( bridge );
|
sl@0
|
136 |
vgiSetCurrentBridge( NULL );
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
VGI_API_CALL int VGIResize( int width, int height )
|
sl@0
|
140 |
{
|
sl@0
|
141 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
142 |
|
sl@0
|
143 |
return bridge->VGIResize( width, height );
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
VGI_API_CALL int VGIBindToImage( VGImage image )
|
sl@0
|
147 |
{
|
sl@0
|
148 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
149 |
|
sl@0
|
150 |
return bridge->VGIBindToImage( image );
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
VGI_API_CALL int VGIUnBindImage( void )
|
sl@0
|
154 |
{
|
sl@0
|
155 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
156 |
|
sl@0
|
157 |
return bridge->VGIUnBindImage();
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
#ifdef __SYMBIAN32__
|
sl@0
|
161 |
|
sl@0
|
162 |
EXPORT_C TInt VGISymbianInitialize( TSize aSize, VGIColorSpace aColorSpace )
|
sl@0
|
163 |
{
|
sl@0
|
164 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
165 |
|
sl@0
|
166 |
return bridge->VGISymbianInitialize( aSize, aColorSpace );
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
EXPORT_C TInt VGISymbianInitializeEx( TSize aSize, VGIColorSpace aColorSpace, TBool aPremultiplied, TBool aConformant )
|
sl@0
|
170 |
{
|
sl@0
|
171 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
172 |
|
sl@0
|
173 |
return bridge->VGISymbianInitializeEx( aSize, aColorSpace, aPremultiplied, aConformant );
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
EXPORT_C TInt VGISymbianCopyToBitmap( CFbsBitmap *aBitmap, CFbsBitmap *aMaskBitmap, VGICopyToTargetHint aHint )
|
sl@0
|
177 |
{
|
sl@0
|
178 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
179 |
|
sl@0
|
180 |
return bridge->VGISymbianCopyToBitmap( aBitmap, aMaskBitmap, aHint );
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
EXPORT_C void VGISymbianTerminate()
|
sl@0
|
184 |
{
|
sl@0
|
185 |
VGI_GET_BRIDGE;
|
sl@0
|
186 |
|
sl@0
|
187 |
bridge->VGISymbianTerminate();
|
sl@0
|
188 |
|
sl@0
|
189 |
bridge->libHandle.Close();
|
sl@0
|
190 |
|
sl@0
|
191 |
free( bridge );
|
sl@0
|
192 |
vgiSetCurrentBridge( NULL );
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
EXPORT_C TInt VGISymbianResize( TSize aSize )
|
sl@0
|
196 |
{
|
sl@0
|
197 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
198 |
|
sl@0
|
199 |
return bridge->VGISymbianResize( aSize );
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
EXPORT_C TInt VGISymbianBindToImage( VGImage aImage )
|
sl@0
|
203 |
{
|
sl@0
|
204 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
205 |
|
sl@0
|
206 |
return bridge->VGISymbianBindToImage( aImage );
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
EXPORT_C TInt VGISymbianUnBindImage()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
VGI_GET_BRIDGE_RET;
|
sl@0
|
212 |
|
sl@0
|
213 |
return bridge->VGISymbianUnBindImage();
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
#endif
|