Beispiel #1
0
Shm_Handle *
cserve2_shm_resize(Shm_Handle *shm, size_t newsize)
{
   size_t map_size;
   int fd;

   if (!shm)
     return NULL;

   if (shm->map_offset || shm->image_offset)
     {
        CRI("Can not resize shm with non-zero offset");
        return NULL;
     }

   if (eina_inlist_count(shm->mapping->segments) > 1)
     {
        CRI("Can not resize shm with more than one segment");
        return NULL;
     }

   fd = shm_open(shm->mapping->name, O_RDWR, S_IRUSR | S_IWUSR);
   if (fd == -1)
     {
        ERR("Could not reopen shm handle: %m");
        return NULL;
     }

   map_size = cserve2_shm_size_normalize(newsize, 0);
   if (ftruncate(fd, map_size))
     {
        ERR("Could not set the size of the shm: %m");
        close(fd);
        return NULL;
     }

   if (shm->data)
     {
        munmap(shm->data, shm->image_size);
        shm->data = mmap(NULL, shm->image_size, PROT_WRITE, MAP_SHARED,
                         fd, shm->image_offset);
     }
   close(fd);

   shm->map_size = map_size;
   shm->image_size = newsize;
   shm->mapping->length = map_size;

   return shm;
}
Beispiel #2
0
/* TODO: Documentation says "All  implementations  support  the  system-wide
 * real-time clock, which is identified by CLOCK_REALTIME. Check if the fallback
 * to unix time (without specifying the resolution) might be removed
 */
void
_ecore_time_init(void)
{
#if defined (HAVE_CLOCK_GETTIME) || defined (EXOTIC_PROVIDE_CLOCK_GETTIME)
   struct timespec t;

   if (_ecore_time_clock_id != -1) return;

   if (!clock_gettime(CLOCK_MONOTONIC, &t))
     {
        _ecore_time_clock_id = CLOCK_MONOTONIC;
        DBG("using CLOCK_MONOTONIC.");
     }
   else if (!clock_gettime(CLOCK_REALTIME, &t))
     {
        /* may go backwards */
         _ecore_time_clock_id = CLOCK_REALTIME;
         WRN("CLOCK_MONOTONIC not available. Fallback to CLOCK_REALTIME.");
     }
   else
     {
        _ecore_time_clock_id = -2;
        CRI("Cannot get a valid clock_gettime() clock id! "
             "Fallback to unix time.");
     }
#else
# ifndef HAVE_EVIL
#  if defined(__APPLE__) && defined(__MACH__)
   mach_timebase_info_data_t info;
   kern_return_t err = mach_timebase_info(&info);
   if (err == 0)
     {
        _ecore_time_clock_conversion = 1e-9 * (double)info.numer / (double)info.denom;
     }
   else
     {
        WRN("Unable to get timebase info. Fallback to nanoseconds.");
     }
#  else
#  warning "Your platform isn't supported yet"
   CRI("Platform does not support clock_gettime. "
       "Fallback to unix time.");
#  endif
# endif
#endif

   _ecore_time_loop_time = ecore_time_get();
}
Beispiel #3
0
EAPI void
e_icon_object_set(Evas_Object *obj, Evas_Object *o)
{
   E_Smart_Data *sd;
   const char *str;

   if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR();
   if (!(sd = evas_object_smart_data_get(obj))) return;
   str = evas_object_type_get(o);
   if ((!str) || strcmp(str, "image"))
     CRI(EINA_COLOR_RED"******************\ntrying to set an image object of type '%s'! this is not what you want!\n******************\n"EINA_COLOR_RESET, str);

   if (sd->timer) ecore_timer_del(sd->timer);
   sd->timer = NULL;
   if (sd->guessing_animation) ecore_timer_del(sd->guessing_animation);
   sd->guessing_animation = NULL;
   sd->frame = 0;
   sd->frame_count = 0;
   sd->edje = EINA_FALSE;

   /* smart code here */
   if (sd->obj) evas_object_del(sd->obj);
   sd->loading = 0;
   sd->obj = o;
   evas_object_smart_member_add(sd->obj, obj);
   if (evas_object_visible_get(obj)) evas_object_show(sd->obj);
   _e_icon_smart_reconfigure(sd);
}
Beispiel #4
0
Eina_Bool
set_clip_name(char **name, char * text, int mode, int n)
{
  Eina_Bool ret = EINA_TRUE;

  /* Sanity check */
  if (!text) {
    WRN("ERROR: Text is NULL\n");
    text = "";
  }
  /* to be continued latter */
  if (name)
    *name = _sanitize_ln(text, n, mode);
  else {
    ERR("Error: Clip name pointer is Null!!");
    return EINA_FALSE;
  }

  if (!*name) {
      /* This is bad, leave it to calling function */
      CRI("ERROR: Memory allocation Failed!!");
      ret = EINA_FALSE;
    }

  return ret;
}
/**
 * @brief Validate a transmission attempt
 *
 * This function is used to check both the #Azy_Client_Call_Id and the #Azy_Content
 * of an azy_client_call or azy_client_put attempt, and will additionally set
 * an #Azy_Client_Return_Cb and log the calling function name upon failure.
 * Note that this function also calls azy_content_error_reset.
 * Also note: THIS FUNCTION IS MEANT TO BE USED IN A MACRO!!!!
 * @param cli The client (NOT NULL)
 * @param err_content The content used to make the call which may contain an error (NOT NULL)
 * @param ret The call id
 * @param cb The callback to set for @p ret (NOT NULL)
 * @param func The function name of the calling function
 * @return This function returns #EINA_TRUE only if the call was successful and @p cb was set, else #EINA_FALSE
 */
