sl@0: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "tsmallwindowopenvg.h" sl@0: sl@0: sl@0: // todo: is it the right config sl@0: const EGLint KColorRGB565AttribList[] = sl@0: { sl@0: EGL_RED_SIZE, 5, sl@0: EGL_GREEN_SIZE, 6, sl@0: EGL_BLUE_SIZE, 5, sl@0: EGL_SURFACE_TYPE, EGL_WINDOW_BIT, sl@0: EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, sl@0: EGL_NONE sl@0: }; sl@0: sl@0: sl@0: CTWindow* CTSmallWindowOpenVG::NewL(RWsSession &aWs, sl@0: const RWindowTreeNode &aParent, sl@0: const TPoint& aStartingPoint, sl@0: const TSize& aWindowSize) sl@0: { sl@0: CTSmallWindowOpenVG* self = new (ELeave) CTSmallWindowOpenVG(aStartingPoint, aWindowSize); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aWs, aParent); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTSmallWindowOpenVG::CTSmallWindowOpenVG(const TPoint& aStartingPoint, const TSize& aWindowSize): sl@0: CTWindow(aStartingPoint, aWindowSize) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CTSmallWindowOpenVG::~CTSmallWindowOpenVG() sl@0: { sl@0: // Make sure that this egl status is active sl@0: eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG); sl@0: vgDestroyPaint(iFillPaint); sl@0: vgDestroyPaint(iStrokePaint); sl@0: vgDestroyPath(iPath); sl@0: if (iContextVG != EGL_NO_CONTEXT) sl@0: { sl@0: eglDestroyContext(iDisplay,iContextVG); sl@0: } sl@0: if (iSurface != EGL_NO_SURFACE) sl@0: { sl@0: eglDestroySurface(iDisplay,iSurface); sl@0: } sl@0: // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed. sl@0: eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); sl@0: //eglTerminate(iDisplay); sl@0: eglReleaseThread(); sl@0: } sl@0: sl@0: sl@0: sl@0: void CTSmallWindowOpenVG::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent) sl@0: { sl@0: CTWindow::ConstructL(aWs, aParent); sl@0: sl@0: iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); sl@0: eglInitialize(iDisplay, NULL, NULL); sl@0: sl@0: EGLint numConfigs; sl@0: EGLConfig chosenConfig = 0; sl@0: sl@0: // Choose the config to use sl@0: eglChooseConfig(iDisplay, KColorRGB565AttribList, &chosenConfig, 1, &numConfigs); sl@0: if (numConfigs == 0) sl@0: { sl@0: RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS)); sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: // Create window surface to draw direct to. sl@0: eglBindAPI(EGL_OPENVG_API); sl@0: iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL); sl@0: sl@0: // Create context to store surface settings sl@0: iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL); sl@0: sl@0: eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG); sl@0: sl@0: VGfloat strokeColor[4] = {1.f, 0.f, 0.f, 1.f}; sl@0: VGfloat fillColor[4] = {0.f, 0.f, 1.f, 1.f}; sl@0: sl@0: VGubyte pathSegments[6] = sl@0: { sl@0: VG_LINE_TO | (int)VG_ABSOLUTE, sl@0: VG_LINE_TO | (int)VG_ABSOLUTE, sl@0: VG_LINE_TO | (int)VG_ABSOLUTE, sl@0: VG_LINE_TO | (int)VG_ABSOLUTE, sl@0: VG_CLOSE_PATH sl@0: }; sl@0: sl@0: VGfloat pathData[10] = sl@0: { sl@0: 0.f, 100.f, sl@0: 100.f, 100.f, sl@0: 100.f, 0.f, sl@0: 0.f, 0.f sl@0: }; sl@0: sl@0: vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); sl@0: sl@0: iCurrentRotation = 0.f; sl@0: iStrokePaint = vgCreatePaint(); sl@0: iFillPaint = vgCreatePaint(); sl@0: sl@0: vgSetParameteri(iStrokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); sl@0: vgSetParameterfv(iStrokePaint, VG_PAINT_COLOR, 4, strokeColor); sl@0: sl@0: vgSetParameteri(iFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); sl@0: vgSetParameterfv(iFillPaint, VG_PAINT_COLOR, 4, fillColor); sl@0: sl@0: iPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL); sl@0: sl@0: vgAppendPathData(iPath, 4, pathSegments, pathData); sl@0: } sl@0: sl@0: void CTSmallWindowOpenVG::RenderL() sl@0: { sl@0: CTWindow::RenderL(); sl@0: sl@0: // Make sure that this egl status is active sl@0: eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG); sl@0: sl@0: VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f}; sl@0: VGfloat scaleFactor = Size().iWidth/200.f; sl@0: if (Size().iHeight/200.f < scaleFactor) sl@0: { sl@0: scaleFactor = Size().iHeight/200.f; sl@0: } sl@0: sl@0: iCurrentRotation = iTime; sl@0: sl@0: if (iCurrentRotation >= 360.f) sl@0: { sl@0: iCurrentRotation -= 360.f; sl@0: } sl@0: sl@0: vgSetfv(VG_CLEAR_COLOR, 4, clearColor); sl@0: vgClear(0, 0, Size().iWidth, Size().iHeight); sl@0: sl@0: vgLoadIdentity(); sl@0: vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2); sl@0: vgScale(scaleFactor, scaleFactor); sl@0: vgRotate(iCurrentRotation); sl@0: vgTranslate(-50.f, -50.f); sl@0: sl@0: vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); sl@0: vgSeti(VG_FILL_RULE, VG_EVEN_ODD); sl@0: sl@0: vgSetPaint(iFillPaint, VG_FILL_PATH); sl@0: sl@0: vgSetf(VG_STROKE_LINE_WIDTH, 10.f); sl@0: vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); sl@0: vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); sl@0: vgSetf(VG_STROKE_MITER_LIMIT, 0.f); sl@0: vgSetPaint(iStrokePaint, VG_STROKE_PATH); sl@0: sl@0: vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH); sl@0: sl@0: iTime++; sl@0: eglSwapBuffers(iDisplay, iSurface); sl@0: } sl@0: