From c1bbac52d78b2e3e93fa43a5a7b3907073493216 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 30 Jun 2017 16:45:12 +0200 Subject: text widget has a constant buffer and owns the string to draw now (passing a const char * from a local stack context is not really a good idea!) added more efficiet draw method for characters in vga driver protected desktop for now against too often redraws (boolean global variable needs_redraw, this is later a soffisticated set-of-areas-to -redraw algorithm) --- src/drivers/video/vga.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index bcd4366..647456b 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -254,6 +254,7 @@ bool vga_set_mode( vga_t *vga, const vga_mode_t mode ) vga->mode.segment = get_frame_buffer_segment( vga ); vga_use_z_buffer( vga, false ); + memset( vga->zbuffer, 0, sizeof( vga->zbuffer ) ); return true; } @@ -325,12 +326,12 @@ void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t colo void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const vga_color_t color ) { if( !params_ok( vga, x, y ) ) { - kernel_panic( "Pixel coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", + kernel_panic( "Rectangle start coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", x, y, vga->mode.x, vga->mode.y ); } if( !params_ok( vga, x + w, y + h ) ) { - kernel_panic( "Pixel coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", + kernel_panic( "Rectangle end coordinates are out of bounds: (%d, %d), resolution is only (%d, %d)", x + w, y + h, vga->mode.x, vga->mode.y ); } @@ -365,15 +366,35 @@ void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, // for now, the 34 entry, character height is 16, assuming A-Z const unsigned char *bmap = &vga_font.Bitmap[(c-32)*16]; + uint8_t fg_color_idx = get_color_index( foreground ); + uint8_t bg_color_idx = get_color_index( background ); + // should be dynamic and vga_font.Width + uint8_t data[8]; + + for( int yy = 0; yy < vga_font.Height; yy++ ) { + memset( data, bg_color_idx, sizeof( data ) ); + for( int xx = 0; xx < vga_font.Width; xx++ ) { + if( bmap[yy] & mask[xx] ) { + data[7-xx] = fg_color_idx; + } + } + uint8_t *addr = vga->base_addr + vga->mode.x * ( y + yy ) + x; + memcpy( addr, data, 8 ); + } + +// amazingly slow +/* for( int xx = 0; xx < vga_font.Width; xx++ ) { for( int yy = 0; yy < vga_font.Height; yy++ ) { if( bmap[yy] & mask[xx] ) { vga_set_pixel( vga, x + 10 - xx, y + yy, foreground ); } else { - vga_set_pixel( vga, x + 10 - xx, y + yy, background ); +// drawing only what's needed, the background is done by the widget +// vga_set_pixel( vga, x + 10 - xx, y + yy, background ); } } } +*/ } void vga_wait_for_retrace( vga_t *vga ) -- cgit v1.2.3-54-g00ecf