|
1 // Copyright (c) 2010 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 #include <string.h> |
|
16 #include "eglrendering.h" |
|
17 #include "openvgengine.h" |
|
18 #include <hal.h> |
|
19 |
|
20 const TInt KTimerDelay = 0; |
|
21 |
|
22 |
|
23 /** Attributes to be passed into eglChooseConfig */ |
|
24 const EGLint KColorRGB565AttribList[] = |
|
25 { |
|
26 EGL_RED_SIZE, 5, |
|
27 EGL_GREEN_SIZE, 6, |
|
28 EGL_BLUE_SIZE, 5, |
|
29 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
|
30 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, |
|
31 EGL_NONE |
|
32 }; |
|
33 |
|
34 |
|
35 CEGLRendering* CEGLRendering::NewL(RWindow& aWindow, TBool aQhd) |
|
36 { |
|
37 CEGLRendering* self = CEGLRendering::NewLC(aWindow, aQhd); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 CEGLRendering* CEGLRendering::NewLC(RWindow& aWindow, TBool aQhd) |
|
44 { |
|
45 CEGLRendering* self = new(ELeave) CEGLRendering(aWindow); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aQhd); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CEGLRendering::~CEGLRendering() |
|
52 { |
|
53 Stop(); |
|
54 |
|
55 delete iTimer; |
|
56 |
|
57 if (iContextVG!=EGL_NO_CONTEXT) |
|
58 { |
|
59 EGLCheckReturnError(eglDestroyContext(iDisplay,iContextVG)); |
|
60 } |
|
61 |
|
62 if (iSurface!=EGL_NO_SURFACE) |
|
63 { |
|
64 EGLCheckReturnError(eglDestroySurface(iDisplay,iSurface)); |
|
65 } |
|
66 |
|
67 // Call eglMakeCurrent() to ensure the surfaces and contexts are truly destroyed. |
|
68 EGLCheckReturnError(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); |
|
69 |
|
70 EGLCheckReturnError(eglTerminate(iDisplay)); |
|
71 EGLCheckReturnError(eglReleaseThread()); |
|
72 |
|
73 delete iBitmap; |
|
74 } |
|
75 |
|
76 void CEGLRendering::Start() |
|
77 { |
|
78 // Start drawing the screen periodically |
|
79 iTimer->Start(0, KTimerDelay, TCallBack(TimerCallBack,this)); |
|
80 } |
|
81 |
|
82 void CEGLRendering::Stop() |
|
83 { |
|
84 if(iTimer) |
|
85 { |
|
86 iTimer->Cancel(); |
|
87 } |
|
88 } |
|
89 |
|
90 void CEGLRendering::EGLCheckError() |
|
91 { |
|
92 EGLint error = eglGetError(); |
|
93 if(error != EGL_SUCCESS) |
|
94 { |
|
95 User::Panic(_L("EGL error"), error); |
|
96 } |
|
97 } |
|
98 |
|
99 void CEGLRendering::VGCheckError() |
|
100 { |
|
101 VGint error = vgGetError(); |
|
102 if(error != VG_NO_ERROR) |
|
103 { |
|
104 User::Panic(_L("OpenVG error"), error); |
|
105 } |
|
106 } |
|
107 |
|
108 void CEGLRendering::EGLCheckReturnError(EGLBoolean aBool) |
|
109 { |
|
110 if (!aBool) |
|
111 { |
|
112 User::Panic(_L("EGL return error"),eglGetError()); |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 CEGLRendering::CEGLRendering(RWindow& aWindow) |
|
118 : iWindow(aWindow),iCount(0) |
|
119 { |
|
120 } |
|
121 |
|
122 /* |
|
123 * Construct EGL objects, and OpenVG binding. |
|
124 * |
|
125 * Here we collaborate with EGL to associate a session, pick and configuration, assign |
|
126 * it to the window we have, and then bind the OpenVG rendering API to our newly created |
|
127 * context. |
|
128 * |
|
129 * In bring up terms, here is where the first EGL code entry points are called from. Its |
|
130 * the natural point where an EGL bringup starts debugging from, assuming the core EGL |
|
131 * works in terms of supporting EGL sync objects (needed for boot before we get to the |
|
132 * ESHELL command prompt). |
|
133 */ |
|
134 void CEGLRendering::ConstructL(TBool aQhd) |
|
135 { |
|
136 RDebug::Printf("CEGLRendering::ConstructL"); |
|
137 |
|
138 // Refresh timer |
|
139 iTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
140 |
|
141 const TDisplayMode dispMode = iWindow.DisplayMode(); |
|
142 const TSize windowSize(iWindow.Size()); |
|
143 |
|
144 // Create display object |
|
145 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
|
146 RDebug::Printf("CEGLRendering::ConstructL 1"); |
|
147 EGLCheckError(); |
|
148 |
|
149 // Initialize display object |
|
150 EGLCheckReturnError(eglInitialize(iDisplay, NULL, NULL)); |
|
151 RDebug::Printf("CEGLRendering::ConstructL 2"); |
|
152 |
|
153 RDebug::Printf("Vendor string %s", eglQueryString(iDisplay, EGL_VENDOR)); |
|
154 RDebug::Printf("Version string %s", eglQueryString(iDisplay, EGL_VERSION)); |
|
155 RDebug::Printf("Version string %s", eglQueryString(iDisplay, EGL_EXTENSIONS)); |
|
156 |
|
157 |
|
158 // Check that EGL provides the capabilities for this app. |
|
159 TInt error = KErrNone; |
|
160 if ( NULL == strstr(eglQueryString(iDisplay, EGL_CLIENT_APIS), "OpenVG") ) |
|
161 { |
|
162 RDebug::Printf("OpenVG not listed in supported client APIs %s", eglQueryString(iDisplay, EGL_CLIENT_APIS)); |
|
163 error = KErrNotSupported; |
|
164 } |
|
165 |
|
166 |
|
167 if ( NULL == strstr(eglQueryString(iDisplay, EGL_EXTENSIONS), "EGL_SYMBIAN_COMPOSITION") ) |
|
168 { |
|
169 RDebug::Printf("EGL_SYMBIAN_COMPOSITION not listed in extension string %s", eglQueryString(iDisplay, EGL_EXTENSIONS)); |
|
170 error = KErrNotSupported; |
|
171 } |
|
172 if (error != KErrNone) |
|
173 { |
|
174 User::Leave(error); |
|
175 } |
|
176 |
|
177 EGLint numConfigs; |
|
178 EGLConfig chosenConfig = 0; |
|
179 |
|
180 // Choose the config to use |
|
181 EGLCheckReturnError(eglChooseConfig(iDisplay, KColorRGB565AttribList, &chosenConfig, 1, &numConfigs)); |
|
182 RDebug::Printf("CEGLRendering::ConstructL 3"); |
|
183 if (numConfigs == 0) |
|
184 { |
|
185 RDebug::Printf("No matching configs found", eglQueryString(iDisplay, EGL_EXTENSIONS)); |
|
186 User::Leave(KErrNotSupported); |
|
187 } |
|
188 |
|
189 // Create window surface to draw direct to. |
|
190 EGLCheckReturnError(eglBindAPI(EGL_OPENVG_API)); |
|
191 RDebug::Printf("CEGLRendering::ConstructL 4"); |
|
192 iSurface = eglCreateWindowSurface(iDisplay, chosenConfig, &iWindow, NULL); |
|
193 RDebug::Printf("CEGLRendering::ConstructL 5"); |
|
194 EGLCheckError(); |
|
195 |
|
196 TInt redSize, greenSize, blueSize, alphaSize; |
|
197 |
|
198 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_ALPHA_SIZE, &alphaSize)); |
|
199 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_RED_SIZE, &redSize)); |
|
200 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_GREEN_SIZE, &greenSize)); |
|
201 EGLCheckReturnError(eglGetConfigAttrib(iDisplay, chosenConfig, EGL_BLUE_SIZE, &blueSize)); |
|
202 RDebug::Print(_L("EGLConfig id:%d alpha:%d red:%d green:%d blue:%d"), chosenConfig, |
|
203 alphaSize, redSize, greenSize, blueSize); |
|
204 RDebug::Printf("CEGLRendering::ConstructL 6"); |
|
205 |
|
206 // Create context to store surface settings |
|
207 iContextVG = eglCreateContext(iDisplay, chosenConfig, EGL_NO_CONTEXT, NULL); |
|
208 RDebug::Printf("CEGLRendering::ConstructL 7"); |
|
209 EGLCheckError(); |
|
210 |
|
211 CEGLRendering::EGLCheckReturnError(eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG)); |
|
212 RDebug::Printf("CEGLRendering::ConstructL 8"); |
|
213 } |
|
214 |
|
215 |
|
216 /** Update the display */ |
|
217 void CEGLRendering::UpdateDisplay() |
|
218 { |
|
219 // Flush colour buffer to the window surface |
|
220 CEGLRendering::EGLCheckReturnError(eglSwapBuffers(iDisplay, iSurface)); |
|
221 } |
|
222 |
|
223 /** Callback called by refresh timer */ |
|
224 TInt CEGLRendering::TimerCallBack(TAny* aDemo) |
|
225 { |
|
226 |
|
227 static_cast<CEGLRendering*>(aDemo)->UpdateDisplay(); |
|
228 return KErrNone; |
|
229 } |