sl@0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@test
|
sl@0
|
19 |
@internalComponent - Internal Symbian test code
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "tsmallwindowopenvg.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
// todo: is it the right config
|
sl@0
|
27 |
const EGLint KColorRGB565AttribList[] =
|
sl@0
|
28 |
{
|
sl@0
|
29 |
EGL_RED_SIZE, 5,
|
sl@0
|
30 |
EGL_GREEN_SIZE, 6,
|
sl@0
|
31 |
EGL_BLUE_SIZE, 5,
|
sl@0
|
32 |
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
sl@0
|
33 |
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
|
sl@0
|
34 |
EGL_NONE
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
CTWindow* CTSmallWindowOpenVG::NewL(RWsSession &aWs,
|
sl@0
|
39 |
const RWindowTreeNode &aParent,
|
sl@0
|
40 |
const TPoint& aStartingPoint,
|
sl@0
|
41 |
const TSize& aWindowSize)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
CTSmallWindowOpenVG* self = new (ELeave) CTSmallWindowOpenVG(aStartingPoint, aWindowSize);
|
sl@0
|
44 |
CleanupStack::PushL(self);
|
sl@0
|
45 |
self->ConstructL(aWs, aParent);
|
sl@0
|
46 |
CleanupStack::Pop(self);
|
sl@0
|
47 |
return self;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CTSmallWindowOpenVG::CTSmallWindowOpenVG(const TPoint& aStartingPoint, const TSize& aWindowSize):
|
sl@0
|
51 |
CTWindow(aStartingPoint, aWindowSize)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
// empty
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
CTSmallWindowOpenVG::~CTSmallWindowOpenVG()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
// Make sure that this egl status is active
|
sl@0
|
59 |
eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
|
sl@0
|
60 |
vgDestroyPaint(iFillPaint);
|
sl@0
|
61 |
vgDestroyPaint(iStrokePaint);
|
sl@0
|
62 |
vgDestroyPath(iPath);
|
sl@0
|
63 |
if (iContextVG != EGL_NO_CONTEXT)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
eglDestroyContext(iDisplay,iContextVG);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
if (iSurface != EGL_NO_SURFACE)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
eglDestroySurface(iDisplay,iSurface);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
// Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed.
|
sl@0
|
72 |
eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
sl@0
|
73 |
//eglTerminate(iDisplay);
|
sl@0
|
74 |
eglReleaseThread();
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
void CTSmallWindowOpenVG::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
CTWindow::ConstructL(aWs, aParent);
|
sl@0
|
82 |
|
sl@0
|
83 |
iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
sl@0
|
84 |
eglInitialize(iDisplay, NULL, NULL);
|
sl@0
|
85 |
|
sl@0
|
86 |
EGLint numConfigs;
|
sl@0
|
87 |
EGLConfig chosenConfig = 0;
|
sl@0
|
88 |
|
sl@0
|
89 |
// Choose the config to use
|
sl@0
|
90 |
eglChooseConfig(iDisplay, KColorRGB565AttribList, &chosenConfig, 1, &numConfigs);
|
sl@0
|
91 |
if (numConfigs == 0)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS));
|
sl@0
|
94 |
User::Leave(KErrNotSupported);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
// Create window surface to draw direct to.
|
sl@0
|
98 |
eglBindAPI(EGL_OPENVG_API);
|
sl@0
|
99 |
iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL);
|
sl@0
|
100 |
|
sl@0
|
101 |
// Create context to store surface settings
|
sl@0
|
102 |
iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL);
|
sl@0
|
103 |
|
sl@0
|
104 |
eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
|
sl@0
|
105 |
|
sl@0
|
106 |
VGfloat strokeColor[4] = {1.f, 0.f, 0.f, 1.f};
|
sl@0
|
107 |
VGfloat fillColor[4] = {0.f, 0.f, 1.f, 1.f};
|
sl@0
|
108 |
|
sl@0
|
109 |
VGubyte pathSegments[6] =
|
sl@0
|
110 |
{
|
sl@0
|
111 |
VG_LINE_TO | (int)VG_ABSOLUTE,
|
sl@0
|
112 |
VG_LINE_TO | (int)VG_ABSOLUTE,
|
sl@0
|
113 |
VG_LINE_TO | (int)VG_ABSOLUTE,
|
sl@0
|
114 |
VG_LINE_TO | (int)VG_ABSOLUTE,
|
sl@0
|
115 |
VG_CLOSE_PATH
|
sl@0
|
116 |
};
|
sl@0
|
117 |
|
sl@0
|
118 |
VGfloat pathData[10] =
|
sl@0
|
119 |
{
|
sl@0
|
120 |
0.f, 100.f,
|
sl@0
|
121 |
100.f, 100.f,
|
sl@0
|
122 |
100.f, 0.f,
|
sl@0
|
123 |
0.f, 0.f
|
sl@0
|
124 |
};
|
sl@0
|
125 |
|
sl@0
|
126 |
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
|
sl@0
|
127 |
|
sl@0
|
128 |
iCurrentRotation = 0.f;
|
sl@0
|
129 |
iStrokePaint = vgCreatePaint();
|
sl@0
|
130 |
iFillPaint = vgCreatePaint();
|
sl@0
|
131 |
|
sl@0
|
132 |
vgSetParameteri(iStrokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
sl@0
|
133 |
vgSetParameterfv(iStrokePaint, VG_PAINT_COLOR, 4, strokeColor);
|
sl@0
|
134 |
|
sl@0
|
135 |
vgSetParameteri(iFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
sl@0
|
136 |
vgSetParameterfv(iFillPaint, VG_PAINT_COLOR, 4, fillColor);
|
sl@0
|
137 |
|
sl@0
|
138 |
iPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 4, 4, (unsigned int)VG_PATH_CAPABILITY_ALL);
|
sl@0
|
139 |
|
sl@0
|
140 |
vgAppendPathData(iPath, 4, pathSegments, pathData);
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
void CTSmallWindowOpenVG::RenderL()
|
sl@0
|
144 |
{
|
sl@0
|
145 |
CTWindow::RenderL();
|
sl@0
|
146 |
|
sl@0
|
147 |
// Make sure that this egl status is active
|
sl@0
|
148 |
eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);
|
sl@0
|
149 |
|
sl@0
|
150 |
VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f};
|
sl@0
|
151 |
VGfloat scaleFactor = Size().iWidth/200.f;
|
sl@0
|
152 |
if (Size().iHeight/200.f < scaleFactor)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
scaleFactor = Size().iHeight/200.f;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
iCurrentRotation = iTime;
|
sl@0
|
158 |
|
sl@0
|
159 |
if (iCurrentRotation >= 360.f)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
iCurrentRotation -= 360.f;
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
|
sl@0
|
165 |
vgClear(0, 0, Size().iWidth, Size().iHeight);
|
sl@0
|
166 |
|
sl@0
|
167 |
vgLoadIdentity();
|
sl@0
|
168 |
vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2);
|
sl@0
|
169 |
vgScale(scaleFactor, scaleFactor);
|
sl@0
|
170 |
vgRotate(iCurrentRotation);
|
sl@0
|
171 |
vgTranslate(-50.f, -50.f);
|
sl@0
|
172 |
|
sl@0
|
173 |
vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
|
sl@0
|
174 |
vgSeti(VG_FILL_RULE, VG_EVEN_ODD);
|
sl@0
|
175 |
|
sl@0
|
176 |
vgSetPaint(iFillPaint, VG_FILL_PATH);
|
sl@0
|
177 |
|
sl@0
|
178 |
vgSetf(VG_STROKE_LINE_WIDTH, 10.f);
|
sl@0
|
179 |
vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
|
sl@0
|
180 |
vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
|
sl@0
|
181 |
vgSetf(VG_STROKE_MITER_LIMIT, 0.f);
|
sl@0
|
182 |
vgSetPaint(iStrokePaint, VG_STROKE_PATH);
|
sl@0
|
183 |
|
sl@0
|
184 |
vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH);
|
sl@0
|
185 |
|
sl@0
|
186 |
iTime++;
|
sl@0
|
187 |
eglSwapBuffers(iDisplay, iSurface);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|