windowing/windowserver/nga/SERVER/openwfc/backedupwindow.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-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 // Window redraw code, three sorts of redrawing are supported
       
    15 // This class deals with drawing from backup bitmap
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "backedupwindow.h"
       
    20 #include "server.h"
       
    21 #include "gc.h"
       
    22 #include "wstop.h"
       
    23 #include "ANIM.H"
       
    24 #include "EVQUEUE.H"
       
    25 #include <s32mem.h>
       
    26 #include <gdi.h>
       
    27 #include "panics.h"
       
    28 #include "inifile.h"
       
    29 #include "rootwin.h"
       
    30 #include "EVENT.H"
       
    31 #include "playbackgc.h"
       
    32 #include "devicemap.h"
       
    33 
       
    34 CFbsBitGc *CWsBackedUpWindow::iBitGc=NULL;
       
    35 
       
    36 CWsBackedUpWindow::CWsBackedUpWindow(CWsWindow *aWin, TDisplayMode aDisplayMode) 
       
    37 	: CWsWindowRedraw(aWin), iDisplayMode(aDisplayMode)
       
    38 	{}
       
    39 
       
    40 void CWsBackedUpWindow::StaticInitL()
       
    41 	{
       
    42 	iBitGc=CFbsBitGc::NewL();
       
    43 	}
       
    44 
       
    45 void CWsBackedUpWindow::StaticDestroy()
       
    46 	{
       
    47 	delete iBitGc;
       
    48 	iBitGc = 0;
       
    49 	}
       
    50 
       
    51 void CWsBackedUpWindow::ActivateGc()
       
    52 	{
       
    53 	iBitGc->Activate(iBitmapDevice);
       
    54 	iBitGc->Reset();
       
    55 	iBitGc->SetBrushColor(BackColor());
       
    56 	}
       
    57 
       
    58 TBool CWsBackedUpWindow::DrawCommand(CWsGc*,const TAny*)
       
    59 	{
       
    60 	if (Screen()->ChangeTracking())
       
    61 		MarkDirtyAndSchedule(iCurrentRegion);
       
    62 	else
       
    63 		Screen()->AddRedrawRegion(iWsWin->VisibleRegion());
       
    64 	
       
    65 	return ETrue;
       
    66 	}
       
    67 
       
    68 void CWsBackedUpWindow::ConstructL()
       
    69 	{
       
    70 	iDisplayMode=iWsWin->SetRequiredDisplayModeL(iDisplayMode);
       
    71 	TSize size=iWsWin->Size();
       
    72 	iBitmap=new(ELeave) CFbsBitmap();
       
    73 	User::LeaveIfError(iBitmap->Create(size, iDisplayMode));
       
    74 	iBitmapDevice=CFbsBitmapDevice::NewL(iBitmap);
       
    75 	SetSizeInTwips();
       
    76 //
       
    77 	ActivateGc();
       
    78 	iBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
    79 	iBitGc->Clear(TRect(size));
       
    80 	iBitGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
    81 	WS_ASSERT_DEBUG(iWsWin->WinType()==EWinTypeClient,EWsPanicWindowType);
       
    82 	}
       
    83 
       
    84 void CWsBackedUpWindow::PrepareForResizeL(const TSize &aSize, TSize &aOldSize)
       
    85 	{
       
    86 	aOldSize=iBitmapDevice->SizeInPixels();
       
    87 	if (aOldSize!=aSize)
       
    88 		{
       
    89 		User::LeaveIfError(iBitmapDevice->Resize(aSize));
       
    90 		SetSizeInTwips();
       
    91 		}
       
    92 	}
       
    93 
       
    94 void CWsBackedUpWindow::Resize(const TSize &aSize, const TSize &aOldSize)
       
    95 	{
       
    96 	ActivateGc();
       
    97 	iBitGc->SetClippingRegion(NULL);
       
    98 	iBitGc->Clear(TRect(aOldSize.iWidth, 0, aSize.iWidth, aOldSize.iHeight));
       
    99 	iBitGc->Clear(TRect(0, aOldSize.iHeight,aSize.iWidth, aSize.iHeight));
       
   100 	
       
   101 	static_cast<CWsClientWindow *>(iWsWin)->ReactivateGcs();
       
   102 	
       
   103 	if(Screen()->ChangeTracking())
       
   104 		{
       
   105 		//Keep track of the region we need to refresh when we recieve draw commands
       
   106 		iCurrentRegion.Reset();
       
   107 		iCurrentRegion.Copy(iWsWin->WindowArea());
       
   108 		iCurrentRegion.Offset(-iWsWin->Origin());
       
   109 		iCurrentRegion.Tidy();
       
   110 		if(iCurrentRegion.CheckError())
       
   111 			{
       
   112 			iCurrentRegion.Reset();
       
   113 			TRegionFix<1> fallback(iWsWin->AbsRect());
       
   114 			iCurrentRegion.Copy(fallback); 
       
   115 			iCurrentRegion.Offset(-iWsWin->Origin());
       
   116 			}
       
   117 		
       
   118 		//If the window has nerver been drawn to screen, we now schedule the initial draw. This can't
       
   119 		//be done in ConstructL because BackedUpWindows are created with size(0,0). And we can't check
       
   120 		//iWsWin->IsActive() because the client might activate the window before giving it a size.
       
   121 		if (!iHasBeenScheduled)
       
   122 			{
       
   123 			iHasBeenScheduled = ETrue;
       
   124 			MarkDirtyAndSchedule(iCurrentRegion);
       
   125 			}
       
   126 		}
       
   127 	}
       
   128 
       
   129 CWsBackedUpWindow::~CWsBackedUpWindow()
       
   130 	{
       
   131 	iCurrentRegion.Reset();
       
   132 	delete iBitmapDevice;
       
   133 	delete iBitmap;
       
   134 	}
       
   135 
       
   136 TBool CWsBackedUpWindow::CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd)
       
   137 	{
       
   138 	switch(aOpcode)
       
   139 		{
       
   140 		case EWsWinOpUpdateBackupBitmap:
       
   141 			break;
       
   142 		case EWsWinOpMaintainBackup:
       
   143 			break;
       
   144 		case EWsWinOpBitmapHandle:
       
   145 			SetReply(iBitmap->Handle());
       
   146 			break;
       
   147 		case EWsWinOpUpdateScreen:
       
   148 			{
       
   149 			TRegionFix<1> fixRegion(iWsWin->AbsRect());
       
   150 			UpdateScreen(fixRegion);
       
   151 			}
       
   152 			break;
       
   153 		case EWsWinOpUpdateScreenRegion:
       
   154 			{
       
   155 			RWsRegion *clientRegion=NULL;
       
   156 			TRAPD(err,clientRegion=GetRegionFromClientL(iWsWin->WsOwner(), *aCmd.Int));
       
   157 			if (err==KErrNone && !clientRegion->CheckError())
       
   158 				{
       
   159 				clientRegion->Offset(iWsWin->Origin());
       
   160 				clientRegion->ClipRect(iWsWin->AbsRect());
       
   161 				UpdateScreen(*clientRegion);
       
   162 				}
       
   163 			else
       
   164 				{
       
   165 				TRegionFix<1> fixRegion(iWsWin->AbsRect());
       
   166 				UpdateScreen(fixRegion);
       
   167 				}
       
   168 			clientRegion->Destroy();
       
   169 			}
       
   170 			break;
       
   171 		case EWsWinOpSetBackgroundSurface:
       
   172 		case EWsWinOpSetBackgroundSurfaceConfig:
       
   173 		case EWsWinOpGetBackgroundSurfaceConfig:
       
   174 			OwnerPanic(EWservPanicDrawable);	// Backed up windows don't support these
       
   175 			break;
       
   176 		default:
       
   177 			return(EFalse);
       
   178 		}
       
   179 	return(ETrue);
       
   180 	}
       
   181 
       
   182 CWsBackedUpWindow *CWsBackedUpWindow::Backup() const
       
   183 	{
       
   184 	return((CWsBackedUpWindow *)this);
       
   185 	}
       
   186 
       
   187 CFbsDevice* CWsBackedUpWindow::OutputDevice() const
       
   188 	{
       
   189 	return iBitmapDevice;
       
   190 	}
       
   191 
       
   192 TRgb CWsBackedUpWindow::BackColor() const
       
   193 	{
       
   194 	return(iWsWin->RootWindow()->DefaultBackgroundColor());
       
   195 	}
       
   196 
       
   197 void CWsBackedUpWindow::Scroll(const TRect &aClipRect, const TPoint &aOffset,const TRect &aRect)
       
   198 	{
       
   199 	TRect winBorder=TRect(iWsWin->Size());
       
   200 	TRect clipRect=aClipRect;
       
   201 	TRect srcRect = aRect;		
       
   202 	clipRect.Intersection(winBorder);	
       
   203 	if (!clipRect.IsEmpty())
       
   204 		{	// If we have to do something (a visible part will change)
       
   205 		srcRect.Intersection(clipRect);
       
   206 
       
   207 		STACK_REGION regionToClear;
       
   208 		regionToClear.AddRect(aRect);
       
   209 		regionToClear.SubRect(srcRect);
       
   210 		regionToClear.Offset(aOffset);
       
   211 		
       
   212 		ActivateGc();
       
   213 		iBitGc->SetClippingRect(clipRect);
       
   214 		iBitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   215 		iBitGc->CopyRect(aOffset,srcRect);				
       
   216 		for (TInt k=0;k<regionToClear.Count();k++)
       
   217 			{
       
   218 			iBitGc->Clear(regionToClear[k]);
       
   219 			}
       
   220 		iBitGc->SetClippingRect(winBorder);
       
   221 		iBitGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   222 		TRegionFix<1> fixRegion(iWsWin->AbsRect());
       
   223 		UpdateScreen(fixRegion);
       
   224 		regionToClear.Close();
       
   225 		}
       
   226 	}
       
   227 
       
   228 TBool CWsBackedUpWindow::NeedsRedraw() const
       
   229 	{
       
   230 	return(EFalse);
       
   231 	}
       
   232 
       
   233 TBool CWsBackedUpWindow::GetRedrawRect(TRect &) const
       
   234 	{
       
   235 	return(EFalse);
       
   236 	}
       
   237 
       
   238 void CWsBackedUpWindow::SetSizeInTwips()
       
   239 	{
       
   240 	TSize size=iBitmap->SizeInPixels();
       
   241 	size.iWidth=Screen()->DeviceMap().HorizontalPixelsToTwips(size.iWidth);
       
   242 	size.iHeight=Screen()->DeviceMap().VerticalPixelsToTwips(size.iHeight);
       
   243 	iBitmap->SetSizeInTwips(size);
       
   244 	}
       
   245 
       
   246 void CWsBackedUpWindow::DrawWindow()
       
   247 	{
       
   248 	MWsGraphicsContext* gc = static_cast<MWsGraphicsContext*>(CPlaybackGc::Instance()->ResolveObjectInterface(KMWsGraphicsContext));
       
   249 	
       
   250 	gc->SetOrigin(iWsWin->Origin());
       
   251 	gc->SetClippingRegion(*iRedrawRegion);
       
   252 	gc->BitBlt(TPoint(0,0), *iBitmap);
       
   253 	}
       
   254 
       
   255 /** 
       
   256 This function updates the window's dirty region and schedules a redraw if needed.
       
   257 Only used when the screen is run in CHANGETRACKING mode. 
       
   258 @param aRegion in window coordinates
       
   259 */
       
   260 void CWsBackedUpWindow::MarkDirtyAndSchedule(const TRegion& aRegion)
       
   261 	{
       
   262 	WS_ASSERT_DEBUG(Screen()->ChangeTracking(),EWsPanicNoChangetracking);
       
   263 	
       
   264 	if(!aRegion.IsEmpty())
       
   265 		{
       
   266 		iWsWin->AddDirtyWindowRegion(aRegion);
       
   267 		if (iWsWin->IsActive() && iWsWin->IsVisible())
       
   268 			{
       
   269 			Screen()->ScheduleWindow(iWsWin);
       
   270 			}
       
   271 		}
       
   272 	}
       
   273 
       
   274 /**
       
   275 This function selects the desired behaviour depending on whether the screen is
       
   276 run in CHANGETRACKING mode or not. 
       
   277 @param aRegion in screen coordinates
       
   278 */
       
   279 void CWsBackedUpWindow::UpdateScreen(const TRegion& aRegion)
       
   280 	{
       
   281 	if (Screen()->ChangeTracking())
       
   282 		{
       
   283 		STACK_REGION region;
       
   284 		region.Copy(aRegion);
       
   285 		region.Offset(-WsWin()->Origin()); //convert to window coordinates 
       
   286 		MarkDirtyAndSchedule(region);
       
   287 		region.Close();		
       
   288 		}
       
   289 	else
       
   290 		{
       
   291 		Screen()->AddRedrawRegion(aRegion);
       
   292 		}
       
   293 	}