vnc-server.c
来自「eCos操作系统源码」· C语言 代码 · 共 1,754 行 · 第 1/4 页
C
1,754 行
void VncInit(vnc_colour_t colour){ /* Initialise the frame buffer */ int i, j; for (i = 0; i < CYGNUM_VNC_SERVER_FRAME_HEIGHT; i++) { for (j = 0; j < CYGNUM_VNC_SERVER_FRAME_WIDTH; j++) { frame_buffer[i][j] = colour; } } for (i = 0; i < CYGNUM_VNC_SERVER_FRAME_HEIGHT/TILE_SIZE; i++) { for (j = 0; j < CYGNUM_VNC_SERVER_FRAME_WIDTH/TILE_SIZE; j++) { tile_updated[i][j] = 1; } }}void VncDrawPixel(cyg_uint16 x, cyg_uint16 y, vnc_colour_t colour){ /* Set that pixel to 'colour' */ frame_buffer[y][x] = colour; /* Mark the tile for update */ tile_updated[y/TILE_SIZE][x/TILE_SIZE] = 1;}vnc_colour_t VncReadPixel(cyg_uint16 x, cyg_uint16 y){ return frame_buffer[y][x];}void VncDrawHorzLine(cyg_uint16 x1, cyg_uint16 x2, cyg_uint16 y, vnc_colour_t colour){ int i; /* Draw the line */ for (i = x1; i <= x2; i++) { frame_buffer[y][i] = colour; } /* Mark the tiles for update */ for (i = x1/TILE_SIZE; i <= x2/TILE_SIZE; i++) { tile_updated[y/TILE_SIZE][i] = 1; }}void VncDrawVertLine(cyg_uint16 x, cyg_uint16 y1, cyg_uint16 y2, vnc_colour_t colour){ int i; /* Draw the line */ for (i = y1; i <= y2; i++) { frame_buffer[i][x] = colour; } /* Mark the tiles for update */ for (i = y1/TILE_SIZE; i <= y2/TILE_SIZE; i++) { tile_updated[i][x/TILE_SIZE] = 1; }}void VncFillRect(cyg_uint16 x1, cyg_uint16 y1, cyg_uint16 x2, cyg_uint16 y2, vnc_colour_t colour){ /* Draw a solid rectangle */ int i, j; for (i = y1; i <= y2; i++) { for (j = x1; j <= x2; j++) { frame_buffer[i][j] = colour; } } for (i = y1/TILE_SIZE; i <= y2/TILE_SIZE; i++) { for (j = x1/TILE_SIZE; j <= x2/TILE_SIZE; j++) { tile_updated[i][j] = 1; } }}/* Copy rectangle of size widthxheight form (x1, y1) to (x2, y2) */void VncCopyRect(cyg_uint16 x1, cyg_uint16 y1, cyg_uint16 width, cyg_uint16 height, cyg_uint16 x2, cyg_uint16 y2){ int i, j; int xmove, ymove; /* Calulate how much to move the rectangle by */ xmove = x2 - x1; ymove = y2 - y1; if ((xmove == 0) && (ymove == 0)) { /* No move required */ return; } if (ymove < 0) { /* Copy pixels from top to bottom */ if (x1 >= x2) { /* Copy pixels from left to right */ for (i = y1; i < y1 + height; i++) { for (j = x1; j < x1 + width; j++) { frame_buffer[i + ymove][j + xmove] = frame_buffer[i][j]; } } } else { /* Copy pixels from right to left */ for (i = y1; i < y1 + height; i++) { for (j = x1 + width - 1; j >= x1 ; j--) { frame_buffer[i + ymove][j + xmove] = frame_buffer[i][j]; } } } } else { /* Copy pixels from bottom to top */ if (xmove < 0) { /* Copy pixels from left to right */ for (i = y1 + height - 1; i >= y1; i--) { for (j = x1; j < x1 + width; j++) { frame_buffer[i + ymove][j + xmove] = frame_buffer[i][j]; } } } else { /* Copy pixels from right to left */ for (i = y1 + height - 1; i >= y1; i--) { for (j = x1 + width - 1; j >= x1 ; j--) { frame_buffer[i + ymove][j + xmove] = frame_buffer[i][j]; } } } } /* Mark the required tiles for update */ for (i = y2/TILE_SIZE; i <= (y2 + height - 1) /TILE_SIZE; i++) { for (j = x2/TILE_SIZE; j <= (x2 + width - 1)/TILE_SIZE; j++) { tile_updated[i][j] = 1; } }}/* Function to copy a rectangle from the frame buffer to a supplied buffer */void VncCopyRect2Buffer(cyg_uint16 x, cyg_uint16 y, cyg_uint16 width, cyg_uint16 height, void *buffer, cyg_uint16 buff_w, cyg_uint16 buff_h, cyg_uint16 x_off, cyg_uint16 y_off){ int i, j; cyg_uint16 eol_padding = buff_w - width - x_off;#if (BITS_PER_PIXEL == 8) cyg_uint8 *dst_buffer; dst_buffer = (cyg_uint8 *)buffer;#else cyg_uint16 *dst_buffer; dst_buffer = (cyg_uint16 *)buffer;#endif dst_buffer += ((x_off + width) * y_off); /* Allow for a y offset into supplied buffer */ for (i = y; i < y + height; i++) { dst_buffer += x_off; /* Allow for an x offset into supplied buffer */ for (j = x; j < x + width; j++) { /* Copy each pixel in the rectangle to the supplied buffer */ *dst_buffer = frame_buffer[i][j]; dst_buffer++; } dst_buffer += eol_padding; /* Allow for unused space at the end of each line */ }}/* Function to copy data from a supplied buffer to a rectangle in the frame buffer */void VncCopyBuffer2Rect( void *buffer, cyg_uint16 buff_w, cyg_uint16 buff_h ,cyg_uint16 x_off, cyg_uint16 y_off, cyg_uint16 x, cyg_uint16 y, cyg_uint16 width, cyg_uint16 height){ int i, j; cyg_uint16 eol_padding = buff_w - width - x_off;#if (BITS_PER_PIXEL == 8) cyg_uint8 *src_buffer = (cyg_uint8 *)buffer;#else cyg_uint16 *src_buffer = (cyg_uint16 *)buffer;#endif src_buffer += ((x_off + width) * y_off); /* Allow for a y offset into supplied buffer */ for (i = y; i < y + height; i++) { src_buffer += x_off; /* Allow for an x offset into supplied buffer */ for (j = x; j < x + width; j++) { /* Copy each pixel in the supplied buffer to the frame buffer */ frame_buffer[i][j] = *src_buffer; src_buffer++; } src_buffer += eol_padding; /* Allow for unused space at the end of each line */ } /* Mark the required tiles for update */ for (i = y/TILE_SIZE; i <= (y + height - 1) /TILE_SIZE; i++) { for (j = x/TILE_SIZE; j <= (x + width - 1)/TILE_SIZE; j++) { tile_updated[i][j] = 1; } }}/* Function to copy data from a supplied buffer to a rectangle in the frame buffer with mask */void VncCopyBuffer2RectMask( void *buffer, cyg_uint16 buff_w, cyg_uint16 buff_h ,cyg_uint16 x_off, cyg_uint16 y_off, cyg_uint16 x, cyg_uint16 y, cyg_uint16 width, cyg_uint16 height, vnc_colour_t col){ int i, j; cyg_uint16 eol_padding = buff_w - width - x_off;#if (BITS_PER_PIXEL == 8) cyg_uint8 *src_buffer = (cyg_uint8 *)buffer;#else cyg_uint16 *src_buffer = (cyg_uint16 *)buffer;#endif src_buffer += ((x_off + width) * y_off); /* Allow for a y offset into supplied buffer */ for (i = y; i < y + height; i++) { src_buffer += x_off; /* Allow for an x offset into supplied buffer */ for (j = x; j < x + width; j++) { /* Copy each non-mask pixel in the supplied buffer to the frame buffer */ if (*src_buffer != col) { frame_buffer[i][j] = *src_buffer; } src_buffer++; } src_buffer += eol_padding; /* Allow for unused space at the end of each line */ } /* Mark the required tiles for update */ for (i = y/TILE_SIZE; i <= (y + height - 1) /TILE_SIZE; i++) { for (j = x/TILE_SIZE; j <= (x + width - 1)/TILE_SIZE; j++) { tile_updated[i][j] = 1; } }}void VncSoundBell(void){ cyg_mutex_lock(&SoundBell_lock); SoundBellCount++; cyg_mutex_unlock(&SoundBell_lock);}#ifdef CYGNUM_VNC_SERVER_INCLUDE_VNC_PRINTFvnc_printf_return_t VncPrintf(MWCFONT* font, int do_print, vnc_colour_t colour, int x, int y, const char *fmt, ... ){ va_list args; static char buf[200]; int x_pos, x_max, y_pos, y_max, char_pos; int char_offset, char_width; int ret, i, j; MWCFONT* sel_font; vnc_printf_return_t ret_vals; cyg_scheduler_lock(); /* Prevent other threads from running */ va_start(args, fmt); ret = diag_vsprintf(buf, fmt, args); va_end(args); if (ret <= 0) { /* sprintf failed */ ret_vals.width = 0; ret_vals.height = 0; return ret_vals; } x_pos = x; /* Initial print positions */ x_max = x_pos; y_pos = y; y_max = y_pos; char_pos = 0; if (font == NULL) { /* No font specified - use default font */ sel_font = &font_winFreeSystem14x16; } else { /* Font has been specified */ sel_font = font; } while (buf[char_pos] != 0) { /* Check for '\n' character */ if (buf[char_pos] == '\n') { x_pos = x; y_pos += sel_font->height; char_pos++; continue; } /* Check for characters not if the font - set to first char */ if (buf[char_pos] < sel_font->firstchar) { buf[char_pos] = sel_font->firstchar; } char_offset = ((cyg_uint8) buf[char_pos]) - sel_font->firstchar; /* Get the character width */ if (sel_font->width != 0) { char_width = sel_font->width[char_offset]; } else { char_width = sel_font->maxwidth; } if (sel_font->offset != 0) { char_offset = sel_font->offset[char_offset]; } else { char_offset *= sel_font->height; } y_max = y_pos; if (do_print) { /* Draw the character in the frame buffer */ for (i = char_offset; i < (char_offset + sel_font->height); i++) { if ((y_pos + i - char_offset) < CYGNUM_VNC_SERVER_FRAME_HEIGHT) { /* This has not gone off the bottom of the frame */ for (j = 0; j < char_width; j++) { if ((x_pos + j) < CYGNUM_VNC_SERVER_FRAME_WIDTH) { /* This has not gone off the right edge of the frame */ if (sel_font->bits[i] & (0x8000 >> j)) { /* This pixel should be drawn */ frame_buffer[y_pos + i - char_offset][x_pos + j] = colour; } } } } } } x_pos += char_width; if (x_pos > x_max) { x_max = x_pos; } char_pos++; } /* Mark the required tiles for update */ if (do_print) { for (i = y/TILE_SIZE; i <= (y_max + sel_font->height)/TILE_SIZE; i++) { for (j = x/TILE_SIZE; j <= x_max/TILE_SIZE; j++) { tile_updated[i][j] = 1; } } } ret_vals.width = x_max - x; ret_vals.height = y_max + sel_font->height - y; cyg_scheduler_unlock(); /* Allow other threads to run */ return ret_vals;}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?