|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // CWsRedrawMsgWindow and associated classes definitions |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef __REDRAWMSGWINDOW_H__ |
|
19 #define __REDRAWMSGWINDOW_H__ |
|
20 |
|
21 #include "wnredraw.h" |
|
22 #include "redrawmsgwindow.h" |
|
23 |
|
24 class CWsFbsFont; |
|
25 class CWsDrawableSource; |
|
26 |
|
27 // This class is intended to be used in cases, where it's needed to track how many times a CFbsBitmap |
|
28 // is referenced, e.g. in redraws, where already drawn bitmaps need to be re-drawn in different position. |
|
29 class CFbsBitmapRef : public CFbsBitmap |
|
30 { |
|
31 public: |
|
32 CFbsBitmapRef(); |
|
33 ~CFbsBitmapRef(); |
|
34 inline TInt RefCount() const; |
|
35 inline void IncRefCount(); |
|
36 inline void DecRefCount(); |
|
37 private: |
|
38 TInt iRefCount; |
|
39 }; |
|
40 |
|
41 class CWsRedrawMsgWindow : public CWsWindowRedraw |
|
42 { |
|
43 class CRedrawSegment; |
|
44 enum TFlags |
|
45 { |
|
46 EBackgroundClear=0x0001, //Clear background when starting redraw |
|
47 EBeginEndRedraw=0x0002, //This window is currently in the middle of a redraw, that is between client calls to BeginRedraw and EndRedraw. |
|
48 EPendingScheduledDraw=0x0004, //We have scheduled a redraw but it hasn't happened yet |
|
49 EStoringEntireWindow=0x0008, //If store commands for the entire window or only the viewport |
|
50 ECurrentRedrawFailedStorage=0x0010, //The current redraw failed to store a command (is reset for each redraw). Is used to make sure we only request a redraw from the client once per failing redraw |
|
51 EPreviousRedrawFailedStorage=0x0020, //The previous redraw failed to store a command. Is used to avoid infinite loops -- if two consecutive redraws fail (i.e. current and previous) then there is no use requesting yet another redraw from the client |
|
52 }; |
|
53 enum TScope |
|
54 { |
|
55 EStoreEntireWindow, //We try to obtain draw commands for the entire window |
|
56 EStoreViewport //We only try to obtain commands for the on screen viewport |
|
57 }; |
|
58 public: |
|
59 enum TRedrawSegmentType |
|
60 { |
|
61 ESegmentTypePendingRedraw, // A redraw segment still being received |
|
62 ESegmentTypeRedraw // A segment received between a begin and end redraw |
|
63 }; |
|
64 public: |
|
65 static void StaticInitL(); |
|
66 CWsRedrawMsgWindow(CWsWindow *aWin); |
|
67 ~CWsRedrawMsgWindow(); |
|
68 void AddFbsBitmapsL(TInt aHandle, TInt aMaskHandle); |
|
69 void AddFbsBitmapRefL(TInt aHandle); |
|
70 void AddWsBitmapsL(TInt aHandle, TInt aMaskHandle); |
|
71 void AddWsFontL(TInt aHandle); |
|
72 void AddWsDrawableSourceL(TInt aHandle); |
|
73 void SetScope(TScope aStore); |
|
74 void CleanupBitmapRefArray(const RArray<TInt>& aHandleArray); |
|
75 |
|
76 public: //from CWsWindowRedraw |
|
77 void ConstructL(); |
|
78 TBool CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd); |
|
79 void ClipInvalidRegion(const TRect &aRect); |
|
80 TBool NeedsRedraw() const; |
|
81 TBool GetRedrawRect(TRect &aRect) const; |
|
82 const TRegion& BaseDrawRegion() const; |
|
83 const TRegion& InvalidArea() const; |
|
84 void ClearRedrawStore(TBool aClearPendingRedraw=EFalse); |
|
85 TBool DrawCommand(CWsGc* aGc,const TAny *aCmdData); |
|
86 void GcAttributeChange(CWsGc* aGc,const TAny *aCmdData); |
|
87 void GcDeactivate(CWsGc* aGc); |
|
88 void ClientExposing(); |
|
89 void DrawWindow(); |
|
90 void PrepareForResizeL(const TSize &aSize, TSize &aOldSize); |
|
91 void Moved(); |
|
92 TBool Contains(const TArray<TGraphicDrawerId>& aDrawers,const TRegion& aRegion) const; |
|
93 TBool ReleaseMemory(MWsMemoryRelease::TMemoryReleaseLevel aLevel); |
|
94 void VisibleRegionChange(); |
|
95 TBool ReadyToDraw() const; |
|
96 TInt SizeInBytes() const; |
|
97 TBool RedrawingInProgress() const; |
|
98 void WindowClosing(); |
|
99 TBool IsRedrawStoreEmpty() const; |
|
100 TBool IsBackgroundClearEnabled() const; |
|
101 CFbsBitmap* BitmapFromHandle(TInt aHandle) const; |
|
102 |
|
103 private: //from CWsWindowRedraw |
|
104 void Invalidate(const TRect * aRect = 0); |
|
105 TRgb BackColor() const; |
|
106 void Scroll(const TRect &aClipRect, const TPoint &aOffset,const TRect &aRect); |
|
107 |
|
108 private: |
|
109 void RemoveFromRedrawQueueIfEmpty(); |
|
110 const TRegion * ReadRegion(const TInt aRegionNum); |
|
111 void BeginRedraw(const TRect* aRect); |
|
112 void DoBeginRedrawL(const TRect* aRect); |
|
113 void SubtractRectFromSegmentArray(const TRect& aRect); |
|
114 void EndRedraw(); |
|
115 void ValidateRect(const TRect *aRect); |
|
116 void StoreDrawCommandL(CWsGc* aGc,const TAny *aCmdData); |
|
117 void AppendCommandL(const TAny* aCmdData, const TUint16 aOpcodeFlags = 0); |
|
118 void StoreAllGcAttributesL(CWsGc* aGc); |
|
119 void DrawCommandsL(); |
|
120 void DiscardStoredCommands(); |
|
121 TBool DiscardSegmentsOutsideViewport(); |
|
122 inline TBool NoBuffer() const; |
|
123 void DiscardStoredCommandsIfError(TInt aError); |
|
124 inline TBool IsFbsBitmapOperation(TInt aOpCode) const; |
|
125 inline TBool IsWsBitmapOperation(TInt aOpCode) const; |
|
126 inline TBool IsRemoteReadRequired(TInt aOpCode) const; |
|
127 inline TBool IsWsFontOperation(TInt aOpCode) const; |
|
128 inline TBool IsDrawWsGraphicOperation(TInt aOpCode) const; |
|
129 inline TBool IsWsDrawableSourceOperation(TInt aOpCode) const; |
|
130 void ReplaceAndAppendCommandL(TInt aOpcode,const TAny* aCmdData); |
|
131 // CRedrawSegment related methods |
|
132 inline TInt CurrentCommandBufferWritePos() const; |
|
133 inline CBufSeg* CurrentDrawCommandBuffer() const; |
|
134 void ExpandCommandBufferL(TInt aLength); |
|
135 void CommandBufferWrite(const TDesC8& aDes, TInt aLength); |
|
136 void CommandBufferWrite(const TAny* aPtr,TInt aLength); |
|
137 void CreateNewSegmentL(const TRect& aRect, TRedrawSegmentType aRegionType); |
|
138 inline TBool InRedraw() const; |
|
139 void PromotePendingSegment(); |
|
140 void Lock(); |
|
141 void Unlock(); |
|
142 void ReleaseRedrawSegments(); |
|
143 private: |
|
144 static TBool iAtomic; |
|
145 RPointerArray<CFbsBitmapRef> iFbsBitmapRefArray; |
|
146 private: |
|
147 class CRedrawSegment : public CBase |
|
148 { |
|
149 public: |
|
150 static CRedrawSegment* NewLC(const TRect& aRect, TRedrawSegmentType aNewRegionType, CWsRedrawMsgWindow& aRedraw); |
|
151 ~CRedrawSegment(); |
|
152 void AddWsBitmapL(DWsBitmap* bitmap); |
|
153 void AddWsDrawableSourceL(CWsDrawableSource* aDrawableSource); |
|
154 void AddDrawerL(TGraphicDrawerId aDrawerId); |
|
155 TBool ContainsDrawers(const TArray<TGraphicDrawerId>& aDrawers,const TRegion& aRegion) const; |
|
156 TInt SizeInBytes() const; |
|
157 TBool AppendNonDuplicateBitmapHandleL(TInt aHandle); |
|
158 private: |
|
159 CRedrawSegment(CWsRedrawMsgWindow& aRedraw); |
|
160 void ConstructL(const TRect& aRect, TRedrawSegmentType aNewRegionType); |
|
161 void ReleaseFontsBitmapsDrawableSources(); |
|
162 public: |
|
163 TRedrawSegmentType iRedrawSegmentType; |
|
164 CBufSeg* iDrawCommands; |
|
165 TInt iCurrentCommandBufferWritePos; |
|
166 RWsRegion iRegion; |
|
167 RPointerArray<DWsBitmap> iWsBitmapArray; |
|
168 RPointerArray<CWsFbsFont> iWsFontArray; |
|
169 RArray<TGraphicDrawerId> iDrawerArray; |
|
170 RPointerArray<CWsDrawableSource> iWsDrawableSourceArray; |
|
171 TTime iCreationTime; |
|
172 private: |
|
173 CWsRedrawMsgWindow& iRedraw; |
|
174 RArray<TInt> iBitmapHandleArray; |
|
175 }; |
|
176 RWsRegion iInvalid; // Region we haven't been sent a begin redraw for. |
|
177 TRect iRedrawRect; |
|
178 TRgb iBackColor; |
|
179 TInt iFlags; |
|
180 // Regions currently in use for drawing this window: |
|
181 RPointerArray<CRedrawSegment> iRedrawSegments; |
|
182 // The segment we are currently storing to. This is allowed to be null! |
|
183 CRedrawSegment * iCurrentSegment; |
|
184 // The last GC we drew with so we can detect changes |
|
185 CWsGc* iLastDrawGc; |
|
186 // During a scheduled draw, this is the area being drawn to (see comments on ReadRegion) |
|
187 RWsRegion iLocalRedrawRegion; |
|
188 TInt iMemoryLock; |
|
189 TBool iOSBStatus; |
|
190 }; |
|
191 |
|
192 inline TBool CWsRedrawMsgWindow::IsRemoteReadRequired(TInt aOpCode) const |
|
193 { |
|
194 return (aOpCode==EWsGcOpDrawTextPtr || aOpCode==EWsGcOpDrawTextVerticalPtr || |
|
195 aOpCode==EWsGcOpDrawBoxTextPtr || aOpCode==EWsGcOpDrawBoxTextVerticalPtr); |
|
196 } |
|
197 |
|
198 inline TInt CWsRedrawMsgWindow::CurrentCommandBufferWritePos() const |
|
199 { |
|
200 WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState); |
|
201 return iCurrentSegment->iCurrentCommandBufferWritePos; |
|
202 } |
|
203 |
|
204 inline CBufSeg* CWsRedrawMsgWindow::CurrentDrawCommandBuffer() const |
|
205 { |
|
206 WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState); |
|
207 return iCurrentSegment->iDrawCommands; |
|
208 } |
|
209 |
|
210 inline TBool CWsRedrawMsgWindow::InRedraw() const |
|
211 { |
|
212 return iFlags&EBeginEndRedraw; |
|
213 } |
|
214 |
|
215 inline TInt CFbsBitmapRef::RefCount() const |
|
216 { |
|
217 return iRefCount; |
|
218 } |
|
219 |
|
220 inline void CFbsBitmapRef::IncRefCount() |
|
221 { |
|
222 ++iRefCount; |
|
223 } |
|
224 |
|
225 inline void CFbsBitmapRef::DecRefCount() |
|
226 { |
|
227 WS_ASSERT_DEBUG(iRefCount>0,EWsPanicCounterValue); |
|
228 --iRefCount; |
|
229 } |
|
230 |
|
231 #endif |