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