os/graphics/graphicstest/uibench/s60/src/windows/tsmallwindowopenvg.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/windows/tsmallwindowopenvg.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,189 @@
     1.4 +// Copyright (c) 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 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +
    1.26 +#include "tsmallwindowopenvg.h"
    1.27 +
    1.28 +
    1.29 +// todo: is it the right config
    1.30 +const EGLint KColorRGB565AttribList[] =
    1.31 +    {
    1.32 +    EGL_RED_SIZE,			5,
    1.33 +    EGL_GREEN_SIZE,			6,
    1.34 +    EGL_BLUE_SIZE,			5,
    1.35 +    EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
    1.36 +    EGL_RENDERABLE_TYPE, 	EGL_OPENVG_BIT,
    1.37 +    EGL_NONE
    1.38 +    };
    1.39 +
    1.40 +
    1.41 +CTWindow* CTSmallWindowOpenVG::NewL(RWsSession &aWs, 
    1.42 +        const RWindowTreeNode &aParent, 
    1.43 +        const TPoint& aStartingPoint,
    1.44 +        const TSize& aWindowSize)
    1.45 +    {
    1.46 +    CTSmallWindowOpenVG* self = new (ELeave) CTSmallWindowOpenVG(aStartingPoint, aWindowSize);
    1.47 +    CleanupStack::PushL(self);
    1.48 +    self->ConstructL(aWs, aParent);
    1.49 +    CleanupStack::Pop(self);
    1.50 +    return self;
    1.51 +    }
    1.52 +
    1.53 +CTSmallWindowOpenVG::CTSmallWindowOpenVG(const TPoint& aStartingPoint, const TSize& aWindowSize):
    1.54 +        CTWindow(aStartingPoint, aWindowSize)
    1.55 +	{
    1.56 +	// empty
    1.57 +	}
    1.58 +
    1.59 +CTSmallWindowOpenVG::~CTSmallWindowOpenVG()
    1.60 +	{
    1.61 +	// Make sure that this egl status is active
    1.62 +	eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
    1.63 +    vgDestroyPaint(iFillPaint);
    1.64 +    vgDestroyPaint(iStrokePaint);
    1.65 +    vgDestroyPath(iPath);
    1.66 +	if (iContextVG != EGL_NO_CONTEXT)
    1.67 +		{
    1.68 +		eglDestroyContext(iDisplay,iContextVG);
    1.69 +		}
    1.70 +	if (iSurface != EGL_NO_SURFACE)
    1.71 +		{
    1.72 +		eglDestroySurface(iDisplay,iSurface);
    1.73 +		}	
    1.74 +	// Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed. 
    1.75 +	eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    1.76 +	//eglTerminate(iDisplay);
    1.77 +	eglReleaseThread();
    1.78 +	}
    1.79 +
    1.80 +
    1.81 +
    1.82 +void CTSmallWindowOpenVG::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
    1.83 +	{
    1.84 +	CTWindow::ConstructL(aWs, aParent);
    1.85 +	
    1.86 +	iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    1.87 +	eglInitialize(iDisplay, NULL, NULL);
    1.88 +	
    1.89 +	EGLint numConfigs;
    1.90 +	EGLConfig chosenConfig = 0;
    1.91 +
    1.92 +	// Choose the config to use
    1.93 +	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 +	eglBindAPI(EGL_OPENVG_API);
   1.102 +	iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
   1.103 +
   1.104 +	// Create context to store surface settings
   1.105 +	iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
   1.106 +	
   1.107 +	eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);	
   1.108 +	
   1.109 +    VGfloat strokeColor[4]  = {1.f, 0.f, 0.f, 1.f};
   1.110 +    VGfloat fillColor[4]    = {0.f, 0.f, 1.f, 1.f};
   1.111 +
   1.112 +    VGubyte pathSegments[6] =
   1.113 +        {
   1.114 +        VG_LINE_TO | (int)VG_ABSOLUTE,
   1.115 +        VG_LINE_TO | (int)VG_ABSOLUTE,
   1.116 +        VG_LINE_TO | (int)VG_ABSOLUTE,
   1.117 +        VG_LINE_TO | (int)VG_ABSOLUTE,
   1.118 +        VG_CLOSE_PATH
   1.119 +        };
   1.120 +
   1.121 +    VGfloat pathData[10] =
   1.122 +        {
   1.123 +          0.f, 100.f,
   1.124 +        100.f, 100.f,
   1.125 +        100.f,   0.f,
   1.126 +          0.f,   0.f
   1.127 +        };
   1.128 +
   1.129 +    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
   1.130 +
   1.131 +    iCurrentRotation = 0.f;
   1.132 +    iStrokePaint = vgCreatePaint();
   1.133 +    iFillPaint   = vgCreatePaint();
   1.134 +
   1.135 +    vgSetParameteri(iStrokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.136 +    vgSetParameterfv(iStrokePaint, VG_PAINT_COLOR, 4, strokeColor);
   1.137 +
   1.138 +    vgSetParameteri(iFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.139 +    vgSetParameterfv(iFillPaint, VG_PAINT_COLOR, 4, fillColor);
   1.140 +
   1.141 +    iPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL);
   1.142 +
   1.143 +    vgAppendPathData(iPath, 4, pathSegments, pathData);
   1.144 +	}
   1.145 +
   1.146 +void CTSmallWindowOpenVG::RenderL()
   1.147 +	{
   1.148 +	CTWindow::RenderL();
   1.149 +
   1.150 +	// Make sure that this egl status is active
   1.151 +	eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
   1.152 +
   1.153 +    VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f};
   1.154 +    VGfloat scaleFactor = Size().iWidth/200.f;
   1.155 +    if (Size().iHeight/200.f < scaleFactor)
   1.156 +        {
   1.157 +        scaleFactor = Size().iHeight/200.f;
   1.158 +        }        
   1.159 +
   1.160 +    iCurrentRotation = iTime;
   1.161 +
   1.162 +    if (iCurrentRotation >= 360.f)
   1.163 +        {
   1.164 +        iCurrentRotation -= 360.f;
   1.165 +        }
   1.166 +
   1.167 +    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
   1.168 +    vgClear(0, 0, Size().iWidth, Size().iHeight);
   1.169 +
   1.170 +    vgLoadIdentity();
   1.171 +    vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2);
   1.172 +    vgScale(scaleFactor, scaleFactor);
   1.173 +    vgRotate(iCurrentRotation);
   1.174 +    vgTranslate(-50.f, -50.f);
   1.175 +
   1.176 +    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   1.177 +    vgSeti(VG_FILL_RULE, VG_EVEN_ODD);
   1.178 +
   1.179 +    vgSetPaint(iFillPaint, VG_FILL_PATH);
   1.180 +
   1.181 +    vgSetf(VG_STROKE_LINE_WIDTH, 10.f);
   1.182 +    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
   1.183 +    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
   1.184 +    vgSetf(VG_STROKE_MITER_LIMIT, 0.f);
   1.185 +    vgSetPaint(iStrokePaint, VG_STROKE_PATH);
   1.186 +
   1.187 +    vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH);
   1.188 +
   1.189 +	iTime++;
   1.190 +	eglSwapBuffers(iDisplay, iSurface);
   1.191 +	}
   1.192 +