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