📄 accel.c
字号:
/* * This is only a tool to test the acceleration primitives. * Do not use the primitives as library graphics functions; * have higher level functions make use of acceleration * primitives if available, otherwise using normal framebuffer code. * For example, the vgagl should use acceleration when it can. */#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <time.h>#include <math.h>#include <alloca.h>#include <string.h>#include "vga.h"#include "vgagl.h"#include "wizard.xbm"#include "wizardmsk.xbm"#define CROSS_SZ 5#define LOGO_NAME "linuxlogo.bmp"#define LOGO_WIDTH 201#define LOGO_HEIGHT 85#define BOXES_Y 3#define BOXES_X 4#define BOXES_B 10#define BOXES_WIDTH (WIDTH/BOXES_X)#define BOXES_HEIGHT ((HEIGHT - 8) / BOXES_Y)#define COPY_OFF 3#define min(a, b) (((a) < (b)) ? (a) : (b))#define max(a, b) (((a) > (b)) ? (a) : (b))#define abs(a) (((a) < 0) ? -(a) : (a))#define QIXLINES 200int vgamode;int background_blits;unsigned char *bitmap;int accelfuncs, ropfuncs, transfuncs;int ropmodes, transmodes;int maxy;unsigned char blitimage[LOGO_WIDTH * LOGO_HEIGHT], *scaleimage, *expandimage;unsigned char conv_wizard_bits[wizard_height * ((wizard_width + 31) & ~31)];unsigned char conv_wizardmsk_bits[wizardmsk_height * ((wizardmsk_width + 31) & ~31)];void Configure(void);void DrawDots(void);void DoAccelTest(void (*accelfunc) (void), char *name, int exp_pixelrate, int pixels_per_call);void FillBoxTest(void);void HlineBoxTest(void);void ScreenCopyTest(void);void ScrollTest(void);void FillBoxXORTest(void);void PutBitmapTest(void);void PositionTest(void);void GetLogo(void);void ScaleLogo(void);void RopTest(void);void QixDemo(int rop, char *txt);void convxbm(int width, int height, unsigned char *bits, unsigned char *conv_bits);void main(void){ vga_modeinfo *minfo; vga_init(); Configure(); /* Getting accel info only works if the mode it set. */ vga_setlinearaddressing(); vga_setmode(vgamode); accelfuncs = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ACCEL); ropfuncs = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ROP); transfuncs = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_TRANSPARENCY); ropmodes = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ROPMODES); transmodes = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_TRANSMODES); minfo = vga_getmodeinfo(vgamode); if (minfo->bytesperpixel) maxy = minfo->maxpixels / (minfo->linewidth / minfo->bytesperpixel); else maxy = HEIGHT; usleep(100000); vga_setmode(TEXT); if (accelfuncs == 0) { printf("No acceleration supported.\n"); exit(0); } printf("Accelflags: 0x%08X\n", accelfuncs); if (accelfuncs & ACCELFLAG_FILLBOX) printf("FillBox supported.\n"); if (accelfuncs & ACCELFLAG_SCREENCOPY) printf("ScreenCopy supported.\n"); if (accelfuncs & ACCELFLAG_PUTIMAGE) printf("PutImage supported.\n"); if (accelfuncs & ACCELFLAG_DRAWLINE) printf("DrawLine.\n"); if (accelfuncs & ACCELFLAG_SETFGCOLOR) printf("SetFGColor supported.\n"); if (accelfuncs & ACCELFLAG_SETBGCOLOR) printf("SetBGColor supported.\n"); if (accelfuncs & ACCELFLAG_SETTRANSPARENCY) printf("SetTransparency supported.\n"); if (accelfuncs & ACCELFLAG_SETRASTEROP) printf("SetRasterOp supported.\n"); if (accelfuncs & ACCELFLAG_PUTBITMAP) printf("PutBitmap supported.\n"); if (accelfuncs & ACCELFLAG_SCREENCOPYBITMAP) printf("ScreenCopyBitmap supported.\n"); if (accelfuncs & ACCELFLAG_DRAWHLINELIST) printf("DrawHLineList supported.\n"); if (accelfuncs & ACCELFLAG_POLYLINE) printf("PolyLine supported.\n"); if (accelfuncs & ACCELFLAG_POLYHLINE) printf("PolyHLine supported.\n"); if (accelfuncs & ACCELFLAG_POLYFILLMODE) printf("PolyFillMode supported.\n"); if (accelfuncs & ACCELFLAG_SETMODE) printf("SetMode supported.\n"); if (accelfuncs & ACCELFLAG_SYNC) printf("Sync supported.\n"); if (accelfuncs & ACCELFLAG_SETRASTEROP) { printf("\nRopAccelflags: 0x%08X\n", ropfuncs); printf("RopModes: 0x%08X", ropmodes); if (ropmodes & (1 << ROP_COPY)) printf(" Copy"); if (ropmodes & (1 << ROP_OR)) printf(" Or"); if (ropmodes & (1 << ROP_AND)) printf(" And"); if (ropmodes & (1 << ROP_XOR)) printf(" Xor"); if (ropmodes & (1 << ROP_INVERT)) printf(" Invert"); printf("\n"); if (ropfuncs & ACCELFLAG_FILLBOX) printf("FillBox supported.\n"); if (ropfuncs & ACCELFLAG_SCREENCOPY) printf("ScreenCopy supported.\n"); if (ropfuncs & ACCELFLAG_PUTIMAGE) printf("PutImage supported.\n"); if (ropfuncs & ACCELFLAG_DRAWLINE) printf("DrawLine.\n"); if (ropfuncs & ACCELFLAG_PUTBITMAP) printf("PutBitmap supported.\n"); if (ropfuncs & ACCELFLAG_SCREENCOPYBITMAP) printf("ScreenCopyBitmap supported.\n"); if (ropfuncs & ACCELFLAG_DRAWHLINELIST) printf("DrawHLineList supported.\n"); if (ropfuncs & ACCELFLAG_POLYLINE) printf("PolyLine supported.\n"); if (ropfuncs & ACCELFLAG_POLYHLINE) printf("PolyHLine supported.\n"); if (ropfuncs & ACCELFLAG_POLYFILLMODE) printf("PolyFillMode supported.\n"); } if (accelfuncs & ACCELFLAG_SETTRANSPARENCY) { printf("\nTransparencyAccelflags: 0x%08X\n", transfuncs); printf("TranparencyModes: 0x%08X", transmodes); if (transmodes & (1 << ENABLE_TRANSPARENCY_COLOR)) printf(" TransparentColor"); if (transmodes & (1 << ENABLE_BITMAP_TRANSPARENCY)) printf(" TransparentBitmap"); printf("\n"); if (transfuncs & ACCELFLAG_FILLBOX) printf("FillBox supported.\n"); if (transfuncs & ACCELFLAG_SCREENCOPY) printf("ScreenCopy supported.\n"); if (transfuncs & ACCELFLAG_PUTIMAGE) printf("PutImage supported.\n"); if (transfuncs & ACCELFLAG_DRAWLINE) printf("DrawLine.\n"); if (transfuncs & ACCELFLAG_PUTBITMAP) printf("PutBitmap supported.\n"); if (transfuncs & ACCELFLAG_SCREENCOPYBITMAP) printf("ScreenCopyBitmap supported.\n"); if (transfuncs & ACCELFLAG_DRAWHLINELIST) printf("DrawHLineList supported.\n"); if (transfuncs & ACCELFLAG_POLYLINE) printf("PolyLine supported.\n"); if (transfuncs & ACCELFLAG_POLYHLINE) printf("PolyHLine supported.\n"); if (transfuncs & ACCELFLAG_POLYFILLMODE) printf("PolyFillMode supported.\n"); } printf("\nPress enter to start test.\n"); getchar(); convxbm(wizard_width, wizard_height, wizard_bits, conv_wizard_bits); convxbm(wizardmsk_width, wizardmsk_height, wizardmsk_bits, conv_wizardmsk_bits); GetLogo(); vga_setmode(vgamode); gl_setcontextvga(vgamode); ScaleLogo(); gl_setcontextvga(vgamode); if (COLORS == 256) gl_setrgbpalette(); gl_setwritemode(FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(gl_rgbcolor(0, 0, 0), gl_rgbcolor(255, 255, 255)); background_blits = 0; if (accelfuncs & ACCELFLAG_SYNC) background_blits = 1; PositionTest(); gl_clearscreen(0); if (accelfuncs & ACCELFLAG_SETRASTEROP) RopTest(); QixDemo(ROP_COPY, "Replace QuixDemo"); QixDemo(ROP_XOR, "Xor QuixDemo"); if (accelfuncs & ACCELFLAG_FILLBOX) DoAccelTest( FillBoxTest, "FillBox", 50000000 / BYTESPERPIXEL, WIDTH * HEIGHT * 256 ); if (accelfuncs & ACCELFLAG_SCREENCOPY) { DrawDots(); gl_write(1, 1, "Measuring ACCEL_SCREENCOPY"); DoAccelTest( ScreenCopyTest, "ScreenCopy", 20000000 / BYTESPERPIXEL, WIDTH * (HEIGHT / 3) * 3 ); } if ((accelfuncs & ACCELFLAG_SCREENCOPY) && (accelfuncs & ACCELFLAG_FILLBOX) && (maxy > HEIGHT)) { DrawDots(); gl_write(1, HEIGHT - 9, "Scrolling with SCREENCOPY & FILLBOX"); DoAccelTest( ScrollTest, "Scroll Demo", 20000000 / BYTESPERPIXEL, WIDTH * HEIGHT ); } if (accelfuncs & ACCELFLAG_DRAWHLINELIST) DoAccelTest( HlineBoxTest, "FillBox with DrawHlineList", 50000000 / BYTESPERPIXEL, WIDTH * HEIGHT * 256 ); if ((accelfuncs & ACCELFLAG_FILLBOX) && (accelfuncs & ACCELFLAG_SETRASTEROP) && (ropfuncs & ACCELFLAG_FILLBOX)) { DrawDots(); gl_write(1, 1, "FILLBOX, xor with varying colors"); DoAccelTest( FillBoxXORTest, "FillBox XOR", 30000000 / BYTESPERPIXEL, WIDTH * HEIGHT * 256 ); } if (accelfuncs & ACCELFLAG_PUTBITMAP) { bitmap = malloc(WIDTH * HEIGHT / 8); memset(bitmap, 0x55, WIDTH * HEIGHT / 8); DrawDots(); DoAccelTest( PutBitmapTest, "PutBitmap", 30000000 / BYTESPERPIXEL, WIDTH * HEIGHT * 2 ); } vga_setmode(TEXT); exit(-1);}void Configure(void){ int allowed[GLASTMODE + 1]; for (;;) { int i; int m; for (i = G320x200x16; i <= GLASTMODE; i++) { allowed[i] = 0; if (vga_hasmode(i) && vga_getmodeinfo(i)->bytesperpixel >= 1) { printf("%2d %s\n", i, vga_getmodename(i)); allowed[i] = 1; } } printf("\nWhich mode? "); scanf("%d", &m); getchar(); printf("\n"); if (m >= G320x200x16 && m <= GLASTMODE) { vgamode = m; break; } }}void convxbm(int width, int height, unsigned char *bits, unsigned char *conv_bits){ int scanline = ((width + 31) & ~31); int y; scanline >>= 3; width = (width + 7) >> 3; for(y = 0; y < height; y++, conv_bits += scanline, bits += width) { memcpy(conv_bits, bits, width); if (width < scanline) memset(conv_bits + width, 0, scanline - width); }}static unsigned char rotbyte(unsigned char c)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -