ARGB Graphics Made Easy

Code — May 22, 2006 @ 5:49 am

Many people dismiss Enlightenment’s cool GUI effects as just “hacks” that are no substitute for real transparency. That may have been true in the past when X didn’t have such features, but thanks to the new Xrender engine in Evas, it’s no longer true. For the skeptics, here’s a little 48-line program that can display any Edje file with full transparency (when a composite manager is running). Don’t try this with XLib.

#include <stdio.h>
#include <stdlib.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>

int main(int argc, char ** argv)
{
   Evas *evas;
   Ecore_Evas *ee;
   Evas_Object *edje;

   if (argc < 2)
      exit(1);

   ecore_init();
   ecore_app_args_set(argc, (const char **)argv);
   ecore_evas_init();
   ee = ecore_evas_xrender_x11_new(0, 0, 0, 0, 400, 400);
   evas = ecore_evas_get(ee);
   ecore_evas_alpha_set(ee, 1);
   ecore_evas_title_set(ee, "MAGIC!");
   ecore_evas_borderless_set(ee, 1);
   edje_init();
   edje_frametime_set(1.0/30.0);
   ecore_evas_move(ee, 0, 0);

   edje = edje_object_add(evas);
   if (!edje_object_file_set(edje, argv[1], "Main"))
   {
      fprintf(stderr, "Failed to load collection 'Main' from Edje file %s\n",
              argv[1]);
      exit(1);
   }
   evas_object_move(edje, 0, 0);
   ecore_evas_resize(ee, 200, 200);
   evas_object_resize(edje, 200, 200);
   evas_object_show(edje);
   ecore_evas_show(ee);
   ecore_main_loop_begin();
   edje_shutdown();
   ecore_evas_shutdown();
   ecore_shutdown();
   return 0;
}

Two examples are shown here -- a static camera image and an animated E logo:
Screenshot

You can download the source, together with the two sample edjes here. You need to have Evas, Ecore and Edje installed (visit Get-E.org for more info). This all comes with a minor caveat: Xrender performance generally ranges from sucky to depressing, and as a result evas_xrender is approximately 10 times slower than the plain software engine. But any decently fast computer should be able to handle this test case with ease.

Share:
  • Digg
  • Facebook
  • Technorati
  • Twitter
  • Add to favorites
  • email
  • Ping.fm

3 Responses to “ARGB Graphics Made Easy”

  1. Cius says:

    Did you happen to try RenderAccel “true” in your xorg.conf or similar file? I’m just wondering maybe the lack of render performance could be improved by this.

  2. xcomp says:

    Yes I did. It works well enough to be usable, but the frame rates are absolute crap compared to regular Evas software rendering, even with hardware render acceleration enabled. See this Slashdot Story from a couple of years ago.

  3. raster says:

    Actually you can just use the software_x11 engine too – it works with ARGB targets as well :) so you can play with a middle ground – render contents with sw, let xcomposite/xrender deal with the rest.

Leave a Reply

You must be logged in to post a comment.

Copyright © Ibukun Olumuyiwa 2007.