Giving thanks…framebuffer style.
For those in the Unites States, you may be eating up turkey with the family…But me, well I’m giving my thanks in a different way. I couldn’t stop playing with this framebuffer code for the iPhone I mentioned earlier. I now know of the two framebuffer addresses and how to retrieve them individually.
Why is this important? Well it’s all about my emulator’s performance in our case!
But are you willing to give up transparent overlays in landscape mode for this performance boost? Remember for this to work it will draw on top of every area I write to. So if you are in landscape mode, for performance reasons I can’t draw an opaque overlay on top of each frame I draw. And blending a semi-transparent overlay is out of question. What we are left with is possibly to center the emulator screen in the center, and have controls on the sides. Leaving the controls outside of the emulation screen could let things work.
Some quick benchmarks I ran show the average blit to a CoreSurface buffer to draw to the screen takes between 5 and 13ms per blit. It spikes constantly from that 5ms. If I simply have it write to a different buffer that is malloc’d, the blit takes less than 1ms. While this isn’t scientific, it indicates to me that the traditional way of writing to the screen via CoreSurface, while better than OpenGL ES (for this type of blit) and CoreGraphics, is still very slow. This is where getting a lower level access to the screen’s pixel data comes into play, and hence the framebuffers.
I noticed writing to the first framebuffer with CoreSurface ID 1 (more on this in a sec) is about the same speed as writing to a CoreSurface you can create on your own. The magic happens when you write to the second CoreSurface ID 2. The above test of 5ms – 13ms goes down to 2ms! Much better, considering you only have 16ms to deal with when running at 60 FPS.
So how do you access these framebuffers? Leaving behind the complex code mentioned earlier, here’s how. First add the CoreSurface framework to your project. Then:
extern void* CoreSurfaceBufferGetBaseAddress(CoreSurfaceBufferRef surface);
extern void* CoreSurfaceBufferLookup(long lookup);
...
void* framebufferID1 = CoreSurfaceBufferGetBaseAddress(CoreSurfaceBufferLookup(1));
void* framebufferID2 = CoreSurfaceBufferGetBaseAddress(CoreSurfaceBufferLookup(2));
...
Simple as that! You now have a pointer to each framebuffer. Simply write your ARGB pixel data straight to it!
Maybe psx4iphone could use this technique for an added performance increase?
Thanks,
ZodTTD