| 1 |
This is code for using the Skia library as a drawing library in VCL backends. |
| 2 |
See external/skia for info on the library itself. |
| 3 |
|
| 4 |
Environment variables: |
| 5 |
====================== |
| 6 |
|
| 7 |
See README.vars in the toplevel vcl/ directory. Note that many backends do not |
| 8 |
use Skia. E.g. on Linux it is necessary to also use SAL_USE_VCLPLUGIN=gen . |
| 9 |
|
| 10 |
There are also GUI options for controlling whether Skia is enabled. |
| 11 |
|
| 12 |
Skia drawing methods: |
| 13 |
===================== |
| 14 |
|
| 15 |
Skia supports several methods to draw: |
| 16 |
- Raster - CPU-based drawing (here primarily used for fallback when Vulkan isn't available or for debugging) |
| 17 |
- Vulkan - Vulkan-based GPU drawing, this is the default |
| 18 |
- Metal - MACOSX GPU drawing, this is the Mac default |
| 19 |
|
| 20 |
There are more (OpenGL, Metal on Mac, etc.), but (as of now) they are not supported by VCL. |
| 21 |
|
| 22 |
Logging: |
| 23 |
======== |
| 24 |
|
| 25 |
Run LO with 'SAL_LOG=+INFO.vcl.skia' to get log information about Skia including |
| 26 |
tracing each drawing operation. If you want log information without drawing operations, |
| 27 |
use 'SAL_LOG=+INFO.vcl.skia-INFO.vcl.skia.trace'. |
| 28 |
|
| 29 |
Debugging: |
| 30 |
========== |
| 31 |
|
| 32 |
Both SkiaSalBitmap and SkiaSalGraphicsImpl have a dump() method that writes a PNG |
| 33 |
with the current contents. There is also SkiaHelper::dump() for dumping contents |
| 34 |
of SkBitmap, SkImage and SkSurface. You can use these in a debugger too, for example |
| 35 |
'p SkiaHelper::dump(image, "/tmp/a.png")'. |
| 36 |
|
| 37 |
If there is a drawing problem, you can use something like the following piece of code |
| 38 |
to dump an image after each relevant operation (or do it in postDraw() if you don't |
| 39 |
know which operation is responsible). You can then find the relevant image |
| 40 |
and match it with the responsible operation (run LO with 'SAL_LOG=+INFO.vcl.skia'). |
| 41 |
|
| 42 |
static int cnt = 0; |
| 43 |
++cnt; |
| 44 |
char buf[100]; |
| 45 |
sprintf(buf,"/tmp/a%05d.png", cnt); |
| 46 |
SAL_DEBUG("CNT:" << cnt); |
| 47 |
if(cnt > 4000) // skip some initial drawing operations |
| 48 |
dump(buf); |
| 49 |
|
| 50 |
|
| 51 |
Testing: |
| 52 |
======== |
| 53 |
|
| 54 |
Currently unittests always use the 'headless' VCL backend. Use something like the following |
| 55 |
to run VCL unittests with Skia (and possibly skip slowcheck): |
| 56 |
|
| 57 |
SAL_SKIA=raster SAL_ENABLESKIA=1 SAL_USE_VCLPLUGIN=gen make vcl.build vcl.unitcheck vcl.slowcheck |
| 58 |
|
| 59 |
You can also use 'visualbackendtest' to visually check some operations. Use something like: |
| 60 |
|
| 61 |
SAL_SKIA=raster SAL_ENABLESKIA=1 SAL_USE_VCLPLUGIN=gen [srcdir]/bin/run visualbackendtest |
| 62 |
|
| 63 |
|
| 64 |
Thread safety: |
| 65 |
============== |
| 66 |
|
| 67 |
SolarMutex must be held for most operations (asserted in SkiaSalGraphicsImpl::preDraw() and |
| 68 |
in SkiaZone constructor). The reason for this is that this restriction does not appear to be |
| 69 |
a problem, so there's no need to verify thread safety of the code (including the Skia library). |
| 70 |
There's probably no fundamental reason why the code couldn't be made thread-safe. |
| 71 |
|
| 72 |
|
| 73 |
GrDirectContext sharing: |
| 74 |
======================== |
| 75 |
|
| 76 |
We use Skia's sk_app::WindowContext class for creating surfaces for windows, that class |
| 77 |
takes care of the internals. But of offscreen drawing, we need an instance of class |
| 78 |
GrDirectContext. There is sk_app::WindowContext::getGrDirectContext(), but each instance creates |
| 79 |
its own GrDirectContext, and apparently it does not work to mix them. Which means that |
| 80 |
for offscreen drawing we would need to know which window (and only that window) |
| 81 |
the contents will be eventually painted to, which is not possible (it may not even |
| 82 |
be known at the time). |
| 83 |
|
| 84 |
To solve this problem we patch sk_app::WindowContext to create just one GrDirectContext object |
| 85 |
and share it between instances. Additionally, using sk_app::WindowContext::SharedGrDirectContext |
| 86 |
it is possible to share it also for offscreen drawing, including keeping proper reference |
| 87 |
count. |