2
#include "sdlepocapi.h"
6
LOCAL_C TInt BytesPerPixel(TDisplayMode aMode)
8
return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1;
15
NONSHARABLE_CLASS(CBitmapSurface) : public T
18
CBitmapSurface(RWsSession& aSession);
20
void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
22
TUint8* LockSurface();
23
void UnlockHwSurface();
24
void CreateSurfaceL();
25
void Wipe(TInt aLength);
27
void Update(CFbsBitmap& aBmp);
28
TInt ExternalUpdate();
36
void CBitmapSurface<T>::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
40
iCopyBmp = new (ELeave) CFbsBitmap();
41
T::ConstructL(aWindow, aDevice);
45
CBitmapSurface<T>::CBitmapSurface(RWsSession& aSession) : T(aSession)
50
void CBitmapSurface<T>::Free()
58
CBitmapSurface<T>::~CBitmapSurface()
60
__ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady));
65
TUint8* CBitmapSurface<T>::LockSurface()
68
return reinterpret_cast<TUint8*>(iBmp->DataAddress());
73
void CBitmapSurface<T>::UnlockHwSurface()
76
T::SetUpdating(EFalse);
82
void CBitmapSurface<T>::Update(CFbsBitmap& aBmp)
86
if(T::SwSize() == T::HwRect().Size())
87
T::Gc().BitBlt(T::HwRect().iTl, &aBmp);
89
T::Gc().DrawBitmap(T::HwRect(), &aBmp);
96
void CBitmapSurface<T>::CreateSurfaceL()
99
iBmp = new (ELeave) CFbsBitmap();
100
User::LeaveIfError(iBmp->Create(T::SwSize(), T::DisplayMode()));
101
T::CreateSurfaceL(*iBmp);
105
void CBitmapSurface<T>::Wipe(TInt aLength) //dont call in drawing
108
Mem::FillZ(iBmp->DataAddress(), aLength);
113
TInt CBitmapSurface<T>::ExternalUpdate()
115
if(iCopyBmp->Handle() == 0)
117
const TInt err = iCopyBmp->Duplicate(iBmp->Handle());
126
//////////////////////////////////////////////////////////////////////
130
NONSHARABLE_CLASS(CDsaBitgdi) : public CDsa
133
CDsaBitgdi(RWsSession& aSession);
135
void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
136
CBitmapContext& Gc();
137
void CompleteUpdate();
139
void CreateSurfaceL(CFbsBitmap& aBmp);
141
void UnlockHWSurfaceRequestComplete();
147
CFbsBitmap* iBitGdiBmp;
154
CDsaBitgdi::CDsaBitgdi(RWsSession& aSession) : CDsa(aSession)
158
CDsaBitgdi::~CDsaBitgdi()
164
void CDsaBitgdi::CompleteUpdate()
166
EpocSdlEnv::Request(CDsa::ERequestUpdate);
170
void CDsaBitgdi::UnlockHWSurfaceRequestComplete()
175
if(iBitGdiBmp == NULL)
177
iBitGdiBmp = new CFbsBitmap();
178
if(iBitGdiBmp == NULL)
180
iBitGdiBmp->Duplicate(iHandle);
183
iWindow->Invalidate();
185
iWindow->BeginRedraw();
186
iWinGc->Activate(*iWindow);
187
iWinGc->BitBlt(TPoint(0, 0), iBitGdiBmp);
188
iWinGc->Deactivate();
189
iWindow->EndRedraw();
192
void CDsaBitgdi::Resume()
197
CBitmapContext& CDsaBitgdi::Gc()
202
void CDsaBitgdi::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
212
User::LeaveIfError(aDevice.CreateContext(iWinGc));
213
CDsa::ConstructL(aWindow, aDevice);
217
void CDsaBitgdi::CreateSurfaceL(CFbsBitmap& aBmp)
219
iDevice = CFbsBitmapDevice::NewL(&aBmp);
220
User::LeaveIfError(iDevice->CreateContext(iGc));
221
iHandle = aBmp.Handle();
224
void CDsaBitgdi::Free()
232
////////////////////////////////////////////////////////////////////////
233
///////////////////////////////////////////////////////////////////////
235
NONSHARABLE_CLASS(CDsaBase) : public CDsa, public MDirectScreenAccess
238
inline CDirectScreenAccess& Dsa() const;
239
CDsaBase(RWsSession& aSession);
241
void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
244
CBitmapContext& Gc();
246
CDirectScreenAccess* iDsa;
248
void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
249
void Restart(RDirectScreenAccess::TTerminationReasons aReason);
255
inline CDirectScreenAccess& CDsaBase::Dsa() const
261
CDsaBase::CDsaBase(RWsSession& aSession) : CDsa(aSession)
265
CBitmapContext& CDsaBase::Gc()
270
void CDsaBase::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
272
CDsa::ConstructL(aWindow, aDevice);
280
iDsa = CDirectScreenAccess::NewL(
288
void CDsaBase::Resume()
291
Restart(RDirectScreenAccess::ETerminateRegion);
294
CDsaBase::~CDsaBase()
304
void CDsaBase::RestartL()
310
const RRegion* r = iDsa->DrawingRegion();
311
const TRect rect = r->BoundingRect();
312
iDsa->Gc()->SetClippingRegion(r);
314
if(rect != ScreenRect())
328
void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
333
void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons aReason)
335
if(aReason == RDirectScreenAccess::ETerminateRegion) //auto restart
337
TRAPD(err, RestartL());
343
void CDsaBase::Stop()
350
///////////////////////////////////////////////////////////////////////
351
///////////////////////////////////////////////////////////////////////
352
NONSHARABLE_CLASS(TDsa)
355
inline TDsa(const CDsa& aDsa);
356
inline TBool IsFlip() const;
357
inline TBool IsTurn() const;
358
inline const TSize& SwSize() const;
359
inline void Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const;
367
inline TDsa::TDsa(const CDsa& aDsa) : iDsa(aDsa)
371
inline TBool TDsa::IsTurn() const
373
return iDsa.iStateFlags & CDsa::EOrientation90;
376
inline TBool TDsa::IsFlip() const
378
return iDsa.iStateFlags & CDsa::EOrientation180;
381
inline const TSize& TDsa::SwSize() const
383
return iDsa.SwSize();
386
inline void TDsa::Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const
388
iDsa.iCopyFunction(iDsa, aTarget, aSrc, aBytes, aHeight);
391
template<class T, class S>
392
void ClipCopy(const TDsa& iDsa, TUint8* aTarget,
393
const TUint8* aSource,
394
const TRect& aUpdateRect,
395
const TRect& aSourceRect)
397
const S* source = reinterpret_cast<const S*>(aSource);
398
const TInt lineWidth = aSourceRect.Width();
400
source += (aUpdateRect.iTl.iY * lineWidth);
401
const TInt sourceStartOffset = aUpdateRect.iTl.iX;
402
source += sourceStartOffset;
404
T* targetPtr = reinterpret_cast<T*>(aTarget);
406
const TInt scanLineWidth = iDsa.SwSize().iWidth;
408
targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * scanLineWidth;
409
const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX);
411
targetPtr += targetStartOffset;
414
const TInt height = aUpdateRect.Height();
416
const TInt lineMove = iDsa.IsTurn() ? 1 : lineWidth;
417
const TInt copyLen = aUpdateRect.Width();
423
targetPtr += scanLineWidth * (height - 1);
425
for(TInt i = 0; i < height; i++) //source is always smaller
427
iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
429
targetPtr -= scanLineWidth;
436
for(TInt i = 0; i < height; i++) //source is always smaller
438
iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
440
targetPtr += scanLineWidth; // >> 2;
448
NONSHARABLE_CLASS(CDsaA) : public CDsaBase
451
CDsaA(RWsSession& aSession);
453
void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
454
void CompleteUpdate();
455
void CreateSurfaceL(CFbsBitmap& aBmp);
457
void UnlockHWSurfaceRequestComplete();
461
CDsaA::CDsaA(RWsSession& aSession) : CDsaBase(aSession)
466
void CDsaA::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
468
CDsaBase::ConstructL(aWindow, aDevice);
471
void CDsaA::CompleteUpdate()
473
iDsa->ScreenDevice()->Update();
476
void CDsaA::CreateSurfaceL(CFbsBitmap& /*aBmp*/)
485
void CDsaA::UnlockHWSurfaceRequestComplete()
487
PANIC(KErrNotSupported);
492
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
494
NONSHARABLE_CLASS(MDsbObs)
497
virtual void SurfaceReady() = 0;
498
virtual CDirectScreenBitmap& Dsb() = 0;
501
NONSHARABLE_CLASS(CDsbSurface) : public CActive
504
CDsbSurface(MDsbObs& aDsb);
516
CDsbSurface::CDsbSurface(MDsbObs& aDsb) : CActive(CActive::EPriorityHigh) , iDsb(aDsb)
518
CActiveScheduler::Add(this);
521
CDsbSurface::~CDsbSurface()
526
void CDsbSurface::Complete()
528
if(iAddress != NULL && !IsActive())
532
iDsb.Dsb().EndUpdate(iStatus);
536
TUint8* CDsbSurface::Address()
538
if(iAddress == NULL && !IsActive())
540
TAcceleratedBitmapInfo info;
541
if(KErrNone == iDsb.Dsb().BeginUpdate(info))
542
iAddress = info.iAddress;
547
void CDsbSurface::RunL()
552
void CDsbSurface::DoCancel()
557
NONSHARABLE_CLASS(CDsaB) : public CDsaBase,
561
CDsaB(RWsSession& aSession, TInt aFlags);
564
TUint8* LockSurface();
565
void UnlockHWSurfaceRequestComplete();
566
void UnlockHwSurface();
567
void CreateSurfaceL();
568
void Wipe(TInt aLength);
570
void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
571
CDirectScreenBitmap& Dsb();
573
TInt ExternalUpdate();
575
CDsbSurface* iSurface1;
576
CDsbSurface* iSurface2;
577
CDirectScreenBitmap* iDsb;
581
CDsaB::CDsaB(RWsSession& aSession, TInt aFlags) : CDsaBase(aSession), iType(aFlags)
587
void CDsaB::UnlockHWSurfaceRequestComplete()
589
iSurface1->Complete();
590
if(iSurface2 != NULL)
591
iSurface2->Complete();
594
void CDsaB::CreateSurfaceL()
596
__ASSERT_ALWAYS(SwSize() == HwRect().Size(), PANIC(KErrNotSupported));
599
void CDsaB::Wipe(TInt aLength) //dont call in drawing
601
TUint8* addr = LockSurface();
604
Mem::FillZ(addr, aLength);
610
void CDsaB::UnlockHwSurface()
612
EpocSdlEnv::Request(CDsa::ERequestUpdate);
615
TUint8* CDsaB::LockSurface()
617
TUint8* addr = iSurface1->Address();
618
if(addr == NULL && iSurface2 != NULL)
619
addr = iSurface2->Address();
620
SetUpdating(addr == NULL);
624
void CDsaB::SurfaceReady()
629
CDirectScreenBitmap& CDsaB::Dsb()
634
void CDsaB::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
637
iDsb = CDirectScreenBitmap::NewL();
638
CDsaBase::ConstructL(aWindow, aDevice);
639
if(iSurface1 == NULL)
640
iSurface1 = new (ELeave) CDsbSurface(*this);
641
if(iSurface2 == NULL && iType & CDirectScreenBitmap::EDoubleBuffer)
642
iSurface2 = new (ELeave) CDsbSurface(*this);
652
void CDsaB::RecreateL()
655
iDsb->Create(HwRect(), CDirectScreenBitmap::TSettingsFlags(iType));
658
TInt CDsaB::ExternalUpdate()
662
UnlockHWSurfaceRequestComplete();
669
/////////////////////////////////////////////////////////////////////////////////////////////////////
673
CDsa* CDsa::CreateL(RWsSession& aSession)
675
if(EpocSdlEnv::Flags(CSDL::EDrawModeDSB))
677
TInt flags = CDirectScreenBitmap::ENone;
678
if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBDoubleBuffer))
679
flags |= CDirectScreenBitmap::EDoubleBuffer;
680
if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBIncrementalUpdate))
681
flags |= CDirectScreenBitmap::EIncrementalUpdate;
682
return new (ELeave) CDsaB(aSession, flags);
684
else if(EpocSdlEnv::Flags(CSDL::EDrawModeGdi))
686
return new (ELeave) CBitmapSurface<CDsaBitgdi>(aSession);
690
return new (ELeave) CBitmapSurface<CDsaA>(aSession);
695
void CDsa::RecreateL()
703
TSize CDsa::WindowSize() const
705
TSize size = iSwSize;
706
if(iStateFlags & EOrientation90)
708
const TInt tmp = size.iWidth;
709
size.iWidth = size.iHeight;
715
void CDsa::SetSuspend()
717
iStateFlags |= ESdlThreadSuspend;
721
void CDsa::SetUpdating(TBool aUpdate)
724
iStateFlags |= EUpdating;
726
iStateFlags &= ~EUpdating;
730
TBool CDsa::Stopped() const
732
return (iStateFlags & ESdlThreadExplicitStop);
735
void CDsa::SetOrientation(CSDL::TOrientationMode aOrientation)
740
case CSDL::EOrientation90:
741
flags = EOrientation90;
743
case CSDL::EOrientation180:
744
flags = EOrientation180;
746
case CSDL::EOrientation270:
747
flags = EOrientation90 | EOrientation180;
749
case CSDL::EOrientation0:
753
if(flags != (iStateFlags & EOrientationFlags))
755
iStateFlags |= EOrientationChanged;
756
iNewFlags = flags; //cannot be set during drawing...
766
void CDsa::ConstructL(RWindow& aWindow, CWsScreenDevice& /*aDevice*/)
769
iLut256 = (TUint32*) User::AllocL(256 * sizeof(TUint32));
770
iTargetMode = aWindow.DisplayMode();
771
iTargetBpp = BytesPerPixel(DisplayMode());
772
iScreenRect = TRect(aWindow.Position(), aWindow.Size());
776
void CDsa::DrawOverlays()
778
const TInt last = iOverlays.Count() - 1;
779
for(TInt i = last; i >= 0 ; i--)
780
iOverlays[i].iOverlay->Draw(Gc(), HwRect(), SwSize());
783
TInt CDsa::AppendOverlay(MOverlay& aOverlay, TInt aPriority)
786
for(i = 0; i < iOverlays.Count() && iOverlays[i].iPriority < aPriority; i++)
788
const TOverlay overlay = {&aOverlay, aPriority};
789
return iOverlays.Insert(overlay, i);
792
TInt CDsa::RemoveOverlay(MOverlay& aOverlay)
794
for(TInt i = 0; i < iOverlays.Count(); i++)
796
if(iOverlays[i].iOverlay == &aOverlay)
805
void CDsa::LockPalette(TBool aLock)
808
iStateFlags |= EPaletteLocked;
810
iStateFlags &= ~EPaletteLocked;
812
TInt CDsa::SetPalette(TInt aFirst, TInt aCount, TUint32* aPalette)
816
const TInt count = aCount - aFirst;
819
if(iStateFlags & EPaletteLocked)
821
for(TInt i = aFirst; i < count; i++) //not so busy here:-)
823
iLut256[i] = aPalette[i];
832
CDsa::CDsa(RWsSession& aSession) :
837
// CActiveScheduler::Add(this);
838
iCFTable[0] = CopyMem;
839
iCFTable[1] = CopyMemFlipReversed;
840
iCFTable[2] = CopyMemReversed;
841
iCFTable[3] = CopyMemFlip;
843
iCFTable[4] = Copy256;
844
iCFTable[5] = Copy256FlipReversed;
845
iCFTable[6] = Copy256Reversed;
846
iCFTable[7] = Copy256Flip;
849
iCFTable[8] = CopySlow;
850
iCFTable[9] = CopySlowFlipReversed;
851
iCFTable[10] = CopySlowReversed;
852
iCFTable[11] = CopySlowFlip;
855
RWsSession& CDsa::Session()
860
TInt CDsa::RedrawRequest()
862
if(!(iStateFlags & (EUpdating) && (iStateFlags & ERunning)))
864
return ExternalUpdate();
869
TUint8* CDsa::LockHwSurface()
871
if((iStateFlags & EUpdating) == 0) //else frame is skipped
873
return LockSurface();
881
iStateFlags &= ~EUpdating;
885
void CDsa::DoCancel()
887
iStateFlags &= ~EUpdating;
888
//nothing can do, just wait?
893
TInt CDsa::AllocSurface(TBool aHwSurface, const TSize& aSize, TDisplayMode aMode)
895
if(aHwSurface && aMode != DisplayMode())
900
iSourceBpp = BytesPerPixel(aMode);
902
const TSize size = WindowSize();
903
if(aSize.iWidth > size.iWidth)
905
if(aSize.iHeight > size.iHeight)
908
TRAPD(err, CreateSurfaceL());
918
void CDsa::CreateZoomerL(const TSize& aSize)
921
iStateFlags |= EResizeRequest;
928
void SaveBmp(const TDesC& aName, const TAny* aData, TInt aLength, const TSize& aSz, TDisplayMode aMode)
930
CFbsBitmap* s = new CFbsBitmap();
931
s->Create(aSz, aMode);
933
TUint32* addr = s->DataAddress();
934
Mem::Copy(addr, aData, aLength);
941
void SaveBmp(const TDesC& aName, const TUint32* aData, const TSize& aSz)
943
CFbsBitmap* s = new CFbsBitmap();
944
s->Create(aSz, EColor64K);
946
bmp.Begin(TPoint(0, 0));
947
for(TInt j = 0; j < aSz.iHeight; j++)
949
bmp.SetPos(TPoint(0, j));
950
for(TInt i = 0; i < aSz.iWidth; i++)
952
bmp.SetPixel(*aData);
963
TBuf<16> FooName(TInt aFoo)
966
b.Format(_L("C:\\pic%d.mbm"), aFoo);
973
void CDsa::ClipCopy(TUint8* aTarget,
974
const TUint8* aSource,
975
const TRect& aUpdateRect,
976
const TRect& aSourceRect) const
978
const TDsa dsa(*this);
982
::ClipCopy<TUint32, TUint8>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
985
::ClipCopy<TUint32, TUint16>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
988
::ClipCopy<TUint32, TUint32>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
994
void CDsa::Wipe() //dont call in drawing
997
Wipe(iTargetBpp * SwSize().iWidth * SwSize().iHeight);
1000
void CDsa::SetCopyFunction()
1002
//calculate offset to correct function in iCFTable according to given parameters
1004
const TInt KCopyFunctions = 4;
1005
const TInt KOffsetToNative = 0;
1006
const TInt KOffsetTo256 = KOffsetToNative + KCopyFunctions;
1007
const TInt KOffsetToOtherModes = KOffsetTo256 + KCopyFunctions;
1008
const TInt KOffsetTo90Functions = 1;
1009
const TInt KOffsetTo180Functions = 2;
1011
if(iSourceMode == DisplayMode())
1012
function = KOffsetToNative; //0
1013
else if(iSourceMode == EColor256)
1014
function = KOffsetTo256; //4
1016
function = KOffsetToOtherModes; //8
1018
if(iStateFlags & EOrientation90)
1019
function += KOffsetTo90Functions; // + 1
1020
if(iStateFlags & EOrientation180)
1021
function += KOffsetTo180Functions; //+ 2
1023
iCopyFunction = iCFTable[function];
1028
inline void Rotate(TRect& aRect)
1030
const TInt dx = aRect.iBr.iX - aRect.iTl.iX;
1031
const TInt dy = aRect.iBr.iY - aRect.iTl.iY;
1033
aRect.iBr.iX = aRect.iTl.iX + dy;
1034
aRect.iBr.iY = aRect.iTl.iY + dx;
1036
const TInt tmp = aRect.iTl.iX;
1037
aRect.iTl.iX = aRect.iTl.iY;
1045
TBool CDsa::AddUpdateRect(const TUint8* aBits, const TRect& aUpdateRect, const TRect& aRect)
1048
if(iStateFlags & EOrientationChanged)
1050
iStateFlags &= ~EOrientationFlags;
1051
iStateFlags |= iNewFlags;
1053
iStateFlags &= ~EOrientationChanged;
1054
EpocSdlEnv::WaitDeviceChange();
1055
return EFalse; //skip this frame as data is may be changed
1058
if(iTargetAddr == NULL)
1060
iTargetAddr = LockHwSurface();
1063
TUint8* target = iTargetAddr;
1068
TRect targetRect = TRect(TPoint(0, 0), SwSize());
1070
TRect sourceRect = aRect;
1071
TRect updateRect = aUpdateRect;
1073
// TPoint move(0, 0);
1076
if(iStateFlags & EOrientation90)
1082
if(iSourceMode != DisplayMode() || targetRect != sourceRect || targetRect != updateRect || ((iStateFlags & EOrientationFlags) != 0))
1084
sourceRect.Intersection(targetRect); //so source always smaller or equal than target
1085
//updateRect.Intersection(targetRect);
1086
ClipCopy(target, aBits, updateRect, sourceRect);
1090
const TInt byteCount = aRect.Width() * aRect.Height() * iSourceBpp; //this could be stored
1091
Mem::Copy(target, aBits, byteCount);
1098
void CDsa::UpdateSwSurface()
1101
UnlockHwSurface(); //could be faster if does not use AO, but only check status before redraw, then no context switch needed
1109
if(IsDsaAvailable())
1110
iStateFlags |= ESdlThreadExplicitStop;
1117
iStateFlags &= ~ERunning;
1122
iStateFlags |= ERunning;
1124
iStateFlags &= ~ESdlThreadExplicitStop;
1126
if(iStateFlags & ESdlThreadSuspend)
1128
EpocSdlEnv::Resume();
1129
iStateFlags &= ~ ESdlThreadSuspend;
1131
EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved);
1135
TBool CDsa::Blitter(CFbsBitmap& aBmp)
1137
return iBlitter && iBlitter->BitBlt(Gc(), aBmp, HwRect(), SwSize());
1140
void CDsa::SetBlitter(MBlitter* aBlitter)
1142
iBlitter = aBlitter;
1146
TPoint CDsa::WindowCoordinates(const TPoint& aPoint) const
1148
TPoint pos = aPoint - iScreenRect.iTl;
1149
const TSize asz = iScreenRect.Size();
1150
if(iStateFlags & EOrientation180)
1152
pos.iX = asz.iWidth - pos.iX;
1153
pos.iY = asz.iHeight - pos.iY;
1155
if(iStateFlags & EOrientation90)
1162
pos.iX /= asz.iWidth;
1163
pos.iY /= asz.iHeight;
1164
pos.iX *= iSwSize.iWidth;
1165
pos.iY *= iSwSize.iHeight;
1171
void CDsa::SetTargetRect()
1173
iTargetRect = iScreenRect;
1174
if(iStateFlags & EResizeRequest && EpocSdlEnv::Flags(CSDL::EAllowImageResizeKeepRatio))
1176
const TSize asz = iScreenRect.Size();
1177
const TSize sz = iSwSize;
1181
const TInt dh = (sz.iHeight << 16) / sz.iWidth;
1183
if((asz.iWidth * dh ) >> 16 <= asz.iHeight)
1185
rect.SetRect(TPoint(0, 0), TSize(asz.iWidth, (asz.iWidth * dh) >> 16));
1189
const TInt dw = (sz.iWidth << 16) / sz.iHeight;
1190
rect.SetRect(TPoint(0, 0), TSize((asz.iHeight * dw) >> 16, asz.iHeight));
1192
rect.Move((asz.iWidth - rect.Size().iWidth) >> 1, (asz.iHeight - rect.Size().iHeight) >> 1);
1195
iTargetRect.Move(iScreenRect.iTl);
1198
if(!(iStateFlags & EResizeRequest))
1199
iSwSize = iScreenRect.Size();
1204
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1206
void CDsa::Copy256(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1208
TUint32* target = aTarget;
1209
const TUint32* endt = target + aBytes;
1210
const TUint8* source = aSource;
1211
while(target < endt)
1213
*target++ = aDsa.iLut256[*source++];
1217
void CDsa::Copy256Reversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1219
const TUint32* target = aTarget;
1220
TUint32* endt = aTarget + aBytes;
1221
const TUint8* source = aSource;
1222
while(target < endt)
1224
*(--endt) = aDsa.iLut256[*source++];
1228
void CDsa::Copy256Flip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1230
TUint32* target = aTarget;
1231
const TUint32* endt = target + aBytes;
1232
const TUint8* column = aSource;
1234
while(target < endt)
1236
*target++ = aDsa.iLut256[*column];
1241
void CDsa::Copy256FlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1243
const TUint32* target = aTarget;
1244
TUint32* endt = aTarget + aBytes;
1245
const TUint8* column = aSource;
1247
while(target < endt)
1249
*(--endt) = aDsa.iLut256[*column];
1254
void CDsa::CopyMem(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1256
const TUint32* src = reinterpret_cast<const TUint32*>(aSource);
1257
Mem::Copy(aTarget, src, aBytes << 2);
1260
void CDsa::CopyMemFlip(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1262
TUint32* target = aTarget;
1263
const TUint32* endt = target + aBytes;
1264
const TUint32* column = reinterpret_cast<const TUint32*>(aSource);
1266
while(target < endt)
1268
*target++ = *column;
1273
void CDsa::CopyMemReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1275
const TUint32* target = aTarget;
1276
TUint32* endt = aTarget + aBytes;
1277
const TUint32* source = reinterpret_cast<const TUint32*>(aSource);
1278
while(target < endt)
1280
*(--endt) = *source++;
1285
void CDsa::CopyMemFlipReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1287
const TUint32* target = aTarget;
1288
TUint32* endt = aTarget + aBytes;
1289
const TUint32* column = reinterpret_cast<const TUint32*>(aSource);
1291
while(target < endt)
1293
*(--endt) = *column;
1300
LOCAL_C TRgb rgb16MA(TInt aValue)
1302
return TRgb::Color16MA(aValue);
1305
NONSHARABLE_CLASS(MRgbCopy)
1308
virtual void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed) = 0;
1309
virtual void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed) = 0;
1313
NONSHARABLE_CLASS(TRgbCopy) : public MRgbCopy
1316
TRgbCopy(TDisplayMode aMode);
1317
void* operator new(TUint aBytes, TAny* aMem);
1318
void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed);
1319
void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed);
1320
static TUint32 Gray256(const TUint8& aPixel);
1321
static TUint32 Color256(const TUint8& aPixel);
1322
static TUint32 Color4K(const TUint16& aPixel);
1323
static TUint32 Color64K(const TUint16& aPixel);
1324
static TUint32 Color16M(const TUint32& aPixel);
1325
static TUint32 Color16MU(const TUint32& aPixel);
1326
static TUint32 Color16MA(const TUint32& aPixel);
1328
typedef TUint32 (*TRgbFunc) (const T& aValue);
1334
void* TRgbCopy<T>::operator new(TUint /*aBytes*/, TAny* aMem)
1340
TRgbCopy<T>::TRgbCopy(TDisplayMode aMode)
1344
case EGray256 : iFunc = (TRgbFunc) Gray256; break;
1345
case EColor256 : iFunc = (TRgbFunc) Color256; break;
1346
case EColor4K : iFunc = (TRgbFunc) Color4K; break;
1347
case EColor64K : iFunc = (TRgbFunc) Color64K; break;
1348
case EColor16M : iFunc = (TRgbFunc) Color16M; break;
1349
case EColor16MU : iFunc = (TRgbFunc) Color16MU; break;
1350
case EColor16MA : iFunc = (TRgbFunc) Color16MA; break;
1352
PANIC(KErrNotSupported);
1357
void TRgbCopy<T>::Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed)
1359
const T* source = reinterpret_cast<const T*>(aSource);
1360
TUint32* target = aTarget;
1361
TUint32* endt = target + aBytes;
1365
while(target < endt)
1367
const T value = *source++;
1368
*(--endt) = iFunc(value);//iFunc(value).Value();
1373
while(target < endt)
1375
const T value = *source++;
1376
*target++ = iFunc(value);//iFunc(value).Value();
1382
void TRgbCopy<T>::FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed)
1384
const T* column = reinterpret_cast<const T*>(aSource);
1385
TUint32* target = aTarget;
1386
TUint32* endt = target + aBytes;
1390
while(target < endt)
1392
*(--endt) = iFunc(*column);
1398
while(target < endt)
1400
*target++ = iFunc(*column);
1406
template <class T> TUint32 TRgbCopy<T>::Gray256(const TUint8& aPixel)
1408
const TUint32 px = aPixel << 16 | aPixel << 8 | aPixel;
1412
template <class T> TUint32 TRgbCopy<T>::Color256(const TUint8& aPixel)
1414
return TRgb::Color256(aPixel).Value();
1417
template <class T> TUint32 TRgbCopy<T>::Color4K(const TUint16& aPixel)
1419
TUint32 col = (aPixel & 0xF00) << 12;
1420
col |= (aPixel & 0xF00) << 8;
1422
col |= (aPixel & 0x0F0) << 8;
1423
col |= (aPixel & 0x0F0);
1425
col |= (aPixel & 0x00F) << 4;
1426
col |= (aPixel & 0x00F);
1431
template <class T> TUint32 TRgbCopy<T>::Color64K(const TUint16& aPixel)
1433
TUint32 col = (aPixel & 0xF800)<< 8;
1434
col |= (aPixel & 0xE000) << 3;
1436
col |= (aPixel & 0x07E0) << 5;
1437
col |= (aPixel & 0xC0) >> 1;
1439
col |= (aPixel & 0x07E0) << 3;
1440
col |= (aPixel & 0x1C) >> 2;
1445
template <class T> TUint32 TRgbCopy<T>::Color16M(const TUint32& aPixel)
1447
return TRgb::Color16M(aPixel).Value();
1450
template <class T> TUint32 TRgbCopy<T>::Color16MU(const TUint32& aPixel)
1452
return TRgb::Color16MU(aPixel).Value();
1455
template <class T> TUint32 TRgbCopy<T>::Color16MA(const TUint32& aPixel)
1457
return TRgb::Color16MA(aPixel).Value();
1460
typedef TUint64 TStackMem;
1462
LOCAL_C MRgbCopy* GetCopy(TAny* mem, TDisplayMode aMode)
1464
if(aMode == EColor256 || aMode == EGray256)
1466
return new (mem) TRgbCopy<TUint8>(aMode);
1468
if(aMode == EColor4K || aMode == EColor64K)
1470
return new (mem) TRgbCopy<TUint16>(aMode);
1472
if(aMode == EColor16M || aMode == EColor16MU || aMode == EColor16MA)
1474
return new (mem) TRgbCopy<TUint32>(aMode);
1476
PANIC(KErrNotSupported);
1481
void CDsa::CopySlowFlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1484
GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, ETrue);
1487
void CDsa::CopySlowFlip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1490
GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, EFalse);
1493
void CDsa::CopySlow(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1496
GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, EFalse);
1499
void CDsa::CopySlowReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1502
GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, ETrue);
1505
////////////////////////////////////////////////////////////////////////////////////////////////////////////////7