43 #include "qpaintengine_vg_p.h" |
43 #include "qpaintengine_vg_p.h" |
44 #include <QtGui/private/qdrawhelper_p.h> |
44 #include <QtGui/private/qdrawhelper_p.h> |
45 #include "qvg_p.h" |
45 #include "qvg_p.h" |
46 #include "qvgimagepool_p.h" |
46 #include "qvgimagepool_p.h" |
47 |
47 |
48 #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE |
48 #if defined(Q_OS_SYMBIAN) |
49 #include <private/qt_s60_p.h> |
49 #include <private/qt_s60_p.h> |
50 #include <fbs.h> |
50 #include <fbs.h> |
51 #include <graphics/sgimage.h> |
51 #endif |
|
52 #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE |
|
53 #include <sgresource/sgimage.h> |
52 typedef EGLImageKHR (*pfnEglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, EGLint*); |
54 typedef EGLImageKHR (*pfnEglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, EGLint*); |
53 typedef EGLBoolean (*pfnEglDestroyImageKHR)(EGLDisplay, EGLImageKHR); |
55 typedef EGLBoolean (*pfnEglDestroyImageKHR)(EGLDisplay, EGLImageKHR); |
54 typedef VGImage (*pfnVgCreateEGLImageTargetKHR)(VGeglImageKHR); |
56 typedef VGImage (*pfnVgCreateEGLImageTargetKHR)(VGeglImageKHR); |
55 #endif // QT_SYMBIAN_SUPPORTS_SGIMAGE |
57 #endif // QT_SYMBIAN_SUPPORTS_SGIMAGE |
56 |
58 |
462 source = QImage(); |
464 source = QImage(); |
463 } |
465 } |
464 |
466 |
465 void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) |
467 void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) |
466 { |
468 { |
|
469 if (type == QPixmapData::SgImage && pixmap) { |
467 #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
470 #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
468 if (type == QPixmapData::SgImage && pixmap) { |
|
469 RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); |
471 RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); |
470 // when "0" used as argument then |
|
471 // default display, context are used |
|
472 if (!context) |
|
473 context = qt_vg_create_context(0, QInternal::Pixmap); |
|
474 |
472 |
475 destroyImages(); |
473 destroyImages(); |
476 prevSize = QSize(); |
474 prevSize = QSize(); |
477 |
475 |
478 TInt err = 0; |
476 TInt err = 0; |
479 |
477 |
480 err = SgDriver::Open(); |
478 RSgDriver driver; |
481 if(err != KErrNone) { |
479 err = driver.Open(); |
|
480 if (err != KErrNone) { |
482 cleanup(); |
481 cleanup(); |
483 return; |
482 return; |
484 } |
483 } |
485 |
484 |
486 if(sgImage->IsNull()) { |
485 if (sgImage->IsNull()) { |
487 cleanup(); |
486 cleanup(); |
488 SgDriver::Close(); |
487 driver.Close(); |
489 return; |
488 return; |
490 } |
489 } |
491 |
490 |
492 TSgImageInfo sgImageInfo; |
491 TSgImageInfo sgImageInfo; |
493 err = sgImage->GetInfo(sgImageInfo); |
492 err = sgImage->GetInfo(sgImageInfo); |
494 if(err != KErrNone) { |
493 if (err != KErrNone) { |
495 cleanup(); |
494 cleanup(); |
496 SgDriver::Close(); |
495 driver.Close(); |
497 return; |
496 return; |
498 } |
497 } |
499 |
498 |
500 pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
499 pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
501 pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
500 pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
502 pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
501 pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
503 |
502 |
504 if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
503 if (eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
505 cleanup(); |
504 cleanup(); |
506 SgDriver::Close(); |
505 driver.Close(); |
507 return; |
506 return; |
508 } |
507 } |
509 |
508 |
510 const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
509 const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
511 EGLImageKHR eglImage = eglCreateImageKHR(context->display(), |
510 EGLImageKHR eglImage = eglCreateImageKHR(QEglContext::display(), |
512 EGL_NO_CONTEXT, |
511 EGL_NO_CONTEXT, |
513 EGL_NATIVE_PIXMAP_KHR, |
512 EGL_NATIVE_PIXMAP_KHR, |
514 (EGLClientBuffer)sgImage, |
513 (EGLClientBuffer)sgImage, |
515 (EGLint*)KEglImageAttribs); |
514 (EGLint*)KEglImageAttribs); |
516 |
515 |
517 if(eglGetError() != EGL_SUCCESS) { |
516 if (eglGetError() != EGL_SUCCESS) { |
518 cleanup(); |
517 cleanup(); |
519 SgDriver::Close(); |
518 driver.Close(); |
520 return; |
519 return; |
521 } |
520 } |
522 |
521 |
523 vgImage = vgCreateEGLImageTargetKHR(eglImage); |
522 vgImage = vgCreateEGLImageTargetKHR(eglImage); |
524 if(vgGetError() != VG_NO_ERROR) { |
523 if (vgGetError() != VG_NO_ERROR) { |
525 cleanup(); |
524 cleanup(); |
526 eglDestroyImageKHR(context->display(), eglImage); |
525 eglDestroyImageKHR(QEglContext::display(), eglImage); |
527 SgDriver::Close(); |
526 driver.Close(); |
528 return; |
527 return; |
529 } |
528 } |
530 |
529 |
531 w = sgImageInfo.iSizeInPixels.iWidth; |
530 w = sgImageInfo.iSizeInPixels.iWidth; |
532 h = sgImageInfo.iSizeInPixels.iHeight; |
531 h = sgImageInfo.iSizeInPixels.iHeight; |
582 fromImage(img, Qt::AutoColor); |
582 fromImage(img, Qt::AutoColor); |
583 |
583 |
584 if(deleteSourceBitmap) |
584 if(deleteSourceBitmap) |
585 delete bitmap; |
585 delete bitmap; |
586 } |
586 } |
587 #else |
|
588 Q_UNUSED(pixmap); |
|
589 Q_UNUSED(type); |
|
590 #endif |
|
591 } |
587 } |
592 |
588 |
593 void* QVGPixmapData::toNativeType(NativeType type) |
589 void* QVGPixmapData::toNativeType(NativeType type) |
594 { |
590 { |
|
591 if (type == QPixmapData::SgImage) { |
595 #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
592 #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
596 if (type == QPixmapData::SgImage) { |
|
597 toVGImage(); |
593 toVGImage(); |
598 |
594 |
599 if(!isValid() || vgImage == VG_INVALID_HANDLE) |
595 if (!isValid() || vgImage == VG_INVALID_HANDLE) |
600 return 0; |
596 return 0; |
601 |
597 |
602 TInt err = 0; |
598 TInt err = 0; |
603 |
599 |
604 err = SgDriver::Open(); |
600 RSgDriver driver; |
605 if(err != KErrNone) |
601 err = driver.Open(); |
|
602 if (err != KErrNone) |
606 return 0; |
603 return 0; |
607 |
604 |
608 TSgImageInfo sgInfo; |
605 TSgImageInfo sgInfo; |
609 sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; |
606 sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; |
610 sgInfo.iSizeInPixels.SetSize(w, h); |
607 sgInfo.iSizeInPixels.SetSize(w, h); |
611 sgInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget; |
608 sgInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface; |
612 sgInfo.iShareable = ETrue; |
|
613 sgInfo.iCpuAccess = ESgCpuAccessNone; |
|
614 sgInfo.iScreenId = KSgScreenIdMain; //KSgScreenIdAny; |
|
615 sgInfo.iUserAttributes = NULL; |
|
616 sgInfo.iUserAttributeCount = 0; |
|
617 |
609 |
618 RSgImage *sgImage = q_check_ptr(new RSgImage()); |
610 RSgImage *sgImage = q_check_ptr(new RSgImage()); |
619 err = sgImage->Create(sgInfo, NULL, NULL); |
611 err = sgImage->Create(sgInfo, NULL, NULL); |
620 if(err != KErrNone) { |
612 if (err != KErrNone) { |
621 SgDriver::Close(); |
613 driver.Close(); |
622 return 0; |
614 return 0; |
623 } |
615 } |
624 |
616 |
625 pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
617 pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
626 pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
618 pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
627 pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
619 pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
628 |
620 |
629 if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
621 if (eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
630 SgDriver::Close(); |
622 driver.Close(); |
631 return 0; |
623 return 0; |
632 } |
624 } |
633 |
625 |
634 const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
626 const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
635 EGLImageKHR eglImage = eglCreateImageKHR(context->display(), |
627 EGLImageKHR eglImage = eglCreateImageKHR(QEglContext::display(), |
636 EGL_NO_CONTEXT, |
628 EGL_NO_CONTEXT, |
637 EGL_NATIVE_PIXMAP_KHR, |
629 EGL_NATIVE_PIXMAP_KHR, |
638 (EGLClientBuffer)sgImage, |
630 (EGLClientBuffer)sgImage, |
639 (EGLint*)KEglImageAttribs); |
631 (EGLint*)KEglImageAttribs); |
640 if(eglGetError() != EGL_SUCCESS) { |
632 if (eglGetError() != EGL_SUCCESS) { |
641 sgImage->Close(); |
633 sgImage->Close(); |
642 SgDriver::Close(); |
634 driver.Close(); |
643 return 0; |
635 return 0; |
644 } |
636 } |
645 |
637 |
646 VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); |
638 VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); |
647 if(vgGetError() != VG_NO_ERROR) { |
639 if (vgGetError() != VG_NO_ERROR) { |
648 eglDestroyImageKHR(context->display(), eglImage); |
640 eglDestroyImageKHR(QEglContext::display(), eglImage); |
649 sgImage->Close(); |
641 sgImage->Close(); |
650 SgDriver::Close(); |
642 driver.Close(); |
651 return 0; |
643 return 0; |
652 } |
644 } |
653 |
645 |
654 vgCopyImage(dstVgImage, 0, 0, |
646 vgCopyImage(dstVgImage, 0, 0, |
655 vgImage, 0, 0, |
647 vgImage, 0, 0, |
656 w, h, VG_FALSE); |
648 w, h, VG_FALSE); |
657 |
649 |
658 if(vgGetError() != VG_NO_ERROR) { |
650 if (vgGetError() != VG_NO_ERROR) { |
659 sgImage->Close(); |
651 sgImage->Close(); |
660 sgImage = 0; |
652 sgImage = 0; |
661 } |
653 } |
662 // release stuff |
654 // release stuff |
663 vgDestroyImage(dstVgImage); |
655 vgDestroyImage(dstVgImage); |
664 eglDestroyImageKHR(context->display(), eglImage); |
656 eglDestroyImageKHR(QEglContext::display(), eglImage); |
665 SgDriver::Close(); |
657 driver.Close(); |
666 return reinterpret_cast<void*>(sgImage); |
658 return reinterpret_cast<void*>(sgImage); |
|
659 #endif |
667 } else if (type == QPixmapData::FbsBitmap) { |
660 } else if (type == QPixmapData::FbsBitmap) { |
668 CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); |
661 CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); |
669 |
662 |
670 if (bitmap) { |
663 if (bitmap) { |
671 if (bitmap->Create(TSize(source.width(), source.height()), |
664 if (bitmap->Create(TSize(source.width(), source.height()), |