Update contrib.
1 // Copyright (c) 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.
19 @internalComponent - Internal Symbian test code
23 #include "tsmallwindowopenvg.h"
26 // todo: is it the right config
27 const EGLint KColorRGB565AttribList[] =
32 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
33 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
38 CTWindow* CTSmallWindowOpenVG::NewL(RWsSession &aWs,
39 const RWindowTreeNode &aParent,
40 const TPoint& aStartingPoint,
41 const TSize& aWindowSize)
43 CTSmallWindowOpenVG* self = new (ELeave) CTSmallWindowOpenVG(aStartingPoint, aWindowSize);
44 CleanupStack::PushL(self);
45 self->ConstructL(aWs, aParent);
46 CleanupStack::Pop(self);
50 CTSmallWindowOpenVG::CTSmallWindowOpenVG(const TPoint& aStartingPoint, const TSize& aWindowSize):
51 CTWindow(aStartingPoint, aWindowSize)
56 CTSmallWindowOpenVG::~CTSmallWindowOpenVG()
58 // Make sure that this egl status is active
59 eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
60 vgDestroyPaint(iFillPaint);
61 vgDestroyPaint(iStrokePaint);
63 if (iContextVG != EGL_NO_CONTEXT)
65 eglDestroyContext(iDisplay,iContextVG);
67 if (iSurface != EGL_NO_SURFACE)
69 eglDestroySurface(iDisplay,iSurface);
71 // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
72 eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
73 //eglTerminate(iDisplay);
79 void CTSmallWindowOpenVG::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
81 CTWindow::ConstructL(aWs, aParent);
83 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
84 eglInitialize(iDisplay, NULL, NULL);
87 EGLConfig chosenConfig = 0;
89 // Choose the config to use
90 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 eglBindAPI(EGL_OPENVG_API);
99 iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
101 // Create context to store surface settings
102 iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
104 eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
106 VGfloat strokeColor[4] = {1.f, 0.f, 0.f, 1.f};
107 VGfloat fillColor[4] = {0.f, 0.f, 1.f, 1.f};
109 VGubyte pathSegments[6] =
111 VG_LINE_TO | (int)VG_ABSOLUTE,
112 VG_LINE_TO | (int)VG_ABSOLUTE,
113 VG_LINE_TO | (int)VG_ABSOLUTE,
114 VG_LINE_TO | (int)VG_ABSOLUTE,
118 VGfloat pathData[10] =
126 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
128 iCurrentRotation = 0.f;
129 iStrokePaint = vgCreatePaint();
130 iFillPaint = vgCreatePaint();
132 vgSetParameteri(iStrokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
133 vgSetParameterfv(iStrokePaint, VG_PAINT_COLOR, 4, strokeColor);
135 vgSetParameteri(iFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
136 vgSetParameterfv(iFillPaint, VG_PAINT_COLOR, 4, fillColor);
138 iPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL);
140 vgAppendPathData(iPath, 4, pathSegments, pathData);
143 void CTSmallWindowOpenVG::RenderL()
147 // Make sure that this egl status is active
148 eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
150 VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f};
151 VGfloat scaleFactor = Size().iWidth/200.f;
152 if (Size().iHeight/200.f < scaleFactor)
154 scaleFactor = Size().iHeight/200.f;
157 iCurrentRotation = iTime;
159 if (iCurrentRotation >= 360.f)
161 iCurrentRotation -= 360.f;
164 vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
165 vgClear(0, 0, Size().iWidth, Size().iHeight);
168 vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2);
169 vgScale(scaleFactor, scaleFactor);
170 vgRotate(iCurrentRotation);
171 vgTranslate(-50.f, -50.f);
173 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
174 vgSeti(VG_FILL_RULE, VG_EVEN_ODD);
176 vgSetPaint(iFillPaint, VG_FILL_PATH);
178 vgSetf(VG_STROKE_LINE_WIDTH, 10.f);
179 vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
180 vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
181 vgSetf(VG_STROKE_MITER_LIMIT, 0.f);
182 vgSetPaint(iStrokePaint, VG_STROKE_PATH);
184 vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH);
187 eglSwapBuffers(iDisplay, iSurface);