PocketMatrix forums

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

Small suggestion

Hi,

Here is a small suggestion. Add a CopyFrom(source) function to surface that simply copy the source surface to the destination surface, if both are the same size.

Code:

//
DestSurface->CopyFrom(SourceSurface);
//


Of course I can use BltFast() for this, but the above call wouldn't need extra parameters and be much more intuitive, IMO.

I know, I know, I'm lazy. But I find that I use lots of BltFast() that just copy one surface to another and specifying parameters that are never used is such a waste...

Thanks!

--Eric
Perhaps "CreateSurface(CGapiSurface* pSourceSurface)" would do?

CGapiSurface source;
CGapiSurface dest;

source.CreateSurface( /from file or whatever/ );
dest.CreateSurface(&source);
*cough* copy constructor *cough* copy assignment operator *cough*
:D
IMHO copy constructors and assignment operators are pretty useless for objects that allocate heap memory since you can't get a return code from the constructor.
I do like them for small objects that have all their data as member variables though (such as CPoint and CRect)..
The surface->CreateSurface(*src) method would work nicely provided it reuses/reallocates previously created surfaces.
Johan wrote:
Perhaps "CreateSurface(CGapiSurface* pSourceSurface)" would do?

CGapiSurface source;
CGapiSurface dest;

source.CreateSurface( /from file or whatever/ );
dest.CreateSurface(&source;);

This would indeed be useful, but my original suggestion was in the context of blitting, to ease blitting and prevent the passing of several parameters that are not used in the main blit loop.

Thanks!

--Eric
That would probably be better served with a helper method on your part. I have a number of helpers that recreate surfaces and do blts without the need for passing parameters, but they are specialized towards my particular needs (ie certain flags set within the helper).
Yes, it would be easy to write. However, I'm under the feeling that if the function was to be inside GapiDraw, it would be much faster, thanks to Johan amazing abilities ;)

I don't have much knowledge about the cache and how it works, and I fear I might just make a slower function than the BltFast().

Would a memcpy() be possible, and if so, would it be cache optimized?

Thanks!

--Eric
No,no, I'm not saying to recreate BltFast. I'm saying that what I do is put a wrapper around BltFast so I don't have to set the same flags all the time. For instance (off the top of my head for a simple text drawing wrapper for centered, colorized text)

Code:
HRESULT MyClass::DrawColoredText_CENTERED(POINT _p, COLORREF _color)
{
HRESULT hr = GD_OK;

// set up the fx
GDBLTFASTFX gdfx;
gdfx.dwMultiplyOpacity = 255;
gdfx.dwMultiplyColor = _color;

// get the backbuffer
CGapiSurface backbuffer;
hr = m_display->getBackBuffer(&backbuffer;); if(hr != GD_OK) return hr;

// draw the centered, colorized text using a predefined font
hr = backbuffer.DrawText(_p.x, _p.y, &m;_yourFont, GDDRAWTEXT_CENTER, 0, GDBLTFAST_MULTIPLY | GDBLTFAST_MULTIPLYOPACITY, &gdfx;); if(hr != GD_OK) return hr;

return GD_OK;
}


This is just an example of how I wrap up functions that I use over and over. I think you and I are talking about the same thing.
Johan wrote:
:D
IMHO copy constructors and assignment operators are pretty useless for objects that allocate heap memory since you can't get a return code from the constructor.
I do like them for small objects that have all their data as member variables though (such as CPoint and CRect)..


I guess return codes are an issue on the Pocket PC. Normally, you indicate failure in a constructor by throwing an exception. But we don't have exception support in generally available compilers.
agreed...
ppcStudios is correct, it is a sign of good programming style if you make nice wrappers like that in your code for things you want, but shouldn't generally put in the library. E.g. Stroustrup shows you how to wrap the legacy C APIs you use for use in C++. They're not in the standard library, but if you want that kind of convenience when interfacing with legacy code, it's easy to do on your own.

One issue though is all those parameters are still being passed off to the GapiDraw DLL. If GapiDraw actually had a version that did the basics (say a straight copy) and didn't just forward with parameters internally, and you did a *lot* of such calls, there might be a speedup from having a streamlined API.

I can tell you that most of my image drawing is neither scaled nor rotated, and about the only effect I use is key source. If there were an API which took a source surface and rectangle, a destination point, and did a key source blit, I'd be happy as that's most of what I do: take a piece of image from a tiled surface, and blast it to the screen (with key source) at a certain point.
ppcStudios wrote:This is just an example of how I wrap up functions that I use over and over. I think you and I are talking about the same thing.

I understand what you describe, but what I was talking about was in an effort to squeeze the last bit of speed out of GapiDraw ;)


mlepage wrote:One issue though is all those parameters are still being passed off to the GapiDraw DLL. If GapiDraw actually had a version that did the basics (say a straight copy) and didn't just forward with parameters internally, and you did a *lot* of such calls, there might be a speedup from having a streamlined API.

Yes, this is exactly what I mean. I have a screen system that needs a good deal of straight copies with just the surface as the parameter.

Squeezing the library for such gains might not be worth much for some people, but for other it might. In the context of 3D engine programming, I think that having fast 2D functions is as important as fast 3D. It may allow a few more polygons on screen, or inclusion of another feature.

--Eric
efortier: Actually, there are so many paths in BltFast that it's difficult to count them all.

First of all GD checks if rectangle sizes and pitch values match. If they do (i.e. you are copying an entire surface that exactly matches the size of the other) memcpy will be used. I have some ARM assember that will be in a future release that's a bit faster so I can reach those 30% improvements Thierry got with PocketHAL for full backbuffer -> display copy.

Basically after that it's a multitude of paths, for copying rows with the same width with no flags, copying with different effects, etc.

So. Adding a new CopySurface() would not improve performance much more than that less variables has to be pushed to the stack..