18 #include <graphics/wsrenderstage.h> |
18 #include <graphics/wsrenderstage.h> |
19 #include <s32mem.h> |
19 #include <s32mem.h> |
20 #include <AknIconHeader.h> |
20 #include <AknIconHeader.h> |
21 #include <AknIconUtils.h> |
21 #include <AknIconUtils.h> |
22 |
22 |
|
23 TCachedConversion::TCachedConversion() : |
|
24 iLink(), iCachedResult(NULL) |
|
25 {} |
|
26 |
|
27 TCachedConversion::~TCachedConversion() |
|
28 { |
|
29 delete iCachedResult; |
|
30 } |
23 |
31 |
24 const TUid KUidNvgExtendedBitmap = {0x39b9273e}; |
32 const TUid KUidNvgExtendedBitmap = {0x39b9273e}; |
25 |
33 |
26 CNvgRenderStage::CNvgRenderStage() : |
34 CNvgRenderStage::CNvgRenderStage() : |
27 iExtendedBitmapError(KErrNone) |
35 iExtendedBitmapError(KErrNone), |
|
36 iCache(_FOFF(TCachedConversion,iLink)), |
|
37 iCacheIterator(iCache), |
|
38 iCacheFree(MAX_NVG_CACHE_SIZE) |
28 { |
39 { |
29 } |
40 } |
30 |
41 |
31 /** Called by CNvgRenderStageFactory::CreateRenderStageL() and |
42 /** Called by CNvgRenderStageFactory::CreateRenderStageL() and |
32 CNvgRenderStageFactory::CreateFinalRenderStageL() when a new render stage |
43 CNvgRenderStageFactory::CreateFinalRenderStageL() when a new render stage |
154 */ |
169 */ |
155 void CNvgRenderStage::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap) |
170 void CNvgRenderStage::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap) |
156 { |
171 { |
157 if (iGc) |
172 if (iGc) |
158 { |
173 { |
|
174 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
|
175 |
159 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
176 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
160 { |
177 { |
161 TRect destRect(TPoint(aDestPos.iX,aDestPos.iY), aSourceBitmap.SizeInPixels()); |
178 sourceBitmap = GetConvertedBitmap(aSourceBitmap); |
162 DrawExtendedBitmap(*iGc, destRect, aSourceBitmap); |
|
163 } |
179 } |
164 else |
180 |
165 { |
181 iGc->BitBlt(aDestPos, *sourceBitmap); |
166 iGc->BitBlt(aDestPos, aSourceBitmap); |
|
167 } |
|
168 } |
182 } |
169 } |
183 } |
170 |
184 |
171 /** If the passed bitmap is an extended bitmap of type 0x39b9273e, draw it to the |
185 /** If the passed bitmap is an extended bitmap of type 0x39b9273e, draw it to the |
172 stored graphics context of the next render stage using DrawExtendedBitmap(), if the |
186 stored graphics context of the next render stage using DrawExtendedBitmap(), if the |
176 */ |
190 */ |
177 void CNvgRenderStage::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) |
191 void CNvgRenderStage::BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect) |
178 { |
192 { |
179 if (iGc) |
193 if (iGc) |
180 { |
194 { |
|
195 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
|
196 |
181 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
197 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
182 { |
198 { |
183 TRect destRect(TPoint(aDestPos.iX,aDestPos.iY), aSourceRect.Size()); |
199 sourceBitmap = GetConvertedBitmap(aSourceBitmap); |
184 DrawExtendedBitmap(*iGc, destRect, aSourceBitmap); |
|
185 } |
200 } |
186 else |
201 |
187 { |
202 iGc->BitBlt(aDestPos, *sourceBitmap, aSourceRect); |
188 iGc->BitBlt(aDestPos, aSourceBitmap, aSourceRect); |
|
189 } |
|
190 } |
203 } |
191 } |
204 } |
192 |
205 |
193 /** If either of the passed bitmaps is an extended bitmap of type 0x39b9273e convert |
206 /** If either of the passed bitmaps is an extended bitmap of type 0x39b9273e convert |
194 to a normal bitmap before passing to the next render stage, otherwise |
207 to a normal bitmap before passing to the next render stage, otherwise |
203 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
216 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
204 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
217 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
205 |
218 |
206 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
219 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
207 { |
220 { |
208 CopyExtendedBitmapToNormalBitmap(aSourceBitmap, *iBmp); |
221 sourceBitmap = GetConvertedBitmap(aSourceBitmap); |
209 sourceBitmap = iBmp; |
|
210 } |
222 } |
211 |
223 |
212 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
224 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
213 { |
225 { |
214 CopyExtendedBitmapToNormalBitmap(aMaskBitmap, *iMaskBmp); |
226 maskBitmap = GetConvertedBitmap(aMaskBitmap); |
215 maskBitmap = iMaskBmp; |
|
216 } |
227 } |
217 |
228 |
218 iGc->BitBltMasked(aDestPos, *sourceBitmap, aSourceRect, *maskBitmap, aInvertMask); |
229 iGc->BitBltMasked(aDestPos, *sourceBitmap, aSourceRect, *maskBitmap, aInvertMask); |
219 } |
230 } |
220 } |
231 } |
232 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
243 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
233 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
244 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
234 |
245 |
235 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
246 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
236 { |
247 { |
237 CopyExtendedBitmapToNormalBitmap(aSourceBitmap, *iBmp); |
248 sourceBitmap = GetConvertedBitmap(aSourceBitmap); |
238 sourceBitmap = iBmp; |
|
239 } |
249 } |
240 |
250 |
241 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
251 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
242 { |
252 { |
243 CopyExtendedBitmapToNormalBitmap(aMaskBitmap, *iMaskBmp); |
253 maskBitmap = GetConvertedBitmap(aMaskBitmap); |
244 maskBitmap = iMaskBmp; |
|
245 } |
254 } |
246 |
255 |
247 iGc->BitBltMasked(aDestPos, *sourceBitmap, aSourceRect, *maskBitmap, aMaskPos); |
256 iGc->BitBltMasked(aDestPos, *sourceBitmap, aSourceRect, *maskBitmap, aMaskPos); |
248 } |
257 } |
249 } |
258 } |
375 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
382 CFbsBitmap* sourceBitmap = const_cast<CFbsBitmap*>(&aSourceBitmap); |
376 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
383 CFbsBitmap* maskBitmap = const_cast<CFbsBitmap*>(&aMaskBitmap); |
377 |
384 |
378 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
385 if (aSourceBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
379 { |
386 { |
380 CopyExtendedBitmapToNormalBitmap(aSourceBitmap, *iBmp); |
387 sourceBitmap = GetConvertedBitmap(aSourceBitmap); |
381 sourceBitmap = iBmp; |
|
382 } |
388 } |
383 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
389 if (aMaskBitmap.ExtendedBitmapType() == KUidNvgExtendedBitmap) |
384 { |
390 { |
385 CopyExtendedBitmapToNormalBitmap(aMaskBitmap, *iMaskBmp); |
391 maskBitmap = GetConvertedBitmap(aMaskBitmap); |
386 maskBitmap = iMaskBmp; |
|
387 } |
392 } |
388 |
393 |
389 iGc->DrawBitmapMasked(aDestRect, *sourceBitmap, aSourceRect, *maskBitmap, aInvertMask); |
394 iGc->DrawBitmapMasked(aDestRect, *sourceBitmap, aSourceRect, *maskBitmap, aInvertMask); |
390 } |
395 } |
391 } |
396 } |
982 { |
987 { |
983 iGc->Pop(); |
988 iGc->Pop(); |
984 } |
989 } |
985 } |
990 } |
986 |
991 |
987 /** Helper method used by BitBlt() and DrawBitmap() |
992 |
988 |
993 /** Helper method that draws an NVG extended bitmap into a normal bitmap. |
989 @param aGc The graphics context to draw the extended bitmap to. |
994 |
990 @param aDestRect The rectangle that the source bitmap will be drawn to. |
995 @param aExtendedBitmapSrc The extended bitmap to draw |
991 @param aSourceBitmap The extended bitmap of type 0x39b9273e to be drawn. |
996 |
992 |
997 @pre aExtendedBitmapSrc must be an extended bitmap of extended bitmap type 0x39b9273e |
993 @pre aSourceBitmap must be an extended bitmap of type 0x39b9273e. |
998 */ |
994 @post Sets an error that can be retrieved using GetError() is an error occurs. |
999 |
995 */ |
1000 CFbsBitmap* CNvgRenderStage::GetConvertedBitmap(const CFbsBitmap& aExtendedBitmapSrc) |
996 void CNvgRenderStage::DrawExtendedBitmap(MWsGraphicsContext& aGc, const TRect& aDestRect, const CFbsBitmap& aSourceBitmap) |
1001 { |
997 { |
1002 aExtendedBitmapSrc.BeginDataAccess(); |
998 CopyExtendedBitmapToNormalBitmap(aSourceBitmap, *iBmp); |
1003 const TUint8* bmpData = (const TUint8*)aExtendedBitmapSrc.DataAddress(); |
999 aGc.BitBlt(aDestRect.iTl, *iBmp); |
1004 |
1000 } |
1005 TPtr8 IconHeaderPtr((TUint8*)bmpData, KIconHeaderLength, KIconHeaderLength); |
1001 |
1006 TAknIconHeader iconheader(IconHeaderPtr); |
1002 /** Helper method used by BitBlt() and DrawBitmap() |
1007 |
1003 |
1008 TUint32 bitmapid = iconheader.GetBitmapId(); |
1004 @param aGc The graphics context to draw the extended bitmap to. |
1009 TUint32 handle = aExtendedBitmapSrc.Handle(); |
1005 @param aDestRect The rectangle that the source bitmap will be drawn to. |
1010 aExtendedBitmapSrc.EndDataAccess(); |
1006 @param aSourceBitmap The extended bitmap of type 0x39b9273e to be drawn. |
1011 CFbsBitmap* error = const_cast<CFbsBitmap*>(&aExtendedBitmapSrc); // not renderable, but better than panic! |
1007 |
1012 |
1008 @pre aSourceBitmap must be an extended bitmap of type 0x39b9273e. |
1013 // look to see if we have this in the cache |
1009 @post Sets an error that can be retrieved using GetError() is an error occurs. |
1014 iCacheIterator.SetToFirst(); |
1010 */ |
1015 TCachedConversion* cached = iCacheIterator++; |
1011 void CNvgRenderStage::DrawExtendedBitmap(CFbsBitGc& aGc, const TRect& aDestRect, const CFbsBitmap& aSourceBitmap) |
1016 while (cached != NULL) |
1012 { |
1017 { |
1013 CopyExtendedBitmapToNormalBitmap(aSourceBitmap, *iBmp); |
1018 if (cached->iBitmapID == bitmapid && cached->iDiscriminator == handle) |
1014 aGc.BitBlt(aDestRect.iTl, iBmp); |
1019 { |
1015 } |
1020 // Cache hit |
1016 |
1021 #ifdef DEBUG_NVG_RENDERSTAGE |
|
1022 RDebug::Printf("NVG Render cache hit for id %08x, handle %d\n", bitmapid, handle); |
|
1023 #endif |
|
1024 cached->Deque(); |
|
1025 iCache.AddFirst(*cached); // move to front of the list, to record use |
|
1026 return cached->iCachedResult; |
|
1027 } |
|
1028 cached = iCacheIterator++; |
|
1029 } |
|
1030 |
|
1031 // missed in the cache, need to perform the conversion |
|
1032 TInt err = KErrNone; |
|
1033 if (iCacheFree > 0) |
|
1034 { |
|
1035 // just allocate a new entry, which will be added to the end |
|
1036 TRAP(err, cached = new(ELeave) TCachedConversion); |
|
1037 if (err != KErrNone) |
|
1038 { |
|
1039 return error; |
|
1040 } |
|
1041 TRAP(err, cached->iCachedResult = new(ELeave) CFbsBitmap); |
|
1042 if (err != KErrNone) |
|
1043 { |
|
1044 delete cached; |
|
1045 return error; |
|
1046 } |
|
1047 } |
|
1048 else |
|
1049 { |
|
1050 // Remove the least recently used item |
|
1051 cached = iCache.Last(); |
|
1052 cached->Deque(); // remove from the cache |
|
1053 iCacheFree++; |
|
1054 #ifdef DEBUG_NVG_RENDERSTAGE |
|
1055 RDebug::Printf("NVG Render cache removing id %08x, handle %d\n", cached->iBitmapID, cached->iDiscriminator); |
|
1056 #endif |
|
1057 } |
|
1058 |
|
1059 // cached is now available to hold the new result |
|
1060 cached->iBitmapID = bitmapid; |
|
1061 cached->iDiscriminator = handle; |
|
1062 |
|
1063 CopyExtendedBitmapToNormalBitmap(aExtendedBitmapSrc, *cached->iCachedResult); |
|
1064 if (iExtendedBitmapError != KErrNone) |
|
1065 { |
|
1066 delete cached; |
|
1067 return error; |
|
1068 } |
|
1069 |
|
1070 // Newly cached bitmap is valid |
|
1071 iCache.AddFirst(*cached); |
|
1072 iCacheFree--; |
|
1073 #ifdef DEBUG_NVG_RENDERSTAGE |
|
1074 RDebug::Printf("NVG Render cache added id %08x, handle %d (%d free)\n", bitmapid, handle, iCacheFree); |
|
1075 #endif |
|
1076 return cached->iCachedResult; |
|
1077 } |
1017 |
1078 |
1018 /** Helper method that draws an NVG extended bitmap into a normal bitmap. The normal |
1079 /** Helper method that draws an NVG extended bitmap into a normal bitmap. The normal |
1019 bitmap passed is resized before the extended bitmap is drawn into it. |
1080 bitmap passed is resized before the extended bitmap is drawn into it. |
1020 |
1081 |
1021 @param aExtendedBitmapSrc The extended bitmap to draw in to the normal bitmap aBitmapDest |
1082 @param aExtendedBitmapSrc The extended bitmap to draw in to the normal bitmap aBitmapDest |
1022 @param aBitmapDest The normal bitmap that the extended bitmap is to be drawn into |
1083 @param aBitmapDest The normal bitmap that the extended bitmap is to be drawn into |
1023 |
1084 |
1024 @pre aExtendedBitmapSrc must be an extended bitmap of extended bitmap type 0x39b9273e |
1085 @pre aExtendedBitmapSrc must be an extended bitmap of extended bitmap type 0x39b9273e |
1025 @post aBitmapDest has been reset and resized and now contains a representation of the aExtendedBitmapSrc |
1086 @post aBitmapDest has been reset and resized and now contains a representation of the aExtendedBitmapSrc |
1026 */ |
1087 */ |
|
1088 |
1027 void CNvgRenderStage::CopyExtendedBitmapToNormalBitmap(const CFbsBitmap& aExtendedBitmapSrc, CFbsBitmap& aBitmapDst) |
1089 void CNvgRenderStage::CopyExtendedBitmapToNormalBitmap(const CFbsBitmap& aExtendedBitmapSrc, CFbsBitmap& aBitmapDst) |
1028 { |
1090 { |
1029 TSize size = aExtendedBitmapSrc.SizeInPixels(); |
1091 TSize size = aExtendedBitmapSrc.SizeInPixels(); |
1030 TInt err = aBitmapDst.Create(size, aExtendedBitmapSrc.DisplayMode()); |
1092 TInt err = aBitmapDst.Create(size, aExtendedBitmapSrc.DisplayMode()); |
1031 if (err != KErrNone) |
1093 if (err != KErrNone) |