45 #define EGL_DESTROY_SURFACE(display, surface) \ |
45 #define EGL_DESTROY_SURFACE(display, surface) \ |
46 if (surface != EGL_NO_SURFACE) { eglDestroySurface(display, surface); } |
46 if (surface != EGL_NO_SURFACE) { eglDestroySurface(display, surface); } |
47 |
47 |
48 #define EGL_DESTROY_CONTEXT(display, context) \ |
48 #define EGL_DESTROY_CONTEXT(display, context) \ |
49 if (context != EGL_NO_CONTEXT) { eglDestroyContext(display, context); } |
49 if (context != EGL_NO_CONTEXT) { eglDestroyContext(display, context); } |
50 |
50 |
51 // Constants |
51 // Constants |
52 static const int HB_BITS_PER_COLOR = 8; |
52 static const int HB_BITS_PER_COLOR = 8; |
53 |
53 |
54 HbNvgIconImpl::HbNvgIconImpl(const HbSharedIconInfo &iconData, |
54 HbNvgIconImpl::HbNvgIconImpl(const HbSharedIconInfo &iconData, |
55 const QString& name, |
55 const QString &name, |
56 const QSizeF& keySize, |
56 const QSizeF &keySize, |
57 Qt::AspectRatioMode aspectRatioMode, |
57 Qt::AspectRatioMode aspectRatioMode, |
58 QIcon::Mode mode, |
58 QIcon::Mode mode, |
59 bool mirrored, |
59 bool mirrored, |
60 HbRenderingMode renderMode): |
60 HbRenderingMode renderMode): |
61 HbIconImpl(iconData, |
61 HbIconImpl(iconData, |
62 name, |
62 name, |
63 keySize, |
63 keySize, |
64 aspectRatioMode, |
64 aspectRatioMode, |
65 mode, |
65 mode, |
66 mirrored, |
66 mirrored, |
67 renderMode), |
67 renderMode), |
68 readyToRender(false), |
68 readyToRender(false), |
69 specialCaseApplied(false), |
69 specialCaseApplied(false), |
70 nvgEngine(NULL), |
70 nvgEngine(0), |
71 eglStates(HbEglStates::global()), |
71 eglStates(HbEglStates::global()), |
72 vgImageRenderer(0), |
72 vgImageRenderer(0), |
73 pixmapIconRenderer(0) |
73 pixmapIconRenderer(0) |
74 { |
74 { |
75 eglStates->ref(); |
75 eglStates->ref(); |
76 retrieveNvgData(); |
76 retrieveNvgData(); |
77 } |
77 } |
78 |
78 |
257 if (eglChooseConfig(display, attribList, &config, 1, &numConfigs) == EGL_FALSE) { |
257 if (eglChooseConfig(display, attribList, &config, 1, &numConfigs) == EGL_FALSE) { |
258 return currentPixmap; |
258 return currentPixmap; |
259 } |
259 } |
260 |
260 |
261 if (currentReadSurface == EGL_NO_SURFACE) { |
261 if (currentReadSurface == EGL_NO_SURFACE) { |
262 //pixmap is called without EGL being initialized |
262 //pixmap is called without EGL being initialized |
263 |
263 |
264 const EGLint attribList2[] = { |
264 const EGLint attribList2[] = { |
265 EGL_WIDTH, width, |
265 EGL_WIDTH, width, |
266 EGL_HEIGHT, height, |
266 EGL_HEIGHT, height, |
267 EGL_NONE |
267 EGL_NONE |
278 HbNvgEngine localNvgEngine; |
278 HbNvgEngine localNvgEngine; |
279 |
279 |
280 EGLContext newContext = EGL_NO_CONTEXT; |
280 EGLContext newContext = EGL_NO_CONTEXT; |
281 if (eglContext == EGL_NO_CONTEXT) { |
281 if (eglContext == EGL_NO_CONTEXT) { |
282 newContext = eglCreateContext(display, config, EGL_NO_CONTEXT, 0); |
282 newContext = eglCreateContext(display, config, EGL_NO_CONTEXT, 0); |
283 if (newContext == EGL_NO_CONTEXT) { |
283 if (newContext == EGL_NO_CONTEXT) { |
284 EGL_DESTROY_SURFACE(display, dummySurface); |
284 EGL_DESTROY_SURFACE(display, dummySurface); |
285 return currentPixmap; |
285 return currentPixmap; |
286 } |
286 } |
287 } |
287 } |
288 |
288 |
289 if (dummySurface) { |
289 if (dummySurface) { |
290 if (eglMakeCurrent(display, dummySurface, dummySurface, |
290 if (eglMakeCurrent(display, dummySurface, dummySurface, |
291 newContext) == EGL_FALSE) { |
291 newContext) == EGL_FALSE) { |
292 EGL_DESTROY_SURFACE(display, dummySurface); |
292 EGL_DESTROY_SURFACE(display, dummySurface); |
293 EGL_DESTROY_CONTEXT(display, newContext); |
293 EGL_DESTROY_CONTEXT(display, newContext); |
294 return currentPixmap; |
294 return currentPixmap; |
295 } |
295 } |
296 |
296 |
297 surfaceImage = createVGImageFromNVG(display, |
297 surfaceImage = createVGImageFromNVG(display, |
298 dummySurface, |
298 dummySurface, |
299 dummySurface, |
299 dummySurface, |
300 newContext, |
300 newContext, |
301 width, |
301 width, |
324 image = QImage(width, height, QImage::Format_ARGB32_Premultiplied); |
324 image = QImage(width, height, QImage::Format_ARGB32_Premultiplied); |
325 vgGetImageSubData(surfaceImage, image.bits(), image.bytesPerLine(), |
325 vgGetImageSubData(surfaceImage, image.bits(), image.bytesPerLine(), |
326 VG_sARGB_8888_PRE, 0, 0, width, height); |
326 VG_sARGB_8888_PRE, 0, 0, width, height); |
327 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
327 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
328 } else { |
328 } else { |
329 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
329 eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
330 prevEGLState.restore(); |
330 prevEGLState.restore(); |
331 image = QImage(width, height, QImage::Format_ARGB32_Premultiplied); |
331 image = QImage(width, height, QImage::Format_ARGB32_Premultiplied); |
332 vgGetImageSubData(surfaceImage, image.bits(), image.bytesPerLine(), |
332 vgGetImageSubData(surfaceImage, image.bits(), image.bytesPerLine(), |
333 VG_sARGB_8888_PRE, 0, 0, width, height); |
333 VG_sARGB_8888_PRE, 0, 0, width, height); |
334 } |
334 } |
335 |
335 |
336 vgDestroyImage(surfaceImage); |
336 vgDestroyImage(surfaceImage); |
337 |
337 |
338 EGL_DESTROY_SURFACE(display, dummySurface); |
338 EGL_DESTROY_SURFACE(display, dummySurface); |
339 EGL_DESTROY_CONTEXT(display, newContext); |
339 EGL_DESTROY_CONTEXT(display, newContext); |
340 |
340 |
341 currentPixmap = QPixmap::fromImage(image); |
341 currentPixmap = QPixmap::fromImage(image); |
342 return currentPixmap; |
342 return currentPixmap; |
343 } |
343 } |
344 |
344 |
345 HbNvgEngine::HbNvgErrorType HbNvgIconImpl::drawNVGIcon(const QSize & size, HbNvgEngine & nvgEngine) |
345 HbNvgEngine::HbNvgErrorType HbNvgIconImpl::drawNVGIcon(const QSize &size, HbNvgEngine &nvgEngine) |
346 { |
346 { |
347 |
347 |
348 VGint mMatrixMode; |
348 VGint mMatrixMode; |
349 VGfloat mImageMatrix[9]; |
349 VGfloat mImageMatrix[9]; |
350 VGfloat mPathMatrix[9]; |
350 VGfloat mPathMatrix[9]; |
420 } |
420 } |
421 |
421 |
422 void HbNvgIconImpl::retrieveNvgData() |
422 void HbNvgIconImpl::retrieveNvgData() |
423 { |
423 { |
424 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
424 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
425 nvgData = QByteArray::fromRawData((char*)manager->base() + sharedIconData.nvgData.offset, |
425 nvgData = QByteArray::fromRawData((char *)manager->base() + sharedIconData.nvgData.offset, |
426 sharedIconData.nvgData.dataSize); |
426 sharedIconData.nvgData.dataSize); |
427 defaultIconSize = |
427 defaultIconSize = |
428 QSize(sharedIconData.nvgData.defaultWidth, sharedIconData.nvgData.defaultHeight); |
428 QSize(sharedIconData.nvgData.defaultWidth, sharedIconData.nvgData.defaultHeight); |
429 contentSize = QSize(sharedIconData.nvgData.width, sharedIconData.nvgData.height); |
429 contentSize = QSize(sharedIconData.nvgData.width, sharedIconData.nvgData.height); |
430 |
430 |
431 } |
431 } |
432 |
432 |
433 VGImage HbNvgIconImpl::getVgImage(HbIconImpl * impl, QPainter * painter) |
433 VGImage HbNvgIconImpl::getVgImage(HbIconImpl *impl, QPainter *painter) |
434 { |
434 { |
435 HbNvgIconImpl * nvgImpl = (HbNvgIconImpl*)impl; |
435 HbNvgIconImpl *nvgImpl = (HbNvgIconImpl *)impl; |
436 |
436 |
437 painter->beginNativePainting(); |
437 painter->beginNativePainting(); |
438 |
438 |
439 VGImage vgimage = nvgImpl->createVGImageFromNVG(nvgImpl->eglStates->display, |
439 VGImage vgimage = nvgImpl->createVGImageFromNVG(nvgImpl->eglStates->display, |
440 nvgImpl->eglStates->currentReadSurface, |
440 nvgImpl->eglStates->currentReadSurface, |
447 |
447 |
448 painter->endNativePainting(); |
448 painter->endNativePainting(); |
449 |
449 |
450 return vgimage; |
450 return vgimage; |
451 } |
451 } |
452 void HbNvgIconImpl::paint(QPainter* painter, |
452 void HbNvgIconImpl::paint(QPainter *painter, |
453 const QRectF& rect, |
453 const QRectF &rect, |
454 Qt::Alignment alignment, |
454 Qt::Alignment alignment, |
455 const QPainterPath &clipPath, |
455 const QPainterPath &clipPath, |
456 HbMaskableIconImpl * maskIconData) |
456 HbMaskableIconImpl *maskIconData) |
457 { |
457 { |
458 #ifdef HB_ICON_CACHE_DEBUG |
458 #ifdef HB_ICON_CACHE_DEBUG |
459 qDebug() << "HbNvgIconImpl::paint()-->"<<this->fileName; |
459 qDebug() << "HbNvgIconImpl::paint()-->" << this->fileName; |
460 #endif |
460 #endif |
461 QSizeF renderSize = contentSize; |
461 QSizeF renderSize = contentSize; |
462 |
462 |
463 NvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(aspectRatioMode); |
463 NvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(aspectRatioMode); |
464 |
464 |
492 multiPieceIcon || painter->opacity() != 1.0) { |
493 multiPieceIcon || painter->opacity() != 1.0) { |
493 if (drawRasterizedIcon(painter, topLeft, renderSize, clipPath)) { |
494 if (drawRasterizedIcon(painter, topLeft, renderSize, clipPath)) { |
494 return; |
495 return; |
495 } |
496 } |
496 } |
497 } |
497 |
498 |
498 vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER); |
499 vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER); |
499 drawNVGIcon(painter, topLeft, renderSize, settings); |
500 drawNVGIcon(painter, topLeft, renderSize, settings); |
500 } |
501 } |
501 |
502 |
502 void HbNvgIconImpl::drawNVGIcon(QPainter * painter, |
503 void HbNvgIconImpl::drawNVGIcon(QPainter *painter, |
503 const QPointF & topLeft, |
504 const QPointF &topLeft, |
504 const QSizeF & renderSize, |
505 const QSizeF &renderSize, |
505 NvgAspectRatioSettings settings) |
506 NvgAspectRatioSettings settings) |
506 { |
507 { |
507 nvgEngine->engine()->setPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, |
508 nvgEngine->engine()->setPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, |
508 settings.type); |
509 settings.type); |
509 nvgEngine->engine()->enableMirroring(mirrored); |
510 nvgEngine->engine()->enableMirroring(mirrored); |
510 |
511 |
511 painter->beginNativePainting(); |
512 painter->beginNativePainting(); |
512 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); |
513 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); |
513 vgTranslate(topLeft.x(), topLeft.y()); |
514 vgTranslate(topLeft.x(), topLeft.y()); |
579 nvgEngine->engine()->drawNvg(nvgData, renderSize.toSize()); |
580 nvgEngine->engine()->drawNvg(nvgData, renderSize.toSize()); |
580 |
581 |
581 painter->endNativePainting(); |
582 painter->endNativePainting(); |
582 } |
583 } |
583 |
584 |
584 bool HbNvgIconImpl::drawRasterizedIcon(QPainter * painter, |
585 bool HbNvgIconImpl::drawRasterizedIcon(QPainter *painter, |
585 const QPointF & topLeft, |
586 const QPointF &topLeft, |
586 const QSizeF & renderSize, |
587 const QSizeF &renderSize, |
587 const QPainterPath &clipPath) |
588 const QPainterPath &clipPath) |
588 { |
589 { |
589 bool ret = false; |
590 bool ret = false; |
590 // need to do a reset if EGL contexts changes/recreated |
591 // need to do a reset if EGL contexts changes/recreated |
591 if (!eglStates->initialized()) { |
592 if (!eglStates->initialized()) { |
620 ret = vgImageRenderer->draw(painter, topLeft, clipPath); |
621 ret = vgImageRenderer->draw(painter, topLeft, clipPath); |
621 } |
622 } |
622 return ret; |
623 return ret; |
623 } |
624 } |
624 |
625 |
625 QPointF HbNvgIconImpl::setAlignment(const QRectF& rect, |
626 QPointF HbNvgIconImpl::setAlignment(const QRectF &rect, |
626 QSizeF& renderSize, |
627 QSizeF &renderSize, |
627 Qt::Alignment alignment) |
628 Qt::Alignment alignment) |
628 { |
629 { |
629 QPointF topLeft = rect.topLeft(); |
630 QPointF topLeft = rect.topLeft(); |
630 if (alignment & Qt::AlignRight) { |
631 if (alignment & Qt::AlignRight) { |
631 topLeft.setX(rect.right() - renderSize.width()); |
632 topLeft.setX(rect.right() - renderSize.width()); |