render_multi.c
author Tero Marttila <terom@fixme.fi>
Sat, 07 Jun 2008 05:05:18 +0300
changeset 13 ee426f453cf5
parent 11 082bfaf38cf0
child 15 e7f0697814dc
permissions -rw-r--r--
* fix some (of the) stupid things in Makefile
* increment remote_node->current_load in remote_pool_get
* re-add render_init
* add render_raw module to handle non-PNG rendering
* update render_local to support RENDER_RAW
* working (but limited and inefficient) implementation of render_multi
* fixes to render_png
* improve/clean up render_remote
* mark internal function static
* make web_main use render_multi
* random bugfixes (possibly due to vim acting weird re file recovery post-crash)

committer: Tero Marttila <terom@fixme.fi>
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     1
#include <stdlib.h>
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     2
#include <assert.h>
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     4
#include "common.h"
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     5
#include "render_internal.h"
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include "render_multi.h"
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     7
#include "render_remote.h"
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include "remote_node.h"
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
     9
#include "render_png.h"
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
struct render_multi {
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    // these are used as arguments to render_remote
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    13
    struct render_multi_sub {
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
        // our offset in the list
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
        int index;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
        // the remote_render_ctx
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
        struct remote_render_ctx *remote_render;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
        
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
        // a pointer to ourself
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
        struct render_multi *self;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    23
        // if the render connection is marked as done without us having read all the data, move it from render_remote's buffers into here
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    24
        struct evbuffer *in_buf;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    25
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
        // _render_sent called for this?
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
        int render_sent;
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    28
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    29
        // our offset into the row, static
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    30
        size_t row_offset;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    31
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    32
        // how wide our slice is, static
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    33
        size_t slice_width;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    34
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    35
        // how many bytes we have already written into the current row
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    36
        size_t col;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    37
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    38
        // is this render op done?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    39
        int render_done;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
    } remote_renders[RENDER_MULTI_NODES_MAX];
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
    
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    // how many remote_renders we have
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    int remote_render_count;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    45
    // have we called cb_sent?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    46
    int have_sent;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    47
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    48
    // the png thing
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    49
    struct render_png *png_info;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    50
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    51
    // our pixel data row
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    52
    unsigned char *rowbuf;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    53
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    54
    // buffer render_png output in this
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    55
    struct evbuffer *out_buf;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    56
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
    // our own callbacks that we call
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
    void (*cb_sent)(void *arg);
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
    void (*cb_data)(struct evbuffer *buf, void *arg);
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
    void (*cb_done)(void *arg);
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
    void (*cb_fail)(void *arg);
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
    void *cb_arg;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
};
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    66
#define FAIL_PARTIAL 0x01
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    67
#define FAIL_SILENT 0x02
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    68
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    69
// prototypes
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    70
static void _render_multi_do_free (struct render_multi *ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    71
static void _render_multi_do_sent (struct render_multi *ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    72
static void _render_multi_do_done (struct render_multi *ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    73
static void _render_multi_do_fail (struct render_multi *ctx, int flags);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    74
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    75
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    76
 * Actually free the request. Should be de-initialized (either _render_multi_error, or _render_done when this is called
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    77
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    78
static void _render_multi_do_free (struct render_multi *ctx) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    79
    if (!ctx)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    80
        return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    81
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    82
    int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    83
    for (i = 0; i < ctx->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    84
        if (ctx->remote_renders[i].in_buf) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    85
            evbuffer_free(ctx->remote_renders[i].in_buf);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    86
            ctx->remote_renders[i].in_buf = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    87
        }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    88
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    89
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    90
    if (ctx->rowbuf) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    91
        free(ctx->rowbuf);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    92
        ctx->rowbuf = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    93
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    94
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    95
    if (ctx->out_buf) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    96
        evbuffer_free(ctx->out_buf);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    97
        ctx->out_buf = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    98
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    99
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   100
    free(ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   101
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   102
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   103
// the request has been sent
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   104
static void _render_multi_do_sent (struct render_multi *ctx) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   105
    int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   106
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   107
    // check that all the remote_renders have indeed been sent
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   108
    for (i = 0; i < ctx->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   109
        assert(ctx->remote_renders[i].render_sent);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   110
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   111
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   112
    // assert the callbacks are still valid
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   113
    assert(ctx->cb_sent && ctx->cb_fail && ctx->cb_done);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   114
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   115
    // call cb_sent and then invalidate it
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   116
    ctx->cb_sent(ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   117
    ctx->cb_sent = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   118
    ctx->have_sent = 1;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   119
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   120
    // we're going to always have the PNG header data buffered at this point, so give that to the user right away
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   121
    assert(evbuffer_get_length(ctx->out_buf) > 0);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   122
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   123
    ctx->cb_data(ctx->out_buf, ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   124
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   125
    // ok
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   126
    return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   127
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   128
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   129
// the request compelted normally
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   130
static void _render_multi_do_done (struct render_multi *ctx) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   131
    int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   132
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   133
    // check that all the remote_renders are indeed complete
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   134
    for (i = 0; i < ctx->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   135
        assert(ctx->remote_renders[i].remote_render == NULL);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   136
        assert(ctx->remote_renders[i].col == 0);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   137
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   138
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   139
    // finish the png_info
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   140
    if (render_png_done(ctx->png_info)) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   141
        // don't free it twice, though...
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   142
        ctx->png_info = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   143
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   144
        ERROR("render_png_done");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   145
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   146
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   147
    ctx->png_info = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   148
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   149
    // check that both callbacks are still valid
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   150
    assert(ctx->cb_fail && ctx->cb_done);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   151
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   152
    // call cb_done and then invalidate it
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   153
    ctx->cb_done(ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   154
    ctx->cb_fail = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   155
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   156
    // free ourself
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   157
    _render_multi_do_free(ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   158
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   159
    // ok
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   160
    return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   161
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   162
error:    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   163
    /* O_o */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   164
    _render_multi_do_fail(ctx, FAIL_PARTIAL);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   165
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   166
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   167
// the request completed abnormally. Flags:
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   168
//  FAIL_SILENT     - don't call cb_fail
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   169
//  FAIL_PARTIAL    - assume png_info may be NULL
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   170
static void _render_multi_do_fail (struct render_multi *ctx, int flags) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   171
    int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   172
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   173
    // cancel any in-progress remote renders
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   174
    for (i = 0; i < ctx->remote_render_count; i++)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   175
        if (ctx->remote_renders[i].remote_render) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   176
            render_remote_cancel(ctx->remote_renders[i].remote_render);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   177
            ctx->remote_renders[i].remote_render = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   178
        }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   179
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   180
    if (!(flags & FAIL_PARTIAL) || ctx->png_info) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   181
        // abort the render_png
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   182
        render_png_abort(ctx->png_info);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   183
        ctx->png_info = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   184
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   185
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   186
    // check that both callbacks are still valid
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   187
    assert(ctx->cb_fail && ctx->cb_done);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   188
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   189
    if (!(flags & FAIL_SILENT)) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   190
        // call cb_fail and then invalidate it
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   191
        ctx->cb_fail(ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   192
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   193
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   194
    ctx->cb_fail = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   195
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   196
    // free ourselves
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   197
    _render_multi_do_free(ctx);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   198
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   199
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   200
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   201
 * One of the remote render commands has succesfully been sent.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   202
 *
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   203
 * Once all of these commands have been sent, invoke our cb_sent.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   204
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   205
static void _render_multi_sent (void *arg) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   206
    struct render_multi_sub *ctx = arg;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   207
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   208
    ctx->render_sent = 1;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   209
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   210
    // have all render_sub_ctxs been sent?
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   211
    int i;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   212
    for (i = 0; i < ctx->self->remote_render_count; i++) {
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   213
        if (!ctx->self->remote_renders[i].render_sent)
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   214
            break;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   215
    }
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   216
    
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   217
    // did we loop through all of them?
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   218
    if (i == ctx->self->remote_render_count) {
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   219
        // tell our user
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   220
        _render_multi_do_sent(ctx->self);
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   221
    }
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   222
}
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   223
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   224
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   225
 * We have received data from a single render node.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   226
 *
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   227
 * Move the data into the row buffer if there's space in it, otherwise
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   228
 * leave it inside the buffer.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   229
 *
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   230
 * If this fills up our slice, check and see if the entire row is now full. If
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   231
 * it is, pass the row to render_png_row, clear out the col values, and call
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   232
 * render_remote_shake for each remote render
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   233
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   234
static void _render_multi_data (struct evbuffer *buf, void *arg) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   235
    struct render_multi_sub *ctx = arg;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   236
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   237
    assert(ctx->col <= ctx->slice_width);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   238
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   239
    // are we being called from _render_multi_done?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   240
    if (ctx->render_done && ctx->in_buf == NULL) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   241
        // move all the data into our own buffer
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   242
        if (!(ctx->in_buf = evbuffer_new()))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   243
            ERROR("evbuffer_new");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   244
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   245
        if (evbuffer_add_buffer(ctx->in_buf, buf))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   246
            ERROR("evbuffer_add_buffer");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   247
        
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   248
        // don't do anything else
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   249
        return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   250
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   251
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   252
    // is our slice full?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   253
    if (ctx->col == ctx->slice_width) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   254
        // don't care for new data
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   255
        return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   256
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   257
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   258
    // read new data into our slice
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   259
//    printf("rowbuf + %4d : %d");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   260
    ctx->col += evbuffer_remove(buf, ctx->self->rowbuf + ctx->row_offset + ctx->col, ctx->slice_width - ctx->col);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   261
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   262
    // is our slice full now?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   263
    if (ctx->col == ctx->slice_width) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   264
        // is the row complete now?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   265
        int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   266
        for (i = 0; i < ctx->self->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   267
            if (ctx->self->remote_renders[i].col < ctx->self->remote_renders[i].slice_width)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   268
                break;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   269
        }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   270
        
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   271
        // are they all full?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   272
        if (i == ctx->self->remote_render_count) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   273
            // pass the data to render_png, this results in calls to _render_multi_png_data
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   274
            if (render_png_row(ctx->self->png_info, ctx->self->rowbuf))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   275
                ERROR("render_png_row");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   276
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   277
            // clear the col values
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   278
            for (i = 0; i < ctx->self->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   279
                ctx->self->remote_renders[i].col = 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   280
            }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   281
            
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   282
            // shake the buffers
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   283
            // XXX: this will result in recursion
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   284
            for (i = 0; i < ctx->self->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   285
                if (ctx->self->remote_renders[i].remote_render) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   286
                    if (render_remote_shake(ctx->self->remote_renders[i].remote_render))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   287
                        ERROR("render_remote_shake");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   288
                } else {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   289
                    // already disconnected, use in_buf instead
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   290
                    assert(ctx->self->remote_renders[i].in_buf);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   291
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   292
                    // call it directly...
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   293
                    _render_multi_data(ctx->self->remote_renders[i].in_buf, &ctx->self->remote_renders[i]);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   294
                }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   295
            }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   296
        }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   297
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   298
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   299
    return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   300
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   301
error:
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   302
    _render_multi_do_fail(ctx->self, 0);
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   303
}
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   304
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   305
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   306
 * We fed a row of pixels into render_png, and this PNG data came out.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   307
 *
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   308
 * We need to pass it back to our caller
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   309
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   310
static int _render_multi_png_data (const unsigned char *data, size_t length, void *arg) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   311
    struct render_multi *ctx = arg;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   312
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   313
    // XXX: avoid these many data copies?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   314
    if (evbuffer_add(ctx->out_buf, data, length))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   315
        ERROR("evbuffer_add");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   316
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   317
    // only call the data cb if we've already called cb_sent
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   318
    if (ctx->have_sent)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   319
        ctx->cb_data(ctx->out_buf, ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   320
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   321
    // ok
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   322
    return 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   323
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   324
error:
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   325
    // don't do any failing here, this will return control to a _render_* function that will handle it
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   326
    return -1;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   327
}
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   328
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   329
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   330
 * The render node has rendered everything that it needs to render. Our slice
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   331
 * of the last row should be full (or empty) now. If all the remote_renders are
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   332
 * done, we can call render_png_done and then cb_done.
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   333
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   334
static void _render_multi_done (void *arg) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   335
    struct render_multi_sub *ctx = arg;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   336
 
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   337
    // mark it as done
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   338
    ctx->render_done = 1;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   339
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   340
    // shake out the rest of the data as needed, as render_multi won't keep it anymore
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   341
    render_remote_shake(ctx->remote_render);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   342
   
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   343
    // invalidate this ctx's remote render
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   344
    ctx->remote_render = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   345
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   346
    // is the data incomplete?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   347
    if (!(ctx->col == ctx->slice_width || ctx->col == 0))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   348
        ERROR("incomplete data for slice %d: %d/%d bytes", ctx->index, ctx->col, ctx->slice_width);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   349
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   350
    // are all of them done?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   351
    int i;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   352
    for (i = 0; i < ctx->self->remote_render_count; i++) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   353
        if (!ctx->self->remote_renders[i].render_done)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   354
            break;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   355
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   356
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   357
    // are they all done?
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   358
    if (i == ctx->self->remote_render_count) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   359
        // finish it off
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   360
        _render_multi_do_done(ctx->self);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   361
    }
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   362
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   363
    // ok, wait for the rest to complete
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   364
    return;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   365
    
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   366
error:
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   367
    _render_multi_do_fail(ctx->self, 0);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   368
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   369
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   370
/*
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   371
 * One render node failed, abort the whole thing
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   372
 */
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   373
static void _render_multi_fail (void *arg) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   374
    struct render_multi_sub *ctx = arg;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   375
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   376
    // invalidate this ctx's remote render
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   377
    ctx->remote_render = NULL;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   378
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   379
    _render_multi_do_fail(ctx->self, 0);
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   380
}
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   381
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   382
#define ROUND_DOWN(dividend, divisor) ((dividend) / (divisor))
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   383
#define ROUND_UP(dividend, divisor) (((dividend) / (divisor)) + ((dividend) % (divisor)))
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   384
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   385
#define HALF(a, b) (( a + b) / 2)
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   386
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   387
struct render_multi *render_multi (
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   388
        struct render *render,               // what to render
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   389
        struct remote_pool *pool_info,    // what render pool to use
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   390
        void (*cb_sent)(void *arg),
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   391
        void (*cb_data)(struct evbuffer *buf, void *arg),
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   392
        void (*cb_done)(void *arg),
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   393
        void (*cb_fail)(void *arg),
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   394
        void *cb_arg
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   395
) {
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   396
    struct render_multi *ctx = NULL;
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   397
    struct render r_left, r_right;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   398
    
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   399
    // alloc the render_multi
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   400
    ctx = calloc(1, sizeof(struct render_multi));
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   401
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   402
    if (!ctx)
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   403
        ERROR("calloc");
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   404
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   405
    // init the remote_render
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   406
    // for now, just split it in half into two render_ts
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   407
    ctx->remote_renders[0].index = 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   408
    ctx->remote_renders[0].self = ctx;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   409
    ctx->remote_renders[0].slice_width = render->img_w / 2;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   410
    ctx->remote_renders[0].row_offset = 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   411
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   412
    ctx->remote_renders[1].index = 1;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   413
    ctx->remote_renders[1].self = ctx;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   414
    ctx->remote_renders[1].slice_width = render->img_w / 2 + render->img_w % 2;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   415
    ctx->remote_renders[1].row_offset = render->img_w / 2;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   416
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   417
    ctx->remote_render_count = 2;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   418
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   419
    assert(RENDER_MULTI_NODES_MAX >= 2);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   420
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   421
    if (
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   422
            render_init(&r_left, RENDER_RAW)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   423
         || render_init(&r_right, RENDER_RAW)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   424
         || render_set_size(&r_left, ctx->remote_renders[0].slice_width, render->img_h)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   425
         || render_set_size(&r_right, ctx->remote_renders[1].slice_width, render->img_h)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   426
         || render_region_raw(&r_left, render->x1, render->y1, HALF(render->x1, render->x2), render->y2)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   427
         || render_region_raw(&r_right, HALF(render->x1, render->x2), render->y1, render->x2, render->y2)
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   428
    )
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   429
        ERROR("render_{init,set_size,set_region_raw}");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   430
            
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   431
    // store the provided callback functions
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   432
    ctx->cb_sent = cb_sent;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   433
    ctx->cb_data = cb_data;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   434
    ctx->cb_done = cb_done;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   435
    ctx->cb_fail = cb_fail;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   436
    ctx->cb_arg = cb_arg;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   437
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   438
    // our rowbuf
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   439
    if (!(ctx->rowbuf = malloc(render->img_w)))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   440
        ERROR("malloc");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   441
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   442
    // store our render_png callbacks, must be before png_info
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   443
    if (render_io_custom(render, &_render_multi_png_data, NULL, ctx))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   444
        ERROR("render_io_custom");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   445
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   446
    // evbuffer, must be before png_info
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   447
    if (!(ctx->out_buf = evbuffer_new()))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   448
        ERROR("evbuffer_new");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   449
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   450
    // png info
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   451
    if (!(ctx->png_info = render_png_init(render)))
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   452
        ERROR("render_png_init");
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   453
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   454
    // pull two nodes from the pool
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   455
    struct remote_node *node_left, *node_right;
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   456
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   457
    if (
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   458
            !(node_left = remote_pool_get(pool_info))
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   459
         || !(node_right = remote_pool_get(pool_info))
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   460
    )
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   461
        ERROR("remote_pool_get");
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   462
    
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   463
    // the two render_remote calls
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   464
    if (
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   465
            !(ctx->remote_renders[0].remote_render = render_remote(&r_left, node_left, 
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   466
                &_render_multi_sent, &_render_multi_data, &_render_multi_done, &_render_multi_fail, &ctx->remote_renders[0]))
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   467
         || !(ctx->remote_renders[1].remote_render = render_remote(&r_right, node_right,
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   468
                &_render_multi_sent, &_render_multi_data, &_render_multi_done, &_render_multi_fail, &ctx->remote_renders[1]))
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   469
    )
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   470
        ERROR("render_remote");
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   471
    
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   472
    // I guess that's a succesfull start now
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   473
    return ctx;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   474
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   475
error:
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   476
    _render_multi_do_fail(ctx, FAIL_SILENT | FAIL_PARTIAL);
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   477
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   478
    return NULL;
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   479
}
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   480
13
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   481
void render_multi_cancel (struct render_multi *ctx) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   482
    _render_multi_do_fail(ctx, FAIL_SILENT);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   483
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   484
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   485
int render_multi_set_recv (struct render_multi *ctx, size_t recv_threshold, size_t unread_buffer) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   486
    return 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   487
}
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   488
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   489
int render_multi_shake (struct render_multi *ctx) {
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   490
    // call the data cb
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   491
    ctx->cb_data(ctx->out_buf, ctx->cb_arg);
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   492
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   493
    return 0;
ee426f453cf5 * fix some (of the) stupid things in Makefile
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
   494
}