Skip to content

Commit ed3f96a

Browse files
author
fabien
committed
CoreLibrary performance issues
- optimized and added overriden push_clip(x,y,w,h) method while preserving the push_clip(const Rectangle&) method I observed that an important amount of fltk2 code used a push_clip(Rectangle(x,y,w,h)); typical code which was doubly inefficient becaused inside push_clip() we copied again the const rectangle Now only a native rectangle will be copied and with push_clip0(), you can even gain this construction copy if you don't need to preserve original rect. push_clip() is called very often in drawing so i think this optimization is non neglectable furthermore having a second way of calling push_clip is quite convenient too in many situations. git-svn-id: http://seriss.com/public/fltk/fltk/trunk@5114 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
1 parent 899d2bb commit ed3f96a

File tree

15 files changed

+35
-21
lines changed

15 files changed

+35
-21
lines changed

fltk/TabGroup.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ class FL_API TabGroup : public Group {
5151
protected:
5252
void draw();
5353

54-
private:
55-
int push(Widget *);
56-
int tab_positions(int*, int*);
5754
int tab_height();
5855
void draw_tab(int x1, int x2, int W, int H, Widget* o, int sel=0);
5956
void draw_tab_background();
6057

58+
private:
59+
int push(Widget *);
60+
int tab_positions(int*, int*);
61+
6162
bool _drawOutline;
6263
};
6364

