188 |
187 |
189 void CHuiFxVg10OffscreenRenderbuffer::ReadBackground() |
188 void CHuiFxVg10OffscreenRenderbuffer::ReadBackground() |
190 { |
189 { |
191 if (iBackgroundEnabled) |
190 if (iBackgroundEnabled) |
192 { |
191 { |
193 CHuiDisplay& display = CHuiStatic::Env().PrimaryDisplay(); |
192 TBool rotatedDisplay = EFalse; |
194 TBool rotatedDisplay = display.Orientation() == CHuiGc::EOrientationCCW90 || display.Orientation() == CHuiGc::EOrientationCW90; |
193 CHuiGc::TOrientation orientation = CHuiStatic::Env().PrimaryDisplay().Orientation(); |
195 TRect renderBufferLocation = TRect(iPosition, iSize); |
|
196 |
|
197 #ifdef HUIFX_TRACE |
|
198 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::PrepareForReuse - renderBufferLocation original: %i,%i, %i,%i "), |
|
199 renderBufferLocation.iTl.iX, |
|
200 renderBufferLocation.iTl.iY, |
|
201 renderBufferLocation.iBr.iX, |
|
202 renderBufferLocation.iBr.iY); |
|
203 #endif |
|
204 |
194 |
205 TRect displayArea = display.VisibleArea(); |
195 // The current context can be the screen context or, in case of nested effects, an "effect off-screen" |
|
196 // context. The latter uses VG image that is encapsulated inside PBuffer surface. |
|
197 // Only if we have the screen context, the surface content can be in rotated state. |
206 |
198 |
207 TInt displayHeight = displayArea.Height(); |
199 TBool isScreenContext = (iPlugin->EglSharedContext() == eglGetCurrentContext()); |
208 TInt displayWidth = displayArea.Width(); |
200 if (isScreenContext) |
209 |
201 { |
210 TSize rotatedSize = iSize; |
202 rotatedDisplay = orientation == CHuiGc::EOrientationCCW90 || orientation == CHuiGc::EOrientationCW90; |
211 TPoint rotatedPos = iPosition; |
203 } |
|
204 |
|
205 |
|
206 // Read surface size from egl |
|
207 EGLDisplay eglDisp = eglGetCurrentDisplay(); |
|
208 EGLSurface eglSurf = eglGetCurrentSurface(EGL_DRAW); |
|
209 EGLint sfWidth; |
|
210 EGLint sfHeight; |
|
211 eglQuerySurface(eglDisp, eglSurf, EGL_WIDTH, &sfWidth); |
|
212 eglQuerySurface(eglDisp, eglSurf, EGL_HEIGHT, &sfHeight); |
|
213 |
|
214 #ifdef HUIFX_TRACE |
|
215 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::ReadBackground - surface size: %i,%i "), sfWidth, sfHeight); |
|
216 #endif |
212 |
217 |
213 // Read pixels from surface |
218 // Read pixels from surface |
214 if (rotatedDisplay) |
219 if (!rotatedDisplay) |
215 { |
220 { |
216 if (iRotatedImage == VG_INVALID_HANDLE) |
221 // Much easier if no rotation ! |
|
222 vgGetPixels(iImage, 0, 0, iPosition.iX, sfHeight - (iPosition.iY + iSize.iHeight), iSize.iWidth, iSize.iHeight); |
|
223 } |
|
224 else |
|
225 { |
|
226 // If screen is rotated but surface is not in native orientation, this gets difficult |
|
227 // because vgGetPixels is not affected by transformations. |
|
228 |
|
229 // display size = surface size rotated |
|
230 TInt displayHeight = sfWidth; |
|
231 TInt displayWidth = sfHeight; |
|
232 |
|
233 TSize newRotatedImageSize = TSize(iSize.iHeight, iSize.iWidth); |
|
234 if (iRotatedImage == VG_INVALID_HANDLE || iRotatedImageSize != newRotatedImageSize) |
217 { |
235 { |
218 PushEGLContext(); |
236 PushEGLContext(); |
|
237 |
|
238 // *** Create new vg image |
|
239 |
|
240 // Remove existing vg image, if any |
|
241 if (iRotatedImage != VG_INVALID_HANDLE) |
|
242 { |
|
243 vgDestroyImage(iRotatedImage); |
|
244 iRotatedImage = VG_INVALID_HANDLE; |
|
245 HUIFX_VG_INVARIANT(); |
|
246 } |
219 |
247 |
220 #ifndef __WINS__ // Should possibly query the supported mode instead? |
248 #ifndef __WINS__ // Should possibly query the supported mode instead? |
221 VGImageFormat imageInternalFormat = VG_sARGB_8888_PRE; |
249 VGImageFormat imageInternalFormat = VG_sARGB_8888_PRE; |
222 #else |
250 #else |
223 VGImageFormat imageInternalFormat = VG_sARGB_8888; |
251 VGImageFormat imageInternalFormat = VG_sARGB_8888; |
224 #endif |
252 #endif |
225 |
253 |
226 TSize rotatedImageSize = TSize(iSize.iHeight, iSize.iWidth); |
254 iRotatedImageSize = newRotatedImageSize; |
227 iRotatedImage = vgCreateImage(imageInternalFormat, rotatedImageSize.iWidth, rotatedImageSize.iHeight, |
255 iRotatedImage = vgCreateImage(imageInternalFormat, iRotatedImageSize.iWidth, iRotatedImageSize.iHeight, |
228 VG_IMAGE_QUALITY_NONANTIALIASED); |
256 VG_IMAGE_QUALITY_NONANTIALIASED); |
|
257 //iRotatedImage = vgCreateImage(imageInternalFormat, iSize.iWidth, iSize.iHeight, |
|
258 // VG_IMAGE_QUALITY_NONANTIALIASED); |
229 |
259 |
230 PopEGLContext(); |
260 PopEGLContext(); |
231 } |
261 } |
232 |
262 |
233 |
263 |
234 // If we have rotation on CHuiGc level, we must manually take that into account when |
264 // If we have rotation on CHuiGc level, we must manually take that into account when |
235 // accessing pixels directly |
265 // accessing pixels directly |
236 if(display.Orientation() == CHuiGc::EOrientationCCW90) |
266 TSize rotatedSize = iSize; |
|
267 TPoint rotatedPos = iPosition; |
|
268 TRect renderBufferLocation = TRect(iPosition, iSize); |
|
269 if(orientation == CHuiGc::EOrientationCCW90) |
237 { |
270 { |
238 // Rotate the buffer location relative to real surface coordinates |
271 // Rotate the buffer location relative to real surface coordinates |
239 rotatedSize = TSize(iSize.iHeight, iSize.iWidth); |
272 rotatedSize = TSize(iSize.iHeight, iSize.iWidth); |
240 rotatedPos = TPoint(displayHeight - iPosition.iY - iSize.iHeight, iPosition.iX); |
273 rotatedPos = TPoint(displayHeight - iPosition.iY - iSize.iHeight, iPosition.iX); |
241 renderBufferLocation = TRect(rotatedPos, rotatedSize); |
274 renderBufferLocation = TRect(rotatedPos, rotatedSize); |
242 } |
275 } |
243 else if(display.Orientation() == CHuiGc::EOrientationCW90) |
276 else if(orientation == CHuiGc::EOrientationCW90) |
244 { |
277 { |
245 // Rotate the buffer location relative to real surface coordinates |
278 // Rotate the buffer location relative to real surface coordinates |
246 rotatedSize = TSize(iSize.iHeight, iSize.iWidth); |
279 rotatedSize = TSize(iSize.iHeight, iSize.iWidth); |
247 rotatedPos = TPoint(iPosition.iY, displayWidth - iPosition.iX - iSize.iWidth); |
280 rotatedPos = TPoint(iPosition.iY, displayWidth - iPosition.iX - iSize.iWidth); |
248 renderBufferLocation = TRect(rotatedPos, rotatedSize); |
281 renderBufferLocation = TRect(rotatedPos, rotatedSize); |
249 } |
282 } |
250 else |
283 else |
251 { |
284 { |
252 // nothing |
285 // nothing |
253 } |
286 } |
254 |
287 |
255 // If screen is rotated but surface is not in native orientation, this gets difficult |
288 #ifdef HUIFX_TRACE |
256 // because vgGetPixels is not affected by transformations. |
289 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::ReadBackground - renderBufferLocation: %i,%i, %i,%i "), |
257 |
|
258 // Swap h and w so that those are the "real" values from surface point of view. |
|
259 displayHeight = displayWidth; |
|
260 |
|
261 #ifdef HUIFX_TRACE |
|
262 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::PrepareForReuse - renderBufferLocation: %i,%i, %i,%i "), |
|
263 renderBufferLocation.iTl.iX, |
290 renderBufferLocation.iTl.iX, |
264 renderBufferLocation.iTl.iY, |
291 renderBufferLocation.iTl.iY, |
265 renderBufferLocation.iBr.iX, |
292 renderBufferLocation.iBr.iX, |
266 renderBufferLocation.iBr.iY); |
293 renderBufferLocation.iBr.iY); |
267 |
294 |
268 TRect vgRect(TPoint(renderBufferLocation.iTl.iX, displayHeight - renderBufferLocation.iTl.iY - rotatedSize.iHeight), rotatedSize); |
295 TRect vgRect(TPoint(renderBufferLocation.iTl.iX, sfHeight - renderBufferLocation.iTl.iY - rotatedSize.iHeight), rotatedSize); |
269 |
296 |
270 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::PrepareForReuse - vgRect: %i,%i, %i,%i "), |
297 RDebug::Print(_L("CHuiFxVg10OffscreenRenderbuffer::ReadBackground - vgRect: %i,%i, %i,%i "), |
271 vgRect.iTl.iX, |
298 vgRect.iTl.iX, |
272 vgRect.iTl.iY, |
299 vgRect.iTl.iY, |
273 vgRect.iBr.iX, |
300 vgRect.iBr.iX, |
274 vgRect.iBr.iY); |
301 vgRect.iBr.iY); |
275 #endif |
302 #endif |
276 |
303 |
277 // So...first get pixels from surface into rotated image |
304 // So...first get pixels from surface into rotated image |
278 vgGetPixels(iRotatedImage, 0, 0, renderBufferLocation.iTl.iX, displayHeight - renderBufferLocation.iTl.iY - rotatedSize.iHeight, rotatedSize.iWidth, rotatedSize.iHeight); |
305 vgGetPixels(iRotatedImage, 0, 0, renderBufferLocation.iTl.iX, sfHeight - (renderBufferLocation.iTl.iY + rotatedSize.iHeight), rotatedSize.iWidth, rotatedSize.iHeight); |
279 |
306 |
280 // Draw rotated image into real buffer image, first bind it as render target... |
307 // Draw rotated image into real buffer image, first bind it as render target... |
281 BindAsRenderTarget(); |
308 BindAsRenderTarget(); |
282 |
309 |
283 // ...store some states... |
310 // ...store some states... |