javauis/lcdui_akn/lcdui/src/CMIDCanvas.cpp
branchRCL_3
changeset 77 7cee158cb8cd
parent 71 d5e927d5853b
child 83 26b2b12093af
equal deleted inserted replaced
71:d5e927d5853b 77:7cee158cb8cd
   854         ASSERT(!iAlfMonitor);
   854         ASSERT(!iAlfMonitor);
   855         aRead = aEnd;
   855         aRead = aEnd;
   856         return EFalse;
   856         return EFalse;
   857     }
   857     }
   858 
   858 
   859     switch (aRead->OpCode())
   859     // Usually only one op code is processed by Canvas.
   860     {
   860     // Exception is the video overlay case, where MIDlet
   861     case EDrwOpcM3GContentStart:
   861     // does not draw anything inside Canvas.paint().
   862     {
   862     // In this case EDrwOpcPaintStarted and EDrwOpcBitBltRect/EDrwOpcBitBlt
   863         // EGL surface is created if canvas window is currently visible
   863     // are received in one ProcessL(). Also EDrwOpcPaintStarted and EDrwOpcM3GContentStart
   864         // even if MIDlet would be on background.
   864     // may be processed in one ProcessL(), if overlays are enabled.
   865         if (!iM3GContent &&
   865     while (aRead < aEnd)
   866                 i3DAccelerated &&
   866     {
   867                 iDirectContents.Count() == 0 &&
   867         switch (aRead->OpCode())
   868                 IsWindowVisible())
   868         {
   869         {
   869         case EDrwOpcM3GContentStart:
   870             DEBUG("CMIDCanvas::ProcessL - M3G content start");
   870         {
   871             iM3GContent = ETrue;
   871             // EGL surface is created if canvas window is currently visible
   872             iM3GStart = ETrue;
   872             // even if MIDlet would be on background.
   873             PostEvent(EM3GDraw, iM3GContent, 0);
   873             if (!iM3GContent &&
   874             // First time when M3G content is drawn =>
   874                     i3DAccelerated &&
   875             // switch to EGL surface drawing.
   875                     iDirectContents.Count() == 0 &&
   876             // Pixel source must be disposed first.
   876                     IsWindowVisible())
   877             DisposePixelSource();
       
   878             OpenEglL();
       
   879 
       
   880             // if we are scaling with m3g and HW acceleration
       
   881             // create a pbuffer surface to be used with m3g rendering
       
   882             if (iScalingOn && iFullScreen)
       
   883             {
   877             {
   884                 CreatePBufferSurfaceL();
   878                 DEBUG("CMIDCanvas::ProcessL - M3G content start");
       
   879                 iM3GContent = ETrue;
       
   880                 iM3GStart = ETrue;
       
   881                 PostEvent(EM3GDraw, iM3GContent, 0);
       
   882                 // First time when M3G content is drawn =>
       
   883                 // switch to EGL surface drawing.
       
   884                 // Pixel source must be disposed first.
       
   885                 DisposePixelSource();
       
   886                 OpenEglL();
       
   887 
       
   888                 // if we are scaling with m3g and HW acceleration
       
   889                 // create a pbuffer surface to be used with m3g rendering
       
   890                 if (iScalingOn && iFullScreen)
       
   891                 {
       
   892                     CreatePBufferSurfaceL();
       
   893                 }
       
   894                 // Draw the whole framebuffer content (as a texture) on top of
       
   895                 // the EGL window surface.
       
   896                 iUpperUpdateRect = TRect(Size());
       
   897                 UpdateEglContent();
   885             }
   898             }
   886             // Draw the whole framebuffer content (as a texture) on top of
   899 
   887             // the EGL window surface.
   900             ASSERT(aRead + aRead->Size() == aEnd);
   888             iUpperUpdateRect = TRect(Size());
   901         }
   889             UpdateEglContent();
       
   890         }
       
   891     }
       
   892     break;
       
   893     case EDrwOpcBitBltRect:
       
   894     {
       
   895         if (iFirstPaintState == EFirstPaintNeverOccurred)
       
   896         {
       
   897             iFirstPaintState = EFirstPaintInitiated;
       
   898         }
       
   899 
       
   900         const TBitBltData& data = BitBltData(aRead);
       
   901         UpdateL(data.iRect);
       
   902     }
       
   903     break;
       
   904     case EDrwOpcBitBlt:
       
   905     {
       
   906         if (iFirstPaintState == EFirstPaintNeverOccurred)
       
   907         {
       
   908             iFirstPaintState = EFirstPaintInitiated;
       
   909         }
       
   910 
       
   911         UpdateL(iViewRect);
       
   912     }
       
   913     break;
       
   914     default:
       
   915         User::Leave(KErrNotSupported);
       
   916         break;
   902         break;
   917     }
   903         case EDrwOpcBitBltRect:
   918 
   904         {
   919     aRead += aRead->Size();
   905             if (iFirstPaintState == EFirstPaintNeverOccurred)
       
   906             {
       
   907                 iFirstPaintState = EFirstPaintInitiated;
       
   908             }
       
   909 
       
   910             const TBitBltData& data = BitBltData(aRead);
       
   911             UpdateL(data.iRect);
       
   912 
       
   913             ASSERT(aRead + aRead->Size() == aEnd);
       
   914         }
       
   915         break;
       
   916         case EDrwOpcBitBlt:
       
   917         {
       
   918             if (iFirstPaintState == EFirstPaintNeverOccurred)
       
   919             {
       
   920                 iFirstPaintState = EFirstPaintInitiated;
       
   921             }
       
   922 
       
   923             UpdateL(iViewRect);
       
   924 
       
   925             ASSERT(aRead + aRead->Size() == aEnd);
       
   926         }
       
   927         break;
       
   928         case EDrwOpcPaintStarted:
       
   929         {
       
   930             // Clear MMAPI content areas on Canvas to enable overlays.
       
   931             if (IsVideoOverlayActive())
       
   932             {
       
   933                 RRegion directContents;
       
   934                 iDisplayable->GetDirectContentsRegion(directContents);
       
   935                 TInt count = directContents.Count();
       
   936 
       
   937                 iFrameContext->SetBrushColor(KTransparentClearColor);
       
   938                 iFrameContext->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   939 
       
   940                 for (TInt i = 0; i < count; ++i)
       
   941                 {
       
   942                     const TRect rect = directContents[i];
       
   943                     iFrameContext->Clear(rect);
       
   944                 }
       
   945                 directContents.Close();
       
   946             }
       
   947         }
       
   948         break;
       
   949         default:
       
   950             User::Leave(KErrNotSupported);
       
   951             break;
       
   952         }
       
   953 
       
   954         aRead += aRead->Size();
       
   955     }
       
   956 
   920     ASSERT(aRead == aEnd);
   957     ASSERT(aRead == aEnd);
   921 
   958 
   922     // iFrameReady tells if this is async operation.
   959     // iFrameReady tells if this is async operation.
   923     // In async case CMIDBuffer waits until canvas
   960     // In async case CMIDBuffer waits until canvas
   924     // gets callback from Alf.
   961     // gets callback from Alf.
  1143 // From class MDirectContainer.
  1180 // From class MDirectContainer.
  1144 // CMIDCanvas::MdcAddContentBounds
  1181 // CMIDCanvas::MdcAddContentBounds
  1145 // Adds a rectangle to be excluded from redrawing.
  1182 // Adds a rectangle to be excluded from redrawing.
  1146 // ---------------------------------------------------------------------------
  1183 // ---------------------------------------------------------------------------
  1147 //
  1184 //
  1148 void CMIDCanvas::MdcAddContentBounds(const TRect& aRect)
  1185 void CMIDCanvas::MdcAddMMAPIContentBounds(const TRect& aRect)
  1149 {
  1186 {
  1150     if (iDisplayable)
  1187     if (iDisplayable)
  1151     {
  1188     {
  1152         iDisplayable->AddDirectContentArea(aRect);
  1189         iDisplayable->AddDirectContentArea(aRect);
  1153     }
  1190     }
  1158 // From class MDirectContainer.
  1195 // From class MDirectContainer.
  1159 // CMIDCanvas::MdcRemoveContentBounds
  1196 // CMIDCanvas::MdcRemoveContentBounds
  1160 // Removes a rectangle to be excluded from redrawing.
  1197 // Removes a rectangle to be excluded from redrawing.
  1161 // ---------------------------------------------------------------------------
  1198 // ---------------------------------------------------------------------------
  1162 //
  1199 //
  1163 void CMIDCanvas::MdcRemoveContentBounds(const TRect& aRect)
  1200 void CMIDCanvas::MdcRemoveMMAPIContentBounds(const TRect& aRect)
  1164 {
  1201 {
  1165     if (iDisplayable)
  1202     if (iDisplayable)
  1166     {
  1203     {
       
  1204 #ifdef RD_JAVA_NGA_ENABLED
       
  1205         if (iEnv.VideoOverlayEnabled())
       
  1206         {
       
  1207             // iMMAPIAreaUpdated may be modified in LCDUI and MMAPI threads.
       
  1208             // Lock must be released before RemoveDirectContentArea().
       
  1209             RCriticalSection& lock(iEnv.GetMMAPILock());
       
  1210             lock.Wait();
       
  1211             iMMAPIAreaUpdated = ETrue;
       
  1212             lock.Signal();
       
  1213 
       
  1214             iDisplayable->RemoveDirectContentArea(aRect);
       
  1215         }
       
  1216         else
       
  1217         {
       
  1218             iDisplayable->RemoveDirectContentArea(aRect);
       
  1219         }
       
  1220 #else
  1167         iDisplayable->RemoveDirectContentArea(aRect);
  1221         iDisplayable->RemoveDirectContentArea(aRect);
       
  1222 #endif // RD_JAVA_NGA_ENABLED        
  1168     }
  1223     }
  1169 }
  1224 }
  1170 
  1225 
  1171 
  1226 
  1172 // ---------------------------------------------------------------------------
  1227 // ---------------------------------------------------------------------------
  1900     if (iFrameBuffer->DisplayMode() == EColor16MA)
  1955     if (iFrameBuffer->DisplayMode() == EColor16MA)
  1901     {
  1956     {
  1902         gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
  1957         gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
  1903     }
  1958     }
  1904 
  1959 
       
  1960 #ifdef RD_JAVA_NGA_ENABLED
       
  1961     // If overlay is enabled, need to clear previous content
       
  1962     // from CWindowGc.
       
  1963     CMIDCanvas* myself = const_cast<CMIDCanvas*>(this);
       
  1964     if (myself->IsVideoOverlayActive())
       
  1965     {
       
  1966         gc.SetBrushColor(KTransparentClearColor);
       
  1967         gc.Clear(aRect);
       
  1968     }
       
  1969 #endif
       
  1970 
  1905     TRect windowRect(aRect);
  1971     TRect windowRect(aRect);
  1906     PrepareDraw(gc, windowRect);
  1972     PrepareDraw(gc, windowRect);
  1907 
  1973 
  1908     // Check if Canvas scaling is used.
  1974     // Check if Canvas scaling is used.
  1909     if (iViewRect.Size() == iContentSize)
  1975     if (iViewRect.Size() == iContentSize)
  2197     if (aType == KEikInputLanguageChange)
  2263     if (aType == KEikInputLanguageChange)
  2198 #endif // RD_JAVA_S60_RELEASE_9_2
  2264 #endif // RD_JAVA_S60_RELEASE_9_2
  2199     {
  2265     {
  2200         // We need inform TextEditor that input language is changed.
  2266         // We need inform TextEditor that input language is changed.
  2201         if ((iFocusedComponent != KComponentFocusedNone) &&
  2267         if ((iFocusedComponent != KComponentFocusedNone) &&
  2202         (iFocusedComponent < iCustomComponents.Count()))
  2268                 (iFocusedComponent < iCustomComponents.Count()))
  2203         {
  2269         {
  2204             iCustomComponents[iFocusedComponent]->
  2270             iCustomComponents[iFocusedComponent]->
  2205             CustomComponentControl(KComponentMainControl)->
  2271             CustomComponentControl(KComponentMainControl)->
  2206             HandleResourceChange(aType);
  2272             HandleResourceChange(aType);
  2207         }
  2273         }
  2741 
  2807 
  2742         if (IsEglAvailable())
  2808         if (IsEglAvailable())
  2743         {
  2809         {
  2744             myself->ClearUiSurface(ETrue);
  2810             myself->ClearUiSurface(ETrue);
  2745         }
  2811         }
  2746         else if (iAlfCompositionPixelSource)
  2812         // Pixel source is not activated if Canvas is not visible,
       
  2813         // in order that graphics memory is not reserved while being on background
       
  2814         else if (iAlfCompositionPixelSource && IsWindowVisible())
  2747         {
  2815         {
  2748             myself->ClearUiSurface(ETrue);
  2816             myself->ClearUiSurface(ETrue);
  2749             TRAP_IGNORE(myself->ActivatePixelSourceL(ETrue));
  2817             TRAP_IGNORE(myself->ActivatePixelSourceL(ETrue));
  2750         }
  2818         }
  2751         else
  2819         else
  2838     TBool /*aUpdateRequired*/
  2906     TBool /*aUpdateRequired*/
  2839 #else
  2907 #else
  2840     TBool aUpdateRequired
  2908     TBool aUpdateRequired
  2841 #endif // CANVAS_DIRECT_ACCESS
  2909 #endif // CANVAS_DIRECT_ACCESS
  2842 ) :
  2910 ) :
  2843         CCoeControl()
  2911     CCoeControl()
  2844         ,iEnv(aEnv)
  2912     ,iEnv(aEnv)
  2845 #ifdef CANVAS_DOUBLE_BUFFER
  2913 #ifdef CANVAS_DOUBLE_BUFFER
  2846         ,iFrameBuffer(NULL)
  2914     ,iFrameBuffer(NULL)
  2847 #endif // CANVAS_DOUBLE_BUFFER
  2915 #endif // CANVAS_DOUBLE_BUFFER
  2848         ,iIsGameCanvas((
  2916     ,iIsGameCanvas((
  2849                            aComponentType == MMIDComponent::EGameCanvas ? ETrue : EFalse))
  2917                        aComponentType == MMIDComponent::EGameCanvas ? ETrue : EFalse))
  2850         ,iFlags(EPostKeyEvents)
  2918     ,iFlags(EPostKeyEvents)
  2851         ,iFullScreen(EFalse)
  2919     ,iFullScreen(EFalse)
  2852         ,iScalingOn(EFalse)
  2920     ,iScalingOn(EFalse)
  2853         ,iS60SelectionKeyCompatibility(EFalse)
  2921     ,iS60SelectionKeyCompatibility(EFalse)
  2854         ,iRestoreContentWhenUnfaded(EFalse)
  2922     ,iRestoreContentWhenUnfaded(EFalse)
  2855         ,iLastFadeMessage(0)
  2923     ,iLastFadeMessage(0)
  2856 #ifdef CANVAS_DIRECT_ACCESS
  2924 #ifdef CANVAS_DIRECT_ACCESS
  2857         ,iDcDsaToStart(EFalse)
  2925     ,iDcDsaToStart(EFalse)
  2858 #endif // CANVAS_DIRECT_ACCESS
  2926 #endif // CANVAS_DIRECT_ACCESS
  2859         ,iDragEventsStartedInside(EFalse)
  2927     ,iDragEventsStartedInside(EFalse)
  2860         ,iFirstPaintState(EFirstPaintNeverOccurred)
  2928     ,iFirstPaintState(EFirstPaintNeverOccurred)
  2861 {
  2929 {
  2862     DEBUG("+ CMIDCanvas::CMIDCanvas - EDirectEnabled");
  2930     DEBUG("+ CMIDCanvas::CMIDCanvas - EDirectEnabled");
  2863 
  2931 
  2864 #ifdef CANVAS_DIRECT_ACCESS
  2932 #ifdef CANVAS_DIRECT_ACCESS
  2865     iFlags |= (EDirectPaused | EDirectEnabled | EUpdateRequired);
  2933     iFlags |= (EDirectPaused | EDirectEnabled | EUpdateRequired);
  3649 // ---------------------------------------------------------------------------
  3717 // ---------------------------------------------------------------------------
  3650 //
  3718 //
  3651 void CMIDCanvas::HandleFullOrPartialForegroundL(
  3719 void CMIDCanvas::HandleFullOrPartialForegroundL(
  3652     TBool aFullOrPartialFg, TBool aCurrentDisplayable)
  3720     TBool aFullOrPartialFg, TBool aCurrentDisplayable)
  3653 {
  3721 {
  3654     if (!aFullOrPartialFg && aCurrentDisplayable)
  3722     if (!aFullOrPartialFg)
  3655     {
  3723     {
  3656         FreeGraphicsMemory(ETrue);
  3724         FreeGraphicsMemory(ETrue);
  3657     }
  3725     }
  3658     else if (!iPrevM3GContent && iAlfCompositionPixelSource)
  3726 
  3659     {
  3727     // If canvas is not the current displayable but visible when MIDlet has gained
  3660         SuspendPixelSource();
  3728     // foreground, need to invoke forced paint to get content updated on screen
  3661         ActivatePixelSourceL(ETrue);
  3729     if (aFullOrPartialFg && !aCurrentDisplayable && IsVisible())
       
  3730     {
       
  3731         PostForcedPaint();
  3662     }
  3732     }
  3663 }
  3733 }
  3664 
  3734 
  3665 // ---------------------------------------------------------------------------
  3735 // ---------------------------------------------------------------------------
  3666 // CMIDCanvas::FreeGraphicsMemory
  3736 // CMIDCanvas::FreeGraphicsMemory
  4671 void CMIDCanvas::MidletExiting()
  4741 void CMIDCanvas::MidletExiting()
  4672 {
  4742 {
  4673     iExiting = ETrue;
  4743     iExiting = ETrue;
  4674     TRAP_IGNORE(UpdateOffScreenBitmapL(ETrue));
  4744     TRAP_IGNORE(UpdateOffScreenBitmapL(ETrue));
  4675     DrawToWindowGc();
  4745     DrawToWindowGc();
       
  4746 }
       
  4747 
       
  4748 // ---------------------------------------------------------------------------
       
  4749 // CMIDCanvas::IsVideoOverlayActive
       
  4750 // ---------------------------------------------------------------------------
       
  4751 //
       
  4752 TBool CMIDCanvas::IsVideoOverlayActive()
       
  4753 {
       
  4754     if (iEnv.VideoOverlayEnabled() && !iIsGameCanvas)
       
  4755     {
       
  4756         // This method is called also from CMIDGraphics.
       
  4757         // Need to check here if MMAPI video area was removed by calling CheckDirectContentUpdated()
       
  4758         // in order that lcdgr can use the correct alpha blending
       
  4759         // (opaque or transparent target, see CMIDGraphcis.cpp and lcd16ma.cpp).
       
  4760         TBool ret = iDisplayable->DirectContentsCount() > 0;
       
  4761         CheckDirectContentUpdated();
       
  4762         return ret;
       
  4763     }
       
  4764     else
       
  4765     {
       
  4766         return EFalse;
       
  4767     }
  4676 }
  4768 }
  4677 
  4769 
  4678 // ---------------------------------------------------------------------------
  4770 // ---------------------------------------------------------------------------
  4679 // CMIDCanvas::BlitFrameBufferPixels
  4771 // CMIDCanvas::BlitFrameBufferPixels
  4680 // Sets up OpenGL state for 2D texture rendering and renders the textures for
  4772 // Sets up OpenGL state for 2D texture rendering and renders the textures for
  5299 {
  5391 {
  5300     TInt posPacked  = 0;
  5392     TInt posPacked  = 0;
  5301     TInt sizePacked = (iContentSize.iWidth << 16) | (iContentSize.iHeight);
  5393     TInt sizePacked = (iContentSize.iWidth << 16) | (iContentSize.iHeight);
  5302     PostEvent(EForcedPaint, posPacked, sizePacked);
  5394     PostEvent(EForcedPaint, posPacked, sizePacked);
  5303 }
  5395 }
       
  5396 
       
  5397 // ---------------------------------------------------------------------------
       
  5398 // CMIDCanvas::CheckDirectContentUpdated
       
  5399 // Restores opaque alpha channel to direct content areas in
       
  5400 // framebuffer bitmap after video is removed from canvas.
       
  5401 // ---------------------------------------------------------------------------
       
  5402 //
       
  5403 void CMIDCanvas::CheckDirectContentUpdated()
       
  5404 {
       
  5405     if (iEnv.VideoOverlayEnabled() && iMMAPIAreaUpdated)
       
  5406     {
       
  5407         // iMMAPIAreaUpdated is modified in LCDUI and MMAPI threads.
       
  5408         // Lock must be released before GetDirectContentsRegion().
       
  5409         RCriticalSection& lock(iEnv.GetMMAPILock());
       
  5410         lock.Wait();
       
  5411         iMMAPIAreaUpdated = EFalse;
       
  5412         lock.Signal();
       
  5413 
       
  5414         RRegion clearedRegion;
       
  5415         RRegion directContentRegion;
       
  5416         iDisplayable->GetDirectContentsRegion(directContentRegion);
       
  5417         clearedRegion.AddRect(TRect(iFrameBuffer->SizeInPixels()));
       
  5418         clearedRegion.SubRegion(directContentRegion);
       
  5419 
       
  5420         iFrameContext->CancelClipping();
       
  5421         iFrameContext->SetClippingRegion(clearedRegion);
       
  5422         iFrameContext->SetBrushColor(KOpaqueBlackColor);
       
  5423         iFrameContext->SetDrawMode(CGraphicsContext::EDrawModeOR);
       
  5424         iFrameContext->Clear();
       
  5425         // Restore full clip area
       
  5426         iFrameContext->CancelClipping();
       
  5427         clearedRegion.Close();
       
  5428         directContentRegion.Close();
       
  5429     }
       
  5430 }
  5304 #endif // RD_JAVA_NGA_ENABLED        
  5431 #endif // RD_JAVA_NGA_ENABLED        
  5305 // End of File.
  5432 // End of File.