Eina_Bool
azy_client_call_checker(Azy_Client          *cli,
                        Azy_Content         *err_content,
                        Azy_Client_Call_Id   ret,
                        Azy_Client_Return_Cb cb,
                        const char          *func)
{
   DBG("(cli=%p, cb=%p, func='%s')", cli, cb, func);
   EINA_SAFETY_ON_NULL_RETURN_VAL(cli, EINA_FALSE);
   EINA_SAFETY_ON_NULL_RETURN_VAL(err_content, EINA_FALSE);
   EINA_SAFETY_ON_NULL_RETURN_VAL(cb, EINA_FALSE);
   if (!ret) return EINA_FALSE;

   if (azy_content_error_is_set(err_content))
     {
        ERR("%s:\n%s", func ? func : "<calling function not specified>", azy_content_error_message_get(err_content));
        azy_content_error_reset(err_content);
        return EINA_FALSE;
     }

   azy_content_error_reset(err_content);
   if (!azy_client_callback_set(cli, ret, cb))
     {
        CRI("Could not set callback from %s!", func ? func : "<calling function not specified>");
        return EINA_FALSE;
     }

   return EINA_TRUE;
}
Beispiel #6
0
/**
 * Retrieves the current system time as a floating point value in seconds.
 *
 * This uses a monotonic clock and thus never goes back in time while
 * machine is live (even if user changes time or timezone changes,
 * however it may be reset whenever the machine is restarted).
 *
 * @see ecore_loop_time_get().
 * @see ecore_time_unix_get().
 *
 * @return The number of seconds. Start time is not defined (it may be
 *         when the machine was booted, unix time, etc), all it is
 *         defined is that it never goes backwards (unless you got big critical
 *         messages when the application started).
 */
EAPI double
ecore_time_get(void)
{
#if defined (HAVE_CLOCK_GETTIME) || defined (EXOTIC_PROVIDE_CLOCK_GETTIME) 
   struct timespec t;

   if (EINA_UNLIKELY(_ecore_time_clock_id < 0))
     return ecore_time_unix_get();

   if (EINA_UNLIKELY(clock_gettime(_ecore_time_clock_id, &t)))
     {
        CRI("Cannot get current time.");
        /* Try to at least return the latest value retrieved*/
        return _ecore_time_loop_time;
     }

   return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
#elif defined(HAVE_EVIL)
   return evil_time_get();
#elif defined(__APPLE__) && defined(__MACH__)
   return _ecore_time_clock_conversion * (double)mach_absolute_time();
#else
   return ecore_time_unix_get();
#endif
}
Beispiel #7
0
static Eina_Bool
_bump_map_cpu_rgba_rgba(Evas_Filter_Command *cmd)
{
   (void) cmd;

   CRI("Not implemented yet.");
   return EINA_FALSE;
}
Beispiel #8
0
EOLIAN static Eo *
_efl_ui_pager_efl_object_constructor(Eo *obj,
                                     Efl_Ui_Pager_Data *pd)
{
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);

   if (!elm_widget_theme_klass_get(obj))
     elm_widget_theme_klass_set(obj, "pager");

   obj = efl_constructor(efl_super(obj, MY_CLASS));

   if (elm_widget_theme_object_set(obj, wd->resize_obj,
                                       elm_widget_theme_klass_get(obj),
                                       elm_widget_theme_element_get(obj),
                                       elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC)
     CRI("Failed to set layout!");

   pd->cnt = 0;
   pd->loop = EFL_UI_PAGER_LOOP_DISABLED;

   pd->curr.page = -1;
   pd->curr.pos = 0.0;

   pd->transition = NULL;
   pd->indicator = NULL;

   pd->fill_width = EINA_TRUE;
   pd->fill_height = EINA_TRUE;

   pd->page_spec.sz.w = -1;
   pd->page_spec.sz.h = -1;

   elm_widget_can_focus_set(obj, EINA_TRUE);

   pd->page_root = efl_add(EFL_CANVAS_GROUP_CLASS, evas_object_evas_get(obj));
   efl_content_set(efl_part(obj, "efl.page_root"), pd->page_root);

   efl_event_callback_add(pd->page_root, EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _resize_cb, pd);
   efl_event_callback_add(pd->page_root, EFL_GFX_ENTITY_EVENT_POSITION_CHANGED, _move_cb, pd);

   pd->page_box = efl_add(EFL_UI_BOX_CLASS, obj);
   efl_ui_widget_internal_set(pd->page_box, EINA_TRUE);
   efl_canvas_group_member_add(pd->page_root, pd->page_box);

   pd->foreclip = efl_add(EFL_CANVAS_RECTANGLE_CLASS,
                          evas_object_evas_get(obj));
   efl_canvas_group_member_add(pd->page_root, pd->foreclip);
   evas_object_static_clip_set(pd->foreclip, EINA_TRUE);
   efl_canvas_object_clipper_set(pd->page_box, pd->foreclip);

   pd->backclip = efl_add(EFL_CANVAS_RECTANGLE_CLASS,
                          evas_object_evas_get(obj));
   efl_canvas_group_member_add(pd->page_root, pd->backclip);
   evas_object_static_clip_set(pd->backclip, EINA_TRUE);
   efl_gfx_entity_visible_set(pd->backclip, EINA_FALSE);

   return obj;
}
Beispiel #9
0
static void
_block_events_theme_apply(Evas_Object *obj)
{
   ELM_NOTIFY_DATA_GET(obj, sd);

   const char *style = elm_widget_style_get(obj);

   if (!elm_layout_theme_set
       (sd->block_events, "notify", "block_events", style))
     CRI("Failed to set layout!");
}
/*
 * TSTENG_client_thread()
 *
 * Each client gets allocated a thread to handle all incoming
 * messages
 */
