The canvas will here use the buffer engine.
#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);
}
#define EINA_LIST_FOREACH(list, l, _data)
Definition for the macro to iterate over a list.
Definition: eina_list.h:1415
EVAS_API Evas_Engine_Info * evas_engine_info_get(const Evas *obj)
Retrieves the current render engine info struct from the given evas.
Definition: evas_main.c:677
EVAS_API Eina_List * evas_render_updates(Evas_Canvas *obj)
Force immediate renderization of the given Evas canvas.
Definition: evas_canvas_eo.legacy.c:297
EVAS_API void evas_free(Evas *eo_e)
Frees the given evas and any objects created on it.
Definition: evas_main.c:391
EVAS_API void evas_render_updates_free(Eina_List *updates)
Free the rectangles returned by evas_render_updates().
Definition: evas_render.c:4078
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
EVAS_API void evas_output_method_set(Evas *eo_e, int render_method)
Sets the output engine for the given evas.
Definition: evas_main.c:1292
EVAS_API void evas_output_size_get(const Evas *eo_e, int *w, int *h)
Retrieve the output size of the render engine of the given evas.
Definition: evas_main.c:1402
EVAS_API void evas_output_size_set(Evas *eo_e, int w, int h)
Sets the output size of the render engine of the given evas.
Definition: evas_main.c:1374
EVAS_API Eina_Bool evas_engine_info_set(Evas *obj, Evas_Engine_Info *info)
Applies the engine settings for the given evas from the given Evas_Engine_Info structure.
Definition: evas_main.c:696
EVAS_API void evas_output_viewport_set(Evas *eo_e, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
Sets the output viewport of the given evas in evas units.
Definition: evas_main.c:1413
EVAS_API Evas * evas_new(void)
Creates a new empty evas.
Definition: evas_main.c:309
EVAS_API int evas_init(void)
Directly initialize Evas and its required dependencies.
Definition: evas_main.c:152
EVAS_API int evas_shutdown(void)
Directly shutdown Evas.
Definition: evas_main.c:239
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2024
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
EVAS_API int evas_render_method_lookup(const char *name)
Look up a numeric ID from a string name of a rendering engine.
Definition: evas_main.c:754
Type for a generic double linked list.
Definition: eina_list.h:318
Definition: eina_rectangle.h:109
int h
height of rectangle
Definition: eina_rectangle.h:113
int x
top-left x coordinate of rectangle
Definition: eina_rectangle.h:110
int y
top-left y coordinate of rectangle
Definition: eina_rectangle.h:111
int w
width of rectangle
Definition: eina_rectangle.h:112
Generic engine information.
Definition: Evas_Legacy.h:48