PERFORCE change 213015 for review
Robert Watson
rwatson at FreeBSD.org
Sun Jun 17 19:42:25 UTC 2012
http://p4web.freebsd.org/@@213015?ac=10
Change 213015 by rwatson at rwatson_svr_ctsrd_mipsbuild on 2012/06/17 19:42:06
Integrate CTSRD CheriBSD branch to merge further demo improvements
from the FreeBSD/BERI branch.
Affected files ...
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/Makefile#2 integrate
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#2 integrate
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/Makefile#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/Makefile#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/boot-bottom.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/boot-top.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner00.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner01.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner02.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner03.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner04.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner05.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner06.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner07.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner08.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner09.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner10.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/spinner11.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/upgrade-bottom.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/images/upgrade-top.png#1 branch
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/spinner/spinner.c#1 branch
Differences ...
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/Makefile#2 (text+ko) ====
@@ -1,7 +1,8 @@
.include <bsd.own.mk>
SUBDIR= flashit \
- pictview
+ pictview \
+ spinner
.include <bsd.arch.inc.mk>
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#2 (text+ko) ====
@@ -42,390 +42,15 @@
#include <de4tc.h>
-#if DIKE
-// endian.h not available in Linux?
-// #include <sys/endian.h>
-#include <sys/mman.h>
-#define PNG_DEBUG 3
-#include <png.h>
-
-// file descriptors for MTL control and display regions
-static int ctrlfd;
-static int dispfd;
-static int textfd;
-static int fademode=0;
-volatile static u_int32_t *pfbp;
-volatile static u_int16_t *tfbp;
-volatile static u_int32_t *mtlctrl;
-// frame buffer dimensions
-static const int fb_height = 480;
-static const int fb_width = 800;
-
-// fade timing (for crude timing loop)
-static const int fb_cross_fade_time = 500;
-
-// number of lines in the line pattern
-static const int num_lines_pattern = 600;
-#endif
-
// send keyboard output to stdout by default
static int kbdfd = 0;
u_int32_t *fb_buf;
-#if DIKE
-
-
-/*****************************************************************************
- * hack around endian issue
- * TODO: replace with endian library call (but not present in Linux?)
- *****************************************************************************/
-
-u_int32_t
-endian_swap(u_int32_t lend)
-{
- u_int32_t bend;
- bend = lend & 0xff;
- bend = bend<<8;
- lend = lend>>8;
-
- bend |= lend & 0xff;
- bend = bend<<8;
- lend = lend>>8;
-
- bend |= lend & 0xff;
- bend = bend<<8;
- lend = lend>>8;
-
- bend |= lend & 0xff;
- return bend;
-}
-
-
-
-/*****************************************************************************
- * sample touch input
- *****************************************************************************/
-
-static int touch_x0=0;
-static int touch_y0=0;
-static int touch_x1=0;
-static int touch_y1=0;
-static int touch_gesture=0;
-static int touch_count=0;
-volatile static int touch_tmp=0;
-
-void
-multitouch_pole(void)
-{
- /*
- int j;
- for(j=3; j<8; j++)
- touch_tmp += pfbp[j]; // provoke cache line flush
- */
- int t_x0 = endian_swap(mtlctrl[3]);
- if(t_x0>=0) { // new touch info available
- touch_x0 = t_x0;
- touch_y0 = endian_swap(mtlctrl[4]);
- touch_x1 = endian_swap(mtlctrl[5]);
- touch_y1 = endian_swap(mtlctrl[6]);
- // note that this final read dequeues
- touch_gesture = endian_swap(mtlctrl[7]);
- touch_count = touch_gesture>>8;
- if(touch_count<0) touch_count=0; // hack
- touch_gesture &= 0xff;
- }
- // else
- // t_x0 = mtlctrl[7]; // clear any -1s from FIFO?
-}
-
-
-// filter out short lived touch releases
-void
-multitouch_filter(void)
-{
- int j;
- multitouch_pole();
- for(j=30000; (j>0) && (touch_count==0); j--)
- multitouch_pole();
-}
-
-// wait for touch release
-void
-multitouch_release_event(void)
-{
- do {
- // multitouch_filter();
- multitouch_pole();
- } while(touch_count!=0);
-}
-
-
-/*****************************************************************************
- * frame buffer routines
- * TODO: put in seperate library
- *****************************************************************************/
-
-void
-fb_init(void)
-{
- ctrlfd = open("/dev/mtl_reg0", O_RDWR | O_NONBLOCK);
- if(ctrlfd < 0)
- err(1, "open mtl_reg0");
-
- mtlctrl = mmap(NULL, 0x20, PROT_READ | PROT_WRITE, MAP_SHARED, ctrlfd, 0);
- if (mtlctrl == MAP_FAILED)
- err(1, "mmap mtl_reg0");
-
- dispfd = open("/dev/mtl_pixel0", O_RDWR | O_NONBLOCK);
- if(dispfd < 0)
- err(1, "open mtl_pixel0");
- pfbp = mmap(NULL, 0x177000, PROT_READ | PROT_WRITE, MAP_SHARED, dispfd, 0);
- if (pfbp == MAP_FAILED)
- err(1, "mmap mtl_pixel0");
-
- textfd = open("/dev/mtl_text0", O_RDWR | O_NONBLOCK);
- if(textfd < 0)
- err(1, "open mtl_text0");
- tfbp = mmap(NULL, 100*40*2, PROT_READ | PROT_WRITE, MAP_SHARED, textfd, 0);
- if (tfbp == MAP_FAILED)
- err(1, "mmap mtl_text0");
-}
-
-
-inline u_int32_t
-fb_colour(int r, int g, int b)
-{
- return ((r&0xff)<<8) | ((g&0xff)<<16) | ((b&0xff)<<24);
-}
-
-
-inline void
-fb_putpixel(int px, int py, int colour)
-{
- pfbp[px+py*fb_width] = colour;
-}
-
-
-void
-fb_fill(int col)
-{
- int addr;
- for(addr=0; addr<(fb_height*fb_width); addr++)
- pfbp[addr] = col;
-}
-
-
-void
-fb_blend(int blend_text_bg, int blend_text_fg, int blend_pixel, int wash)
-{
- mtlctrl[0] =
- ((blend_text_bg & 0xff)<<24) |
- ((blend_text_fg & 0xff)<<16) |
- ((blend_pixel & 0xff)<<8) |
- // to avoid a red screen colour wash "attack" indicator from being
- // removed, preserve the "wash" value:
- //wash;
- mtlctrl[0] & 0xff;
- // to try the dark red "attack" indicator:
- //4;
-}
-
-
-void
-fb_text_cursor(int x, int y)
-{
- mtlctrl[1] = ((y&0xff)<<24) | ((x)<<16);
-}
-
-
-// fade the pixel framebuffer to black using the MTL hardware alpha blending
-void
-fb_fade2off(void)
-{
- int b,t;
- if(fademode==0)
- fb_blend(255,255,255,0);
- else
- for(b=0; b<256; b++)
- for(t=fb_cross_fade_time; t>0; t--)
- fb_blend(b,b,255,0);
- fademode=0;
-}
-
-
-// fade the pixel framebuffer from black using the MTL hardware alpha blending
-void
-fb_fade2on(void)
-{
- int b,t;
- if(fademode==1)
- fb_blend(0,0,255,0);
- else
- for(b=0; b<256; b++)
- for(t=fb_cross_fade_time; t>0; t--)
- fb_blend(255-b,255-b,255,0);
- fademode=1;
-}
-
-
-void
-fb_fade2text(int textbg_alpha)
-{
- int b, t;
- if(fademode==2)
- fb_blend(255,255,0,0);
- else
- for(b=0; b<256; b++)
- for(t=fb_cross_fade_time; t>0; t--)
- fb_blend((b<textbg_alpha) ? b : textbg_alpha,b,0,0);
- fademode=2;
-}
-
-
-/*****************************************************************************
- * plot_line
- * draws a line using Bresenham's line-drawing algorithm, which uses
- * no multiplication or division.
- *****************************************************************************/
-
-inline int
-sgn(int j)
-{
- return j==0 ? 0 : ((j<0) ? -1 : 1);
-}
-inline int
-abs(int j)
-{
- return j<0 ? -j : j;
-}
void
-plot_line(int x1, int y1, int x2, int y2, unsigned int colour)
-{
- int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
- dx=x2-x1; /* the horizontal distance of the line */
- dy=y2-y1; /* the vertical distance of the line */
- dxabs=abs(dx);
- dyabs=abs(dy);
- sdx=sgn(dx);
- sdy=sgn(dy);
- x=dyabs>>1;
- y=dxabs>>1;
- px=x1;
- py=y1;
-
- if((x1==x2) && (y1==y2))
- fb_putpixel(x1,y1,colour);
- else if (dxabs>=dyabs) { /* the line is more horizontal than vertical */
- for(i=0;i<dxabs;i++) {
- y+=dyabs;
- if (y>=dxabs) {
- y-=dxabs;
- py+=sdy;
- }
- px+=sdx;
- fb_putpixel(px,py,colour);
- }
- } else { /* the line is more vertical than horizontal */
- for(i=0;i<dyabs;i++) {
- x+=dxabs;
- if (x>=dyabs) {
- x-=dyabs;
- px+=sdx;
- }
- py+=sdy;
- fb_putpixel(px,py,colour);
- }
- }
-}
-
-/*****************************************************************************
- * some test pattern generators, etc.
- *****************************************************************************/
-
-/*
-void line_pattern()
-{
- int x0buf[num_lines_pattern];
- int y0buf[num_lines_pattern];
- int x1buf[num_lines_pattern];
- int y1buf[num_lines_pattern];
- int j;
- int x0=10;
- int y0=10;
- int dx0=3;
- int dy0=3;
- int x1=200;
- int y1=200;
- int dx1=2;
- int dy1=-2;
- const int on_colour = 0xffffffff; // white
- const int off_colour = 0xff<<24; // blue
- for(j=0; j<num_lines_pattern; j++) {
- x0buf[j]=0;
- y0buf[j]=0;
- x1buf[j]=1;
- y1buf[j]=1;
- }
- j=0;
- while(1) {
- plot_line(x0buf[j],y0buf[j], x1buf[j],y1buf[j], off_colour);
- plot_line(x0,y0, x1,y1, on_colour);
- x0buf[j]=x0;
- y0buf[j]=y0;
- x1buf[j]=x1;
- y1buf[j]=y1;
- //printf("x0,y0=%3d,%3d x1,y1=%3d,%3d\n", x0,y0, x1,y1);
- //usleep(1000);
- j++; if(j>=num_lines_pattern) j=0;
- x0=x0+dx0; if((x0>=fb_width) || (x0<0)) { x0=x0-2*dx0; dx0=-dx0; }
- y0=y0+dy0; if((y0>=fb_height) || (y0<0)) { y0=y0-2*dy0; dy0=-dy0; }
- x1=x1+dx1; if((x1>=fb_width) || (x1<0)) { x1=x1-2*dx1; dx1=-dx1; }
- y1=y1+dy1; if((y1>=fb_height) || (y1<0)) { y1=y1-2*dy1; dy1=-dy1; }
- // fb_refresh();
- }
-}
-*/
-
- /*
-void
-stripy_pixels_fast()
-{
- // write stripes to pixel buffer
- u_int32_t fb[fb_height][fb_width];
- int x,y,r,g,b;
- for(y=0; y<fb_height; y++) {
- for(x=0; x<fb_width; x++) {
- r = x;
- g = y;
- b = ((x+y)>>1);
- fb_putpixel(x,y,fb_colour(r,g,b));
- }
- }
-}
-*/
-
-
-/*
-void
-flash_colours()
-{
- int j, r, g, b;
- for(j=0; j<8; j++) {
- r = (j & 0x1)==0 ? 0 : 0xff;
- g = (j & 0x2)==0 ? 0 : 0xff;
- b = (j & 0x4)==0 ? 0 : 0xff;
- fb_fill(fb_colour(r,g,b));
- }
-}
-*/
-#endif /* DIKE */
-
-
-void
pen_drawing_clear_screen(void)
{
int x0,y0;
@@ -490,113 +115,6 @@
}
-#if DIKE
-/*****************************************************************************
- * PNG image loader
- *****************************************************************************/
-
-void
-read_png_file(char* file_name, u_int32_t* imgbuf, int maxwidth, int maxheight)
-{
- unsigned char header[8]; // 8 is the maximum size that can be checked
- size_t tmp;
- int x,y;
-
- int width, height, rowbytes;
- png_byte colour_type;
- png_byte bit_depth;
-
- png_structp png_ptr;
- png_infop info_ptr;
- int number_of_passes;
- png_bytep * row_pointers;
- int bppx; // bytes per pixel
-
- /* open file and test for it being a png */
- FILE *fp = fopen(file_name, "rb");
- if (!fp)
- err(1,"fopen - failed to read from %s",file_name);
- tmp=fread(header, 1, 8, fp);
- if (png_sig_cmp(header, 0, 8))
- err(1,"file $s not PNG", file_name);
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr)
- err(1,"png_create_read_struct failed");
-
- info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr)
- err(1,"png_create_info_struct failed");
-
- if (setjmp(png_jmpbuf(png_ptr)))
- err(1,"Error during init_io");
-
- png_init_io(png_ptr, fp);
- png_set_sig_bytes(png_ptr, 8);
-
- png_read_info(png_ptr, info_ptr);
-
- width = png_get_image_width(png_ptr, info_ptr);
- height = png_get_image_height(png_ptr, info_ptr);
- colour_type = png_get_color_type(png_ptr, info_ptr);
- bit_depth = png_get_bit_depth(png_ptr, info_ptr);
-
- //printf("image=%s, width=%1d, height=%1d, colour_type=%1d, bit_depth=%1d\n",
- // file_name, width, height, colour_type, bit_depth);
-
- if((colour_type != PNG_COLOR_TYPE_RGB) && (colour_type != 6))
- err(1,"colour type is not RGB - panic!");
- if(bit_depth != 8)
- err(1,"bit depth is not 8 - panic!");
-
- number_of_passes = png_set_interlace_handling(png_ptr);
- png_read_update_info(png_ptr, info_ptr);
-
- /* read file */
- if (setjmp(png_jmpbuf(png_ptr)))
- err(1,"Error during read_image");
-
- row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
-
- if (bit_depth == 16)
- rowbytes = width*8;
- else
- rowbytes = width*4;
-
- for (y=0; y<height; y++)
- row_pointers[y] = (png_byte*) malloc(rowbytes);
-
- png_read_image(png_ptr, row_pointers);
-
- fclose(fp);
-
- // check that the image isn't too big
- if(height>maxheight) height=maxheight;
- if(width>maxwidth) width=maxwidth;
-
- bppx = 3;
- if(colour_type==6)
- bppx = 4;
- for (y=0; y<height; y++) {
- png_byte* row = row_pointers[y];
- for (x=0; x<width; x++) {
- //png_byte* ptr = &(row[x*4]);
- //fb_putpixel(x,y,fb_colour(ptr[0],ptr[1],ptr[2]));
- png_byte r = row[x*bppx+0];
- png_byte g = row[x*bppx+1];
- png_byte b = row[x*bppx+2];
- imgbuf[x+y*maxwidth] = fb_colour(r,g,b);
- }
- // if the image is too small, fill with black
- for(x=width; x<maxwidth; x++)
- imgbuf[x+y*maxwidth] = 0;
- }
- // if the image is too small, fill with black
- for(y=height; y<maxheight; y++)
- for(x=0; x<maxwidth; x++)
- imgbuf[x+y*maxwidth] = 0;
-}
-#endif
/*****************************************************************************
More information about the p4-projects
mailing list