static void *TSTENG_client_thread(void *args)
{
    TSTENG_socket_msg_t msg;
    TSTENG_client_t *client_p=NULL;
    int len;

    // get our client details
    client_p = (TSTENG_client_t *) args;
    if (client_p == NULL) {
    ERR("failed to retrive client information\n");
    return NULL;
    }

    INF("fd=%d client thread\n", client_p->fd);

    while (1) {
    len = OSA_RecvSocket(client_p->fd, &msg, sizeof(msg));

    if (len == 0) {
        INF("client disconnected\n");
        break;
    } else if (len == -1) {
        if (errno != ECONNRESET)
        CRI("unexpected error %d\n", errno);

        break;
    } else if (len > (int) sizeof(msg)) {
        CRI("Invalid read length!!! %d\n", len);
        exit(errno);
    }

    DBG("received command string %s on fd=%d \n", msg.testcase_str, client_p->fd);

    TSTENG_handle_new_message(&msg, client_p);
    }

    TSTENG_remove_client(client_p->handle);

    return NULL;
}
/*
 * TSTENG_test_result_cb
 *
 * Called by sub-module under test to send time information to client
 */
void TSTENG_test_result_cb(TSTENG_handle_t handle, TSTENG_result_t result)
{
    TSTENG_client_t *client_p=NULL;
    TSTENG_socket_rtn_msg_t *msg_p=NULL;
    int len;

    if ((client_p = TSTENG_find_client(handle)) == NULL) {
    ERR("invalid test handle\n");
    return;
    }

    len = 0;

    if (client_p->cmd_p != NULL) {
    if (client_p->cmd_p->description != NULL) {
        len = strlen(client_p->cmd_p->description);
    }
    }

    if (len < 0) {
    ERR("impossible!\n");
    return;
    }

    msg_p = OSA_Malloc(sizeof(*msg_p) + len);
    if (msg_p == NULL) {
    CRI("unable to allocate memory\n");
    return;
    }

    bzero(msg_p, sizeof(*msg_p) + len);

    msg_p->type = TSTENG_RTN_RESULT;
    msg_p->result = result;
    msg_p->len = sizeof(*msg_p) + len;

    if (len == 0)
    msg_p->string = NULL;
    else
    memcpy(&(msg_p->string), client_p->cmd_p->description, len);

// XXX OSA_SocketSend

    if (write(client_p->fd, msg_p, sizeof(*msg_p) + len) < 0) {
    ERR("failed to write all data to client\n");
    }

    free(msg_p);
    msg_p = NULL;
}
Beispiel #12
0
Eina_Bool
set_clip_content(char **content, char* text, int mode)
{
  Eina_Bool ret = EINA_TRUE;
  char *temp, *trim;
  /* Sanity check */
  if (!text) {
    WRN("ERROR: Text is NULL\n");
    text = "";
  }
  if (content) {
    switch (mode) {
      case 0:
        /* Don't trim */
        temp = strdup(text);
        break;
      case 1:
        /* Trim new lines */
        trim = strip_whitespace(text, TRIM_NEWLINES);
        temp = strdup(trim);
        break;
      case 2:
        /* Trim all white Space
         *  since white space includes new lines
         *  drop thru here */
      case 3:
        /* Trim white space and new lines */
        trim = strip_whitespace(text, TRIM_SPACES);
        temp = strdup(trim);
        break;
      default :
        /* Error Don't trim */
        WRN("ERROR: Invalid strip_mode %d\n", mode);
        temp = strdup(text);
        break;
    }
    if (!temp) {
      /* This is bad, leave it to calling function */
      CRI("ERROR: Memory allocation Failed!!");
      ret = EINA_FALSE;
    }
    *content = temp;
  } else
    ERR("Error: Clip content pointer is Null!!");
  return ret;
}
Beispiel #13
0
void 
evas_outbuf_reconfigure(Evas_Engine_Info_Drm *info, Outbuf *ob, int w, int h)
{
   int i = 0;

   /* check for changes */
   if ((ob->w == w) && (ob->h == h) && 
       (ob->destination_alpha == info->info.destination_alpha) && 
       (ob->rotation == info->info.rotation) && 
       (ob->depth == info->info.depth)) 
     return;

   /* set new outbuf properties */
   ob->rotation =info->info. rotation;
   ob->depth = info->info.depth;
   ob->destination_alpha = info->info.destination_alpha;

   /* handle rotation */
   if ((ob->rotation == 0) || (ob->rotation == 180))
     {
        ob->w = w;
        ob->h = h;
        if (ob->w < ob->priv.mode.hdisplay) ob->w = ob->priv.mode.hdisplay;
        if (ob->h < ob->priv.mode.vdisplay) ob->h = ob->priv.mode.vdisplay;
     }
   else
     {
        ob->w = h;
        ob->h = w;
        if (ob->w < ob->priv.mode.vdisplay) ob->w = ob->priv.mode.vdisplay;
        if (ob->h < ob->priv.mode.hdisplay) ob->h = ob->priv.mode.hdisplay;
     }

   /* destroy the old buffers */
   for (; i < ob->priv.num; i++)
     evas_drm_framebuffer_destroy(ob->priv.fd, &(ob->priv.buffer[i]));

   for (i = 0; i < ob->priv.num; i++)
     {
        if (!_evas_outbuf_buffer_new(ob, &(ob->priv.buffer[i])))
          {
             CRI("Failed to create buffer");
             break;
          }
     }
}
Beispiel #14
0
static Eina_Bool
_config_init(Email_Config *cfg)
{
    Eina_Bool chk;

    chk = eina_spinlock_new(&cfg->lock);
    if (EINA_UNLIKELY(!chk))
    {
        CRI("Failed to create spinlock");
        goto fail;
    }

    cfg->user_config = eina_hash_string_superfast_new(_free_cb);

    return EINA_TRUE;
fail:
    return EINA_FALSE;
}
/*
 * TSTENG_test_info_cb
 *
 * Called by test cases to provide feedback during a test
 */
