2 #include "sdlepocapi.h"
6 LOCAL_C TInt
BytesPerPixel(TDisplayMode aMode
)
8 return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode
) - 1) >> 3) + 1;
12 NONSHARABLE_CLASS(CBitmapSurface
) : public T
15 CBitmapSurface(RWsSession
& aSession
);
18 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
20 TUint8
* LockSurface();
21 void UnlockHwSurface();
22 void CreateSurfaceL();
23 void Wipe(TInt aLength
);
25 void Update(CFbsBitmap
& aBmp
);
26 TInt
ExternalUpdate();
32 void CBitmapSurface
<T
>::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
36 iCopyBmp
= new (ELeave
) CFbsBitmap();
37 T::ConstructL(aWindow
, aDevice
);
41 CBitmapSurface
<T
>::CBitmapSurface(RWsSession
& aSession
) : T(aSession
)
46 void CBitmapSurface
<T
>::Free()
54 CBitmapSurface
<T
>::~CBitmapSurface()
56 __ASSERT_DEBUG(iBmp
== NULL
, PANIC(KErrNotReady
));
61 TUint8
* CBitmapSurface
<T
>::LockSurface()
64 return reinterpret_cast<TUint8
*>(iBmp
->DataAddress());
69 void CBitmapSurface
<T
>::UnlockHwSurface()
72 T::SetUpdating(EFalse
);
78 void CBitmapSurface
<T
>::Update(CFbsBitmap
& aBmp
)
86 void CBitmapSurface
<T
>::CreateSurfaceL()
89 iBmp
= new (ELeave
) CFbsBitmap();
90 User::LeaveIfError(iBmp
->Create(T::SwSize(), T::DisplayMode()));
91 T::CreateSurfaceL(*iBmp
);
95 void CBitmapSurface
<T
>::Wipe(TInt aLength
) //dont call in drawing
98 Mem::FillZ(iBmp
->DataAddress(), aLength
);
103 TInt CBitmapSurface
<T
>::ExternalUpdate()
105 if(iCopyBmp
->Handle() == 0)
107 const TInt err
= iCopyBmp
->Duplicate(iBmp
->Handle());
116 //////////////////////////////////////////////////////////////////////
118 NONSHARABLE_CLASS(CDsaGles
) : public CDsa
121 CDsaGles(RWsSession
& aSession
);
123 TUint8
* LockSurface();
124 void UnlockHWSurfaceRequestComplete();
125 void UnlockHwSurface();
127 void CreateSurfaceL();
128 void Wipe(TInt aLength
);
129 TInt
ExternalUpdate();
130 CBitmapContext
* Gc();
133 CDsaGles::CDsaGles(RWsSession
& aSession
) : CDsa(aSession
)
137 TUint8
* CDsaGles::LockSurface()
142 void CDsaGles::UnlockHWSurfaceRequestComplete()
146 void CDsaGles::UnlockHwSurface()
150 void CDsaGles::Resume()
154 void CDsaGles::CreateSurfaceL()
158 void CDsaGles::Wipe(TInt aLength
)
162 TInt
CDsaGles::ExternalUpdate()
164 return KErrNotSupported
;
167 CBitmapContext
* CDsaGles::Gc()
173 //////////////////////////////////////////////////////////////////////
176 NONSHARABLE_CLASS(CDsaBitgdi
) : public CDsa
179 CDsaBitgdi(RWsSession
& aSession
);
181 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
182 CBitmapContext
* Gc();
183 void CompleteUpdate();
185 void CreateSurfaceL(CFbsBitmap
& aBmp
);
187 void UnlockHWSurfaceRequestComplete();
193 CFbsBitmap
* iBitGdiBmp
;
200 CDsaBitgdi::CDsaBitgdi(RWsSession
& aSession
) : CDsa(aSession
)
204 CDsaBitgdi::~CDsaBitgdi()
210 void CDsaBitgdi::CompleteUpdate()
212 EpocSdlEnv::Request(CDsa::ERequestUpdate
);
216 void CDsaBitgdi::UnlockHWSurfaceRequestComplete()
221 if(iBitGdiBmp
== NULL
)
223 iBitGdiBmp
= new CFbsBitmap();
224 if(iBitGdiBmp
== NULL
)
226 iBitGdiBmp
->Duplicate(iHandle
);
229 iWindow
->Invalidate();
231 iWindow
->BeginRedraw();
232 iWinGc
->Activate(*iWindow
);
234 if(!Blitter(*iBitGdiBmp
))
236 if(SwSize() == HwRect().Size())
237 iWinGc
->BitBlt(HwRect().iTl
, iBitGdiBmp
);
239 iWinGc
->DrawBitmap(HwRect(), iBitGdiBmp
);
242 iWinGc
->Deactivate();
243 iWindow
->EndRedraw();
246 void CDsaBitgdi::Resume()
251 CBitmapContext
* CDsaBitgdi::Gc()
256 void CDsaBitgdi::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
266 User::LeaveIfError(aDevice
.CreateContext(iWinGc
));
267 CDsa::ConstructL(aWindow
, aDevice
);
271 void CDsaBitgdi::CreateSurfaceL(CFbsBitmap
& aBmp
)
273 iDevice
= CFbsBitmapDevice::NewL(&aBmp
);
274 User::LeaveIfError(iDevice
->CreateContext(iGc
));
275 iHandle
= aBmp
.Handle();
278 void CDsaBitgdi::Free()
286 ///////////////////////////////////////////////////////////////////////
288 NONSHARABLE_CLASS(CDsaBase
) : public CDsa
, public MDirectScreenAccess
291 inline CDirectScreenAccess
& Dsa() const;
292 CDsaBase(RWsSession
& aSession
);
294 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
297 CBitmapContext
* Gc();
299 CDirectScreenAccess
* iDsa
;
301 void AbortNow(RDirectScreenAccess::TTerminationReasons aReason
);
302 void Restart(RDirectScreenAccess::TTerminationReasons aReason
);
308 inline CDirectScreenAccess
& CDsaBase::Dsa() const
314 CDsaBase::CDsaBase(RWsSession
& aSession
) : CDsa(aSession
)
318 CBitmapContext
* CDsaBase::Gc()
323 void CDsaBase::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
325 CDsa::ConstructL(aWindow
, aDevice
);
333 iDsa
= CDirectScreenAccess::NewL(
341 void CDsaBase::Resume()
344 Restart(RDirectScreenAccess::ETerminateRegion
);
347 CDsaBase::~CDsaBase()
357 void CDsaBase::RestartL()
363 const RRegion
* r
= iDsa
->DrawingRegion();
364 const TRect rect
= r
->BoundingRect();
365 iDsa
->Gc()->SetClippingRegion(r
);
367 if(rect
!= ScreenRect())
381 void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons
/*aReason*/)
386 void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons aReason
)
388 if(aReason
== RDirectScreenAccess::ETerminateRegion
) //auto restart
390 TRAPD(err
, RestartL());
391 if(err
== KLeaveExit
)
403 void CDsaBase::Stop()
409 ///////////////////////////////////////////////////////////////////////
410 NONSHARABLE_CLASS(TDsa
)
413 inline TDsa(const CDsa
& aDsa
);
414 inline TBool
IsFlip() const;
415 inline TBool
IsTurn() const;
416 inline const TSize
& SwSize() const;
417 inline void Copy(TUint32
* aTarget
, const TUint8
* aSrc
, TInt aBytes
, TInt aHeight
) const;
422 inline TDsa::TDsa(const CDsa
& aDsa
) : iDsa(aDsa
)
426 inline TBool
TDsa::IsTurn() const
428 return iDsa
.iStateFlags
& CDsa::EOrientation90
;
431 inline TBool
TDsa::IsFlip() const
433 return iDsa
.iStateFlags
& CDsa::EOrientation180
;
436 inline const TSize
& TDsa::SwSize() const
438 return iDsa
.SwSize();
441 inline void TDsa::Copy(TUint32
* aTarget
, const TUint8
* aSrc
, TInt aBytes
, TInt aHeight
) const
443 iDsa
.iCopyFunction(iDsa
, aTarget
, aSrc
, aBytes
, aHeight
);
446 template<class T
, class S
>
447 void ClipCopy(const TDsa
& iDsa
, TUint8
* aTarget
,
448 const TUint8
* aSource
,
449 const TRect
& aUpdateRect
,
450 const TRect
& aSourceRect
)
452 const S
* source
= reinterpret_cast<const S
*>(aSource
);
453 const TInt lineWidth
= aSourceRect
.Width();
455 source
+= (aUpdateRect
.iTl
.iY
* lineWidth
);
456 const TInt sourceStartOffset
= aUpdateRect
.iTl
.iX
;
457 source
+= sourceStartOffset
;
459 T
* targetPtr
= reinterpret_cast<T
*>(aTarget
);
461 const TInt scanLineWidth
= iDsa
.SwSize().iWidth
;
463 targetPtr
+= (aSourceRect
.iTl
.iY
+ aUpdateRect
.iTl
.iY
) * scanLineWidth
;
464 const TInt targetStartOffset
= (aUpdateRect
.iTl
.iX
+ aSourceRect
.iTl
.iX
);
466 targetPtr
+= targetStartOffset
;
469 const TInt height
= aUpdateRect
.Height();
471 const TInt lineMove
= iDsa
.IsTurn() ? 1 : lineWidth
;
472 const TInt copyLen
= aUpdateRect
.Width();
478 targetPtr
+= scanLineWidth
* (height
- 1);
480 for(TInt i
= 0; i
< height
; i
++) //source is always smaller
482 iDsa
.Copy(reinterpret_cast<TUint32
*>(targetPtr
), reinterpret_cast<const TUint8
*>(source
), copyLen
, height
);
484 targetPtr
-= scanLineWidth
;
491 for(TInt i
= 0; i
< height
; i
++) //source is always smaller
493 iDsa
.Copy(reinterpret_cast<TUint32
*>(targetPtr
), reinterpret_cast<const TUint8
*>(source
), copyLen
, height
);
495 targetPtr
+= scanLineWidth
; // >> 2;
503 NONSHARABLE_CLASS(CDsaA
) : public CDsaBase
506 CDsaA(RWsSession
& aSession
);
508 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
509 void CompleteUpdate();
510 void CreateSurfaceL(CFbsBitmap
& aBmp
);
512 void UnlockHWSurfaceRequestComplete();
513 void DoBlt(CFbsBitmap
& aBmp
);
517 CDsaA::CDsaA(RWsSession
& aSession
) : CDsaBase(aSession
)
522 void CDsaA::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
524 CDsaBase::ConstructL(aWindow
, aDevice
);
527 void CDsaA::CompleteUpdate()
529 iDsa
->ScreenDevice()->Update();
532 void CDsaA::CreateSurfaceL(CFbsBitmap
& /*aBmp*/)
540 void CDsaA::DoBlt(CFbsBitmap
& aBmp
)
544 if(SwSize() == HwRect().Size())
545 Gc()->BitBlt(HwRect().iTl
, &aBmp
);
547 Gc()->DrawBitmap(HwRect(), &aBmp
);
551 void CDsaA::UnlockHWSurfaceRequestComplete()
553 PANIC(KErrNotSupported
);
558 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
560 NONSHARABLE_CLASS(MDsbObs
)
563 virtual void SurfaceReady() = 0;
564 virtual CDirectScreenBitmap
& Dsb() = 0;
567 NONSHARABLE_CLASS(CDsbSurface
) : public CActive
570 CDsbSurface(MDsbObs
& aDsb
);
571 virtual TUint8
* Address() = 0;
572 virtual void Complete() = 0;
573 virtual void Unlock() = 0;
583 CDsbSurface::CDsbSurface(MDsbObs
& aDsb
) : CActive(CActive::EPriorityHigh
) , iDsb(aDsb
)
585 CActiveScheduler::Add(this);
588 CDsbSurface::~CDsbSurface()
593 void CDsbSurface::RunL()
598 void CDsbSurface::DoCancel()
603 NONSHARABLE_CLASS(CDsbSyncSurface
) : public CDsbSurface
607 CDsbSyncSurface(MDsbObs
& aDsb
);
616 CDsbSyncSurface::CDsbSyncSurface(MDsbObs
& aDsb
) : CDsbSurface(aDsb
)
618 iSema
.CreateLocal(1);
621 TUint8
* CDsbSyncSurface::Address()
625 TAcceleratedBitmapInfo info
;
626 if(KErrNone
== iDsb
.Dsb().BeginUpdate(info
))
627 iAddress
= info
.iAddress
;
631 void CDsbSyncSurface::Unlock()
633 EpocSdlEnv::Request(CDsa::ERequestUpdate
);
636 void CDsbSyncSurface::RunL()
642 CDsbSyncSurface::~CDsbSyncSurface()
648 void CDsbSyncSurface::Complete()
650 if(iAddress
!= NULL
&& !IsActive())
654 iDsb
.Dsb().EndUpdate(iStatus
);
660 NONSHARABLE_CLASS(CDsbAsyncSurface
) : public CDsbSurface
664 CDsbAsyncSurface(MDsbObs
& aDsb
);
670 TUint8
* CDsbAsyncSurface::Address()
672 if(iAddress
== NULL
&& !IsActive())
674 TAcceleratedBitmapInfo info
;
675 if(KErrNone
== iDsb
.Dsb().BeginUpdate(info
))
676 iAddress
= info
.iAddress
;
681 CDsbAsyncSurface::CDsbAsyncSurface(MDsbObs
& aDsb
) : CDsbSurface(aDsb
)
685 CDsbAsyncSurface::~CDsbAsyncSurface()
689 void CDsbAsyncSurface::Unlock()
691 EpocSdlEnv::Request(CDsa::ERequestUpdate
);
694 void CDsbAsyncSurface::Complete()
696 if(iAddress
!= NULL
&& !IsActive())
700 iDsb
.Dsb().EndUpdate(iStatus
);
704 NONSHARABLE_CLASS(CDsaB
) : public CDsaBase
,
708 enum {EDrawModeDSBAsync
= 0x1000};
709 CDsaB(RWsSession
& aSession
, TInt aFlags
);
712 TUint8
* LockSurface();
713 void UnlockHWSurfaceRequestComplete();
714 void UnlockHwSurface();
715 void CreateSurfaceL();
716 void Wipe(TInt aLength
);
718 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
719 CDirectScreenBitmap
& Dsb();
721 TInt
ExternalUpdate();
723 CDsbSurface
* iSurface1
;
724 CDirectScreenBitmap
* iDsb
;
728 CDsaB::CDsaB(RWsSession
& aSession
, TInt aFlags
) : CDsaBase(aSession
), iType(aFlags
)
734 void CDsaB::UnlockHWSurfaceRequestComplete()
736 iSurface1
->Complete();
739 void CDsaB::CreateSurfaceL()
741 __ASSERT_ALWAYS(SwSize() == HwRect().Size(), PANIC(KErrNotSupported
));
744 void CDsaB::Wipe(TInt aLength
) //dont call in drawing
746 TUint8
* addr
= LockSurface();
749 Mem::FillZ(addr
, aLength
);
755 void CDsaB::UnlockHwSurface()
760 TUint8
* CDsaB::LockSurface()
762 TUint8
* addr
= iSurface1
->Address();
763 SetUpdating(addr
== NULL
);
767 void CDsaB::SurfaceReady()
772 CDirectScreenBitmap
& CDsaB::Dsb()
777 void CDsaB::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
780 iDsb
= CDirectScreenBitmap::NewL();
781 CDsaBase::ConstructL(aWindow
, aDevice
);
782 if(iSurface1
== NULL
)
784 if( (iType
& CDsaB::EDrawModeDSBAsync
))
785 iSurface1
= new (ELeave
) CDsbAsyncSurface(*this);
787 iSurface1
= new (ELeave
) CDsbSyncSurface(*this);
797 void CDsaB::RecreateL()
800 CDirectScreenBitmap::TSettingsFlags flags
= CDirectScreenBitmap::TSettingsFlags(iType
& 0xFF);
801 iDsb
->Create(HwRect(), flags
);
804 TInt
CDsaB::ExternalUpdate()
808 UnlockHWSurfaceRequestComplete();
814 /////////////////////////////////////////////////////////////////////////////////////////////////////
816 CDsa
* CDsa::CreateL(RWsSession
& aSession
)
818 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSB
))
820 TInt flags
= CDirectScreenBitmap::ENone
;
821 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBDoubleBuffer
))
822 flags
|= CDirectScreenBitmap::EDoubleBuffer
;
823 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBIncrementalUpdate
))
824 flags
|= CDirectScreenBitmap::EIncrementalUpdate
;
825 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBAsync
))
826 flags
|= CDsaB::EDrawModeDSBAsync
;
827 return new (ELeave
) CDsaB(aSession
, flags
);
829 else if(EpocSdlEnv::Flags(CSDL::EDrawModeGdi
))
831 return new (ELeave
) CBitmapSurface
<CDsaBitgdi
>(aSession
);
835 return new (ELeave
) CBitmapSurface
<CDsaA
>(aSession
);
840 void CDsa::RecreateL()
848 TSize
CDsa::WindowSize() const
850 TSize size
= iSwSize
;
851 if(iStateFlags
& EOrientation90
)
853 const TInt tmp
= size
.iWidth
;
854 size
.iWidth
= size
.iHeight
;
860 void CDsa::SetSuspend()
862 iStateFlags
|= ESdlThreadSuspend
;
866 void CDsa::SetUpdating(TBool aUpdate
)
869 iStateFlags
|= EUpdating
;
871 iStateFlags
&= ~EUpdating
;
875 TBool
CDsa::Stopped() const
877 return (iStateFlags
& ESdlThreadExplicitStop
);
880 void CDsa::SetOrientation(CDsa::TOrientationMode aOrientation
)
885 case CDsa::EViewOrientation90
:
886 flags
= EOrientation90
;
888 case CDsa::EViewOrientation180
:
889 flags
= EOrientation180
;
891 case CDsa::EViewOrientation270
:
892 flags
= EOrientation90
| EOrientation180
;
894 case CDsa::EViewOrientation0
:
898 if(flags
!= (iStateFlags
& EOrientationFlags
))
900 iStateFlags
|= EOrientationChanged
;
901 iNewFlags
= flags
; //cannot be set during drawing...
911 void CDsa::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& /*aDevice*/)
914 iLut256
= (TUint32
*) User::AllocL(256 * sizeof(TUint32
));
915 iTargetMode
= aWindow
.DisplayMode();
916 iTargetBpp
= BytesPerPixel(DisplayMode());
917 iScreenRect
= TRect(aWindow
.Position(), aWindow
.Size());
923 void CDsa::DrawOverlays()
925 const TInt last
= iOverlays
.Count() - 1;
926 for(TInt i
= last
; i
>= 0 ; i
--)
927 iOverlays
[i
].iOverlay
->Draw(*Gc(), HwRect(), SwSize());
930 void CDsa::DoBlt(CFbsBitmap
& /*aBmp*/)
934 TInt
CDsa::AppendOverlay(MOverlay
& aOverlay
, TInt aPriority
)
937 for(i
= 0; i
< iOverlays
.Count() && iOverlays
[i
].iPriority
< aPriority
; i
++)
939 const TOverlay overlay
= {&aOverlay
, aPriority
};
940 return iOverlays
.Insert(overlay
, i
);
943 TInt
CDsa::RemoveOverlay(MOverlay
& aOverlay
)
945 for(TInt i
= 0; i
< iOverlays
.Count(); i
++)
947 if(iOverlays
[i
].iOverlay
== &aOverlay
)
956 void CDsa::LockPalette(TBool aLock
)
959 iStateFlags
|= EPaletteLocked
;
961 iStateFlags
&= ~EPaletteLocked
;
963 TInt
CDsa::SetPalette(TInt aFirst
, TInt aCount
, TUint32
* aPalette
)
967 const TInt count
= aCount
- aFirst
;
970 if(iStateFlags
& EPaletteLocked
)
972 for(TInt i
= aFirst
; i
< count
; i
++) //not so busy here:-)
974 iLut256
[i
] = aPalette
[i
];
979 CDsa::CDsa(RWsSession
& aSession
) :
984 iCFTable
[0] = CopyMem
;
985 iCFTable
[1] = CopyMemFlipReversed
;
986 iCFTable
[2] = CopyMemReversed
;
987 iCFTable
[3] = CopyMemFlip
;
989 iCFTable
[4] = Copy256
;
990 iCFTable
[5] = Copy256FlipReversed
;
991 iCFTable
[6] = Copy256Reversed
;
992 iCFTable
[7] = Copy256Flip
;
995 iCFTable
[8] = CopySlow
;
996 iCFTable
[9] = CopySlowFlipReversed
;
997 iCFTable
[10] = CopySlowReversed
;
998 iCFTable
[11] = CopySlowFlip
;
1001 RWsSession
& CDsa::Session()
1006 TInt
CDsa::RedrawRequest()
1008 if(!(iStateFlags
& (EUpdating
) && (iStateFlags
& ERunning
)))
1010 return ExternalUpdate();
1012 return KErrNotReady
;
1015 TUint8
* CDsa::LockHwSurface()
1017 if((iStateFlags
& EUpdating
) == 0) //else frame is skipped
1019 return LockSurface();
1024 TInt
CDsa::AllocSurface(TBool aHwSurface
, const TSize
& aSize
, TDisplayMode aMode
)
1026 if(aHwSurface
&& aMode
!= DisplayMode())
1027 return KErrArgument
;
1029 iSourceMode
= aMode
;
1031 iSourceBpp
= BytesPerPixel(aMode
);
1033 const TSize size
= WindowSize();
1034 if(aSize
.iWidth
> size
.iWidth
)
1036 if(aSize
.iHeight
> size
.iHeight
)
1039 TRAPD(err
, CreateSurfaceL());
1049 void CDsa::CreateZoomerL(const TSize
& aSize
)
1052 iStateFlags
|= EResizeRequest
;
1057 void CDsa::ClipCopy(TUint8
* aTarget
,
1058 const TUint8
* aSource
,
1059 const TRect
& aUpdateRect
,
1060 const TRect
& aSourceRect
) const
1062 const TDsa
dsa(*this);
1066 ::ClipCopy
<TUint32
, TUint8
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
1069 ::ClipCopy
<TUint32
, TUint16
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
1072 ::ClipCopy
<TUint32
, TUint32
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
1078 void CDsa::Wipe() //dont call in drawing
1080 if(IsDsaAvailable())
1081 Wipe(iTargetBpp
* SwSize().iWidth
* SwSize().iHeight
);
1084 void CDsa::SetCopyFunction()
1086 //calculate offset to correct function in iCFTable according to given parameters
1088 const TInt KCopyFunctions
= 4;
1089 const TInt KOffsetToNative
= 0;
1090 const TInt KOffsetTo256
= KOffsetToNative
+ KCopyFunctions
;
1091 const TInt KOffsetToOtherModes
= KOffsetTo256
+ KCopyFunctions
;
1092 const TInt KOffsetTo90Functions
= 1;
1093 const TInt KOffsetTo180Functions
= 2;
1095 if(iSourceMode
== DisplayMode())
1096 function
= KOffsetToNative
; //0
1097 else if(iSourceMode
== EColor256
)
1098 function
= KOffsetTo256
; //4
1100 function
= KOffsetToOtherModes
; //8
1102 if(iStateFlags
& EOrientation90
)
1103 function
+= KOffsetTo90Functions
; // + 1
1104 if(iStateFlags
& EOrientation180
)
1105 function
+= KOffsetTo180Functions
; //+ 2
1107 iCopyFunction
= iCFTable
[function
];
1112 inline void Rotate(TRect
& aRect
)
1114 const TInt dx
= aRect
.iBr
.iX
- aRect
.iTl
.iX
;
1115 const TInt dy
= aRect
.iBr
.iY
- aRect
.iTl
.iY
;
1117 aRect
.iBr
.iX
= aRect
.iTl
.iX
+ dy
;
1118 aRect
.iBr
.iY
= aRect
.iTl
.iY
+ dx
;
1120 const TInt tmp
= aRect
.iTl
.iX
;
1121 aRect
.iTl
.iX
= aRect
.iTl
.iY
;
1125 TBool
CDsa::AddUpdateRect(const TUint8
* aBits
, const TRect
& aUpdateRect
, const TRect
& aRect
)
1128 if(iStateFlags
& EOrientationChanged
)
1130 iStateFlags
&= ~EOrientationFlags
;
1131 iStateFlags
|= iNewFlags
;
1133 iStateFlags
&= ~EOrientationChanged
;
1134 EpocSdlEnv::WaitDeviceChange();
1135 return EFalse
; //skip this frame as data is may be changed
1138 if(iTargetAddr
== NULL
)
1140 iTargetAddr
= LockHwSurface();
1143 TUint8
* target
= iTargetAddr
;
1148 TRect targetRect
= TRect(TPoint(0, 0), SwSize());
1150 TRect sourceRect
= aRect
;
1151 TRect updateRect
= aUpdateRect
;
1153 if(iStateFlags
& EOrientation90
)
1159 if(iSourceMode
!= DisplayMode() || targetRect
!= sourceRect
|| targetRect
!= updateRect
|| ((iStateFlags
& EOrientationFlags
) != 0))
1161 sourceRect
.Intersection(targetRect
); //so source always smaller or equal than target
1162 ClipCopy(target
, aBits
, updateRect
, sourceRect
);
1166 const TInt byteCount
= aRect
.Width() * aRect
.Height() * iSourceBpp
; //this could be stored
1167 Mem::Copy(target
, aBits
, byteCount
);
1174 void CDsa::UpdateSwSurface()
1177 UnlockHwSurface(); //could be faster if does not use AO, but only check status before redraw, then no context switch needed
1182 if(IsDsaAvailable())
1183 iStateFlags
|= ESdlThreadExplicitStop
;
1190 iStateFlags
&= ~ERunning
;
1195 iStateFlags
|= ERunning
;
1197 iStateFlags
&= ~ESdlThreadExplicitStop
;
1199 if(iStateFlags
& ESdlThreadSuspend
)
1201 EpocSdlEnv::Resume();
1202 iStateFlags
&= ~ ESdlThreadSuspend
;
1204 EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved
);
1208 TBool
CDsa::Blitter(CFbsBitmap
& aBmp
)
1210 return iBlitter
&& iBlitter
->BitBlt(*Gc(), aBmp
, HwRect(), SwSize());
1213 void CDsa::SetBlitter(MBlitter
* aBlitter
)
1215 iBlitter
= aBlitter
;
1219 TPoint
CDsa::WindowCoordinates(const TPoint
& aPoint
) const
1221 TPoint pos
= aPoint
- iScreenRect
.iTl
;
1222 const TSize asz
= iScreenRect
.Size();
1223 if(iStateFlags
& EOrientation180
)
1225 pos
.iX
= asz
.iWidth
- pos
.iX
;
1226 pos
.iY
= asz
.iHeight
- pos
.iY
;
1228 if(iStateFlags
& EOrientation90
)
1235 pos
.iX
/= asz
.iWidth
;
1236 pos
.iY
/= asz
.iHeight
;
1237 pos
.iX
*= iSwSize
.iWidth
;
1238 pos
.iY
*= iSwSize
.iHeight
;
1244 void CDsa::SetTargetRect()
1246 iTargetRect
= iScreenRect
;
1247 if(iStateFlags
& EResizeRequest
&& EpocSdlEnv::Flags(CSDL::EAllowImageResizeKeepRatio
))
1249 const TSize asz
= iScreenRect
.Size();
1250 const TSize sz
= iSwSize
;
1254 const TInt dh
= (sz
.iHeight
<< 16) / sz
.iWidth
;
1256 if((asz
.iWidth
* dh
) >> 16 <= asz
.iHeight
)
1258 rect
.SetRect(TPoint(0, 0), TSize(asz
.iWidth
, (asz
.iWidth
* dh
) >> 16));
1262 const TInt dw
= (sz
.iWidth
<< 16) / sz
.iHeight
;
1263 rect
.SetRect(TPoint(0, 0), TSize((asz
.iHeight
* dw
) >> 16, asz
.iHeight
));
1265 rect
.Move((asz
.iWidth
- rect
.Size().iWidth
) >> 1, (asz
.iHeight
- rect
.Size().iHeight
) >> 1);
1268 iTargetRect
.Move(iScreenRect
.iTl
);
1271 if(!(iStateFlags
& EResizeRequest
))
1272 iSwSize
= iScreenRect
.Size();
1276 RWindow
* CDsa::Window()
1281 CDsa
* CDsa::CreateGlesDsaL()
1283 CDsa
* dsa
= new (ELeave
) CDsaGles(Session());
1284 CWsScreenDevice
* dummy
= NULL
;
1285 dsa
->ConstructL(*Window(), *dummy
);
1292 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1294 void CDsa::Copy256(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1296 TUint32
* target
= aTarget
;
1297 const TUint32
* endt
= target
+ aBytes
;
1298 const TUint8
* source
= aSource
;
1299 while(target
< endt
)
1301 *target
++ = aDsa
.iLut256
[*source
++];
1305 void CDsa::Copy256Reversed(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1307 const TUint32
* target
= aTarget
;
1308 TUint32
* endt
= aTarget
+ aBytes
;
1309 const TUint8
* source
= aSource
;
1310 while(target
< endt
)
1312 *(--endt
) = aDsa
.iLut256
[*source
++];
1316 void CDsa::Copy256Flip(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1318 TUint32
* target
= aTarget
;
1319 const TUint32
* endt
= target
+ aBytes
;
1320 const TUint8
* column
= aSource
;
1322 while(target
< endt
)
1324 *target
++ = aDsa
.iLut256
[*column
];
1329 void CDsa::Copy256FlipReversed(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1331 const TUint32
* target
= aTarget
;
1332 TUint32
* endt
= aTarget
+ aBytes
;
1333 const TUint8
* column
= aSource
;
1335 while(target
< endt
)
1337 *(--endt
) = aDsa
.iLut256
[*column
];
1342 void CDsa::CopyMem(const CDsa
& /*aDsa*/, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1344 const TUint32
* src
= reinterpret_cast<const TUint32
*>(aSource
);
1345 Mem::Copy(aTarget
, src
, aBytes
<< 2);
1348 void CDsa::CopyMemFlip(const CDsa
& /*aDsa*/, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1350 TUint32
* target
= aTarget
;
1351 const TUint32
* endt
= target
+ aBytes
;
1352 const TUint32
* column
= reinterpret_cast<const TUint32
*>(aSource
);
1354 while(target
< endt
)
1356 *target
++ = *column
;
1361 void CDsa::CopyMemReversed(const CDsa
& /*aDsa*/, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1363 const TUint32
* target
= aTarget
;
1364 TUint32
* endt
= aTarget
+ aBytes
;
1365 const TUint32
* source
= reinterpret_cast<const TUint32
*>(aSource
);
1366 while(target
< endt
)
1368 *(--endt
) = *source
++;
1373 void CDsa::CopyMemFlipReversed(const CDsa
& /*aDsa*/, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1375 const TUint32
* target
= aTarget
;
1376 TUint32
* endt
= aTarget
+ aBytes
;
1377 const TUint32
* column
= reinterpret_cast<const TUint32
*>(aSource
);
1379 while(target
< endt
)
1381 *(--endt
) = *column
;
1386 NONSHARABLE_CLASS(MRgbCopy
)
1389 virtual void Copy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TBool aReversed
) = 0;
1390 virtual void FlipCopy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
, TBool aReversed
) = 0;
1394 NONSHARABLE_CLASS(TRgbCopy
) : public MRgbCopy
1397 TRgbCopy(TDisplayMode aMode
);
1398 void* operator new(TUint aBytes
, TAny
* aMem
);
1399 void Copy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TBool aReversed
);
1400 void FlipCopy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
, TBool aReversed
);
1401 static TUint32
Gray256(const TUint8
& aPixel
);
1402 static TUint32
Color256(const TUint8
& aPixel
);
1403 static TUint32
Color4K(const TUint16
& aPixel
);
1404 static TUint32
Color64K(const TUint16
& aPixel
);
1405 static TUint32
Color16M(const TUint32
& aPixel
);
1406 static TUint32
Color16MU(const TUint32
& aPixel
);
1407 static TUint32
Color16MA(const TUint32
& aPixel
);
1409 typedef TUint32 (*TRgbFunc
) (const T
& aValue
);
1415 void* TRgbCopy
<T
>::operator new(TUint
/*aBytes*/, TAny
* aMem
)
1421 TRgbCopy
<T
>::TRgbCopy(TDisplayMode aMode
)
1425 case EGray256
: iFunc
= (TRgbFunc
) Gray256
; break;
1426 case EColor256
: iFunc
= (TRgbFunc
) Color256
; break;
1427 case EColor4K
: iFunc
= (TRgbFunc
) Color4K
; break;
1428 case EColor64K
: iFunc
= (TRgbFunc
) Color64K
; break;
1429 case EColor16M
: iFunc
= (TRgbFunc
) Color16M
; break;
1430 case EColor16MU
: iFunc
= (TRgbFunc
) Color16MU
; break;
1431 case EColor16MA
: iFunc
= (TRgbFunc
) Color16MA
; break;
1433 PANIC(KErrNotSupported
);
1438 void TRgbCopy
<T
>::Copy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TBool aReversed
)
1440 const T
* source
= reinterpret_cast<const T
*>(aSource
);
1441 TUint32
* target
= aTarget
;
1442 TUint32
* endt
= target
+ aBytes
;
1446 while(target
< endt
)
1448 const T value
= *source
++;
1449 *(--endt
) = iFunc(value
);
1454 while(target
< endt
)
1456 const T value
= *source
++;
1457 *target
++ = iFunc(value
);
1463 void TRgbCopy
<T
>::FlipCopy(TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
, TBool aReversed
)
1465 const T
* column
= reinterpret_cast<const T
*>(aSource
);
1466 TUint32
* target
= aTarget
;
1467 TUint32
* endt
= target
+ aBytes
;
1471 while(target
< endt
)
1473 *(--endt
) = iFunc(*column
);
1479 while(target
< endt
)
1481 *target
++ = iFunc(*column
);
1487 template <class T
> TUint32 TRgbCopy
<T
>::Gray256(const TUint8
& aPixel
)
1489 const TUint32 px
= aPixel
<< 16 | aPixel
<< 8 | aPixel
;
1493 template <class T
> TUint32 TRgbCopy
<T
>::Color256(const TUint8
& aPixel
)
1495 return TRgb::Color256(aPixel
).Value();
1498 template <class T
> TUint32 TRgbCopy
<T
>::Color4K(const TUint16
& aPixel
)
1500 TUint32 col
= (aPixel
& 0xF00) << 12;
1501 col
|= (aPixel
& 0xF00) << 8;
1503 col
|= (aPixel
& 0x0F0) << 8;
1504 col
|= (aPixel
& 0x0F0);
1506 col
|= (aPixel
& 0x00F) << 4;
1507 col
|= (aPixel
& 0x00F);
1512 template <class T
> TUint32 TRgbCopy
<T
>::Color64K(const TUint16
& aPixel
)
1514 TUint32 col
= (aPixel
& 0xF800)<< 8;
1515 col
|= (aPixel
& 0xE000) << 3;
1517 col
|= (aPixel
& 0x07E0) << 5;
1518 col
|= (aPixel
& 0xC0) >> 1;
1520 col
|= (aPixel
& 0x07E0) << 3;
1521 col
|= (aPixel
& 0x1C) >> 2;
1526 template <class T
> TUint32 TRgbCopy
<T
>::Color16M(const TUint32
& aPixel
)
1528 return TRgb::Color16M(aPixel
).Value();
1531 template <class T
> TUint32 TRgbCopy
<T
>::Color16MU(const TUint32
& aPixel
)
1533 return TRgb::Color16MU(aPixel
).Value();
1536 template <class T
> TUint32 TRgbCopy
<T
>::Color16MA(const TUint32
& aPixel
)
1538 return TRgb::Color16MA(aPixel
).Value();
1541 typedef TUint64 TStackMem
;
1543 LOCAL_C MRgbCopy
* GetCopy(TAny
* mem
, TDisplayMode aMode
)
1545 if(aMode
== EColor256
|| aMode
== EGray256
)
1547 return new (mem
) TRgbCopy
<TUint8
>(aMode
);
1549 if(aMode
== EColor4K
|| aMode
== EColor64K
)
1551 return new (mem
) TRgbCopy
<TUint16
>(aMode
);
1553 if(aMode
== EColor16M
|| aMode
== EColor16MU
|| aMode
== EColor16MA
)
1555 return new (mem
) TRgbCopy
<TUint32
>(aMode
);
1557 PANIC(KErrNotSupported
);
1562 void CDsa::CopySlowFlipReversed(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1565 GetCopy(&mem
, aDsa
.iSourceMode
)->FlipCopy(aTarget
, aSource
, aBytes
, aLineLen
, ETrue
);
1568 void CDsa::CopySlowFlip(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt aLineLen
)
1571 GetCopy(&mem
, aDsa
.iSourceMode
)->FlipCopy(aTarget
, aSource
, aBytes
, aLineLen
, EFalse
);
1574 void CDsa::CopySlow(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1577 GetCopy(&mem
, aDsa
.iSourceMode
)->Copy(aTarget
, aSource
, aBytes
, EFalse
);
1580 void CDsa::CopySlowReversed(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, TInt aBytes
, TInt
)
1583 GetCopy(&mem
, aDsa
.iSourceMode
)->Copy(aTarget
, aSource
, aBytes
, ETrue
);