82 The createCacheItem is responsible for creating an icon in cpu or gpu memory |
82 The createCacheItem is responsible for creating an icon in cpu or gpu memory |
83 based on the format provided. |
83 based on the format provided. |
84 \a key denotes the unique identifier for the cache item |
84 \a key denotes the unique identifier for the cache item |
85 \a options indicate different ways of loading icons |
85 \a options indicate different ways of loading icons |
86 \a format indicates the icon format e.g. svg/nvg etc.\ |
86 \a format indicates the icon format e.g. svg/nvg etc.\ |
87 \a currentRenderingMode ThemeServer's current rendering mode state. |
87 \a renderingMode rendering mode to be used for creating CacheItem. |
88 */ |
88 */ |
89 HbIconCacheItem *HbIconCacheItemCreator::createCacheItem(const HbIconKey &key, |
89 HbIconCacheItem *HbIconCacheItemCreator::createCacheItem(const HbIconKey &key, |
90 HbIconLoader::IconLoaderOptions options, |
90 HbIconLoader::IconLoaderOptions options, |
91 const QString &format, |
91 const QString &format, |
92 HbRenderingMode currentRenderingMode, |
92 HbRenderingMode renderMode, |
93 bool isMultiPiece) |
93 bool isMultiPiece) |
94 { |
94 { |
95 #ifndef Q_OS_SYMBIAN |
95 #ifndef Q_OS_SYMBIAN |
96 Q_UNUSED(isMultiPiece) |
96 Q_UNUSED(isMultiPiece) |
97 Q_UNUSED(currentRenderingMode) |
97 Q_UNUSED(renderMode) |
98 #endif |
98 #endif |
99 QScopedPointer <HbIconCacheItem> tempIconCacheItem(new HbIconCacheItem); |
99 QScopedPointer <HbIconCacheItem> tempIconCacheItem(new HbIconCacheItem); |
100 HbIconCacheItem *item = tempIconCacheItem.data(); |
100 HbIconCacheItem *item = tempIconCacheItem.data(); |
|
101 QScopedPointer <HbIconProcessor> rasterIcon; |
|
102 QScopedPointer <HbIconProcessor> vectorIcon; |
|
103 |
|
104 bool isIconCreated = false; |
|
105 |
|
106 if ((format == KSvg) || (format == KPic)) { |
|
107 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
108 |
|
109 #ifdef SVG_INTERMEDIATE_PIC |
|
110 vectorIcon.reset(new HbPicIconProcessor(key, options, format)); |
|
111 #endif |
|
112 } else if (format == KNvg) { |
|
113 #ifdef HB_NVG_CS_ICON |
|
114 if (!isMultiPiece) { |
|
115 #ifdef HB_SGIMAGE_ICON |
|
116 if(renderMode == ESWRendering){ |
|
117 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
118 } else { |
|
119 if (HbThemeServerPrivate::gpuMemoryState()) { |
|
120 rasterIcon.reset(new HbSgimageIconProcessor(key, options, format)); |
|
121 } |
|
122 |
|
123 if(!rasterIcon.data()) { |
|
124 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
125 } else { |
|
126 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
127 } |
|
128 } |
|
129 #endif |
|
130 |
|
131 // if sgImage support is enabled by default remove this block |
|
132 #ifndef HB_SGIMAGE_ICON |
|
133 if(renderMode == ESWRendering){ |
|
134 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
135 } else { |
|
136 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
137 } |
|
138 #endif |
|
139 // block end |
|
140 } |
|
141 else { |
|
142 if(renderMode == ESWRendering){ |
|
143 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
144 } else { |
|
145 // multipieceIcon So make nvgiconimpl for .nvg files |
|
146 // No raster icon data is created |
|
147 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
148 } |
|
149 } |
|
150 #endif |
|
151 } else if (format == KBlob) { |
|
152 item->blobIconData.type = BLOB; |
|
153 bool fail = true; |
|
154 HbIconSource *source = HbThemeServerUtils::getIconSource(key.filename); |
|
155 if (source) { |
|
156 QByteArray *content = source->byteArray(); |
|
157 if (content) { |
|
158 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
159 item->blobIconData.blobData.offset = manager->alloc(content->length()); |
|
160 if (item->blobIconData.blobData.offset != -1) { |
|
161 fail = false; |
|
162 // Store vector cost because blobs go into the "cpu" cache. |
|
163 item->blobIconData.blobData.dataSize |
|
164 = item->vectorIconDataCost |
|
165 = content->length(); |
|
166 item->blobIconData.renderingMode = ESWRendering; |
|
167 memcpy(HbMemoryUtils::getAddress<char>( |
|
168 HbMemoryManager::SharedMemory, |
|
169 item->blobIconData.blobData.offset), |
|
170 content->data(), |
|
171 content->length()); |
|
172 } |
|
173 |
|
174 } |
|
175 } |
|
176 if (fail) { |
|
177 return 0; |
|
178 } |
|
179 } else { |
|
180 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
181 } |
|
182 |
|
183 if (rasterIcon.data()) { |
|
184 isIconCreated = rasterIcon.data()->createIconData(key.filename); |
|
185 if (isIconCreated) { |
|
186 item->rasterIconData = rasterIcon.data()->sharedIconData(); |
|
187 item->rasterIconDataCost = rasterIcon.data()->sharedIconDataCost(); |
|
188 } else if(format == KNvg && renderMode == EHWRendering){ |
|
189 #ifdef HB_SGIMAGE_ICON |
|
190 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
191 if (rasterIcon.data()) { |
|
192 isIconCreated = rasterIcon.data()->createIconData(key.filename); |
|
193 if (isIconCreated) { |
|
194 item->rasterIconData = rasterIcon.data()->sharedIconData(); |
|
195 item->rasterIconDataCost = rasterIcon.data()->sharedIconDataCost(); |
|
196 } |
|
197 } |
|
198 #endif |
|
199 } |
|
200 } |
|
201 |
|
202 if (vectorIcon.data()) { |
|
203 isIconCreated = vectorIcon.data()->createIconData(key.filename); |
|
204 if (isIconCreated) { |
|
205 item->vectorIconData = vectorIcon.data()->sharedIconData(); |
|
206 item->vectorIconDataCost = vectorIcon.data()->sharedIconDataCost(); |
|
207 } |
|
208 } |
|
209 |
|
210 if (item) { |
|
211 item->iconOptions = options; |
|
212 } |
|
213 if (tempIconCacheItem.data()) { |
|
214 tempIconCacheItem.take(); |
|
215 } |
|
216 return item; |
|
217 } |
|
218 |
|
219 |
|
220 /*! |
|
221 \fn HbIconCacheItemCreator::createCacheItem() |
|
222 This overloaded createCacheItem is a helper function to populate a cache item |
|
223 if this item is already created with some parameters either on the Gpu or the Cpu |
|
224 \a iconCacheItem denotes the cacheItem to be populated |
|
225 \a key unique identifier to identify the cache item |
|
226 \a currentRenderingMode ThemeServer's current rendering mode state |
|
227 |
|
228 */ |
|
229 void HbIconCacheItemCreator::createCacheItem(HbIconCacheItem &iconCacheItem, |
|
230 const HbIconKey &key, |
|
231 HbRenderingMode currentRenderingMode) |
|
232 { |
|
233 #ifndef Q_OS_SYMBIAN |
|
234 Q_UNUSED(currentRenderingMode) |
|
235 #endif |
101 QScopedPointer <HbIconProcessor> rasterIcon; |
236 QScopedPointer <HbIconProcessor> rasterIcon; |
102 QScopedPointer <HbIconProcessor> vectorIcon; |
237 QScopedPointer <HbIconProcessor> vectorIcon; |
103 |
238 |
104 // Set the render mode to EHWRendering, only if the client is requesting a HW rendered icon |
239 // Set the render mode to EHWRendering, only if the client is requesting a HW rendered icon |
105 // and ThemeServer is in HW rendering mode |
240 // and ThemeServer is in HW rendering mode |
106 HbRenderingMode renderMode = ESWRendering; |
241 HbRenderingMode renderMode = ESWRendering; |
107 #ifndef Q_OS_SYMBIAN |
242 #ifndef Q_OS_SYMBIAN |
108 Q_UNUSED(renderMode) |
243 Q_UNUSED(renderMode) |
109 #endif |
244 #endif |
110 |
245 |
111 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
|
112 if((key.renderMode == EHWRendering) && (currentRenderingMode == EHWRendering)) { |
|
113 renderMode = EHWRendering; |
|
114 } |
|
115 #endif |
|
116 bool isIconCreated = false; |
|
117 |
|
118 if ((format == KSvg) || (format == KPic)) { |
|
119 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
120 |
|
121 #ifdef SVG_INTERMEDIATE_PIC |
|
122 vectorIcon.reset(new HbPicIconProcessor(key, options, format)); |
|
123 #endif |
|
124 } else if (format == KNvg) { |
|
125 #ifdef HB_NVG_CS_ICON |
|
126 if (!isMultiPiece) { |
|
127 #ifdef HB_SGIMAGE_ICON |
|
128 if(renderMode == ESWRendering){ |
|
129 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
130 } else { |
|
131 if (HbThemeServerPrivate::gpuMemoryState()) { |
|
132 rasterIcon.reset(new HbSgimageIconProcessor(key, options, format)); |
|
133 } |
|
134 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
135 } |
|
136 #endif |
|
137 |
|
138 // if sgImage support is enabled by default remove this block |
|
139 #ifndef HB_SGIMAGE_ICON |
|
140 if(renderMode == ESWRendering){ |
|
141 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
142 } else { |
|
143 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
144 } |
|
145 #endif |
|
146 // block end |
|
147 } |
|
148 else { |
|
149 if(renderMode == ESWRendering){ |
|
150 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
151 } else { |
|
152 // multipieceIcon So make nvgiconimpl for .nvg files |
|
153 // No raster icon data is created |
|
154 vectorIcon.reset(new HbNvgIconProcessor(key, options, format)); |
|
155 } |
|
156 } |
|
157 #endif |
|
158 } else if (format == KBlob) { |
|
159 item->blobIconData.type = BLOB; |
|
160 QFile f(key.filename); |
|
161 bool fail = true; |
|
162 if (f.open(QIODevice::ReadOnly)) { |
|
163 QByteArray content = f.readAll(); |
|
164 f.close(); |
|
165 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
166 item->blobIconData.blobData.offset = manager->alloc(content.length()); |
|
167 if (item->blobIconData.blobData.offset != -1) { |
|
168 fail = false; |
|
169 // Store vector cost because blobs go into the "cpu" cache. |
|
170 item->blobIconData.blobData.dataSize |
|
171 = item->vectorIconDataCost |
|
172 = content.length(); |
|
173 memcpy(HbMemoryUtils::getAddress<char>( |
|
174 HbMemoryManager::SharedMemory, |
|
175 item->blobIconData.blobData.offset), |
|
176 content.data(), |
|
177 content.length()); |
|
178 } |
|
179 } |
|
180 if (fail) { |
|
181 return 0; |
|
182 } |
|
183 } else { |
|
184 rasterIcon.reset(new HbPixmapIconProcessor(key, options, format)); |
|
185 } |
|
186 |
|
187 if (rasterIcon.data()) { |
|
188 isIconCreated = rasterIcon.data()->createIconData(key.filename); |
|
189 if (isIconCreated) { |
|
190 item->rasterIconData = rasterIcon.data()->sharedIconData(); |
|
191 item->rasterIconDataCost = rasterIcon.data()->sharedIconDataCost(); |
|
192 } |
|
193 } |
|
194 |
|
195 if (vectorIcon.data()) { |
|
196 isIconCreated = vectorIcon.data()->createIconData(key.filename); |
|
197 if (isIconCreated) { |
|
198 item->vectorIconData = vectorIcon.data()->sharedIconData(); |
|
199 item->vectorIconDataCost = vectorIcon.data()->sharedIconDataCost(); |
|
200 } |
|
201 } |
|
202 |
|
203 if (item) { |
|
204 item->iconOptions = options; |
|
205 } |
|
206 if (tempIconCacheItem.data()) { |
|
207 tempIconCacheItem.take(); |
|
208 } |
|
209 return item; |
|
210 } |
|
211 |
|
212 |
|
213 /*! |
|
214 \fn HbIconCacheItemCreator::createCacheItem() |
|
215 This overloaded createCacheItem is a helper function to populate a cache item |
|
216 if this item is already created with some parameters either on the Gpu or the Cpu |
|
217 \a iconCacheItem denotes the cacheItem to be populated |
|
218 \a key unique identifier to identify the cache item |
|
219 \a currentRenderingMode ThemeServer's current rendering mode state |
|
220 |
|
221 */ |
|
222 void HbIconCacheItemCreator::createCacheItem(HbIconCacheItem &iconCacheItem, |
|
223 const HbIconKey &key, |
|
224 HbRenderingMode currentRenderingMode) |
|
225 { |
|
226 #ifndef Q_OS_SYMBIAN |
|
227 Q_UNUSED(currentRenderingMode) |
|
228 #endif |
|
229 QScopedPointer <HbIconProcessor> rasterIcon; |
|
230 QScopedPointer <HbIconProcessor> vectorIcon; |
|
231 |
|
232 // Set the render mode to EHWRendering, only if the client is requesting a HW rendered icon |
|
233 // and ThemeServer is in HW rendering mode |
|
234 HbRenderingMode renderMode = ESWRendering; |
|
235 #ifndef Q_OS_SYMBIAN |
|
236 Q_UNUSED(renderMode) |
|
237 #endif |
|
238 |
|
239 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
246 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
240 if((key.renderMode == EHWRendering) && (currentRenderingMode == EHWRendering)) { |
247 if((key.renderMode == EHWRendering) && (currentRenderingMode == EHWRendering)) { |
241 renderMode = EHWRendering; |
248 renderMode = EHWRendering; |
242 } |
249 } |
243 #endif |
250 #endif |
303 HbIconLoader::IconLoaderOptions options, |
324 HbIconLoader::IconLoaderOptions options, |
304 const QString &format, |
325 const QString &format, |
305 const QVector<HbSharedIconInfo> &multiPieceIconInfo, |
326 const QVector<HbSharedIconInfo> &multiPieceIconInfo, |
306 HbMultiIconParams &multiPieceIconParams, |
327 HbMultiIconParams &multiPieceIconParams, |
307 bool allNvg, |
328 bool allNvg, |
308 HbRenderingMode currentRenderingMode) |
329 HbRenderingMode renderMode) |
309 { |
330 { |
310 |
331 |
311 #ifndef Q_OS_SYMBIAN |
332 #ifndef Q_OS_SYMBIAN |
312 Q_UNUSED(currentRenderingMode) |
333 Q_UNUSED(renderMode) |
313 #endif |
334 #endif |
314 |
335 |
315 HbIconCacheItem *item = 0; |
336 HbIconCacheItem *item = 0; |
316 QScopedPointer<HbIconCacheItem> tempIconCacheItem; |
337 QScopedPointer<HbIconCacheItem> tempIconCacheItem; |
317 bool isIconCreated = false; |
338 bool isIconCreated = false; |
318 QScopedPointer<HbIconProcessor> rasterIcon; |
339 QScopedPointer<HbIconProcessor> rasterIcon; |
319 |
340 |
320 // Set the render mode to EHWRendering, only if the client is requesting a HW rendered icon |
|
321 // and ThemeServer is in HW rendering mode |
|
322 HbRenderingMode renderMode = ESWRendering; |
|
323 #ifndef Q_OS_SYMBIAN |
|
324 Q_UNUSED(renderMode) |
|
325 #endif |
|
326 |
|
327 #if defined(HB_SGIMAGE_ICON) || defined(HB_NVG_CS_ICON) |
|
328 if((finalIconKey.renderMode == EHWRendering) && (currentRenderingMode == EHWRendering)) { |
|
329 renderMode = EHWRendering; |
|
330 } |
|
331 #endif |
|
332 if (allNvg) { |
341 if (allNvg) { |
333 #ifdef HB_SGIMAGE_ICON |
342 #ifdef HB_SGIMAGE_ICON |
334 if(renderMode == EHWRendering){ |
343 if(renderMode == EHWRendering){ |
335 if (HbThemeServerPrivate::gpuMemoryState()) { |
344 if (HbThemeServerPrivate::gpuMemoryState()) { |
336 rasterIcon.reset(new HbSgimageIconProcessor( |
345 rasterIcon.reset(new HbSgimageIconProcessor( |
337 finalIconKey, |
346 finalIconKey, |
338 (HbIconLoader::IconLoaderOptions)multiPieceIconParams.options, |
347 (HbIconLoader::IconLoaderOptions)multiPieceIconParams.options, |
339 KSgimage)); |
348 KSgimage)); |
|
349 |
|
350 if(!rasterIcon.data()) { |
|
351 rasterIcon.reset(new HbPixmapIconProcessor( |
|
352 finalIconKey, |
|
353 (HbIconLoader::IconLoaderOptions)multiPieceIconParams.options, |
|
354 KNvg)); |
|
355 } |
340 } |
356 } |
341 |
357 |
342 } else { |
358 } else { |
343 rasterIcon.reset(new HbPixmapIconProcessor( |
359 rasterIcon.reset(new HbPixmapIconProcessor( |
344 finalIconKey, |
360 finalIconKey, |