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. But I don't have to work on that right now (I am going on holydays). Feel free to experiment.

Unless I hear objection soon I will commit now if only because of the crashes that it solves.

Abdel.
Log:

BufferView:
* needRedra(), need_redraw_: deleted.
* updateMetrics(): now public.
* update(): only do the first drawing step. Returns true if a full updateMetrics is needed before drawing on screen.

WorkArea:
* redraw(): no check on BufferView::needRedraw(), call updateMetrics() unconditionally.

Index: BufferView.C
===================================================================
--- BufferView.C        (revision 14448)
+++ BufferView.C        (working copy)
@@ -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)
@@ -117,8 +117,8 @@
         *  position changes. \c forceupdate means to force an update
         *  in any case.
         */
-
        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 +223,9 @@
                int length, bool backwards);
        ///
        ViewMetricsInfo const & viewMetricsInfo();
-
        ///
-       bool needsRedraw() const;
-       void needsRedraw(bool redraw_needed);
+       void updateMetrics(bool singlepar = false);
+
 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;
 
@@ -667,30 +667,18 @@
        // Check needed to survive LyX startup
        if (!buffer_)
                return;
-       
-       // Check if there is already a redraw waiting in the queue.
-       if (needs_redraw_)
-               return;
 
        // 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))
+       if ((flags & (Update::Force | Update::FitCursor | Update::MultiParSel))
                && (fitCursor() || multiParSel())) {
-                       needs_redraw_ = true;
-                       singlePar = false;
+               // The second drawing step is done in WorkArea::redraw.
+               // nothing to do here?
        }
-
-       if (needs_redraw_) {
-               // Second drawing step
-               updateMetrics(singlePar);
-       }
 }
 
 
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h  (revision 14448)
+++ BufferView_pimpl.h  (working copy)
@@ -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,10 @@
                return;
        }
 
-       if (!buffer_view_->needsRedraw())
-               return;
+//     if (!buffer_view_->needsRedraw())
+//             return;
 
+       buffer_view_->updateMetrics(false);
        ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
        greyed_out_ = false;
        getPainter().start();
@@ -202,7 +203,7 @@
                ( vi.p2 < vi.size - 1 ?  vi.y2 : height() );
        expose(0, ymin, width(), ymax - ymin);
        getPainter().end();
-       buffer_view_->needsRedraw(false);
+//     buffer_view_->needsRedraw(false);
 
        lyxerr[Debug::DEBUG]
        << "  ymin = " << ymin << "  width() = " << width()

Reply via email to