Lines Matching refs:rc

293 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)  in rfb_send_resize_update_msg()  argument
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()
314 rfb_send_extended_keyevent_update_msg(struct rfb_softc *rc, int cfd) in rfb_send_extended_keyevent_update_msg() argument
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()
335 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc __unused, int cfd) 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()
402 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd) in rfb_recv_set_encodings_msg() argument
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()
454 rfb_send_update_header(struct rfb_softc *rc __unused, int cfd, int numrects) in rfb_send_update_header()
467 rfb_adjust_pixels(struct rfb_softc *rc, uint32_t *gcptr, int width) in rfb_adjust_pixels() argument
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()
491 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc, in rfb_send_rect() argument
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()
519 pixelp = rfb_adjust_pixels(rc, p, width); 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()
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()
556 pixelp = rfb_adjust_pixels(rc, p, width); in rfb_send_rect()
569 total = stream_write(cfd, rc->zbuf, total); in rfb_send_rect()
575 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc) in rfb_send_all() argument
596 if (rc->pixfmt.adjust_pixels) { in rfb_send_all()
597 return (rfb_send_rect(rc, cfd, gc, 0, 0, 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()
657 rfb_set_pixel_adjustment(struct rfb_softc *rc) in rfb_set_pixel_adjustment() argument
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()
665 rfb_send_screen(struct rfb_softc *rc, int cfd) in rfb_send_screen() argument
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()
692 rfb_set_pixel_adjustment(rc); 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()
714 rfb_send_resize_update_msg(rc, cfd); 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()
721 retval = rfb_send_all(rc, cfd, gc_image); 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()
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()
765 if (rc->hw_crc) in rfb_send_screen()
795 rc->pending = true; in rfb_send_screen()
801 retval = rfb_send_all(rc, cfd, gc_image); in rfb_send_screen()
805 rfb_send_update_header(rc, cfd, changes); in rfb_send_screen()
808 crc_p = rc->crc_tmp; in rfb_send_screen()
822 nwrite = rfb_send_rect(rc, cfd, in rfb_send_screen()
836 rc->sending = false; in rfb_send_screen()
843 rfb_recv_update_msg(struct rfb_softc *rc, int cfd) in rfb_recv_update_msg() argument
849 if (rc->enc_extkeyevent_ok && (!rc->enc_extkeyevent_send)) { in rfb_recv_update_msg()
850 rfb_send_extended_keyevent_update_msg(rc, cfd); 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()
860 rfb_recv_key_msg(struct rfb_softc *rc, int cfd) in rfb_recv_key_msg() argument
867 rc->input_detected = true; in rfb_recv_key_msg()
871 rfb_recv_client_msg(struct rfb_softc *rc, int cfd) in rfb_recv_client_msg() argument
883 rc->input_detected = true; in rfb_recv_client_msg()
888 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd) in rfb_recv_ptr_msg() argument
895 rc->input_detected = true; in rfb_recv_ptr_msg()
899 rfb_recv_cuttext_msg(struct rfb_softc *rc __unused, int cfd) in rfb_recv_cuttext_msg()
926 struct rfb_softc *rc; in rfb_wr_thr() local
934 rc = arg; in rfb_wr_thr()
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()
962 if (rfb_send_screen(rc, cfd) <= 0) { in rfb_wr_thr()
976 rfb_handle(struct rfb_softc *rc, int cfd) in rfb_handle() argument
997 rc->cfd = cfd; in rfb_handle()
1021 if (rc->password) { in rfb_handle()
1066 strncpy(keystr, rc->password, PASSWD_LENGTH); 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()
1154 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc); in rfb_handle()
1168 rfb_recv_set_pixfmt_msg(rc, cfd); in rfb_handle()
1171 rfb_recv_set_encodings_msg(rc, cfd); in rfb_handle()
1174 rfb_recv_update_msg(rc, cfd); in rfb_handle()
1177 rfb_recv_key_msg(rc, cfd); in rfb_handle()
1180 rfb_recv_ptr_msg(rc, cfd); in rfb_handle()
1183 rfb_recv_cuttext_msg(rc, cfd); in rfb_handle()
1186 rfb_recv_client_msg(rc, cfd); 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()
1204 struct rfb_softc *rc; in rfb_thr() local
1209 rc = arg; in rfb_thr()
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()
1233 rfb_handle(rc, cfd); in rfb_thr()
1258 struct rfb_softc *rc; in rfb_init() local
1267 rc = calloc(1, sizeof(struct rfb_softc)); in rfb_init()
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()
1361 free(rc); in rfb_init()