2 #include "sdlepocapi.h"
6 static int BytesPerPixel(TDisplayMode aMode
)
8 return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode
) - 1) >> 3) + 1;
12 class CBitmapSurface
: public T
15 CBitmapSurface(RWsSession
& aSession
);
18 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
20 TUint8
* LockSurface();
21 void UnlockHwSurface();
22 void CreateSurfaceL(const TSize
& aSize
);
24 void Update(CFbsBitmap
& aBmp
);
29 void CBitmapSurface
<T
>::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
31 T::ConstructL(aWindow
, aDevice
);
35 CBitmapSurface
<T
>::CBitmapSurface(RWsSession
& aSession
) : T(aSession
)
40 void CBitmapSurface
<T
>::Free()
48 CBitmapSurface
<T
>::~CBitmapSurface()
50 __ASSERT_DEBUG(iBmp
== NULL
, PANIC(KErrNotReady
));
54 TUint8
* CBitmapSurface
<T
>::LockSurface()
57 return reinterpret_cast<TUint8
*>(iBmp
->DataAddress());
61 void CBitmapSurface
<T
>::UnlockHwSurface()
68 void CBitmapSurface
<T
>::Update(CFbsBitmap
& aBmp
)
75 void CBitmapSurface
<T
>::CreateSurfaceL(const TSize
& aSize
)
78 iBmp
= new CFbsBitmap();
79 User::LeaveIfError(iBmp
->Create(aSize
, T::DisplayMode()));
82 //////////////////////////////////////////////////////////////////////
84 class CDsaGles
: public CDsa
87 CDsaGles(RWsSession
& aSession
) : CDsa(aSession
) {}
90 TUint8
* LockSurface() { return NULL
; }
91 void UnlockHwSurface() {}
92 void CreateSurfaceL(const TSize
& aSize
) {}
95 //////////////////////////////////////////////////////////////////////
97 class CDsaBase
: public CDsa
, public MDirectScreenAccess
100 CDsaBase(RWsSession
& aSession
) : CDsa(aSession
) { m_updateWholeScreen
= false; }
102 void ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
);
104 void CompleteUpdate();
105 void DoBlt(CFbsBitmap
& aBmp
);
107 CDirectScreenAccess
* iDsa
;
110 void AbortNow(RDirectScreenAccess::TTerminationReasons aReason
);
111 void Restart(RDirectScreenAccess::TTerminationReasons aReason
);
115 void CDsaBase::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& aDevice
)
117 CDsa::ConstructL(aWindow
, aDevice
);
125 iDsa
= CDirectScreenAccess::NewL(Session(), aDevice
, aWindow
, *this);
129 void CDsaBase::CompleteUpdate()
131 iDsa
->ScreenDevice()->Update();
134 void CDsaBase::DoBlt(CFbsBitmap
& aBmp
)
136 iDsa
->Gc()->BitBlt(TPoint(0, 0), &aBmp
);
139 CDsaBase::~CDsaBase()
148 void CDsaBase::RestartL()
151 iDsa
->Gc()->SetClippingRegion(iDsa
->DrawingRegion());
156 void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons
/*aReason*/)
161 void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons
/*aReason*/)
163 TRAPD(err
, RestartL());
164 if(err
== KLeaveExit
)
174 void CDsaBase::Stop()
180 ///////////////////////////////////////////////////////////////////////
185 inline TDsa(const CDsa
& aDsa
) : iDsa(aDsa
) {}
186 inline void Copy(TUint32
* aTarget
, const TUint8
* aSrc
, int aBytes
) const;
191 inline void TDsa::Copy(TUint32
* aTarget
, const TUint8
* aSrc
, int aBytes
) const
193 iDsa
.iCopyFunction(iDsa
, aTarget
, aSrc
, aBytes
);
196 template<class T
, class S
>
197 void ClipCopy(const TDsa
& iDsa
, TUint8
* aTarget
,
198 const TUint8
* aSource
,
199 const TRect
& aUpdateRect
,
200 const TRect
& aSourceRect
)
202 const S
* source
= reinterpret_cast<const S
*>(aSource
);
203 const int lineWidth
= aSourceRect
.Width();
205 source
+= (aUpdateRect
.iTl
.iY
* lineWidth
);
206 const int sourceStartOffset
= aUpdateRect
.iTl
.iX
;
207 source
+= sourceStartOffset
;
209 T
* targetPtr
= reinterpret_cast<T
*>(aTarget
);
211 const int scanLineWidth
= aSourceRect
.iBr
.iX
;
213 targetPtr
+= aUpdateRect
.iTl
.iY
* scanLineWidth
;
214 const int targetStartOffset
= aUpdateRect
.iTl
.iX
;
216 targetPtr
+= targetStartOffset
;
218 const int height
= aUpdateRect
.Height();
220 const int lineMove
= lineWidth
;
221 const int copyLen
= aUpdateRect
.Width();
223 for(int i
= 0; i
< height
; i
++) //source is always smaller
225 iDsa
.Copy(reinterpret_cast<TUint32
*>(targetPtr
), reinterpret_cast<const TUint8
*>(source
), copyLen
);
227 targetPtr
+= scanLineWidth
;
231 /////////////////////////////////////////////////////////////////////////////////////////////////////
233 CDsa
* CDsa::CreateL(RWsSession
& aSession
)
235 return new CBitmapSurface
<CDsaBase
>(aSession
);
247 void CDsa::ConstructL(RWindow
& aWindow
, CWsScreenDevice
& /*aDevice*/)
250 iLut256
= new TUint32
[256];
251 iTargetMode
= aWindow
.DisplayMode();
252 iTargetBpp
= BytesPerPixel(DisplayMode());
256 void CDsa::DoBlt(CFbsBitmap
& /*aBmp*/)
260 int CDsa::SetPalette(int aFirst
, int aCount
, TUint32
* aPalette
)
264 for(int i
= aFirst
; i
< aFirst
+ aCount
; i
++)
266 iLut256
[i
] = aPalette
[i
];
271 CDsa::CDsa(RWsSession
& aSession
) :
276 iCFTable
[0] = CopyMem
;
277 iCFTable
[1] = Copy256
;
278 iCFTable
[2] = CopySlow
;
281 RWsSession
& CDsa::Session()
286 TUint8
* CDsa::LockHwSurface()
288 return LockSurface();
291 int CDsa::AllocSurface(const TSize
& aSize
, TDisplayMode aMode
)
294 iSourceBpp
= BytesPerPixel(aMode
);
296 TRAPD(err
, CreateSurfaceL(aSize
));
305 void CDsa::ClipCopy(TUint8
* aTarget
,
306 const TUint8
* aSource
,
307 const TRect
& aUpdateRect
,
308 const TRect
& aSourceRect
) const
310 const TDsa
dsa(*this);
314 ::ClipCopy
<TUint32
, TUint8
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
317 ::ClipCopy
<TUint32
, TUint16
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
320 ::ClipCopy
<TUint32
, TUint32
>(dsa
, aTarget
, aSource
, aUpdateRect
, aSourceRect
);
325 void CDsa::SetCopyFunction()
327 if(iSourceMode
== DisplayMode())
328 iCopyFunction
= iCFTable
[0];
329 else if(iSourceMode
== EColor256
)
330 iCopyFunction
= iCFTable
[1];
332 iCopyFunction
= iCFTable
[2];
335 TBool
CDsa::AddUpdateRect(const TUint8
* aBits
, const TRect
& aUpdateRect
, const TRect
& aRect
)
337 if(iTargetAddr
== NULL
)
339 iTargetAddr
= LockHwSurface();
342 TUint8
* target
= iTargetAddr
;
346 TRect sourceRect
= aRect
;
347 TRect updateRect
= aUpdateRect
;
349 if(iSourceMode
!= DisplayMode() || aRect
!= aUpdateRect
)
351 ClipCopy(target
, aBits
, aUpdateRect
, aRect
);
355 const int byteCount
= aRect
.Width() * aRect
.Height() * iSourceBpp
; //this could be stored
356 memcpy(target
, aBits
, byteCount
);
362 void CDsa::UpdateSwSurface()
365 UnlockHwSurface(); //could be faster if does not use AO, but only check status before redraw, then no context switch needed
378 RWindow
* CDsa::Window()
383 CDsa
* CDsa::CreateGlesDsaL()
385 CDsa
* dsa
= new CDsaGles(Session());
386 CWsScreenDevice
* dummy
= NULL
;
387 dsa
->ConstructL(*Window(), *dummy
);
393 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
395 void CDsa::Copy256(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
)
397 TUint32
* target
= aTarget
;
398 const TUint32
* endt
= target
+ aBytes
;
399 const TUint8
* source
= aSource
;
402 *target
++ = aDsa
.iLut256
[*source
++];
406 void CDsa::CopyMem(const CDsa
& /*aDsa*/, TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
)
408 memcpy(aTarget
, aSource
, aBytes
<< 2);
414 virtual void Copy(TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
) = 0;
418 class TRgbCopy
: public MRgbCopy
421 TRgbCopy(TDisplayMode aMode
);
422 void* operator new(TUint aBytes
, void* aMem
);
423 void Copy(TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
);
424 static TUint32
Gray256(const TUint8
& aPixel
);
425 static TUint32
Color256(const TUint8
& aPixel
);
426 static TUint32
Color4K(const TUint16
& aPixel
);
427 static TUint32
Color64K(const TUint16
& aPixel
);
428 static TUint32
Color16M(const TUint32
& aPixel
);
429 static TUint32
Color16MU(const TUint32
& aPixel
);
430 static TUint32
Color16MA(const TUint32
& aPixel
);
432 typedef TUint32 (*TRgbFunc
) (const T
& aValue
);
437 void* TRgbCopy
<T
>::operator new(TUint
/*aBytes*/, void* aMem
)
443 TRgbCopy
<T
>::TRgbCopy(TDisplayMode aMode
)
447 case EGray256
: iFunc
= (TRgbFunc
) Gray256
; break;
448 case EColor256
: iFunc
= (TRgbFunc
) Color256
; break;
449 case EColor4K
: iFunc
= (TRgbFunc
) Color4K
; break;
450 case EColor64K
: iFunc
= (TRgbFunc
) Color64K
; break;
451 case EColor16M
: iFunc
= (TRgbFunc
) Color16M
; break;
452 case EColor16MU
: iFunc
= (TRgbFunc
) Color16MU
; break;
453 case EColor16MA
: iFunc
= (TRgbFunc
) Color16MA
; break;
455 PANIC(KErrNotSupported
);
460 void TRgbCopy
<T
>::Copy(TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
)
462 const T
* source
= reinterpret_cast<const T
*>(aSource
);
463 TUint32
* target
= aTarget
;
464 TUint32
* endt
= target
+ aBytes
;
468 const T value
= *source
++;
469 *target
++ = iFunc(value
);
474 TUint32 TRgbCopy
<T
>::Gray256(const TUint8
& aPixel
)
476 const TUint32 px
= aPixel
<< 16 | aPixel
<< 8 | aPixel
;
481 TUint32 TRgbCopy
<T
>::Color256(const TUint8
& aPixel
)
483 return TRgb::Color256(aPixel
).Value();
487 TUint32 TRgbCopy
<T
>::Color4K(const TUint16
& aPixel
)
489 TUint32 col
= (aPixel
& 0xF00) << 12;
490 col
|= (aPixel
& 0xF00) << 8;
492 col
|= (aPixel
& 0x0F0) << 8;
493 col
|= (aPixel
& 0x0F0);
495 col
|= (aPixel
& 0x00F) << 4;
496 col
|= (aPixel
& 0x00F);
502 TUint32 TRgbCopy
<T
>::Color64K(const TUint16
& aPixel
)
504 TUint32 col
= (aPixel
& 0xF800)<< 8;
505 col
|= (aPixel
& 0xE000) << 3;
507 col
|= (aPixel
& 0x07E0) << 5;
508 col
|= (aPixel
& 0xC0) >> 1;
510 col
|= (aPixel
& 0x07E0) << 3;
511 col
|= (aPixel
& 0x1C) >> 2;
517 TUint32 TRgbCopy
<T
>::Color16M(const TUint32
& aPixel
)
519 return TRgb::Color16M(aPixel
).Value();
523 TUint32 TRgbCopy
<T
>::Color16MU(const TUint32
& aPixel
)
525 return TRgb::Color16MU(aPixel
).Value();
529 TUint32 TRgbCopy
<T
>::Color16MA(const TUint32
& aPixel
)
531 return TRgb::Color16MA(aPixel
).Value();
534 typedef TUint64 TStackMem
;
536 static MRgbCopy
* GetCopy(void* mem
, TDisplayMode aMode
)
538 if(aMode
== EColor256
|| aMode
== EGray256
)
540 return new (mem
) TRgbCopy
<TUint8
>(aMode
);
542 if(aMode
== EColor4K
|| aMode
== EColor64K
)
544 return new (mem
) TRgbCopy
<TUint16
>(aMode
);
546 if(aMode
== EColor16M
|| aMode
== EColor16MU
|| aMode
== EColor16MA
)
548 return new (mem
) TRgbCopy
<TUint32
>(aMode
);
550 PANIC(KErrNotSupported
);
554 void CDsa::CopySlow(const CDsa
& aDsa
, TUint32
* aTarget
, const TUint8
* aSource
, int aBytes
)
557 GetCopy(&mem
, aDsa
.iSourceMode
)->Copy(aTarget
, aSource
, aBytes
);