adobe / svg-native-viewer

SVG Native viewer is a library that parses and renders SVG Native documents
Apache License 2.0
155 stars 37 forks source link

fix skia call to saveLayerAlpha #158

Closed moazin closed 2 years ago

moazin commented 3 years ago

This fixes #154 partially. I've done the Skia fix.

@dirkschulze For cairo, you pointed out that they have APIs for transparency layers. Could you point them to me, I couldn't find something simple.

moazin commented 3 years ago

@dirkschulze This looks good, however, the problem still persists in Cairo. I can do the same nested mOpacityStack thing that I did in GDI+. You mentioned that there's an equivalent call to saveLayerAlpha for Cairo, but I couldn't find it. Can you point to it? If one doesn't exist, I can do the same for Cairo as I did it for GDI+.

dirkschulze commented 3 years ago

@moazin You can use

cairo_push_group(cr);
// put cr on a stack so you can call cairo_push_group multiple times
// to create more layers. Needed for nested opacity.

to create a new layer and then draw it back with

cairo_pop_group_to_source(cr);
cairo_paint_with_alpha(cr, crFromTopOfStack);

You can take a look at the WebKit code I wrote years ago: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp#L1198