|
1 /* |
|
2 * Copyright (c) 2009 Symbian Foundation Ltd |
|
3 * This component and the accompanying materials are made available |
|
4 * under the terms of the License "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 * Symbian Foundation Ltd - initial contribution. |
|
10 * |
|
11 * Contributors: |
|
12 * |
|
13 * Description: |
|
14 * Implementation of VGI interface |
|
15 */ |
|
16 |
|
17 #include <e32std.h> |
|
18 #include <vg\vgcontext.h> |
|
19 #include <vg\vgcontext_symbian.h> |
|
20 #include <egl.h> |
|
21 |
|
22 #define MAX_WIDTH 320*4 // in bytes |
|
23 #define MAX_HEIGHT 320*4 // in bytes |
|
24 class TEgl |
|
25 { |
|
26 public: |
|
27 TEgl() : |
|
28 iEgldisplay(0), |
|
29 iEglsurface(0), |
|
30 iEglcontext(0), |
|
31 iInitialised(EFalse), |
|
32 iPixmap(NULL) |
|
33 {}; |
|
34 |
|
35 public: //data |
|
36 EGLDisplay iEgldisplay; |
|
37 EGLSurface iEglsurface; |
|
38 EGLContext iEglcontext; |
|
39 TBool iInitialised; |
|
40 CFbsBitmap* iPixmap; |
|
41 }; |
|
42 |
|
43 |
|
44 TEgl& GetEglInstance() |
|
45 { |
|
46 //use TLS |
|
47 //use TLS to store static global egl |
|
48 TEgl* pEgl=NULL; |
|
49 if((pEgl = static_cast<TEgl*>(Dll::Tls()))==NULL) |
|
50 { |
|
51 //create TLS instance |
|
52 pEgl = new(ELeave)TEgl; |
|
53 Dll::SetTls(pEgl); |
|
54 } |
|
55 return *pEgl; |
|
56 } |
|
57 |
|
58 void ReleaseTls() |
|
59 { |
|
60 TEgl* pEgl = static_cast<TEgl*>(Dll::Tls()); |
|
61 if (pEgl) |
|
62 delete pEgl; |
|
63 Dll::SetTls(NULL); |
|
64 } |
|
65 |
|
66 VGI_API_CALL int VGIInitialize( int /*width*/, int /*height*/, VGIColorSpace /*colorSpace*/ ) |
|
67 { |
|
68 return VGI_OK; |
|
69 } |
|
70 |
|
71 VGI_API_CALL int VGIInitializeEx( int /*width*/, int /*height*/, VGIColorSpace /*colorSpace*/, int /*premultiplied*/, int /*conformant*/ ) |
|
72 { |
|
73 return VGI_OK; |
|
74 } |
|
75 |
|
76 VGI_API_CALL int VGICopyToTarget( VGIColorBufferFormat /*format*/, int /*bufferStride*/, void */*buffer*/, int /*maskStride*/, void */*mask*/, VGICopyToTargetHint /*hint*/ ) |
|
77 { |
|
78 return VGI_OK; |
|
79 } |
|
80 |
|
81 VGI_API_CALL void VGITerminate( void ) |
|
82 { |
|
83 |
|
84 } |
|
85 |
|
86 VGI_API_CALL int VGIResize( int /*width*/, int /*height*/ ) |
|
87 { |
|
88 return VGI_OK; |
|
89 } |
|
90 |
|
91 VGI_API_CALL int VGIBindToImage( VGImage /*image*/ ) |
|
92 { |
|
93 return VGI_OK; |
|
94 } |
|
95 |
|
96 VGI_API_CALL int VGIUnBindImage( void ) |
|
97 { |
|
98 return VGI_OK; |
|
99 } |
|
100 |
|
101 |
|
102 |
|
103 VGI_API_CALL TInt VGISymbianInitialize( TSize aSize, VGIColorSpace /*aColorSpace*/ ) |
|
104 { |
|
105 TEgl& egl = GetEglInstance(); |
|
106 //only init once |
|
107 if(!egl.iInitialised) |
|
108 { |
|
109 egl.iInitialised = ETrue; |
|
110 static const EGLint s_configAttribs[] = |
|
111 { |
|
112 EGL_RED_SIZE, |
|
113 8, |
|
114 EGL_GREEN_SIZE, |
|
115 8, |
|
116 EGL_BLUE_SIZE, |
|
117 8, |
|
118 EGL_ALPHA_SIZE, |
|
119 8, |
|
120 EGL_LUMINANCE_SIZE, |
|
121 EGL_DONT_CARE, //EGL_DONT_CARE |
|
122 EGL_SURFACE_TYPE, |
|
123 EGL_WINDOW_BIT, |
|
124 EGL_SAMPLES, |
|
125 1, |
|
126 EGL_NONE |
|
127 }; |
|
128 EGLint numconfigs; |
|
129 |
|
130 egl.iEgldisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
|
131 eglInitialize(egl.iEgldisplay, NULL, NULL); |
|
132 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
133 eglBindAPI(EGL_OPENVG_API); |
|
134 |
|
135 EGLConfig eglconfig; |
|
136 |
|
137 eglChooseConfig(egl.iEgldisplay, s_configAttribs, &eglconfig, 1, &numconfigs); |
|
138 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
139 __ASSERT_ALWAYS(numconfigs == 1,User::Invariant()); |
|
140 |
|
141 TSize maxSize(MAX_WIDTH,MAX_HEIGHT); |
|
142 egl.iPixmap = new(ELeave) CFbsBitmap(); |
|
143 egl.iPixmap->Create( maxSize, EColor16MA ); |
|
144 |
|
145 egl.iEglsurface = eglCreatePixmapSurface(egl.iEgldisplay, eglconfig, (EGLNativePixmapType)egl.iPixmap, NULL); |
|
146 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
147 |
|
148 egl.iEglcontext = eglCreateContext(egl.iEgldisplay, eglconfig, NULL, NULL); |
|
149 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
150 eglMakeCurrent(egl.iEgldisplay, egl.iEglsurface, egl.iEglsurface, egl.iEglcontext); |
|
151 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
152 |
|
153 } |
|
154 return VGI_OK; |
|
155 } |
|
156 |
|
157 VGI_API_CALL TInt VGISymbianInitializeEx( TSize /*aSize*/, VGIColorSpace /*aColorSpace*/, TBool /*aPremultiplied*/, TBool /*aConformant*/ ) |
|
158 { |
|
159 return VGI_OK; |
|
160 } |
|
161 |
|
162 VGI_API_CALL TInt VGISymbianCopyToBitmap( CFbsBitmap *aBitmap, CFbsBitmap *aMaskBitmap, VGICopyToTargetHint /*aHint*/ ) |
|
163 { |
|
164 TEgl& egl = GetEglInstance(); |
|
165 |
|
166 eglCopyBuffers(egl.iEgldisplay, egl.iEglsurface,(EGLNativePixmapType)aBitmap); |
|
167 |
|
168 if(aMaskBitmap) |
|
169 { |
|
170 eglCopyBuffers(egl.iEgldisplay, egl.iEglsurface,(EGLNativePixmapType)aMaskBitmap); |
|
171 } |
|
172 |
|
173 __ASSERT_ALWAYS(eglGetError() == EGL_SUCCESS,User::Invariant()); |
|
174 return VGI_OK; |
|
175 } |
|
176 |
|
177 VGI_API_CALL void VGISymbianTerminate() |
|
178 { |
|
179 TEgl& egl = GetEglInstance(); |
|
180 eglDestroyContext(egl.iEgldisplay, egl.iEglcontext); |
|
181 eglDestroySurface(egl.iEgldisplay, egl.iEglsurface); |
|
182 delete egl.iPixmap; |
|
183 ReleaseTls(); |
|
184 } |
|
185 |
|
186 VGI_API_CALL TInt VGISymbianResize( TSize aSize ) |
|
187 { |
|
188 return VGI_OK; |
|
189 } |
|
190 |
|
191 VGI_API_CALL TInt VGISymbianBindToImage( VGImage /*aImage*/ ) |
|
192 { |
|
193 return VGI_OK; |
|
194 } |
|
195 |
|
196 VGI_API_CALL TInt VGISymbianUnBindImage() |
|
197 { |
|
198 return VGI_OK; |
|
199 } |
|
200 |