sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file
sl@0:  @test
sl@0:  @internalComponent - Internal Symbian test code
sl@0: */
sl@0: 
sl@0: #include "bufferdrawer.h"
sl@0: #include <s32mem.h>
sl@0: #include <s32strm.h>
sl@0: #include <fbs.h>
sl@0: #include <bitdev.h>
sl@0: #include <bitstd.h>
sl@0: #include <graphics/wsgraphicscontext.h>
sl@0: #include <graphics/wsuibuffer.h>
sl@0: 
sl@0: 
sl@0: // CWsGraphicDrawer	
sl@0: CWsBufferGraphicDrawer* CWsBufferGraphicDrawer::NewL()
sl@0: 	{
sl@0: 	return new(ELeave) CWsBufferGraphicDrawer;	
sl@0: 	}
sl@0: 	
sl@0: CWsBufferGraphicDrawer::~CWsBufferGraphicDrawer()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: void CWsBufferGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
sl@0: 	{
sl@0: 	BaseConstructL(aEnv, aId, aOwner);
sl@0:  	// default white line number
sl@0: 	iWhiteLinePos = 0;
sl@0:  	}
sl@0: 
sl@0: void CWsBufferGraphicDrawer::HandleMessage(const TDesC8& aData)
sl@0: 	{
sl@0: 	TInt linePos = aData[0];
sl@0: 	DoUpdateWhiteLinePos(linePos);
sl@0: 	}
sl@0: 
sl@0: void CWsBufferGraphicDrawer::DoUpdateWhiteLinePos(TInt aWhiteLinePos)
sl@0: 	{
sl@0: 	iWhiteLinePos = aWhiteLinePos;
sl@0: 	// Invalidate the redrawing
sl@0: 	Invalidate();
sl@0: 	}
sl@0: 
sl@0: void CWsBufferGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& /*aData*/) const
sl@0: 	{
sl@0: 	MWsGraphicsContext* context = static_cast<MWsGraphicsContext*>(aGc.ResolveObjectInterface(KMWsGraphicsContext));
sl@0: 	
sl@0: 	//Draw a filled rect with the chosen color
sl@0: 	context->Push();
sl@0: 	context->SetBrushStyle(MWsGraphicsContext::ESolidBrush);
sl@0: 	context->SetBrushColor(KRgbBlue);
sl@0: 	context->DrawRect(aRect);
sl@0: 	context->Pop();
sl@0: 	
sl@0: 	//Obtain access to the screen/OSB buffer
sl@0: 	MWsUiBuffer* buffer = static_cast<MWsUiBuffer*>(aGc.ResolveObjectInterface(KMWsUiBufferInterfaceId));
sl@0: 	TAny* data;
sl@0: 	TInt stride;
sl@0: 	
sl@0: 	TInt err = buffer->MapReadWrite(data, stride);
sl@0: 	
sl@0: 	if (err == KErrNone)
sl@0: 		{
sl@0: 		//Fill the chosen line with white
sl@0: 		TUint8* scanLine = static_cast<TUint8*>(data);
sl@0: 		scanLine += stride * iWhiteLinePos;
sl@0: 		Mem::Fill(scanLine, stride, 0xFF);
sl@0: 	
sl@0: 		buffer->Unmap();
sl@0: 		}
sl@0: 	}