Hello,

With this patch I further reduce the need for the workArea_ member in BufferView::pimpl. Basically, on addition to the small fixes, updateSrollbar now only update the internal SrollbarParameter which is then read by GuiWorkArea on each update. This saves at least two calls to updateScrollbar() which turned out to be pretty expensive.

And the good news is that, with this patch and msvc2005, the UserGuide PageDown scrolling test is now at *18* seconds whereas it was at *34* seconds previously! It is now faster than qt3 on my machine (which is 22s).

Pretty happy with how the cleanup is turning out :-)

Here is my todo list for my cleanup API branch.

1) fix qt3/gtk/xforms to use the new API.
2) merge with trunk.

There are now two remaining uses of workArea_:

BufferView::Pimpl::update(Update::flags flags)

        workArea_->redraw(*bv_, vi);
        workArea_->greyOut();

These should be reasonably easy to solve but then I am affraid of the work involved to fix the frontends other than qt4.

If somebody wants to help, he will be pretty welcome.

Andel.


________________


Log:

* BufferView.h
  - ScrollbarParameters: new structure containing scrollbar parameters
  - ScrollbarParameters const & scrollbarParameters() const : new method
* BufferView.C
  - use pimpl_->width() instead of ->workarea().width()
  - use pimpl_->height() instead of ->workarea().height()

* BufferView_pimpl
  - use width_ instead of workArea_->width()
  - use height_ instead of workArea_->height()
  - ScrollbarParameters scrollbarParameters_: new private member
  - updateScrollbar() now only fills in scrollbarParameters_, no call to
    workArea_->setScrollbarParams() anymore.
  - updateScrollbar(): now only
- setBuffer(Buffer * b): erased duplicate call to updateScrollbar(), it was
    called already at the end of the update() method.

* GuiWorkArea::update() : adjust the scrollbar there without emitting a signal (tracking=false).
Index: BufferView.C
===================================================================
--- BufferView.C        (revision 14175)
+++ BufferView.C        (working copy)
@@ -148,6 +148,12 @@
 }
 
 
+ScrollbarParameters const & BufferView::scrollbarParameters() const
+{
+       return pimpl_->scrollbarParameters();
+}
+
+
 void BufferView::scrollDocView(int value)
 {
        pimpl_->scrollDocView(value);
@@ -196,7 +202,7 @@
 
 int BufferView::workWidth() const
 {
-       return pimpl_->workarea().width();
+       return pimpl_->width();
 }
 
 
@@ -340,7 +346,7 @@
 
 int BufferView::workHeight() const
 {
-       return pimpl_->workarea().height();
+       return pimpl_->height();
 }
 
 
Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14175)
+++ BufferView.h        (working copy)
@@ -62,7 +62,24 @@
 
 } // namespace
 
