From 78e128b380cce9b52d458faa94d275a50b2db2c3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 3 May 2007 06:14:41 +0000 Subject: [PATCH] special-case region intersection for rectangular regions svn: r6123 --- src/wxcommon/Region.cxx | 50 ++++++++++++++++++++++++++++++++++++++--- src/wxcommon/Region.h | 1 + 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/wxcommon/Region.cxx b/src/wxcommon/Region.cxx index dc44743583..7d6b115824 100644 --- a/src/wxcommon/Region.cxx +++ b/src/wxcommon/Region.cxx @@ -705,15 +705,57 @@ void wxRegion::Union(wxRegion *r) void wxRegion::Intersect(wxRegion *r) { if (r->dc != dc) return; + if (ReallyEmpty()) + return; if (r->ReallyEmpty()) { Cleanup(); return; } if (!no_prgn) { - wxPathRgn *pr; - if (!r->prgn) abort(); - pr = new WXGC_PTRS wxIntersectPathRgn(prgn, r->prgn); + wxPathRgn *rprgn, *pr; + rprgn = r->prgn; + if (!rprgn) abort(); + if (prgn->is_rect + && rprgn->is_rect + && (prgn->ox == rprgn->ox) + && (prgn->oy == rprgn->oy) + && (prgn->sx == rprgn->sx) + && (prgn->sy == rprgn->sy)) { + /* Special case: both are rectangles with the same + origin and scale. This is a common case, and it + can be a lot faster making a rectangle directly. */ + wxRectanglePathRgn *r1 = (wxRectanglePathRgn *)prgn; + wxRectanglePathRgn *r2 = (wxRectanglePathRgn *)rprgn; + double px, py, pw, ph; + + if (r1->x < r2->x) + px = r2->x; + else + px = r1->x; + if (r1->y < r2->y) + py = r2->y; + else + py = r1->y; + if (r1->x + r1->width < r2->x + r2->width) + pw = (r1->x + r1->width) - px; + else + pw = (r2->x + r2->width) - px; + if (r1->y + r1->height < r2->y + r2->height) + ph = (r1->y + r1->height) - py; + else + ph = (r2->y + r2->height) - py; + + if ((pw > 0) && (ph > 0)) + pr = new WXGC_PTRS wxRectanglePathRgn(dc, px, py, pw, ph); + else { + /* empty */ + Cleanup(); + return; + } + } else { + pr = new WXGC_PTRS wxIntersectPathRgn(prgn, r->prgn); + } prgn = pr; } @@ -1106,6 +1148,7 @@ wxPathRgn::wxPathRgn(wxDC *dc) ox = oy = 0.0; sx = sy = 1.0; } + is_rect = 0; } wxPathRgn::~wxPathRgn() @@ -1223,6 +1266,7 @@ wxRectanglePathRgn::wxRectanglePathRgn(wxDC *dc_for_scale, double _x, double _y, y = _y; width = _width; height = _height; + is_rect = 1; } Bool wxRectanglePathRgn::Install(long target, Bool reverse, Bool align) diff --git a/src/wxcommon/Region.h b/src/wxcommon/Region.h index ee1940dab7..66bbf4b1f1 100644 --- a/src/wxcommon/Region.h +++ b/src/wxcommon/Region.h @@ -104,6 +104,7 @@ class wxPathRgn : public wxObject { public: double ox, oy, sx, sy; + int is_rect; wxPathRgn(wxDC *dc_for_scale); ~wxPathRgn();