windowing/windowserver/nonnga/SERVER/wnredraw.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 // Sending a redraw message to the client (see redrawmsgwindow.cpp)
       
    16 // Drawing from backup bitmap
       
    17 // Simply clearing the window
       
    18 // 
       
    19 //
       
    20 
       
    21 #include "wnredraw.h"
       
    22 #include "server.h"
       
    23 #include "playbackgc.h"
       
    24 #include "wstop.h"
       
    25 #include "ANIM.H"
       
    26 #include "EVQUEUE.H"
       
    27 #include "offscreenbitmap.h"
       
    28 #include <s32mem.h>
       
    29 #include <gdi.h>
       
    30 #include "panics.h"
       
    31 #include "inifile.h"
       
    32 #include "rootwin.h"
       
    33 #include "EVENT.H"
       
    34 #include "wstypes.h"
       
    35 
       
    36 struct TFadingParams
       
    37 	{
       
    38 	TUint8 blackMap;
       
    39 	TUint8 whiteMap;
       
    40 	};
       
    41 
       
    42 CWsWindowRedraw::CWsWindowRedraw(CWsWindow *aWin) : iWsWin(aWin)
       
    43 	{
       
    44 	}
       
    45 
       
    46 CWsWindowRedraw::~CWsWindowRedraw()
       
    47 	{
       
    48 	if (iWsWin->WsOwner())
       
    49 		{
       
    50 		iWsWin->WsOwner()->RedrawQueue()->RemoveInvalid(this);
       
    51 		}
       
    52 	}
       
    53 
       
    54 void CWsWindowRedraw::ConstructL()
       
    55 	{
       
    56 	}
       
    57 
       
    58 void CWsWindowRedraw::ClipInvalidRegion(const TRect &)
       
    59 	{
       
    60 	}
       
    61 
       
    62 void CWsWindowRedraw::Resize(const TSize &, const TSize &)
       
    63 	{
       
    64 	}
       
    65 
       
    66 void CWsWindowRedraw::SetReply(TInt aReply)
       
    67 	{
       
    68 	iWsWin->WsOwner()->SetReply(aReply);
       
    69 	}
       
    70 
       
    71 void CWsWindowRedraw::OwnerPanic(TClientPanic aPanic)
       
    72 	{
       
    73 	iWsWin->OwnerPanic(aPanic);
       
    74 	}
       
    75 
       
    76 CWsBackedUpWindow *CWsWindowRedraw::Backup() const
       
    77 	{
       
    78 	return(NULL);
       
    79 	}
       
    80 
       
    81 void CWsWindowRedraw::Scroll(const TRect &, const TPoint &,const TRect &)
       
    82 	{
       
    83 	}
       
    84 
       
    85 void CWsWindowRedraw::UpdateAnimArea()
       
    86 	{
       
    87 	}
       
    88 
       
    89 void CWsWindowRedraw::PrepareForResizeL(const TSize &, TSize &)
       
    90 	{
       
    91 	}
       
    92 
       
    93 TBool CWsWindowRedraw::DrawCommand(CWsGc*,const TAny*)
       
    94 	{
       
    95 	return ETrue;
       
    96 	}
       
    97 
       
    98 void CWsWindowRedraw::GcAttributeChange(CWsGc*,const TAny*)
       
    99 	{
       
   100 	}
       
   101 
       
   102 void CWsWindowRedraw::GcDeactivate(CWsGc*)
       
   103 	{
       
   104 	}
       
   105 
       
   106 CFbsDevice* CWsWindowRedraw::OutputDevice() const
       
   107 	{
       
   108 	return iWsWin->Screen()->GetFbsDevice();
       
   109 	}
       
   110 
       
   111 void CWsWindowRedraw::ClientExposing()
       
   112 	{
       
   113 	}
       
   114 
       
   115 void CWsWindowRedraw::ClearRedrawStore(TBool)
       
   116 	{}
       
   117 
       
   118 void CWsWindowRedraw::PreDrawWindow(CFbsBitGc* aGc, const TRegion &aRegion)
       
   119 	{
       
   120 	WS_ASSERT_DEBUG(iGlobalRedrawRegion == NULL, EWsPanicScheduledRedraw);
       
   121 	iGlobalRedrawRegion = &aRegion;
       
   122 	CPlaybackGc::Instance()->SetTargetRegion(iGlobalRedrawRegion);
       
   123 	CWsClient::iCurrentCommand.iOpcode=0; // Andy - urgh - loose me please
       
   124 	CPlaybackGc::Instance()->Activate(CliWin(), aGc, iGlobalRedrawRegion);
       
   125 	}
       
   126 
       
   127 void CWsWindowRedraw::PostDrawWindow(CFbsBitGc* aGc)
       
   128 	{	
       
   129 	if(CWsTop::IsFadeEnabled() && iWsWin->FadeCount()>0 && !iWsWin->IsNonFading())
       
   130 		{
       
   131 		//x86gcc compiler needs this syntax to perform 
       
   132 		//multiple inheritance duplicate common base class declaration resolution
       
   133 		//combined with the template resolution.
       
   134 		MWsGc* objectInterfaceResolver=CPlaybackGc::Instance();
       
   135 		MWsFader* fader = objectInterfaceResolver->ObjectInterface<MWsFader>();
       
   136 		if(fader)
       
   137 			{
       
   138 	      	TFadingParams parameters;
       
   139 	      	iWsWin->GetFadingParams(parameters.blackMap,parameters.whiteMap);
       
   140 	      	TPckgBuf<TFadingParams> buf(parameters);
       
   141 	      	fader->SetFadingParameters(buf);
       
   142 	      	// Only fade the region that hasn't been faded before
       
   143       		STACK_REGION fdRgn;
       
   144       		fdRgn.Copy( *iGlobalRedrawRegion );
       
   145       		fdRgn.Intersect( iWsWin->FadableRegion() );
       
   146       		fader->FadeArea( aGc, &fdRgn );
       
   147       		fdRgn.Close();
       
   148 	      	}
       
   149 		}
       
   150 
       
   151 	CPlaybackGc::Instance()->Deactivate();
       
   152 	
       
   153 	WS_ASSERT_DEBUG(iGlobalRedrawRegion, EWsPanicScheduledRedraw);
       
   154 	DrawAnims(aGc, *iGlobalRedrawRegion);
       
   155 	
       
   156 	CPlaybackGc::Instance()->SetTargetRegion(NULL);
       
   157 	iGlobalRedrawRegion = 0;
       
   158 	}
       
   159 	
       
   160 void CWsWindowRedraw::DrawAnims(CFbsBitGc * aGc, const TRegion& aRegion)
       
   161 	{
       
   162 	if (iWsWin->iAnimList)
       
   163 		{
       
   164 		// If an anim panics, it will leave and set the panic flag on the client
       
   165 		// The client itself won't actually panic yet, and we don't want to leave from here.
       
   166 		TRAP_IGNORE(DrawAnimsL(aGc, aRegion));
       
   167 		}
       
   168 
       
   169 	// Draw standard text cursor if required
       
   170 	RWsTextCursor* const cursor = CWsTop::CurrentTextCursor();
       
   171 	if (cursor && cursor->Win() == iWsWin && cursor->IsStandardCursorActive())
       
   172 		{
       
   173 		// Standard text cursor is active on this window
       
   174 		const TBool flashing = cursor->IsFlashing();
       
   175 		TFlashState flashState = EFlashOff;
       
   176 		if (flashing)
       
   177 			{
       
   178 			flashState = Screen()->SpriteManager()->CurrentCursorFlashState();
       
   179 			}
       
   180 		if (flashState == EFlashOn || !flashing)
       
   181 			{
       
   182 			// Cursor should be visible, so draw it
       
   183 			aGc->Reset();
       
   184 			cursor->Draw(aGc, aRegion);
       
   185 			}
       
   186 		if (flashing)
       
   187 			{
       
   188 			// Reschedule to flash the standard cursor on or off
       
   189 			Screen()->ScheduleAnimation(cursor->RectRelativeToScreen(), Screen()->SpriteManager()->NextCursorFlashStateChange(), 0, 0);
       
   190 			}
       
   191 		}
       
   192 
       
   193 	for (CWsSpriteBase * sprite = iWsWin->iSpriteList; sprite; sprite = sprite->Next())
       
   194 		{
       
   195 		aGc->Reset();
       
   196 		sprite->Redraw(aGc, aRegion);
       
   197 		}
       
   198 	}
       
   199 
       
   200 void CWsWindowRedraw::DrawAnimsL(CFbsBitGc * aGc, const TRegion& aRegion)
       
   201 	{
       
   202 	for (CWsAnim * anim = iWsWin->iAnimList; anim; anim = anim->Next())
       
   203 		{
       
   204 		// This can leave
       
   205 		TRAPD(err,anim->Redraw(aGc, &aRegion));
       
   206 		if(err!=KErrNone)
       
   207 			{
       
   208 			anim->Panic(EWservPanicAnimLeave);
       
   209 			}
       
   210 		}
       
   211 	}
       
   212 
       
   213 TBool CWsWindowRedraw::Contains(const TArray<TGraphicDrawerId>& /*aDrawers*/,const TRegion& aRegion) const
       
   214 	{
       
   215 	// if in doubt, assume we do
       
   216 	return !aRegion.IsEmpty();
       
   217 	}
       
   218 
       
   219 TInt CWsWindowRedraw::DrawBackgroundColor(const TRegion* aRegion)
       
   220 	{
       
   221 	if(Screen()->BltOffScreen())
       
   222 		{
       
   223 		return KErrNone;
       
   224 		}
       
   225 	TRgb col = BackColor();
       
   226 	if (col.Alpha() == 0)
       
   227 		{
       
   228 		return KErrNone;
       
   229 		}
       
   230 	TRect abs(CliWin()->AbsRect());
       
   231 	abs.Move(-CliWin()->Origin());
       
   232 	TBuf8<sizeof(TRect)> cmd;
       
   233 	cmd.Copy(reinterpret_cast<TUint8*>(&abs),sizeof(TRect));
       
   234 	CPlaybackGc::Instance()->BitGc().SetClippingRegion(aRegion);
       
   235 	CPlaybackGc::Instance()->BitGc().SetBrushColor(col);
       
   236 	CPlaybackGc::Instance()->BitGc().SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   237 	CPlaybackGc::Instance()->BitGc().SetPenStyle(CGraphicsContext::ENullPen);
       
   238 	// Andy - this is pretty ridiculous - can't we just draw using the gc?
       
   239 	TRAPD(err,CPlaybackGc::Instance()->CommandL(EWsGcOpDrawRect, cmd));		//Should not leave ###
       
   240 	CPlaybackGc::Instance()->BitGc().SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   241 	CPlaybackGc::Instance()->BitGc().CancelClippingRegion();
       
   242 	return err;
       
   243 	}
       
   244 
       
   245 TBool CWsWindowRedraw::ReleaseMemory(MWsMemoryRelease::TMemoryReleaseLevel)
       
   246 	{
       
   247 	return EFalse;
       
   248 	}
       
   249 
       
   250 void CWsWindowRedraw::VisibleRegionChange()
       
   251 	{
       
   252 	}
       
   253 	
       
   254 TBool CWsWindowRedraw::ReadyToDraw() const
       
   255 	{
       
   256 	return ETrue;
       
   257 	}
       
   258 
       
   259 void CWsWindowRedraw::WindowClosing()
       
   260 	{}
       
   261 	
       
   262 //
       
   263 // Blank up window //
       
   264 //
       
   265 
       
   266 CWsBlankWindow::CWsBlankWindow(CWsWindow *aWin) : CWsWindowRedraw(aWin), iColor(iWsWin->RootWindow()->DefaultBackgroundColor()), iNoColor(EFalse)
       
   267 	{
       
   268 	}
       
   269 
       
   270 CWsBlankWindow::~CWsBlankWindow()
       
   271 	{
       
   272 	}
       
   273 
       
   274 void CWsBlankWindow::SetColor(TRgb aColor)
       
   275 	{
       
   276 	iColor=aColor;
       
   277 	iNoColor=EFalse;
       
   278 	Screen()->AddRedrawRegion(iWsWin->VisibleRegion());
       
   279 	}
       
   280 
       
   281 TBool CWsBlankWindow::CommandL(TInt aOpcode, TWsWinCmdUnion &aCmd)
       
   282 	{
       
   283 	switch(aOpcode)
       
   284 		{
       
   285 		case EWsWinOpSetColor:
       
   286 			SetColor(*aCmd.rgb);
       
   287 			break;
       
   288 		case EWsWinOpSetNoBackgroundColor:
       
   289 			SetBackgroundClear();
       
   290 			break;
       
   291 		default:
       
   292 			return(EFalse);
       
   293 		}
       
   294 	return(ETrue);
       
   295 	}
       
   296 
       
   297 TRgb CWsBlankWindow::BackColor() const
       
   298 	{
       
   299 	return(iColor);
       
   300 	}
       
   301 
       
   302 TBool CWsBlankWindow::GetRedrawRect(TRect &) const
       
   303 	{
       
   304 	if (!iNoColor || iWsWin->iAnimList)
       
   305 		iWsWin->Screen()->AddRedrawRegion(iWsWin->VisibleRegion());
       
   306 	return(EFalse);
       
   307 	}
       
   308 
       
   309 TBool CWsBlankWindow::NeedsRedraw() const
       
   310 	{
       
   311 	return(EFalse);
       
   312 	}
       
   313 
       
   314 void CWsBlankWindow::DrawWindow()
       
   315 	{
       
   316 	if (!iNoColor)
       
   317 		{
       
   318 		DrawBackgroundColor(iGlobalRedrawRegion);
       
   319 		}
       
   320 	}