PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketHAL - BitBlt()

I'm new to Pocket PC programming, so maybe my question is really stupid.
I dind't find any Blit function in PocketHAL, so I assume that I have to write my own. Am I right?

I wrote this one, but I thing It's really slow:

Code:
void BitBltMasked(Surface& aDSurface, const TPoint& aPos, Surface& aSSurface, TRect& aSourceRect, uint16_t aMaskColor)
{
uint16_t *currDPix;
const uint16_t *currSPix;
uint16_t *dPixels = aDSurface.GetPixels(aPos.iX, aPos.iY);
const uint16_t *sPixels = aSSurface.GetPixels(aSourceRect.iTl.iX, aSourceRect.iTl.iY);

TInt width = aSourceRect.Width();
TInt height = aSourceRect.Height();
TInt dPitch = aDSurface.GetPitch() / 2;
TInt sPitch = aSSurface.GetPitch() / 2;

while (height--)
{
currDPix = dPixels;
currSPix = sPixels;

for (TInt cnt = 0; cnt < width; cnt++)
{
if (*currSPix++ != aMaskColor)
*currDPix = *currSPix;

currDPix++;
}

dPixels += dPitch;
sPixels += sPitch;
}
}


I would appreciate any comment.

Tomas

http://www.1-easysoft.com
This actually looks pretty good. Why do you think it is slow?

If you want more juice, assembly is probably required...
Some questions:
What is a TInt defined as?
<EDIT: too early...>
What kind of times are you seeing for a full screen blit?
TInt is simply an int (32 bits) in the Symbian SDKs.
Pejo Software - Per · 26 May 2004, 07:11 UTC
Why are you incrementing the currSPix before the assignment, isn't this wrong?

You can probably gain a small (neglectible) speed increase if you move the definition of currSPix and currDPix within te loop, (this could be compiler specific though).

If you wan't to go faster without using assembler you need to operate on 2 pixels at the same time. My tests shows about 15% speed increase there (if source and destination is aligned), and even more if you also apply effects like alpha blending.
Pejo Software - Per wrote:Why are you incrementing the currSPix before the assignment, isn't this wrong?


Yes, it's wrong.

Thanks a lot for all responses. I haven't got any PPC device yet, so I can't try it on a real device. But in the emulator it looks fast enough.

My current problem is a frame timing. This is my main game loop:

Code:
#define FRAME_TIME 1000 / 30

void CMyGame::GameLoop(void)
{
TUint time = GetClock();

// Count FPS
if (time - iLastSecondTime >= 1000)
{
iLastSecondTime = time;
iFPS = iTempFPS;
iTempFPS = 0;
}

// Draw a frame
if (time - iLastFrameTime >= FRAME_TIME)
{
iTempFPS++;
iLastFrameTime = time;

Surface *backBuf = iDisplay->GetBackBuffer();

if (backBuf == NULL)
return;

BitBlt(*backBuf, TPoint(0, 0), *iBackground);
iSpriteList->Render(*backBuf);

iDisplay->Swap(SWAP_VSYNC);
}
}


The problem is that the FPS should be 30 (FRAME_TIME = 1000 / 30), but the real FPS is 20 only.
If I define FRAME_TIME = 1000 / 50, than the real FPS is 40.
I can't get over 40 FPS (FRAME_TIME = 1000 / 1000 is still 40 FPS only), but if I delete the frame limitation (if (time - iLastFrameTime ....) than the FPS is about 300.

Am I doing something wrong?
The problem is probably in the GetClock() function. Time resolution of GetClock() is only 25 ms (in the emulator).