void TSTENG_test_info_cb(TSTENG_handle_t handle, TSTENG_result_t result, const char *str)
{
    TSTENG_client_t *client=NULL;
    TSTENG_socket_rtn_msg_t *msg=NULL;
    int len;

    client = TSTENG_find_client(handle);
    if (client == NULL) {
    ERR("invalid test handle\n");
    return;
    }

    if (str != NULL)
    len = strlen(str);
    else
    len = 0;

    msg = OSA_Malloc(sizeof(*msg) + len);
    if (msg == NULL) {
    CRI("Unable to allocate enough memory\n");
    return;
    }

    bzero(msg, sizeof(*msg) + len);

    msg->type = TSTENG_RTN_INFO;
    msg->result = result;
    msg->len = sizeof(*msg) + len;

    if (len == 0) {
    msg->string = NULL;
    } else {
    memcpy(&(msg->string), str, len);
    }

    if (write(client->fd, msg, sizeof(*msg) + len) < 0) {
    ERR("failed to write all data to client\n");
    }

    free(msg);
    msg = NULL;
}
Beispiel #16
0
EAPI Eina_Bool
email_config_data_add(Email_Config *cfg,
                      const char   *key,
                      void         *data,
                      Eina_Free_Cb  free_cb)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(cfg, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);

    Hash_Data *hd;
    Eina_Bool chk;

    hd = malloc(sizeof(*hd));
    if (EINA_UNLIKELY(!hd))
    {
        CRI("Failed to allocate memory");
        goto fail;
    }
    hd->data = data;
    hd->free_cb = free_cb;

    _config_lock(cfg);
    chk = !!eina_hash_find(cfg->user_config, key);
    if (EINA_UNLIKELY(chk == EINA_TRUE))
    {
        ERR("Element for key \"%s\" is already registered", key);
        _config_unlock(cfg);
        goto free;
    }
    chk = eina_hash_add(cfg->user_config, key, hd);
    _config_unlock(cfg);
    if (EINA_UNLIKELY(!chk))
        goto free;

    return chk;
free:
    free(hd);
fail:
    return EINA_FALSE;
}
Beispiel #17
0
static void
_eina_stringshare_small_del(const char *str, unsigned char length)
{
   Eina_Stringshare_Small_Bucket **bucket;
   const char *ret;
   int i;

   bucket = _eina_small_share.buckets + (unsigned char)str[0];
   if (!*bucket)
     goto error;

   ret = _eina_stringshare_small_bucket_find(*bucket, str, length, &i);
   if (!ret)
     goto error;

   _eina_stringshare_small_bucket_remove_at(bucket, i);
   return;

error:
   CRI("EEEK trying to del non-shared stringshare \"%s\"", str);
}
Beispiel #18
0
EAPI void
eina_stringshare_del(Eina_Stringshare *str)
{
   int slen;

   if (!str)
     return;

   /* special cases */
   if (str[0] == '\0')
     slen = 0;
   else if (str[1] == '\0')
     slen = 1;
   else if (str[2] == '\0')
     slen = 2;
   else if (str[3] == '\0')
     slen = 3;
   else
     slen = 4;  /* handled later */

   if (slen < 2)
     {
        eina_share_common_population_del(stringshare_share, slen);

        return;
     }
   else if (slen < 4)
     {
        eina_share_common_population_del(stringshare_share, slen);
        eina_spinlock_take(&_mutex_small);
        _eina_stringshare_small_del(str, slen);
        eina_spinlock_release(&_mutex_small);

        return;
     }

   if (!eina_share_common_del(stringshare_share, str))
     CRI("EEEK trying to del non-shared stringshare \"%s\"", str);
}
/*
 * TSTENG_server_thread
 *
 * Single thread to bring up server port and accept new clients
 */
