2015-04-14 12:39:55 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h" /* so that EAPI in Evas.h is correctly defined */
|
|
|
|
#endif
|
|
|
|
|
2015-12-02 22:10:18 -08:00
|
|
|
#include "Ector_Cairo.h"
|
|
|
|
#include "ector_private.h"
|
2015-11-30 22:22:20 -08:00
|
|
|
#include <software/Ector_Software.h>
|
2015-04-14 12:39:55 -07:00
|
|
|
#include "ector_cairo_software_surface.eo.h"
|
2015-11-30 22:22:20 -08:00
|
|
|
|
|
|
|
#define MY_CLASS ECTOR_CAIRO_SOFTWARE_SURFACE_CLASS
|
2015-04-14 12:39:55 -07:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
sym = ector_cairo_surface_symbol_get(ector_surface, name);
|
2015-04-14 12:39:55 -07:00
|
|
|
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;
|
2015-11-30 22:22:20 -08:00
|
|
|
Ector_Software_Buffer_Base_Data *base;
|
2015-04-14 12:39:55 -07:00
|
|
|
};
|
|
|
|
|
2015-11-30 22:22:20 -08:00
|
|
|
EOLIAN static Eina_Bool
|
2016-05-11 04:57:06 -07:00
|
|
|
_ector_cairo_software_surface_ector_buffer_pixels_set(Eo *obj, Ector_Cairo_Software_Surface_Data *pd,
|
2018-02-07 21:27:15 -08:00
|
|
|
void *pixels, int width, int height, int stride,
|
evas filters: Refactor ector and gfx filters A LOT
Alright, so this is a massive patch that is the result of
trying to get rid of unused or poorly implemented classes in
ector. Originally ector was meant to support VG but extend to
things like filters as well. At the moment, ector's design
makes it quite hard to plug in the filters.
For now I think it's easier to implement the GL support for
the filters directly in the engine, where I hope to interfere
as little as possible.
This massive patch keeps only the required minimum to support
a versatile gl buffer that can be mapped, drawn or rendered to (FBO).
It's extremely inefficient as it relies on glReadPixels and lots
of texture uploads, as well as conversions between ARGB and Alpha.
Another type of GL buffer is a wrap around an existing GL image,
but that one is read-only (map or draw: no write map, no FBO).
No, all the filters run fine, and the high-level implementation
(evas_filters.c) does not need to know whether the underlying engine
is SW or GL. One problem though appears with the blending or blurring
of some Alpha buffers, the colors are wrong.
This patch removes more lines than it adds so it must be good ;)
2017-01-17 18:47:25 -08:00
|
|
|
Efl_Gfx_Colorspace cspace, Eina_Bool writable)
|
2015-04-14 12:39:55 -07:00
|
|
|
{
|
2015-11-30 22:22:20 -08:00
|
|
|
cairo_t *ctx = NULL;
|
|
|
|
Eina_Bool ok = EINA_FALSE;
|
|
|
|
|
|
|
|
if ((cspace != EFL_GFX_COLORSPACE_ARGB8888) || !writable)
|
|
|
|
{
|
|
|
|
ERR("Unsupported surface type!");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
USE(obj, cairo_image_surface_create_for_data, EINA_FALSE);
|
|
|
|
USE(obj, cairo_surface_destroy, EINA_FALSE);
|
|
|
|
USE(obj, cairo_create, EINA_FALSE);
|
|
|
|
USE(obj, cairo_destroy, EINA_FALSE);
|
2015-04-14 12:39:55 -07:00
|
|
|
|
2015-11-30 22:22:20 -08:00
|
|
|
if (pd->surface)
|
|
|
|
cairo_surface_destroy(pd->surface);
|
|
|
|
pd->surface = NULL;
|
2015-04-14 12:39:55 -07:00
|
|
|
|
2018-02-07 21:27:15 -08:00
|
|
|
ok = ector_buffer_pixels_set(efl_super(obj, MY_CLASS), pixels, width, height, stride, cspace, writable);
|
2015-04-14 12:39:55 -07:00
|
|
|
|
2015-11-30 22:22:20 -08:00
|
|
|
if (ok && pixels)
|
2015-04-14 12:39:55 -07:00
|
|
|
{
|
|
|
|
pd->surface = cairo_image_surface_create_for_data(pixels,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
2015-11-30 22:22:20 -08:00
|
|
|
width, height, pd->base->stride);
|
2015-04-14 12:39:55 -07:00
|
|
|
if (!pd->surface) goto end;
|
|
|
|
|
2015-11-30 22:22:20 -08:00
|
|
|
ctx = cairo_create(pd->surface);
|
2015-04-14 12:39:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2015-12-02 22:10:18 -08:00
|
|
|
/* evas_common_cpu_end_opt(); // do we need this? */
|
2016-03-01 10:06:28 -08:00
|
|
|
ector_cairo_surface_context_set(obj, ctx);
|
2015-11-30 22:22:20 -08:00
|
|
|
return ok;
|
2015-04-14 12:39:55 -07:00
|
|
|
}
|
|
|
|
|
2015-11-30 22:22:20 -08:00
|
|
|
void
|
2015-04-14 12:39:55 -07:00
|
|
|
_ector_cairo_software_surface_surface_get(Eo *obj EINA_UNUSED, Ector_Cairo_Software_Surface_Data *pd, void **pixels, unsigned int *width, unsigned int *height)
|
|
|
|
{
|
2015-11-30 22:22:20 -08:00
|
|
|
if (pixels) *pixels = pd->base->pixels.u8;
|
|
|
|
if (width) *width = pd->base->generic->w;
|
|
|
|
if (height) *height = pd->base->generic->h;
|
|
|
|
}
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
static Efl_Object *
|
|
|
|
_ector_cairo_software_surface_efl_object_constructor(Eo *obj, Ector_Cairo_Software_Surface_Data *pd)
|
2015-11-30 22:22:20 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_constructor(efl_super(obj, MY_CLASS));
|
2016-01-21 15:56:49 -08:00
|
|
|
|
|
|
|
if (!obj) return NULL;
|
2016-08-15 06:44:41 -07:00
|
|
|
pd->base = efl_data_ref(obj, ECTOR_SOFTWARE_BUFFER_BASE_MIXIN);
|
|
|
|
pd->base->generic = efl_data_ref(obj, ECTOR_BUFFER_MIXIN);
|
2015-11-30 22:22:20 -08:00
|
|
|
pd->base->generic->eo = obj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_ector_cairo_software_surface_efl_object_destructor(Eo *obj, Ector_Cairo_Software_Surface_Data *pd)
|
2015-11-30 22:22:20 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_data_unref(obj, pd->base);
|
|
|
|
efl_destructor(efl_super(obj, MY_CLASS));
|
2015-04-14 12:39:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "ector_cairo_software_surface.eo.c"
|