- /* potential FALL THROUGH */
-
- 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 */
-
- case SST_SENDING:
- while (1) {
- unsigned char mbuf[8192 /* XXX magic */];
-
- 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 = ceildiv(fb->curmode.xres, SCREEN_CHUNKS_X);
+ 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 = ceildiv(fb->curmode.yres, SCREEN_CHUNKS_Y);
+ 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);
+ }
+
+ /* 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]) {
+ if (advance_chunk(state))
+ return;
+ continue;
+ }
+ /* Checksum gets set in data block, AFTER the data has been sent. */