static void *TSTENG_server_thread(void *args)
{
    int skt;
    int on = 1;
    struct sockaddr_in svraddr, cliaddr;
    TSTENG_client_t *pl_client_t=NULL;
    struct sockaddr *pl_soc=NULL;

    args=args;
    INF("bringing up test engine...\n");

    // allocate a socket fd
    if ((skt = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    CRI("TSTENG_server_thread: unable to create a socket\n");
    exit(errno);
    }
    // setup port information
    svraddr.sin_family = AF_INET;
    svraddr.sin_port = htons(TSTENG_port_no);
    svraddr.sin_addr.s_addr = htonl(INADDR_ANY);

    INF("starting on port %d\n", TSTENG_port_no);

    memset(&(svraddr.sin_zero), '\0', 8);

    // allow us to re-use a public facing port
    if (setsockopt(skt, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int)) < 0) {
    CRI("unable to set socket options\n");
    exit(errno);
    }
    // request port
    if (bind(skt, (struct sockaddr *) &svraddr, sizeof(*pl_soc)) < 0) {
    CRI("socket bind failed\n");
    exit(errno);
    }
    // start listening for incoming messages
    if (listen(skt, TSTENG_MAX_CLIENT) != 0) {
    CRI("cant listen on socket");
    exit(errno);
    }

    INF("ready to accept clients...\n");

    while (1) {
    int fd;
    TSTENG_client_t *client_p;
    socklen_t len = sizeof(*pl_soc);

    // wait for new client
    if ((fd = accept(skt, (struct sockaddr *) &cliaddr, &len)) == -1) {
        INF("accept gives error...\n");
        ERR("Socket accept\n");
        exit(errno);
    }

    INF("socket accepted new connection, create client fd = %d\n", fd);
    // allocate client info
    if ((client_p = OSA_Malloc(sizeof(*pl_client_t))) == NULL) {
        CRI("Unable to allocate memory\n");
        close(fd);
        continue;
    }

    client_p->fd = fd;
    client_p->handle = fd;    // for now, may need to pass handle in the msg from the LTP process
    client_p->next = NULL;

    TSTENG_add_client(client_p);

    (void) OSA_ThreadCreate(client_p->thread, TSTENG_client_thread, (void *) client_p);

    }

    // if we ever get here, try and close down everything
    // gracefully
    TSTENG_close_down();

    INF("closing down socket\n");
    (void) close(skt);

}
Beispiel #20
0
Evas_Filter_Buffer *
evas_filter_buffer_scaled_get(Evas_Filter_Context *ctx,
                              Evas_Filter_Buffer *src,
                              unsigned w, unsigned h)
{
   Evas_Filter_Buffer *fb;
   Image_Entry *dstdata = NULL;
   Image_Entry *srcdata;
   void *drawctx;

   srcdata = evas_filter_buffer_backing_get(ctx, src->id);
   EINA_SAFETY_ON_NULL_RETURN_VAL(srcdata, NULL);

   if (src->alpha_only)
     {
        // There is no supporting function in Evas for alpha scaling...
        // but guess what? There is also no use case in the filters :)
        CRI("Alpha buffer scaling is not supported");
        return NULL;
     }

   fb = evas_filter_temporary_buffer_get(ctx, w, h, src->alpha_only);
   if (!fb) return NULL;

   dstdata = evas_filter_buffer_backing_get(ctx, fb->id);
   if (!dstdata)
     {
        CRI("No backing found for buffer %d", fb->id);
        return NULL;
     }

   if ((dstdata->w != w) || (dstdata->h != h))
     {
        CRI("Buffer size mismatch: got %dx%d requested %dx%d",
            dstdata->w, dstdata->h, w, h);
        return NULL;
     }

   if (ctx->gl_engine)
     {
        RGBA_Image *s = (RGBA_Image *) srcdata;
        RGBA_Image *d = (RGBA_Image *) dstdata;
        EINA_SAFETY_ON_NULL_RETURN_VAL(s->image.data, NULL);
        EINA_SAFETY_ON_NULL_RETURN_VAL(d->image.data, NULL);

        if (src->w == (int) w && src->h == (int) h)
          memcpy(d->image.data, s->image.data, w * h * 4);
        else
          {
             Eina_Bool ok;
             RGBA_Draw_Context dc;

             memset(&dc, 0, sizeof(dc));
             dc.sli.h = 1;
             dc.render_op = EVAS_RENDER_COPY;

             ok = evas_common_scale_rgba_in_to_out_clip_smooth
                   (s, d, &dc, 0, 0, src->w, src->h, 0, 0, w, h);
             if (!ok)
               {
                  ERR("RGBA Image scaling failed.");
                  return NULL;
               }
          }
     }
   else
     {
        drawctx = ENFN->context_new(ENDT);
        ENFN->context_color_set(ENDT, drawctx, 255, 255, 255, 255);
        ENFN->context_render_op_set(ENDT, drawctx, EVAS_RENDER_COPY);
        ENFN->image_draw(ENDT, drawctx, dstdata, srcdata,
                         0, 0, src->w, src->h, // src
                         0, 0, w, h, // dst
                         EINA_TRUE, // smooth
                         EINA_FALSE); // Not async
        ENFN->context_free(ENDT, drawctx);
     }

   return fb;
}
Beispiel #21
0
uint16_t
tile_mask_calculate(uint8_t tl,
                    uint8_t tr,
                    uint8_t bl,
                    uint8_t br)
{
   /* Helpers */
#define TILE_HAS(type) _tile_has_type(tl, tr, bl, br, type)
#define LOW_MASK(first) _tile_boundry_low_mask_get(tl, tr, bl, br, first)

   uint16_t tile = 0x0000;

   if (tile_solid_is(tl, tr, bl, br))
     {
        switch (tl & 0x0f) /* tl == tr == bl == br */
          {
           case TILE_WATER_LIGHT:  tile = 0x0010; break;
           case TILE_WATER_DARK:   tile = 0x0020; break;
           case TILE_GROUND_LIGHT: tile = 0x0030; break;
           case TILE_GROUND_DARK:  tile = 0x0040; break;
           case TILE_GRASS_LIGHT:  tile = 0x0050; break;
           case TILE_GRASS_DARK:   tile = 0x0060; break;
           case TILE_TREES:        tile = 0x0070; break;
           case TILE_ROCKS:        tile = 0x0080; break;

           case TILE_HUMAN_WALL:
             tile = (tl & TILE_WALL_OPEN) ? 0x00b0 : 0x0090;
             break;

           case TILE_ORC_WALL:
             tile = (tl & TILE_WALL_OPEN) ? 0x00c0 : 0x00a0;
             break;

           default:
              CRI("Unhandled solid tile %x", tl);
              goto fail;
          }
     }
   else
     {
        if (TILE_HAS(TILE_GRASS_LIGHT))
          {
             if (TILE_HAS(TILE_TREES))
               {
                  tile = 0x0700 | LOW_MASK(TILE_TREES);
               }
             else if (TILE_HAS(TILE_GRASS_DARK))
               {
                  tile = 0x0600 | LOW_MASK(TILE_GRASS_DARK);
               }
             else if (TILE_HAS(TILE_GROUND_LIGHT))
               {
                  tile = 0x0500 | LOW_MASK(TILE_GROUND_LIGHT);
               }
             else
               {
                  CRI("Invalid disposition of tiles (with grass light)");
                  goto fail;
               }
          }
        else if (TILE_HAS(TILE_GROUND_LIGHT))
          {
             if (TILE_HAS(TILE_GROUND_DARK))
               {
                  tile = 0x0300 | LOW_MASK(TILE_GROUND_DARK);
               }
             else if (TILE_HAS(TILE_ROCKS))
               {
                  tile = 0x0400 | LOW_MASK(TILE_ROCKS);
               }
             else if (TILE_HAS(TILE_WATER_LIGHT))
               {
                  tile = 0x0200 | LOW_MASK(TILE_WATER_LIGHT);
               }
             else
               {
                  CRI("Invalid disposition of tiles (with ground light)");
                  goto fail;
               }
          }
        else if (TILE_HAS(TILE_WATER_LIGHT))
          {
             if (TILE_HAS(TILE_WATER_DARK))
               {
                  tile = 0x0100 | LOW_MASK(TILE_WATER_DARK);
               }
             else
               {
                  CRI("Invalid disposition of tiles (with water light)");
                  goto fail;
               }
          }
        else if (TILE_HAS(TILE_ORC_WALL))
          {
             tile = 0x0900 | _tile_wall_mask_get(tl, tr, bl, br);
          }
        else if (TILE_HAS(TILE_HUMAN_WALL))
          {
             tile = 0x0800 | _tile_wall_mask_get(tl, tr, bl, br);
          }
        else
          {
             CRI("Uncovered tile disposition");
             goto fail;
          }
     }

   return tile;

fail:
   CRI("Analysis of tile (tl, tr, bl, br) = (0x%02x, 0x%02x, 0x%02x, 0x%02x) failed",
       tl, tr, bl, br);
   return 0x0000;

#undef LOW_MASK
#undef TILE_HAS
}
Beispiel #22
0
int
evas_common_rgba_image_colorspace_set(Image_Entry* ie, Evas_Colorspace cspace)
{
   RGBA_Image *im = (RGBA_Image *) ie;

   // FIXME: This function looks extremely dubious now, trying to free the
   // data pointer without even knowing how it was allocated (malloc / mmap).
   // Also, lacks support for S3TC and exotic formats.

   if (im->cache_entry.space == cspace)
     return 1;

   if (ie->references > 1)
     WRN("Releasing data of image with >1 refs. Bad things may happen.");

   if (im->cs.data)
     {
        if (!im->cs.no_free) free(im->cs.data);
        im->cs.data = NULL;
     }
   im->cs.no_free = 0;
   if (im->image.data && !im->image.no_free)
     {
        // FIXME: Call _evas_common_rgba_image_surface_munmap
        free(im->image.data);
     }
   ie->allocated.w = 0;
   ie->allocated.h = 0;
   ie->flags.preload_done = 0;
   ie->flags.loaded = 0;
   im->image.data = NULL;
   im->image.no_free = 0;

   switch (cspace)
     {
      case EVAS_COLORSPACE_ARGB8888:
      case EVAS_COLORSPACE_AGRY88:
      case EVAS_COLORSPACE_GRY8:
        // all good
        break;
      case EVAS_COLORSPACE_ETC1:
      case EVAS_COLORSPACE_ETC1_ALPHA:
      case EVAS_COLORSPACE_RGB8_ETC2:
      case EVAS_COLORSPACE_RGBA8_ETC2_EAC:
        // living on the edge (no conversion atm)
        break;
      case EVAS_COLORSPACE_YCBCR422P601_PL:
      case EVAS_COLORSPACE_YCBCR422P709_PL:
      case EVAS_COLORSPACE_YCBCR422601_PL:
      case EVAS_COLORSPACE_YCBCR420TM12601_PL:
      case EVAS_COLORSPACE_YCBCR420NV12601_PL:
        // prepare cspace conversion buffer
        im->cs.data = calloc(1, im->cache_entry.h * sizeof(unsigned char *) * 2);
        im->cs.no_free = 0;
        break;
      default:
        CRI("Can't set colorspace to %u: unsupported", (unsigned) cspace);
        abort();
        return 0;
     }
   im->cache_entry.space = cspace;
   evas_common_image_colorspace_dirty(im);
   _evas_common_rgba_image_post_surface(ie);
   return 1;
}
Beispiel #23
0
EAPI int
eio_shutdown(void)
{
   Eio_File_Direct_Info *info;
   Eio_File_Char *cin;
   Eio_Progress *pg;
   Eio_File_Associate *asso;
   Eio_File *f;
   Eina_List *l;

   if (_eio_init_count <= 0)
     {
        ERR("Init count not greater than 0 in shutdown.");
        return 0;
     }
   if (--_eio_init_count != 0)
     return _eio_init_count;

   eina_log_timing(_eio_log_dom_global,
                   EINA_LOG_STATE_START,
                   EINA_LOG_STATE_SHUTDOWN);

   efl_del(io_manager);
   io_manager = NULL;

   EINA_LIST_FOREACH(tracked_thread, l, f)
     ecore_thread_cancel(f->thread);

   EINA_LIST_FREE(tracked_thread, f)
     {
        if (!ecore_thread_wait(f->thread, 0.5))
          CRI("We couldn't terminate in less than 30s some pending IO. This can led to some crash.");
     }

   efreet_mime_shutdown();

   eio_monitor_shutdown();

   eina_condition_free(&(memory_pool_cond));
   eina_lock_free(&(memory_pool_mutex));
   eina_spinlock_free(&(memory_pool_lock));

   eina_lock_free(&(direct_info_pool.lock));
   eina_lock_free(&(progress_pool.lock));
   eina_lock_free(&(char_pool.lock));
   eina_lock_free(&(associate_pool.lock));

   /* Cleanup pool */
   EINA_TRASH_CLEAN(&progress_pool.trash, pg)
     free(pg);
   progress_pool.count = 0;

   EINA_TRASH_CLEAN(&direct_info_pool.trash, info)
     free(info);
   direct_info_pool.count = 0;

   EINA_TRASH_CLEAN(&char_pool.trash, cin)
     free(cin);
   char_pool.count = 0;

   EINA_TRASH_CLEAN(&associate_pool.trash, asso)
     free(asso);
   associate_pool.count = 0;

   ecore_shutdown();
   eina_log_domain_unregister(_eio_log_dom_global);
   _eio_log_dom_global = -1;
   eina_shutdown();

   return _eio_init_count;
}
Beispiel #24
0
EAPI_MAIN int
elm_main(int    argc,
         char **argv)
{
   int ret = EXIT_FAILURE;
   int args;
   int i;
   Editor *ed;
   unsigned int ed_count = 0;
   Eina_Bool quit_opt = EINA_FALSE;
   Eina_Bool debug = EINA_FALSE;
   Ecore_Getopt_Value values[] = {
      ECORE_GETOPT_VALUE_BOOL(debug),
      ECORE_GETOPT_VALUE_BOOL(quit_opt),
      ECORE_GETOPT_VALUE_BOOL(quit_opt)
   };
   const Module *mod_ptr;
   const Module *mod_end = &(_modules[EINA_C_ARRAY_LENGTH(_modules)]);
   const char *env;
   unsigned int debug_flags = 0;

   args = ecore_getopt_parse(&_options, values, argc, argv);
   if (args < 0)
     {
        EINA_LOG_CRIT("Getopt failed");
        goto end;
     }

   /* Quit option requested? End now, with success */
   if (quit_opt)
     {
        ret = EXIT_SUCCESS;
        goto end;
     }

   if (debug)
     debug_flags = ~0U;

   /* Are we running in tree? */
   env = getenv("WAR2EDIT_IN_TREE");
   _in_tree = (env) ? !!atoi(env) : EINA_FALSE;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_language_set("");
   elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
   elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR);
   elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
   elm_app_info_set(elm_main, "war2edit", "sprites/units/units.eet");

   if (EINA_UNLIKELY(!_edje_get(NULL)))
     {
        EINA_LOG_CRIT("Failed to get edje theme");
        goto end;
     }

   for (mod_ptr = _modules; mod_ptr != mod_end; ++mod_ptr)
     {
       if (EINA_UNLIKELY(EINA_FALSE == mod_ptr->init()))
         {
            EINA_LOG_CRIT("Failed to initialize module \"%s\"", mod_ptr->name);
            goto modules_shutdown;
         }
     }


   /* Open editors for each specified files */
   for (i = args; i < argc; ++i)
     {
        /* If an editor fails to open, don't close now */
        ed = editor_new(argv[i], debug_flags);
        if (!ed)
          ERR("Failed to create editor with file \"%s\"", argv[i]);
        else
          ++ed_count;
     }

   if (ed_count == 0)
     {
        ed = editor_new(NULL, debug_flags);
        if (EINA_UNLIKELY(!ed))
          {
             CRI("Failed to create editor");
             goto modules_shutdown;
          }
     }

   /* === Main loop === */
   elm_run();
   ret = EXIT_SUCCESS;

