windowing/windowserver/test/tbufferdrawer/bufferdrawer.cpp
changeset 103 2717213c588a
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code
       
    20 */
       
    21 
       
    22 #include "bufferdrawer.h"
       
    23 #include <s32mem.h>
       
    24 #include <s32strm.h>
       
    25 #include <fbs.h>
       
    26 #include <bitdev.h>
       
    27 #include <bitstd.h>
       
    28 #include <graphics/wsgraphicscontext.h>
       
    29 #include <graphics/wsuibuffer.h>
       
    30 
       
    31 
       
    32 // CWsGraphicDrawer	
       
    33 CWsBufferGraphicDrawer* CWsBufferGraphicDrawer::NewL()
       
    34 	{
       
    35 	return new(ELeave) CWsBufferGraphicDrawer;	
       
    36 	}
       
    37 	
       
    38 CWsBufferGraphicDrawer::~CWsBufferGraphicDrawer()
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CWsBufferGraphicDrawer::ConstructL(MWsGraphicDrawerEnvironment& aEnv, const TGraphicDrawerId& aId, MWsClient& aOwner, const TDesC8& /*aData*/)
       
    43 	{
       
    44 	BaseConstructL(aEnv, aId, aOwner);
       
    45  	// default white line number
       
    46 	iWhiteLinePos = 0;
       
    47  	}
       
    48 
       
    49 void CWsBufferGraphicDrawer::HandleMessage(const TDesC8& aData)
       
    50 	{
       
    51 	TInt linePos = aData[0];
       
    52 	DoUpdateWhiteLinePos(linePos);
       
    53 	}
       
    54 
       
    55 void CWsBufferGraphicDrawer::DoUpdateWhiteLinePos(TInt aWhiteLinePos)
       
    56 	{
       
    57 	iWhiteLinePos = aWhiteLinePos;
       
    58 	// Invalidate the redrawing
       
    59 	Invalidate();
       
    60 	}
       
    61 
       
    62 void CWsBufferGraphicDrawer::DoDraw(MWsGc& aGc, const TRect& aRect, const TDesC8& /*aData*/) const
       
    63 	{
       
    64 	MWsGraphicsContext* context = static_cast<MWsGraphicsContext*>(aGc.ResolveObjectInterface(KMWsGraphicsContext));
       
    65 	
       
    66 	//Draw a filled rect with the chosen color
       
    67 	context->Push();
       
    68 	context->SetBrushStyle(MWsGraphicsContext::ESolidBrush);
       
    69 	context->SetBrushColor(KRgbBlue);
       
    70 	context->DrawRect(aRect);
       
    71 	context->Pop();
       
    72 	
       
    73 	//Obtain access to the screen/OSB buffer
       
    74 	MWsUiBuffer* buffer = static_cast<MWsUiBuffer*>(aGc.ResolveObjectInterface(KMWsUiBufferInterfaceId));
       
    75 	TAny* data;
       
    76 	TInt stride;
       
    77 	
       
    78 	TInt err = buffer->MapReadWrite(data, stride);
       
    79 	
       
    80 	if (err == KErrNone)
       
    81 		{
       
    82 		//Fill the chosen line with white
       
    83 		TUint8* scanLine = static_cast<TUint8*>(data);
       
    84 		scanLine += stride * iWhiteLinePos;
       
    85 		Mem::Fill(scanLine, stride, 0xFF);
       
    86 	
       
    87 		buffer->Unmap();
       
    88 		}
       
    89 	}