javauis/lcdui_akn/lcdui/src/CMIDCanvas.cpp
branchRCL_3
changeset 19 71c436fe3ce0
parent 18 9ac0a0a7da70
child 21 4376525cdefb
equal deleted inserted replaced
18:9ac0a0a7da70 19:71c436fe3ce0
   106 const TInt KPhoneScreen = 0;
   106 const TInt KPhoneScreen = 0;
   107 // The color that is used to clear the framebuffer when
   107 // The color that is used to clear the framebuffer when
   108 // mixing 3D & 2D rendering
   108 // mixing 3D & 2D rendering
   109 #define KTransparentClearColor TRgb(0x000000, 0x0)
   109 #define KTransparentClearColor TRgb(0x000000, 0x0)
   110 #define KOpaqueClearColor      TRgb(0xFFFFFF, 0xFF)
   110 #define KOpaqueClearColor      TRgb(0xFFFFFF, 0xFF)
       
   111 #define KOpaqueBlackColor      TRgb(0x000000, 255)
   111 
   112 
   112 #ifdef _DEBUG
   113 #ifdef _DEBUG
   113 #define ASSERT_GL() AssertGL()
   114 #define ASSERT_GL() AssertGL()
   114 #else
   115 #else
   115 #define ASSERT_GL()
   116 #define ASSERT_GL()
   857             // create a pbuffer surface to be used with m3g rendering
   858             // create a pbuffer surface to be used with m3g rendering
   858             if (iScalingOn && iFullScreen)
   859             if (iScalingOn && iFullScreen)
   859             {
   860             {
   860                 CreatePBufferSurfaceL();
   861                 CreatePBufferSurfaceL();
   861             }
   862             }
   862             // Draw all framebuffer content to EGL surface.
   863             // Draw the whole framebuffer content (as a texture) on top of
       
   864             // the EGL window surface.
   863             iUpperUpdateRect = TRect(Size());
   865             iUpperUpdateRect = TRect(Size());
   864             UpdateEglContent();
   866             UpdateEglContent();
   865         }
   867         }
   866     }
   868     }
   867     break;
   869     break;
  1066     // Unregistration is done in destructor.
  1068     // Unregistration is done in destructor.
  1067 #ifdef RD_JAVA_NGA_ENABLED
  1069 #ifdef RD_JAVA_NGA_ENABLED
  1068     iEnv.ToLcduiObserver().RegisterControl(*this, this);
  1070     iEnv.ToLcduiObserver().RegisterControl(*this, this);
  1069 #else
  1071 #else
  1070     iEnv.ToLcduiObserver().RegisterControl(*this);
  1072     iEnv.ToLcduiObserver().RegisterControl(*this);
  1071 #endif
  1073 #endif // RD_JAVA_NGA_ENABLED
       
  1074 
       
  1075 #ifdef RD_JAVA_NGA_ENABLED
       
  1076     if (iFirstPaintState != EFirstPaintOccurred &&
       
  1077         iDirectContents.Count() == 1)
       
  1078     {
       
  1079         // The first canvas paint using NGA might be interrupted
       
  1080         // by addition of the direct content.
       
  1081         // Invoking repaint event to restore the first paint.
       
  1082         TInt posPacked  = (iViewRect.iTl.iX << 16) | (iViewRect.iTl.iY);
       
  1083         TSize size = iViewRect.Size();
       
  1084         TInt sizePacked = (size.iWidth << 16) | (size.iHeight);
       
  1085         
       
  1086         PostEvent(EPaint, posPacked, sizePacked);
       
  1087     }
       
  1088 #endif // RD_JAVA_NGA_ENABLED
  1072 }
  1089 }
  1073 
  1090 
  1074 
  1091 
  1075 // ---------------------------------------------------------------------------
  1092 // ---------------------------------------------------------------------------
  1076 // From class MDirectContainer.
  1093 // From class MDirectContainer.
  1539     // DrawNow need to be called, otherwise  Canvas will be unfaded
  1556     // DrawNow need to be called, otherwise  Canvas will be unfaded
  1540     if (iDirectContents.Count() == 0 && !iRestoreContentWhenUnfaded && IsFocused())
  1557     if (iDirectContents.Count() == 0 && !iRestoreContentWhenUnfaded && IsFocused())
  1541     {
  1558     {
  1542         // In case direct content content was removed
  1559         // In case direct content content was removed
  1543         // from canvas, recreate pixel source here
  1560         // from canvas, recreate pixel source here
  1544         if (!iAlfCompositionPixelSource &&
  1561         if (!iAlfCompositionPixelSource && !IsEglAvailable())
  1545                 !IsEglAvailable())
       
  1546         {
  1562         {
  1547             InitPixelSourceL();
  1563             InitPixelSourceL();
  1548         }
  1564         }
  1549         DrawWindowNgaL(aRect);
  1565         DrawWindowNgaL(aRect);
  1550     }
  1566     }
  1556             DrawNow(iViewRect);
  1572             DrawNow(iViewRect);
  1557         }
  1573         }
  1558         else
  1574         else
  1559         {
  1575         {
  1560             DrawNow(aRect);
  1576             DrawNow(aRect);
       
  1577         }
       
  1578 #ifdef RD_JAVA_NGA_ENABLED
       
  1579         iCoeEnv->WsSession().Finish();
       
  1580 #endif
       
  1581         
       
  1582         if (iFirstPaintState == EFirstPaintInitiated ||
       
  1583             iFirstPaintState == EFirstPaintPrepared)
       
  1584         {
       
  1585             // NGA is not used, StartScreen can be informed now
       
  1586             if (iForeground)
       
  1587             {
       
  1588                 // The canvas is current, therefore we can flush
       
  1589                 // the graphics and take the start screen snapshot.
       
  1590                 iFirstPaintState = EFirstPaintOccurred;
       
  1591                 java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi()->stopStartScreen();
       
  1592             }
  1561         }
  1593         }
  1562     }
  1594     }
  1563 
  1595 
  1564     // This is needed to avoid artifacting after orientation switch.
  1596     // This is needed to avoid artifacting after orientation switch.
  1565     // It is called once after orientation change.
  1597     // It is called once after orientation change.
  1790     if (iViewRect.Size() == iContentSize)
  1822     if (iViewRect.Size() == iContentSize)
  1791     {
  1823     {
  1792         DEBUG("DrawWindow - Not scaled - BitBlt");
  1824         DEBUG("DrawWindow - Not scaled - BitBlt");
  1793         gc.BitBlt(windowRect.iTl, iFrameBuffer, windowRect);
  1825         gc.BitBlt(windowRect.iTl, iFrameBuffer, windowRect);
  1794     }
  1826     }
  1795     else
  1827 
  1796 #ifdef RD_JAVA_NGA_ENABLED
  1828 #ifdef RD_JAVA_NGA_ENABLED
  1797         if (IsDownScaling(iContentSize, iViewRect, iM3GContent))
  1829     else if (IsDownScaling(iContentSize, iViewRect, iM3GContent))
  1798 #else
  1830 #else
  1799         if (IsDownScaling(iContentSize, iViewRect))
  1831     else if (IsDownScaling(iContentSize, iViewRect))
  1800 #endif //RD_JAVA_NGA_ENABLED
  1832 #endif //RD_JAVA_NGA_ENABLED
  1801         {
  1833     {
  1802             DEBUG("DrawWindow - Downscaling - BitBlt");
  1834         DEBUG("DrawWindow - Downscaling - BitBlt");
  1803             gc.BitBlt(windowRect.iTl, iFrameBuffer, windowRect.Size());
  1835         gc.BitBlt(windowRect.iTl, iFrameBuffer, windowRect.Size());
  1804         }
  1836     }
  1805     // Upscaling
  1837     // Upscaling
  1806         else if (iScaler)
  1838     else if (iScaler)
  1807         {
  1839     {
  1808             iFrameBuffer->LockHeap();
  1840         iFrameBuffer->LockHeap();
  1809             TUint32* pixelData = iFrameBuffer->DataAddress();
  1841         TUint32* pixelData = iFrameBuffer->DataAddress();
  1810 
  1842         // Scale the framebuffer content.
  1811             // Scale the framebuffer content.
  1843         CFbsBitmap* map = iScaler->Process(
  1812             CFbsBitmap* map = iScaler->Process(
  1844                               iFrameBuffer->DisplayMode(),
  1813                                   iFrameBuffer->DisplayMode(),
  1845                               pixelData,
  1814                                   pixelData,
  1846                               iContentSize.iWidth,
  1815                                   iContentSize.iWidth,
  1847                               iContentSize.iHeight,
  1816                                   iContentSize.iHeight,
  1848                               iFrameBuffer->SizeInPixels().iWidth - iContentSize.iWidth,
  1817                                   iFrameBuffer->SizeInPixels().iWidth - iContentSize.iWidth,
  1849                               iViewRect.Width(),
  1818                                   iViewRect.Width(),
  1850                               iViewRect.Height());
  1819                                   iViewRect.Height());
  1851 
  1820 
  1852         iFrameBuffer->UnlockHeap();
  1821             iFrameBuffer->UnlockHeap();
  1853 
  1822 
  1854         if (map)
  1823             if (map)
  1855         {
  1824             {
  1856             DEBUG("DrawWindow - Upscaling - BitBlt - map ok");
  1825                 DEBUG("DrawWindow - Upscaling - BitBlt - map ok");
  1857             gc.BitBlt(windowRect.iTl, map, windowRect.Size());
  1826                 gc.BitBlt(windowRect.iTl, map, windowRect.Size());
  1858         }
  1827             }
  1859         else
  1828             else
  1860         {
  1829             {
  1861             DEBUG("DrawWindow - Upscaling - DrawBitmap - no map");
  1830                 DEBUG("DrawWindow - Upscaling - DrawBitmap - no map");
  1862             gc.DrawBitmap(windowRect, iFrameBuffer, iContentSize);
  1831                 gc.DrawBitmap(windowRect, iFrameBuffer, iContentSize);
  1863         }
  1832             }
  1864     }
  1833         }
       
  1834 
       
  1835 #ifdef RD_JAVA_NGA_ENABLED
       
  1836     iCoeEnv->WsSession().Finish();
       
  1837 #endif
       
  1838 
       
  1839     DEBUG("CMIDCanvas::DrawWindow --");
  1865     DEBUG("CMIDCanvas::DrawWindow --");
  1840 }
  1866 }
  1841 #endif // CANVAS_DOUBLE_BUFFER
  1867 #endif // CANVAS_DOUBLE_BUFFER
  1842 
  1868 
  1843 
  1869 
  2381         {
  2407         {
  2382             iCustomComponents[iFocusedComponent]->
  2408             iCustomComponents[iFocusedComponent]->
  2383             CustomComponentControl(KComponentMainControl)->
  2409             CustomComponentControl(KComponentMainControl)->
  2384             SetFocus(ETrue);
  2410             SetFocus(ETrue);
  2385         }
  2411         }
  2386         // Redraw the canvas after unfading
       
  2387         DrawDeferred();
       
  2388 
  2412 
  2389 #ifdef RD_JAVA_NGA_ENABLED
  2413 #ifdef RD_JAVA_NGA_ENABLED
  2390         // To avoid situation when Canvas is redrawn but black area remains
  2414         // To avoid situation when Canvas is redrawn but black area remains
  2391         if (iAlfCompositionPixelSource)
  2415         if (iAlfCompositionPixelSource)
  2392         {
  2416         {
  2394             if (err != KErrNone)
  2418             if (err != KErrNone)
  2395             {
  2419             {
  2396                 DEBUG_INT("CMIDCanvas::FocusChanged - ActivatePixelSourceL error %d", err);
  2420                 DEBUG_INT("CMIDCanvas::FocusChanged - ActivatePixelSourceL error %d", err);
  2397             }
  2421             }
  2398         }
  2422         }
       
  2423         else
       
  2424         {
       
  2425             // Redraw the canvas after unfading
       
  2426             DrawDeferred();
       
  2427         }
       
  2428 #else // !RD_JAVA_NGA_ENABLED
       
  2429         // Redraw the canvas after unfading
       
  2430         DrawDeferred();
  2399 #endif // RD_JAVA_NGA_ENABLED
  2431 #endif // RD_JAVA_NGA_ENABLED
  2400 
  2432 
  2401     }
  2433     }
  2402     else
  2434     else
  2403     {
  2435     {
  2537     // variable iWndUpdate is set to True. If iWndUpdate is True
  2569     // variable iWndUpdate is set to True. If iWndUpdate is True
  2538     // DrawWindow() is called from method Update()
  2570     // DrawWindow() is called from method Update()
  2539     // This is needed to avoid artifacting after orientation switch.
  2571     // This is needed to avoid artifacting after orientation switch.
  2540     TBool landscape = Layout_Meta_Data::IsLandscapeOrientation();
  2572     TBool landscape = Layout_Meta_Data::IsLandscapeOrientation();
  2541 
  2573 
  2542     if (iLandscape != landscape)
  2574     if (iLandscape != landscape && !iAlfCompositionPixelSource)
  2543     {
  2575     {
  2544         iLandscape = landscape;
  2576         iLandscape = landscape;
  2545         iWndUpdate = ETrue;
  2577         iWndUpdate = ETrue;
  2546     }
  2578     }
  2547     else
  2579     else
  2552         // already lost focus, then IsFocused is used
  2584         // already lost focus, then IsFocused is used
  2553         if (iDirectContents.Count() > 0 || iRestoreContentWhenUnfaded || !IsFocused())
  2585         if (iDirectContents.Count() > 0 || iRestoreContentWhenUnfaded || !IsFocused())
  2554         {
  2586         {
  2555             DrawWindow(aRect);
  2587             DrawWindow(aRect);
  2556         }
  2588         }
  2557         else if (iAlfCompositionPixelSource)
  2589         else
  2558         {
  2590         {
  2559             CMIDCanvas* myself = const_cast<CMIDCanvas*>(this);
  2591             CMIDCanvas* myself = const_cast<CMIDCanvas*>(this);
  2560             TRAP_IGNORE(myself->ActivatePixelSourceL());
  2592             myself->ClearUiSurface(ETrue);
       
  2593             if (iAlfCompositionPixelSource)
       
  2594             {
       
  2595                 TRAP_IGNORE(myself->ActivatePixelSourceL());
       
  2596             }
  2561         }
  2597         }
  2562         iWndUpdate = EFalse;
  2598         iWndUpdate = EFalse;
  2563     }
  2599     }
  2564 
  2600 
  2565     if (!iStartUpTraceDone)
  2601     if (!iStartUpTraceDone)
  2657     TBool /*aUpdateRequired*/
  2693     TBool /*aUpdateRequired*/
  2658 #else
  2694 #else
  2659     TBool aUpdateRequired
  2695     TBool aUpdateRequired
  2660 #endif // CANVAS_DIRECT_ACCESS
  2696 #endif // CANVAS_DIRECT_ACCESS
  2661 ) :
  2697 ) :
  2662     CCoeControl()
  2698         CCoeControl()
  2663     ,iEnv(aEnv)
  2699         ,iEnv(aEnv)
  2664 #ifdef CANVAS_DOUBLE_BUFFER
  2700 #ifdef CANVAS_DOUBLE_BUFFER
  2665     ,iFrameBuffer(NULL)
  2701         ,iFrameBuffer(NULL)
  2666 #endif // CANVAS_DOUBLE_BUFFER
  2702 #endif // CANVAS_DOUBLE_BUFFER
  2667     ,iIsGameCanvas((
  2703         ,iIsGameCanvas((
  2668                        aComponentType == MMIDComponent::EGameCanvas ? ETrue : EFalse))
  2704                            aComponentType == MMIDComponent::EGameCanvas ? ETrue : EFalse))
  2669     ,iFlags(EPostKeyEvents)
  2705         ,iFlags(EPostKeyEvents)
  2670     ,iFullScreen(EFalse)
  2706         ,iFullScreen(EFalse)
  2671     ,iScalingOn(EFalse)
  2707         ,iScalingOn(EFalse)
  2672     ,iS60SelectionKeyCompatibility(EFalse)
  2708         ,iS60SelectionKeyCompatibility(EFalse)
  2673     ,iRestoreContentWhenUnfaded(EFalse)
  2709         ,iRestoreContentWhenUnfaded(EFalse)
  2674     ,iLastFadeMessage(0)
  2710         ,iLastFadeMessage(0)
  2675 #ifdef CANVAS_DIRECT_ACCESS
  2711 #ifdef CANVAS_DIRECT_ACCESS
  2676     ,iDcDsaToStart(EFalse)
  2712         ,iDcDsaToStart(EFalse)
  2677 #endif // CANVAS_DIRECT_ACCESS
  2713 #endif // CANVAS_DIRECT_ACCESS
  2678     ,iDragEventsStartedInside(EFalse)
  2714         ,iDragEventsStartedInside(EFalse)
       
  2715         ,iFirstPaintState(EFirstPaintNeverOccurred)
  2679 {
  2716 {
  2680     DEBUG("+ CMIDCanvas::CMIDCanvas - EDirectEnabled");
  2717     DEBUG("+ CMIDCanvas::CMIDCanvas - EDirectEnabled");
  2681 
  2718 
  2682 #ifdef CANVAS_DIRECT_ACCESS
  2719 #ifdef CANVAS_DIRECT_ACCESS
  2683     iFlags |= (EDirectPaused | EDirectEnabled | EUpdateRequired);
  2720     iFlags |= (EDirectPaused | EDirectEnabled | EUpdateRequired);
  3550         User::Leave(err);
  3587         User::Leave(err);
  3551     }
  3588     }
  3552 
  3589 
  3553     if (iPixelSourceSuspended)
  3590     if (iPixelSourceSuspended)
  3554     {
  3591     {
       
  3592         ClearUiSurface(EFalse);
  3555         iPixelSourceSuspended = EFalse;
  3593         iPixelSourceSuspended = EFalse;
  3556         if (iFullScreen && iScalingOn)
  3594         if (iFullScreen && iScalingOn)
  3557         {
  3595         {
  3558             iAlfCompositionPixelSource->SetExtent(iViewRect, KPhoneScreen);
  3596             iAlfCompositionPixelSource->SetExtent(iViewRect, KPhoneScreen);
  3559         }
  3597         }
  3560     }
  3598     }
  3561 }
  3599 }
  3562 
  3600 
  3563 // ---------------------------------------------------------------------------
  3601 // ---------------------------------------------------------------------------
       
  3602 // CMIDCanvas::ClearUiSurface
       
  3603 // ---------------------------------------------------------------------------
       
  3604 //
       
  3605 void CMIDCanvas::ClearUiSurface(TBool aDrawing)
       
  3606 {
       
  3607     if (!aDrawing)
       
  3608     {
       
  3609         Window().BeginRedraw();
       
  3610         ActivateGc();
       
  3611     }
       
  3612     CWindowGc& gc = SystemGc();
       
  3613     gc.SetBrushColor(KTransparentClearColor);
       
  3614     gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
  3615     gc.Clear();
       
  3616     if (!aDrawing)
       
  3617     {
       
  3618         DeactivateGc();
       
  3619         Window().EndRedraw();
       
  3620     }
       
  3621     iCoeEnv->WsSession().Finish();
       
  3622 }
       
  3623 
  3564 // CMIDCanvas::SuspendPixelSource
  3624 // CMIDCanvas::SuspendPixelSource
  3565 // ---------------------------------------------------------------------------
  3625 // ---------------------------------------------------------------------------
  3566 //
  3626 //
  3567 void CMIDCanvas::SuspendPixelSource()
  3627 void CMIDCanvas::SuspendPixelSource()
  3568 {
  3628 {
  3569     NotifyMonitor();
  3629     NotifyMonitor();
  3570     if (iAlfCompositionPixelSource)
  3630     if (iAlfCompositionPixelSource && !iPixelSourceSuspended)
  3571     {
  3631     {
  3572         iAlfCompositionPixelSource->Suspend();
  3632         iAlfCompositionPixelSource->Suspend();
  3573         iPixelSourceSuspended = ETrue;
  3633         iPixelSourceSuspended = ETrue;
  3574     }
  3634     }
  3575 }
  3635 }
  4149             ELOG1(EJavaUI, "eglCopyBuffers() failed, eglError=%s",
  4209             ELOG1(EJavaUI, "eglCopyBuffers() failed, eglError=%s",
  4150                   GetEglError(eglGetError()).Ptr());
  4210                   GetEglError(eglGetError()).Ptr());
  4151             User::Leave(KErrUnknown);
  4211             User::Leave(KErrUnknown);
  4152         }
  4212         }
  4153 
  4213 
  4154         // Make framebuffer opaque
  4214         // Clear with opaque black so that EDrawModeOR can be used in BitBlt()
  4155         iFrameContext->SetBrushColor(KOpaqueClearColor);
  4215         iFrameContext->SetBrushColor(KOpaqueBlackColor);
  4156         iFrameContext->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
  4216         iFrameContext->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
  4157         iFrameContext->Clear();
  4217         iFrameContext->Clear();
  4158 
  4218         iFrameContext->SetDrawMode(CGraphicsContext::EDrawModeOR);
  4159         iFrameContext->BitBlt(TPoint(), bitmap);
  4219         iFrameContext->BitBlt(TPoint(), bitmap);
  4160         CleanupStack::PopAndDestroy();
  4220         CleanupStack::PopAndDestroy();
  4161         SetCurrentEglType(current);
  4221         SetCurrentEglType(current);
  4162 
  4222 
  4163         // Make sure that full Canvas area
  4223         // Make sure that full Canvas area