modules_shutdown:
   for (--mod_ptr; mod_ptr >= _modules; --mod_ptr)
     mod_ptr->shutdown();
end:
   if (_edje_file)
     {
        free(_edje_file);
        _edje_file = NULL;
     }
   return ret;
}
Beispiel #25
0
void
tile_decompose(uint16_t  tile_code,
               uint8_t  *tl,
               uint8_t  *tr,
               uint8_t  *bl,
               uint8_t  *br,
               uint8_t  *seed)
{
   /*
    * FIXME Algo here is sh*t.
    */

   /* Seed is common to all tiles */
   *seed = (uint8_t)(tile_code & 0x000f);

   if ((tile_code & 0xff00) == 0x0000) /* Solid */
     {
        uint8_t code = TILE_NONE;
        switch (tile_code & 0x00f0)
          {
           case 0x0010: code = TILE_WATER_LIGHT; break;
           case 0x0020: code = TILE_WATER_DARK; break;
           case 0x0030: code = TILE_GROUND_LIGHT; break;
           case 0x0040: code = TILE_GROUND_DARK; break;
           case 0x0050: code = TILE_GRASS_LIGHT; break;
           case 0x0060: code = TILE_GRASS_DARK; break;
           case 0x0070: code = TILE_TREES; break;
           case 0x0080: code = TILE_ROCKS; break;
           case 0x0090: code = TILE_HUMAN_WALL | TILE_WALL_CLOSED; break;
           case 0x00b0: code = TILE_HUMAN_WALL | TILE_WALL_OPEN; break;
           case 0x00a0: code = TILE_ORC_WALL | TILE_WALL_CLOSED; break;
           case 0x00c0: code = TILE_ORC_WALL | TILE_WALL_OPEN; break;
           default: CRI("Unhandled tile: 0x%04x", tile_code); return;
          }
        *bl = code; *br = code; *tl = code; *tr = code;
     }
   else /* Boundry */
     {
        uint8_t pair[2];
        const uint16_t master = (tile_code & 0x0f00);
        const uint16_t spread = (tile_code & 0x00f0);

        switch (master)
          {
           case 0x0900:
              pair[1] = TILE_ORC_WALL;    pair[0] = TILE_ORC_WALL; break;
           case 0x0800:
              pair[1] = TILE_HUMAN_WALL;  pair[0] = TILE_HUMAN_WALL; break;
           case 0x0700:
             pair[1] = TILE_TREES;        pair[0] = TILE_GRASS_LIGHT; break;
           case 0x0600:
             pair[1] = TILE_GRASS_DARK;   pair[0] = TILE_GRASS_LIGHT; break;
           case 0x0500:
             pair[1] = TILE_GROUND_LIGHT; pair[0] = TILE_GRASS_LIGHT; break;
           case 0x0400:
             pair[1] = TILE_ROCKS;        pair[0] = TILE_GROUND_LIGHT; break;
           case 0x0300:
             pair[1] = TILE_GROUND_DARK;  pair[0] = TILE_GROUND_LIGHT; break;
           case 0x0200:
             pair[1] = TILE_WATER_LIGHT;  pair[0] = TILE_GROUND_LIGHT; break;
           case 0x0100:
             pair[1] = TILE_WATER_DARK;   pair[0] = TILE_WATER_LIGHT; break;

           default:
             CRI("Invalid tile 0x%04x (unhandled master 0x%04x)",
                 tile_code, master);
             return;
          }

        /* Walls */
        if ((pair[0] == TILE_ORC_WALL) || (pair[0] == TILE_HUMAN_WALL))
          {
             const uint8_t key = (spread >> 4) & 0xf;
             uint8_t val;
             if (EINA_UNLIKELY(key > 0xd))
               {
                  CRI("Invalid wall spread 0x%04x", spread);
                  return;
               }

             val = _walls_table[key];
             *tl = _wall_tile_gen((val >> 3) & 0x1) | pair[0];
             *tr = _wall_tile_gen((val >> 2) & 0x1) | pair[0];
             *bl = _wall_tile_gen((val >> 1) & 0x1) | pair[0];
             *br = _wall_tile_gen(val & 0x1) | pair[0];
          }
        else /* Everything but walls */
          {
             switch (spread)
               {
                  /* TL  TR
                   * BL  BR */
                case 0x0000:
                   *tl = pair[1]; *tr = pair[0]; *bl = pair[0]; *br = pair[0]; break;
                case 0x00d0:
                   *tl = pair[0]; *tr = pair[1]; *bl = pair[1]; *br = pair[1]; break;
                case 0x0010:
                   *tl = pair[0]; *tr = pair[1]; *bl = pair[0]; *br = pair[0]; break;
                case 0x00c0:
                   *tl = pair[1]; *tr = pair[0]; *bl = pair[1]; *br = pair[1]; break;
                case 0x0020:
                   *tl = pair[1]; *tr = pair[1]; *bl = pair[0]; *br = pair[0]; break;
                case 0x00b0:
                   *tl = pair[0]; *tr = pair[0]; *bl = pair[1]; *br = pair[1]; break;
                case 0x0030:
                   *tl = pair[0]; *tr = pair[0]; *bl = pair[1]; *br = pair[0]; break;
                case 0x00a0:
                   *tl = pair[1]; *tr = pair[1]; *bl = pair[0]; *br = pair[1]; break;
                case 0x0040:
                   *tl = pair[1]; *tr = pair[0]; *bl = pair[1]; *br = pair[0]; break;
                case 0x0090:
                   *tl = pair[0]; *tr = pair[1]; *bl = pair[0]; *br = pair[1]; break;
                case 0x0070:
                   *tl = pair[0]; *tr = pair[0]; *bl = pair[0]; *br = pair[1]; break;
                case 0x0060:
                   *tl = pair[1]; *tr = pair[1]; *bl = pair[1]; *br = pair[0]; break;
                case 0x0080:
                   *tl = pair[1]; *tr = pair[0]; *bl = pair[0]; *br = pair[1]; break;
                case 0x0050:
                   *tl = pair[0]; *tr = pair[1]; *bl = pair[1]; *br = pair[0]; break;

                default:
                   CRI("Invalid tile 0x%04x (unhandled spread 0x%04x)",
                       tile_code, spread);
                   return;
               }
          }
     }