Lines Matching +full:ecx +full:- +full:2000

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
91 /* Client-to-server msg types */
186 #define RFB_ENCODING_RESIZE -223
187 #define RFB_ENCODING_EXT_KEYEVENT -258
191 #define RFB_MAX_WIDTH 2000
272 sinfo.width = htons(gc_image->width); in rfb_send_server_init_msg()
273 sinfo.height = htons(gc_image->height); in rfb_send_server_init_msg()
307 srect_hdr.width = htons(rc->width); in rfb_send_resize_update_msg()
308 srect_hdr.height = htons(rc->height); in rfb_send_resize_update_msg()
328 srect_hdr.width = htons(rc->width); in rfb_send_extended_keyevent_update_msg()
329 srect_hdr.height = htons(rc->height); in rfb_send_extended_keyevent_update_msg()
343 sizeof(pixfmt_msg) - 1); in rfb_recv_set_pixfmt_msg()
390 pthread_mutex_lock(&rc->pixfmt_mtx); in rfb_recv_set_pixfmt_msg()
391 rc->new_pixfmt.red_shift = red_shift; in rfb_recv_set_pixfmt_msg()
392 rc->new_pixfmt.green_shift = green_shift; in rfb_recv_set_pixfmt_msg()
393 rc->new_pixfmt.blue_shift = blue_shift; in rfb_recv_set_pixfmt_msg()
394 rc->new_pixfmt.adjust_pixels = adjust_pixels; in rfb_recv_set_pixfmt_msg()
395 pthread_mutex_unlock(&rc->pixfmt_mtx); in rfb_recv_set_pixfmt_msg()
398 rc->update_pixfmt = true; in rfb_recv_set_pixfmt_msg()
408 (void)stream_read(cfd, (uint8_t *)&enc_msg + 1, sizeof(enc_msg) - 1); in rfb_recv_set_encodings_msg()
414 rc->enc_raw_ok = true; in rfb_recv_set_encodings_msg()
417 if (!rc->enc_zlib_ok) { in rfb_recv_set_encodings_msg()
418 deflateInit(&rc->zstream, Z_BEST_SPEED); in rfb_recv_set_encodings_msg()
419 rc->enc_zlib_ok = true; in rfb_recv_set_encodings_msg()
423 rc->enc_resize_ok = true; in rfb_recv_set_encodings_msg()
426 rc->enc_extkeyevent_ok = true; in rfb_recv_set_encodings_msg()
441 while (q--) { in fast_crc32()
474 if (!rc->pixfmt.adjust_pixels) { in rfb_adjust_pixels()
478 for (i = 0, pixelp = rc->pixrow; i < width; i++, pixelp++, gcptr++) { in rfb_adjust_pixels()
482 *pixelp = (red << rc->pixfmt.red_shift) | in rfb_adjust_pixels()
483 (green << rc->pixfmt.green_shift) | in rfb_adjust_pixels()
484 (blue << rc->pixfmt.blue_shift); in rfb_adjust_pixels()
487 return (rc->pixrow); in rfb_adjust_pixels()
514 if (rc->enc_zlib_ok) { in rfb_send_rect()
515 zbufp = rc->zbuf; in rfb_send_rect()
516 rc->zstream.total_in = 0; in rfb_send_rect()
517 rc->zstream.total_out = 0; in rfb_send_rect()
518 for (p = &gc->data[y * gc->width + x]; y < h; y++) { in rfb_send_rect()
520 rc->zstream.next_in = (Bytef *)pixelp; in rfb_send_rect()
521 rc->zstream.avail_in = w; in rfb_send_rect()
522 rc->zstream.next_out = (Bytef *)zbufp; in rfb_send_rect()
523 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 - in rfb_send_rect()
524 rc->zstream.total_out; in rfb_send_rect()
525 rc->zstream.data_type = Z_BINARY; in rfb_send_rect()
528 err = deflate(&rc->zstream, Z_SYNC_FLUSH); in rfb_send_rect()
531 rc->enc_zlib_ok = false; in rfb_send_rect()
532 deflateEnd(&rc->zstream); in rfb_send_rect()
535 zbufp = rc->zbuf + rc->zstream.total_out; in rfb_send_rect()
536 p += gc->width; in rfb_send_rect()
544 zlen = htonl(rc->zstream.total_out); in rfb_send_rect()
548 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out)); in rfb_send_rect()
554 zbufp = rc->zbuf; in rfb_send_rect()
555 for (p = &gc->data[y * gc->width + x]; y < h; y++) { in rfb_send_rect()
560 p += gc->width; in rfb_send_rect()
569 total = stream_write(cfd, rc->zbuf, total); in rfb_send_rect()
596 if (rc->pixfmt.adjust_pixels) { in rfb_send_all()
598 gc->width, gc->height)); in rfb_send_all()
604 srect_hdr.width = htons(gc->width); in rfb_send_all()
605 srect_hdr.height = htons(gc->height); in rfb_send_all()
606 if (rc->enc_zlib_ok) { in rfb_send_all()
607 rc->zstream.next_in = (Bytef *)gc->data; in rfb_send_all()
608 rc->zstream.avail_in = gc->width * gc->height * in rfb_send_all()
610 rc->zstream.next_out = (Bytef *)rc->zbuf; in rfb_send_all()
611 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16; in rfb_send_all()
612 rc->zstream.data_type = Z_BINARY; in rfb_send_all()
614 rc->zstream.total_in = 0; in rfb_send_all()
615 rc->zstream.total_out = 0; in rfb_send_all()
618 err = deflate(&rc->zstream, Z_SYNC_FLUSH); in rfb_send_all()
621 rc->enc_zlib_ok = false; in rfb_send_all()
622 deflateEnd(&rc->zstream); in rfb_send_all()
632 zlen = htonl(rc->zstream.total_out); in rfb_send_all()
636 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out)); in rfb_send_all()
646 nwrite = stream_write(cfd, gc->data, in rfb_send_all()
647 gc->width * gc->height * sizeof(uint32_t)); in rfb_send_all()
659 pthread_mutex_lock(&rc->pixfmt_mtx); in rfb_set_pixel_adjustment()
660 rc->pixfmt = rc->new_pixfmt; in rfb_set_pixel_adjustment()
661 pthread_mutex_unlock(&rc->pixfmt_mtx); in rfb_set_pixel_adjustment()
682 if (atomic_compare_exchange_strong(&rc->sending, &expected, true) == false) in rfb_send_screen()
688 if (atomic_exchange(&rc->pending, false) == false) in rfb_send_screen()
691 if (atomic_exchange(&rc->update_pixfmt, false) == true) { in rfb_send_screen()
699 if (rc->crc_width != gc_image->width || in rfb_send_screen()
700 rc->crc_height != gc_image->height) { in rfb_send_screen()
701 memset(rc->crc, 0, sizeof(uint32_t) * in rfb_send_screen()
704 rc->crc_width = gc_image->width; in rfb_send_screen()
705 rc->crc_height = gc_image->height; in rfb_send_screen()
709 if (rc->width != gc_image->width || in rfb_send_screen()
710 rc->height != gc_image->height) { in rfb_send_screen()
711 rc->width = gc_image->width; in rfb_send_screen()
712 rc->height = gc_image->height; in rfb_send_screen()
713 if (rc->enc_resize_ok) { in rfb_send_screen()
715 rc->update_all = true; in rfb_send_screen()
720 if (atomic_exchange(&rc->update_all, false) == true) { in rfb_send_screen()
730 w = rc->crc_width; in rfb_send_screen()
731 h = rc->crc_height; in rfb_send_screen()
732 xcells = howmany(rc->crc_width, PIX_PER_CELL); in rfb_send_screen()
733 ycells = howmany(rc->crc_height, PIX_PER_CELL); in rfb_send_screen()
741 p = gc_image->data; in rfb_send_screen()
749 crc_p = rc->crc_tmp - xcells; in rfb_send_screen()
750 orig_crc = rc->crc - xcells; in rfb_send_screen()
752 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells); in rfb_send_screen()
760 if (x == (xcells - 1) && rem_x > 0) in rfb_send_screen()
765 if (rc->hw_crc) in rfb_send_screen()
777 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) { in rfb_send_screen()
795 rc->pending = true; in rfb_send_screen()
808 crc_p = rc->crc_tmp; in rfb_send_screen()
818 if (x == (xcells - 1) && rem_x > 0) in rfb_send_screen()
836 rc->sending = false; in rfb_send_screen()
847 (void)stream_read(cfd, (uint8_t *)&updt_msg + 1 , sizeof(updt_msg) - 1); in rfb_recv_update_msg()
849 if (rc->enc_extkeyevent_ok && (!rc->enc_extkeyevent_send)) { in rfb_recv_update_msg()
851 rc->enc_extkeyevent_send = true; in rfb_recv_update_msg()
854 rc->pending = true; in rfb_recv_update_msg()
856 rc->update_all = true; in rfb_recv_update_msg()
864 (void)stream_read(cfd, (uint8_t *)&key_msg + 1, sizeof(key_msg) - 1); in rfb_recv_key_msg()
867 rc->input_detected = true; in rfb_recv_key_msg()
877 sizeof(client_msg) - 1); in rfb_recv_client_msg()
881 sizeof(extkey_msg) - 2); in rfb_recv_client_msg()
883 rc->input_detected = true; in rfb_recv_client_msg()
892 (void)stream_read(cfd, (uint8_t *)&ptr_msg + 1, sizeof(ptr_msg) - 1); in rfb_recv_ptr_msg()
895 rc->input_detected = true; in rfb_recv_ptr_msg()
905 len = stream_read(cfd, (uint8_t *)&ct_msg + 1, sizeof(ct_msg) - 1); in rfb_recv_cuttext_msg()
910 ct_msg.length -= len; in rfb_recv_cuttext_msg()
918 n1 = now->tv_sec * 1000000 + now->tv_usec; in timeval_delta()
919 n2 = prev->tv_sec * 1000000 + prev->tv_usec; in timeval_delta()
920 return (n1 - n2); in timeval_delta()
935 cfd = rc->cfd; in rfb_wr_thr()
939 while (rc->cfd >= 0) { in rfb_wr_thr()
956 input = atomic_exchange(&rc->input_detected, false); in rfb_wr_thr()
961 if ((++rc->wrcount & 1) || input) { in rfb_wr_thr()
968 usleep(SCREEN_POLL_DELAY - tdiff); in rfb_wr_thr()
997 rc->cfd = cfd; in rfb_handle()
1005 strncmp(vbuf, buf, VERSION_LENGTH - 2) != 0) { in rfb_handle()
1009 client_ver = buf[VERSION_LENGTH - 2]; in rfb_handle()
1018 /* In versions 3.7 & 3.8, it's 2-way handshake */ in rfb_handle()
1021 if (rc->password) { in rfb_handle()
1063 * The client then sends the resulting 16-bytes response. in rfb_handle()
1066 strncpy(keystr, rc->password, PASSWD_LENGTH); in rfb_handle()
1081 /* Initialize a 16-byte random challenge */ in rfb_handle()
1085 /* Receive the 16-byte challenge response */ in rfb_handle()
1143 /* 3a. Read client shared-flag byte */ in rfb_handle()
1146 /* 4a. Write server-init info */ in rfb_handle()
1149 if (!rc->zbuf) { in rfb_handle()
1150 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16); in rfb_handle()
1151 assert(rc->zbuf != NULL); in rfb_handle()
1189 WPRINTF(("rfb unknown cli-code %d!", buf[0] & 0xff)); in rfb_handle()
1194 rc->cfd = -1; in rfb_handle()
1197 if (rc->enc_zlib_ok) in rfb_handle()
1198 deflateEnd(&rc->zstream); in rfb_handle()
1219 rc->enc_raw_ok = false; in rfb_thr()
1220 rc->enc_zlib_ok = false; in rfb_thr()
1221 rc->enc_resize_ok = false; in rfb_thr()
1222 rc->enc_extkeyevent_ok = false; in rfb_thr()
1224 rc->enc_extkeyevent_send = false; in rfb_thr()
1226 cfd = accept(rc->sfd, NULL, NULL); in rfb_thr()
1227 if (rc->conn_wait) { in rfb_thr()
1228 pthread_mutex_lock(&rc->mtx); in rfb_thr()
1229 pthread_cond_signal(&rc->cond); in rfb_thr()
1230 pthread_mutex_unlock(&rc->mtx); in rfb_thr()
1231 rc->conn_wait = 0; in rfb_thr()
1244 u_int cpu_registers[4], ecx; in sse42_supported() local
1248 ecx = cpu_registers[2]; in sse42_supported()
1250 return ((ecx & CPUID2_SSE42) != 0); in sse42_supported()
1271 rc->crc = calloc(cnt, sizeof(uint32_t)); in rfb_init()
1272 rc->crc_tmp = calloc(cnt, sizeof(uint32_t)); in rfb_init()
1273 rc->crc_width = RFB_MAX_WIDTH; in rfb_init()
1274 rc->crc_height = RFB_MAX_HEIGHT; in rfb_init()
1275 rc->sfd = -1; in rfb_init()
1277 rc->password = password; in rfb_init()
1279 rc->pixrow = malloc(RFB_MAX_WIDTH * sizeof(uint32_t)); in rfb_init()
1280 if (rc->pixrow == NULL) { in rfb_init()
1304 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0); in rfb_init()
1305 if (rc->sfd < 0) { in rfb_init()
1310 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); in rfb_init()
1312 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) { in rfb_init()
1317 if (listen(rc->sfd, 1) < 0) { in rfb_init()
1324 if (caph_rights_limit(rc->sfd, &rights) == -1) in rfb_init()
1328 rc->hw_crc = sse42_supported(); in rfb_init()
1330 rc->conn_wait = wait; in rfb_init()
1332 pthread_mutex_init(&rc->mtx, NULL); in rfb_init()
1333 pthread_cond_init(&rc->cond, NULL); in rfb_init()
1336 pthread_mutex_init(&rc->pixfmt_mtx, NULL); in rfb_init()
1337 pthread_create(&rc->tid, NULL, rfb_thr, rc); in rfb_init()
1338 pthread_set_name_np(rc->tid, "rfb"); in rfb_init()
1342 pthread_mutex_lock(&rc->mtx); in rfb_init()
1343 pthread_cond_wait(&rc->cond, &rc->mtx); in rfb_init()
1344 pthread_mutex_unlock(&rc->mtx); in rfb_init()
1352 if (rc->pixfmt_mtx) in rfb_init()
1353 pthread_mutex_destroy(&rc->pixfmt_mtx); in rfb_init()
1356 if (rc->sfd != -1) in rfb_init()
1357 close(rc->sfd); in rfb_init()
1358 free(rc->crc); in rfb_init()
1359 free(rc->crc_tmp); in rfb_init()
1360 free(rc->pixrow); in rfb_init()
1362 return (-1); in rfb_init()