2 Understanding the painting process
4 This file tries to describe the state of the metrics/painting
5 mechanism, and identify the improvements that could be made. The first
6 section can be read alone, although the context for them is really
7 given in the following ones.
9 Please keep this file up to date as the code evolves!!!
18 These questions are consequences of the description made in the
19 following section. Some actions are proposed.
23 The flag Update::SinglePar is set in many places but never acted on.
24 Instead, metrics update is skipped whenever the recorded height of
25 current paragraph did not change and Update::Force was not specified.
26 Is it better to keep that (which incurs extra work) or to condition it
27 on Update::SinglePar? If the first solution is kept, the flag
28 SingleParUpdate shall be removed.
30 Moreover, I fail to see (yet) where the 'single' part of the program
33 ** Buffer::change issues
35 When calling Buffer::changed outside of bv::processUpdateFlags,
36 how do we now that the update strategy is set correctly? It is
37 possible to reset the strategy at the end of bv::draw. What would be
38 a good value? NoScreenUpdate?
40 On a related note, what is the semantics of a call to
41 Buffer::changed(false)? What does the caller mean?
43 ** What happens with FitCursor when the cursor is already OK?
45 In this case, we invoke Buffer::change(false) with drawing disabled,
46 which means that the paint machinery is invoked to update inset
49 Actually, this was added as part of the horizontal scrolling GSoC
50 work. We need to investigate how costly this is.
55 ** get rid of pm::insetDimension.
57 The information contained there is already in bv::coordCache.
59 Effect: only code simplification.
61 ** set inset position during metrics phase
63 This implies to set inset positions relative to outer isnet during
64 metrics phase and then in a second loop to descend into insets and
65 update positions correctly.
67 Effect: avoid going through the painter machinery when it is not necessary.
69 ** Merging bv::updateMetrics and tm::metrics
71 While the full metrics computation tries hard to limit the number of
72 paragraphs that are rebroken, the version that is used for inner inset
73 does not try any such optimization. This can be very bad for very tall
74 insets. We should re-use the bv::updateMetrics logic:
75 + transfer all the logic of bv::updateMetrics to tm.
76 + Main InsetText should not be special.
78 ** Metrics outside of visible area
80 Currently metrics are computed for current visible paet of text, the
81 page above and the page below. It should be possible to compute hidden
82 rows ony on demand, although it might be a bit slow.
84 There was a proposal to always compute _all_ rows, but this may become
85 expensive for large files. This would though help scrolling.
90 There are two parts to drawing the work area:
92 + the metrics phase computes the size of insets and breaks the
93 paragraphs into rows. It stores the dimension of insets (both
94 normal and math) in bv::coordCache, and the size of normal
95 insets in pm::insetDimension.
97 + the drawing phase draws the contents and caches the inset
98 positions. Since the caching of positions is useful in itself,
99 there is a provision for drawing "without" drawing when the only
100 thing we want is to cache inset positions
101 (Painter::setDrawingEnabled).
104 The machinery is controlled via bv::processUpdateFlags. This method is
105 called at the end of bv::mouseEventDispatch and in
106 GuiApplication::dispatch, via the updateCurrentView method. There are
107 also several calls in code related to dialogs. We should evaluate
108 whether this is correct.
110 Depending on the Update::flags passed to the method, it sets an update
111 strategy in (NoScreenUpdate, SingleParUpdate, FullScreenUpdate,
112 DecorationUpdate). It triggers a recomputation of the metrics when either:
114 + Update::Force has been specified
115 + Update::FitCursor has been specified and there is a need to scroll
117 + the current paragraph, after rebreak, does not have the same height as in
118 existing metrics. Note that the Update::SinglePar flag is *never*
121 The screen is drawn (with appropriate update strategy), except when
122 update flag is Update::None.
125 * Metrics computation
127 This is triggered by bv::updateMetrics, which calls tm::redoParagraph for
128 + all visible paragraphs
129 + paragraph above the screen (up to one page)
130 + paragraphs below the screen (up to one page again)
132 The paragraphs outside of the screen are required to make PageUp/Down
135 tm::redoParagraph will call Inset::metrics for each inset. In the case
136 of text insets, this will invoke recursively tm::metrics, which redoes
137 all the paragraphs of the inset.
140 * Drawing the work area.
142 This is done in bv::draw. This method is triggered mainly by
143 Buffer::changed, which draws all the work areas that show the given buffer.
145 Note that, When Buffer::changed is called outside of
146 bv::processUpdateFlags, it is not clear whether the update strategy
147 has been set to a reasonable value beforehand.
149 The action depends on the update strategy:
151 + NoScreenUpdate: repaint the whole screen with drawing disabled.
152 This is only needed to update the inset positions. I am not sure
153 when this is necessary, actually. This is triggered when:
154 - Update::FitCursor is set but the cursor is already visible. It is
155 not clear why something needs to be done in this case, since this
156 should be equivalent to Update::None.
157 - this is also set when update flag is Update::None, but this value
158 is AFAICS not acted on in the code (meaning that nothing happens
159 at all in this case).
161 + FullScreenUpdate: repaint the whole screen. This is set when:
162 - updateMetrics has been invoked.
163 - scroll value of current row has changed (although this should not
166 + DecorationUpdate: actually like FullScreenUpdate, although it is
167 intended to only update inset decorations. This triggers when:
168 - Update::Decoration is set (without Update::Force) as flag.
169 - An hovered inset is detected.
171 + SingleParUpdate: only tries to repaint current paragraph in a way
172 that is not yet very clear to me.