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