#ifndef RENDER_SLICES_H
#define RENDER_SLICES_H
#include "render.h"
#define RENDER_SLICES_MAX 2
struct render_slices;
struct render_slice_info {
// our index
size_t index;
// the render info
struct render *render_info;
// where to put the pixel data
unsigned char *render_buf;
};
/*
* Split the given render operation into multiple slices that can be rendered
* induvidually.
*
* A segment is a single row of a slice. The raw pixel data for each segment
* should be stored into the render_buf item in that slice's render_slice_info.
* When a full segment has been stored into the render_buf, you should call
* render_slices_segment_done with that slice's index as an argument, and then
* proceed based on its return code.
*
* Returns a struct render_slices handle which can be used to operate on the
* slices, or NULL on failure.
*/
struct render_slices *render_slices_alloc (struct render *render);
/*
* Get the number of slices that need to be rendered, which is also the valid
* range of index values for render_slices_get_slice_info.
*/
int render_slices_get_count (struct render_slices *ctx);
/*
* Get the struct render_slice_info corresponding to the given index. This
* the information required to render the segment. The index is used as an
* argument to render_slices_segment_done.
*/
struct render_slice_info *render_slices_get_slice_info (struct render_slices *ctx, int index);
/*
* You may call render_slices_segment_done again for any slice now, including
* those which returned ~SLICE_CONTINUE earlier.
*/
#define SLICE_CONTINUE 0x01
/*
* You may call render_slices_process_row next.
*/
#define SLICE_PROCESS_ROW 0x02
// XXX: you can't modify the slice's row buffer until these return SLICE_CONTINUE
/*
* The render_buf for the render_slice_info with the given index value contains
* the full information for the next row of the render_info render. Returns a
* bitwise-OR of the SLICE_* flags, or -1 for an error:
*
* Valid return values:
* zero
* Do not call segment_done for this index, or process_row right now.
* Information for some slice needed to complete the next row is missing,
* and the other segments must call segment_done first.
*
* SLICE_PROCESS_ROW
* Do not call segment_done for this index or any others, but do call
* process_row as soon as possible, and then continue once it returns
* (see render_slices_process_row).
*
* SLICE_CONTINUE & SLICE_PROCESS_ROW
* You should call process_row next, but you can also call segment_done
* for all segments that returned ~SLICE_CONTINUE earlier.
*
* -1 - An error occured. Rendering must be aborted.
*
*/
int render_slices_segment_done (struct render_slices *ctx, int index);
/*
* Process a completed row and generate output in the PNG format (how that is
* handled depends on the render given to render_slices_alloc/init). Returns a
* bitwise-OR of the SLICE_* flags, or -1 for an error:
*
* Valid return values :
* zero
* The PNG is done - you don't need to call segment_done or process_row
* anymore, doing so will result in an error. You don't need to deinit
* ctx, but you may need to free it.
*
* SLICE_CONTINUE
* You may call render_slices_segment_done again for those slices that
* returned ~SLICE_CONTINUE earlier.
*
* SLICE_CONTINUE & SLICE_PROCESS_ROW
* In addition to calling render_slices_segment_done again, you may also
* call render_slices_process_row again.
*
* -1 - An error occured. Rendering must be aborted.
*/
int render_slices_process_row (struct render_slices *ctx);
/*
* Signifiy that the render has been completed. This will flush out buffered
* output data.
*/
int render_slices_done (struct render_slices *ctx);
/*
* Free a render_slices. The rendering may or may not be complete.
*/
void render_slices_free (struct render_slices *ctx);
#endif /* RENDER_SLICES_H */