aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/evas/engines/gl_generic/ector_surface.c
blob: 32805b95f2f69adce875390036e0fe44c0527b90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifdef HAVE_CONFIG_H
#include "config.h"  /* so that EAPI in Evas.h is correctly defined */
#endif

#include <Ector.h>

#include "cairo/Ector_Cairo.h"
#include "software/Ector_Software.h"

#include "evas_common_private.h"
#include "evas_private.h"
#include "ector_cairo_software_surface.eo.h"

#define USE(Obj, Sym, Error)                            \
  if (!Sym) Sym = _ector_cairo_symbol_get(Obj, #Sym);   \
  if (!Sym) return Error;

static inline void *
_ector_cairo_symbol_get(Eo *ector_surface, const char *name)
{
   void *sym;

   eo_do(ector_surface,
         sym = ector_cairo_surface_symbol_get(ector_surface, name));
   return sym;
}

typedef struct _cairo_surface_t cairo_surface_t;
typedef enum {
  CAIRO_FORMAT_INVALID   = -1,
  CAIRO_FORMAT_ARGB32    = 0,
  CAIRO_FORMAT_RGB24     = 1,
  CAIRO_FORMAT_A8        = 2,
  CAIRO_FORMAT_A1        = 3,
  CAIRO_FORMAT_RGB16_565 = 4,
  CAIRO_FORMAT_RGB30     = 5
} cairo_format_t;

static cairo_surface_t *(*cairo_image_surface_create_for_data)(unsigned char *data,
                                                               cairo_format_t format,
                                                               int width,
                                                               int height,
                                                               int stride) = NULL;
static void (*cairo_surface_destroy)(cairo_surface_t *surface) = NULL;
static cairo_t *(*cairo_create)(cairo_surface_t *target) = NULL;
static void (*cairo_destroy)(cairo_t *cr) = NULL;

typedef struct _Ector_Cairo_Software_Surface_Data Ector_Cairo_Software_Surface_Data;
struct _Ector_Cairo_Software_Surface_Data
{
   cairo_surface_t *surface;
   cairo_t *ctx;

   void *pixels;

   unsigned int width;
   unsigned int height;
};

static void
_ector_cairo_software_surface_surface_set(Eo *obj, Ector_Cairo_Software_Surface_Data *pd, void *pixels, unsigned int width, unsigned int height)
{
   USE(obj, cairo_image_surface_create_for_data, );
   USE(obj, cairo_surface_destroy, );
   USE(obj, cairo_create, );
   USE(obj, cairo_destroy, );

   if (pd->surface) cairo_surface_destroy(pd->surface); pd->surface = NULL;
   if (pd->ctx) cairo_destroy(pd->ctx); pd->ctx = NULL;

   pd->pixels = NULL;
   pd->width = 0;
   pd->height = 0;

   if (pixels)
     {
        pd->surface = cairo_image_surface_create_for_data(pixels,
                                                          CAIRO_FORMAT_ARGB32,
                                                          width, height, width);
        if (!pd->surface) goto end;

        pd->ctx = cairo_create(pd->surface);
        if (!pd->ctx) goto end;
     }
   pd->pixels = pixels;
   pd->width = width;
   pd->height = height;

 end:
   eo_do(obj,
         ector_cairo_surface_context_set(obj, pd->ctx),
         ector_surface_size_set(obj, pd->width, pd->height));
}

static void
_ector_cairo_software_surface_surface_get(Eo *obj EINA_UNUSED, Ector_Cairo_Software_Surface_Data *pd, void **pixels, unsigned int *width, unsigned int *height)
{
   if (pixels) *pixels = pd->pixels;
   if (width) *width = pd->width;
   if (height) *height = pd->height;
}

#include "ector_cairo_software_surface.eo.c"