ector: first implementation of a Cairo surface.
authorCedric BAIL <cedric@osg.samsung.com>
Fri, 3 Apr 2015 14:22:01 +0000 (16:22 +0200)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 3 Apr 2015 14:22:01 +0000 (16:22 +0200)
src/Makefile_Ector.am
src/lib/ector/cairo/ector_cairo_private.h [new file with mode: 0644]
src/lib/ector/cairo/ector_cairo_surface.c
src/lib/ector/cairo/ector_cairo_surface.eo

index dca175f..5b0fbd1 100644 (file)
@@ -94,4 +94,5 @@ tests_ector_ector_suite_DEPENDENCIES = @USE_ECTOR_INTERNAL_LIBS@
 endif
 
 EXTRA_DIST += \
-src/lib/ector/ector_private.h
+src/lib/ector/ector_private.h \
+src/lib/ector/cairo/ector_cairo_private,h
diff --git a/src/lib/ector/cairo/ector_cairo_private.h b/src/lib/ector/cairo/ector_cairo_private.h
new file mode 100644 (file)
index 0000000..6777370
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef ECTOR_CAIRO_PRIVATE_H_
+# define ECTOR_CAIRO_PRIVATE_H_
+
+typedef void cairo_pattern_t;
+
+typedef struct _Ector_Cairo_Surface_Data Ector_Cairo_Surface_Data;
+struct _Ector_Cairo_Surface_Data
+{
+   cairo_t *cairo;
+};
+
+#define USE(Obj, Sym, Error)                     \
+  if (!Sym) _ector_cairo_symbol_get(Obj, #Sym);  \
+  if (!Sym) return Error;
+
+#define CHECK_CAIRO(Parent) (!(Parent && Parent->cairo))
+
+static inline void *
+_ector_cairo_symbol_get(Eo *obj, const char *name)
+{
+   Eo *parent;
+   void *sym;
+
+   eo_do(obj, parent = eo_parent_get());
+   if (!parent) return NULL;
+
+   eo_do(parent, sym = ector_cairo_surface_symbol_get(name));
+   return sym;
+}
+
+#endif
index 06f8ed7..c2d42a9 100644 (file)
@@ -7,30 +7,90 @@
 #include <cairo/Ector_Cairo.h>
 
 #include "ector_private.h"
+#include "ector_cairo_private.h"
 
-typedef struct _Ector_Cairo_Surface_Data Ector_Cairo_Surface_Data;
-struct _Ector_Cairo_Surface_Data
+static unsigned int _cairo_count = 0;
+static Eina_Module *_cairo_so = NULL;
+
+static void *
+_ector_cairo_surface_symbol_get(Eo *obj EINA_UNUSED,
+                                Ector_Cairo_Surface_Data *pd EINA_UNUSED,
+                                const char *name)
+{
+   if (!_cairo_so)
+     {
+#define LOAD(x)                                 \
+        if (!_cairo_so)                         \
+          {                                     \
+             _cairo_so = eina_module_new(x);    \
+             if (_cairo_so &&                   \
+                 !eina_module_load(_cairo_so))  \
+               {                                \
+                  eina_module_free(_cairo_so);  \
+                  _cairo_so = NULL;             \
+               }                                \
+          }
+#if defined(_WIN32) || defined(__CYGWIN__)
+        LOAD("libcairo.dll");
+#elif defined(__APPLE__) && defined(__MACH__)
+        LOAD("libcairo.dylib");
+        LOAD("libcairo.so");
+#else
+        LOAD("libcairo.so");
+#endif
+
+#undef LOAD
+     }
+
+   return eina_module_symbol_get(_cairo_so, name);
+}
+
+
+static Ector_Renderer *
+_ector_cairo_surface_ector_generic_surface_renderer_factory_new(Eo *obj,
+                                                                Ector_Cairo_Surface_Data *pd EINA_UNUSED,
+                                                                const Eo_Class *type)
 {
-};
+   if (eo_isa(type, ECTOR_RENDERER_CAIRO_SHAPE_CLASS))
+     return eo_add(ECTOR_RENDERER_CAIRO_SHAPE_CLASS, obj);
+   else if (eo_isa(type, ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS))
+     return eo_add(ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS, obj);
+   else if (eo_isa(type, ECTOR_RENDERER_CAIRO_GRADIENT_RADIAL_CLASS))
+     return eo_add(ECTOR_RENDERER_CAIRO_GRADIENT_RADIAL_CLASS, obj);
+   return NULL;
+}
 
-void *
-_ector_cairo_surface_symbol_get(Eo *obj, Ector_Cairo_Surface_Data *pd, char *name)
+static void
+_ector_cairo_surface_context_set(Eo *obj EINA_UNUSED,
+                                 Ector_Cairo_Surface_Data *pd,
+                                 cairo_t *ctx)
 {
+   pd->cairo = ctx;
 }
 
-Ector_Renderer *
-_ector_cairo_surface_ector_generic_surface_renderer_factory_new(Eo *obj, Ector_Cairo_Surface_Data *pd, const Eo_Class *type)
+static cairo_t *
+_ector_cairo_surface_context_get(Eo *obj EINA_UNUSED,
+                                 Ector_Cairo_Surface_Data *pd)
 {
+   return pd->cairo;
 }
 
-Eina_Bool
-_ector_cairo_surface_context_set(Eo *obj, Ector_Cairo_Surface_Data *pd, cairo_t *ctx)
+static void
+_ector_cairo_surface_eo_base_constructor(Eo *obj EINA_UNUSED,
+                                         Ector_Cairo_Surface_Data *pd EINA_UNUSED)
 {
+   _cairo_count++;
 }
 
-Eo *
-_ector_cairo_surface_eo_base_finalize(Eo *obj, Ector_Cairo_Surface_Data *pd)
+static void
+_ector_cairo_surface_eo_base_destructor(Eo *obj EINA_UNUSED,
+                                        Ector_Cairo_Surface_Data *pd EINA_UNUSED)
 {
+   if (--_cairo_count) return ;
+   if (_cairo_so) eina_module_free(_cairo_so);
+   _cairo_so = NULL;
 }
 
+
 #include "ector_cairo_surface.eo.c"
+#include "ector_renderer_cairo_base.eo.c"
index 8a36767..10f6d9f 100644 (file)
@@ -2,22 +2,28 @@ class Ector.Cairo.Surface (Ector.Generic.Surface)
 {
    eo_prefix: ector_cairo_surface;
    legacy_prefix: null;
+   properties {
+      context {
+         set {
+        }
+        get {
+        }
+        values {
+           cairo_t *ctx;
+        }
+      }
+   }
    methods {
       symbol_get {
          return: void * @warn_unused;
          params {
-            @in char* name;
+            @in const(char)* name;
          }
       }
-      context_set {
-         return: Eina_Bool;
-         params {
-           @in cairo_t *ctx;
-        }
-      }
    }
    implements {
       Ector.Generic.Surface.renderer_factory_new;
-      Eo.Base.finalize;
+      Eo.Base.destructor;
+      Eo.Base.constructor;
    }
 }