Author: Carlos Lopez <genet...@gmail.com> Date: Sun Aug 12 10:57:11 2012 +0200
Checkerboard Layer: add support for Cairo render --- .../src/modules/mod_geometry/checkerboard.cpp | 95 ++++++++++++++++++++ .../src/modules/mod_geometry/checkerboard.h | 1 + 2 files changed, 96 insertions(+), 0 deletions(-) diff --git a/synfig-core/src/modules/mod_geometry/checkerboard.cpp b/synfig-core/src/modules/mod_geometry/checkerboard.cpp index 2e20c88..bb81100 100644 --- a/synfig-core/src/modules/mod_geometry/checkerboard.cpp +++ b/synfig-core/src/modules/mod_geometry/checkerboard.cpp @@ -200,3 +200,98 @@ CheckerBoard::accelerated_render(Context context,Surface *surface,int quality, c return true; } + +////////// + +bool +CheckerBoard::accelerated_cairorender(Context context,cairo_surface_t *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const +{ + SuperCallback supercb(cb,0,9500,10000); + + if(!is_solid_color()) + if(!context.accelerated_cairorender(surface,quality,renddesc,&supercb)) + return false; + + if(get_amount()==0) + return true; + + const float r(color.get_r()); + const float g(color.get_g()); + const float b(color.get_b()); + const float a(color.get_a()); + + const Point tl(renddesc.get_tl()); + const Point br(renddesc.get_br()); + + const int w(renddesc.get_w()); + const int h(renddesc.get_h()); + + // Width and Height of a pixel + const Real pw = (br[0] - tl[0]) / w; + const Real ph = (br[1] - tl[1]) / h; + + // These are translation values + const double tx(-tl[0]/pw); + const double ty(-tl[1]/ph); + + Point newsize(size); + if(newsize[0] <0.0) newsize[0]=-newsize[0]; + if(newsize[1] <0.0) newsize[1]=-newsize[1]; + + // Now let's render the minimum checkerboard in other surface + // Initially I'll fill it completely with the alpha color + // Create a similar image with the same dimensions than the minimum checkerboard + RendDesc desc(renddesc); + //desc.set_flags(0); + // this will modify the w and h values in pixels. + desc.set_tl(Point(origin[0]-newsize[0], origin[1]+newsize[1])); + desc.set_br(Point(origin[0]+newsize[0], origin[1]-newsize[1])); + double subsx(1/desc.get_pw()); + double subsy(1/desc.get_ph()); + double subtx(-desc.get_tl()[0]*subsx); + double subty(-desc.get_tl()[1]*subsy); + cairo_surface_t* subimage=cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, desc.get_w(), desc.get_h()); + cairo_t* subcr=cairo_create(subimage); + cairo_save(subcr); + cairo_translate(subcr, subtx , subty); + cairo_scale(subcr, subsx, subsy); + cairo_set_source_rgba(subcr, r, g, b, a); + cairo_rectangle(subcr, origin[0]-newsize[0], origin[1]-newsize[1], newsize[0], newsize[1]); + cairo_clip(subcr); + cairo_paint_with_alpha(subcr, get_amount()); + cairo_restore(subcr); + cairo_save(subcr); + cairo_translate(subcr, subtx , subty); + cairo_scale(subcr, subsx, subsy); + cairo_set_source_rgba(subcr, r, g, b, a); + cairo_rectangle(subcr, origin[0], origin[1], newsize[0], newsize[1]); + cairo_clip(subcr); + cairo_paint_with_alpha(subcr, get_amount()); + cairo_restore(subcr); + + cairo_t* cr=cairo_create(surface); + cairo_save(cr); + cairo_translate(cr, tx , ty); + cairo_pattern_t* pattern=cairo_pattern_create_for_surface(subimage); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_set_source(cr, pattern); + if(is_solid_color()) + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + else + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); // TODO this has to be the real operator + cairo_paint_with_alpha(cr, get_amount()); + + cairo_surface_destroy(subimage); + cairo_pattern_destroy(pattern); + cairo_destroy(subcr); + cairo_destroy(cr); + + // Mark our progress as finished + if(cb && !cb->amount_complete(10000,10000)) + return false; + + return true; +} + +////////// + diff --git a/synfig-core/src/modules/mod_geometry/checkerboard.h b/synfig-core/src/modules/mod_geometry/checkerboard.h index f30bda7..95d5e96 100644 --- a/synfig-core/src/modules/mod_geometry/checkerboard.h +++ b/synfig-core/src/modules/mod_geometry/checkerboard.h @@ -64,6 +64,7 @@ public: synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; + virtual bool accelerated_cairorender(synfig::Context context,cairo_surface_t *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; }; /* === E N D =============================================================== */ ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Synfig-devl mailing list Synfig-devl@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/synfig-devl