#include <Evas.h>
#include <Evas_Engine_Buffer.h>
#include <stdio.h>
#include <errno.h>
#define WIDTH (320)
#define HEIGHT (240)
static Evas *create_canvas(
int width,
int height);
static void destroy_canvas(
Evas *canvas);
static void draw_scene(
Evas *canvas);
static void save_scene(
Evas *canvas,
const char *dest);
int main(void)
{
canvas = create_canvas(WIDTH, HEIGHT);
if (!canvas)
return -1;
puts("initial scene, with just background:");
draw_scene(canvas);
puts("final scene (note updates):");
draw_scene(canvas);
save_scene(canvas, "/tmp/evas-buffer-simple-render.ppm");
destroy_canvas(canvas);
return 0;
}
static Evas *create_canvas(
int width,
int height)
{
Evas_Engine_Info_Buffer *einfo;
int method;
void *pixels;
if (method <= 0)
{
fputs("ERROR: evas was not compiled with 'buffer' engine!\n", stderr);
return NULL;
}
if (!canvas)
{
fputs("ERROR: could not instantiate new evas canvas.\n", stderr);
return NULL;
}
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
return NULL;
}
pixels = malloc(width * height * sizeof(int));
if (!pixels)
{
fputs("ERROR: could not allocate canvas pixels!\n", stderr);
return NULL;
}
einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
einfo->info.dest_buffer = pixels;
einfo->info.dest_buffer_row_bytes = width * sizeof(int);
einfo->info.use_color_key = 0;
einfo->info.alpha_threshold = 0;
einfo->info.func.new_update_region = NULL;
einfo->info.func.free_update_region = NULL;
return canvas;
}
static void destroy_canvas(
Evas *canvas)
{
Evas_Engine_Info_Buffer *einfo;
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
return;
}
free(einfo->info.dest_buffer);
}
static void draw_scene(
Evas *canvas)
{
printf("UPDATED REGION: pos: %3d, %3d size: %3dx%3d\n",
update->
x, update->
y, update->
w, update->
h);
}
static void save_scene(
Evas *canvas,
const char *dest)
{
Evas_Engine_Info_Buffer *einfo;
const unsigned int *pixels, *pixels_end;
int width, height;
FILE *f;
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
return;
}
f = fopen(dest, "wb+");
if (!f)
{
fprintf(stderr, "ERROR: could not open for writing '%s': %s\n",
dest, strerror(errno));
return;
}
pixels = einfo->info.dest_buffer;
pixels_end = pixels + (width * height);
fprintf(f, "P6\n%d %d\n255\n", width, height);
for (; pixels < pixels_end; pixels++)
{
int r, g, b;
r = ((*pixels) & 0xff0000) >> 16;
g = ((*pixels) & 0x00ff00) >> 8;
b = (*pixels) & 0x0000ff;
fprintf(f, "%c%c%c", r, g, b);
}
fclose(f);
printf("saved scene as '%s'\n", dest);
}