fltk/compat/FL/fl_draw.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inline void fl_color(uchar r, uchar g, uchar b) {fltk::setcolor(fltk::color(r,g,
99
inline fltk::Color fl_color() {return fltk::getcolor();}
1010

1111
// clip:
12-
inline void fl_push_clip(int x, int y, int w, int h) {fltk::push_clip(fltk::Rectangle(x,y,w,h));}
12+
inline void fl_push_clip(int x, int y, int w, int h) {fltk::push_clip(x,y,w,h);}
1313
#define fl_clip fl_push_clip
1414
#define fl_pop_clip fltk::pop_clip
1515
inline int fl_not_clipped(int x, int y, int w, int h) {return fltk::not_clipped(fltk::Rectangle(x,y,w,h));}

fltk/draw.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ FL_API void transform(Rectangle&);
6161

6262
/*! \addtogroup clipping
6363
\{ */
64-
FL_API void push_clip(const Rectangle&);
64+
FL_API void push_clip0(Rectangle& r); // common method for push_clip primitives, r is modified in output
65+
// standard push_clip equals to former monolithic definition no perf. change
66+
inline void push_clip(const Rectangle& rectangle) {Rectangle r(rectangle); push_clip0(r);}
67+
// gain one rectangle construction by providing ddirect x,y,w,h push_clip alternative
68+
inline void push_clip(int X,int Y, int W, int H) {Rectangle r(X,Y,W,H); push_clip0(r);}
69+
6570
FL_API void clipout(const Rectangle&);
6671
FL_API void pop_clip();
6772
FL_API void push_no_clip();

ide/visualc/fltk.lib.dsp

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Browser.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using namespace fltk;
4141
/*! \class fltk::Browser
4242
4343
Displays a scrolling vertical list of text widgets, possibly with a
44-
hierachial arrangement, and lets the user select one of them.
44+
hierarchical arrangement, and lets the user select one of them.
4545
4646
\image html browser.gif
4747

src/Group.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void Group::draw() {
662662
#if USE_CLIPOUT
663663
// Non-blinky draw, draw the inside widgets first, clip their areas
664664
// out, and then draw the background:
665-
push_clip(Rectangle(w(), h()));
665+
push_clip(0,0, w(), h());
666666
int n; for (n = numchildren; n--;) {
667667
Widget& w = *child(n);
668668
fl_did_clipping = 0;
@@ -723,7 +723,7 @@ void Widget::draw_background() const {
723723
if (damage()&DAMAGE_EXPOSE) return;
724724
#endif
725725
if (!parent()) return;
726-
push_clip(Rectangle(w(),h()));
726+
push_clip(0,0,w(),h());
727727
push_matrix();
728728
translate(-x(), -y());
729729
if (!parent()->box()->fills_rectangle()) parent()->draw_background();

src/clip.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ void fltk::clip_region(Region region) {
136136
Pushes the \e intersection of the current region and \a rectangle
137137
onto the clip stack.
138138
*/
139-
void fltk::push_clip(const Rectangle& rectangle) {
140-
Rectangle r(rectangle); transform(r);
139+
void fltk::push_clip0(Rectangle& r) {
140+
transform(r);
141141
Region region;
142142
if (r.empty()) {
143143
#if USE_X11

src/color_chooser.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void ccHueBox::draw() {
228228
if (damage()&DAMAGE_ALL) draw_frame();
229229
Rectangle r(w(),h()); box()->inset(r);
230230
if (damage() == DAMAGE_VALUE) {
231-
push_clip(Rectangle(r.x()+px,r.y()+py,6,6));
231+
push_clip(r.x()+px,r.y()+py,6,6);
232232
}
233233
drawimage(generate_image, this, RGB, r);
234234
if (damage() == DAMAGE_VALUE) pop_clip();
@@ -327,7 +327,7 @@ void ccValueBox::draw() {
327327
i.aimage = false;
328328
}
329329
if (damage() == DAMAGE_VALUE) {
330-
push_clip(Rectangle(i.wh.x(),i.wh.y()+py,i.wh.w(),6));
330+
push_clip(i.wh.x(),i.wh.y()+py,i.wh.w(),6);
331331
}
332332
drawimage(generate_vimage, &i, RGB, i.wh);
333333
if (damage() == DAMAGE_VALUE) pop_clip();

src/drawtext.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ void fltk::drawtext(void (*textfunction)(const char*,int,float,float),
678678
for (i=0; i<current_column; i++) xx += column_widths_[i];
679679
pop_clip();
680680
if (segment_count > 1)
681-
push_clip(Rectangle(xx, r.y(), column_widths_[current_column], r.h()));
681+
push_clip(xx, r.y(), column_widths_[current_column], r.h());
682682
else
683-
push_clip(Rectangle(xx, r.y(), r.w(), r.h()));
683+
push_clip(xx, r.y(), r.w(), r.h());
684684
}
685685
if (s.symbol) {
686686
Symbol::text(s.start);

src/osx/clip.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void fltk::clip_region(Region r) {
9595
/*!
9696
Pushes the \e intersection of the current region and this rectangle
9797
onto the clip stack. */
98-
void fltk::push_clip(const Rectangle& r1) {
99-
Rectangle r(r1); transform(r);
98+
void fltk::push_clip0(Rectangle& r) {
99+
transform(r);
100100
Region region = NewRgn();
101101
if (r.empty()) {
102102
SetEmptyRgn(region);

test/arc.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const char* name[7] = {"X", "Y", "W", "H", "start", "end", "rotate"};
3333

3434
class Drawing : public fltk::Widget {
3535
void draw() {
36-
fltk::push_clip(Rectangle(w(), h()));
36+
fltk::push_clip(0,0, w(), h());
3737
fltk::setcolor(fltk::BLACK);
3838
fltk::fillrect(Rectangle(w(), h()));
3939
fltk::push_matrix();

test/curve.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int points;
4040

4141
class Drawing : public Widget {
4242
void draw() {
43-
push_clip(Rectangle(w(),h()));
43+
push_clip(0,0,w(),h());
4444
setcolor(GRAY20);
4545
fillrect(Rectangle(w(),h()));
4646
push_matrix();

test/fonts.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fltk::Widget* id_box;
4747

4848
void FontDisplay::draw() {
4949
draw_box();
50-
fltk::push_clip(fltk::Rectangle(2,2,w()-2,h()-2));
50+
fltk::push_clip(2,2,w()-2,h()-2);
5151
const char* saved_encoding = fltk::get_encoding();
5252
fltk::set_encoding(encoding);
5353
fltk::setfont(font, (float) size);

test/image_transform.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ rgbImage* theimage;
3838

3939
class Drawing : public Widget {
4040
void draw() {
41-
push_clip(Rectangle(w(),h()));
41+
push_clip(0, 0, w(),h());
4242
setcolor(GRAY20);
4343
fillrect(Rectangle(w(),h()));
4444
setcolor(GRAY10);

test/qubix.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ int makemove() {
824824

825825
class QubixView : public Widget {
826826
void draw() {
827-
push_clip(Rectangle(w(),h()));
827+
push_clip(0, 0, w(),h());
828828
setcolor(WHITE);
829829
fillrect(Rectangle(w(),h()));
830830
push_matrix();

0 commit comments

Comments
 (0)