Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 12
Registered: ‎06-01-2011
My Device: Blackberry Tourch
My Carrier: 3 mobile

Sample: Drawing using Blits, Pixmaps, and Buffers

Hi Folks,

I am a bit confused and I hope someone can set me straight on this.

In the sample code for 'Drawing using Blits, Pixmaps, and Buffers.  The example states that the code is using a double buffer for drawing to the screen, which is reflected in the code given as:

screen_create_window_buffers(screen_win, 2);

 
On every iteration of the main loop the example gets a pointer to those buffers using the code:

screen_buffer_t    screen_buf[2];
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_buf);

 

However all drawing seems to be done to screen_buf[0] which is only 1 of the buffers, code as below:

 

screen_blit(screen_ctx, screen_buf[0], screen_pbuf, hg);
screen_post_window(screen_win, screen_buf[0], 1, rect, 0);

 

So my questions are as follows:

1) is it necessary to get a a pointer to the buffers on each iteration of the main loop?
2) Does the example fail to use both buffers, even though it stated that It would be using a double buffer?
3) or does the buffer swap occur automatically perhaps on a call to screen_post_window() which is why the example is re-obtaining the pointers to the buffer on each iteration and why drawing is always done to screen_buf[0]?

I am confused because, If 'I' (the programmer) am supposed to handle the swap of the buffers then the example would appear to be incorrect in that it is not using both buffers.  If the swap occurs automatically the example does not make clear at what point that occurs and that you should only draw to screen_buf[0] as it is constantly pointing to the current back buffer.

I hope that you find the above straight forward to follow.  All help is appreciated.

New Contributor
Posts: 7
Registered: ‎04-06-2012
My Device: Playbook
My Carrier: AT&T

Re: Sample: Drawing using Blits, Pixmaps, and Buffers

From my observation (you could just print out the pointer of the screen_pbuf[0]):
Your (3) is correct. After screen_post_window, SCREEN_PROPERTY_RENDER_BUFFERS is the back buffer, and SCREEN_PROPERTY_FRONT_BUFFER is the front buffer.
Buffer swap happens at screen_post_window API call.