2 #include "sdlepocapi.h"
6 LOCAL_C TInt BytesPerPixel(TDisplayMode aMode)
8 return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1;
12 NONSHARABLE_CLASS(TDsa)
15 inline TDsa(const CDsa& aDsa);
16 inline TBool IsFlip() const;
17 inline TBool IsTurn() const;
18 inline const TSize& SwSize() const;
19 inline void Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const;
25 inline TDsa::TDsa(const CDsa& aDsa) : iDsa(aDsa)
29 inline TBool TDsa::IsTurn() const
31 return iDsa.iStateFlags & CDsa::EOrientation90;
34 inline TBool TDsa::IsFlip() const
36 return iDsa.iStateFlags & CDsa::EOrientation180;
39 inline const TSize& TDsa::SwSize() const
44 inline void TDsa::Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const
46 iDsa.iCopyFunction(iDsa, aTarget, aSrc, aBytes, aHeight);
49 template<class T, class S>
50 void ClipCopy(const TDsa& iDsa, TUint8* aTarget,
51 const TUint8* aSource,
52 const TRect& aUpdateRect,
53 const TRect& aSourceRect)
55 const S* source = reinterpret_cast<const S*>(aSource);
56 const TInt lineWidth = aSourceRect.Width();
58 source += (aUpdateRect.iTl.iY * lineWidth);
59 const TInt sourceStartOffset = aUpdateRect.iTl.iX;
60 source += sourceStartOffset;
62 T* targetPtr = reinterpret_cast<T*>(aTarget);
64 const TInt scanLineWidth = iDsa.SwSize().iWidth;
66 targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * scanLineWidth;
67 const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX);
69 targetPtr += targetStartOffset;
72 const TInt height = aUpdateRect.Height();
74 const TInt lineMove = iDsa.IsTurn() ? 1 : lineWidth;
75 const TInt copyLen = aUpdateRect.Width();
81 targetPtr += scanLineWidth * (height - 1);
83 for(TInt i = 0; i < height; i++) //source is always smaller
85 iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
87 targetPtr -= scanLineWidth;
94 for(TInt i = 0; i < height; i++) //source is always smaller
96 iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);
98 targetPtr += scanLineWidth; // >> 2;
106 NONSHARABLE_CLASS(CDsaA) : public CDsa
109 CDsaA(RWsSession& aSession);
112 TUint8* LockSurface();
113 void UnlockHWSurfaceRequestComplete();
114 void UnlockHwSurface();
115 void CreateSurfaceL();
116 void Wipe(TInt aLength);
118 void Update(CFbsBitmap& aBmp);
119 void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
120 TInt ExternalUpdate();
121 // void ExternalUpdate();
124 CFbsBitmap* iCopyBmp;
128 CDsaA::CDsaA(RWsSession& aSession) : CDsa(aSession)
141 __ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady));
145 TUint8* CDsaA::LockSurface()
148 return reinterpret_cast<TUint8*>(iBmp->DataAddress());
151 void CDsaA::UnlockHWSurfaceRequestComplete()
153 PANIC(KErrNotSupported);
156 void CDsaA::UnlockHwSurface()
163 void CDsaA::Update(CFbsBitmap& aBmp)
167 if(SwSize() == HwRect().Size())
168 Dsa().Gc()->BitBlt(HwRect().iTl, &aBmp);
170 Dsa().Gc()->DrawBitmap(HwRect(), &aBmp);
173 Dsa().ScreenDevice()->Update();
175 void CDsaA::CreateSurfaceL()
179 iBmp = new (ELeave) CFbsBitmap();
180 User::LeaveIfError(iBmp->Create(SwSize(), DisplayMode()));
183 void CDsaA::Wipe(TInt aLength) //dont call in drawing
186 Mem::FillZ(iBmp->DataAddress(), aLength);
192 TInt CDsaA::ExternalUpdate()
194 if(iCopyBmp->Handle() == 0)
196 const TInt err = iCopyBmp->Duplicate(iBmp->Handle());
204 void CDsaA::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
206 iCopyBmp = new (ELeave) CFbsBitmap();
207 CDsa::ConstructL(aWindow, aDevice);
211 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
213 NONSHARABLE_CLASS(MDsbObs)
216 virtual void SurfaceReady() = 0;
217 virtual CDirectScreenBitmap& Dsb() = 0;
220 NONSHARABLE_CLASS(CDsbSurface) : public CActive
223 CDsbSurface(MDsbObs& aDsb);
235 CDsbSurface::CDsbSurface(MDsbObs& aDsb) : CActive(CActive::EPriorityHigh) , iDsb(aDsb)
237 CActiveScheduler::Add(this);
240 CDsbSurface::~CDsbSurface()
245 void CDsbSurface::Complete()
247 if(iAddress != NULL && !IsActive())
251 iDsb.Dsb().EndUpdate(iStatus);
255 TUint8* CDsbSurface::Address()
257 if(iAddress == NULL && !IsActive())
259 TAcceleratedBitmapInfo info;
260 if(KErrNone == iDsb.Dsb().BeginUpdate(info))
261 iAddress = info.iAddress;
266 void CDsbSurface::RunL()
271 void CDsbSurface::DoCancel()
276 NONSHARABLE_CLASS(CDsaB) : public CDsa, public MDsbObs
279 CDsaB(RWsSession& aSession, TInt aFlags);
282 TUint8* LockSurface();
283 void UnlockHWSurfaceRequestComplete();
284 void UnlockHwSurface();
285 void CreateSurfaceL();
286 void Wipe(TInt aLength);
288 void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);
289 CDirectScreenBitmap& Dsb();
291 TInt ExternalUpdate();
293 CDsbSurface* iSurface1;
294 CDsbSurface* iSurface2;
295 CDirectScreenBitmap* iDsb;
299 CDsaB::CDsaB(RWsSession& aSession, TInt aFlags) : CDsa(aSession), iType(aFlags)
305 void CDsaB::UnlockHWSurfaceRequestComplete()
307 iSurface1->Complete();
308 if(iSurface2 != NULL)
309 iSurface2->Complete();
312 void CDsaB::CreateSurfaceL()
314 __ASSERT_ALWAYS(SwSize() == HwRect().Size(), PANIC(KErrNotSupported));
317 void CDsaB::Wipe(TInt aLength) //dont call in drawing
319 TUint8* addr = LockSurface();
322 Mem::FillZ(addr, aLength);
328 void CDsaB::UnlockHwSurface()
330 EpocSdlEnv::Request(CDsa::ERequestUpdate);
333 TUint8* CDsaB::LockSurface()
335 TUint8* addr = iSurface1->Address();
336 if(addr == NULL && iSurface2 != NULL)
337 addr = iSurface2->Address();
338 SetUpdating(addr == NULL);
342 void CDsaB::SurfaceReady()
347 CDirectScreenBitmap& CDsaB::Dsb()
352 void CDsaB::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
355 iDsb = CDirectScreenBitmap::NewL();
356 CDsa::ConstructL(aWindow, aDevice);
357 if(iSurface1 == NULL)
358 iSurface1 = new (ELeave) CDsbSurface(*this);
359 if(iSurface2 == NULL && iType & CDirectScreenBitmap::EDoubleBuffer)
360 iSurface2 = new (ELeave) CDsbSurface(*this);
370 void CDsaB::RecreateL()
373 iDsb->Create(HwRect(), CDirectScreenBitmap::TSettingsFlags(iType));
376 TInt CDsaB::ExternalUpdate()
380 UnlockHWSurfaceRequestComplete();
387 /////////////////////////////////////////////////////////////////////////////////////////////////////
390 CDsa* CDsa::CreateL(RWsSession& aSession)
392 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSB))
394 TInt flags = CDirectScreenBitmap::ENone;
395 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBDoubleBuffer))
396 flags |= CDirectScreenBitmap::EDoubleBuffer;
397 if(EpocSdlEnv::Flags(CSDL::EDrawModeDSBIncrentalUpdate))
398 flags |= CDirectScreenBitmap::EIncrementalUpdate;
399 return new (ELeave) CDsaB(aSession, flags);
402 return new (ELeave) CDsaA(aSession);
406 void CDsa::RecreateL()
414 TSize CDsa::WindowSize() const
416 TSize size = iSwSize;
417 if(iStateFlags & EOrientation90)
419 const TInt tmp = size.iWidth;
420 size.iWidth = size.iHeight;
426 void CDsa::SetSuspend()
428 iStateFlags |= ESdlThreadSuspend;
431 void CDsa::ReleaseStop()
433 iStateFlags &= ~ESdlThreadExplicitStop;
437 TBool CDsa::Stopped() const
439 return (iStateFlags & ESdlThreadExplicitStop);
442 void CDsa::SetOrientation(CSDL::TOrientationMode aOrientation)
447 case CSDL::EOrientation90:
448 flags = EOrientation90;
450 case CSDL::EOrientation180:
451 flags = EOrientation180;
453 case CSDL::EOrientation270:
454 flags = EOrientation90 | EOrientation180;
456 case CSDL::EOrientation0:
460 if(flags != (iStateFlags & EOrientationFlags))
462 iStateFlags |= EOrientationChanged;
463 iNewFlags = flags; //cannot be set during drawing...
478 void CDsa::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)
487 iDsa = CDirectScreenAccess::NewL(
494 iLut256 = (TUint32*) User::AllocL(256 * sizeof(TUint32));
495 iTargetMode = aWindow.DisplayMode();
496 iTargetBpp = BytesPerPixel(DisplayMode());
497 iScreenRect = TRect(aWindow.Position(), aWindow.Size());
502 void CDsa::DrawOverlays()
504 const TInt last = iOverlays.Count() - 1;
505 for(TInt i = last; i >= 0 ; i--)
506 iOverlays[i].iOverlay->Draw(*iDsa->Gc(), HwRect(), SwSize());
509 TInt CDsa::AppendOverlay(MOverlay& aOverlay, TInt aPriority)
512 for(i = 0; i < iOverlays.Count() && iOverlays[i].iPriority < aPriority; i++)
514 const TOverlay overlay = {&aOverlay, aPriority};
515 return iOverlays.Insert(overlay, i);
518 TInt CDsa::RemoveOverlay(MOverlay& aOverlay)
520 for(TInt i = 0; i < iOverlays.Count(); i++)
522 if(iOverlays[i].iOverlay == &aOverlay)
531 void CDsa::LockPalette(TBool aLock)
534 iStateFlags |= EPaletteLocked;
536 iStateFlags &= ~EPaletteLocked;
538 TInt CDsa::SetPalette(TInt aFirst, TInt aCount, TUint32* aPalette)
542 const TInt count = aCount - aFirst;
545 if(iStateFlags & EPaletteLocked)
547 for(TInt i = aFirst; i < count; i++) //not so busy here:-)
549 iLut256[i] = aPalette[i];
556 void CDsa::RestartL()
558 //const TBool active = iDsa->IsActive();
564 const RRegion* r = iDsa->DrawingRegion();
565 const TRect rect = r->BoundingRect();
566 iDsa->Gc()->SetClippingRegion(r);
568 if(rect != iScreenRect)
576 //iScreenRect = rect; //to ensure properly set, albeit may not(?) match to value SDL has - therefore may has to clip
577 //targetrect shall no change
581 iStateFlags |= ERunning;
584 if(iStateFlags & ESdlThreadSuspend)
586 EpocSdlEnv::Resume();
587 iStateFlags &= ~ ESdlThreadSuspend;
589 EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved);
592 CDsa::CDsa(RWsSession& aSession) :
596 // CActiveScheduler::Add(this);
597 iCFTable[0] = CopyMem;
598 iCFTable[1] = CopyMemFlipReversed;
599 iCFTable[2] = CopyMemReversed;
600 iCFTable[3] = CopyMemFlip;
602 iCFTable[4] = Copy256;
603 iCFTable[5] = Copy256FlipReversed;
604 iCFTable[6] = Copy256Reversed;
605 iCFTable[7] = Copy256Flip;
608 iCFTable[8] = CopySlow;
609 iCFTable[9] = CopySlowFlipReversed;
610 iCFTable[10] = CopySlowReversed;
611 iCFTable[11] = CopySlowFlip;
614 RWsSession& CDsa::Session()
619 TInt CDsa::RedrawRequest()
621 if(!(iStateFlags & (EUpdating) && (iStateFlags & ERunning)))
623 return ExternalUpdate();
628 TUint8* CDsa::LockHwSurface()
630 if((iStateFlags & EUpdating) == 0) //else frame is skipped
632 return LockSurface();
640 iStateFlags &= ~EUpdating;
644 void CDsa::DoCancel()
646 iStateFlags &= ~EUpdating;
647 //nothing can do, just wait?
652 TInt CDsa::AllocSurface(TBool aHwSurface, const TSize& aSize, TDisplayMode aMode)
654 if(aHwSurface && aMode != DisplayMode())
659 iSourceBpp = BytesPerPixel(aMode);
661 const TSize size = WindowSize();
662 if(aSize.iWidth > size.iWidth)
664 if(aSize.iHeight > size.iHeight)
667 TRAPD(err, CreateSurfaceL());
677 void CDsa::CreateZoomerL(const TSize& aSize)
680 iStateFlags |= EResizeRequest;
687 void SaveBmp(const TDesC& aName, const TAny* aData, TInt aLength, const TSize& aSz, TDisplayMode aMode)
689 CFbsBitmap* s = new CFbsBitmap();
690 s->Create(aSz, aMode);
692 TUint32* addr = s->DataAddress();
693 Mem::Copy(addr, aData, aLength);
700 void SaveBmp(const TDesC& aName, const TUint32* aData, const TSize& aSz)
702 CFbsBitmap* s = new CFbsBitmap();
703 s->Create(aSz, EColor64K);
705 bmp.Begin(TPoint(0, 0));
706 for(TInt j = 0; j < aSz.iHeight; j++)
708 bmp.SetPos(TPoint(0, j));
709 for(TInt i = 0; i < aSz.iWidth; i++)
711 bmp.SetPixel(*aData);
722 TBuf<16> FooName(TInt aFoo)
725 b.Format(_L("C:\\pic%d.mbm"), aFoo);
729 void ClipCopy(TUint8* aTarget, const TUint8* aSource, const TRect& aRect, const TPoint& aTargetPos)
731 const TInt iSourceBpp = 1;
732 const TInt iTargetBpp = 4;
733 const TInt iScanLineWidth = 800;
735 TUint8* target = aTarget;
736 const TUint8* source = aSource;
737 const TInt lineWidth = aRect.Width();
738 source += iSourceBpp * (aRect.iTl.iY * lineWidth);
739 const TInt sourceStartOffset = iSourceBpp * aRect.iTl.iX;
740 source += sourceStartOffset;
741 target += iTargetBpp * ((aTargetPos.iY + aRect.iTl.iY ) * lineWidth);
742 const TInt targetStartOffset = iTargetBpp * (aRect.iTl.iX + aTargetPos.iX);
743 target += targetStartOffset;
744 TUint32* targetPtr = reinterpret_cast<TUint32*>(target);
745 const TInt targetWidth = iScanLineWidth >> 2;
746 const TInt height = aRect.Height();
750 void CDsa::ClipCopy(TUint8* aTarget,
751 const TUint8* aSource,
752 const TRect& aUpdateRect,
753 const TRect& aSourceRect) const
755 //TUint8* target = aTarget;
756 const TUint32* source = (const TUint32*) aSource;
757 const TInt lineWidth = aSourceRect.Width();
759 source += (aUpdateRect.iTl.iY * lineWidth);
760 const TInt sourceStartOffset = aUpdateRect.iTl.iX;
761 source += sourceStartOffset;
763 TUint32* targetPtr = reinterpret_cast<TUint32*>(aTarget);
765 targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * SwSize().iWidth;
766 const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX);
768 targetPtr += targetStartOffset;
770 // TUint32* targetPtr = reinterpret_cast<TUint32*>(target);
772 const TInt targetWidth32 = SwSize().iWidth;
774 const TInt height = aUpdateRect.Height();
776 const TInt lineMove = iStateFlags & EOrientation90 ? 1 : lineWidth;
777 const TInt copyLen = aUpdateRect.Width();
780 if(iStateFlags & EOrientation180)
783 targetPtr += targetWidth32 * (height - 1);
785 for(TInt i = 0; i < height; i++) //source is always smaller
787 iCopyFunction(*this, targetPtr, (TUint8*)source, copyLen, height);
789 targetPtr -= targetWidth32;
796 for(TInt i = 0; i < height; i++) //source is always smaller
798 iCopyFunction(*this, targetPtr, (TUint8*)source, copyLen, height);
800 targetPtr += targetWidth32; // >> 2;
808 void CDsa::ClipCopy(TUint8* aTarget, const TUint8* aSource, const TRect& aRect, const TPoint& aTargetPos) const
810 TUint8* target = aTarget;
811 const TUint8* source = aSource;
812 const TInt lineWidth = aRect.Width();
813 source += iSourceBpp * (aRect.iTl.iY * lineWidth);
814 TInt sourceStartOffset = iSourceBpp * aRect.iTl.iX;
815 source += sourceStartOffset;
816 target += iTargetBpp * ((aTargetPos.iY + aRect.iTl.iY ) * lineWidth);
817 TInt targetStartOffset = iTargetBpp * (aRect.iTl.iX + aTargetPos.iX);
818 target += targetStartOffset;
819 TUint32* targetPtr = reinterpret_cast<TUint32*>(target);
820 const TInt targetWidth = iScanLineWidth >> 2;
821 const TInt height = aRect.Height();
823 TInt lineMove = iStateFlags & EOrientation90 ? 1 : lineWidth;
825 if(iStateFlags & EOrientation180)
828 targetPtr += targetWidth * (height - 1);
830 for(TInt i = 0; i < height; i++) //source is always smaller
832 iCopyFunction(*this, targetPtr, source, lineWidth, height);
834 targetPtr -= targetWidth;
841 for(TInt i = 0; i < height; i++) //source is always smaller
843 iCopyFunction(*this, targetPtr, source, lineWidth, height);
845 targetPtr += targetWidth;
854 void CDsa::ClipCopy(TUint8* aTarget,
855 const TUint8* aSource,
856 const TRect& aUpdateRect,
857 const TRect& aSourceRect) const
859 const TDsa dsa(*this);
863 ::ClipCopy<TUint32, TUint8>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
866 ::ClipCopy<TUint32, TUint16>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
869 ::ClipCopy<TUint32, TUint32>(dsa, aTarget, aSource, aUpdateRect, aSourceRect);
879 void CDsa::Wipe() //dont call in drawing
882 Wipe(iTargetBpp * SwSize().iWidth * SwSize().iHeight);
885 void CDsa::SetCopyFunction()
887 //calculate offset to correct function in iCFTable according to given parameters
889 const TInt KCopyFunctions = 4;
890 const TInt KOffsetToNative = 0;
891 const TInt KOffsetTo256 = KOffsetToNative + KCopyFunctions;
892 const TInt KOffsetToOtherModes = KOffsetTo256 + KCopyFunctions;
893 const TInt KOffsetTo90Functions = 1;
894 const TInt KOffsetTo180Functions = 2;
896 if(iSourceMode == DisplayMode())
897 function = KOffsetToNative; //0
898 else if(iSourceMode == EColor256)
899 function = KOffsetTo256; //4
901 function = KOffsetToOtherModes; //8
903 if(iStateFlags & EOrientation90)
904 function += KOffsetTo90Functions; // + 1
905 if(iStateFlags & EOrientation180)
906 function += KOffsetTo180Functions; //+ 2
908 iCopyFunction = iCFTable[function];
913 inline void Rotate(TRect& aRect)
915 const TInt dx = aRect.iBr.iX - aRect.iTl.iX;
916 const TInt dy = aRect.iBr.iY - aRect.iTl.iY;
918 aRect.iBr.iX = aRect.iTl.iX + dy;
919 aRect.iBr.iY = aRect.iTl.iY + dx;
921 const TInt tmp = aRect.iTl.iX;
922 aRect.iTl.iX = aRect.iTl.iY;
930 TBool CDsa::AddUpdateRect(const TUint8* aBits, const TRect& aUpdateRect, const TRect& aRect)
933 if(iStateFlags & EOrientationChanged)
935 iStateFlags &= ~EOrientationFlags;
936 iStateFlags |= iNewFlags;
938 iStateFlags &= ~EOrientationChanged;
939 EpocSdlEnv::WaitDeviceChange();
940 return EFalse; //skip this frame as data is may be changed
943 if(iTargetAddr == NULL)
945 iTargetAddr = LockHwSurface();
948 TUint8* target = iTargetAddr;
953 TRect targetRect = TRect(TPoint(0, 0), SwSize());
955 TRect sourceRect = aRect;
956 TRect updateRect = aUpdateRect;
958 // TPoint move(0, 0);
961 if(iStateFlags & EOrientation90)
967 if(iSourceMode != DisplayMode() || targetRect != sourceRect || targetRect != updateRect || ((iStateFlags & EOrientationFlags) != 0))
969 sourceRect.Intersection(targetRect); //so source always smaller or equal than target
970 //updateRect.Intersection(targetRect);
971 ClipCopy(target, aBits, updateRect, sourceRect);
975 const TInt byteCount = aRect.Width() * aRect.Height() * iSourceBpp; //this could be stored
976 Mem::Copy(target, aBits, byteCount);
983 TBool CDsa::AddUpdateRect(const TUint8* aBits, const TRect& aUpdateRect, const TRect& aRect)
986 if(iStateFlags & EOrientationChanged)
988 iStateFlags &= ~EOrientationFlags;
989 iStateFlags |= iNewFlags;
991 iStateFlags &= ~EOrientationChanged;
992 EpocSdlEnv::WaitDeviceChange();
993 return EFalse; //skip this frame as data is may be changed
996 if(iTargetAddr == NULL)
998 iTargetAddr = LockHwSurface();
1000 TUint8* target = iTargetAddr;
1005 TRect targetRect = Rect();
1006 TRect sourceRect = aRect;
1007 TRect updateRect = aUpdateRect;
1009 if(iStateFlags & EOrientation90)
1015 if(iSourceMode != DisplayMode() || targetRect != sourceRect || targetRect != updateRect || ((iStateFlags & EOrientationFlags) != 0))
1017 sourceRect.Intersection(targetRect); //so source always smaller or equal than target
1018 updateRect.Intersection(targetRect);
1019 ClipCopy(target, aBits, updateRect, sourceRect.iTl);
1023 const TInt byteCount = aRect.Width() * aRect.Height() * iSourceBpp; //this could be stored
1024 Mem::Copy(target, aBits, byteCount);
1029 void CDsa::UpdateSwSurface()
1032 UnlockHwSurface(); //could be faster if does not use AO, but only check status before redraw, then no context switch needed
1039 Restart(RDirectScreenAccess::ETerminateRegion);
1044 if(IsDsaAvailable())
1045 iStateFlags |= ESdlThreadExplicitStop;
1051 iStateFlags &= ~ERunning;
1052 // Cancel(); //can be called only from main!
1056 void CDsa::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
1058 // iStateFlags |= EChangeNotify;
1062 void CDsa::Restart(RDirectScreenAccess::TTerminationReasons aReason)
1064 if(aReason == RDirectScreenAccess::ETerminateRegion) //auto restart
1066 TRAPD(err, RestartL());
1067 PANIC_IF_ERROR(err);
1071 void CDsa::SetBlitter(MBlitter* aBlitter)
1073 iBlitter = aBlitter;
1077 TPoint CDsa::WindowCoordinates(const TPoint& aPoint) const
1079 TPoint pos = aPoint - iScreenRect.iTl;
1080 const TSize asz = iScreenRect.Size();
1081 if(iStateFlags & EOrientation180)
1083 pos.iX = asz.iWidth - pos.iX;
1084 pos.iY = asz.iHeight - pos.iY;
1086 if(iStateFlags & EOrientation90)
1093 pos.iX /= asz.iWidth;
1094 pos.iY /= asz.iHeight;
1095 pos.iX *= iSwSize.iWidth;
1096 pos.iY *= iSwSize.iHeight;
1102 void CDsa::SetTargetRect()
1104 iTargetRect = iScreenRect;
1105 if(iStateFlags & EResizeRequest && EpocSdlEnv::Flags(CSDL::EAllowImageResizeKeepRatio))
1107 const TSize asz = iScreenRect.Size();
1108 const TSize sz = iSwSize;
1112 const TInt dh = (sz.iHeight << 16) / sz.iWidth;
1114 if((asz.iWidth * dh ) >> 16 <= asz.iHeight)
1116 rect.SetRect(TPoint(0, 0), TSize(asz.iWidth, (asz.iWidth * dh) >> 16));
1120 const TInt dw = (sz.iWidth << 16) / sz.iHeight;
1121 rect.SetRect(TPoint(0, 0), TSize((asz.iHeight * dw) >> 16, asz.iHeight));
1123 rect.Move((asz.iWidth - rect.Size().iWidth) >> 1, (asz.iHeight - rect.Size().iHeight) >> 1);
1126 iTargetRect.Move(iScreenRect.iTl);
1129 if(!(iStateFlags & EResizeRequest))
1130 iSwSize = iScreenRect.Size();
1131 // iScanLineWidth = /*iTargetBpp **/ SwSize().iWidth;
1135 TBool CDsa::ChangeTrigger()
1137 const TBool change = iStateFlags & EChangeNotify;
1138 iStateFlags &= ~EChangeNotify;
1142 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1144 void CDsa::Copy256(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1146 TUint32* target = aTarget;
1147 const TUint32* endt = target + aBytes;
1148 const TUint8* source = aSource;
1149 while(target < endt)
1151 *target++ = aDsa.iLut256[*source++];
1155 void CDsa::Copy256Reversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1157 const TUint32* target = aTarget;
1158 TUint32* endt = aTarget + aBytes;
1159 const TUint8* source = aSource;
1160 while(target < endt)
1162 *(--endt) = aDsa.iLut256[*source++];
1166 void CDsa::Copy256Flip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1168 TUint32* target = aTarget;
1169 const TUint32* endt = target + aBytes;
1170 const TUint8* column = aSource;
1172 while(target < endt)
1174 *target++ = aDsa.iLut256[*column];
1179 void CDsa::Copy256FlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1181 const TUint32* target = aTarget;
1182 TUint32* endt = aTarget + aBytes;
1183 const TUint8* column = aSource;
1185 while(target < endt)
1187 *(--endt) = aDsa.iLut256[*column];
1192 void CDsa::CopyMem(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1194 const TUint32* src = reinterpret_cast<const TUint32*>(aSource);
1195 Mem::Copy(aTarget, src, aBytes << 2);
1198 void CDsa::CopyMemFlip(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1200 TUint32* target = aTarget;
1201 const TUint32* endt = target + aBytes;
1202 const TUint32* column = reinterpret_cast<const TUint32*>(aSource);
1204 while(target < endt)
1206 *target++ = *column;
1211 void CDsa::CopyMemReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1213 const TUint32* target = aTarget;
1214 TUint32* endt = aTarget + aBytes;
1215 const TUint32* source = reinterpret_cast<const TUint32*>(aSource);
1216 while(target < endt)
1218 *(--endt) = *source++;
1223 void CDsa::CopyMemFlipReversed(const CDsa& /*aDsa*/, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1225 const TUint32* target = aTarget;
1226 TUint32* endt = aTarget + aBytes;
1227 const TUint32* column = reinterpret_cast<const TUint32*>(aSource);
1229 while(target < endt)
1231 *(--endt) = *column;
1238 LOCAL_C TRgb rgb16MA(TInt aValue)
1240 return TRgb::Color16MA(aValue);
1243 NONSHARABLE_CLASS(MRgbCopy)
1246 virtual void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed) = 0;
1247 virtual void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed) = 0;
1251 NONSHARABLE_CLASS(TRgbCopy) : public MRgbCopy
1254 TRgbCopy(TDisplayMode aMode);
1255 void* operator new(TUint aBytes, TAny* aMem);
1256 void Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed);
1257 void FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed);
1258 static TUint32 Gray256(const TUint8& aPixel);
1259 static TUint32 Color256(const TUint8& aPixel);
1260 static TUint32 Color4K(const TUint16& aPixel);
1261 static TUint32 Color64K(const TUint16& aPixel);
1262 static TUint32 Color16M(const TUint32& aPixel);
1263 static TUint32 Color16MU(const TUint32& aPixel);
1264 static TUint32 Color16MA(const TUint32& aPixel);
1266 typedef TUint32 (*TRgbFunc) (const T& aValue);
1272 void* TRgbCopy<T>::operator new(TUint /*aBytes*/, TAny* aMem)
1278 TRgbCopy<T>::TRgbCopy(TDisplayMode aMode)
1282 case EGray256 : iFunc = (TRgbFunc) Gray256; break;
1283 case EColor256 : iFunc = (TRgbFunc) Color256; break;
1284 case EColor4K : iFunc = (TRgbFunc) Color4K; break;
1285 case EColor64K : iFunc = (TRgbFunc) Color64K; break;
1286 case EColor16M : iFunc = (TRgbFunc) Color16M; break;
1287 case EColor16MU : iFunc = (TRgbFunc) Color16MU; break;
1288 case EColor16MA : iFunc = (TRgbFunc) Color16MA; break;
1290 PANIC(KErrNotSupported);
1295 void TRgbCopy<T>::Copy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TBool aReversed)
1297 const T* source = reinterpret_cast<const T*>(aSource);
1298 TUint32* target = aTarget;
1299 TUint32* endt = target + aBytes;
1303 while(target < endt)
1305 const T value = *source++;
1306 *(--endt) = iFunc(value);//iFunc(value).Value();
1311 while(target < endt)
1313 const T value = *source++;
1314 *target++ = iFunc(value);//iFunc(value).Value();
1320 void TRgbCopy<T>::FlipCopy(TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen, TBool aReversed)
1322 const T* column = reinterpret_cast<const T*>(aSource);
1323 TUint32* target = aTarget;
1324 TUint32* endt = target + aBytes;
1328 while(target < endt)
1330 *(--endt) = iFunc(*column);
1336 while(target < endt)
1338 *target++ = iFunc(*column);
1344 template <class T> TUint32 TRgbCopy<T>::Gray256(const TUint8& aPixel)
1346 const TUint32 px = aPixel << 16 | aPixel << 8 | aPixel;
1350 template <class T> TUint32 TRgbCopy<T>::Color256(const TUint8& aPixel)
1352 return TRgb::Color256(aPixel).Value();
1355 template <class T> TUint32 TRgbCopy<T>::Color4K(const TUint16& aPixel)
1357 TUint32 col = (aPixel & 0xF00) << 12;
1358 col |= (aPixel & 0xF00) << 8;
1360 col |= (aPixel & 0x0F0) << 8;
1361 col |= (aPixel & 0x0F0);
1363 col |= (aPixel & 0x00F) << 4;
1364 col |= (aPixel & 0x00F);
1369 template <class T> TUint32 TRgbCopy<T>::Color64K(const TUint16& aPixel)
1371 TUint32 col = (aPixel & 0xF800)<< 8;
1372 col |= (aPixel & 0xE000) << 3;
1374 col |= (aPixel & 0x07E0) << 5;
1375 col |= (aPixel & 0xC0) >> 1;
1377 col |= (aPixel & 0x07E0) << 3;
1378 col |= (aPixel & 0x1C) >> 2;
1383 template <class T> TUint32 TRgbCopy<T>::Color16M(const TUint32& aPixel)
1385 return TRgb::Color16M(aPixel).Value();
1388 template <class T> TUint32 TRgbCopy<T>::Color16MU(const TUint32& aPixel)
1390 return TRgb::Color16MU(aPixel).Value();
1393 template <class T> TUint32 TRgbCopy<T>::Color16MA(const TUint32& aPixel)
1395 return TRgb::Color16MA(aPixel).Value();
1398 typedef TUint64 TStackMem;
1400 LOCAL_C MRgbCopy* GetCopy(TAny* mem, TDisplayMode aMode)
1402 if(aMode == EColor256 || aMode == EGray256)
1404 return new (mem) TRgbCopy<TUint8>(aMode);
1406 if(aMode == EColor4K || aMode == EColor64K)
1408 return new (mem) TRgbCopy<TUint16>(aMode);
1410 if(aMode == EColor16M || aMode == EColor16MU || aMode == EColor16MA)
1412 return new (mem) TRgbCopy<TUint32>(aMode);
1414 PANIC(KErrNotSupported);
1419 void CDsa::CopySlowFlipReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1422 GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, ETrue);
1425 void CDsa::CopySlowFlip(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt aLineLen)
1428 GetCopy(&mem, aDsa.iSourceMode)->FlipCopy(aTarget, aSource, aBytes, aLineLen, EFalse);
1431 void CDsa::CopySlow(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1434 GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, EFalse);
1437 void CDsa::CopySlowReversed(const CDsa& aDsa, TUint32* aTarget, const TUint8* aSource, TInt aBytes, TInt)
1440 GetCopy(&mem, aDsa.iSourceMode)->Copy(aTarget, aSource, aBytes, ETrue);
1443 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////7