First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // CWsRedrawMsgWindow and associated classes definitions
18 #ifndef __REDRAWMSGWINDOW_H__
19 #define __REDRAWMSGWINDOW_H__
22 #include "redrawmsgwindow.h"
25 class CWsDrawableSource;
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
34 inline TInt RefCount() const;
35 inline void IncRefCount();
36 inline void DecRefCount();
41 class CWsRedrawMsgWindow : public CWsWindowRedraw
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
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
59 enum TRedrawSegmentType
61 ESegmentTypePendingRedraw, // A redraw segment still being received
62 ESegmentTypeRedraw // A segment received between a begin and end redraw
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);
76 public: //from CWsWindowRedraw
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();
90 void PrepareForResizeL(const TSize &aSize, TSize &aOldSize);
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;
99 TBool IsRedrawStoreEmpty() const;
100 TBool IsBackgroundClearEnabled() const;
101 CFbsBitmap* BitmapFromHandle(TInt aHandle) const;
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);
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);
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();
142 void ReleaseRedrawSegments();
144 static TBool iAtomic;
145 RPointerArray<CFbsBitmapRef> iFbsBitmapRefArray;
147 class CRedrawSegment : public CBase
150 static CRedrawSegment* NewLC(const TRect& aRect, TRedrawSegmentType aNewRegionType, CWsRedrawMsgWindow& aRedraw);
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);
159 CRedrawSegment(CWsRedrawMsgWindow& aRedraw);
160 void ConstructL(const TRect& aRect, TRedrawSegmentType aNewRegionType);
161 void ReleaseFontsBitmapsDrawableSources();
163 TRedrawSegmentType iRedrawSegmentType;
164 CBufSeg* iDrawCommands;
165 TInt iCurrentCommandBufferWritePos;
167 RPointerArray<DWsBitmap> iWsBitmapArray;
168 RPointerArray<CWsFbsFont> iWsFontArray;
169 RArray<TGraphicDrawerId> iDrawerArray;
170 RPointerArray<CWsDrawableSource> iWsDrawableSourceArray;
173 CWsRedrawMsgWindow& iRedraw;
174 RArray<TInt> iBitmapHandleArray;
176 RWsRegion iInvalid; // Region we haven't been sent a begin redraw for.
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
186 // During a scheduled draw, this is the area being drawn to (see comments on ReadRegion)
187 RWsRegion iLocalRedrawRegion;
192 inline TBool CWsRedrawMsgWindow::IsRemoteReadRequired(TInt aOpCode) const
194 return (aOpCode==EWsGcOpDrawTextPtr || aOpCode==EWsGcOpDrawTextVerticalPtr ||
195 aOpCode==EWsGcOpDrawBoxTextPtr || aOpCode==EWsGcOpDrawBoxTextVerticalPtr);
198 inline TInt CWsRedrawMsgWindow::CurrentCommandBufferWritePos() const
200 WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState);
201 return iCurrentSegment->iCurrentCommandBufferWritePos;
204 inline CBufSeg* CWsRedrawMsgWindow::CurrentDrawCommandBuffer() const
206 WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState);
207 return iCurrentSegment->iDrawCommands;
210 inline TBool CWsRedrawMsgWindow::InRedraw() const
212 return iFlags&EBeginEndRedraw;
215 inline TInt CFbsBitmapRef::RefCount() const
220 inline void CFbsBitmapRef::IncRefCount()
225 inline void CFbsBitmapRef::DecRefCount()
227 WS_ASSERT_DEBUG(iRefCount>0,EWsPanicCounterValue);