From: André Pönitz Date: Tue, 12 Mar 2002 14:59:08 +0000 (+0000) Subject: speed up math drawing X-Git-Tag: 1.6.10~19671 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d15da27db8264a33c14d1abca4dc7c8413f16126;p=features.git speed up math drawing git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3729 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 2ece17bdb9..b81cd36295 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -24,12 +24,10 @@ libmathed_la_SOURCES = \ math_biginset.h \ math_binominset.C \ math_binominset.h \ - math_braceinset.C \ - math_braceinset.h \ math_boxinset.C \ math_boxinset.h \ - math_binaryopinset.C \ - math_binaryopinset.h \ + math_braceinset.C \ + math_braceinset.h \ math_casesinset.C \ math_casesinset.h \ math_charinset.C \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 36d717c72e..fc759f7744 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -335,14 +335,13 @@ void InsetFormula::read(Buffer const *, LyXLex & lex) void InsetFormula::draw(BufferView * bv, LyXFont const & font, int y, float & xx, bool) const { - int x = int(xx); - - Painter & pain = bv->painter(); - metrics(bv, font); + + int x = int(xx); int w = par_->width(); int h = par_->height(); int a = par_->ascent(); + Painter & pain = bv->painter(); if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background)) pain.fillRectangle(x, y - a, w, h, LColor::mathbg); diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 5eaa8f93ed..d7298a06b2 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -392,6 +392,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, hideInsetCursor(bv); mathcursor->normalize(); + mathcursor->touch(); + switch (action) { // --- Cursor Movements --------------------------------------------- @@ -721,6 +723,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, } mathcursor->normalize(); + mathcursor->touch(); lyx::Assert(mathcursor); diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index 0e70a9b043..8e423064ba 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -20,14 +20,10 @@ #include "math_atom.h" #include "math_inset.h" -#include "support/LAssert.h" #include -using std::swap; - - MathAtom::MathAtom() : nucleus_(0) {} @@ -48,7 +44,7 @@ void MathAtom::operator=(MathAtom const & p) if (&p == this) return; MathAtom tmp(p); - swap(tmp.nucleus_, nucleus_); + std::swap(tmp.nucleus_, nucleus_); } @@ -65,16 +61,3 @@ void MathAtom::reset(MathInset * p) delete nucleus_; nucleus_ = p; } - - -MathInset * MathAtom::nucleus() const -{ - lyx::Assert(nucleus_); - return nucleus_; -} - - -MathInset * MathAtom::operator->() const -{ - return nucleus(); -} diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 8e78a4b0c8..2c79655c8a 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -47,10 +47,10 @@ public: void operator=(MathAtom const &); /// change inset under the hood void reset(MathInset * p); + /// access to the inset (checked with gprof) + MathInset * nucleus() const { return nucleus_; } /// access to the inset - MathInset * nucleus() const; - /// access to the inset - MathInset * operator->() const; + MathInset * operator->() const { return nucleus_; } private: /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index fe08e2802a..2fe623fc35 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -934,6 +934,15 @@ void MathCursor::pullArg(bool goright) } +void MathCursor::touch() +{ + cursor_type::const_iterator it = Cursor_.begin(); + cursor_type::const_iterator et = Cursor_.end(); + for ( ; it != et; ++it) + it->xcell().touch(); +} + + void MathCursor::normalize() { // rebreak diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 3561d2089e..433810c229 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -185,6 +185,8 @@ public: /// make sure cursor position is valid void normalize(); + /// mark current cursor trace for redraw + void touch(); /// UpdatableInset * asHyperActiveInset() const; @@ -221,11 +223,6 @@ public: /// returns the normalized anchor of the selection MathCursorPos normalAnchor() const; - /// path of positions the cursor had to go if it were leving each inset - cursor_type Cursor_; - /// path of positions the anchor had to go if it were leving each inset - mutable cursor_type Anchor_; - /// reference to the last item of the path, i.e. "The Cursor" MathCursorPos & cursor(); /// reference to the last item of the path, i.e. "The Cursor" @@ -278,9 +275,13 @@ private: /// write access to cursor cell index idx_type & idx(); - /// + /// path of positions the cursor had to go if it were leving each inset + cursor_type Cursor_; + /// path of positions the anchor had to go if it were leving each inset + mutable cursor_type Anchor_; + /// pointer to enclsing LyX inset InsetFormulaBase * formula_; - /// + /// text code of last char entered MathTextCodes lastcode_; // Selection stuff /// do we currently select diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C index 3d6406c799..7bb1845097 100644 --- a/src/mathed/math_iterator.C +++ b/src/mathed/math_iterator.C @@ -21,20 +21,6 @@ MathIterator::MathIterator(MathInset * p) //{} -MathCursorPos const & MathIterator::position() const -{ - lyx::Assert(cursor_.size()); - return cursor_.back(); -} - - -MathCursorPos & MathIterator::position() -{ - lyx::Assert(cursor_.size()); - return cursor_.back(); -} - - MathCursor::cursor_type const & MathIterator::cursor() const { return cursor_; @@ -111,29 +97,32 @@ void MathIterator::operator++() { // move into the current inset if possible // it is impossible for pos() == size()! - if (nextInset() && nextInset()->isActive()) { - push(nextInset()); + MathInset * n = nextInset(); + if (n && n->isActive()) { + push(n); return; } // otherwise move on one cell position if possible - if (position().pos_ < xcell().data_.size()) { + MathCursorPos & top = position(); + if (top.pos_ < top.par_->cell(top.idx_).size()) { // pos() == size() is valid! - ++position().pos_; + ++top.pos_; return; } // otherwise move on one cell if possible - if (position().idx_ + 1 < par()->nargs()) { + if (top.idx_ + 1 < top.par_->nargs()) { // idx() == nargs() is _not_ valid! - ++position().idx_; - position().pos_ = 0; + ++top.idx_; + top.pos_ = 0; return; } // otherwise leave array, move on one position // this might yield pos() == size(), but that's a ok. - pop(); + // it certainly invalidates top + pop(); ++position().pos_; } diff --git a/src/mathed/math_iterator.h b/src/mathed/math_iterator.h index 7b484b030b..29998f4ac4 100644 --- a/src/mathed/math_iterator.h +++ b/src/mathed/math_iterator.h @@ -22,10 +22,10 @@ public: void operator++(); /// move on several steps void jump(MathInset::difference_type); - /// read access to top most item - MathCursorPos const & position() const; + /// read access to top most item (inline after running gprof!) + MathCursorPos const & position() const { return cursor_.back(); } /// write access to top most item - MathCursorPos & position(); + MathCursorPos & position() { return cursor_.back(); } /// read access to full path MathCursor::cursor_type const & cursor() const; /// read access to top most inset diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 78dc7cefd1..9ea3366ef3 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -609,8 +609,7 @@ int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size, whichFont(font, type, size); if (isBinaryOp(c, type)) return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font); - else - return lyxfont::width(c, font); + return lyxfont::width(c, font); } diff --git a/src/mathed/math_xdata.C b/src/mathed/math_xdata.C index cab9a2c337..3a1faff1fc 100644 --- a/src/mathed/math_xdata.C +++ b/src/mathed/math_xdata.C @@ -18,13 +18,26 @@ extern MathScriptInset const * asScript(MathArray::const_iterator it); MathXArray::MathXArray() - : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_() + : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(), + clean_(false), drawn_(false) {} +void MathXArray::touch() const +{ + clean_ = false; + drawn_ = false; +} + + void MathXArray::metrics(MathMetricsInfo const & mi) const { - size_ = mi; + if (clean_) + return; + + size_ = mi; + clean_ = true; + drawn_ = false; if (data_.empty()) { mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_); @@ -58,8 +71,12 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const void MathXArray::draw(Painter & pain, int x, int y) const { - xo_ = x; - yo_ = y; + //if (drawn_ && x == xo_ && y == yo_) + // return; + + xo_ = x; + yo_ = y; + drawn_ = true; if (data_.empty()) { pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline); diff --git a/src/mathed/math_xdata.h b/src/mathed/math_xdata.h index ee5b1d73a9..3a6739591b 100644 --- a/src/mathed/math_xdata.h +++ b/src/mathed/math_xdata.h @@ -32,6 +32,8 @@ public: void metrics(MathMetricsInfo const & st) const; /// redraw cell using cache metrics information void draw(Painter & pain, int x, int y) const; + /// mark cell for re-drawing + void touch() const; /// access to cached x coordinate of last drawing int xo() const { return xo_; } @@ -86,6 +88,10 @@ public: mutable int yo_; /// cache size information of last drawing mutable MathMetricsInfo size_; + /// cached cleaness of cell + mutable bool clean_; + /// cached draw status of cell + mutable bool drawn_; }; /// output cell on a stream