Changeset a35b458 in mainline for uspace/srv/hid/rfb/rfb.c
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
-
uspace/srv/hid/rfb/rfb.c (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/rfb/rfb.c
r3061bc1 ra35b458 70 70 rbuf_out = 0; 71 71 rbuf_in = 0; 72 72 73 73 rc = tcp_conn_recv_wait(conn, rbuf, BUFFER_SIZE, &nrecv); 74 74 if (rc != EOK) 75 75 return rc; 76 76 77 77 rbuf_in = nrecv; 78 78 } 79 79 80 80 *c = rbuf[rbuf_out++]; 81 81 return EOK; … … 177 177 memset(rfb, 0, sizeof(rfb_t)); 178 178 fibril_mutex_initialize(&rfb->lock); 179 179 180 180 rfb_pixel_format_t *pf = &rfb->pixel_format; 181 181 pf->bpp = 32; … … 189 189 pf->g_shift = 8; 190 190 pf->b_shift = 16; 191 191 192 192 rfb->name = str_dup(name); 193 193 rfb->supports_trle = false; 194 194 195 195 return rfb_set_size(rfb, width, height); 196 196 } … … 209 209 rfb->width = width; 210 210 rfb->height = height; 211 211 212 212 /* Fill with white */ 213 213 memset(rfb->framebuffer.data, 255, new_size); 214 214 215 215 return EOK; 216 216 } … … 242 242 } 243 243 } 244 244 245 245 if (first_free_index != -1) { 246 246 rfb->palette[first_free_index] = PIXEL(255, RED(pixel), GREEN(pixel), … … 250 250 return; 251 251 } 252 252 253 253 /* TODO find nearest color index. We are lazy so return index 0 for now */ 254 254 *buf = 0; … … 262 262 pix |= rfb_scale_channel(GREEN(pixel), pf->g_max) << pf->g_shift; 263 263 pix |= rfb_scale_channel(BLUE(pixel), pf->b_max) << pf->b_shift; 264 264 265 265 if (pf->bpp == 8) { 266 266 uint8_t pix8 = pix; … … 317 317 size_t size = sizeof(rfb_set_color_map_entries_t) + 318 318 rfb->palette_used * sizeof(rfb_color_map_entry_t); 319 319 320 320 void *buf = malloc(size); 321 321 if (buf == NULL) 322 322 return NULL; 323 323 324 324 void *pos = buf; 325 325 326 326 rfb_set_color_map_entries_t *scme = pos; 327 327 scme->message_type = RFB_SMSG_SET_COLOR_MAP_ENTRIES; … … 330 330 rfb_set_color_map_entries_to_be(scme, scme); 331 331 pos += sizeof(rfb_set_color_map_entries_t); 332 332 333 333 rfb_color_map_entry_t *entries = pos; 334 334 for (unsigned i = 0; i < rfb->palette_used; i++) { … … 338 338 rfb_color_map_entry_to_be(&entries[i], &entries[i]); 339 339 } 340 340 341 341 *psize = size; 342 342 return buf; … … 347 347 size_t pixel_size = rfb->pixel_format.bpp / 8; 348 348 size_t size = (rect->width * rect->height * pixel_size); 349 349 350 350 if (buf == NULL) 351 351 return size; 352 352 353 353 for (uint16_t y = 0; y < rect->height; y++) { 354 354 for (uint16_t x = 0; x < rect->width; x++) { … … 359 359 } 360 360 } 361 361 362 362 return size; 363 363 } … … 376 376 ctx->size = pixel_format->bpp / 8; 377 377 ctx->compress_type = COMP_NONE; 378 378 379 379 if (pixel_format->bpp == 32 && pixel_format->depth <= 24) { 380 380 uint32_t mask = 0; … … 382 382 mask |= pixel_format->g_max << pixel_format->g_shift; 383 383 mask |= pixel_format->b_max << pixel_format->b_shift; 384 384 385 385 if (pixel_format->big_endian) { 386 386 mask = host2uint32_t_be(mask); … … 389 389 mask = host2uint32_t_le(mask); 390 390 } 391 391 392 392 uint8_t *mask_data = (uint8_t *) &mask; 393 393 if (mask_data[0] == 0) { … … 407 407 uint8_t data[4]; 408 408 rfb_encode_pixel(rfb, data, pixel); 409 409 410 410 switch (cpixel->compress_type) { 411 411 case COMP_NONE: … … 424 424 if (buf == NULL) 425 425 return size; 426 426 427 427 for (uint16_t y = tile->y; y < tile->y + tile->height; y++) { 428 428 for (uint16_t x = tile->x; x < tile->x + tile->width; x++) { … … 431 431 } 432 432 } 433 433 434 434 return size; 435 435 } … … 446 446 } 447 447 } 448 448 449 449 /* OK, encode it */ 450 450 if (buf) … … 458 458 cpixel_ctx_t cpixel; 459 459 cpixel_context_init(&cpixel, &rfb->pixel_format); 460 460 461 461 size_t size = 0; 462 462 for (uint16_t y = 0; y < rect->height; y += 16) { … … 468 468 .height = (y + 16 <= rect->height ? 16 : rect->height - y) 469 469 }; 470 470 471 471 size += 1; 472 472 uint8_t *tile_enctype_ptr = buf; 473 473 if (buf) 474 474 buf += 1; 475 475 476 476 uint8_t tile_enctype = RFB_TILE_ENCODING_SOLID; 477 477 size_t tile_size; … … 482 482 tile_enctype = RFB_TILE_ENCODING_RAW; 483 483 } 484 484 485 485 if (buf) { 486 486 *tile_enctype_ptr = tile_enctype; … … 502 502 rfb->damage_rect.height = rfb->height; 503 503 } 504 504 505 505 506 506 /* We send only single raw rectangle right now */ … … 509 509 rfb_rect_encode_raw(rfb, &rfb->damage_rect, NULL) 510 510 ; 511 511 512 512 void *buf = malloc(buf_size); 513 513 if (buf == NULL) { … … 516 516 } 517 517 memset(buf, 0, buf_size); 518 518 519 519 void *pos = buf; 520 520 rfb_framebuffer_update_t *fbu = buf; … … 523 523 rfb_framebuffer_update_to_be(fbu, fbu); 524 524 pos += sizeof(rfb_framebuffer_update_t); 525 525 526 526 rfb_rectangle_t *rect = pos; 527 527 pos += sizeof(rfb_rectangle_t); 528 528 529 529 *rect = rfb->damage_rect; 530 530 531 531 if (rfb->supports_trle) { 532 532 rect->enctype = RFB_ENCODING_TRLE; … … 538 538 } 539 539 rfb_rectangle_to_be(rect, rect); 540 540 541 541 rfb->damage_valid = false; 542 542 543 543 size_t send_palette_size = 0; 544 544 void *send_palette = NULL; 545 545 546 546 if (!rfb->pixel_format.true_color) { 547 547 send_palette = rfb_send_palette_message(rfb, &send_palette_size); … … 552 552 } 553 553 } 554 554 555 555 fibril_mutex_unlock(&rfb->lock); 556 556 557 557 if (!rfb->pixel_format.true_color) { 558 558 errno_t rc = tcp_conn_send(conn, send_palette, send_palette_size); … … 562 562 } 563 563 } 564 564 565 565 errno_t rc = tcp_conn_send(conn, buf, buf_size); 566 566 free(buf); 567 567 568 568 return rc; 569 569 } … … 605 605 return; 606 606 } 607 607 608 608 char client_version[12]; 609 609 rc = recv_chars(conn, client_version, 12); … … 613 613 return; 614 614 } 615 615 616 616 if (memcmp(client_version, "RFB 003.008\n", 12) != 0) { 617 617 log_msg(LOG_DEFAULT, LVL_WARN, "Client version is not RFB 3.8"); 618 618 return; 619 619 } 620 620 621 621 /* Security handshake 622 622 * 1 security type supported, which is 1 - None … … 631 631 return; 632 632 } 633 633 634 634 char selected_sec_type = 0; 635 635 rc = recv_char(conn, &selected_sec_type); … … 651 651 return; 652 652 } 653 653 654 654 /* Client init */ 655 655 char shared_flag; … … 660 660 return; 661 661 } 662 662 663 663 /* Server init */ 664 664 fibril_mutex_lock(&rfb->lock); … … 684 684 return; 685 685 } 686 686 687 687 while (true) { 688 688 char message_type = 0; … … 693 693 return; 694 694 } 695 695 696 696 rfb_set_pixel_format_t spf; 697 697 rfb_set_encodings_t se; … … 765 765 inet_ep_t ep; 766 766 errno_t rc; 767 767 768 768 rc = tcp_create(&tcp); 769 769 if (rc != EOK) { … … 771 771 goto error; 772 772 } 773 773 774 774 inet_ep_init(&ep); 775 775 ep.port = port; 776 776 777 777 rc = tcp_listener_create(tcp, &ep, &listen_cb, rfb, &conn_cb, rfb, 778 778 &lst); … … 781 781 goto error; 782 782 } 783 783 784 784 rfb->tcp = tcp; 785 785 rfb->lst = lst; 786 786 787 787 return EOK; 788 788 error:
Note:
See TracChangeset
for help on using the changeset viewer.
