418 CleanupStack::Pop(obj); |
574 CleanupStack::Pop(obj); |
419 return obj; |
575 return obj; |
420 } |
576 } |
421 |
577 |
422 |
578 |
423 void CRawSingleBufferSurface::CreateL(TInt aIndex) |
579 void CRawSingleBufferSurface::CreateL(TInt aIndex, const TPoint & /*aPoint */) |
424 { |
580 { |
425 RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs; |
581 RSurfaceManager::TSurfaceCreationAttributesBuf surfaceAttribs; |
426 |
582 |
427 GetSurfAttribs(surfaceAttribs, aIndex); |
583 TInt sizeIndex = 0; |
428 |
584 if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG) |
429 iBuffers = 1; |
585 { |
430 surfaceAttribs().iBuffers = 1; |
586 sizeIndex = KMaxSurfaceSizes-1; |
431 |
587 } |
432 TInt err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId); |
588 TInt err = KErrNone; |
433 User::LeaveIfError(err); |
589 do |
|
590 { |
|
591 GetSurfAttribs(surfaceAttribs, aIndex, sizeIndex); |
|
592 iBuffers = 1; |
|
593 surfaceAttribs().iBuffers = 1; |
|
594 err = iSurfaceManager.CreateSurface(surfaceAttribs, iSurfaceId); |
|
595 iActualSize = surfaceAttribs().iSize; |
|
596 sizeIndex--; |
|
597 } |
|
598 while(err != KErrNone && sizeIndex >= 0); |
434 } |
599 } |
435 |
600 |
436 CRawSingleBufferSurface::~CRawSingleBufferSurface() |
601 CRawSingleBufferSurface::~CRawSingleBufferSurface() |
437 { |
602 { |
438 } |
603 } |
439 |
604 |
440 class CWindow: public CBase |
605 |
441 { |
606 TInt CEglSurfaceBase::Activate() |
442 public: |
|
443 static CWindow *NewL(TInt aIndex); |
|
444 RWindow& Window(); |
|
445 ~CWindow(); |
|
446 private: |
|
447 void ConstructL(TInt aIndex); |
|
448 CWindow(); |
|
449 |
|
450 private: |
|
451 RWindow iWindow; |
|
452 RWindowGroup iWindowGroup; |
|
453 RWsSession iWsSession; |
|
454 }; |
|
455 |
|
456 |
|
457 CWindow* CWindow::NewL(TInt aIndex) |
|
458 { |
|
459 CWindow *self = new (ELeave) CWindow; |
|
460 CleanupStack::PushL(self); |
|
461 self->ConstructL(aIndex); |
|
462 CleanupStack::Pop(self); |
|
463 return self; |
|
464 } |
|
465 |
|
466 |
|
467 void CWindow::ConstructL(TInt aIndex) |
|
468 { |
|
469 RFbsSession::Connect(); |
|
470 if (aIndex >= KSurfaceMaxIndex) |
|
471 { |
|
472 User::Leave(KErrOverflow); |
|
473 } |
|
474 User::LeaveIfError(iWsSession.Connect()); |
|
475 iWindowGroup = RWindowGroup(iWsSession); |
|
476 User::LeaveIfError(iWindowGroup.Construct((TUint32)this)); |
|
477 iWindow = RWindow(iWsSession); |
|
478 User::LeaveIfError(iWindow.Construct(iWindowGroup, -1U)); |
|
479 const TSurfaceParamsCommon& winAttrib = KSurfaceParams[aIndex]; |
|
480 iWindow.SetExtent(TPoint(winAttrib.iXPos, winAttrib.iYPos), TSize(winAttrib.iXSize, winAttrib.iYSize)); |
|
481 iWindow.SetRequiredDisplayMode(winAttrib.iDisplayMode); |
|
482 iWindow.Activate(); |
|
483 } |
|
484 |
|
485 |
|
486 CWindow::~CWindow() |
|
487 { |
|
488 iWindow.Close(); |
|
489 iWindowGroup.Close(); |
|
490 iWsSession.Close(); |
|
491 RFbsSession::Disconnect(); |
|
492 } |
|
493 |
|
494 |
|
495 CWindow::CWindow() |
|
496 { |
|
497 } |
|
498 |
|
499 |
|
500 RWindow& CWindow::Window() |
|
501 { |
|
502 return iWindow; |
|
503 } |
|
504 |
|
505 |
|
506 CEglWindowSurface* CEglWindowSurface::NewL() |
|
507 { |
|
508 CEglWindowSurface* self = new (ELeave) CEglWindowSurface; |
|
509 CleanupStack::PushL(self); |
|
510 self->ConstructL(); |
|
511 CleanupStack::Pop(self); |
|
512 return self; |
|
513 } |
|
514 |
|
515 |
|
516 void CEglWindowSurface::ConstructL() |
|
517 { |
|
518 } |
|
519 |
|
520 |
|
521 CEglWindowSurface::CEglWindowSurface() |
|
522 { |
|
523 } |
|
524 |
|
525 |
|
526 void CEglWindowSurface::CreateL(TInt aIndex) |
|
527 { |
|
528 SURF_ASSERT(aIndex < KSurfaceMaxIndex); |
|
529 SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex); |
|
530 iParamIndex = aIndex; |
|
531 iWindow = CWindow::NewL(aIndex); |
|
532 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
|
533 EGLint err; |
|
534 if (iDisplay == EGL_NO_DISPLAY) |
|
535 { |
|
536 err = eglGetError(); |
|
537 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
538 User::Leave(KErrNotSupported); |
|
539 } |
|
540 |
|
541 EGLConfig config; |
|
542 EGLint nConfigs = 0; |
|
543 |
|
544 // TODO: Need to use differnet config attribs based on aIndex. |
|
545 static const EGLint KConfigAttribs[] = |
|
546 { |
|
547 EGL_BUFFER_SIZE, 32, |
|
548 EGL_RED_SIZE, 8, |
|
549 EGL_GREEN_SIZE, 8, |
|
550 EGL_BLUE_SIZE, 8, |
|
551 EGL_ALPHA_SIZE, 8, |
|
552 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
|
553 EGL_RENDERABLE_TYPE,EGL_OPENVG_BIT, |
|
554 EGL_NONE |
|
555 }; |
|
556 |
|
557 // Need some way to configure the attribs ... |
|
558 eglChooseConfig(iDisplay, KConfigAttribs, &config, 1, &nConfigs); |
|
559 if (!nConfigs) |
|
560 { |
|
561 err = eglGetError(); |
|
562 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
563 User::Leave(KErrNotSupported); |
|
564 } |
|
565 |
|
566 if (!eglBindAPI(EGL_OPENVG_API)) |
|
567 { |
|
568 err = eglGetError(); |
|
569 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
570 User::Leave(KErrNotSupported); |
|
571 } |
|
572 iContext = eglCreateContext(iDisplay, config, 0, NULL); |
|
573 if (iContext == EGL_NO_CONTEXT) |
|
574 { |
|
575 err = eglGetError(); |
|
576 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
577 User::Leave(KErrNotSupported); |
|
578 } |
|
579 |
|
580 iSurface = eglCreateWindowSurface(iDisplay, config, &iWindow->Window(), NULL); |
|
581 if (iSurface == EGL_NO_SURFACE) |
|
582 { |
|
583 err = eglGetError(); |
|
584 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
585 User::Leave(KErrNotSupported); |
|
586 } |
|
587 } |
|
588 |
|
589 void CEglWindowSurface::SubmitContentL(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */) |
|
590 { |
|
591 ActivateL(); |
|
592 if (!eglSwapBuffers(iDisplay, iSurface)) |
|
593 { |
|
594 User::Leave(KErrBadHandle); |
|
595 } |
|
596 if (aShouldWaitForDisplay) |
|
597 { |
|
598 // We are cheating: We just wait for a bit to ensure that the swapbuffer is actually finished. |
|
599 // There is no way to determine how long this takes, so we just grab a number that should be |
|
600 // large enough... |
|
601 User::After(100 * 1000); // Wait 100ms. |
|
602 } |
|
603 } |
|
604 |
|
605 void CEglWindowSurface::ActivateL() |
|
606 { |
607 { |
607 if (!eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)) |
608 if (!eglMakeCurrent(iDisplay, iSurface, iSurface, iContext)) |
608 { |
609 { |
609 User::Leave(KErrBadHandle); |
610 EGLint err = eglGetError(); |
610 } |
611 RDebug::Printf("%s:%d: eglMakeCurrent gave error 0x%x", __FILE__, __LINE__, err); |
611 } |
612 return KErrBadHandle; |
612 |
613 } |
613 CEglWindowSurface::~CEglWindowSurface() |
614 return KErrNone; |
614 { |
615 } |
615 eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
616 |
616 if (iSurface != EGL_NO_SURFACE) |
617 void CEglSurfaceBase::ActivateL() |
617 { |
618 { |
618 eglDestroySurface(iDisplay, iSurface); |
619 User::LeaveIfError(Activate()); |
619 iSurface = EGL_NO_SURFACE; |
620 } |
620 } |
621 |
621 |
622 void CEglSurfaceBase::DrawComplexL(const TRgb& aColour) |
622 if (iDisplay != EGL_NO_DISPLAY) |
|
623 { |
|
624 eglDestroyContext(iDisplay, iContext); |
|
625 } |
|
626 |
|
627 delete iWindow; |
|
628 } |
|
629 |
|
630 TSurfaceId CEglWindowSurface::SurfaceId() const |
|
631 { |
|
632 // Default constructor for id sets it to a NULL-value, so if no window is created, we get |
|
633 // a defined surface id value that is invalid. |
|
634 TSurfaceId id; |
|
635 if (iWindow) |
|
636 { |
|
637 TSurfaceConfiguration surfConfig; |
|
638 iWindow->Window().GetBackgroundSurface(surfConfig); |
|
639 surfConfig.GetSurfaceId(id); |
|
640 } |
|
641 return id; |
|
642 } |
|
643 |
|
644 |
|
645 void CEglWindowSurface::DrawContentL(const TRgb& aColour) |
|
646 { |
623 { |
647 ActivateL(); |
624 ActivateL(); |
648 |
625 |
649 TSize size; |
626 TSize size; |
650 eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth); |
627 eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth); |
651 eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight); |
628 eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight); |
652 |
629 |
|
630 //Paint lots of random circles to keep the GPU busy. |
|
631 for(TInt i=0; i < 300; i++) |
|
632 { |
|
633 VGPaint paint = vgCreatePaint(); |
|
634 VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_APPEND_TO); |
|
635 |
|
636 TInt minDim = Min(size.iWidth, size.iHeight); |
|
637 VGfloat cx = RandomNumberInRange(0, size.iWidth); |
|
638 VGfloat cy = RandomNumberInRange(0, size.iHeight); |
|
639 VGfloat diameter = RandomNumberInRange(minDim / 20, minDim / 3); |
|
640 TRgb fillColour(RandomNumberInRange(0, 255), RandomNumberInRange(0, 255), RandomNumberInRange(0, 255), RandomNumberInRange(0, 255)); |
|
641 |
|
642 vguEllipse(path, cx, cy, diameter, diameter); |
|
643 vgSetPaint(paint, VG_FILL_PATH); |
|
644 vgSetColor(paint, fillColour.Value()); |
|
645 vgDrawPath(path, VG_FILL_PATH); |
|
646 |
|
647 vgDestroyPath(path); |
|
648 vgDestroyPaint(paint); |
|
649 } |
|
650 |
|
651 //Paint the top corner with aColour so we can identify the drawing. |
653 VGfloat fillColour[4]; |
652 VGfloat fillColour[4]; |
654 fillColour[0] = (VGfloat)aColour.Red() / 255.0f; |
653 fillColour[0] = (VGfloat)aColour.Red() / 255.0f; |
655 fillColour[1] = (VGfloat)aColour.Green() / 255.0f; |
654 fillColour[1] = (VGfloat)aColour.Green() / 255.0f; |
656 fillColour[2] = (VGfloat)aColour.Blue() / 255.0f; |
655 fillColour[2] = (VGfloat)aColour.Blue() / 255.0f; |
657 fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f; |
656 fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f; |
|
657 |
|
658 vgSetfv(VG_CLEAR_COLOR, 4, fillColour); |
|
659 vgClear(0, 0, 20, size.iHeight); |
|
660 } |
|
661 |
|
662 void CEglSurfaceBase::DrawContentL(const TRgb& aColour) |
|
663 { |
|
664 ActivateL(); |
|
665 |
|
666 TSize size; |
|
667 eglQuerySurface(iDisplay, iSurface, EGL_WIDTH, &size.iWidth); |
|
668 eglQuerySurface(iDisplay, iSurface, EGL_HEIGHT, &size.iHeight); |
|
669 |
|
670 VGfloat fillColour[4]; |
|
671 fillColour[0] = (VGfloat)aColour.Red() / 255.0f; |
|
672 fillColour[1] = (VGfloat)aColour.Green() / 255.0f; |
|
673 fillColour[2] = (VGfloat)aColour.Blue() / 255.0f; |
|
674 fillColour[3] = (VGfloat)aColour.Alpha() / 255.0f; |
658 |
675 |
659 vgSetfv(VG_CLEAR_COLOR, 4, fillColour); |
676 vgSetfv(VG_CLEAR_COLOR, 4, fillColour); |
660 vgClear(0, 0, size.iWidth, size.iHeight); |
677 vgClear(0, 0, size.iWidth, size.iHeight); |
661 } |
678 } |
662 |
679 |
663 |
680 void CEglSurfaceBase::CreateL(TInt aIndex, const TPoint &aOffset) |
664 void CEglWindowSurface::DrawContentL(TInt aIndex) |
681 { |
|
682 SURF_ASSERT(aIndex < KSurfaceMaxIndex); |
|
683 SURF_ASSERT(aIndex == KSurfaceParams[aIndex].iIndex); |
|
684 |
|
685 TInt sizeIndex = 0; |
|
686 if (KSurfaceParams[aIndex].iXSize & LARGEST_POSSIBLE_FLAG) |
|
687 { |
|
688 sizeIndex = KMaxSurfaceSizes-1; |
|
689 } |
|
690 TInt err = KErrNone; |
|
691 do |
|
692 { |
|
693 TRAP(err, DoCreateL(aIndex, aOffset, sizeIndex)); |
|
694 sizeIndex--; |
|
695 } |
|
696 while(err != KErrNone && sizeIndex >= 0); |
|
697 if (err != KErrNone) |
|
698 { |
|
699 // RDebug::Printf("%s:%d: err=%d (%d x %d)", __FILE__, __LINE__, err, iActualSize.iWidth, iActualSize.iHeight); |
|
700 User::Leave(err); |
|
701 } |
|
702 } |
|
703 |
|
704 TInt CEglSurfaceBase::SubmitContent(TBool aShouldWaitForDisplay, TInt /* aRectsIndex */) |
|
705 { |
|
706 TInt err = Activate(); |
|
707 if (err != KErrNone) |
|
708 { |
|
709 return err; |
|
710 } |
|
711 if (!eglSwapBuffers(iDisplay, iSurface)) |
|
712 { |
|
713 EGLint err = eglGetError(); |
|
714 RDebug::Printf("%s:%d: eglSwapBuffers gave error 0x%x", __FILE__, __LINE__, err); |
|
715 return KErrBadHandle; |
|
716 } |
|
717 if (aShouldWaitForDisplay) |
|
718 { |
|
719 // We are cheating: We just wait for a bit to ensure that the swapbuffer is actually finished. |
|
720 // There is no way to determine how long this takes, so we just grab a number that should be |
|
721 // large enough... |
|
722 User::After(100 * 1000); // Wait 100ms. |
|
723 } |
|
724 return KErrNone; |
|
725 } |
|
726 |
|
727 void CEglSurfaceBase::DrawContentL(TInt aIndex) |
665 { |
728 { |
666 ActivateL(); |
729 ActivateL(); |
667 CTestVgImage *vgImage = CTestVgImage::NewL(aIndex); |
730 CTestVgImage *vgImage = CTestVgImage::NewL(aIndex); |
668 CleanupStack::PushL(vgImage); |
731 CleanupStack::PushL(vgImage); |
669 vgDrawImage(vgImage->VGImage()); |
732 vgDrawImage(vgImage->VGImage()); |
670 CleanupStack::PopAndDestroy(vgImage); |
733 CleanupStack::PopAndDestroy(vgImage); |
671 } |
734 } |
672 |
735 |
673 void CEglWindowSurface::GetSurfaceParamsL(TSurfaceParamsRemote &aParams) |
736 void CEglSurfaceBase::GetSurfaceParamsL(TSurfaceParamsRemote &aParams) |
674 { |
737 { |
675 RSurfaceManager surfaceManager; |
738 RSurfaceManager surfaceManager; |
676 User::LeaveIfError(surfaceManager.Open()); |
739 User::LeaveIfError(surfaceManager.Open()); |
677 RSurfaceManager::TInfoBuf infoBuf; |
740 RSurfaceManager::TInfoBuf infoBuf; |
678 TInt err = surfaceManager.SurfaceInfo(SurfaceId(), infoBuf); |
741 TInt err = surfaceManager.SurfaceInfo(SurfaceId(), infoBuf); |
692 { |
755 { |
693 aParams.iCommonParams.iAttribs[i] = KSurfaceParams[iParamIndex].iAttribs[i]; |
756 aParams.iCommonParams.iAttribs[i] = KSurfaceParams[iParamIndex].iAttribs[i]; |
694 } |
757 } |
695 } |
758 } |
696 |
759 |
|
760 |
|
761 TInt CEglSurfaceBase::Notify(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, TUint32 /*aXTImes*/) |
|
762 { |
|
763 return KErrNotSupported; |
|
764 } |
|
765 |
|
766 TInt CEglSurfaceBase::WaitFor(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, |
|
767 TInt /*aTimeoutinMicroseconds*/, TUint32 & /*aTimeStamp*/) |
|
768 { |
|
769 return KErrNotSupported; |
|
770 } |
|
771 |
|
772 void CEglSurfaceBase::BaseCreateL(TInt aIndex, EGLint aSurfaceType) |
|
773 { |
|
774 iParamIndex = aIndex; |
|
775 iDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
|
776 |
|
777 EGLint err; |
|
778 if (iDisplay == EGL_NO_DISPLAY) |
|
779 { |
|
780 err = eglGetError(); |
|
781 RDebug::Printf("%s:%d: err = 0x%x", __FILE__, __LINE__, err); |
|
782 User::Leave(KErrNotSupported); |
|
783 } |
|
784 |
|
785 EGLint nConfigs = 0; |
|
786 |
|
787 // TODO: Need to use differnet config attribs based on aIndex. |
|
788 EGLint configAttribs[] = |
|
789 { |
|
790 EGL_BUFFER_SIZE, 32, |
|
791 EGL_RED_SIZE, 8, |
|
792 EGL_GREEN_SIZE, 8, |
|
793 EGL_BLUE_SIZE, 8, |
|
794 EGL_ALPHA_SIZE, 8, |
|
795 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
|
796 EGL_RENDERABLE_TYPE,EGL_OPENVG_BIT, |
|
797 EGL_NONE |
|
798 }; |
|
799 |
|
800 // Update surfacetype type to match |
|
801 for(TInt i = 0; configAttribs[i] != EGL_NONE; i += 2) |
|
802 { |
|
803 if (configAttribs[i] == EGL_SURFACE_TYPE) |
|
804 { |
|
805 configAttribs[i+1] = aSurfaceType; |
|
806 } |
|
807 } |
|
808 // Need some way to configure the attribs ... |
|
809 eglChooseConfig(iDisplay, configAttribs, &iConfig, 1, &nConfigs); |
|
810 if (!nConfigs) |
|
811 { |
|
812 err = eglGetError(); |
|
813 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
814 User::Leave(KErrNotSupported); |
|
815 } |
|
816 |
|
817 if (!eglBindAPI(EGL_OPENVG_API)) |
|
818 { |
|
819 err = eglGetError(); |
|
820 RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
821 User::Leave(KErrNotSupported); |
|
822 } |
|
823 iContext = eglCreateContext(iDisplay, iConfig, 0, NULL); |
|
824 if (iContext == EGL_NO_CONTEXT) |
|
825 { |
|
826 err = eglGetError(); |
|
827 //RDebug::Printf("%s:%d: err = %d", __FILE__, __LINE__, err); |
|
828 User::Leave(KErrNotSupported); |
|
829 } |
|
830 } |
|
831 |
|
832 void CEglSurfaceBase::Destroy() |
|
833 { |
|
834 eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
|
835 if (iSurface != EGL_NO_SURFACE) |
|
836 { |
|
837 eglDestroySurface(iDisplay, iSurface); |
|
838 iSurface = EGL_NO_SURFACE; |
|
839 } |
|
840 |
|
841 if (iDisplay != EGL_NO_DISPLAY) |
|
842 { |
|
843 eglDestroyContext(iDisplay, iContext); |
|
844 } |
|
845 } |
|
846 |
|
847 |
|
848 class CWindow: public CBase |
|
849 { |
|
850 public: |
|
851 static CWindow *NewL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex); |
|
852 RWindow& Window(); |
|
853 ~CWindow(); |
|
854 private: |
|
855 void ConstructL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex); |
|
856 CWindow(); |
|
857 |
|
858 private: |
|
859 RWindow iWindow; |
|
860 RWindowGroup iWindowGroup; |
|
861 RWsSession iWsSession; |
|
862 }; |
|
863 |
|
864 |
|
865 CWindow* CWindow::NewL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex) |
|
866 { |
|
867 CWindow *self = new (ELeave) CWindow; |
|
868 CleanupStack::PushL(self); |
|
869 self->ConstructL(aIndex, aOffset, aSizeIndex); |
|
870 CleanupStack::Pop(self); |
|
871 return self; |
|
872 } |
|
873 |
|
874 |
|
875 void CWindow::ConstructL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex) |
|
876 { |
|
877 RFbsSession::Connect(); |
|
878 if (aIndex >= KSurfaceMaxIndex) |
|
879 { |
|
880 User::Leave(KErrOverflow); |
|
881 } |
|
882 User::LeaveIfError(iWsSession.Connect()); |
|
883 iWindowGroup = RWindowGroup(iWsSession); |
|
884 User::LeaveIfError(iWindowGroup.Construct((TUint32)this)); |
|
885 iWindow = RWindow(iWsSession); |
|
886 User::LeaveIfError(iWindow.Construct(iWindowGroup, -1U)); |
|
887 TSurfaceParamsCommon winAttrib = KSurfaceParams[aIndex]; |
|
888 TSize winSize; |
|
889 if (winAttrib.iXSize & LARGEST_POSSIBLE_FLAG) |
|
890 { |
|
891 winSize = TSize(KSurfaceSizes[aSizeIndex].iWidth, KSurfaceSizes[aSizeIndex].iHeight); |
|
892 } |
|
893 else |
|
894 { |
|
895 winSize = TSize(winAttrib.iXSize, winAttrib.iYSize); |
|
896 } |
|
897 iWindow.SetExtent(TPoint(winAttrib.iXPos + aOffset.iX, winAttrib.iYPos + aOffset.iY), winSize); |
|
898 iWindow.SetRequiredDisplayMode(winAttrib.iDisplayMode); |
|
899 iWindow.Activate(); |
|
900 } |
|
901 |
|
902 |
|
903 CWindow::~CWindow() |
|
904 { |
|
905 iWindow.Close(); |
|
906 iWindowGroup.Close(); |
|
907 iWsSession.Close(); |
|
908 RFbsSession::Disconnect(); |
|
909 } |
|
910 |
|
911 |
|
912 CWindow::CWindow() |
|
913 { |
|
914 } |
|
915 |
|
916 |
|
917 RWindow& CWindow::Window() |
|
918 { |
|
919 return iWindow; |
|
920 } |
|
921 |
|
922 |
|
923 CEglWindowSurface* CEglWindowSurface::NewL() |
|
924 { |
|
925 CEglWindowSurface* self = new (ELeave) CEglWindowSurface; |
|
926 CleanupStack::PushL(self); |
|
927 self->ConstructL(); |
|
928 CleanupStack::Pop(self); |
|
929 return self; |
|
930 } |
|
931 |
|
932 |
|
933 void CEglWindowSurface::ConstructL() |
|
934 { |
|
935 } |
|
936 |
|
937 |
|
938 CEglWindowSurface::CEglWindowSurface() |
|
939 { |
|
940 } |
|
941 |
|
942 |
|
943 void CEglWindowSurface::DoCreateL(TInt aIndex, const TPoint &aOffset, TInt aSizeIndex) |
|
944 { |
|
945 iParamIndex = aIndex; |
|
946 iWindow = CWindow::NewL(aIndex, aOffset, aSizeIndex); |
|
947 iActualSize = iWindow->Window().Size(); |
|
948 |
|
949 CEglSurfaceBase::BaseCreateL(aIndex, EGL_WINDOW_BIT); |
|
950 |
|
951 iSurface = eglCreateWindowSurface(iDisplay, iConfig, &iWindow->Window(), NULL); |
|
952 if (iSurface == EGL_NO_SURFACE) |
|
953 { |
|
954 EGLint err = eglGetError(); |
|
955 RDebug::Printf("%s:%d: err = %x (%d x %d)", __FILE__, __LINE__, err, iActualSize.iWidth, iActualSize.iHeight); |
|
956 User::Leave(KErrNotSupported); |
|
957 } |
|
958 } |
|
959 |
|
960 |
|
961 CEglWindowSurface::~CEglWindowSurface() |
|
962 { |
|
963 Destroy(); |
|
964 eglReleaseThread(); |
|
965 delete iWindow; |
|
966 } |
|
967 |
|
968 |
|
969 TSurfaceId CEglWindowSurface::SurfaceId() const |
|
970 { |
|
971 // Default constructor for id sets it to a NULL-value, so if no window is created, we get |
|
972 // a defined surface id value that is invalid. |
|
973 TSurfaceId id; |
|
974 if (iWindow) |
|
975 { |
|
976 TSurfaceConfiguration surfConfig; |
|
977 iWindow->Window().GetBackgroundSurface(surfConfig); |
|
978 surfConfig.GetSurfaceId(id); |
|
979 } |
|
980 return id; |
|
981 } |
|
982 |
|
983 |
697 const TText *CEglWindowSurface::GetSurfaceTypeStr() const |
984 const TText *CEglWindowSurface::GetSurfaceTypeStr() const |
698 { |
985 { |
699 return _S("CEglWindowSurface"); |
986 return _S("CEglWindowSurface"); |
700 } |
987 } |
701 |
988 |
702 TInt CEglWindowSurface::Notify(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, TUint32 /*aXTImes*/) |
989 |
703 { |
990 CEglPBufferSurface::CEglPBufferSurface() |
704 return KErrNotSupported; |
991 { |
705 } |
992 } |
706 |
993 |
707 TInt CEglWindowSurface::WaitFor(TNotification /*aWhen*/, TRequestStatus& /*aStatus*/, |
994 |
708 TInt /*aTimeoutinMicroseconds*/, TUint32 & /*aTimeStamp*/) |
995 CEglPBufferSurface::~CEglPBufferSurface() |
709 { |
996 { |
710 return KErrNotSupported; |
997 Destroy(); |
|
998 eglReleaseThread(); |
|
999 } |
|
1000 |
|
1001 |
|
1002 CEglPBufferSurface* CEglPBufferSurface::NewL() |
|
1003 { |
|
1004 CEglPBufferSurface* self = new (ELeave) CEglPBufferSurface; |
|
1005 CleanupStack::PushL(self); |
|
1006 self->ConstructL(); |
|
1007 CleanupStack::Pop(self); |
|
1008 return self; |
|
1009 } |
|
1010 |
|
1011 |
|
1012 void CEglPBufferSurface::ConstructL() |
|
1013 { |
|
1014 } |
|
1015 |
|
1016 |
|
1017 const TText *CEglPBufferSurface::GetSurfaceTypeStr() const |
|
1018 { |
|
1019 return _S("CEglPBufferSurface"); |
|
1020 } |
|
1021 |
|
1022 |
|
1023 void CEglPBufferSurface::DoCreateL(TInt aIndex, const TPoint &/*aOffset*/, TInt aSizeIndex) |
|
1024 { |
|
1025 CEglSurfaceBase::BaseCreateL(aIndex, EGL_PBUFFER_BIT); |
|
1026 |
|
1027 EGLint attribs[] = |
|
1028 { |
|
1029 EGL_WIDTH, 0, |
|
1030 EGL_HEIGHT, 0, |
|
1031 EGL_NONE, |
|
1032 }; |
|
1033 if (KSurfaceParams[aIndex].iXSize & ELargestPossibleSurface) |
|
1034 { |
|
1035 iActualSize.iWidth = KSurfaceSizes[aSizeIndex].iWidth; |
|
1036 iActualSize.iHeight = KSurfaceSizes[aSizeIndex].iHeight; |
|
1037 } |
|
1038 else |
|
1039 { |
|
1040 iActualSize.iWidth = KSurfaceParams[aIndex].iXSize; |
|
1041 iActualSize.iHeight = KSurfaceParams[aIndex].iYSize; |
|
1042 } |
|
1043 for(TInt i = 0; attribs[i] != EGL_NONE; i += 2) |
|
1044 { |
|
1045 switch(attribs[i]) |
|
1046 { |
|
1047 case EGL_HEIGHT: |
|
1048 attribs[i+1] = iActualSize.iHeight; |
|
1049 break; |
|
1050 case EGL_WIDTH: |
|
1051 attribs[i+1] = iActualSize.iWidth; |
|
1052 break; |
|
1053 } |
|
1054 } |
|
1055 |
|
1056 iSurface = eglCreatePbufferSurface(iDisplay, iConfig, attribs); |
|
1057 if (iSurface == EGL_NO_SURFACE) |
|
1058 { |
|
1059 EGLint err = eglGetError(); |
|
1060 User::Leave(KErrNotSupported); |
|
1061 } |
|
1062 } |
|
1063 |
|
1064 |
|
1065 TSurfaceId CEglPBufferSurface::SurfaceId() const |
|
1066 { |
|
1067 SURF_ASSERT(0); // We shouldn't call this! |
|
1068 return TSurfaceId::CreateNullId(); |
|
1069 } |
|
1070 |
|
1071 TInt CEglPBufferSurface::SizeInBytes() const |
|
1072 { |
|
1073 // size of a pixel in bits. |
|
1074 EGLint size; |
|
1075 if (!eglGetConfigAttrib(iDisplay, iConfig, EGL_BUFFER_SIZE, &size)) |
|
1076 { |
|
1077 RDebug::Printf("Unable to get EGL_BUFFER_SIZE from config %d, err = %04x", iConfig, eglGetError()); |
|
1078 return 0; |
|
1079 } |
|
1080 |
|
1081 return (KSurfaceParams[iParamIndex].iXSize * KSurfaceParams[iParamIndex].iYSize * size) / 8; |
711 } |
1082 } |
712 |
1083 |
713 |
1084 |
714 // Factory function. |
1085 // Factory function. |
715 CSurface *CSurface::SurfaceFactoryL(TSurfaceType aSurfaceType) |
1086 CSurface *CSurface::SurfaceFactoryL(TSurfaceType aSurfaceType) |
716 { |
1087 { |
717 switch(aSurfaceType) |
1088 switch(aSurfaceType) |
718 { |
1089 { |
719 case ESurfTypeRaw: |
1090 case ESurfTypeRaw: |
720 return CRawSurface::NewL(); |
1091 return CRawSurface::NewL(); |
|
1092 |
721 case ESurfTypeEglWindow: |
1093 case ESurfTypeEglWindow: |
722 return CEglWindowSurface::NewL(); |
1094 return CEglWindowSurface::NewL(); |
|
1095 |
723 case ESurfTypeRawSingleBuffered: |
1096 case ESurfTypeRawSingleBuffered: |
724 return CRawSingleBufferSurface::NewL(); |
1097 return CRawSingleBufferSurface::NewL(); |
|
1098 |
|
1099 case ESurfTypePBuffer: |
|
1100 return CEglPBufferSurface::NewL(); |
|
1101 |
725 default: |
1102 default: |
726 SURF_ASSERT(0); |
1103 SURF_ASSERT(0); |
727 return NULL; |
1104 return NULL; |
728 } |
1105 } |
729 } |
1106 } |
730 |
|