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 know 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 ** How to avoid redraw with FitCursor when the cursor is already OK?
45 In this case, we invoke Buffer::change(false) with drawing disabled
46 and NoScreenUpdate strategy.
48 In the draw phase, bv::checkCursorScrollOffset (the horizontal
49 scrolling machinery) will change the strategy to FullScreenUpdate if
50 the current row needs further scrolling.
52 When the update strategy it kept to NoScreenUpdate, there is currently
53 a no-draw full repaint, which should not be necessary. It would be
54 possible to avoid that if the call to checkCursorScrollOffset was done
55 in bv::processUpdateFlags instead of bv::draw.
57 The global idea would be to extend FitCursor to cover also horizontal
63 * Clean-up of drawing code
65 The goal is to make painting with drawing disable fast enough that it
66 can be used after every metrics computation. Then we can separate real
71 Inset position is set in paintInset, paintOnlyInsets, and paintText.
72 This should be done only once in paintInset
74 ** DONE TextMetrics::drawParagraph
76 We can really simplify the code when drawing is disabled only
77 paintInset needs to be called.
78 + do right at the start when drawing is already disabled
79 + do it in the loop for rows that are not visible on screen.
81 The only thing we want to do here is to set inset positions (for
82 text). The other insets still use the painter with drawing disabled.
86 We cannot remove (or make private) the version that uses a
87 FontInfo because it is used by PainterInfo::draw. Document this and
88 remove unused arguments rtl and double spacing. This would become a specialized helper.
89 Proposed solution: keep the existing function, but private and without
92 Avoid to return (and thus compute) the width of strings?
93 + used by InsetSpecialChar (fixable)
94 + used by textDecoration() in text(): more difficult to fix
96 Idea: add a version of text where wordspacing and textwidth (giving
97 the width of strings) are required parameters and remove optional
100 ==> more versions, no optional parameters.
102 ** Set inset position during metrics phase
104 In order to do that, a no-paint drawing will be initiated after every
105 redoParagraph. This code path will need to be made as fast as possible.
107 Effect: avoid depending on actual drawing having taken place. In turn,
108 it will allow to do drawing on paint events, like any reasonable
109 application would do.
111 ** Cleanup after complete metrics
112 Then the following can be done:
113 + remove hack in InsetMathNest::drawSelection
114 + remove painting when not inside in drawParagraph
115 + remove Cursor::inCoordCache?
117 ** Use Row for MathData
119 It may not be so difficult. Implement x2pos and pos2x from
120 the TM:cursorX and TM::getPosNearX, and use them for both text and
123 Will the strings display OK if drawing string-wise?
125 Then it would be possible to streamline drawing with disabled painter.
127 ** Paint directly to screen
129 Instead of using an intermediary pixmap. I have no idea of how
130 difficult it will prove.
131 One benefit will be that subpixel aliasing will work again (#9972)
133 ** Merging bv::updateMetrics and tm::metrics
135 While the full metrics computation tries hard to limit the number of
136 paragraphs that are rebroken, the version that is used for inner inset
137 does not try any such optimization. This can be very bad for very tall
138 insets. We should re-use the bv::updateMetrics logic:
139 + transfer all the logic of bv::updateMetrics to tm.
140 + Main InsetText should not be special.
142 The difficuly for a tall table cell for example, is that it may be
143 necessary to break the whole contents to know the width of the cell.
146 * Description of current drawing mechanism
150 There are two parts to drawing the work area:
152 + the metrics phase computes the size of insets and breaks the
153 paragraphs into rows. It stores the dimension of insets (both
154 normal and math) in bv::coordCache.
156 + the drawing phase draws the contents and caches the inset
157 positions. Since the caching of positions is useful in itself,
158 there is a provision for drawing "without" drawing when the only
159 thing we want is to cache inset positions
160 (Painter::setDrawingEnabled).
162 The machinery is controlled via bv::processUpdateFlags. This method is
163 called at the end of bv::mouseEventDispatch and in
164 GuiApplication::dispatch, via the updateCurrentView method. There are
165 also several calls in code related to dialogs. We should evaluate
166 whether this is correct.
168 Depending on the Update::flags passed to the method, it sets an update
169 strategy in (NoScreenUpdate, SingleParUpdate, FullScreenUpdate,
170 DecorationUpdate). It triggers a recomputation of the metrics when either:
172 + Update::Force has been specified
173 + Update::FitCursor has been specified and there is a need to scroll
175 + the current paragraph, after rebreak, does not have the same height as in
176 existing metrics. Note that the Update::SinglePar flag is *never*
179 The screen is drawn (with appropriate update strategy), except when
180 update flag is Update::None.
183 ** Metrics computation
185 This is triggered by bv::updateMetrics, which calls tm::redoParagraph for
186 + all visible paragraphs
187 + paragraph above the screen (up to one page)
188 + paragraphs below the screen (up to one page again)
190 The paragraphs outside of the screen are required to make PageUp/Down
193 tm::redoParagraph will call Inset::metrics for each inset. In the case
194 of text insets, this will invoke recursively tm::metrics, which redoes
195 all the paragraphs of the inset.
198 ** Drawing the work area.
200 This is done in bv::draw. This method is triggered mainly by
201 Buffer::changed, which draws all the work areas that show the given buffer.
203 Note that, When Buffer::changed is called outside of
204 bv::processUpdateFlags, it is not clear whether the update strategy
205 has been set to a reasonable value beforehand.
207 The action depends on the update strategy:
209 + NoScreenUpdate: repaint the whole screen with drawing disabled.
210 This is only needed to update the inset positions. I am not sure
211 when this is necessary, actually. This is triggered when:
212 - Update::FitCursor is set but the cursor is already visible. It is
213 not clear why something needs to be done in this case, since this
214 should be equivalent to Update::None.
215 - this is also set when update flag is Update::None, but this value
216 is AFAICS not acted on in the code (meaning that nothing happens
217 at all in this case).
219 + FullScreenUpdate: repaint the whole screen. This is set when:
220 - updateMetrics has been invoked.
221 - scroll value of current row has changed (although this should not
224 + DecorationUpdate: actually like FullScreenUpdate, although it is
225 intended to only update inset decorations. This triggers when:
226 - Update::Decoration is set (without Update::Force) as flag.
227 - An hovered inset is detected.
229 + SingleParUpdate: only tries to repaint current paragraph in a way
230 that is not yet very clear to me.