uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10OffscreenRenderbuffer.cpp
branchRCL_3
changeset 17 3ac8bf5c5014
parent 0 15bf7259bb7c
child 50 1801340c26a2
child 60 5dafecb0892a
equal deleted inserted replaced
11:46927d61fef3 17:3ac8bf5c5014
    67     EGLConfig config = iPlugin->EglConfig(0);
    67     EGLConfig config = iPlugin->EglConfig(0);
    68     
    68     
    69     // Create a context
    69     // Create a context
    70     iContext = eglCreateContext(iPlugin->EglDisplay(), config,
    70     iContext = eglCreateContext(iPlugin->EglDisplay(), config,
    71             iPlugin->EglSharedContext(), NULL);
    71             iPlugin->EglSharedContext(), NULL);
    72     EGLint err = eglGetError();
       
    73     ASSERT(iContext);
    72     ASSERT(iContext);
    74     
    73     
    75     // Create a pbuffer surface
    74     // Create a pbuffer surface
    76     iSurface = eglCreatePbufferFromClientBuffer(iPlugin->EglDisplay(), EGL_OPENVG_IMAGE,
    75     iSurface = eglCreatePbufferFromClientBuffer(iPlugin->EglDisplay(), EGL_OPENVG_IMAGE,
    77                                                 iImage, config, NULL);
    76                                                 iImage, config, NULL);
   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...
   293 
   320 
   294             TInt w = iSize.iWidth;
   321             TInt w = iSize.iWidth;
   295             TInt h = iSize.iHeight;
   322             TInt h = iSize.iHeight;
   296             
   323             
   297             // ...select right rotation...
   324             // ...select right rotation...
   298             if (display.Orientation() == CHuiGc::EOrientationCW90)
   325             if (orientation == CHuiGc::EOrientationCW90)
   299                 {
   326                 {
   300                 // Rotate around origo and move back to displayarea
   327                 // Rotate around origo and move back to displayarea
   301                 vgRotate(-90);
   328                 vgRotate(-90);
   302                 vgTranslate(-h, 0);
   329                 vgTranslate(-h, 0);
   303                 }
   330                 }
   304             else if (display.Orientation() == CHuiGc::EOrientationCCW90)
   331             else if (orientation == CHuiGc::EOrientationCCW90)
   305                 {
   332                 {
   306                 // Rotate around origo and move back to displayarea
   333                 // Rotate around origo and move back to displayarea
   307                 vgRotate(90);
   334                 vgRotate(90);
   308                 vgTranslate(0, -w);
   335                 vgTranslate(0, -w);
   309                 }
   336                 }
   310             else if (display.Orientation() == CHuiGc::EOrientation180)
   337             else if (orientation == CHuiGc::EOrientation180)
   311                 {
   338                 {
   312                 // Rotate around origo and move back to displayarea
   339                 // Rotate around origo and move back to displayarea
   313                 vgRotate(180);
   340                 vgRotate(180);
   314                 vgTranslate(-w, -h);            
   341                 vgTranslate(-w, -h);            
   315                 }
   342                 }
   328             vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   355             vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   329             vgLoadMatrix(oldMatrix);
   356             vgLoadMatrix(oldMatrix);
   330 
   357 
   331             // ...finally unbind image and we should have the content correctly.
   358             // ...finally unbind image and we should have the content correctly.
   332             UnbindAsRenderTarget();
   359             UnbindAsRenderTarget();
   333             }
       
   334         else
       
   335             {
       
   336             // Much easier if no rotation !
       
   337             vgGetPixels(iImage, 0, 0, renderBufferLocation.iTl.iX, displayHeight - renderBufferLocation.iTl.iY - rotatedSize.iHeight, rotatedSize.iWidth, rotatedSize.iHeight);
       
   338             }
   360             }
   339         }    
   361         }    
   340     }
   362     }
   341 
   363 
   342 void CHuiFxVg10OffscreenRenderbuffer::PushEGLContext()
   364 void CHuiFxVg10OffscreenRenderbuffer::PushEGLContext()