applications/Symbian_MiniGUI_TestApp/yuv.cpp
author Faisal Memon <faisal.memon@nokia.com>
Thu, 25 Mar 2010 22:08:14 +0000
changeset 67 57a5a30dc911
child 68 535d0a02b797
permissions -rw-r--r--
Add a yuv based test program for YUV surface support testing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     1
#include <w32std.h> 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     2
#include "profiler.h"
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     3
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     4
#include <graphics/surfacemanager.h>
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     5
#include <graphics/surfaceupdateclient.h>
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     6
const TSize KSize(64,60);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     7
const TInt KRow = 4;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     8
const TInt KCol = 5; 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
     9
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    10
void MainL()	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    11
	{	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    12
	RWsSession ws;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    13
	ws.Connect();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    14
 	CWsScreenDevice* scr = new(ELeave) CWsScreenDevice(ws);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    15
	scr->Construct();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    16
 	CWindowGc* gc = new(ELeave) CWindowGc(scr);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    17
	gc->Construct();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    18
 	RWindowGroup grp(ws);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    19
	grp.Construct(0xc0decafe, ETrue);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    20
 	RWindow win(ws);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    21
	win.Construct(grp, 0xbeefcafe);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    22
	win.SetExtent(TPoint(20,160), TSize(320,240));
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    23
	win.Activate();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    24
 	win.Invalidate();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    25
	win.BeginRedraw();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    26
	gc->Activate(win);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    27
 	gc->SetPenStyle(CGraphicsContext::ENullPen);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    28
	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    29
 	TBool color = EFalse;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    30
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    31
if (Profiler::Start() == KErrNotFound)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    32
	{
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    33
	_LIT(KProfiler,"profiler");
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    34
	_LIT(KStart,"start -noui -drive=S");
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    35
	RProcess p;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    36
	if (p.Create(KProfiler,KStart) == KErrNone)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    37
		{
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    38
		p.Resume();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    39
		p.Close();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    40
		}
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    41
	}
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    42
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    43
	for (TInt col=0; col<KCol; ++col)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    44
		{
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    45
		color = !color;		
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    46
		for (TInt row=0; row<KRow; ++row)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    47
			{
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    48
			TRect rect;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    49
			rect.iTl.iX = col * KSize.iWidth;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    50
			rect.iTl.iY = row * KSize.iHeight;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    51
			rect.SetSize(KSize);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    52
			color = !color;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    53
			gc->SetBrushColor(color? KRgbGreen : KRgbBlack);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    54
			gc->DrawRect(rect);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    55
			}
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    56
	}
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    57
	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    58
	// Open the surface manager
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    59
	RSurfaceManager surfaceManager;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    60
	User::LeaveIfError(surfaceManager.Open());
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    61
	// Store the attributes used to create the Surface
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    62
	RSurfaceManager::TSurfaceCreationAttributesBuf buf;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    63
	RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    64
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    65
	attributes.iSize = TSize(361,341);      // w > 0, h > 0
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    66
	attributes.iBuffers = 4;                // > 0, <= 4
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    67
	attributes.iPixelFormat = EUidPixelFormatYUV_422Planar; // 2bpp
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    68
	attributes.iStride = 1400;              // > 0,  width * bpp
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    69
	attributes.iOffsetToFirstBuffer = 184;  // > 0, divisible by alignment
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    70
	attributes.iAlignment = 4;              // 1 || 2 || 4 || 8
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    71
	attributes.iContiguous = EFalse;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    72
	attributes.iMappable = ETrue;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    73
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    74
	RSurfaceManager::THintPair hints[2];         // two hint pairs specified
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    75
	attributes.iHintCount=2;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    76
	hints[0].Set(TUid::Uid(0x124578), 20, ETrue);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    77
	hints[1].Set(TUid::Uid(0x237755), 50, EFalse);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    78
	attributes.iSurfaceHints = hints;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    79
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    80
	attributes.iOffsetBetweenBuffers = 0;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    81
	// Create a surface
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    82
	TSurfaceId surfaceId;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    83
	User::LeaveIfError(surfaceManager.CreateSurface(buf, surfaceId));
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    84
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    85
	// We have a surface, so map it in.
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    86
	RChunk chunk;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    87
	TInt err = surfaceManager.MapSurface(surfaceId, chunk);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    88
	if ( err == KErrNone)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    89
	    { 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    90
	    // Get info about it
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    91
	    RSurfaceManager::TInfoBuf buf;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    92
	    RSurfaceManager::TSurfaceInfoV01& surfaceInfo = buf(); 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    93
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    94
	    surfaceManager.SurfaceInfo(surfaceId, buf); 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    95
	    }
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    96
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    97
	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    98
	win.SetBackgroundSurface(surfaceId);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
    99
	gc->Deactivate();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   100
	win.EndRedraw();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   101
	ws.Flush();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   102
 	User::After(3000000);
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   103
 	win.Close();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   104
	grp.Close();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   105
	delete gc;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   106
	delete scr;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   107
	ws.Close();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   108
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   109
	Profiler::Stop();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   110
	Profiler::Close();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   111
	Profiler::Unload();
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   112
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   113
	} 
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   114
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   115
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   116
GLDEF_C TInt E32Main()	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   117
{	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   118
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   119
	CTrapCleanup* tc = CTrapCleanup::New();	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   120
	if (!tc)
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   121
		{		
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   122
		return KErrNoMemory;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   123
		}
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   124
	TRAPD(err, MainL());
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   125
	delete tc;
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   126
 	return err;	
57a5a30dc911 Add a yuv based test program for YUV surface support testing.
Faisal Memon <faisal.memon@nokia.com>
parents:
diff changeset
   127
}