First public contribution.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "eglrendering.h"
19 #include "openvgengine.h"
25 _LIT(KErrEgl, "EGL error");
26 _LIT(KErrOpenVg, "OpenVG error");
27 _LIT(KErrEglReturn, "EGL return error");
30 /** Attributes to be passed into eglChooseConfig */
31 const EGLint KColorRGB565AttribList[] =
36 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
37 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
42 CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
44 CEGLRendering* self = CEGLRendering::NewLC(aWindow);
45 CleanupStack::Pop(self);
49 CEGLRendering* CEGLRendering::NewLC(RWindow& aWindow)
51 CEGLRendering* self = new(ELeave) CEGLRendering(aWindow);
52 CleanupStack::PushL(self);
57 CEGLRendering::CEGLRendering(RWindow& aWindow) : iWindow(aWindow),iCount(0)
62 void CEGLRendering::ConstructL()
64 const TDisplayMode dispMode = iWindow.DisplayMode();
65 const TSize windowSize(iWindow.Size());
67 // Create display object
68 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
71 // Initialize display object
72 EGLCheckReturnError(eglInitialize(iDisplay, NULL, NULL));
74 // Check that EGL provides the capabilities for this app.
75 if (NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG"))
77 RDebug::Printf("OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS));
78 User::Leave(KErrNotSupported);
80 if (NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION"))
82 RDebug::Printf("EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
83 User::Leave(KErrNotSupported);
87 EGLConfig chosenConfig = 0;
89 // Choose the config to use
90 EGLCheckReturnError(eglChooseConfig(iDisplay, KColorRGB565AttribList, &chosenConfig, 1, &numConfigs));
93 RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS));
94 User::Leave(KErrNotSupported);
97 // Create window surface to draw direct to.
98 EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
99 iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
102 TInt redSize, greenSize, blueSize, alphaSize;
103 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_ALPHA_SIZE, &alphaSize));
104 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_RED_SIZE, &redSize));
105 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_GREEN_SIZE, &greenSize));
106 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_BLUE_SIZE, &blueSize));
108 // Create context to store surface settings
109 iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
112 iCurrentDemo = COpenVGEngine::NewL(iWindow,iDisplay,iSurface,iContextVG);
113 iCurrentDemo->ActivateL();
116 CEGLRendering::~CEGLRendering()
119 CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
120 if (iContextVG != EGL_NO_CONTEXT)
122 EGLCheckReturnError(eglDestroyContext(iDisplay,iContextVG));
124 if (iSurface != EGL_NO_SURFACE)
126 EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface));
128 // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
129 EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
130 //EGLCheckReturnError(eglTerminate(iDisplay));
134 void CEGLRendering::EGLCheckError()
136 EGLint error = eglGetError();
137 if(error != EGL_SUCCESS)
139 User::Panic(KErrEgl, error);
143 void CEGLRendering::VGCheckError()
145 VGint error = vgGetError();
146 if(error != VG_NO_ERROR)
148 User::Panic(KErrOpenVg, error);
152 void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool)
156 User::Panic(KErrEglReturn, eglGetError());
161 * Update the display.
163 void CEGLRendering::UpdateDisplay()
165 // Guard against unexpected re-entrant problem. Use this flag until the issue is resolved.
171 if (iCurrentDemo->IsPending() || (!iCurrentDemo->IsPending() && iShowMirrorToggled))
173 // needed to make sure the correct status is active
174 CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
175 iShowMirrorToggled = EFalse;
176 iCurrentDemo->Step();
177 iBusySwapping = ETrue;
178 CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface));
179 iBusySwapping = EFalse;