os/graphics/windowing/windowserver/nga/SERVER/openwfc/redrawmsgwindow.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/nga/SERVER/openwfc/redrawmsgwindow.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,231 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// CWsRedrawMsgWindow and associated classes definitions
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef __REDRAWMSGWINDOW_H__
    1.22 +#define __REDRAWMSGWINDOW_H__
    1.23 +
    1.24 +#include "wnredraw.h"
    1.25 +#include "redrawmsgwindow.h"
    1.26 +
    1.27 +class CWsFbsFont;
    1.28 +class CWsDrawableSource;
    1.29 +
    1.30 +// This class is intended to be used in cases, where it's needed to track how many times a CFbsBitmap
    1.31 +// is referenced, e.g. in redraws, where already drawn bitmaps need to be re-drawn in different position.
    1.32 +class CFbsBitmapRef : public CFbsBitmap
    1.33 +    {
    1.34 +public:
    1.35 +    CFbsBitmapRef();
    1.36 +    ~CFbsBitmapRef();
    1.37 +    inline TInt RefCount() const;
    1.38 +    inline void IncRefCount();
    1.39 +    inline void DecRefCount();
    1.40 +private:
    1.41 +    TInt iRefCount;
    1.42 +    };
    1.43 +
    1.44 +class CWsRedrawMsgWindow : public CWsWindowRedraw
    1.45 +	{
    1.46 +	class CRedrawSegment;
    1.47 +	enum TFlags
    1.48 +		{
    1.49 +		EBackgroundClear=0x0001,		//Clear background when starting redraw
    1.50 +		EBeginEndRedraw=0x0002,			//This window is currently in the middle of a redraw, that is between client calls to BeginRedraw and EndRedraw.
    1.51 +		EPendingScheduledDraw=0x0004,   //We have scheduled a redraw but it hasn't happened yet
    1.52 +		EStoringEntireWindow=0x0008,    //If store commands for the entire window or only the viewport
    1.53 +		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
    1.54 +		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
    1.55 +		};
    1.56 +	enum TScope
    1.57 +		{
    1.58 +		EStoreEntireWindow,             //We try to obtain draw commands for the entire window
    1.59 +		EStoreViewport                  //We only try to obtain commands for the on screen viewport
    1.60 +		};
    1.61 +public:
    1.62 +	enum TRedrawSegmentType
    1.63 +		{
    1.64 +		ESegmentTypePendingRedraw,      // A redraw segment still being received
    1.65 +		ESegmentTypeRedraw              // A segment received between a begin and end redraw
    1.66 +		};
    1.67 +public:
    1.68 +	static void StaticInitL();
    1.69 +	CWsRedrawMsgWindow(CWsWindow *aWin);
    1.70 +	~CWsRedrawMsgWindow();
    1.71 +	void AddFbsBitmapsL(TInt aHandle, TInt aMaskHandle);
    1.72 +	void AddFbsBitmapRefL(TInt aHandle);
    1.73 +	void AddWsBitmapsL(TInt aHandle, TInt aMaskHandle);
    1.74 +	void AddWsFontL(TInt aHandle);
    1.75 +	void AddWsDrawableSourceL(TInt aHandle);
    1.76 +	void SetScope(TScope aStore);
    1.77 +	void CleanupBitmapRefArray(const RArray<TInt>& aHandleArray);
    1.78 +	
    1.79 +public:	//from CWsWindowRedraw		
    1.80 +	void ConstructL();
    1.81 +	TBool CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd);
    1.82 +	void ClipInvalidRegion(const TRect &aRect);
    1.83 +	TBool NeedsRedraw() const;
    1.84 +	TBool GetRedrawRect(TRect &aRect) const;
    1.85 +	const TRegion& BaseDrawRegion() const;
    1.86 +	const TRegion& InvalidArea() const;
    1.87 +	void ClearRedrawStore(TBool aClearPendingRedraw=EFalse);
    1.88 +	TBool DrawCommand(CWsGc* aGc,const TAny *aCmdData);
    1.89 +	void GcAttributeChange(CWsGc* aGc,const TAny *aCmdData);
    1.90 +	void GcDeactivate(CWsGc* aGc);
    1.91 +	void ClientExposing();
    1.92 +	void DrawWindow();
    1.93 +	void PrepareForResizeL(const TSize &aSize, TSize &aOldSize);
    1.94 +	void Moved();
    1.95 +	TBool Contains(const TArray<TGraphicDrawerId>& aDrawers,const TRegion& aRegion) const;
    1.96 +	TBool ReleaseMemory(MWsMemoryRelease::TMemoryReleaseLevel aLevel);
    1.97 +	void VisibleRegionChange();
    1.98 +	TBool ReadyToDraw() const;
    1.99 +	TInt SizeInBytes() const;
   1.100 +	TBool RedrawingInProgress() const;
   1.101 +	void WindowClosing();
   1.102 +	TBool IsRedrawStoreEmpty() const;
   1.103 +	TBool IsBackgroundClearEnabled() const;
   1.104 +	CFbsBitmap* BitmapFromHandle(TInt aHandle) const;
   1.105 +
   1.106 +private: //from CWsWindowRedraw	
   1.107 +	void Invalidate(const TRect * aRect = 0);
   1.108 +	TRgb BackColor() const;
   1.109 +	void Scroll(const TRect &aClipRect, const TPoint &aOffset,const TRect &aRect);
   1.110 +	
   1.111 +private:
   1.112 +	void RemoveFromRedrawQueueIfEmpty();
   1.113 +	const TRegion * ReadRegion(const TInt aRegionNum);
   1.114 +	void BeginRedraw(const TRect* aRect);
   1.115 +	void DoBeginRedrawL(const TRect* aRect);
   1.116 +	void SubtractRectFromSegmentArray(const TRect& aRect);
   1.117 +	void EndRedraw();
   1.118 +	void ValidateRect(const TRect *aRect);
   1.119 +	void StoreDrawCommandL(CWsGc* aGc,const TAny *aCmdData);
   1.120 +	void AppendCommandL(const TAny* aCmdData, const TUint16 aOpcodeFlags = 0);
   1.121 +	void StoreAllGcAttributesL(CWsGc* aGc);
   1.122 +	void DrawCommandsL();
   1.123 +	void DiscardStoredCommands();
   1.124 +	TBool DiscardSegmentsOutsideViewport();
   1.125 +	inline TBool NoBuffer() const;
   1.126 +	void DiscardStoredCommandsIfError(TInt aError);
   1.127 +	inline TBool IsFbsBitmapOperation(TInt aOpCode) const;
   1.128 +	inline TBool IsWsBitmapOperation(TInt aOpCode) const;
   1.129 +	inline TBool IsRemoteReadRequired(TInt aOpCode) const;
   1.130 +	inline TBool IsWsFontOperation(TInt aOpCode) const;
   1.131 +	inline TBool IsDrawWsGraphicOperation(TInt aOpCode) const;
   1.132 +	inline TBool IsWsDrawableSourceOperation(TInt aOpCode) const;
   1.133 +	void ReplaceAndAppendCommandL(TInt aOpcode,const TAny* aCmdData);
   1.134 +	// CRedrawSegment related methods
   1.135 +	inline TInt CurrentCommandBufferWritePos() const;
   1.136 +	inline CBufSeg* CurrentDrawCommandBuffer() const;
   1.137 +	void ExpandCommandBufferL(TInt aLength);
   1.138 +	void CommandBufferWrite(const TDesC8& aDes, TInt aLength);
   1.139 +	void CommandBufferWrite(const TAny* aPtr,TInt aLength);
   1.140 +	void CreateNewSegmentL(const TRect& aRect, TRedrawSegmentType aRegionType);
   1.141 +	inline TBool InRedraw() const;
   1.142 +	void PromotePendingSegment();
   1.143 +	void Lock();
   1.144 +	void Unlock();
   1.145 +	void ReleaseRedrawSegments();
   1.146 +private:
   1.147 +	static TBool iAtomic;
   1.148 +	RPointerArray<CFbsBitmapRef> iFbsBitmapRefArray;
   1.149 +private:
   1.150 +	class CRedrawSegment : public CBase
   1.151 +		{
   1.152 +	public:
   1.153 +		static CRedrawSegment* NewLC(const TRect& aRect, TRedrawSegmentType aNewRegionType, CWsRedrawMsgWindow& aRedraw);
   1.154 +		~CRedrawSegment();
   1.155 +		void AddWsBitmapL(DWsBitmap* bitmap);
   1.156 +		void AddWsDrawableSourceL(CWsDrawableSource* aDrawableSource);
   1.157 +		void AddDrawerL(TGraphicDrawerId aDrawerId);
   1.158 +		TBool ContainsDrawers(const TArray<TGraphicDrawerId>& aDrawers,const TRegion& aRegion) const;
   1.159 +		TInt SizeInBytes() const;
   1.160 +		TBool AppendNonDuplicateBitmapHandleL(TInt aHandle);
   1.161 +	private:
   1.162 +		CRedrawSegment(CWsRedrawMsgWindow& aRedraw);
   1.163 +		void ConstructL(const TRect& aRect, TRedrawSegmentType aNewRegionType);
   1.164 +		void ReleaseFontsBitmapsDrawableSources();
   1.165 +	public:
   1.166 +		TRedrawSegmentType iRedrawSegmentType;
   1.167 +		CBufSeg* iDrawCommands;
   1.168 +		TInt iCurrentCommandBufferWritePos;
   1.169 +		RWsRegion iRegion;
   1.170 +		RPointerArray<DWsBitmap> iWsBitmapArray;
   1.171 +		RPointerArray<CWsFbsFont> iWsFontArray;
   1.172 +		RArray<TGraphicDrawerId> iDrawerArray;
   1.173 +		RPointerArray<CWsDrawableSource> iWsDrawableSourceArray;
   1.174 +		TTime iCreationTime;
   1.175 +	private:
   1.176 +	    CWsRedrawMsgWindow& iRedraw;
   1.177 +	    RArray<TInt> iBitmapHandleArray;
   1.178 +		};
   1.179 +	RWsRegion iInvalid; // Region we haven't been sent a begin redraw for.
   1.180 +	TRect iRedrawRect;
   1.181 +	TRgb iBackColor;
   1.182 +	TInt iFlags;
   1.183 +	// Regions currently in use for drawing this window:
   1.184 +	RPointerArray<CRedrawSegment> iRedrawSegments;
   1.185 +	// The segment we are currently storing to.  This is allowed to be null!
   1.186 +	CRedrawSegment * iCurrentSegment;
   1.187 +	// The last GC we drew with so we can detect changes
   1.188 +	CWsGc* iLastDrawGc;
   1.189 +	// During a scheduled draw, this is the area being drawn to (see comments on ReadRegion)
   1.190 +	RWsRegion iLocalRedrawRegion;
   1.191 +	TInt iMemoryLock;
   1.192 +	TBool iOSBStatus;
   1.193 +	};
   1.194 +
   1.195 +inline TBool CWsRedrawMsgWindow::IsRemoteReadRequired(TInt aOpCode) const
   1.196 +	{
   1.197 +	return (aOpCode==EWsGcOpDrawTextPtr || aOpCode==EWsGcOpDrawTextVerticalPtr || 
   1.198 +		aOpCode==EWsGcOpDrawBoxTextPtr || aOpCode==EWsGcOpDrawBoxTextVerticalPtr);
   1.199 +	}
   1.200 +
   1.201 +inline TInt CWsRedrawMsgWindow::CurrentCommandBufferWritePos() const
   1.202 +	{
   1.203 +	WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState);
   1.204 +	return iCurrentSegment->iCurrentCommandBufferWritePos;
   1.205 +	}
   1.206 +
   1.207 +inline CBufSeg* CWsRedrawMsgWindow::CurrentDrawCommandBuffer() const
   1.208 +	{
   1.209 +	WS_ASSERT_DEBUG(iCurrentSegment, EWsPanicDrawCommandsInvalidState);
   1.210 +	return iCurrentSegment->iDrawCommands;
   1.211 +	}
   1.212 +
   1.213 +inline TBool CWsRedrawMsgWindow::InRedraw() const
   1.214 +	{
   1.215 +	return iFlags&EBeginEndRedraw;
   1.216 +	}
   1.217 +	
   1.218 +inline TInt CFbsBitmapRef::RefCount() const
   1.219 +    {
   1.220 +    return iRefCount;
   1.221 +    }
   1.222 +
   1.223 +inline void CFbsBitmapRef::IncRefCount()
   1.224 +    {
   1.225 +    ++iRefCount;
   1.226 +    }
   1.227 +
   1.228 +inline void CFbsBitmapRef::DecRefCount()
   1.229 +    {
   1.230 +    WS_ASSERT_DEBUG(iRefCount>0,EWsPanicCounterValue);
   1.231 +    --iRefCount;
   1.232 +    }
   1.233 +	
   1.234 +#endif