summaryrefslogtreecommitdiff
path: root/libs/canvas/rectangle.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-04-12 11:08:24 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-04-12 11:08:24 -0400
commitfcb423f3f69225e0be896cb10b34b9628ab666f2 (patch)
tree922e0ad9df487c09cd68f7b668208776f1e0c96c /libs/canvas/rectangle.cc
parentf208593249c7bc1f139809aa32c8aa6320782af0 (diff)
slightly optimize drawing of rectangles with all 4 sides outlined to avoid multiple paths etc
Diffstat (limited to 'libs/canvas/rectangle.cc')
-rw-r--r--libs/canvas/rectangle.cc70
1 files changed, 48 insertions, 22 deletions
diff --git a/libs/canvas/rectangle.cc b/libs/canvas/rectangle.cc
index ea141e0954..cff7beffd4 100644
--- a/libs/canvas/rectangle.cc
+++ b/libs/canvas/rectangle.cc
@@ -40,32 +40,58 @@ Rectangle::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context)
if (_fill) {
setup_fill_context (context);
context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
- context->fill ();
- }
-
- if (_outline) {
- if (_outline_what & LEFT) {
- context->move_to (plot.x0, plot.y0);
- context->line_to (plot.x0, plot.y1);
- }
- if (_outline_what & BOTTOM) {
- context->move_to (plot.x0, plot.y1);
- context->line_to (plot.x1, plot.y1);
- }
-
- if (_outline_what & RIGHT) {
- context->move_to (plot.x1, plot.y0);
- context->line_to (plot.x1, plot.y1);
+ if (!_outline) {
+ context->fill ();
+ } else {
+
+ /* special/common case: outline the entire rectangle is
+ * requested, so just use the same path for the fill
+ * and stroke.
+ */
+
+ if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
+ context->fill_preserve();
+ setup_outline_context (context);
+ context->stroke ();
+ } else {
+ context->fill ();
+ }
}
+ }
+
+ if (_outline) {
- if (_outline_what & TOP) {
- context->move_to (plot.x0, plot.y0);
- context->line_to (plot.x1, plot.y0);
+ if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
+ context->rectangle (plot.x0, plot.y0, plot.width(), plot.height());
+ setup_outline_context (context);
+ context->stroke ();
+
+ } else {
+
+ if (_outline_what & LEFT) {
+ context->move_to (plot.x0, plot.y0);
+ context->line_to (plot.x0, plot.y1);
+ }
+
+ if (_outline_what & BOTTOM) {
+ context->move_to (plot.x0, plot.y1);
+ context->line_to (plot.x1, plot.y1);
+ }
+
+ if (_outline_what & RIGHT) {
+ context->move_to (plot.x1, plot.y0);
+ context->line_to (plot.x1, plot.y1);
+ }
+
+ if (_outline_what & TOP) {
+ context->move_to (plot.x0, plot.y0);
+ context->line_to (plot.x1, plot.y0);
+ }
+
+ setup_outline_context (context);
+ context->stroke ();
}
-
- setup_outline_context (context);
- context->stroke ();
}
}