00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00033 #include <eikenv.h>
00034 #include <string.h>
00035 #include "eglrendering.h"
00036 #include "engine.h"
00037 #include "openvgengine.h"
00038 #include <hal.h>
00039
00043 const EGLint KColorRGB565AttribList[] =
00044 {
00045 EGL_RED_SIZE, 5,
00046 EGL_GREEN_SIZE, 6,
00047 EGL_BLUE_SIZE, 5,
00048 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
00049 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
00050 EGL_NONE
00051 };
00052
00058 CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
00059 {
00060 CEGLRendering* self = CEGLRendering::NewLC(aWindow);
00061 CleanupStack::Pop(self);
00062 return self;
00063 }
00064
00070 CEGLRendering* CEGLRendering::NewLC(RWindow& aWindow)
00071 {
00072 CEGLRendering* self = new(ELeave) CEGLRendering(aWindow);
00073 CleanupStack::PushL(self);
00074 self->ConstructL();
00075 return self;
00076 }
00077
00081 CEGLRendering::~CEGLRendering()
00082 {
00083
00084 Stop();
00085 delete iTimer;
00086
00087 if(iCurrentDemo)
00088 {
00089
00090 iCurrentDemo->Deactivate();
00091 }
00092 delete iCurrentDemo;
00093
00094 if (iContextVG!=EGL_NO_CONTEXT)
00095 {
00096 EGLCheckReturnError(eglDestroyContext(iDisplay,iContextVG));
00097 }
00098
00099 if (iSurface!=EGL_NO_SURFACE)
00100 {
00101 EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface));
00102 }
00103
00104 EGLCheckReturnError(eglTerminate(iDisplay));
00105 EGLCheckReturnError(eglReleaseThread());
00106
00107 delete iBitmap;
00108 }
00109
00113 void CEGLRendering::Start()
00114 {
00115
00116 iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack,this));
00117 }
00118
00122 void CEGLRendering::Stop()
00123 {
00124 if(iTimer)
00125 {
00126 iTimer->Cancel();
00127 }
00128 }
00129
00133 void CEGLRendering::EGLCheckError()
00134 {
00135 EGLint error = eglGetError();
00136 if(error != EGL_SUCCESS)
00137 {
00138 User::Panic(_L("EGL error"), error);
00139 }
00140 }
00141
00145 void CEGLRendering::VGCheckError()
00146 {
00147 VGint error = vgGetError();
00148 if(error != VG_NO_ERROR)
00149 {
00150 User::Panic(_L("OpenVG error"), error);
00151 }
00152 }
00153
00158 void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool)
00159 {
00160 if (!aBool)
00161 {
00162 User::Panic(_L("EGL return error"),eglGetError());
00163 }
00164 }
00165
00170 CEGLRendering::CEGLRendering(RWindow& aWindow)
00171 : iWindow(aWindow)
00172 {
00173 }
00174
00180 TKeyResponse CEGLRendering::HandleKeyEventL(const TKeyEvent& aKeyEvent)
00181 {
00182 TKeyResponse response = EKeyWasConsumed;
00183 switch (aKeyEvent.iCode)
00184 {
00185 case EKeySpace:
00186
00187
00188
00189 iTimer->IsActive()? Stop() : Start();
00190 break;
00191
00192 case EKeyTab:
00193 break;
00194 case EKeyUpArrow:
00195 break;
00196 case EKeyDownArrow:
00197 break;
00198 case EKeyBackspace:
00199
00200 iShowMirrorToggled = ETrue;
00201 default:
00202 response = iCurrentDemo->HandleKeyEventL(aKeyEvent);
00203 break;
00204 };
00205 return response;
00206 }
00207
00211 void CEGLRendering::ConstructL()
00212 {
00213
00214 iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
00215
00216 const TSize windowSize(iWindow.Size());
00217
00218
00219 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
00220 EGLCheckError();
00221
00222
00223 EGLint iMajor, iMinor;
00224
00225 EGLCheckReturnError(eglInitialize(iDisplay, &iMajor, &iMinor));
00226 RDebug::Printf("Vendor string %s", eglQueryString(iDisplay, EGL_VENDOR));
00227 RDebug::Printf("Version string %s", eglQueryString(iDisplay, EGL_VERSION));
00228
00229 if ( NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG") )
00230 {
00231 RDebug::Printf("OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS));
00232 }
00233 if ( NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION") )
00234 {
00235 CEikonEnv::Static()->InfoMsg(_L("Graphics Composition is not supported in this SymbianOS version"));
00236 RDebug::Printf("EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
00237 User::Leave(KErrNotSupported);
00238 }
00239
00240
00241 EGLint numConfigs;
00242
00243 EGLCheckReturnError(eglGetConfigs(iDisplay, iConfig, KMaxConfigs, &numConfigs));
00244
00245
00246 EGLCheckReturnError(eglChooseConfig(iDisplay, KColorRGB565AttribList, iConfig, 1, &numConfigs));
00247 EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
00248
00249
00250
00251 iSurface = eglCreateWindowSurface(iDisplay, iConfig[0], &iWindow, NULL);
00252 EGLCheckError();
00253
00254 TInt redSize, greenSize, blueSize, alphaSize;
00255
00256 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, iConfig[0], EGL_ALPHA_SIZE, &alphaSize));
00257 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, iConfig[0], EGL_RED_SIZE, &redSize));
00258 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, iConfig[0], EGL_GREEN_SIZE, &greenSize));
00259 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, iConfig[0], EGL_BLUE_SIZE, &blueSize));
00260 RDebug::Print(_L("EGLConfig id:%d alpha:%d red:%d green:%d blue:%d"), iConfig[0],
00261 alphaSize, redSize, greenSize, blueSize);
00262
00263
00264 iContextVG = eglCreateContext(iDisplay, iConfig[0], NULL, NULL);
00265 EGLCheckError();
00266
00267 CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
00268 iCurrentDemo = COpenVGEngine::NewL(windowSize,iDisplay,iSurface,iContextVG);
00269 iCurrentDemo->ActivateL();
00270
00271 User::LeaveIfError(HAL::Get(HAL::EFastCounterFrequency, iFastCounterFrequency));
00272 }
00273
00274
00278 void CEGLRendering::UpdateDisplay()
00279 {
00280
00281 if (iBusySwapping)
00282 {
00283 return;
00284 }
00285
00286 if (iCurrentDemo->IsPending() || (!iCurrentDemo->IsPending() && iShowMirrorToggled))
00287 {
00288 iShowMirrorToggled = EFalse;
00289
00290
00291 iCurrentDemo->Step();
00292 iBusySwapping = ETrue;
00293
00294
00295 CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface));
00296 iBusySwapping = EFalse;
00297
00298 TUint currentTimeStamp = User::FastCounter();
00299 TReal delta = currentTimeStamp - iLastFrameTimeStamp;
00300
00301 TReal measuredFrameRate = static_cast<TReal>(iFastCounterFrequency/delta);
00302
00303 iLastFrameTimeStamp = currentTimeStamp;
00304 RDebug::Printf("[Timestamp: %d FrameRate: %f]", iLastFrameTimeStamp, measuredFrameRate);
00305 }
00306 }
00307
00313 TInt CEGLRendering::TimerCallBack(TAny* aDemo)
00314 {
00315 static_cast<CEGLRendering*>(aDemo)->UpdateDisplay();
00316 return KErrNone;
00317 }