+/// Scrollbar Parameters
+struct ScrollbarParameters
+{
+       void reset(int h = 0, int p = 0, int l = 0)
+       {
+         height = h;
+         position = p;
+         lineScrollHeight = l;
+       }
 
+       /// The total document height in pixels
+       int height;
+       /// The current position in the document, in pixels
+       int position;
+       /// the line-scroll amount, in pixels
+       int lineScrollHeight;
+};
+
 /**
  * A buffer view encapsulates a view onto a particular
  * buffer, and allows access to operate upon it. A view
@@ -115,6 +132,8 @@
        bool fitCursor();
        /// reset the scrollbar to reflect current view position
        void updateScrollbar();
+       /// return the Scrollbar Parameters
+       ScrollbarParameters const & scrollbarParameters() const;
 
        /// FIXME
        bool available() const;
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14175)
+++ BufferView_pimpl.C  (working copy)
@@ -337,6 +337,18 @@
 }
 
 
+int BufferView::Pimpl::width() const
+{
+       return width_;
+}
+
+
+int BufferView::Pimpl::height() const
+{
+       return height_;
+}
+
+
 void BufferView::Pimpl::setBuffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
@@ -401,7 +413,6 @@
        }
 
        update();
-       updateScrollbar();
        owner_->updateMenubar();
        owner_->updateToolbars();
        owner_->updateLayoutChoice();
@@ -456,7 +467,7 @@
        if (!bv_->text()) {
                lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
                                     << " no text in updateScrollbar" << endl;
-               workArea_->setScrollbarParams(0, 0, 0);
+               scrollbarParameters_.reset();
                return;
        }
 
@@ -478,7 +489,7 @@
 
        // estimated average paragraph height:
        if (wh_ == 0)
-               wh_ = workArea_->height() / 4;
+               wh_ = height_ / 4;
        int h = t.getPar(anchor_ref_).height();
 
        // Normalize anchor/offset (MV):
@@ -491,7 +502,7 @@
        int sumh = 0;
        int nh = 0;
        for (lyx::pit_type pit = anchor_ref_; pit <= parsize; ++pit) {
-               if (sumh > workArea_->height())
+               if (sumh > height_)
                        break;
                int const h2 = t.getPar(pit).height();
                sumh += h2;
@@ -502,12 +513,18 @@
        if (hav > wh_)
                wh_ = hav;
 
-       workArea_->setScrollbarParams((parsize + 1) * wh_,
-               anchor_ref_ * wh_ + int(offset_ref_ * wh_ / float(h)),
-               int(wh_ * defaultRowHeight() / float(h)));
+       scrollbarParameters_.height = (parsize + 1) * wh_;
+       scrollbarParameters_.position = anchor_ref_ * wh_ + int(offset_ref_ * 
wh_ / float(h));
+       scrollbarParameters_.lineScrollHeight = int(wh_ * defaultRowHeight() / 
float(h));
 }
 
 
+ScrollbarParameters const & BufferView::Pimpl::scrollbarParameters() const
+{
+       return scrollbarParameters_;
+}
+
+
 void BufferView::Pimpl::scrollDocView(int value)
 {
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
@@ -535,7 +552,7 @@
 
        int const height = 2 * defaultRowHeight();
        int const first = height;
-       int const last = workArea_->height() - height;
+       int const last = height_ - height;
        LCursor & cur = cursor_;
 
        bv_funcs::CurStatus st = bv_funcs::status(bv_, cur);
@@ -668,7 +685,7 @@
                int const asc = font_metrics::maxAscent(font);
                int const des = font_metrics::maxDescent(font);
                Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
-               if (p.y_ - asc >= 0 && p.y_ + des < workArea_->height())
+               if (p.y_ - asc >= 0 && p.y_ + des < height_)
                        return false;
        }
        center();
@@ -869,7 +886,7 @@
        Paragraph const & par = bot.text()->paragraphs()[pit];
        anchor_ref_ = pit;
        offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
-               + par.ascent() - workArea_->height() / 2;
+               + par.ascent() - height_ / 2;
 }
 
 
@@ -1006,7 +1023,7 @@
        // surrounding LyXText will handle this event.
 
        // Build temporary cursor.
-       cmd.y = min(max(cmd.y, -1), workArea_->height());
+       cmd.y = min(max(cmd.y, -1), height_);
        InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
        //lyxerr << BOOST_CURRENT_FUNCTION
        //       << " * hit inset at tip: " << inset << endl;
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h  (revision 14175)
+++ BufferView_pimpl.h  (working copy)
@@ -79,6 +79,8 @@
        ///
        void updateScrollbar();
        ///
+       ScrollbarParameters const & scrollbarParameters() const;
+       ///
        void scrollDocView(int value);
        /// Wheel mouse scroll, move by multiples of text->defaultRowHeight().
        void scroll(int lines);
@@ -123,12 +125,18 @@
        lyx::frontend::WorkArea & workarea() const;
        /// the clipboard
        lyx::frontend::Clipboard & clipboard() const;
+       ///
+       int width() const;
+       ///
+       int height() const;
 
 private:
        ///
        int width_;
        ///
        int height_;
+       ///
+       ScrollbarParameters scrollbarParameters_;
 
        /// An error list (replaces the error insets)
        ErrorList errorlist_;
Index: frontends/qt4/GuiWorkArea.C
===================================================================
--- frontends/qt4/GuiWorkArea.C (revision 14175)
+++ frontends/qt4/GuiWorkArea.C (working copy)
@@ -461,6 +461,15 @@
        //q.drawImage(x, y, paint_device_.copy(x, y, w, h));
 
        viewport()->update(x, y, w, h);
+
+       buffer_view_->updateScrollbar();
+
+       ScrollbarParameters const & scroll_ = 
buffer_view_->scrollbarParameters();
+
+       verticalScrollBar()->setTracking(false);
+       setScrollbarParams(scroll_.height, scroll_.position,
+               scroll_.lineScrollHeight);
+       verticalScrollBar()->setTracking(true);
 }
 
 

Reply via email to