]> git.lyx.org Git - features.git/blob - development/PAINTING_ANALYSIS
12b9983ea81e640a8aa0ec83d5e74c1c8e9a71bf
[features.git] / development / PAINTING_ANALYSIS
1 # -*- org-mode -*-
2 This file tries to describe the state of the metrics/painting
3 mechanism, and identify the improvements that could be made. The first
4 section can be read alone, although the context for them is really
5 given in the following ones.
6
7 Please keep this file up to date as the code evolves!!!
8
9 Abbreviations:
10 bv: BufferView
11 pm: ParagraphMetrics
12 tm::TextMetrics
13
14 * Questions / Ideas
15
16 These questions are consequences of the description made in the
17 following section. Some actions are proposed.
18
19 ** Inset cache
20
21 Why do we store inset dimensions both in bv::coordCache and in
22 pm::insetDimension? The later one is bad when same
23 buffer is shown in different views.
24
25 I propose to get rid of pm::insetDimension.
26
27 ** SinglePar update
28
29 The flag Update::SinglePar is set in many places but never acted on.
30 Instead, metrics update is skipped whenever the recorded height of
31 current paragraph did not change and Update::Force was not specified.
32 Is it better to keep that (which incurs extra work) or to condition it
33 on Update::SinglePar? If the first solution is kept, the flag
34 SingleParUpdate shall be removed.
35
36 Moreover, I fail to see (yet) where the 'single' part of the program
37 is acted on.
38
39 ** Two phase drawing
40
41 Why is it necessary to set the inset positions in the drawing phase?
42 It seems to me that everything can be done in the metrics phase (at
43 least for non-math insets).
44
45 ** Buffer::change issues
46
47 When calling Buffer::changed outside of bv::processUpdateFlags,
48 how do we now that the update strategy is set correctly? It is
49 possible to reset the strategy at the end of bv::draw. What would be
50 a good value? NoScreenUpdate?
51
52 On a related note, what is the semantics of a call to
53 Buffer::changed(false)? What does the caller mean?
54
55 ** Metrics outside of visible area
56
57 Why is it required to compute metrics on page above and below the
58 visible area? Couldn't this be done on demand? I suspect this could be
59 made transparent by doing it in the proper metrics-fetching method.
60
61 ** What happens with FitCursor when the cursor is already OK?
62
63 In this case, we invoke Buffer::change(false) with drawing disabled,
64 which means that the paint machinery is invoked to update inset
65 positions. Why is this necessary at all?
66
67 ** Merging bv::updateMetrics and tm::metrics
68
69 While the full metrics computation tries hard to limit the number of
70 paragraphs that are rebroken, the version that is used for inner inset
71 does not try any such optimization. This can be very bad for very tall
72 insets. How difficult would it be to re-use the bv::updateMetrics logic?
73
74
75 * Two phase drawing
76
77 There are two parts to drawing the work area:
78
79  + the metrics phase computes the size of insets and breaks the
80    paragraphs into rows. It stores the dimension of insets (both
81    normal and math) in bv::coordCache, and the size of normal
82    insets in pm::insetDimension.
83
84  + the drawing phase draws the contents and caches the inset
85    positions. Since the caching of positions is useful in itself,
86    there is a provision for drawing "without" drawing when the only
87    thing we want is to cache inset positions
88    (Painter::setDrawingEnabled).
89
90
91 The machinery is controlled via bv::processUpdateFlags. This method is
92 called at the end of bv::mouseEventDispatch and in
93 GuiApplication::dispatch, via the updateCurrentView method. There are
94 also several calls in code related to dialogs. We should evaluate
95 whether this is correct.
96
97 Depending on the Update::flags passed to the method, it sets an update
98 strategy in (NoScreenUpdate, SingleParUpdate, FullScreenUpdate,
99 DecorationUpdate). It triggers a recomputation of the metrics when either:
100
101  + Update::Force has been specified
102  + Update::FitCursor has been specified and there is a need to scroll
103    the display.
104  + the current paragraph, after rebreak, has the same height as in
105    existing metrics. Note that the Update::SinglePar flag is *never*
106    taken into account.
107
108 The screen is drawn (with appropriate update strategy), except when
109 update flag is Update::None.
110
111
112 ** Metrics computation
113
114 This is triggered by bv::updateMetrics, which calls tm::redoParagraph for
115   + all visible paragraphs
116   + paragraph above the screen (up to one page)
117   + paragraphs below the screen (up to one page again)
118
119 The paragraphs outside of the screen are required to make PageUp/Down
120 work.
121
122 tm::redoParagraph will call Inset::metrics for each inset. In the case
123 of text insets, this will invoke recursively tm::metrics, which redoes
124 all the paragraphs of the inset.
125
126
127 ** Drawing the work area.
128
129 This is done in bv::draw. This method is triggered mainly by
130 Buffer::changed, which draws all the work areas that show the given buffer.
131
132 Note that, When Buffer::changed is called outside of
133 bv::processUpdateFlags, it is not clear whether the update strategy
134 has been set to a reasonable value beforehand.
135
136 The action depends on the update strategy:
137
138  + NoScreenUpdate: repaint the whole screen with drawing disabled.
139    This is only needed to update the inset positions. I am not sure
140    when this is necessary, actually. This is triggered when:
141    - Update::FitCursor is set but the cursor is already visible. It is
142      not clear why something needs to be done in this case, since this
143      should be equivalent to Update::None.
144    - this is also set when update flag is Update::None, but this value
145      is AFAICS not acted on in the code (meaning that nothing happens
146      at all in this case).
147
148  + FullScreenUpdate: repaint the whole screen. This is set when:
149    - updateMetrics has been invoked.
150    - scroll value of current row has changed (although this should not
151      be necessary).
152
153  + DecorationUpdate: actually like FullScreenUpdate, although it is
154    intended to only update inset decorations. This triggers when:
155    - Update::Decoration is set (without Update::Force) as flag.
156    - An hovered inset is detected.
157
158  + SingleParUpdate: only tries to repaint current paragraph in a way
159    that is not yet very clear to me.