1 # Visual Class Library (VCL)
3 Visual Class Library (VCL) is responsible for the widgets (windowing, buttons, controls,
4 file-pickers etc.), operating system abstraction, including basic rendering (e.g. the output device).
6 It should not be confused with Borland's Visual Component Library, which is entirely unrelated.
8 VCL provides a graphical toolkit similar to gtk+, Qt, SWING etc.
11 + the main cross-platform chunk of source
14 + cross-platform abstraction headers
17 + a backend renderer that draws to bitmaps
29 + code common to macOS and iOS
35 + Qt5 (under construction)
38 + X11 backend and its sub-platforms
42 + KF5 support (based on qt5 VCL plugin mentioned above)
44 + GTK3 support with KDE5 file pickers (alternative to native kf5 one)
49 + "data transfer" - clipboard handling
50 + http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard
51 for tips how to show the current content of the
55 + How the platform abstraction works
57 + InitVCL calls 'CreateSalInstance'
58 + this is implemented by the compiled platform backends
59 + the SalInstance vtable is the primary outward facing gateway
60 API for platform backends
61 + It is a factory for:
62 SalFrames, SalVirtualDevices, SalPrinters,
63 Timers, the SolarMutex, Drag&Drop and other
64 objects, as well as the primary event loop wrapper.
66 Note: references to "SV" in the code mean StarView, which was a
67 portable C++ class library for GUIs, with very old roots, that was
68 developed by StarDivision. Nowadays it is not used by anything except
69 LibreOffice (and OpenOffice).
71 "svp" stands for "StarView Plugin".
73 ## SalData implementations
75 Each backend must provide an implementation of the SalData class. There is no
76 defined interface, so feel free to implement whatever suits your platform.
78 If your platform does font handling based on Freetype and Fontconfig, it's
79 highly recommended to use GenericUnixSalData as the base class; there isn't
80 really much *nix stuff in it.
82 Currently Windows, iOS and MacOSX have independent SalData implementations.
86 The way COM is used in LO generally:
87 - vcl puts main thread into Single-threaded Apartment (STA)
88 - oslWorkerWrapperFunction() puts every thread spawned via `oslCreateThread()`
89 into MTA (free-threaded)
93 GDIMetafile is a vector drawing representation that corresponds directly
94 to the SVM (StarView Metafile) format; it is extremely important as
95 an intermediate format in all sorts of drawing and printing operations.
97 There is a class `MetafileXmlDump` in `include/vcl/mtfxmldump.hxx` that
98 can store a GDIMetafile as XML, which makes debugging much easier
99 since you can just use "diff" to see changes.
103 emf+ is vector file format used by MSO and is successor of wmf and
105 http://msdn.microsoft.com/en-us/library/cc230724.aspx for
106 documentation. note that we didn't have this documentation from
107 start, so part of the code predates to the time when we had guessed
108 some parts and can be enhanced today. there also still many thing not
111 emf+ is handled a bit differently compared to original emf/wmf files,
112 because GDIMetafile is missing features we need (mostly related to
113 transparency, argb colors, etc.)
115 emf/wmf is translated to GDIMetafile in import filter
116 `vcl/source/filter/wmf` and so special handling ends here
118 emf+ is encapsulated into GDIMetafile inside comment records and
119 parsed/rendered later, when it reaches cppcanvas. It is parsed and
120 rendered in cppcanvas/source/mtfrenderer. also note that there are
121 emf+-only and emf+-dual files. dual files contains both types of
122 records (emf and emf+) for rendering the images. these can used also
123 in applications which don't know emf+. in that case we must ignore
124 emf records and use emf+ for rendering. for more details see
129 wmf/emf filter --> GDI metafile with emf+ in comments --> cppcanvas metafile renderer
131 lately the GDIMetafile rendering path changed which also influenced
132 emf+ rendering. now many things happen in drawing layer, where
133 GDIMetafile is translated into drawing layer primitives. for
134 metafiles with emf+ we let the mtfrenderer render them into bitmap
135 (with transparency) and use this bitmap in drawinlayer. cleaner
136 solution for current state would be to extend the drawing layer for
137 missing features and move parsing into drawing layer (might be quite
138 a lot of work). intermediary enhancement would be to know better the
139 needed size/resolution of the bitmap, before we render emf+ into
140 bitmap in drawing layer. Thorsten is working on the same problem with
141 svg rendering, so hopefully his approach could be extended for emf+ as
142 well. the places in drawing layer where we use canvas mtfrenderer to
143 render into bitmaps can be found when you grep for GetUseCanvas. also
144 look at vcl/source/gdi/gdimetafile.cxx where you can look for
145 UseCanvas again. moving the parsing into drawinglayer might also have
146 nice side effect for emf+-dual metafiles. in case the emf+ records
147 are broken, it would be easier to use the duplicit emf
148 rendering. fortunately we didn't run into such a broken emf+ file
149 yet. but there were already few cases where we first though that the
150 problem might be because of broken emf+ part. so far it always turned
151 out to be another problem.
157 vcl --> cppcanvas metafile renderer --> vcl
161 drawing layer --> vcl --> cppcanvas metafile renderer --> vcl --> drawing layer
163 another interesting part is actual rendering into canvas bitmap and
164 using that bitmap later in code using vcl API.
166 EMF+ implementation has some extensive logging, best if you do a dbgutil
169 export SAL_LOG=+INFO.cppcanvas.emf+INFO.vcl.emf
171 before running LibreOffice; it will give you lots of useful hints.
173 You can also fallback to EMF (from EMF+) rendering via
175 export EMF_PLUS_DISABLE=1
178 ## Printing/PDF Export
180 Printing from Writer works like this:
182 1) individual pages print by passing an appropriate OutputDevice to XRenderable
183 2) in drawinglayer, a VclMetafileProcessor2D is used to record everything on
184 the page (because the OutputDevice has been set up to record a GDIMetaFile)
185 3) the pages' GDIMetaFiles are converted to PDF by the vcl::PDFWriter
186 in `vcl/source/gdi/pdfwriter*`
188 Creating the ODF thumbnail for the first page works as above except step 3 is:
190 3) the GDIMetaFile is replayed to create the thumbnail
192 On-screen display differs in step 1 and 2:
194 1) the VCL Window gets invalidated somehow and paints itself
195 2) in drawinglayer, a `VclPixelProcessor2D` is used to display the content
198 ### Debugging PDF export
200 Debugging the PDF export becomes much easier when
201 compression is disabled (so the PDF file is directly readable) and
202 the MARK function puts comments into the PDF file about which method
203 generated the following PDF content.
205 The compression can be disabled even using an env. var:
207 export VCL_DEBUG_DISABLE_PDFCOMPRESSION=1
209 To de-compress the contents of a PDF file written by a release build or
210 other programs, use the "pdfunzip" tool:
212 bin/run pdfunzip input.pdf output.pdf
216 The solar mutex is the "big kernel lock" of LibreOffice, a global one. It's a
217 recursive mutex, so it's allowed to take the lock on the same thread multiple
218 times, and only the last unlock will actually release the mutex.
220 UNO methods on components can be called from multiple threads, while the
221 majority of the codebase is not prepared for multi-threading. One way to get
222 around this mismatch is to create a SolarMutexGuard instance at the start of
223 each & every UNO method implementation, but only when it is necessary:
225 - Only acquire the SolarMutex if you actually need it (e.g., not in functions
226 that return static information).
228 - Only around the code that actually needs it (i.e., never call out with it
231 This way you ensure that code (not prepared for multithreading) is still
232 executed only on a single thread.
234 In case you expect that your caller takes the solar mutex, then you can use
235 the `DBG_TESTSOLARMUTEX()` macro to assert that in dbgutil builds.
237 Event listeners are a special (but frequent) case of the "never call out with
238 a mutex (`SolarMutex` or other) locked" fundamental rule:
240 - UNO methods can be called from multiple threads, so most implementations
241 take the solar mutex as their first action when necessary.
243 - This can be problematic if later calling out (an event handler is called),
244 where the called function may be an UNO method implementation as well and
245 may be invoked on a different thread.
247 - So we try to not own the solar mutex, whenever we call out (invoke event
250 In short, never hold any mutex unless necessary, especially not when calling
254 * [Environment variables in VCL](README.vars.md)
255 * [GDIMetaFile class](README.GDIMetaFile.md)
256 * [Understanding transitional VCL lifecycle](README.lifecycle.md)
257 * [VCL scheduler](README.scheduler.md)