by Lucas De Marchi
RSS icon Home icon
  • Easily embedding WebKit into your EFL application

    This is the first of a series of posts that I’m planning to do using basic examples in EFL, the Enlightenment Foundation Libraries. You may have heard that EFL is reaching its 1.0 release. Instead of starting from the very beginning with the basic functions of these libraries, I decided to go the opposite way, showing the fun stuff that is possible to do. Since I’m also an WebKit developer, let’s put the best of both softwares together and have a basic window rendering a webpage.

    Before starting off, just some remarks:

    1. I’m using here the basic EFL + WebKit-EFL (sometimes called ewebkit). Developing an EFL application can be much simpler, particularly if you use an additional library with pre-made widgets like Elementary. However, it’s good to know how the underlying stuff works, so I’m providing this example.
    2. This could have been the last post in a series when talking about EFL since it uses at least 3 libraries. Don’t be afraid if you don’t understand what a certain function is for or if you can’t get all EFL and WebKit running right now. Use the comment section below and I’ll make my best to help you.

    Getting EFL and WebKit

    In order to able to compile the example here, you will need to compile two libraries from source: EFL and WebKit. For both libraries, you can either get the last version from svn or use the last snapshots provided.

    • EFL:

    Grab a snapshot from the download page. How to checkout the latest version from svn is detailed here, as well as some instructions on how to compile

    • WebKit-EFL:

    A very detailed explanation on how to get WebKit-EFL up and running is available on trac. Recently, though, WebKit-EFL started to be released too. It’s not detailed in the wiki yet, but you can grab a snapshot instead of checking out from svn.

    hellobrowser!

    In the spirit of “hello world” examples, our goal here is to make a window showing a webpage rendered by WebKit. For the sake of simplicity, we will use a default start page and put a WebKit-EFL “widget” to cover the entire window. See below a screenshot:

    hellobrowser - WebKit + EFL

    The code for this example is available here. Pay attention to a comment in the beginning of this file that explains how to compile it:

    gcc -o hellobrowser hellobrowser.c \
         -DEWK_DATADIR="\"$(pkg-config --variable=datadir ewebkit)\"" \
         $(pkg-config --cflags --libs ecore ecore-evas evas ewebkit)

    The things worth noting here are the dependencies and a variable. We directly depend on ecore and evas from EFL and on WebKit. We define a variable, EWK_DATADIR, using pkg-config so our browser can use the default theme for web widgets defined in WebKit. Ecore handles events like mouse and keyboard inputs, timers etc whilst evas is the library responsible for drawing. In a later post I’ll detail them a bit more. For now, you can read more about them on their official site.

    The main function is really simple. Let’s divide it by pieces:

        // Init all EFL stuff we use
        evas_init();
        ecore_init();
        ecore_evas_init();
        ewk_init();

    Before you use a library from EFL, remember to initialize it. All of them use their own namespace, so it’s easy to know which library you have to initialize: for example, if you call a function starting by “ecore_”, you know you first have to call “ecore_init()”. The last initialization function is WebKit’s, which uses the “ewk_” namespace.

        window = ecore_evas_new(NULL, 0, 0, 800, 600, NULL);
        if (!window) {
            fprintf(stderr, "something went wrong... :(\n");
            return 1;
        }

    Ecore-evas then is used to create a new window with size 800×600. The other options are not relevant for an introduction to the libraries and you can find its complete documentation here.

        // Get the canvas off just-created window
        evas = ecore_evas_get(window);

    From the Ecore_Evas object we just created, we grab a pointer to the evas, which is the space in which we can draw, adding Evas_Objects. Basically an Evas_Object is an object that you draw somewhere, i.e. in the evas. We want to add only one object to our window, that is where WebKit you render the webpages. Then, we have to ask WebKit to create this object:

        // Add a View object into this canvas. A View object is where WebKit will
        // render stuff.
        browser = ewk_view_single_add(evas);

    Below I demonstrate a few Evas’ functions that you use to manipulate any Evas_Object. Here we are manipulating the just create WebKit object, moving to the desired position, resizing to 780x580px and then telling Evas to show this object. Finally, we tell Evas to show the window we created too. This way we have a window with an WebKit object inside with a little border.

        // Make a 10px border, resize and show
        evas_object_move(browser, 10, 10);
        evas_object_resize(browser, 780, 580);
        evas_object_show(browser);
        ecore_evas_show(window);

    We need to setup a bit more things before having a working application. The first one is to give focus to the Evas_Object we are interested on in order to receive keyboard events when opened. Then we connect a function that will be called when the window is closed, so we can properly exit our application.

        // Focus it so it will receive pressed keys
        evas_object_focus_set(browser, 1);
     
        // Add a callback so clicks on "X" on top of window will call
        // main_signal_exit() function
        ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, main_signal_exit, window);

    After this, we are ready to show our application, so we start the mainloop. This function will only return when the application is closed:

        ecore_main_loop_begin();

    The function called when the application is close, just tell Ecore to exit the mainloop, so the function above returns and the application can shutdown. See its implementation below:

    static Eina_Bool
    main_signal_exit(void *data, int ev_type, void *ev)
    {
        ecore_evas_free(data);
        ecore_main_loop_quit();
        return EINA_TRUE;
    }

    Before the application exits, we shutdown all the libraries that were initialized, in the opposite order:

        // Destroy all the stuff we have used
        ewk_shutdown();
        ecore_evas_shutdown();
        ecore_shutdown();
        evas_shutdown();

    This is a basic working browser, with which you can navigate through pages, but you don’t have an entry to set the current URL, nor “go back” and “go forward” buttons etc. All you have to do is start adding more Evas_Objects to your Evas and connect them to the object we just created. For a still basic example, but with more stuff implemented, refer to the EWebLauncher that we ship with the WebKit source code. You can see it in the “WebKitTools/EWebLauncher/” folder or online at webkit’s trac. Eve is another browser with a lot more features that uses Elementary in addition to EFL, WebKit. See a blog post about it with some nice pictures.

    Now, let’s do something funny with our browser. With a bit more lines of code you can turn your browser upside down. Not really useful, but it’s funny. All you have to do is to rotate the Evas_Object WebKit is rendering on. This is implemented by the following function:

    // Rotate an evas object by 180 degrees
    static void
    _rotate_obj(Evas_Object *obj)
    {
        Evas_Map *map = evas_map_new(4);
     
        evas_map_util_points_populate_from_object(map, obj);
        evas_map_util_rotate(map, 180.0, 400, 300);
        evas_map_alpha_set(map, 0);
        evas_map_smooth_set(map, 1);
        evas_object_map_set(obj, map);
        evas_object_map_enable_set(obj, 1);
     
        evas_map_free(map);
    }

    See this screenshot below and  get the complete source code.

    EFL + WebKit doing Politreco upside down

  • Understanding RT by graphics

    A lot of people seem not to understand very well what real-time means. They usually tend to think RT has anything to do with performance and the raw throughput. It doesn’t. It’s all about determinism and guarantees.

    This post’s title has “by graphics” words. I think the graphics below are worth a thousand words. I obtained them while porting the RT tree to Freescale boards some weeks ago at ProFUSION. Basically I’m running a task that wakes up every 40ms, run a tiny job, send some numbers through the network and sleeps again. The time in the graphics is the difference between the total time (sleep + wake-up + execution) and 40ms.

    One important fact: while this is running, I’m running some CPU-intensive jobs in background and the board is receiving a ping flood from another host.

    See that when the task is running with real-time priority, it doesn’t matter there’s a hugger job in background or someone is trying to take your board down with a ping flood. It’s always possible to draw a line and say it will never* go beyond that limit. In the other hand, when running with normal priority, the total time varies much more.

    scope with no real-time

    Task running with normal priority

    Task running with real-time priority

    PS.: In the graphics above I’m using an oscilloscope made by Arnaldo Carvalho de Melo. Thanks, acme.

    * Well, never is a strong word. You better test with several scenarios, workloads, etc before saying that.

  • Embedded Linux Conference 2010

    So, today was the last day of the Embedded Linux Conference. Now, I’ll be here in USA for the Linux Collaboration Summit. It was really cool and it was amazing to meet people you are only used to chat, exchange some emails or that you heard about. Just to name some: Steven Rostedt, Greg Kroah-Hartman, Frank Rowand, Mike Anderson, Andrew Morton, Jon Corbet and others. I was really impressed too seeing Rostedt programming or Greg answering emails. What a great guys

    And yesterday I presented my work, talking about the optimization of the Linux scheduler for soft real-time when running on multi-core architectures. I must admit I was a bit nervous, but it seems that people liked it. Following some pictures:

  • Banco do Brasil + Linux 64 bits

    Faz 1 mês mais ou menos que liguei no Banco do Brasil reclamando que a “solução de segurança” do site deles não estava funcionando no meu Linux 64 bits. Sem grandes surpresas, depois de me perguntarem se eu tinha a VM java da sun instalada, versão, etc, eles me passaram para o suporte de segundo nível. Pediram o meu telefone, dizendo que entrariam em contato (isso foi no sábado).

    Logo na segunda-feira de manhã me ligaram e após mais um tempo conversando, ele disse: “o problema é que a nossa solução de segurança não é homologada para a jre 1.6. Acontece que em algumas plataformas ela funciona, mas não é garantido. A gente sabe que em Linux 32 bits funciona, mas a jre 1.5 é que é oficialmente homologada”. Então eu tinha duas opções: ou instalar a versão 1.5 ou rodar um browser 32 bits. Felizmente no meu sistema, archlinux, já tem um pacote firefox32 que faz tudo o que preciso e foi o a solução que adotei. Até hoje.

    Hoje quando fiz meu usual “sudo pacman -Syu” para instalar atualizações de todos os pacotes, vi que tinha uma atualização da jre para ser feita: jre-6u18-2. Aí pensei… quem sabe nessa versão mudou alguma coisa que fez funcionar o applet do BB? Sem muitas esperanças, abri o site no chromium e para minha surpresa, funcionou! Abri no Firefox, e funcionou também. Pra tirar a dúvida, fiz o downgrade para a versão anterior do java, jre-6u17-1. Abri novamente e continuou funcionando. Logo, não foi causada pela atualização da VM, mas sim por alguma mudança que o pessoal do Banco do Brasil fez. Não sei se eles chegaram a homologar a versão 1.6 da JVM (o que já estaria mais do que na hora), só sei que agora funciona com Linux 64 bits.

    Felizmente agora posso acessar a minha conta no Banco do Brasil sem precisar do browser 32 bits. Já estou removendo-o. Deixe seu comentário pra eu saber se funcionou pra você também (inclusive aqueles que usam FreeBSDs e outros unixes).

  • Amazing kernel related blog

    Today while reading “posts” on Buzz and digging in my RSS reader, I found this blog: http://smackerelofopinion.blogspot.com/ made by an ubuntu engineer. How many amazing posts there are on this blog. Particularly interesting is the one about ACPI Debugging and the other about perf, the tool I posted about some days ago (although it covers just a tiny amount of things this tool is capable of).

    When I have some spare time I’ll try to use that first post to debug the ACPI on my buggy asus laptop, where temperature goes sometimes as high as 90 °C. Last year I tried to adjust the hysteresis curve of the fan control in order to have a cooler laptop but had no success on it.

    PS.: I wished a day had 48h to be able to read all the cool stuff out there

  • Chromium

    After reading this post at “Linux Today” I decided to install the so expected Linux version of Chrome, the Google’s browser.

    As I use Arch Linux, I haven’t expected to have a compiled version linked directly by the chromium’s website. Instead, I was hoping Arch’s developers already packaged it. And, with no big surprises, they did. Just to clarify a thing before continuing: Chromium is the open source projected behind Chrome (which is not opensource).

    I’m not writing this post to repeat what’s already written there. So read it too. As opposed to his impression however, I’m running it without big problems: pages are rendered well formatted, without html or css problems. Sure, it’s not a browser to use everyday yet, but as a pre-alpha version it’s doing pretty good. Below, a picture with this post been written.

    Read the rest of this entry »

  • Playing with your cache

    Another possible titles could be “how to really slow down your computer” or “why caches are so important in computer architectures”. I started playing with turning my cache on and off last week using Linux because there are some situations in which you have to know why a piece of software is not working as expected. A possible problem could be the well known cache trashing, in which the contents of the cache is thrown away very often. Turning it down may give an answer if this is really the problem since now even running very slowly this variable is eliminated.

    For example in my stage we had some tests showing that in certain scenarios a quad-core machine is much slower than an equivalent single or dual core. Next post I’ll show how to play with your cores, activating and deactivating them, so you may create your own programs and test them against a 1, 2, 3,… cores machine.

    Also I think it’s a good exercise to students of computer science/engineering who are enrolled in courses as “computer architectures” and “operating systems”. For those, two good books: “Modern Operating Systems” by Tanenbaum and “Computer Architecture: A Quantitative Approach” by Hennessy and Patterson.

    Read the rest of this entry »