Author: Carlos Lopez <[email protected]>
Date: Mon Aug 13 12:24:37 2012 +0200
Layer_Polygon: initial version for Cairo render. No feather support yet. Needed
to expose some private members of Layer_Shape to Polygon_Layer in order to use
them in the render procedure
---
synfig-core/src/synfig/layer_polygon.cpp | 86 ++++++++++++++++++++++++++++++
synfig-core/src/synfig/layer_polygon.h | 2 +
synfig-core/src/synfig/layer_shape.h | 6 +-
3 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/synfig-core/src/synfig/layer_polygon.cpp
b/synfig-core/src/synfig/layer_polygon.cpp
index 9060dad..c46f1a2 100644
--- a/synfig-core/src/synfig/layer_polygon.cpp
+++ b/synfig-core/src/synfig/layer_polygon.cpp
@@ -179,3 +179,89 @@ Layer_Polygon::get_param_vocab()const
return ret;
}
+
+
+/////////
+bool
+Layer_Polygon::accelerated_cairorender(Context context,cairo_surface_t
*surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
+{
+ synfig::info("rendering Cairo polygon");
+
+ // Grab the rgba values
+ const float r(color.get_r());
+ const float g(color.get_g());
+ const float b(color.get_b());
+ const float a(color.get_a());
+
+ // Window Boundaries
+ 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 the scale and translation values
+ const double sx(1/pw);
+ const double sy(1/ph);
+ const double tx((-tl[0]+origin[0])*sx);
+ const double ty((-tl[1]+origin[1])*sy);
+
+ cairo_t* cr=cairo_create(surface);
+ // Let's render the polygon in other surface
+ // Initially I'll fill it completely with the alpha color
+ // Create a similar image with the same dimensions than the current
renddesc
+ cairo_surface_t* subimage=cairo_surface_create_similar(surface,
CAIRO_CONTENT_COLOR_ALPHA, renddesc.get_w(), renddesc.get_h());
+ cairo_t* subcr=cairo_create(subimage);
+ cairo_save(subcr);
+ cairo_set_source_rgba(subcr, r, g, b, a);
+ // Now let's check if it is inverted
+ if(invert)
+ {
+ cairo_paint(subcr);
+ }
+ // Draw the polygon
+ cairo_save(subcr);
+ cairo_translate(subcr, tx , ty);
+ cairo_scale(subcr, sx, sy);
+ int i,pointcount=vector_list.size();
+ for(i=0;i<pointcount; i++)
+ {
+ cairo_line_to(subcr, vector_list[i][0], vector_list[i][1]);
+ }
+ cairo_close_path(subcr);
+ if(invert)
+ cairo_set_operator(subcr, CAIRO_OPERATOR_CLEAR);
+ else
+ cairo_set_operator(subcr, CAIRO_OPERATOR_OVER);
+
+ cairo_fill(subcr);
+ cairo_restore(subcr);
+
+ // ADD FEATHER HERE
+
+ // Put the polygon on the surface
+ if(!is_solid_color()) // we need to render the context before
+
if(!context.accelerated_cairorender(surface,quality,renddesc,cb))
+ {
+ if(cb)
+ cb->error(strprintf(__FILE__"%d: Accelerated
Cairo Renderer Failure",__LINE__));
+ cairo_destroy(cr);
+ cairo_destroy(subcr);
+ cairo_surface_destroy(subimage);
+ return false;
+ }
+ cairo_set_source_surface(cr, subimage, 0, 0);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER); // TODO: this has to be
the real operator
+ cairo_paint_with_alpha(cr, get_amount());
+ cairo_restore(cr);
+ cairo_surface_destroy(subimage);
+ cairo_destroy(subcr);
+ cairo_destroy(cr);
+
+ return true;
+}
+
+/////////
diff --git a/synfig-core/src/synfig/layer_polygon.h
b/synfig-core/src/synfig/layer_polygon.h
index 262c91b..8294648 100644
--- a/synfig-core/src/synfig/layer_polygon.h
+++ b/synfig-core/src/synfig/layer_polygon.h
@@ -88,6 +88,8 @@ public:
private:
class PolySpan;
bool render_polyspan(Surface *surface,PolySpan &polyspan)const;
+ virtual bool accelerated_cairorender(Context context,cairo_surface_t
*surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
+
}; // END of Layer_Polygon
}; // END of namespace synfig
diff --git a/synfig-core/src/synfig/layer_shape.h
b/synfig-core/src/synfig/layer_shape.h
index 1b20d52..5655cfd 100644
--- a/synfig-core/src/synfig/layer_shape.h
+++ b/synfig-core/src/synfig/layer_shape.h
@@ -62,9 +62,9 @@ private:
//internal caching
struct Intersector;
Intersector *edge_table;
-
+protected:
//exported data
- Color color;
+ Color color;
Point origin;
bool invert;
@@ -73,7 +73,7 @@ private:
int blurtype;
Real feather;
WindingStyle winding_style;
-
+private:
std::vector< char > bytestream;
//for use in creating the bytestream
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl