- /* FALL THROUGH to SST_NEEDS_UPDATE*/
- case SST_NEEDS_UPDATE:
- outputf("RFB send: sending header");
- /* Send a header */
- state->frame_bytes = fb->curmode.xres * fb->curmode.yres * fb->curmode.bytestride;
- hdr.msgtype = 0;
- hdr.nrects = htons(1);
- hdr.xpos = htons(0);
- hdr.ypos = htons(0);
- hdr.width = htons(fb->curmode.xres);
- hdr.height = htons(fb->curmode.yres);
- hdr.enctype = htonl(0);
- tcp_write(pcb, &hdr, sizeof(hdr), TCP_WRITE_FLAG_COPY);
-
- state->update_pos = 0;
- state->send_state = SST_SENDING;
-
- /* FALL THROUGH to SST_SENDING*/
- case SST_SENDING:
- while (1) {
- left = state->frame_bytes - state->update_pos;
-
- if (left == 0) {
- state->send_state = SST_IDLE;
- break;
+ /* FALL THROUGH to SST_HEADER */
+
+ case SST_HEADER:
+
+ /* Calculate the width and height for this chunk, remembering
+ * that if SCREEN_CHUNKS_[XY] do not evenly divide the width and
+ * height, we may need to have shorter chunks at the edge of
+ * the screen. */
+
+ state->chunk_width = fb->curmode.xres / SCREEN_CHUNKS_X;
+ if (fb->curmode.xres % SCREEN_CHUNKS_X != 0)
+ state->chunk_width += 1;
+ state->chunk_xpos = state->chunk_width * state->chunk_xnum;
+ totaldim = state->chunk_width * (state->chunk_xnum + 1);
+ if (totaldim > fb->curmode.xres) {
+ state->chunk_width -= (totaldim - fb->curmode.xres);
+ }
+
+ state->chunk_height = fb->curmode.yres / SCREEN_CHUNKS_Y;
+ if (fb->curmode.yres % SCREEN_CHUNKS_Y != 0)
+ state->chunk_height += 1;
+ state->chunk_ypos = state->chunk_height
+ * state->chunk_ynum;
+ totaldim = state->chunk_height * (state->chunk_ynum + 1);
+ if (totaldim > fb->curmode.yres) {
+ state->chunk_height -= (totaldim - fb->curmode.yres);
+ }
+
+ outputf("rfb send: (%d [%d], %d [%d]) %d x %d",
+ state->chunk_xnum, state->chunk_xpos,
+ state->chunk_ynum, state->chunk_ypos,
+ state->chunk_width, state->chunk_height);
+
+ /* Do we _actually_ need to send this chunk? */
+ if (fb->checksum_rect) {
+ state->chunk_checksum = fb->checksum_rect(state->chunk_xpos, state->chunk_ypos,
+ state->chunk_width, state->chunk_height);
+
+ if (state->chunk_checksum == state->checksums[state->chunk_xnum][state->chunk_ynum]) {
+ outputf("!!!!!!! SKIPPING: %08x", state->chunk_checksum);
+ if (advance_chunk(state))
+ return;
+ continue;
+ }
+ /* Checksum gets set in data block, AFTER the data has been sent. */