Created
January 22, 2019 17:48
-
-
Save frednora/32ea7c6a45b4a382837ecbb068194e14 to your computer and use it in GitHub Desktop.
Refresh rectangle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
refresh_rectangle ( unsigned long x, | |
unsigned long y, | |
unsigned long width, | |
unsigned long height ) | |
{ | |
void *p = (void *) FRONTBUFFER_ADDRESS; | |
const void *q = (const void*) BACKBUFFER_ADDRESS; | |
//#TEST | |
register unsigned int i; | |
//unsigned int i; | |
unsigned int line_size, lines; | |
unsigned int offset; | |
unsigned long Width = (unsigned long) screenGetWidth(); | |
unsigned long Height = (unsigned long) screenGetHeight(); | |
line_size = (unsigned int) width; | |
lines = (unsigned int) height; | |
// = 3; | |
//24bpp | |
int bytes_count; | |
switch (SavedBPP) | |
{ | |
case 32: | |
bytes_count = 4; | |
break; | |
case 24: | |
bytes_count = 3; | |
break; | |
//... | |
} | |
//offset = (unsigned int) BUFFER_PIXEL_OFFSET( x, y ); | |
offset = (unsigned int) ( (bytes_count*SavedX*(y)) + (bytes_count*(x)) ); | |
p = (void *) (p + offset); | |
q = (const void *) (q + offset); | |
vsync (); | |
//(line_size * bytes_count) é o número de bytes por linha. | |
int count; | |
//#importante | |
//É bem mais rápido com múltiplos de 4. | |
//se for divisível por 4. | |
if ( ((line_size * bytes_count) % 4) == 0 ) | |
{ | |
count = ((line_size * bytes_count) / 4); | |
for ( i=0; i < lines; i++ ) | |
{ | |
//copia uma linha ou um pouco mais caso não seja divisível por | |
memcpy32 ( p, q, count ); | |
q += (Width * bytes_count); | |
p += (Width * bytes_count); | |
}; | |
} | |
//se não for divisível por 4. | |
if ( ((line_size * bytes_count) % 4) != 0 ) | |
{ | |
for ( i=0; i < lines; i++ ) | |
{ | |
memcpy ( (void *) p, (const void *) q, (line_size * bytes_count) ); | |
q += (Width * bytes_count); | |
p += (Width * bytes_count); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eu tenho essa rotina de 'refresh rectangle'. Se a largura é múltiplo de 4 então ela copia a memória de 4 em 4 bytes, se não é múltiplo de 4 então ela copia de 1 em 1.
Eu quero que a rotina copie de 4 em 4 bytes mesmo quando não seja múltiplo de 4, podendo copiar bytes extras, chamados de padding.