1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/windows/twindow.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,158 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +
1.26 +#include "twindow.h"
1.27 +
1.28 +#include <hal.h>
1.29 +#include <ImageConversion.h>
1.30 +
1.31 +
1.32 +/**
1.33 +Gets the size of the hardware display in pixels
1.34 +@return TSize object containing the screen size
1.35 +*/
1.36 +TSize CTWindow::GetDisplaySizeInPixels()
1.37 + {
1.38 + static TSize displaySize;
1.39 + static TBool first = ETrue;
1.40 + if (first)
1.41 + {
1.42 + RWsSession ws;
1.43 + ws.Connect();
1.44 + CWsScreenDevice* screen = new(ELeave) CWsScreenDevice(ws);
1.45 + screen->Construct();
1.46 + TPixelsAndRotation pixelsAndRotation;
1.47 + screen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
1.48 + delete screen;
1.49 + ws.Close();
1.50 + displaySize = pixelsAndRotation.iPixelSize;
1.51 + first = EFalse;
1.52 + }
1.53 + /*
1.54 + // that doesn't work for S60 emulator, it returns wrong values
1.55 + TInt x;
1.56 + HAL::Get(HALData::EDisplayXPixels, x); // Get number x pixel of screen
1.57 + TInt y;
1.58 + HAL::Get(HALData::EDisplayYPixels, y); // Get number y pixel of screen
1.59 + return TSize(x,y);
1.60 + */
1.61 + return displaySize;
1.62 + }
1.63 +
1.64 +CFbsBitmap* CTWindow::CreateBitmapFromFileL(const TDesC& aFileName)
1.65 + {
1.66 + RFs fs;
1.67 + User::LeaveIfError(fs.Connect());
1.68 + CleanupClosePushL(fs);
1.69 + CImageDecoder* decoder = CImageDecoder::FileNewL(fs, aFileName, CImageDecoder::EOptionAlwaysThread);
1.70 + CleanupStack::PushL(decoder);
1.71 +
1.72 + CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
1.73 + CleanupStack::PushL(bitmap);
1.74 + const TFrameInfo& info = decoder->FrameInfo();
1.75 + User::LeaveIfError(bitmap->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode));
1.76 + TRequestStatus status;
1.77 + decoder->Convert(&status, *bitmap);
1.78 + User::WaitForRequest(status);
1.79 + User::LeaveIfError(status.Int());
1.80 +
1.81 + CleanupStack::Pop(bitmap);
1.82 + CleanupStack::PopAndDestroy(decoder);
1.83 + CleanupStack::PopAndDestroy(&fs);
1.84 + return bitmap;
1.85 + }
1.86 +
1.87 +CTWindow::CTWindow(const TPoint& aStartingPoint, const TSize& aWindowSize) :
1.88 + iLoaded(EFalse), iSize(aWindowSize), iPosition(aStartingPoint)
1.89 + {
1.90 + iScreenSize = GetDisplaySizeInPixels();
1.91 + }
1.92 +
1.93 +void CTWindow::ConstructL(RWsSession &aWs, const RWindowTreeNode &aParent)
1.94 + {
1.95 + // Create a window with the window group as a parent
1.96 + iWindow = RWindow(aWs);
1.97 + // it's common to use the address of the owning object as an unique window handle
1.98 + User::LeaveIfError(iWindow.Construct(aParent, reinterpret_cast<TUint32>(this)));
1.99 + iWindow.SetPosition(iPosition);
1.100 + iWindow.SetSize(iSize);
1.101 +
1.102 + // Activate window and set it invisible
1.103 + iWindow.Activate();
1.104 + iWindow.SetVisible(EFalse);
1.105 + }
1.106 +
1.107 +CTWindow::~CTWindow()
1.108 + {
1.109 + iDirtyRegion.Close();
1.110 + iWindow.Close();
1.111 + }
1.112 +
1.113 +void CTWindow::LoadL(CSurfaceUtility* /*aUtility*/, TPtrC /*aFileName*/)
1.114 + {
1.115 + // empty
1.116 + }
1.117 +
1.118 +void CTWindow::RenderL()
1.119 + {
1.120 + iWindow.SetVisible(ETrue);
1.121 + iDirtyRegion.Clear();
1.122 + iDirtyRegion.AddRect(TRect(TPoint(0, 0), iScreenSize));
1.123 + iDirtyRegion.ClipRect(TRect(iPosition, iSize));
1.124 + }
1.125 +
1.126 +void CTWindow::Move(TInt aX, TInt aY)
1.127 + {
1.128 + iPosition.iX += aX;
1.129 + iPosition.iY += aY;
1.130 + iWindow.SetPosition(iPosition);
1.131 + }
1.132 +
1.133 +TPoint CTWindow::CurrentPosition()
1.134 + {
1.135 + return iPosition;
1.136 + }
1.137 +
1.138 +void CTWindow::SetPosition(TInt aX, TInt aY)
1.139 + {
1.140 + iPosition.SetXY(aX, aY);
1.141 + }
1.142 +
1.143 +void CTWindow::SetVisible(TBool aIsVisible)
1.144 + {
1.145 + iWindow.SetVisible(aIsVisible);
1.146 + }
1.147 +
1.148 +const RRegion& CTWindow::DirtyRegion() const
1.149 + {
1.150 + return iDirtyRegion;
1.151 + }
1.152 +
1.153 +TInt CTWindow::SetBackgroundSurface(const TSurfaceId& aSurface)
1.154 + {
1.155 + return iWindow.SetBackgroundSurface(aSurface);
1.156 + }
1.157 +
1.158 +TSize CTWindow::Size()
1.159 + {
1.160 + return iWindow.Size();
1.161 + }