uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp
changeset 13 8f67d927ea57
parent 0 15bf7259bb7c
child 14 83d2d132aa58
equal deleted inserted replaced
0:15bf7259bb7c 13:8f67d927ea57
    27 #include "uiacceltk/HuiEnv.h"
    27 #include "uiacceltk/HuiEnv.h"
    28 #include "uiacceltk/HuiTextureManager.h"
    28 #include "uiacceltk/HuiTextureManager.h"
    29 #include "uiacceltk/HuiTextureProcessor.h"
    29 #include "uiacceltk/HuiTextureProcessor.h"
    30 #include "uiacceltk/HuiUtil.h"
    30 #include "uiacceltk/HuiUtil.h"
    31 #include "uiacceltk/HuiPanic.h"
    31 #include "uiacceltk/HuiPanic.h"
       
    32 
       
    33 #include "huiextension.h"
    32 
    34 
    33 // temporary hack until the openvg headers are fixed..
    35 // temporary hack until the openvg headers are fixed..
    34 #ifndef OPENVG_VERSION_1_0_1
    36 #ifndef OPENVG_VERSION_1_0_1
    35     #warning using temporary hack to define OPENVG_VERSION_1_0_1, see TSW: SKYA-7QQB8
    37     #warning using temporary hack to define OPENVG_VERSION_1_0_1, see TSW: SKYA-7QQB8
    36     #define OPENVG_VERSION_1_0_1
    38     #define OPENVG_VERSION_1_0_1
   876         }
   878         }
   877     }
   879     }
   878     
   880     
   879 void CHuiVg10Texture::TextureExtension(const TUid& aExtensionUid, TAny** aExtensionParameters)
   881 void CHuiVg10Texture::TextureExtension(const TUid& aExtensionUid, TAny** aExtensionParameters)
   880     {
   882     {
   881 	CHuiTexture::TextureExtension(aExtensionUid, aExtensionParameters);    	
   883     if ( aExtensionUid == KHuiTexturePartialBitmapUploadUid && 
       
   884          aExtensionParameters && *aExtensionParameters )
       
   885         {
       
   886         THuiTexturePartialBitmapUploadParams* params = 
       
   887             static_cast<THuiTexturePartialBitmapUploadParams*>(*aExtensionParameters);
       
   888         PartialBitmapUpload(params);
       
   889         }
       
   890     else
       
   891         {
       
   892 	    CHuiTexture::TextureExtension(aExtensionUid, aExtensionParameters);    	
       
   893 	    }
   882     }
   894     }
   883 
   895 
   884 void CHuiVg10Texture::EnableShadow(TBool aEnable)
   896 void CHuiVg10Texture::EnableShadow(TBool aEnable)
   885     {
   897     {
   886     CHuiTexture::EnableShadow(aEnable);
   898     CHuiTexture::EnableShadow(aEnable);
   999         default:
  1011         default:
  1000             break;
  1012             break;
  1001         }
  1013         }
  1002 
  1014 
  1003     HUI_VG_INVARIANT();
  1015     HUI_VG_INVARIANT();
       
  1016     }
       
  1017 
       
  1018 void CHuiVg10Texture::PartialBitmapUpload(THuiTexturePartialBitmapUploadParams* aParams)
       
  1019     {
       
  1020     if ( !aParams->iBitmap || !aParams->iBitmap->Handle() ||
       
  1021          aParams->iBitmap->DisplayMode() != EColor16MAP )
       
  1022         {
       
  1023         // Only specific format supported.
       
  1024         aParams->iErrorCode = KErrArgument;
       
  1025         return;
       
  1026         }
       
  1027         
       
  1028     if ( SegmentCount() != 1 || ((VGImage)SegmentName(0)) == VG_INVALID_HANDLE || 
       
  1029          Size() != aParams->iBitmap->SizeInPixels() )
       
  1030         {
       
  1031         // You must perform initial upload using normal methods.
       
  1032         aParams->iErrorCode = KErrNotReady;
       
  1033         return;
       
  1034         }
       
  1035     
       
  1036     //TRect segmentRect(SegmentSize(0));
       
  1037     TRect segmentRect(Size());
       
  1038     TRect rect(aParams->iRect);
       
  1039     rect.Intersection(segmentRect);
       
  1040     
       
  1041     if ( rect != aParams->iRect )
       
  1042         {
       
  1043         // Rect must be fully within segment rect
       
  1044         aParams->iErrorCode = KErrArgument;
       
  1045         return;        
       
  1046         }
       
  1047 
       
  1048     aParams->iErrorCode = KErrNone;
       
  1049     
       
  1050     if ( rect.IsEmpty() )
       
  1051         {
       
  1052         // Nothing to upload.
       
  1053         return;
       
  1054         }
       
  1055 
       
  1056     PushEGLContext();
       
  1057     aParams->iBitmap->BeginDataAccess();
       
  1058 
       
  1059     const TInt scanLineLength = CFbsBitmap::ScanLineLength(
       
  1060         aParams->iBitmap->SizeInPixels().iWidth, EColor16MAP);
       
  1061     const TInt bytesPerPixel = 4;
       
  1062     
       
  1063     TUint8* dataAddress = (TUint8*)aParams->iBitmap->DataAddress();
       
  1064     dataAddress += rect.iTl.iX * bytesPerPixel;
       
  1065     dataAddress += rect.iTl.iY * scanLineLength;
       
  1066         
       
  1067     vgImageSubData(
       
  1068         (VGImage)SegmentName(0), // image
       
  1069         dataAddress,             // data
       
  1070         scanLineLength,          // dataStride
       
  1071         VG_sARGB_8888_PRE,       // dataFormat
       
  1072         rect.iTl.iX,             // x
       
  1073         rect.iTl.iY,             // y
       
  1074         rect.Width(),            // width
       
  1075         rect.Height()            // height
       
  1076         );
       
  1077     
       
  1078     aParams->iBitmap->EndDataAccess( ETrue );
       
  1079     PopEGLContext();
  1004     }
  1080     }
  1005 
  1081 
  1006 #ifdef __NVG
  1082 #ifdef __NVG
  1007 HBufC8* CHuiVg10Texture::ReadNVGDataL(const CFbsBitmap& aBitmap)
  1083 HBufC8* CHuiVg10Texture::ReadNVGDataL(const CFbsBitmap& aBitmap)
  1008     {
  1084     {
  1080         // Create the real image from NVG databuf
  1156         // Create the real image from NVG databuf
  1081         iNVGData = dataBuf;
  1157         iNVGData = dataBuf;
  1082         image = CreateRenderedImage(&nvgEngine, dataBuf, Size());
  1158         image = CreateRenderedImage(&nvgEngine, dataBuf, Size());
  1083         
  1159         
  1084         // New functionality for checking the mask
  1160         // New functionality for checking the mask
  1085         if (header.GetBitmapId() != maskHeader.GetBitmapId() &&
  1161         if (header.GetBitmapId() != maskHeader.GetBitmapId() && maskDataBuf &&
  1086             CompareNvgData(dataBuf, maskDataBuf) != 0)
  1162             CompareNvgData(dataBuf, maskDataBuf) != 0)
  1087             {
  1163             {
  1088             VGImage maskImg = VG_INVALID_HANDLE;
  1164             VGImage maskImg = VG_INVALID_HANDLE;
  1089             // The mask is from different bitmap => we have to create
  1165             // The mask is from different bitmap => we have to create
  1090             // a separate mask image for masking the NVG icon
  1166             // a separate mask image for masking the NVG icon
  1434     }
  1510     }
  1435 
  1511 
  1436 TSize CHuiVg10Texture::ApplyMargin(VGImage aImage, TSize aSize, EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext)
  1512 TSize CHuiVg10Texture::ApplyMargin(VGImage aImage, TSize aSize, EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext)
  1437     {
  1513     {
  1438     HUI_VG_INVARIANT();
  1514     HUI_VG_INVARIANT();
  1439     // If the icon is also a current EGL surface, the getImageSubData
  1515     #ifdef __WINSCW__
  1440     // won't succeed and return "image in use" -error..
  1516         if ( eglMakeCurrent( aDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ) == EGL_FALSE )
  1441     if ( eglMakeCurrent( aDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ) == EGL_FALSE )
  1517            {
  1442         {
  1518            HUI_DEBUG1(_L("CHuiVg10Texture::ApplyMargin() - EGL NO_Surface could not be made current, eglErr: %04x"), eglGetError());
  1443         HUI_DEBUG1(_L("CHuiVg10Texture::ApplyMargin() - EGL NO_Surface could not be made current, eglErr: %04x"), eglGetError());
  1519            return aSize;
  1444         return aSize;
  1520            }
  1445         }
  1521     #endif      
  1446     
       
  1447 #ifndef __WINS__ // Should possibly query the supported mode instead?
  1522 #ifndef __WINS__ // Should possibly query the supported mode instead?
  1448     VGImageFormat imageInternalFormat = VG_sARGB_8888_PRE;
  1523     VGImageFormat imageInternalFormat = VG_sARGB_8888_PRE;
  1449 #else
  1524 #else
  1450     // This doesn't work in the Emulator anyways.. => remove?
  1525     // This doesn't work in the Emulator anyways.. => remove?
  1451     VGImageFormat imageInternalFormat = VG_sARGB_8888;
  1526     VGImageFormat imageInternalFormat = VG_sARGB_8888;
  1468     TInt C = 0;
  1543     TInt C = 0;
  1469     TInt hNTN = Ha - 2.0 * 0.12 * Ha;
  1544     TInt hNTN = Ha - 2.0 * 0.12 * Ha;
  1470     TReal R = 1.0;
  1545     TReal R = 1.0;
  1471     TInt HaN = Ha;
  1546     TInt HaN = Ha;
  1472     
  1547     
  1473     const TInt lastColumn = aSize.iHeight - 1;
  1548     const TInt lastColumn = aSize.iWidth - 1;
  1474     for (TInt curRow = 0; curRow < lValidMargin; curRow++)
  1549     for (TInt curRow = 0; curRow < lValidMargin; curRow++)
  1475         {
  1550         {
  1476         const TInt y = (aSize.iHeight - 1) - curRow; // h - 1 is the last line
  1551         const TInt y = (aSize.iHeight - 1) - curRow; // h - 1 is the last line
  1477         // Get just one stride at a time (iWidth wide, 1 pixel high)
  1552         // Get just one stride at a time (iWidth wide, 1 pixel high)
  1478         vgGetImageSubData(aImage, ptr, stride, imageInternalFormat, 0, y, aSize.iWidth, 1);
  1553         vgGetImageSubData(aImage, ptr, stride, imageInternalFormat, 0, y, aSize.iWidth, 1);
  1490                 }
  1565                 }
  1491             }
  1566             }
  1492         }
  1567         }
  1493     delete buf;
  1568     delete buf;
  1494     HUI_VG_INVARIANT();
  1569     HUI_VG_INVARIANT();
  1495     
  1570     #ifdef __WINSCW__    
  1496     // Make the PBuffer surface current again 
  1571     // Make the PBuffer surface current again 
  1497     if ( eglMakeCurrent(aDisplay, aSurface, aSurface, aContext) == EGL_FALSE )
  1572      if ( eglMakeCurrent(aDisplay, aSurface, aSurface, aContext) == EGL_FALSE )
  1498         {
  1573          {
  1499         HUI_DEBUG1(_L("CHuiVg10Texture::ApplyMargin() - EGL aSurface could not be made current, eglErr: %04x"), eglGetError());
  1574          HUI_DEBUG1(_L("CHuiVg10Texture::ApplyMargin() - EGL aSurface could not be made current, eglErr: %04x"), eglGetError());
  1500         return aSize;
  1575          return aSize;
  1501         }
  1576          }
  1502     
  1577     #endif     
  1503     // If icon size has to be changed, clear out old area for new DrawNVG round!
  1578     // If icon size has to be changed, clear out old area for new DrawNVG round!
  1504     if(aSize.iHeight > HaN)
  1579     if(aSize.iHeight > HaN)
  1505         {
  1580         {
  1506         vgLoadIdentity();
  1581         vgLoadIdentity();
  1507         
  1582