Andre Poenitz wrote:

> On Mon, Apr 05, 2004 at 11:19:49PM +0200, Alfredo Braunstein wrote:
>> Andre Poenitz wrote:
>> 
>> > fitCursor should be called at most once per user interaction, so this
>> > is a factor 2 at most. We can afford this.
>> 
>> I'm not so sure. For instance now we have a redraw after every cursor
>> movement that I think it is already too slow (cpu bumps to 100% when
>> pressing the right key...). I don't want to make it twice as slow...
> 
> Well. We could add cur.noUpdate() calls whenever we feel it's safe.
> The LFUN_LEFT/RIGHT handler seem to be good candidates.

Good idea. Will have a look.

> Can you send the patch?

Attached.
 
>> That would indeed be an option. Another one (maybe simpler?) is to have a
>> no-op painter as Angus suggested.
> 
> Yes. I saw this mail too late. It seems to be simpler and faster.

So I'm more confortable to apply it now, as we
 
>> I think this is too slow. But I will experiment a bit more and send a
>> patch soonish.

Attached. You can feel that going right in a small par is faster than going
right in a big par.

Now we have 1 update for cursor right (+ the aditional draw I'm introducing)
and it feels a bit slower than cvs (that I think that it's nevertheless too
slow). But should be sort of cured if we remove yet another unneeded update
call. And there are also possible reasonable optimizations in view, so I'm
more confortable with the patch now.

Still testing.

Alfredo

? ChangeLog-old
? PosIterator.C-save
? PosIterator.h-save
? bfri.C
? safe
? textcursor.C-save
? textcursor.h-save
? insets/insetcollapsable-save.C
? insets/insettext-save.C
? insets/safe
? mathed/safe
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.249
diff -u -p -u -r1.249 BufferView.C
--- BufferView.C	3 Apr 2004 08:36:53 -0000	1.249
+++ BufferView.C	6 Apr 2004 10:03:48 -0000
@@ -379,23 +379,10 @@ void BufferView::setCursor(ParIterator c
 		par[i].inset().edit(cursor(), true);
 
 	cursor().setCursor(makeDocIterator(par, pos), false);
+	par.bottom().text()->redoParagraph(par.bottom().par());
 }
 
 
-/*
-if the fitCursor call refers to some point in never-explored-land, then we
-don't have y information in insets there, then we cannot even do an update
-to get it (because we need the y infomation for setting top_y first). So
-this is solved in putSelectionAt with:
-
-- setting top_y to the y of the outerPar (that has good info)
-- calling update
-- calling cursor().updatePos()
-- then call fitCursor()
-
-Ab.
-*/
-
 void BufferView::putSelectionAt(DocIterator const & cur,
 				int length, bool backwards)
 {
@@ -403,16 +390,8 @@ void BufferView::putSelectionAt(DocItera
 
 	cursor().clearSelection();
 
-	LyXText & text = *cur[0].text();
 	setCursor(par, cur.pos());
 
-	// hack for the chicken and egg problem
-	top_y(text.getPar(par.outerPar()).y);
-
-	update();
-	//text.setCursor(cursor(), cur.par(), cur.pos());
-	cursor().updatePos();
-
 	if (length) {
 		if (backwards) {
 			cursor().setSelection(cursor(), -length);
@@ -422,9 +401,6 @@ void BufferView::putSelectionAt(DocItera
 		} else
 			cursor().setSelection(cursor(), length);
 	}
-
-	fitCursor();
-	update();
 }
 
 
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.536
diff -u -p -u -r1.536 BufferView_pimpl.C
--- BufferView_pimpl.C	5 Apr 2004 09:36:16 -0000	1.536
+++ BufferView_pimpl.C	6 Apr 2004 10:03:49 -0000
@@ -44,6 +44,7 @@
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "pariterator.h"
+#include "rowpainter.h"
 #include "undo.h"
 #include "vspace.h"
 
@@ -358,6 +359,9 @@ void BufferView::Pimpl::setBuffer(Buffer
 
 bool BufferView::Pimpl::fitCursor()
 {
+	// to get the correct y cursor info
+	screen().paintPar(*bv_, bv_->cursor().bottom().par());
+
 	if (!screen().fitCursor(bv_))
 		return false;
 	updateScrollbar();
@@ -388,7 +392,6 @@ void BufferView::Pimpl::resizeCurrentBuf
 
 	text->init(bv_);
 	update();
-	bv_->cursor().updatePos();
 	fitCursor();
 
 	switchKeyMap();
@@ -896,14 +899,12 @@ bool BufferView::Pimpl::workAreaDispatch
 
 	// If the request was dispatched the temp cursor should have been
 	// in a way to be used as new 'real' cursor.
-	if (res.dispatched())
+	if (res.dispatched()) {
 		bv_->cursor() = cur;
-
-	// Redraw if requested or necessary.
-	if (res.update())
-		update();
-	if (fitCursor())
-		update();
+		// Redraw if requested or necessary.
+		if (fitCursor() || res.update())
+			update();
+	}
 
 	// see workAreaKeyPress
 	cursor_timeout.restart();
@@ -1092,7 +1093,6 @@ bool BufferView::Pimpl::dispatch(FuncReq
 #endif
 		while (lyx::find::findNextChange(bv_))
 			bv_->getLyXText()->rejectChange(bv_->cursor());
-		update();
 		break;
 	}
 
@@ -1106,7 +1106,6 @@ bool BufferView::Pimpl::dispatch(FuncReq
 
 	case LFUN_MARK_OFF:
 		cur.clearSelection();
-		update();
 		cur.resetAnchor();
 		cur.message(N_("Mark off"));
 		break;
@@ -1114,7 +1113,6 @@ bool BufferView::Pimpl::dispatch(FuncReq
 	case LFUN_MARK_ON:
 		cur.clearSelection();
 		cur.mark() = true;
-		update();
 		cur.resetAnchor();
 		cur.message(N_("Mark on"));
 		break;
@@ -1129,7 +1127,6 @@ bool BufferView::Pimpl::dispatch(FuncReq
 			cur.message(N_("Mark set"));
 		}
 		cur.resetAnchor();
-		update();
 		break;
 
 	case LFUN_CENTER:
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.90
diff -u -p -u -r1.90 cursor.C
--- cursor.C	5 Apr 2004 16:44:09 -0000	1.90
+++ cursor.C	6 Apr 2004 10:03:50 -0000
@@ -84,8 +84,7 @@ void region(CursorSlice const & i1, Curs
 
 
 LCursor::LCursor(BufferView & bv)
-	: DocIterator(), bv_(&bv),
-	  anchor_(), cached_y_(0), x_target_(-1),
+	: DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
 	  selection_(false), mark_(false)
 {}
 
@@ -95,7 +94,6 @@ void LCursor::reset(InsetBase & inset)
 	clear();
 	push_back(CursorSlice(inset));
 	anchor_ = DocIterator(inset);
-	cached_y_ = 0;
 	clearTargetX();
 	selection_ = false;
 	mark_ = false;
@@ -236,15 +234,6 @@ int LCursor::currentMode()
 }
 
 
-void LCursor::updatePos()
-{
-	BOOST_ASSERT(!empty());
-	if (size() > 1)
-		cached_y_ = bv().top_y() + back().inset().yo();
-		//cached_y_ = back().inset().yo();
-}
-
-
 void LCursor::getDim(int & asc, int & des) const
 {
 	if (inMathed()) {
@@ -270,16 +259,6 @@ void LCursor::getPos(int & x, int & y) c
 	y = 0;
 	if (!empty())
 		inset().getCursorPos(back(), x, y);
-	// getCursorPos gives _screen_ coordinates. We need to add
-	// top_y to get document coordinates. This is hidden in cached_y_.
-	//y += cached_y_ - inset().yo();
-	// The rest is non-obvious. The reason we have to have these
-	// extra computation is that the getCursorPos() calls rely
-	// on the inset's own knowledge of its screen position.
-	// If we scroll up or down in a big enough increment,
-	// inset->draw() is not called: this doesn't update
-	// inset.yo_, so getCursor() returns an old value.
-	// Ugly as you like.
 }
 
 
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.57
diff -u -p -u -r1.57 cursor.h
--- cursor.h	5 Apr 2004 16:44:10 -0000	1.57
+++ cursor.h	6 Apr 2004 10:03:50 -0000
@@ -148,8 +148,6 @@ public:
 	CursorSlice & anchor();
 	/// access to selection anchor
 	CursorSlice const & anchor() const;
-	/// cache the absolute coordinate from the top inset
-	void updatePos();
 	/// sets anchor to cursor position
 	void resetAnchor();
 	/// access to owning BufferView
@@ -186,8 +184,6 @@ public:
 	DispatchResult disp_;
 
 private:
-	///
-	int cached_y_;
 	/**
 	 * The target x position of the cursor. This is used for when
 	 * we have text like :
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.610
diff -u -p -u -r1.610 lyxfunc.C
--- lyxfunc.C	5 Apr 2004 18:34:33 -0000	1.610
+++ lyxfunc.C	6 Apr 2004 10:03:52 -0000
@@ -1372,7 +1372,6 @@ void LyXFunc::dispatch(FuncRequest const
 		if (view()->available()) {
 			view()->fitCursor();
 			view()->update();
-			view()->cursor().updatePos();
 			// if we executed a mutating lfun, mark the buffer as dirty
 			if (getStatus(cmd).enabled()
 					&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.125
diff -u -p -u -r1.125 rowpainter.C
--- rowpainter.C	27 Mar 2004 01:18:47 -0000	1.125
+++ rowpainter.C	6 Apr 2004 10:03:52 -0000
@@ -844,43 +844,41 @@ void RowPainter::paintText()
 }
 
 
+} // namespace anon
+
+
 int paintPars(BufferView const & bv, LyXText const & text,
-	par_type pit, int xo, int yo, int y)
+	      par_type pit, par_type end)
 {
 	//lyxerr << "  paintRows: pit: " << &*pit << endl;
-	int const y2 = bv.painter().paperHeight();
-	y -= bv.top_y();
-
 	ParagraphList & pars = text.paragraphs();
-	for ( ; pit != par_type(pars.size()); ++pit) {
+	int y = pars[pit].y - bv.top_y();
+	for (; pit != end; ++pit) {
 		RowList::iterator row = pars[pit].rows.begin();
 		RowList::iterator rend = pars[pit].rows.end();
 
 		for ( ; row != rend; ++row) {
-			RowPainter(bv, text, pit, row, xo, y + yo);
+			RowPainter(bv, text, pit, row,
+				   text.xo_, y + text.yo_);
 			y += row->height();
 		}
-		if (yo + y >= y2)
-			break;
 	}
-
 	return y;
 }
 
-} // namespace anon
-
 
 int paintText(BufferView const & bv)
 {
-	par_type pit;
-	bv.text()->updateParPositions();
-	bv.text()->getRowNearY(bv.top_y(), pit);
+	par_type pit, end;
+	getParsInRange(bv.text()->paragraphs(), bv.top_y(),
+		       bv.top_y() + bv.painter().paperHeight(), pit, end);
 	//lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
-	return paintPars(bv, *bv.text(), pit, 0, 0, bv.text()->paragraphs()[pit].y);
+	return paintPars(bv, *bv.text(), pit, end);
 }
 
 
-void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo)
+void paintTextInset(LyXText const & text, PainterInfo & pi,
+		    int /*xo*/, int /*yo*/)
 {
-	paintPars(*pi.base.bv, text, 0, xo, yo, 0);
+	paintPars(*pi.base.bv, text, 0, text.paragraphs().size());
 }
Index: rowpainter.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.h,v
retrieving revision 1.18
diff -u -p -u -r1.18 rowpainter.h
--- rowpainter.h	15 Dec 2003 11:36:13 -0000	1.18
+++ rowpainter.h	6 Apr 2004 10:03:53 -0000
@@ -13,12 +13,18 @@
 #ifndef ROWPAINTER_H
 #define ROWPAINTER_H
 
+#include "support/types.h"
+
 class LyXText;
 class BufferView;
 class PainterInfo;
 
 /// paint the rows of the main text, return last drawn y value
 int paintText(BufferView const & bv);
+
+/// paint pars of the main text, return last drawn y value
+int paintPars(BufferView const & bv, LyXText const & text,
+	      lyx::par_type pit, lyx::par_type end);
 
 /// paint the rows of a text inset
 void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y);
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.244
diff -u -p -u -r1.244 text3.C
--- text3.C	5 Apr 2004 09:36:23 -0000	1.244
+++ text3.C	6 Apr 2004 10:03:54 -0000
@@ -1140,9 +1140,6 @@ void LyXText::dispatch(LCursor & cur, Fu
 		finishUndo();
 		cur.x_target() = cursorX(cur.top());
 
-		if (bv->fitCursor())
-			selection_possible = false;
-
 		// Insert primary selection with middle mouse
 		// if there is a local selection in the current buffer,
 		// insert this
Index: frontends/screen.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.C,v
retrieving revision 1.93
diff -u -p -u -r1.93 screen.C
--- frontends/screen.C	3 Apr 2004 08:37:08 -0000	1.93
+++ frontends/screen.C	6 Apr 2004 10:03:54 -0000
@@ -40,6 +40,7 @@
 #include "graphics/GraphicsLoader.h"
 
 #include "support/filetools.h" // LibFileSearch
+#include "support/types.h"
 
 #include <boost/utility.hpp>
 #include <boost/bind.hpp>
@@ -239,6 +240,14 @@ bool LyXScreen::fitCursor(BufferView * b
 
 	bv->top_y(newtop);
 	return true;
+}
+
+
+void LyXScreen::paintPar(BufferView & bv, lyx::par_type pit)
+{
+	workarea().getPainter().start();
+	paintPars(bv, *bv.text(), pit, pit + 1);
+	workarea().getPainter().end();
 }
 
 
Index: frontends/screen.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/screen.h,v
retrieving revision 1.29
diff -u -p -u -r1.29 screen.h
--- frontends/screen.h	13 Jan 2004 14:13:51 -0000	1.29
+++ frontends/screen.h	6 Apr 2004 10:03:54 -0000
@@ -13,6 +13,8 @@
 #ifndef SCREEN_H
 #define SCREEN_H
 
+#include "support/types.h"
+
 class LyXText;
 class CursorSlice;
 class WorkArea;
@@ -39,6 +41,9 @@ public:
 	/// redraw the screen, without using existing pixmap
 	virtual void redraw(BufferView & bv);
 
+	/// 
+	virtual void paintPar(BufferView & bv, lyx::par_type pit);
+	
 	/**
 	 * fitCursor - fit the cursor onto the work area
 	 * @param bv the bufferview

Reply via email to