1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/eglrendering.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,181 @@
1.4 + // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 + // All rights reserved.
1.6 + // This component and the accompanying materials are made available
1.7 + // under the terms of "Eclipse Public License v1.0"
1.8 + // which accompanies this distribution, and is available
1.9 + // at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 + //
1.11 + // Initial Contributors:
1.12 + // Nokia Corporation - initial contribution.
1.13 + //
1.14 + // Contributors:
1.15 + //
1.16 + // Description:
1.17 + //
1.18 +
1.19 +
1.20 +#include "eglrendering.h"
1.21 +#include "engine.h"
1.22 +#include "openvgengine.h"
1.23 +
1.24 +#include <hal.h>
1.25 +#include <string.h>
1.26 +
1.27 +
1.28 +_LIT(KErrEgl, "EGL error");
1.29 +_LIT(KErrOpenVg, "OpenVG error");
1.30 +_LIT(KErrEglReturn, "EGL return error");
1.31 +
1.32 +
1.33 +/** Attributes to be passed into eglChooseConfig */
1.34 +const EGLint KColorRGB565AttribList[] =
1.35 + {
1.36 + EGL_RED_SIZE, 5,
1.37 + EGL_GREEN_SIZE, 6,
1.38 + EGL_BLUE_SIZE, 5,
1.39 + EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
1.40 + EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
1.41 + EGL_NONE
1.42 + };
1.43 +
1.44 +
1.45 +CEGLRendering* CEGLRendering::NewL(RWindow& aWindow)
1.46 + {
1.47 + CEGLRendering* self = CEGLRendering::NewLC(aWindow);
1.48 + CleanupStack::Pop(self);
1.49 + return self;
1.50 + }
1.51 +
1.52 +CEGLRendering* CEGLRendering::NewLC(RWindow& aWindow)
1.53 + {
1.54 + CEGLRendering* self = new(ELeave) CEGLRendering(aWindow);
1.55 + CleanupStack::PushL(self);
1.56 + self->ConstructL();
1.57 + return self;
1.58 + }
1.59 +
1.60 +CEGLRendering::CEGLRendering(RWindow& aWindow) : iWindow(aWindow),iCount(0)
1.61 + {
1.62 + // empty
1.63 + }
1.64 +
1.65 +void CEGLRendering::ConstructL()
1.66 + {
1.67 + const TDisplayMode dispMode = iWindow.DisplayMode();
1.68 + const TSize windowSize(iWindow.Size());
1.69 +
1.70 + // Create display object
1.71 + iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1.72 + EGLCheckError();
1.73 +
1.74 + // Initialize display object
1.75 + EGLCheckReturnError(eglInitialize(iDisplay, NULL, NULL));
1.76 +
1.77 + // Check that EGL provides the capabilities for this app.
1.78 + if (NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG"))
1.79 + {
1.80 + RDebug::Printf("OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS));
1.81 + User::Leave(KErrNotSupported);
1.82 + }
1.83 + if (NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION"))
1.84 + {
1.85 + RDebug::Printf("EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS));
1.86 + User::Leave(KErrNotSupported);
1.87 + }
1.88 +
1.89 + EGLint numConfigs;
1.90 + EGLConfig chosenConfig = 0;
1.91 +
1.92 + // Choose the config to use
1.93 + EGLCheckReturnError(eglChooseConfig(iDisplay, KColorRGB565AttribList, &chosenConfig, 1, &numConfigs));
1.94 + if (numConfigs == 0)
1.95 + {
1.96 + RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS));
1.97 + User::Leave(KErrNotSupported);
1.98 + }
1.99 +
1.100 + // Create window surface to draw direct to.
1.101 + EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API));
1.102 + iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
1.103 + EGLCheckError();
1.104 +
1.105 + TInt redSize, greenSize, blueSize, alphaSize;
1.106 + EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_ALPHA_SIZE, &alphaSize));
1.107 + EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_RED_SIZE, &redSize));
1.108 + EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_GREEN_SIZE, &greenSize));
1.109 + EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_BLUE_SIZE, &blueSize));
1.110 +
1.111 + // Create context to store surface settings
1.112 + iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
1.113 + EGLCheckError();
1.114 +
1.115 + iCurrentDemo = COpenVGEngine::NewL(iWindow,iDisplay,iSurface,iContextVG);
1.116 + iCurrentDemo->ActivateL();
1.117 + }
1.118 +
1.119 +CEGLRendering::~CEGLRendering()
1.120 + {
1.121 + delete iCurrentDemo;
1.122 + CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
1.123 + if (iContextVG != EGL_NO_CONTEXT)
1.124 + {
1.125 + EGLCheckReturnError(eglDestroyContext(iDisplay,iContextVG));
1.126 + }
1.127 + if (iSurface != EGL_NO_SURFACE)
1.128 + {
1.129 + EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface));
1.130 + }
1.131 + // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
1.132 + EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1.133 + //EGLCheckReturnError(eglTerminate(iDisplay));
1.134 + eglReleaseThread();
1.135 + }
1.136 +
1.137 +void CEGLRendering::EGLCheckError()
1.138 + {
1.139 + EGLint error = eglGetError();
1.140 + if(error != EGL_SUCCESS)
1.141 + {
1.142 + User::Panic(KErrEgl, error);
1.143 + }
1.144 + }
1.145 +
1.146 +void CEGLRendering::VGCheckError()
1.147 + {
1.148 + VGint error = vgGetError();
1.149 + if(error != VG_NO_ERROR)
1.150 + {
1.151 + User::Panic(KErrOpenVg, error);
1.152 + }
1.153 + }
1.154 +
1.155 +void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool)
1.156 + {
1.157 + if (!aBool)
1.158 + {
1.159 + User::Panic(KErrEglReturn, eglGetError());
1.160 + }
1.161 + }
1.162 +
1.163 +/**
1.164 + * Update the display.
1.165 + */
1.166 +void CEGLRendering::UpdateDisplay()
1.167 + {
1.168 + // Guard against unexpected re-entrant problem. Use this flag until the issue is resolved.
1.169 + if (iBusySwapping)
1.170 + {
1.171 + return;
1.172 + }
1.173 +
1.174 + if (iCurrentDemo->IsPending() || (!iCurrentDemo->IsPending() && iShowMirrorToggled))
1.175 + {
1.176 + // needed to make sure the correct status is active
1.177 + CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG));
1.178 + iShowMirrorToggled = EFalse;
1.179 + iCurrentDemo->Step();
1.180 + iBusySwapping = ETrue;
1.181 + CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface));
1.182 + iBusySwapping = EFalse;
1.183 + }
1.184 + }