src/hbservers/hbthemeserver/hbthemeserverutils.cpp
changeset 34 ed14f46c0e55
parent 5 627c4a0fd0e7
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbthemeserverutils_p.h"
    26 #include "hbthemeserverutils_p.h"
    27 
    27 
       
    28 #include <QBuffer>
       
    29 #include <QByteArray>
       
    30 #include <QDebug>
       
    31 #include <QFile>
    28 #include <QHash>
    32 #include <QHash>
    29 #include <QString>
    33 #include <QString>
    30 #include <QStringList>
    34 #include <QStringList>
    31 #include <QFile>
    35 #include <QSvgRenderer>
    32 #include <QDebug>
       
    33 
    36 
    34 #include "hbmemoryutils_p.h"
    37 #include "hbmemoryutils_p.h"
    35 #include "hbcssparser_p.h"
    38 #include "hbcssparser_p.h"
    36 #include "hbeffectfxmldata_p.h"
    39 #include "hbeffectfxmldata_p.h"
    37 #include "hbeffectxmlparser_p.h"
    40 #include "hbeffectxmlparser_p.h"
    38 #include "hbdeviceprofiledatabase_p.h"
    41 #include "hbdeviceprofiledatabase_p.h"
    39 #include "hbthemeperf_p.h"
    42 #include "hbthemeperf_p.h"
    40 #include "hbcache_p.h"
       
    41 #include "hbiconsource_p.h"
    43 #include "hbiconsource_p.h"
    42 #include "hbwidgetloader_p.h"
    44 #include "hbwidgetloader_p.h"
    43 #include "hbwidgetloaderactions_p.h"
    45 #include "hbwidgetloaderactions_p.h"
    44 #include "hbthemeindex_p.h"
    46 #include "hbthemeindex_p.h"
    45 
    47 
    51 // cache at the server side to maintain the offsets for
    53 // cache at the server side to maintain the offsets for
    52 // the filename,layout and section combination.
    54 // the filename,layout and section combination.
    53 typedef QHash<QString, int> ServerHashForLayoutDefs;
    55 typedef QHash<QString, int> ServerHashForLayoutDefs;
    54 Q_GLOBAL_STATIC(ServerHashForLayoutDefs, layoutDefsCache)
    56 Q_GLOBAL_STATIC(ServerHashForLayoutDefs, layoutDefsCache)
    55 
    57 
       
    58 // Offset for the cache of the missed CSS files for classes starting 'hb'
       
    59 static int missedHbCssFilesOffset = -1;
       
    60 static const QString HB_CLASSNAME_PREFIX("hb");
       
    61 
    56 static const int ICON_SOURCES_MAX_SIZE = 8;
    62 static const int ICON_SOURCES_MAX_SIZE = 8;
    57 static QList<HbIconSource *> iconSources; // cache of recently used icon sources
    63 static QList<HbIconSource *> iconSources; // cache of recently used icon sources
       
    64 
       
    65 
       
    66 const int PIXEL_DEPTH = 4;
       
    67 const int TILE_SIZE_IN_PIXELS = 32 * 32;
       
    68 const int SGIMAGE_PIXEL_OVERHEAD = 200;
    58 
    69 
    59 HbIconSource *HbThemeServerUtils::getIconSource(const QString &filename)
    70 HbIconSource *HbThemeServerUtils::getIconSource(const QString &filename)
    60 {
    71 {
    61     foreach(HbIconSource *source, iconSources) {
    72     foreach(HbIconSource *source, iconSources) {
    62         if (source->filename() == filename) {
    73         if (source->filename() == filename) {
   105  * \return offset of the shared style sheet in the shared memory, -1 if error
   116  * \return offset of the shared style sheet in the shared memory, -1 if error
   106  *
   117  *
   107  */
   118  */
   108 int HbThemeServerUtils::getSharedStylesheet(const QString &fileName,
   119 int HbThemeServerUtils::getSharedStylesheet(const QString &fileName,
   109                                             HbLayeredStyleLoader::LayerPriority priority,
   120                                             HbLayeredStyleLoader::LayerPriority priority,
       
   121                                             bool &fileExists,
   110                                             bool *inSharedCache)
   122                                             bool *inSharedCache)
   111 {
   123 {
   112     int cssOffset = -1;
   124     qptrdiff cssOffset = -1;
   113     HbSharedCache *sharedCache = 0;
   125     HbSharedCache *sharedCache = 0;
   114     if (priority == HbLayeredStyleLoader::Priority_Core) {
   126     if (priority == HbLayeredStyleLoader::Priority_Core) {
   115         sharedCache = HbSharedCache::instance();
   127         sharedCache = HbSharedCache::instance();
   116         cssOffset = sharedCache->offset(HbSharedCache::Stylesheet, fileName);
   128         cssOffset = sharedCache->offset(HbSharedCache::Stylesheet, fileName);
   117         if (inSharedCache) {
   129         if (inSharedCache) {
   119         }
   131         }
   120     } else if (inSharedCache) {
   132     } else if (inSharedCache) {
   121         *inSharedCache = false;
   133         *inSharedCache = false;
   122     }
   134     }
   123 
   135 
   124 #ifdef THEME_SERVER_TRACES
       
   125     qDebug() << "In " << Q_FUNC_INFO;
       
   126 #endif // THEME_SERVER_TRACES
       
   127     if (cssOffset < 0) {
   136     if (cssOffset < 0) {
   128         if (QFile::exists(fileName)) {
   137         THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Stylesheet: " << fileName << " not found in shared cache.";
   129             HbCss::Parser parser;
   138         HbCss::Parser parser;
   130             if (!parseCssFile(parser, fileName, cssOffset)) {
   139         if (!parseCssFile(parser, fileName, cssOffset, fileExists)) {
   131                 if (parser.errorCode == HbCss::Parser::OutOfMemoryError) {
   140             if (parser.errorCode == HbCss::Parser::OutOfMemoryError) {
   132                     return OUT_OF_MEMORY_ERROR;
   141                 return OUT_OF_MEMORY_ERROR;
   133                 }
       
   134             }
   142             }
   135         }
   143         }
   136         if (sharedCache) { //sharedCache valid only when priority is Priority_Core
   144         if (sharedCache) { //sharedCache valid only when priority is Priority_Core
   137             sharedCache->add(HbSharedCache::Stylesheet, fileName, cssOffset);
   145             sharedCache->add(HbSharedCache::Stylesheet, fileName, cssOffset);
   138         }
   146         }
   139     }
   147     }
   140     return cssOffset;
   148     return cssOffset;
   141 }
   149 }
   142 
   150 
       
   151 /*
       
   152  * Returns the offset of the missed CSS files for widgets starting with 'hb'
       
   153  */
       
   154 int HbThemeServerUtils::getMissedHbCssFilesOffset()
       
   155 {
       
   156     if (missedHbCssFilesOffset < 0) {
       
   157         initMissedHbCssFilesList();
       
   158     }
       
   159     return missedHbCssFilesOffset;
       
   160 }
       
   161 
       
   162 void HbThemeServerUtils::initMissedHbCssFilesList()
       
   163 {
       
   164     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
       
   165     int offset = -1;
       
   166     try {
       
   167         offset = manager->alloc(sizeof(HbVector<uint>));
       
   168         HbVector<uint> *list = new((char*)manager->base() + offset)
       
   169                 HbVector<uint>(HbMemoryManager::SharedMemory);
       
   170     } catch (std::bad_alloc &) {
       
   171         if (offset >= 0) {
       
   172             manager->free(offset);
       
   173             offset = -1;
       
   174         }
       
   175     }
       
   176     missedHbCssFilesOffset = offset;
       
   177 }
       
   178 
   143 /**
   179 /**
   144  * HbThemeServerUtils::parseCssFile()
   180  * HbThemeServerUtils::parseCssFile()
   145  *
   181  *
   146  * Returns false in case Css file has some error or there is not enough memory
   182  * Returns false in case Css file has some error or there is not enough memory
   147  */
   183  */
   148 bool HbThemeServerUtils::parseCssFile(HbCss::Parser &parser, const QString &fileName,
   184 bool HbThemeServerUtils::parseCssFile(HbCss::Parser &parser, const QString &fileName,
   149                                       int &cssOffset)
   185                                       qptrdiff &cssOffset, bool &fileExists)
   150 {
   186 {
   151     bool retVal = false;
   187     bool retVal = false;
   152     // 1. Create a styleSheet in shared memory
   188     // 1. Create a styleSheet in shared memory
   153     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) ;
   189     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory) ;
   154     HB_START_SHAREDMEMORY_PRINT("");
   190     HB_START_SHAREDMEMORY_PRINT("");
   166             cssOffset = -1;
   202             cssOffset = -1;
   167         }
   203         }
   168         return retVal;
   204         return retVal;
   169     }
   205     }
   170     // 2. Parse the required file into styleSheet.
   206     // 2. Parse the required file into styleSheet.
   171     parser.init(fileName, true);
   207     fileExists = parser.init(fileName, true);
       
   208     if (!fileExists) {
       
   209         if (QFileInfo(fileName).fileName().startsWith(HB_CLASSNAME_PREFIX)) {
       
   210             HbVector<uint> *list = HbMemoryUtils::getAddress<HbVector<uint> >(
       
   211                 HbMemoryManager::SharedMemory, getMissedHbCssFilesOffset());
       
   212             if (list) {
       
   213                 list->append(qHash(fileName));
       
   214             }
       
   215         }
       
   216         if (cssOffset != -1) {
       
   217             manager->free(cssOffset);
       
   218             cssOffset = -1;
       
   219         }
       
   220         return retVal;
       
   221     }
   172     
   222     
   173     retVal = parser.parse(styleSheet);
   223     retVal = parser.parse(styleSheet);
   174     if (!retVal) {
   224     if (!retVal) {
   175         //parser::parse returns false in a number of scenarios
   225         //parser::parse returns false in a number of scenarios
   176         // 1. css file has some error
   226         // 1. css file has some error
   187 /*
   237 /*
   188   Returns of the offset for the given filename,layout and section name.
   238   Returns of the offset for the given filename,layout and section name.
   189  */
   239  */
   190 
   240 
   191 int HbThemeServerUtils::getSharedLayoutDefinition(const QString &fileName, const QString &layout,
   241 int HbThemeServerUtils::getSharedLayoutDefinition(const QString &fileName, const QString &layout,
   192                                                   const QString &section)
   242                                                   const QString &section, bool &fileExists)
   193 {
   243 {
   194     int layoutDefOffset = -1;
   244     qptrdiff layoutDefOffset = -1;
   195     QStringRef nameKey(&fileName);
   245     QStringRef nameKey(&fileName);
   196     if (nameKey.at(0) == ':') {
   246     if (nameKey.at(0) == ':') {
   197         //use only filename as a key.
   247         //use only filename as a key.
   198         int index = fileName.lastIndexOf('/');
   248         int index = fileName.lastIndexOf('/');
   199         if (index >= 0) {
   249         if (index >= 0) {
   216         return layoutDefOffset;
   266         return layoutDefOffset;
   217     }
   267     }
   218     HbWidgetLoader loader;
   268     HbWidgetLoader loader;
   219 
   269 
   220     QFile file(fileName);
   270     QFile file(fileName);
   221     if (!file.open(QFile::ReadOnly | QFile::Text)) {
   271     fileExists = file.open(QFile::ReadOnly | QFile::Text);
   222         qWarning("Unable to open file");
   272     if (!fileExists) {
       
   273         THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Unable to open the file: " << fileName;
   223         return -1;
   274         return -1;
   224     }
   275     }
   225 #ifdef THEME_SERVER_TRACES
   276     THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Trying to load: " << fileName << "::" << layout << "::" << section;
   226     qDebug() << "Trying to load: " << fileName << "::" << layout << "::" << section;
       
   227 #endif // THEME_SERVER_TRACES
       
   228 
   277 
   229     HbWidgetLoader::LayoutDefinition *layoutDef(0);
   278     HbWidgetLoader::LayoutDefinition *layoutDef(0);
   230     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   279     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   231     try {
   280     try {
   232         layoutDefOffset = manager->alloc(sizeof(HbWidgetLoader::LayoutDefinition));
   281         layoutDefOffset = manager->alloc(sizeof(HbWidgetLoader::LayoutDefinition));
   305  * \return offset of the parsed effect data in the shared memory, -1 if error
   354  * \return offset of the parsed effect data in the shared memory, -1 if error
   306  *
   355  *
   307  */
   356  */
   308 int HbThemeServerUtils::getSharedEffect(const QString &fileName)
   357 int HbThemeServerUtils::getSharedEffect(const QString &fileName)
   309 {
   358 {
   310 #ifdef THEME_SERVER_TRACES
   359     THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "called with fileName: " << fileName;
   311     qDebug() << "In " << Q_FUNC_INFO << fileName;
   360 
   312 #endif // THEME_SERVER_TRACES
   361     qptrdiff effOffset = -1;
   313 
       
   314     int effOffset = -1;
       
   315     if (effCache()->contains(fileName)) {
   362     if (effCache()->contains(fileName)) {
   316         effOffset = effCache()->value(fileName);
   363         effOffset = effCache()->value(fileName);
   317 
   364         THEME_GENERIC_DEBUG() << "in cache: " << fileName << "offset=" << effOffset;
   318 #ifdef THEME_SERVER_TRACES
       
   319         qDebug() << "Got effect in cache: " << fileName << "offset=" << effOffset;
       
   320 #endif //THEME_SERVER_TRACES
       
   321 
       
   322     } else {
   365     } else {
   323 
   366         THEME_GENERIC_DEBUG() << "Not in cache, parsing: " << fileName;
   324 #ifdef THEME_SERVER_TRACES
   367         
   325         qDebug() << "Not in cache, parsing: " << fileName;
       
   326 #endif //THEME_SERVER_TRACES
       
   327 
       
   328         // 1. Create an effect in shared memory
   368         // 1. Create an effect in shared memory
   329         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   369         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   330         HbEffectFxmlData *data = 0;
   370         HbEffectFxmlData *data = 0;
   331         try {
   371         try {
   332             effOffset = manager->alloc(sizeof(HbEffectFxmlData));
   372             effOffset = manager->alloc(sizeof(HbEffectFxmlData));
   337                 // if manager->alloc in the previous try block suceeds but creation of
   377                 // if manager->alloc in the previous try block suceeds but creation of
   338                 // HbEffectFxmlData on shared memory failed
   378                 // HbEffectFxmlData on shared memory failed
   339                 manager->free(effOffset);
   379                 manager->free(effOffset);
   340                 effOffset = -1;
   380                 effOffset = -1;
   341             }
   381             }
       
   382             THEME_GENERIC_DEBUG() << "Exception when allocating shared memory.";
   342             return effOffset;
   383             return effOffset;
   343         }
   384         }
   344         // 2. Parse the file.
   385         // 2. Parse the file.
   345         HbEffectXmlParser parser;
   386         HbEffectXmlParser parser;
   346 
   387 
       
   388         QBuffer fxmlBuffer;
   347         QFile f(fileName);
   389         QFile f(fileName);
   348         bool fail = false;
   390         bool fail = false;
   349         if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
   391 
       
   392         if (f.open(QIODevice::ReadOnly)) {
   350             try {
   393             try {
   351                 parser.read(&f, data);
   394                 QByteArray arr(f.readAll());
   352                 f.close();
   395                 fxmlBuffer.setBuffer(&arr);
       
   396                 if (fxmlBuffer.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   397                     parser.read(&fxmlBuffer, data);
       
   398                 } else {
       
   399                     THEME_GENERIC_DEBUG() << "Cannot open fxmlBuffer from file:" << fileName;
       
   400                     fail = true;
       
   401                 }
   353 
   402 
   354                 // 3. Mark an entry for this styleSheet into the table
   403                 // 3. Mark an entry for this styleSheet into the table
   355                 effCache()->insert(fileName, effOffset);
   404                 if (!fail) {
       
   405                     effCache()->insert(fileName, effOffset);
       
   406                 }
   356             } catch (std::exception &) {
   407             } catch (std::exception &) {
   357                 f.close();
       
   358                 fail = true;
   408                 fail = true;
   359             }
   409             }
   360         } else {
   410         } else {
   361 #ifdef THEME_SERVER_TRACES
   411             THEME_GENERIC_DEBUG() << "Cannot open:" << fileName;
   362             qWarning() << "Cannot open" << fileName;
       
   363 #endif // THEME_SERVER_TRACES
       
   364             fail = true;
   412             fail = true;
   365         }
   413         }
   366         if (fail) {
   414         if (fail) {
   367             data->~HbEffectFxmlData();
   415             data->~HbEffectFxmlData();
   368             manager->free(effOffset);
   416             manager->free(effOffset);
       
   417             THEME_GENERIC_DEBUG() << "Failed to parse effect.";
   369             return -1;
   418             return -1;
   370         }
   419         }
       
   420 
       
   421         // These will be open, if we got here
       
   422         f.close();
       
   423         fxmlBuffer.close();
   371 
   424 
   372         // add the filename and css offset to the secondary cache.
   425         // add the filename and css offset to the secondary cache.
   373         // no need to check if this item is already present in the
   426         // no need to check if this item is already present in the
   374         // cache as the parsing of the file happens only once
   427         // cache as the parsing of the file happens only once
   375         // in the server side.
   428         // in the server side.
   376         HbSharedCache::instance()->add(HbSharedCache::Effect, fileName, effOffset);
   429         HbSharedCache::instance()->add(HbSharedCache::Effect, fileName, effOffset);
   377     }
   430     }
   378 
   431     
   379 #ifdef THEME_SERVER_TRACES
   432     THEME_GENERIC_DEBUG() << "returning offset: " << effOffset;
   380     qDebug() << "returning offset: " << effOffset;
       
   381 #endif // THEME_SERVER_TRACES
       
   382 
       
   383     return effOffset;
   433     return effOffset;
   384 }
   434 }
   385 
   435 
   386 /**
       
   387  * cleanupUnusedCss  function removes css-resources (stylesheets), whose reference count
       
   388  * is zero, it also releases the shared memory occupied by those resources.
       
   389  * \param cache server css-cache
       
   390  *
       
   391  */
       
   392 void HbThemeServerUtils::cleanupUnusedCss(HbCache *cache)
       
   393 {
       
   394     QList<HbCacheItem*> list = cache->lruList();
       
   395     while (!list.isEmpty()) {
       
   396         HbCacheItem* itemToRemove = list.takeFirst();
       
   397         if (itemToRemove->offset != -1) {
       
   398             HbCss::StyleSheet *styleSheet =
       
   399                 HbMemoryUtils::getAddress<HbCss::StyleSheet>(HbMemoryManager::SharedMemory,
       
   400                         itemToRemove->offset);
       
   401             HbMemoryUtils::release<HbCss::StyleSheet>(styleSheet);
       
   402             itemToRemove->offset = -1;
       
   403         }
       
   404         //Since we are cleaning up css-resources whose ref-count is zero, these entries will be
       
   405         // removed from actual cache.
       
   406         delete cache->cacheHandle().take(itemToRemove->fileName);
       
   407     }
       
   408 }
       
   409 
       
   410 void HbThemeServerUtils::createThemeIndex(const QString &themePath, const HbThemeType &themetype)
   436 void HbThemeServerUtils::createThemeIndex(const QString &themePath, const HbThemeType &themetype)
   411 {
   437 {
   412     #ifdef THEME_INDEX_TRACES
   438     THEME_INDEX_DEBUG() <<  "ThemeIndex: createThemeIndex" << themePath.toUtf8();
   413     qDebug() <<  "ThemeIndex: createThemeIndex" << themePath.toUtf8();
       
   414     #endif
       
   415     QDir themeBasePath(themePath);
   439     QDir themeBasePath(themePath);
   416     // Path is like "C:/resource/hb/themes/icons/sfwhitetheme"
   440     // Path is like "C:/resource/hb/themes/icons/sfwhitetheme"
   417     QString themeName = themeBasePath.dirName();
   441     QString themeName = themeBasePath.dirName();
   418     
   442     
   419     QString filename(themeBasePath.absolutePath());
   443     QString filename(themeBasePath.absolutePath());
   420     int cutindex = filename.lastIndexOf("/",filename.lastIndexOf("/")-1)+1;
   444     int cutindex = filename.lastIndexOf('/',filename.lastIndexOf('/')-1)+1;
   421     filename = filename.left(cutindex);
   445     filename = filename.left(cutindex);
   422     themeBasePath.setPath(filename);
   446     themeBasePath.setPath(filename);
   423     filename.append(themeName);
   447     filename.append(themeName);
   424     filename.append(".themeindex");
   448     filename.append(".themeindex");
   425 
   449 
   432     QFile indexFile(filename);
   456     QFile indexFile(filename);
   433 
   457 
   434     bool indexOK = false;
   458     bool indexOK = false;
   435 
   459 
   436     if (indexFile.open(QIODevice::ReadOnly)) {
   460     if (indexFile.open(QIODevice::ReadOnly)) {
   437 
       
   438         indexOK = true;
   461         indexOK = true;
   439 
       
   440         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   462         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
   441 
   463 
   442         HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();
   464         HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();        
   443         
       
   444         qint64 byteSize = indexFile.size();
   465         qint64 byteSize = indexFile.size();
   445 
   466         THEME_INDEX_DEBUG() <<  "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize;
   446         #ifdef THEME_INDEX_TRACES
       
   447         qDebug() <<  "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize;
       
   448         #endif
       
   449 
   467 
   450         int offset = manager->alloc(byteSize);
   468         int offset = manager->alloc(byteSize);
   451         if (offset >= 0) {
   469         if (offset >= 0) {
   452             #ifdef THEME_INDEX_TRACES
   470             THEME_INDEX_DEBUG() <<  "ThemeIndex: memory allocated for theme: " << themeName.toUtf8();
   453             qDebug() <<  "ThemeIndex: memory allocated for theme: " << themeName.toUtf8();
       
   454             #endif
       
   455 
   471 
   456             // Read the theme index in the shared chunk
   472             // Read the theme index in the shared chunk
   457             char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset);
   473             char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset);
   458 
   474 
   459             indexFile.read(address, byteSize);
   475             indexFile.read(address, byteSize);
   460             indexFile.close();
   476             indexFile.close();
   461 
   477             THEME_INDEX_DEBUG() <<  "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!";
   462             #ifdef THEME_INDEX_TRACES
       
   463             qDebug() <<  "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!";
       
   464             #endif
       
   465 
   478 
   466             // Verify theme index contents if it is not located in ROM,
   479             // Verify theme index contents if it is not located in ROM,
   467             // so that it does not have over-indexing offsets which might
   480             // so that it does not have over-indexing offsets which might
   468             // crash all the clients trying to read from it.
   481             // crash all the clients trying to read from it.
   469 
   482 
   470 #ifdef Q_OS_SYMBIAN // ROM check only for Symbian - verify always in other platforms.
       
   471             if (themePath[0] != 'z' && themePath[0] != 'Z') {
   483             if (themePath[0] != 'z' && themePath[0] != 'Z') {
   472 #endif
   484                 THEME_INDEX_DEBUG() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8();
   473                 #ifdef THEME_INDEX_TRACES
       
   474                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8();
       
   475                 #endif
       
   476 
       
   477                 HbThemeIndex index(address);
   485                 HbThemeIndex index(address);
   478                 indexOK = index.validateItems(byteSize);
   486                 indexOK = index.validateItems(byteSize);
   479 
   487                 THEME_INDEX_DEBUG() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK;
   480                 #ifdef THEME_INDEX_TRACES
   488             }
   481                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK;
   489 
   482                 #endif
       
   483 #ifdef Q_OS_SYMBIAN
       
   484             }
       
   485 #endif
       
   486             if (indexOK) {
   490             if (indexOK) {
   487                 // Allocate theme path string from shared memory
   491                 // Allocate theme path string from shared memory
   488                 QByteArray themePathArray = themeBasePath.absolutePath().toLatin1();
   492                 QByteArray themePathArray = themeBasePath.absolutePath().toLatin1();
   489                 quint32 themePathOffset = manager->alloc(themePathArray.size()+1);
   493                 quint32 themePathOffset = manager->alloc(themePathArray.size()+1);
   490                 memcpy(HbMemoryUtils::getAddress<char>(
   494                 memcpy(HbMemoryUtils::getAddress<char>(
   553             }
   557             }
   554         }
   558         }
   555     }
   559     }
   556 }
   560 }
   557 
   561 
   558 
   562 int HbThemeServerUtils::computeCpuCost(const HbIconKey & key, HbIconFormatType iconType,
       
   563                                         bool isConsolidatedIcon)
       
   564 {
       
   565     int cpuItemCost = 0;
       
   566     if (isConsolidatedIcon) {
       
   567         QSize size = key.size.toSize();
       
   568         cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   569         return cpuItemCost;
       
   570     }
       
   571     HbIconSource *source = HbThemeServerUtils::getIconSource(key.filename);
       
   572     if (source) {
       
   573         if (iconType == BLOB) {
       
   574             QByteArray *sourceByteArray = source->byteArray();
       
   575             if (sourceByteArray) {
       
   576                 cpuItemCost = sourceByteArray->length();
       
   577             }
       
   578         } else if (iconType == NVG) {
       
   579             QByteArray *sourceByteArray = source->byteArray();
       
   580             if (sourceByteArray) {
       
   581                 QSizeF renderSize = source->defaultSize();
       
   582                 if (!key.size.isNull()) {
       
   583                     renderSize.scale(key.size,key.aspectRatioMode);
       
   584                 }
       
   585                 QSize size = renderSize.toSize();
       
   586                 cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   587             }    
       
   588         } else if (iconType == SVG) {
       
   589             QSvgRenderer *svgRenderer = source->svgRenderer();
       
   590             if (svgRenderer && svgRenderer->isValid()) {
       
   591                 QSizeF renderSize = QSizeF(svgRenderer->defaultSize());
       
   592                 if (!key.size.isNull()) {
       
   593                     renderSize.scale(key.size, key.aspectRatioMode);
       
   594                 }
       
   595                 QSize size = renderSize.toSize();
       
   596                 cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   597                 source->releaseSvgRenderer();
       
   598                 
       
   599             }    
       
   600         } else {
       
   601             QPixmap pm = QPixmap::fromImage(*source->image());
       
   602             QSizeF renderSize = pm.size();
       
   603             if (!key.size.isNull() ) {
       
   604                 renderSize.scale(key.size, key.aspectRatioMode);
       
   605             }
       
   606             QSize size = renderSize.toSize();
       
   607             cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   608             
       
   609         }
       
   610             
       
   611     }
       
   612     return cpuItemCost;
       
   613 }
       
   614 
       
   615 
       
   616 int HbThemeServerUtils::computeGpuCost(const HbIconKey & key, HbIconFormatType iconType,
       
   617                                         bool isConsolidatedIcon)
       
   618 {
       
   619     int gpuItemCost = 0;
       
   620     if (isConsolidatedIcon) {
       
   621         QSize size = key.size.toSize();
       
   622         int xTiles = ceil(size.width() / 32.0);
       
   623         int yTiles = ceil(size.height() / 32.0);
       
   624         int sizeInPixels =  xTiles * yTiles * TILE_SIZE_IN_PIXELS;
       
   625         int sizeInBytes = sizeInPixels * PIXEL_DEPTH;
       
   626         gpuItemCost = sizeInBytes + SGIMAGE_PIXEL_OVERHEAD ;
       
   627         return gpuItemCost;
       
   628     }
       
   629     HbIconSource *source = HbThemeServerUtils::getIconSource(key.filename);
       
   630     if (source) {
       
   631         if (iconType == NVG) {
       
   632             QByteArray *sourceByteArray = source->byteArray();
       
   633             if (sourceByteArray) {
       
   634                 QSizeF renderSize = source->defaultSize();
       
   635                 if (!key.size.isNull()) {
       
   636                     renderSize.scale(key.size,key.aspectRatioMode);
       
   637                 }
       
   638                 QSize size = renderSize.toSize();
       
   639                 int xTiles = ceil(size.width() / 32.0);
       
   640                 int yTiles = ceil(size.height() / 32.0);
       
   641                 int sizeInPixels =  xTiles * yTiles * TILE_SIZE_IN_PIXELS;
       
   642                 int sizeInBytes = sizeInPixels * PIXEL_DEPTH;
       
   643                 gpuItemCost = sizeInBytes + SGIMAGE_PIXEL_OVERHEAD ;
       
   644             }
       
   645         }
       
   646     }
       
   647     return gpuItemCost;
       
   648 
       
   649 }
       
   650 
       
   651 int HbThemeServerUtils::computeFrameItemCpuCost(const HbIconKey & key, HbIconFormatType iconType, 
       
   652                                                 HbRenderingMode rm)
       
   653 {
       
   654     int cpuItemCost = 0;
       
   655     HbIconSource *source = HbThemeServerUtils::getIconSource(key.filename);
       
   656     if (source) {
       
   657         if (iconType == SVG) {
       
   658             QSvgRenderer *svgRenderer = source->svgRenderer();
       
   659             if (svgRenderer && svgRenderer->isValid()) {
       
   660                 QSizeF renderSize = QSizeF(svgRenderer->defaultSize());
       
   661                 if (!key.size.isNull()) {
       
   662                     renderSize.scale(key.size, key.aspectRatioMode);
       
   663                 }
       
   664                 QSize size = renderSize.toSize();
       
   665                 cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   666                 source->releaseSvgRenderer();
       
   667                     
       
   668             }
       
   669         } else if (iconType == NVG) {
       
   670             QByteArray *sourceByteArray = source->byteArray();
       
   671             if (sourceByteArray) {    
       
   672                 if (rm == EHWRendering ) {
       
   673                     cpuItemCost = sourceByteArray->length();
       
   674                 } else {
       
   675                     QSizeF renderSize = source->defaultSize();
       
   676                     if (!key.size.isNull()) {
       
   677                         renderSize.scale(key.size,key.aspectRatioMode);
       
   678                     }
       
   679                     QSize size = renderSize.toSize();
       
   680                     cpuItemCost = size.width() * size.height() * PIXEL_DEPTH;
       
   681                }
       
   682             }
       
   683         }
       
   684     }    
       
   685     return cpuItemCost;
       
   686     
       
   687 }
       
   688    
       
   689