\chapter{Simple Evas canvas example}
\hypertarget{Example_Evas_Buffer_Simple}{}\label{Example_Evas_Buffer_Simple}\index{Simple Evas canvas example@{Simple Evas canvas example}}
The canvas will here use the buffer engine.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Evas.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Evas\_Engine\_Buffer.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <errno.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ WIDTH\ (320)}}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ HEIGHT\ (240)}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ Evas\ *create\_canvas(\textcolor{keywordtype}{int}\ width,\ \textcolor{keywordtype}{int}\ height);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ destroy\_canvas(Evas\ *canvas);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ draw\_scene(Evas\ *canvas);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ save\_scene(Evas\ *canvas,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dest);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\ *canvas;}
\DoxyCodeLine{\ \ \ Evas\_Object\ *bg,\ *r1,\ *r2,\ *r3;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Main__Group_gaa617071d85a52779e950e5b1d8c354e3}{evas\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ After\ turning\ Evas\ on,\ we\ create\ an\ Evas\ canvas\ to\ work\ in.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ Canvases\ are\ graphical\ workspaces\ used\ for\ placing\ and\ organizing}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ graphical\ objects.\ \ Normally\ we'd\ be\ using\ Ecore-\/Evas\ to\ create}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ the\ canvas,\ but\ for\ this\ example\ we'll\ hide\ the\ details\ in\ a}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ separate\ routine\ for\ convenience.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ canvas\ =\ create\_canvas(WIDTH,\ HEIGHT);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!canvas)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Next\ set\ the\ background\ to\ solid\ white.\ \ This\ is\ typically\ done\ by}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ creating\ a\ rectangle\ sized\ to\ the\ canvas,\ placed\ at\ the\ canvas}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ origin.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ Note\ that\ if\ the\ canvas\ were\ to\ change\ size,\ our\ background}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ rectangle\ will\ not\ automatically\ resize\ itself;\ we'd\ need\ to\ do}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ that\ manually\ with\ another\ evas\_object\_resize()\ call.\ \ In\ a\ real}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ application\ using\ Ecore-\/Evas,\ functionality\ in\ Ecore\ will\ take}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ care\ of\ resizing\ things.\ \ For\ this\ example,\ we'll\ just\ keep\ the}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ canvas\ dimensions\ fixed\ to\ avoid\ the\ problem.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ bg\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(bg,\ 255,\ 255,\ 255,\ 255);\ \textcolor{comment}{//\ white\ bg,\ no\ transparency}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(bg,\ 0,\ 0);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ at\ origin}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(bg,\ WIDTH,\ HEIGHT);\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ covers\ full\ canvas}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ puts(\textcolor{stringliteral}{"{}initial\ scene,\ with\ just\ background:"{}});}
\DoxyCodeLine{\ \ \ draw\_scene(canvas);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ To\ make\ the\ scene\ interesting\ let's\ add\ a\ few\ more\ rectangles\ of}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ various\ sizes\ and\ colors,\ starting\ with\ a\ big\ red\ one.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ By\ default\ all\ Evas\ objects\ are\ created\ in\ a\ 'hidden'\ state,}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ meaning\ they\ are\ not\ visible,\ won't\ be\ checked\ for\ changes\ during}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ canvas\ rendering,\ and\ won't\ receive\ input\ events.\ \ Thus,\ like\ we}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ did\ for\ the\ background\ object\ we\ must\ call\ evas\_object\_show()\ to}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ make\ our\ graphics\ objects\ usable.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ r1\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(r1,\ 255,\ 0,\ 0,\ 255);\ \textcolor{comment}{//\ 100\%\ opaque\ red}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(r1,\ 10,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(r1,\ 100,\ 100);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(r1);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Let's\ add\ a\ partly\ transparent\ rectangle\ on\ top\ of\ the\ red\ one.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ Graphics\ objects\ are\ treated\ as\ a\ stack\ in\ the\ canvas\ for\ drawing}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ purposes,\ so\ subsequent\ objects\ are\ drawn\ above\ the\ ones\ we've}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ already\ added\ to\ the\ canvas.\ \ This\ is\ important\ in\ objects\ that}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ have\ partially\ transparent\ fill\ coloring\ since\ we'll\ see\ part\ of}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ what's\ "{}behind"{}\ our\ object.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ In\ Evas,\ color\ values\ are\ pre-\/multiplied\ by\ their\ alpha.\ \ This\ means}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ that\ if\ we\ want\ a\ green\ rectangle\ that's\ half\ transparent,\ we'd\ have:}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ non-\/premul:\ r=0,\ g=255,\ b=0\ \ \ \ a=128\ (50\%\ alpha)}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ premul:}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ \ \ \ \ \ \ \ \ r\_premul\ =\ r\ *\ a\ /\ 255\ =\ \ \ \ \ \ 0\ *\ 128\ /\ 255\ =\ \ \ \ \ \ 0}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ \ \ \ \ \ \ \ \ g\_premul\ =\ g\ *\ a\ /\ 255\ =\ \ \ \ 255\ *\ 128\ /\ 255\ =\ \ \ \ 128}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ \ \ \ \ \ \ \ \ b\_premul\ =\ b\ *\ a\ /\ 255\ =\ \ \ \ \ \ 0\ *\ 128\ /\ 255\ =\ \ \ \ \ \ 0}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ Since\ we're\ placing\ our\ half\ transparent\ green\ rectangle\ on\ top\ of}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ a\ red\ one,\ in\ the\ final\ output\ we\ will\ actually\ see\ a\ yellow\ square}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ (since\ in\ RGBA\ color\ green\ +\ red\ =\ yellow).}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ r2\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(r2,\ 0,\ 128,\ 0,\ 128);\ \textcolor{comment}{//\ 50\%\ opaque\ green}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(r2,\ 10,\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(r2,\ 50,\ 50);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(r2);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Lastly,\ for\ comparison\ add\ a\ dark\ green\ rectangle\ with\ no}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ transparency.\ */}}
\DoxyCodeLine{\ \ \ r3\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(canvas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(r3,\ 0,\ 128,\ 0,\ 255);\ \textcolor{comment}{//\ 100\%\ opaque\ dark\ green}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(r3,\ 60,\ 60);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(r3,\ 50,\ 50);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(r3);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ puts(\textcolor{stringliteral}{"{}final\ scene\ (note\ updates):"{}});}
\DoxyCodeLine{\ \ \ draw\_scene(canvas);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ In\ addition\ to\ displaying\ the\ canvas\ to\ the\ screen,\ let's\ also}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ output\ the\ buffer\ to\ a\ graphics\ file,\ for\ comparison.\ \ Evas}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ supports\ a\ range\ of\ graphics\ file\ formats,\ but\ PPM\ is\ particularly}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ trivial\ to\ write,\ so\ our\ save\_scene\ routine\ will\ output\ as\ PPM.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ save\_scene(canvas,\ \textcolor{stringliteral}{"{}/tmp/evas-\/buffer-\/simple-\/render.ppm"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ destroy\_canvas(canvas);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Main__Group_gadb9d1c9f3fcff94cea89e12942c40919}{evas\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/*\ Convenience\ routine\ to\ allocate\ and\ initialize\ the\ canvas.}}
\DoxyCodeLine{\textcolor{comment}{\ *\ In\ a\ real\ application\ we'd\ be\ using\ ecore\_evas\_buffer\_new()\ instead.}}
\DoxyCodeLine{\textcolor{comment}{\ */}}
\DoxyCodeLine{\textcolor{keyword}{static}\ Evas\ *create\_canvas(\textcolor{keywordtype}{int}\ width,\ \textcolor{keywordtype}{int}\ height)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\ *canvas;}
\DoxyCodeLine{\ \ \ Evas\_Engine\_Info\_Buffer\ *einfo;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ method;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{void}\ *pixels;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Request\ a\ handle\ for\ the\ 'buffer'\ type\ of\ rendering\ engine.\ */}}
\DoxyCodeLine{\ \ \ method\ =\ \mbox{\hyperlink{group__Evas__Output__Method_gae83ae2b11ce27503751a13ba44253564}{evas\_render\_method\_lookup}}(\textcolor{stringliteral}{"{}buffer"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (method\ <=\ 0)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ evas\ was\ not\ compiled\ with\ 'buffer'\ engine!\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Create\ a\ general\ canvas\ object.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ Note\ that\ we\ are\ responsible\ for\ freeing\ the\ canvas\ when\ we're\ done.\ */}}
\DoxyCodeLine{\ \ \ canvas\ =\ \mbox{\hyperlink{group__Evas__Canvas_gaff177702a6d5dd364896269a4a81822d}{evas\_new}}();}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!canvas)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ could\ not\ instantiate\ new\ evas\ canvas.\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Specify\ that\ the\ canvas\ will\ be\ rendering\ using\ the\ buffer\ engine\ method.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ We\ also\ size\ the\ canvas\ and\ viewport\ to\ the\ same\ width\ and\ height,\ with}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ the\ viewport\ set\ to\ the\ origin\ of\ the\ canvas.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga9335e65d48b48b0b29408bf580071edd}{evas\_output\_method\_set}}(canvas,\ method);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_gad8f0d6296332695b74022ea581c519e7}{evas\_output\_size\_set}}(canvas,\ width,\ height);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_gaf7502c7443033ea5fba75df5dd8b16c1}{evas\_output\_viewport\_set}}(canvas,\ 0,\ 0,\ width,\ height);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Before\ we\ can\ use\ the\ engine,\ we\ *must*\ set\ its\ configuration}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ parameters.\ \ The\ available\ parameters\ are\ kept\ in\ a\ struct}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ named\ Evas\_Engine\_Info\ which\ is\ internal\ to\ Evas.\ \ Thus\ to\ set}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ parameters\ we\ must\ first\ request\ the\ current\ info\ object\ from}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ our\ canvas:}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ einfo\ =\ (Evas\_Engine\_Info\_Buffer\ *)\mbox{\hyperlink{group__Evas__Canvas_ga1fd811b76d7e2f3a6a12ed198156afa3}{evas\_engine\_info\_get}}(canvas);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!einfo)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ could\ not\ get\ evas\ engine\ info!\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga441113f8898f46a94c2f44f254de0819}{evas\_free}}(canvas);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Create\ the\ underlying\ data\ buffer\ that\ our\ canvas\ will\ use.\ \ This}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ is\ a\ simple\ array\ of\ ARGB32\ pixels.\ \ Each\ color\ component}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ (including\ alpha)\ is\ one\ byte,\ resulting\ in\ 4\ bytes\ per\ pixel\ (or}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ 32\ bits).\ \ We\ can\ thus\ store\ each\ pixel\ in\ an\ integer\ data\ type,}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ thus\ calculating\ our\ data\ buffer\ as\ W\ x\ H\ x\ sizeof(int)\ bytes\ in}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ length.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ pixels\ =\ malloc(width\ *\ height\ *\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{int}));}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!pixels)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ could\ not\ allocate\ canvas\ pixels!\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga441113f8898f46a94c2f44f254de0819}{evas\_free}}(canvas);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Next\ set\ the\ various\ configuration\ parameters.\ \ We}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ register\ the\ pixel\ buffer\ that\ the\ canvas\ will\ use,}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ indicate\ the\ pixel\ format\ as\ ARGB32,\ and\ the\ size\ of}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ each\ row\ of\ data.\ */}}
\DoxyCodeLine{\ \ \ einfo-\/>info.depth\_type\ =\ EVAS\_ENGINE\_BUFFER\_DEPTH\_ARGB32;}
\DoxyCodeLine{\ \ \ einfo-\/>info.dest\_buffer\ =\ pixels;}
\DoxyCodeLine{\ \ \ einfo-\/>info.dest\_buffer\_row\_bytes\ =\ width\ *\ \textcolor{keyword}{sizeof}(int);}
\DoxyCodeLine{\ \ \ einfo-\/>info.use\_color\_key\ =\ 0;}
\DoxyCodeLine{\ \ \ einfo-\/>info.alpha\_threshold\ =\ 0;}
\DoxyCodeLine{\ \ \ einfo-\/>info.func.new\_update\_region\ =\ NULL;}
\DoxyCodeLine{\ \ \ einfo-\/>info.func.free\_update\_region\ =\ NULL;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Finally,\ we\ configure\ the\ canvas\ with\ our\ chosen\ parameters.\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_gaf3efb2e687b20b3ba6df18151558b16c}{evas\_engine\_info\_set}}(canvas,\ (\mbox{\hyperlink{struct__Evas__Engine__Info}{Evas\_Engine\_Info}}\ *)einfo);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ canvas;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/*\ Convenience\ routine\ to\ shut\ down\ the\ canvas.}}
\DoxyCodeLine{\textcolor{comment}{\ *\ In\ a\ real\ application\ we'd\ be\ using\ ecore\_evas\_free()\ instead}}
\DoxyCodeLine{\textcolor{comment}{\ */}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ destroy\_canvas(Evas\ *canvas)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Engine\_Info\_Buffer\ *einfo;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ einfo\ =\ (Evas\_Engine\_Info\_Buffer\ *)\mbox{\hyperlink{group__Evas__Canvas_ga1fd811b76d7e2f3a6a12ed198156afa3}{evas\_engine\_info\_get}}(canvas);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!einfo)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ could\ not\ get\ evas\ engine\ info!\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga441113f8898f46a94c2f44f254de0819}{evas\_free}}(canvas);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Free\ the\ data\ buffer\ we\ allocated\ in\ create\_buffer()\ */}}
\DoxyCodeLine{\ \ \ free(einfo-\/>info.dest\_buffer);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Finally,\ free\ the\ canvas\ itself.\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga441113f8898f46a94c2f44f254de0819}{evas\_free}}(canvas);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/*\ Convenience\ routine\ to\ update\ the\ scene.}}
\DoxyCodeLine{\textcolor{comment}{\ *\ In\ a\ real\ application\ Ecore\ Evas\ would\ be\ doing\ this\ for\ us.}}
\DoxyCodeLine{\textcolor{comment}{\ */}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ draw\_scene(Evas\ *canvas)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *updates,\ *n;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Rectangle}{Eina\_Rectangle}}\ *update;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Render\ the\ canvas,\ and\ get\ a\ list\ of\ the\ updated\ rectangles.\ */}}
\DoxyCodeLine{\ \ \ updates\ =\ \mbox{\hyperlink{group__Evas__Canvas_ga3946287d9b1d06f27826f73aea58f9be}{evas\_render\_updates}}(canvas);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Just\ for\ informative\ purposes,\ print\ out\ the\ areas\ being\ updated:\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(updates,\ n,\ update)}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}UPDATED\ REGION:\ pos:\ \%3d,\ \%3d\ \ \ \ size:\ \%3dx\%3d\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ update-\/>\mbox{\hyperlink{struct__Eina__Rectangle_a8358c0791dcf476432687510ca4e5d5c}{x}},\ update-\/>\mbox{\hyperlink{struct__Eina__Rectangle_ae74dc834fb71a1f4cd9e3fe11dec3940}{y}},\ update-\/>\mbox{\hyperlink{struct__Eina__Rectangle_af6a92d51ec25ee3464c81297ffc3a330}{w}},\ update-\/>\mbox{\hyperlink{struct__Eina__Rectangle_a7570ed17f58fc94be997414a86130074}{h}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Free\ the\ list\ of\ update\ rectangles\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga538ed406dfa68641867cbde42dade5f7}{evas\_render\_updates\_free}}(updates);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{/*\ Output\ the\ canvas\ buffer\ to\ a\ Portable\ Pixel\ Map\ (PPM)\ file\ */}}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ save\_scene(Evas\ *canvas,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dest)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Engine\_Info\_Buffer\ *einfo;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ *pixels,\ *pixels\_end;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ width,\ height;}
\DoxyCodeLine{\ \ \ FILE\ *f;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Retrieve\ the\ current\ data\ buffer.\ */}}
\DoxyCodeLine{\ \ \ einfo\ =\ (Evas\_Engine\_Info\_Buffer\ *)\mbox{\hyperlink{group__Evas__Canvas_ga1fd811b76d7e2f3a6a12ed198156afa3}{evas\_engine\_info\_get}}(canvas);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!einfo)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fputs(\textcolor{stringliteral}{"{}ERROR:\ could\ not\ get\ evas\ engine\ info!\(\backslash\)n"{}},\ stderr);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Retrieve\ the\ canvas\ dimensions\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga9db9974a647850d7bd49afb506c9717a}{evas\_output\_size\_get}}(canvas,\ \&width,\ \&height);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Open\ our\ output\ PPM\ file\ for\ writing\ */}}
\DoxyCodeLine{\ \ \ f\ =\ fopen(dest,\ \textcolor{stringliteral}{"{}wb+"{}});}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!f)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ open\ for\ writing\ '\%s':\ \%s\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dest,\ strerror(errno));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ Write\ out\ the\ pixel\ data\ to\ the\ PPM\ file\ */}}
\DoxyCodeLine{\ \ \ pixels\ =\ einfo-\/>info.dest\_buffer;}
\DoxyCodeLine{\ \ \ pixels\_end\ =\ pixels\ +\ (width\ *\ height);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ PPM\ P6\ format\ is\ dead\ simple\ to\ write.\ \ First\ we\ output\ a\ magic}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ number\ 'P6'\ to\ designate\ the\ file\ as\ PPM,\ then\ the\ width\ and}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ height\ on\ their\ own\ line\ in\ ASCII\ decimal,\ followed\ by\ the\ maximum}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ color\ value\ (255)\ on\ its\ own\ line\ in\ ASCII\ decimal,\ and\ finally\ a}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ the\ pixel\ data\ in\ RGB\ order\ with\ each\ color\ component\ written\ as}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ *\ a\ char\ (byte).\ \ No\ alpha\ information\ is\ stored.}}
\DoxyCodeLine{\textcolor{comment}{\ \ \ \ */}}
\DoxyCodeLine{\ \ \ fprintf(f,\ \textcolor{stringliteral}{"{}P6\(\backslash\)n\%d\ \%d\(\backslash\)n255\(\backslash\)n"{}},\ \ width,\ height);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (;\ pixels\ <\ pixels\_end;\ pixels++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ r,\ g,\ b;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ r\ =\ ((*pixels)\ \&\ 0xff0000)\ >>\ 16;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ g\ =\ ((*pixels)\ \&\ 0x00ff00)\ >>\ 8;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ b\ =\ (*pixels)\ \&\ 0x0000ff;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(f,\ \textcolor{stringliteral}{"{}\%c\%c\%c"{}},\ r,\ g,\ b);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ fclose(f);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}saved\ scene\ as\ '\%s'\(\backslash\)n"{}},\ dest);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 