uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiVg10Texture.cpp
branchRCL_3
changeset 15 cd0ae4656946
parent 9 3ac8bf5c5014
child 17 c9d868f1e20c
equal deleted inserted replaced
13:3a60ebea00d0 15:cd0ae4656946
    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 #include "appiconcache.h"
    32 
    33 
    33 #include "huiextension.h"
    34 #include "huiextension.h"
    34 
    35 
    35 // temporary hack until the openvg headers are fixed..
    36 // temporary hack until the openvg headers are fixed..
    36 #ifndef OPENVG_VERSION_1_0_1
    37 #ifndef OPENVG_VERSION_1_0_1
  1153             iNVGData = NULL;
  1154             iNVGData = NULL;
  1154             }
  1155             }
  1155         
  1156         
  1156         // Create the real image from NVG databuf
  1157         // Create the real image from NVG databuf
  1157         iNVGData = dataBuf;
  1158         iNVGData = dataBuf;
  1158         image = CreateRenderedImage(&nvgEngine, dataBuf, Size());
  1159         image = CreateRenderedImage(&nvgEngine, dataBuf, Size(),aBitmap.SerialNumber());
  1159         
  1160         
  1160         // New functionality for checking the mask
  1161         // New functionality for checking the mask
  1161         if (header.GetBitmapId() != maskHeader.GetBitmapId() && maskDataBuf &&
  1162         if (header.GetBitmapId() != maskHeader.GetBitmapId() && maskDataBuf &&
  1162             CompareNvgData(dataBuf, maskDataBuf) != 0)
  1163             CompareNvgData(dataBuf, maskDataBuf) != 0)
  1163             {
  1164             {
  1208     
  1209     
  1209     TInt returnValue = firstNoHeader.Compare(secondNoHeader);
  1210     TInt returnValue = firstNoHeader.Compare(secondNoHeader);
  1210     return returnValue;
  1211     return returnValue;
  1211     }
  1212     }
  1212 
  1213 
  1213 VGImage CHuiVg10Texture::CreateRenderedImage(CNvgEngine* aNvgEngine, HBufC8* aNVGData, const TSize& aDestSize)
  1214 
       
  1215 
       
  1216 VGImage CHuiVg10Texture::CreateRenderedImage(CNvgEngine* aNvgEngine, HBufC8* aNVGData, const TSize& aDestSize, TInt64 aSerialNumber)
  1214     {
  1217     {
  1215     HUI_VG_INVARIANT();
  1218     HUI_VG_INVARIANT();
  1216     
  1219     
  1217     // Image placeholder
  1220     // Image placeholder
  1218     VGImage image = VG_INVALID_HANDLE;
  1221     VGImage image = VG_INVALID_HANDLE;
  1337     
  1340     
  1338     // Always set blending mode to SRC_OVER before drawing NVG content (so that the  
  1341     // Always set blending mode to SRC_OVER before drawing NVG content (so that the  
  1339     // drawn icons would show correctly, and no issues with transparency would arise)
  1342     // drawn icons would show correctly, and no issues with transparency would arise)
  1340     VGint blendMode = vgGeti(VG_BLEND_MODE);
  1343     VGint blendMode = vgGeti(VG_BLEND_MODE);
  1341     vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
  1344     vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
  1342     if (iIconCommands)
  1345     TAknIconHeader iconheader = GetNvgIconHeader(aNVGData);
  1343         {
  1346     TBool direct = EFalse;
  1344         //HUI_DEBUG(_L("CHuiVg10Texture::CreateRenderedImage() - Drawing iIconCommands"));
  1347     if (iconheader.IsMarginCorrection() && aSerialNumber)
  1345         iIconCommands->Draw(aDestSize, aNvgEngine);
  1348         {
  1346         }
  1349         CFbsBitmap* entry = CHuiStatic::Env().AppIconCache().Find(aSerialNumber, aDestSize);
  1347     else
  1350         if (entry)
  1348         {
  1351             {
  1349         // If ObjectCached version failed, try to use the old way
  1352             TSize entrySize = entry->SizeInPixels();
  1350         //HUI_DEBUG(_L("CHuiVg10Texture::CreateRenderedImage() - Drawing with DrawNvg"));
  1353             entry->BeginDataAccess();
  1351         aNvgEngine->DrawNvg(GetNvgDataWithoutHeader(aNVGData), aDestSize, NULL, NULL);
  1354             TUint8* dataPtr = (TUint8*)entry->DataAddress();
       
  1355             vgImageSubData(image, dataPtr, CFbsBitmap::ScanLineLength(entrySize.iWidth, EColor16MAP), VG_sARGB_8888_PRE, 0, 0, entrySize.iWidth, entrySize.iHeight);
       
  1356             entry->EndDataAccess();
       
  1357             direct = ETrue;
       
  1358             }
       
  1359         }
       
  1360         
       
  1361     if (!direct)
       
  1362         {
       
  1363         if (iIconCommands)
       
  1364             {
       
  1365             //HUI_DEBUG(_L("CHuiVg10Texture::CreateRenderedImage() - Drawing iIconCommands"));
       
  1366             iIconCommands->Draw(aDestSize, aNvgEngine);
       
  1367             }
       
  1368         else
       
  1369             {
       
  1370             // If ObjectCached version failed, try to use the old way
       
  1371             //HUI_DEBUG(_L("CHuiVg10Texture::CreateRenderedImage() - Drawing with DrawNvg"));
       
  1372             aNvgEngine->DrawNvg(GetNvgDataWithoutHeader(aNVGData), aDestSize, NULL, NULL);
       
  1373             }
  1352         }
  1374         }
  1353     
  1375     
  1354     // NVG-TLV icon margin special case check:
  1376     // NVG-TLV icon margin special case check:
  1355     // Check, if the icon has to be margin corrected
  1377     // Check, if the icon has to be margin corrected
  1356     TAknIconHeader iconheader = GetNvgIconHeader(aNVGData);
       
  1357     TSize size = aDestSize; // For using the correct size also later on
  1378     TSize size = aDestSize; // For using the correct size also later on
  1358     if (iconheader.IsMarginCorrection())
  1379     if (iconheader.IsMarginCorrection() && !direct)
  1359         {
  1380         {
  1360         size = ApplyMargin(image, aDestSize, display, newSurface, context);
  1381         size = ApplyMargin(image, aDestSize, display, newSurface, context);
  1361         if( size != aDestSize)
  1382         if( size != aDestSize)
  1362             {
  1383             {
  1363             // Redo the drawing, this time to the correct size
  1384             // Redo the drawing, this time to the correct size
  1364             if (iIconCommands)
  1385             if (iIconCommands)
  1365                 iIconCommands->Draw(size, aNvgEngine);
  1386                 iIconCommands->Draw(size, aNvgEngine);
  1366             else
  1387             else
  1367                 aNvgEngine->DrawNvg(GetNvgDataWithoutHeader(aNVGData), size, NULL, NULL);
  1388                 aNvgEngine->DrawNvg(GetNvgDataWithoutHeader(aNVGData), size, NULL, NULL);
       
  1389             }
       
  1390         // assume 32bpp for the icon, don't cache if it's too large
       
  1391         TInt bitmapBytes = aDestSize.iWidth*aDestSize.iHeight*4;
       
  1392         if (bitmapBytes < 128*128*4)
       
  1393             {
       
  1394             // can't leave here (we would screw up the transformation matrix
       
  1395             // for the primary surface)
       
  1396             CFbsBitmap* rasterizedIcon = new CFbsBitmap;
       
  1397             TInt rastererr(KErrNone);
       
  1398             if (rasterizedIcon)
       
  1399                 {
       
  1400                 rastererr = rasterizedIcon->Create(aDestSize, EColor16MAP);
       
  1401                 }
       
  1402             if (!rastererr)
       
  1403                 {                    
       
  1404                 rasterizedIcon->BeginDataAccess();
       
  1405                 TUint8* dataPtr = (TUint8*)rasterizedIcon->DataAddress();
       
  1406                 vgGetImageSubData(image, dataPtr, CFbsBitmap::ScanLineLength(aDestSize.iWidth, EColor16MAP), VG_sARGB_8888_PRE, 0, 0, aDestSize.iWidth, aDestSize.iHeight);
       
  1407                 rasterizedIcon->EndDataAccess();
       
  1408                 // store for future use....
       
  1409                 TRasterizedBitmap rbmp(aSerialNumber, rasterizedIcon);            
       
  1410                 rastererr = CHuiStatic::Env().AppIconCache().Insert(rbmp);        
       
  1411                 }
       
  1412             // either the bitmap creation failed, or cache insert failed
       
  1413             // delete the bitmap so that we don't leak memory
       
  1414             if (rastererr)
       
  1415                 {
       
  1416                 delete rasterizedIcon;
       
  1417                 }
  1368             }
  1418             }
  1369         }
  1419         }
  1370 
  1420 
  1371     // restore the old surface before restoring original modes
  1421     // restore the old surface before restoring original modes
  1372     oldSurface->MakeCurrent();  // This will also call the SetCurrentRenderSurface
  1422     oldSurface->MakeCurrent();  // This will also call the SetCurrentRenderSurface