Search
lxdream.org :: lxdream/src/pvr2/pvr2.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2.c
changeset 1282:9f445c5e252b
prev1280:38f2b0e60261
next1291:8884bf45f010
author nkeynes
date Tue Mar 27 08:23:52 2012 +1000 (10 years ago)
permissions -rw-r--r--
last change Android: Preserve render buffers when switching away from app.
- fix gl_read_render_buffer + gl_load_frame_buffer to work in GLES
a) glReadPixels only (guaranteed to) work for GL_RGBA,GL_UNSIGNED_BYTE
b) glTexSubImage2D can only load GL_RGBA into a GL_RGBA render buffer.
file annotate diff log raw
1.1 --- a/src/pvr2/pvr2.c Wed Mar 21 14:45:27 2012 +1000
1.2 +++ b/src/pvr2/pvr2.c Tue Mar 27 08:23:52 2012 +1000
1.3 @@ -46,6 +46,7 @@
1.4 static render_buffer_t pvr2_get_render_buffer( frame_buffer_t frame );
1.5 static render_buffer_t pvr2_next_render_buffer( );
1.6 static render_buffer_t pvr2_frame_buffer_to_render_buffer( frame_buffer_t frame );
1.7 +static frame_buffer_t pvr2_render_buffer_to_frame_buffer( render_buffer_t frame );
1.8 uint32_t pvr2_get_sync_status();
1.9 static int output_colour_formats[] = { COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGR888, COLFMT_BGRA8888 };
1.10 static int render_colour_formats[8] = {
1.11 @@ -202,7 +203,6 @@
1.12 fwrite( &buffer->scale, sizeof(buffer->scale), 1, f );
1.13 int32_t flushed = (int32_t)buffer->flushed; // Force to 32-bits for save-file consistency
1.14 fwrite( &flushed, sizeof(flushed), 1, f );
1.15 -
1.16 }
1.17
1.18 render_buffer_t pvr2_load_render_buffer( FILE *f, gboolean *status )
1.19 @@ -870,7 +870,7 @@
1.20 int i;
1.21 for( i=0; i<render_buffer_count; i++ ) {
1.22 if( render_buffers[i] != NULL ) {
1.23 - display_driver->destroy_render_buffer(render_buffers[i]);
1.24 + pvr2_destroy_render_buffer(render_buffers[i]);
1.25 render_buffers[i] = NULL;
1.26 }
1.27 }
1.28 @@ -878,6 +878,57 @@
1.29 }
1.30 }
1.31
1.32 +static frame_buffer_t saved_render_buffers[MAX_RENDER_BUFFERS];
1.33 +static frame_buffer_t saved_displayed_render_buffer = NULL;
1.34 +static int saved_render_buffer_count = 0;
1.35 +
1.36 +/*
1.37 + * Copy all render buffers to main RAM to preserve across GL shutdown
1.38 + */
1.39 +void pvr2_preserve_render_buffers( void )
1.40 +{
1.41 + int i, j;
1.42 + /* If we had previous preserved buffers, blow them away now. */
1.43 + for( i=0; i<MAX_RENDER_BUFFERS; i++ ) {
1.44 + if( saved_render_buffers[i] != NULL ) {
1.45 + g_free(saved_render_buffers[i]);
1.46 + saved_render_buffers[i] = NULL;
1.47 + }
1.48 + }
1.49 + saved_displayed_render_buffer = NULL;
1.50 +
1.51 + for( i=0, j=0; i<render_buffer_count; i++ ) {
1.52 + if( render_buffers[i]->address != -1 ) {
1.53 + saved_render_buffers[j] = pvr2_render_buffer_to_frame_buffer(render_buffers[i]);
1.54 + if( render_buffers[i] == displayed_render_buffer )
1.55 + saved_displayed_render_buffer = saved_render_buffers[j];
1.56 + j++;
1.57 + }
1.58 + }
1.59 + saved_render_buffer_count = j;
1.60 +}
1.61 +
1.62 +/**
1.63 + * Restore render buffers that were preserved by a previous call to
1.64 + * pvr2_preserve_render_buffers().
1.65 + */
1.66 +void pvr2_restore_render_buffers( void )
1.67 +{
1.68 + int i;
1.69 + for( i=0; i<saved_render_buffer_count; i++ ) {
1.70 + if( saved_render_buffers[i] != NULL ) {
1.71 + render_buffers[i] = pvr2_frame_buffer_to_render_buffer(saved_render_buffers[i]);
1.72 + if( saved_render_buffers[i] == saved_displayed_render_buffer )
1.73 + displayed_render_buffer = render_buffers[i];
1.74 + g_free(saved_render_buffers[i]);
1.75 + saved_render_buffers[i] = NULL;
1.76 + }
1.77 + }
1.78 + render_buffer_count = saved_render_buffer_count;
1.79 + saved_render_buffer_count = 0;
1.80 + saved_displayed_render_buffer = NULL;
1.81 +}
1.82 +
1.83
1.84 void pvr2_finish_render_buffer( render_buffer_t buffer )
1.85 {
1.86 @@ -930,6 +981,7 @@
1.87 * display has it. Mark it as unaddressed for later.
1.88 */
1.89 render_buffers[i]->address = -1;
1.90 + render_buffers[i]->flushed = TRUE;
1.91 } else {
1.92 /* perfect */
1.93 result = render_buffers[i];
1.94 @@ -948,6 +1000,7 @@
1.95 pvr2_render_buffer_copy_to_sh4( render_buffers[i] );
1.96 }
1.97 render_buffers[i]->address = -1;
1.98 + render_buffers[i]->flushed = TRUE;
1.99 }
1.100 }
1.101
1.102 @@ -1038,6 +1091,23 @@
1.103 return result;
1.104 }
1.105
1.106 +static frame_buffer_t pvr2_render_buffer_to_frame_buffer( render_buffer_t buffer )
1.107 +{
1.108 + int bpp = colour_formats[buffer->colour_format].bpp;
1.109 + size_t size = buffer->width * buffer->height * bpp;
1.110 + frame_buffer_t result = g_malloc0( sizeof(struct frame_buffer) + size );
1.111 + result->data = (unsigned char *)(result+1);
1.112 + result->width = buffer->width;
1.113 + result->height = buffer->height;
1.114 + result->rowstride = buffer->rowstride;
1.115 + result->colour_format = buffer->colour_format;
1.116 + result->address = buffer->address;
1.117 + result->size = buffer->size;
1.118 + result->inverted = buffer->inverted;
1.119 + display_driver->read_render_buffer( result->data, buffer, buffer->width * bpp, buffer->colour_format );
1.120 + return result;
1.121 +}
1.122 +
1.123
1.124 /**
1.125 * Invalidate any caching on the supplied address. Specifically, if it falls
1.126 @@ -1056,6 +1126,7 @@
1.127 }
1.128 if( isWrite ) {
1.129 render_buffers[i]->address = -1; /* Invalid */
1.130 + render_buffers[i]->flushed = TRUE;
1.131 }
1.132 return TRUE; /* should never have overlapping buffers */
1.133 }
.