Abdelrazak Younes wrote:
Hello,
You are going to be happy Lars, this patch removes the needRedraw
interface and simplify the screen update procedure. It also fixes all
crash problems.
The performance may suffer a bit because we do the second drawing step
in all cases. This could be optimized out by checking the return value
of the BufferView::update() method.
This updated patch implement this bool return value in preparation for
this potential optimization. It also delete the commented out code.
But I don't have to work on that
I don't have _time_ to work on that...
Abdel.
Index: BufferView.C
===================================================================
--- BufferView.C (revision 14448)
+++ BufferView.C (working copy)
@@ -129,9 +129,9 @@
}
-void BufferView::update(Update::flags flags)
+bool BufferView::update(Update::flags flags)
{
- pimpl_->update(flags);
+ return pimpl_->update(flags);
}
@@ -404,13 +404,7 @@
}
-bool BufferView::needsRedraw() const
+void BufferView::updateMetrics(bool singlepar)
{
- return pimpl_->needsRedraw();
+ pimpl_->updateMetrics(singlepar);
}
-
-
-void BufferView::needsRedraw(bool redraw_needed)
-{
- pimpl_->needsRedraw(redraw_needed);
-}
Index: BufferView.h
===================================================================
--- BufferView.h (revision 14448)
+++ BufferView.h (working copy)
@@ -116,9 +116,10 @@
* to do a fitcursor, and to force an update if screen
* position changes. \c forceupdate means to force an update
* in any case.
+ * \return true if a full updateMetrics() is needed.
*/
+ bool update(Update::flags flags = Update::FitCursor | Update::Force);
- void update(Update::flags flags = Update::FitCursor | Update::Force);
/// move the screen to fit the cursor. Only to be called with
/// good y coordinates (after a bv::metrics)
bool fitCursor();
@@ -223,10 +224,9 @@
int length, bool backwards);
///
ViewMetricsInfo const & viewMetricsInfo();
+ ///
+ void updateMetrics(bool singlepar = false);
- ///
- bool needsRedraw() const;
- void needsRedraw(bool redraw_needed);
private:
///
class Pimpl;
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C (revision 14448)
+++ BufferView_pimpl.C (working copy)
@@ -128,7 +128,7 @@
BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner)
: bv_(&bv), owner_(owner), buffer_(0), wh_(0),
cursor_(bv),
- multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0),
needs_redraw_(false)
+ multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0)
{
xsel_cache_.set = false;
@@ -652,7 +652,7 @@
}
-void BufferView::Pimpl::update(Update::flags flags)
+bool BufferView::Pimpl::update(Update::flags flags)
{
// This is close to a hot-path.
if (lyxerr.debugging(Debug::DEBUG)) {
@@ -666,31 +666,20 @@
// Check needed to survive LyX startup
if (!buffer_)
- return;
-
- // Check if there is already a redraw waiting in the queue.
- if (needs_redraw_)
- return;
+ return false;
// Update macro store
buffer_->buildMacros();
// First drawing step
- bool singlePar = flags & Update::SinglePar;
- needs_redraw_ = (flags & (Update::Force | Update::SinglePar));
+ updateMetrics(flags & Update::SinglePar);
- updateMetrics(singlePar);
-
- if ((flags & (Update::FitCursor | Update::MultiParSel))
- && (fitCursor() || multiParSel())) {
- needs_redraw_ = true;
- singlePar = false;
- }
-
- if (needs_redraw_) {
- // Second drawing step
- updateMetrics(singlePar);
- }
+ // The second drawing step is done in WorkArea::redraw() if needed.
+ bool const need_second_step =
+ (flags & (Update::Force | Update::FitCursor |
Update::MultiParSel))
+ && (fitCursor() || multiParSel());
+
+ return need_second_step;
}
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h (revision 14448)
+++ BufferView_pimpl.h (working copy)
@@ -58,7 +58,7 @@
//
bool multiParSel();
///
- void update(Update::flags flags = Update::Force);
+ bool update(Update::flags flags = Update::Force);
/// load a buffer into the view
bool loadLyXFile(std::string const &, bool);
///
@@ -117,14 +117,8 @@
///
ViewMetricsInfo const & viewMetricsInfo();
///
- bool needsRedraw() const
- {
- return needs_redraw_;
- }
- void needsRedraw(bool redraw_needed)
- {
- needs_redraw_ = redraw_needed;
- }
+ void updateMetrics(bool singlepar = false);
+
private:
///
int width_;
@@ -132,8 +126,6 @@
int height_;
///
ScrollbarParameters scrollbarParameters_;
- ///
- bool needs_redraw_;
/// An error list (replaces the error insets)
ErrorList errorlist_;
@@ -164,8 +156,6 @@
///
ViewMetricsInfo metrics_info_;
- ///
- void updateMetrics(bool singlepar = false);
///
friend class BufferView;
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C (revision 14448)
+++ frontends/WorkArea.C (working copy)
@@ -189,9 +189,7 @@
return;
}
- if (!buffer_view_->needsRedraw())
- return;
-
+ buffer_view_->updateMetrics(false);
ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
greyed_out_ = false;
getPainter().start();
@@ -202,7 +200,6 @@
( vi.p2 < vi.size - 1 ? vi.y2 : height() );
expose(0, ymin, width(), ymax - ymin);
getPainter().end();
- buffer_view_->needsRedraw(false);
lyxerr[Debug::DEBUG]
<< " ymin = " << ymin << " width() = " << width()