src/hbcore/image/hbiconloader.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
   622         if (index > 0) {
   622         if (index > 0) {
   623             suffixIndex = index;
   623             suffixIndex = index;
   624         }
   624         }
   625     }
   625     }
   626 
   626 
   627     foreach (const QString &suffix, suffixList) {
   627     foreach(const QString & suffix, suffixList) {
   628         bool dummy = false;
   628         bool dummy = false;
   629 
   629 
   630         QString nameWithSuffix = iconName;
   630         QString nameWithSuffix = iconName;
   631         nameWithSuffix.insert(suffixIndex, suffix);
   631         nameWithSuffix.insert(suffixIndex, suffix);
   632 
   632 
   696     // which is emitted before the signal 'layoutDirectionChanged'. Icon
   696     // which is emitted before the signal 'layoutDirectionChanged'. Icon
   697     // classes use that signal to update their pixmaps, so the new layout
   697     // classes use that signal to update their pixmaps, so the new layout
   698     // directionality must be updated in the icon loader before that.
   698     // directionality must be updated in the icon loader before that.
   699     // Thus, there are these separate signals.
   699     // Thus, there are these separate signals.
   700     QList<HbMainWindow *> allWindows = hbInstance->allMainWindows();
   700     QList<HbMainWindow *> allWindows = hbInstance->allMainWindows();
   701     HbMainWindow *primaryWindow = allWindows.value(0);
   701     if (allWindows.count()) {
   702 
   702         HbMainWindow *primaryWindow = allWindows.value(0);
   703     d->setLayoutMirrored(primaryWindow->layoutDirection() == Qt::RightToLeft);
   703         d->setLayoutMirrored(primaryWindow->layoutDirection() == Qt::RightToLeft);
       
   704     }
   704 }
   705 }
   705 
   706 
   706 void HbIconLoader::handleForegroundLost()
   707 void HbIconLoader::handleForegroundLost()
   707 {
   708 {
   708 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   709 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON)
   947 #ifdef HB_ICON_TRACES
   948 #ifdef HB_ICON_TRACES
   948     qDebug() << "HbIconLoader::getIconFromServer: req to server for" << params.iconFileName;
   949     qDebug() << "HbIconLoader::getIconFromServer: req to server for" << params.iconFileName;
   949 #endif
   950 #endif
   950     HbSharedIconInfo iconInfo;
   951     HbSharedIconInfo iconInfo;
   951     iconInfo.type = INVALID_FORMAT;
   952     iconInfo.type = INVALID_FORMAT;
       
   953     HbThemeClient *themeClient = HbThemeClient::global();
   952     //Initiate an IPC to themeserver to get the icon-data from the server via themeclient.
   954     //Initiate an IPC to themeserver to get the icon-data from the server via themeclient.
   953     iconInfo = HbThemeClient::global()->getSharedIconInfo(
   955     iconInfo = themeClient->getSharedIconInfo(
   954                    params.iconFileName,
   956                    params.iconFileName,
   955                    params.size,
   957                    params.size,
   956                    params.aspectRatioMode,
   958                    params.aspectRatioMode,
   957                    params.mode,
   959                    params.mode,
   958                    (params.mirrored && !params.mirroredIconFound),
   960                    (params.mirrored && !params.mirroredIconFound),
   964     //HbIconImpl thus created could be any one of the following impl-types:
   966     //HbIconImpl thus created could be any one of the following impl-types:
   965     //1. HbSgImageIconImpl
   967     //1. HbSgImageIconImpl
   966     //2. HbNvgIconImpl
   968     //2. HbNvgIconImpl
   967     //3. HbPixmapIconImpl
   969     //3. HbPixmapIconImpl
   968     icon = HbIconImplCreator::createIconImpl(iconInfo, params);
   970     icon = HbIconImplCreator::createIconImpl(iconInfo, params);
       
   971 
       
   972     if (icon && (icon->intialize() == HbIconImpl::ErrorLowGraphicsMemory)) {
       
   973         // initialisation failed due to low graphics memory, in sgimage icon case
       
   974         // try creating pixmap based icon
       
   975 
       
   976         // unload the created GPU icon
       
   977         unLoadIcon(icon);
       
   978         icon = 0;
       
   979 
       
   980         // create a pixmap based icon
       
   981         iconInfo = themeClient->getSharedIconInfo(
       
   982                        params.iconFileName,
       
   983                        params.size,
       
   984                        params.aspectRatioMode,
       
   985                        params.mode,
       
   986                        (params.mirrored && !params.mirroredIconFound),
       
   987                        params.options,
       
   988                        params.color,
       
   989                        ESWRendering);
       
   990 
       
   991         icon = HbIconImplCreator::createIconImpl(iconInfo, params);
       
   992         // no need call initialize of this icon
       
   993     }
   969 
   994 
   970 #ifdef HB_ICON_TRACES
   995 #ifdef HB_ICON_TRACES
   971     qDebug() << "Image from server: " << params.iconFileName << " offset = " << iconInfo.pixmapData.offset << "icon ptr" << (int) icon;
   996     qDebug() << "Image from server: " << params.iconFileName << " offset = " << iconInfo.pixmapData.offset << "icon ptr" << (int) icon;
   972 #endif
   997 #endif
   973     return icon;
   998     return icon;
  1384             //Initiate an IPC to themeserver to get the icon-data from the server.
  1409             //Initiate an IPC to themeserver to get the icon-data from the server.
  1385             icon = getIconFromServer(params);
  1410             icon = getIconFromServer(params);
  1386 
  1411 
  1387             if (icon) {
  1412             if (icon) {
  1388 #ifdef HB_ICONIMPL_CACHE
  1413 #ifdef HB_ICONIMPL_CACHE
  1389                 iconImplCache.insert(cacheKey, icon);
  1414                 if (params.renderMode != icon->iconRenderingMode()) {
       
  1415                     cacheKey = d->createCacheKeyFrom(params.iconName, 
       
  1416                                                  params.size,
       
  1417                                                  params.aspectRatioMode,
       
  1418                                                  params.mode, 
       
  1419                                                  params.mirrored, 
       
  1420                                                  params.color, 
       
  1421                                                  icon->iconRenderingMode());
       
  1422                     if (iconImplCache.contains(cacheKey)) {
       
  1423                         HbIconImpl * oldIcon = iconImplCache.value(cacheKey);
       
  1424                         this->unLoadIcon(icon);
       
  1425                         icon->dispose();
       
  1426                         icon = oldIcon;
       
  1427                         icon->incrementRefCount();
       
  1428                     }
       
  1429                 } else {                
       
  1430                     iconImplCache.insert(cacheKey, icon);
       
  1431                 }
  1390 #ifdef HB_ICON_CACHE_DEBUG
  1432 #ifdef HB_ICON_CACHE_DEBUG
  1391                 qDebug() << "HbIconLoader::loadIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1433                 qDebug() << "HbIconLoader::loadIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1392 #endif
  1434 #endif
  1393 
  1435 
  1394 #endif
  1436 #endif
  1419             t.scale(-1, 1);
  1461             t.scale(-1, 1);
  1420             params.canvasPixmap = params.canvasPixmap.transformed(t);
  1462             params.canvasPixmap = params.canvasPixmap.transformed(t);
  1421         }
  1463         }
  1422     }
  1464     }
  1423 
  1465 
       
  1466     if (params.color.isValid()) {
       
  1467         QPixmap &pm = params.canvasPixmap;
       
  1468         if (!pm.isNull()) {
       
  1469             QPixmap mask = pm.alphaChannel();
       
  1470             pm.fill(color);
       
  1471             pm.setAlphaChannel(mask);
       
  1472         }
       
  1473     }
       
  1474 
  1424     if (!params.modeHandled) {
  1475     if (!params.modeHandled) {
  1425         // Apply mode
  1476         // Apply mode
  1426         if (mode != QIcon::Normal) {
  1477         if (mode != QIcon::Normal) {
  1427             QStyleOption opt(0);
  1478             QStyleOption opt(0);
  1428             opt.palette = QApplication::palette();
  1479             opt.palette = QApplication::palette();
  1429             params.canvasPixmap = QApplication::style()->generatedIconPixmap(mode, params.canvasPixmap, &opt);
  1480             params.canvasPixmap = QApplication::style()->generatedIconPixmap(mode, params.canvasPixmap, &opt);
  1430         }
       
  1431     }
       
  1432 
       
  1433     if ((params.color.isValid()) && (params.mode != QIcon::Disabled)) {
       
  1434         QPixmap &pm = params.canvasPixmap;
       
  1435         if (!pm.isNull()) {
       
  1436             QPixmap mask = pm.alphaChannel();
       
  1437             pm.fill(color);
       
  1438             pm.setAlphaChannel(mask);
       
  1439         }
  1481         }
  1440     }
  1482     }
  1441 
  1483 
  1442 #ifdef HB_ICON_TRACES
  1484 #ifdef HB_ICON_TRACES
  1443     qDebug() << "HbIconLoader::loadIcon END";
  1485     qDebug() << "HbIconLoader::loadIcon END";
  1546 
  1588 
  1547         //Creating HbIconImpl for the consolidated icon-data returned from themeserver
  1589         //Creating HbIconImpl for the consolidated icon-data returned from themeserver
  1548         icon = HbIconImplCreator::createIconImpl(iconInfo, params);
  1590         icon = HbIconImplCreator::createIconImpl(iconInfo, params);
  1549         if (icon) {
  1591         if (icon) {
  1550 #ifdef HB_ICONIMPL_CACHE
  1592 #ifdef HB_ICONIMPL_CACHE
  1551             iconImplCache.insert(cacheKey, icon);
  1593             if (renderMode != icon->iconRenderingMode()) {
       
  1594                 cacheKey = d->createCacheKeyFrom(params.iconName, 
       
  1595                                              params.size,
       
  1596                                              params.aspectRatioMode,
       
  1597                                              params.mode, 
       
  1598                                              params.mirrored, 
       
  1599                                              params.color, 
       
  1600                                              icon->iconRenderingMode());
       
  1601                 if (iconImplCache.contains(cacheKey)) {
       
  1602                     HbIconImpl * oldIcon = iconImplCache.value(cacheKey);
       
  1603                     this->unLoadIcon(icon);
       
  1604                     icon->dispose();
       
  1605                     icon = oldIcon;
       
  1606                     icon->incrementRefCount();
       
  1607                 }
       
  1608             } else {
       
  1609                 iconImplCache.insert(cacheKey, icon);
       
  1610             }
  1552 #ifdef HB_ICON_CACHE_DEBUG
  1611 #ifdef HB_ICON_CACHE_DEBUG
  1553             qDebug() << "HbIconLoader::loadMultiPieceIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1612             qDebug() << "HbIconLoader::loadMultiPieceIcon(): " << params.iconName << " inserted into impl-cache, ref-count now = " << icon->refCount();
  1554 #endif
  1613 #endif
  1555 
  1614 
  1556 #endif
  1615 #endif
  1728         params.mirrored = mirrored;
  1787         params.mirrored = mirrored;
  1729         params.mirroredIconFound = mirroredIconFound;
  1788         params.mirroredIconFound = mirroredIconFound;
  1730 
  1789 
  1731 
  1790 
  1732         for (int i = 0; i < count;  i++) {
  1791         for (int i = 0; i < count;  i++) {
  1733             if (iconInfoList.icon[i].type != INVALID_FORMAT) {
  1792             impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
       
  1793             if (impl) {
  1734                 params.iconFileName = multiPartIconList[i];
  1794                 params.iconFileName = multiPartIconList[i];
  1735                 params.size = sizeList.at(i);
  1795                 params.size = sizeList.at(i);
  1736 
  1796 
  1737                 impl = HbIconImplCreator::createIconImpl(iconInfoList.icon[i], params);
       
  1738 
  1797 
  1739 #ifdef HB_ICONIMPL_CACHE
  1798 #ifdef HB_ICONIMPL_CACHE
  1740                 QByteArray cacheKey = d->createCacheKeyFrom(multiPartIconList[i],
  1799                 QByteArray cacheKey = d->createCacheKeyFrom( multiPartIconList[i], 
  1741                                       sizeList.at(i) ,
  1800                                                              sizeList.at(i) , 
  1742                                       aspectRatioMode,
  1801                                                              aspectRatioMode,
  1743                                       mode,
  1802                                                              mode, 
  1744                                       mirrored,
  1803                                                              mirrored, 
  1745                                       color,
  1804                                                              color, 
  1746                                       currRenderMode);
  1805                                                              impl->iconRenderingMode() );
  1747                 iconImplCache.insert(cacheKey, impl);
  1806                 if (iconImplCache.contains(cacheKey)) {
       
  1807                     HbIconImpl * oldIcon = iconImplCache.value(cacheKey);
       
  1808                     this->unLoadIcon(impl);
       
  1809                     impl->dispose();
       
  1810                     impl = oldIcon;
       
  1811                     impl->incrementRefCount();
       
  1812                 } else {
       
  1813                     iconImplCache.insert(cacheKey, impl);
       
  1814                 }
  1748 #ifdef HB_ICON_CACHE_DEBUG
  1815 #ifdef HB_ICON_CACHE_DEBUG
  1749                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1816                 qDebug() << "HbIconLoader::getMultiIconImplFromServer(): " << params.iconName << " inserted into impl-cache, ref-count now = " << impl->refCount();
  1750 #endif
  1817 #endif
  1751 
  1818 
  1752 #endif
  1819 #endif
  1819 
  1886 
  1820 bool HbIconLoader::isInPrivateDirectory(const QString &filename)
  1887 bool HbIconLoader::isInPrivateDirectory(const QString &filename)
  1821 {
  1888 {
  1822     Q_UNUSED(filename);
  1889     Q_UNUSED(filename);
  1823     bool isPrivate = false;
  1890     bool isPrivate = false;
  1824     
  1891 
  1825 #ifdef Q_OS_SYMBIAN
  1892 #ifdef Q_OS_SYMBIAN
  1826     if (filename.length() > 11) {
  1893     if (filename.length() > 11) {
  1827         // Private dir starts with e.g. "z:/private/"
  1894         // Private dir starts with e.g. "z:/private/"
  1828         if (filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\') &&
  1895         if (filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\') &&
  1829            (filename[10] == '/' || filename[10] == '\\') && filename.mid(3, 7).compare("private"), Qt::CaseInsensitive) {
  1896                 (filename[10] == '/' || filename[10] == '\\') && filename.mid(3, 7).compare("private"), Qt::CaseInsensitive) {
  1830             isPrivate = true;
  1897             isPrivate = true;
  1831         }
  1898         }
  1832     }
  1899     }
  1833 #endif
  1900 #endif
  1834 
  1901