Remove several more low-level graphic primitives from packages/video.c into libopenbios/video_common.c.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- openbios-devel/arch/sparc32/openbios.c | 2 +- openbios-devel/drivers/vga_vbe.c | 2 +- openbios-devel/include/libopenbios/video.h | 7 +- openbios-devel/include/packages/video.h | 5 +- openbios-devel/libopenbios/video_common.c | 205 ++++++++++++++++++++++++++++ openbios-devel/packages/video.c | 196 +------------------------- 6 files changed, 215 insertions(+), 202 deletions(-)
diff --git a/openbios-devel/arch/sparc32/openbios.c b/openbios-devel/arch/sparc32/openbios.c index 8537c1e..ef3c973 100644 --- a/openbios-devel/arch/sparc32/openbios.c +++ b/openbios-devel/arch/sparc32/openbios.c @@ -22,7 +22,7 @@ #include "boot.h" #include "romvec.h" #include "openprom.h" -#include "packages/video.h" +#include "libopenbios/video.h" #define NO_QEMU_PROTOS #include "arch/common/fw_cfg.h" #include "arch/sparc32/ofmem_sparc32.h" diff --git a/openbios-devel/drivers/vga_vbe.c b/openbios-devel/drivers/vga_vbe.c index 569e70d..f7a736f 100644 --- a/openbios-devel/drivers/vga_vbe.c +++ b/openbios-devel/drivers/vga_vbe.c @@ -25,7 +25,7 @@ #include "asm/io.h" #include "libc/vsprintf.h" #include "drivers/vga.h" -#include "packages/video.h" +#include "libopenbios/video.h" #include "libopenbios/ofmem.h"
/* VGA init. We use the Bochs VESA VBE extensions */ diff --git a/openbios-devel/include/libopenbios/video.h b/openbios-devel/include/libopenbios/video.h index dbc1747..75e96c2 100644 --- a/openbios-devel/include/libopenbios/video.h +++ b/openbios-devel/include/libopenbios/video.h @@ -1,7 +1,12 @@
+void init_video(unsigned long fb, int width, int height, int depth, int rb); unsigned long get_color(int col_ind); void set_color(int ind, unsigned long color); -void video_mask_blit(void); +void refresh_palette(void); +int video_get_res(int *w, int *h); +void draw_pixel(int x, int y, int colind); +void video_scroll(int height); +void fill_rect(int col_ind, int x, int y, int w, int h);
typedef struct osi_fb_info { unsigned long mphys; diff --git a/openbios-devel/include/packages/video.h b/openbios-devel/include/packages/video.h index 39ae8df..2b7f412 100644 --- a/openbios-devel/include/packages/video.h +++ b/openbios-devel/include/packages/video.h @@ -2,9 +2,6 @@ #define VIDEO_SUBR_H
/* packages/video.c */ -int video_get_res(int *w, int *h); -void draw_pixel(int x, int y, int colind); -void video_scroll(int height); -void init_video(unsigned long fb, int width, int height, int depth, int rb); +void molvideo_init(void);
#endif /* VIDEO_SUBR_H */ diff --git a/openbios-devel/libopenbios/video_common.c b/openbios-devel/libopenbios/video_common.c index 0c61e3a..0892859 100644 --- a/openbios-devel/libopenbios/video_common.c +++ b/openbios-devel/libopenbios/video_common.c @@ -16,6 +16,7 @@
#include "config.h" #include "libopenbios/bindings.h" +#include "libopenbios/ofmem.h" #include "libopenbios/video.h" #include "packages/video.h" #include "drivers/vga.h" @@ -62,3 +63,207 @@ set_color( int ind, unsigned long color ) (color & 0xff)); #endif } + +static void +startup_splash( void ) +{ +#ifdef CONFIG_MOL + int fd, s, i, y, x, dx, dy; + int width, height; + char *pp, *p; + char buf[64]; +#endif + + /* only draw logo in 24-bit mode (for now) */ + if( video.fb.depth < 15 ) + return; +#ifdef CONFIG_MOL + for( i=0; i<2; i++ ) { + if( !BootHGetStrResInd("bootlogo", buf, sizeof(buf), 0, i) ) + return; + *(!i ? &width : &height) = atol(buf); + } + + if( (s=width * height * 3) > 0x20000 ) + return; + + if( (fd=open_io("pseudo:,bootlogo")) >= 0 ) { + p = malloc( s ); + if( read_io(fd, p, s) != s ) + printk("bootlogo size error\n"); + close_io( fd ); + + dx = (video.fb.w - width)/2; + dy = (video.fb.h - height)/3; + + pp = (char*)video.fb.mvirt + dy * video.fb.rb + dx * (video.fb.depth >= 24 ? 4 : 2); + + for( y=0 ; y<height; y++, pp += video.fb.rb ) { + if( video.fb.depth >= 24 ) { + unsigned long *d = (unsigned long*)pp; + for( x=0; x<width; x++, p+=3, d++ ) + *d = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2]; + } else if( video.fb.depth == 15 ) { + unsigned short *d = (unsigned short*)pp; + for( x=0; x<width; x++, p+=3, d++ ) { + int col = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2]; + *d = ((col>>9) & 0x7c00) | ((col>>6) & 0x03e0) | ((col>>3) & 0x1f); + } + } + } + free( p ); + } +#else + /* No bootlogo support yet on other platforms */ + return; +#endif +} + +int +video_get_res( int *w, int *h ) +{ + if( !video.has_video ) { + *w = *h = 0; + return -1; + } + *w = video.fb.w; + *h = video.fb.h; + return 0; +} + +void +draw_pixel( int x, int y, int colind ) +{ + char *p = (char*)video.fb.mvirt + video.fb.rb * y; + int color, d = video.fb.depth; + + if( x < 0 || y < 0 || x >= video.fb.w || y >=video.fb.h ) + return; + color = get_color( colind ); + + if( d >= 24 ) + *((unsigned long*)p + x) = color; + else if( d >= 15 ) + *((short*)p + x) = color; + else + *(p + x) = color; +} + +void +video_scroll( int height ) +{ + int i, offs, size, *dest, *src; + + if (height <= 0 || height >= video.fb.h) { + return; + } + offs = video.fb.rb * height; + size = (video.fb.h * video.fb.rb - offs)/16; + dest = (int*)video.fb.mvirt; + src = (int*)(video.fb.mvirt + offs); + + for( i=0; i<size; i++ ) { + dest[0] = src[0]; + dest[1] = src[1]; + dest[2] = src[2]; + dest[3] = src[3]; + dest += 4; + src += 4; + } +} + +void +fill_rect( int col_ind, int x, int y, int w, int h ) +{ + char *pp; + unsigned long col = get_color(col_ind); + + if (!video.has_video || x < 0 || y < 0 || w <= 0 || h <= 0 || + x + w > video.fb.w || y + h > video.fb.h) + return; + + pp = (char*)video.fb.mvirt + video.fb.rb * y; + for( ; h--; pp += video.fb.rb ) { + int ww = w; + if( video.fb.depth == 24 || video.fb.depth == 32 ) { + unsigned long *p = (unsigned long*)pp + x; + while( ww-- ) + *p++ = col; + } else if( video.fb.depth == 16 || video.fb.depth == 15 ) { + unsigned short *p = (unsigned short*)pp + x; + while( ww-- ) + *p++ = col; + } else { + char *p = (char *)(pp + x); + + while( ww-- ) + *p++ = col; + } + } +} + +void +refresh_palette( void ) +{ +#ifdef CONFIG_MOL + if( video.fb.depth == 8 ) + OSI_RefreshPalette(); +#endif +} + +void +init_video( unsigned long fb, int width, int height, int depth, int rb ) +{ + int i; +#if defined(CONFIG_OFMEM) && defined(CONFIG_DRIVER_PCI) + int size; +#endif + phandle_t ph=0, saved_ph=0; + + video.fb.mphys = video.fb.mvirt = fb; + +#if defined(CONFIG_SPARC64) + /* Fix virtual address on SPARC64 somewhere else */ + video.fb.mvirt = 0xfe000000; +#endif + + video.fb.w = width; + video.fb.h = height; + video.fb.depth = depth; + video.fb.rb = rb; + + saved_ph = get_cur_dev(); + while( (ph=dt_iterate_type(ph, "display")) ) { + set_int_property( ph, "width", video.fb.w ); + set_int_property( ph, "height", video.fb.h ); + set_int_property( ph, "depth", video.fb.depth ); + set_int_property( ph, "linebytes", video.fb.rb ); + set_int_property( ph, "address", video.fb.mvirt ); + + activate_dev(ph); + molvideo_init(); + } + video.has_video = 1; + video.pal = malloc( 256 * sizeof(unsigned long) ); + activate_dev(saved_ph); + + PUSH(video.fb.mvirt); + feval("to frame-buffer-adr"); + +#if defined(CONFIG_OFMEM) && defined(CONFIG_DRIVER_PCI) + size = ((video.fb.h * video.fb.rb) + 0xfff) & ~0xfff; + + ofmem_claim_phys( video.fb.mphys, size, 0 ); + ofmem_claim_virt( video.fb.mvirt, size, 0 ); + ofmem_map( video.fb.mphys, video.fb.mvirt, size, ofmem_arch_io_translation_mode(video.fb.mphys) ); +#endif + + for( i=0; i<256; i++ ) + set_color( i, i * 0x010101 ); + + set_color( 254, 0xffffcc ); + fill_rect( 254, 0, 0, video.fb.w, video.fb.h ); + + refresh_palette(); + startup_splash(); +} diff --git a/openbios-devel/packages/video.c b/openbios-devel/packages/video.c index bcc9dfc..2c2aeac 100644 --- a/openbios-devel/packages/video.c +++ b/openbios-devel/packages/video.c @@ -25,153 +25,6 @@ #include "drivers/vga.h"
-int -video_get_res( int *w, int *h ) -{ - if( !video.has_video ) { - *w = *h = 0; - return -1; - } - *w = video.fb.w; - *h = video.fb.h; - return 0; -} - -static void -startup_splash( void ) -{ -#ifdef CONFIG_MOL - int fd, s, i, y, x, dx, dy; - int width, height; - char *pp, *p; - char buf[64]; -#endif - - /* only draw logo in 24-bit mode (for now) */ - if( video.fb.depth < 15 ) - return; -#ifdef CONFIG_MOL - for( i=0; i<2; i++ ) { - if( !BootHGetStrResInd("bootlogo", buf, sizeof(buf), 0, i) ) - return; - *(!i ? &width : &height) = atol(buf); - } - - if( (s=width * height * 3) > 0x20000 ) - return; - - if( (fd=open_io("pseudo:,bootlogo")) >= 0 ) { - p = malloc( s ); - if( read_io(fd, p, s) != s ) - printk("bootlogo size error\n"); - close_io( fd ); - - dx = (video.fb.w - width)/2; - dy = (video.fb.h - height)/3; - - pp = (char*)video.fb.mvirt + dy * video.fb.rb + dx * (video.fb.depth >= 24 ? 4 : 2); - - for( y=0 ; y<height; y++, pp += video.fb.rb ) { - if( video.fb.depth >= 24 ) { - unsigned long *d = (unsigned long*)pp; - for( x=0; x<width; x++, p+=3, d++ ) - *d = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2]; - } else if( video.fb.depth == 15 ) { - unsigned short *d = (unsigned short*)pp; - for( x=0; x<width; x++, p+=3, d++ ) { - int col = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2]; - *d = ((col>>9) & 0x7c00) | ((col>>6) & 0x03e0) | ((col>>3) & 0x1f); - } - } - } - free( p ); - } -#else - /* No bootlogo support yet on other platforms */ - return; -#endif -} - -void -draw_pixel( int x, int y, int colind ) -{ - char *p = (char*)video.fb.mvirt + video.fb.rb * y; - int color, d = video.fb.depth; - - if( x < 0 || y < 0 || x >= video.fb.w || y >=video.fb.h ) - return; - color = get_color( colind ); - - if( d >= 24 ) - *((unsigned long*)p + x) = color; - else if( d >= 15 ) - *((short*)p + x) = color; - else - *(p + x) = color; -} - -static void -fill_rect( int col_ind, int x, int y, int w, int h ) -{ - char *pp; - unsigned long col = get_color(col_ind); - - if (!video.has_video || x < 0 || y < 0 || w <= 0 || h <= 0 || - x + w > video.fb.w || y + h > video.fb.h) - return; - - pp = (char*)video.fb.mvirt + video.fb.rb * y; - for( ; h--; pp += video.fb.rb ) { - int ww = w; - if( video.fb.depth == 24 || video.fb.depth == 32 ) { - unsigned long *p = (unsigned long*)pp + x; - while( ww-- ) - *p++ = col; - } else if( video.fb.depth == 16 || video.fb.depth == 15 ) { - unsigned short *p = (unsigned short*)pp + x; - while( ww-- ) - *p++ = col; - } else { - char *p = (char *)(pp + x); - - while( ww-- ) - *p++ = col; - } - } -} - -static void -refresh_palette( void ) -{ -#ifdef CONFIG_MOL - if( video.fb.depth == 8 ) - OSI_RefreshPalette(); -#endif -} - -void -video_scroll( int height ) -{ - int i, offs, size, *dest, *src; - - if (height <= 0 || height >= video.fb.h) { - return; - } - offs = video.fb.rb * height; - size = (video.fb.h * video.fb.rb - offs)/16; - dest = (int*)video.fb.mvirt; - src = (int*)(video.fb.mvirt + offs); - - for( i=0; i<size; i++ ) { - dest[0] = src[0]; - dest[1] = src[1]; - dest[2] = src[2]; - dest[3] = src[3]; - dest += 4; - src += 4; - } -} - /************************************************************************/ /* OF methods */ /************************************************************************/ @@ -259,54 +112,7 @@ NODE_METHODS( video ) = { /************************************************************************/
void -init_video( unsigned long fb, int width, int height, int depth, int rb ) +molvideo_init(void) { - int i; -#if defined(CONFIG_OFMEM) && defined(CONFIG_DRIVER_PCI) - int size; -#endif - phandle_t ph=0; - - video.fb.mphys = video.fb.mvirt = fb; - -#if defined(CONFIG_SPARC64) - /* Fix virtual address on SPARC64 somewhere else */ - video.fb.mvirt = 0xfe000000; -#endif - - video.fb.w = width; - video.fb.h = height; - video.fb.depth = depth; - video.fb.rb = rb; - while( (ph=dt_iterate_type(ph, "display")) ) { - set_int_property( ph, "width", video.fb.w ); - set_int_property( ph, "height", video.fb.h ); - set_int_property( ph, "depth", video.fb.depth ); - set_int_property( ph, "linebytes", video.fb.rb ); - set_int_property( ph, "address", video.fb.mvirt ); - } - video.has_video = 1; - video.pal = malloc( 256 * sizeof(unsigned long) ); - - PUSH(video.fb.mvirt); - feval("to frame-buffer-adr"); - -#if defined(CONFIG_OFMEM) && defined(CONFIG_DRIVER_PCI) - size = ((video.fb.h * video.fb.rb) + 0xfff) & ~0xfff; - - ofmem_claim_phys( video.fb.mphys, size, 0 ); - ofmem_claim_virt( video.fb.mvirt, size, 0 ); - ofmem_map( video.fb.mphys, video.fb.mvirt, size, ofmem_arch_io_translation_mode(video.fb.mphys) ); -#endif - - for( i=0; i<256; i++ ) - set_color( i, i * 0x010101 ); - - set_color( 254, 0xffffcc ); - fill_rect( 254, 0, 0, video.fb.w, video.fb.h ); - - refresh_palette(); - startup_splash(); - REGISTER_NODE( video ); }