Commit Graph

91 Commits

Author SHA1 Message Date
Tyler Denniston
627c6d2569 [svg] Refactor <pattern> and gradient stop elements to new parsing
Change-Id: I1fb84760f7a657aefeb7e0af3758766daac2d0f9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367882
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-02-08 20:27:17 +00:00
Tyler Denniston
c683482e58 [svg] Refactor <polygon> and <polyline> to use new parsing
Change-Id: I7cc2dcce4a645326dcacadd28cbe1b3ea5f4ae36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367877
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-02-08 20:27:17 +00:00
Tyler Denniston
52d9475b05 [svg] Refactor several simple nodes to new parsing code
Refactored nodes are <circle>, <ellipse>, <rect>, <line>.

Change-Id: I955c6a01d6533e61a0c12f56f97040ae0b5ed879
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/366721
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-02-08 20:27:17 +00:00
Tyler Denniston
1f4cd07af8 [svg] Support preserveAspectRatio for images
https://www.w3.org/TR/SVG11/struct.html#ImageElement
https://www.w3.org/TR/SVG11/coords.html#PreserveAspectRatioAttribute

We already had a function to compute the appropriate matrix, and since
we can share the functionality with other elements that establish a new
viewport (including svg, symbol, and a few others), this CL moves the
function to the SVG node base class.

Relevant test for images is struct-image-06.

Bug: skia:10842
Change-Id: I5d6261210d03959e28d0bd7189da7f4ea53abc03
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/366398
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-02-05 15:59:10 +00:00
Tyler Denniston
8ca4626a4b [svg] Implement <image> element
https://www.w3.org/TR/SVG11/struct.html#ImageElement

Supported reference types are data and non-local URIs. Resource loading
requires a ResourceProvider to have been set on the render context.

Not handled in this CL:
- preserveAspectRatio support
- SVG reference types (i.e. '<image xlink:href="file.svg" ...')

Bug: skia:10842
Change-Id: Ieec7569f60516b01fc847f4160d0733b1e3a1cf5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/364576
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-02-02 22:36:05 +00:00
Tyler Denniston
209857c20f [svg] Parse data and non-local IRIs
Not currently used, but will be used for <image> support.

Change-Id: I3bbb79c88890100901a8b85734d3a4d86a618848
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/360605
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-02-02 03:46:59 +00:00
Florin Malita
24df67d04e Reland "[svg] Plumb a ResourceProvider"
This is a reland of dd29e20904

Original change's description:
> [svg] Plumb a ResourceProvider
>
> ... for image loading.
>
> Update the SVG tools to pass local/FS resource providers.
>
> Change-Id: I2c0e446047da87f177fde0f23b7ea1f0a856e808
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359996
> Commit-Queue: Florin Malita <fmalita@google.com>
> Reviewed-by: Tyler Denniston <tdenniston@google.com>

Change-Id: I28de60b299fc89f46b090812fc632105143fb6da
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/360607
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
2021-01-27 21:12:23 +00:00
Tyler Denniston
e71f547302 [svg] Expand SkSVGIRI type
This CL adds a type enum to SkSVGIRI that will eventually be used to
distinguish between local fragments ('#frag-id'), non-local fragments
('/path/to/file.png') and data URIs ('data:image/png;base64,...').

To do so required a bit of refactoring of other types that previously
treated IRIs as basic strings. There are no functional changes in this
CL.

Change-Id: I8bf426f77c0779890bce74d2d243c09617f024c8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/360601
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-27 21:05:41 +00:00
Florin Malita
64400d95d6 Revert "[svg] Plumb a ResourceProvider"
This reverts commit dd29e20904.

Reason for revert: breaking the G3 roll

Original change's description:
> [svg] Plumb a ResourceProvider
>
> ... for image loading.
>
> Update the SVG tools to pass local/FS resource providers.
>
> Change-Id: I2c0e446047da87f177fde0f23b7ea1f0a856e808
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359996
> Commit-Queue: Florin Malita <fmalita@google.com>
> Reviewed-by: Tyler Denniston <tdenniston@google.com>

TBR=fmalita@chromium.org,fmalita@google.com,tdenniston@google.com

Change-Id: If5f9673f9ff40dd5f8a8f9cf8f46a4342f29f31f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/360602
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2021-01-27 18:53:31 +00:00
Tyler Denniston
8eedcd2dea [svg] Partial implementation of feSpecularLighting
https://www.w3.org/TR/SVG11/filters.html#feSpecularLightingElement

Because a fair amount of functionality will be shared between
feSpecularLighting and feDiffuseLighting, this CL adds an intermediate
SkSVGFeLighting base class for common code.

The only light source type implemented in this CL is fePointLight, which
exercised by the filters-light-03 W3C test.

Bug: skia:10841
Change-Id: Icae26dedb1aae1cd25ba2db7c6468a243ebacbc5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359756
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-27 16:14:29 +00:00
Florin Malita
dd29e20904 [svg] Plumb a ResourceProvider
... for image loading.

Update the SVG tools to pass local/FS resource providers.

Change-Id: I2c0e446047da87f177fde0f23b7ea1f0a856e808
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359996
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-27 14:10:09 +00:00
Florin Malita
131decbf41 [svg] Fix node factories order
TBR=
Change-Id: I622581de30dd290b858fe99ece3ae85fd15a0c2f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359918
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Florin Malita <fmalita@google.com>
2021-01-26 23:14:23 +00:00
Tyler Denniston
32b3089618 [svg] Add light source classes and lighting-color pres attr
https://www.w3.org/TR/SVG11/filters.html#LightSourceDefinitions

The three classes represent light source elements that will eventually
be used for feSpecularLighting and feDiffuseLighting. Currently they are
unused.

Also added the (currently unused) lighting-color presentation attribute.

Bug: skia:10841
Change-Id: Ic7824671662b8cd88cf627affc54173d5e881b7d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359557
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-26 21:36:34 +00:00
Florin Malita
f661ec788b [svg] Text asPath() support
Enables use of text as a clip path.

Bug: skia:10840
Change-Id: I9de40e23696083e8cdd7e0b82221da3f3c36ac8b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358533
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2021-01-26 14:55:47 +00:00
Florin Malita
f9652245b4 [svg] Text object bounding box support
Implement onObjectBoundingBox() for SkSVGText.

Enables use of objectBoundingBox filters effects on text.

Bug: skia:10840
Change-Id: I84ab3df04683cb23073ba9ddc531abe4e5788e5e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358476
Commit-Queue: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-25 21:37:59 +00:00
Tyler Denniston
f005c8a30b [svg] Implement feDisplacementMap
https://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement

Bug: skia:10841
Change-Id: Icf1a560b2d83e7954207fb1740e77193362b9fd4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356312
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-25 21:12:01 +00:00
Tyler Denniston
7aea2ae902 [svg] Fix non-xy length scale factor
We were miscalculating percentage lengths that do not correspond to the
x or y axis. Spec:

https://www.w3.org/TR/SVG11/coords.html#Units_viewport_percentage

Change-Id: I5c02e101f3bf7f1f93be3e8718290f490638f9b8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357279
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-25 17:12:46 +00:00
Florin Malita
c55c8c1e8e [svg] Generalize text shaping
In preparation for text bounding box support, fission the actual
rendering phase from the shaping/alignment phase:

  - rename onRenderText -> onShapeText
  - introduce a ShapedTextCallback abstraction for consuming the result
    of text processing
  - relocate the final rendering step to a ShapedTextCallback impl

Bug: skia:10840
Change-Id: Ia8cc0d9a5a5484972a34042fd782f9e4fada6b12
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358223
Commit-Queue: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-25 16:40:16 +00:00
Tyler Denniston
bd91660b6e [svg] Handle unspecified filter effect inputs
Per spec [1], unspecified inputs ('in', 'in2' attributes) have different
meaning depending on whether the referencing filter is the first in the
pipeline. This CL adds previous result tracking to the filter context
and handles unspecified values accordingly during input resolution.

[1] https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveInAttribute

Bug: skia:10841
Change-Id: I64618ad712979f6dd62adb4686085fe31618c3cb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357278
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-25 15:18:16 +00:00
Florin Malita
302ea2e03c [svg] Cleanup text content model rules
Per spec (and empirically) <text> elements are not nestable (neither
directly or indirectly):
https://www.w3.org/TR/SVG11/intro.html#TermTextContentChildElement

Update the implementation to

 - only bridge onRender -> onRenderText in the root SkSVGText
   implementation
 - disallow <text> elements as text container descendants

Change-Id: I07b3abaf943b820e01c88f78bddf7ce5970ee508
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358220
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-25 14:49:16 +00:00
Tyler Denniston
8a37fb2c60 [svg] Implement SourceAlpha input for filter effects
https://www.w3.org/TR/SVG11/filters.html#SourceAlpha

This is the last "trivial" filter input type.

Bug: skia:10841
Change-Id: I96a7c9ccd318dec3b2b3ddd656be714b6b8fc59e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356838
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-21 19:34:39 +00:00
Tyler Denniston
c7e482441e [svg] Several filter helper tweaks
- Allow resolving inputs without modifying their colorspace
- Add helper to get the colorspace of a particular input
- Make resolveColorspace() virtual and add filter context to its
  signature

Bug: skia:10841
Change-Id: I2e226ec26205f527c2d171140072f106ec35fbe0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356416
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-21 19:23:39 +00:00
Florin Malita
cdeabcaf57 [svg] Fix handling of root element position attributes
Per https://www.w3.org/TR/SVG11/struct.html#SVGElementXAttribute,
x/y have "no meaning or effect on outermost svg elements".

Change-Id: I028e3a4a1d91735d849e32874ae99d609fae4aaf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356308
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-20 19:13:17 +00:00
Tyler Denniston
4c89481be4 [svg] Implement feMorphology filter
https://www.w3.org/TR/SVG11/filters.html#feMorphologyElement

Bug: skia:10841
Change-Id: I0b0028fb815c490670f9f1e888770efb194a8f3b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356107
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-20 16:13:56 +00:00
Florin Malita
ea27de5cb7 [svg] Cleanup: use FP alpha for opacity
Update general opacity and stop-opacity to use float alpha.

Change-Id: I496b2d41d77c0123ea2a2e1f8f8e4b1377a98abc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355627
Auto-Submit: Florin Malita <fmalita@chromium.org>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2021-01-19 19:22:49 +00:00
Florin Malita
bde06cc511 [svg] Cleanup: drop the presentation attribute SkPaint cache
Instead of attempting to keep fill & stroke SkPaints synchronized with
the current presentation attributes throughout the DAG walk, build the
SkPaints on the fly, only when needed.

This simplifies presentation attribute handling and enables further
/future refactoring.

Change-Id: I3791b4244530644e7e4b983d93b3c966ea7a1b22
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355096
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-19 15:58:55 +00:00
Florin Malita
d414e600b2 [svg] Property inheritance workaround
Property inheritance is supposed to follow the tree hierarchy, but we
implement it based on the render path.

One nasty side effect is when resolving IRI paint servers
(gradients, patterns), the referencing node properties get inherited
(leak) into the paint server fragment.  E.g.

  <pattern id="pat">
    <rect fill="green"/>
  </pattern>

  <rect stroke="blue" fill="url(#pat)" stroke="blue"/>

The pattern subtree incorrectly inherits a blue stroke property from
the referencing node when we resolve the fill.

As a temporary (and imperfect) workaround, we can reset the presentation
context when resolving IRI paint servers.

Change-Id: Ia4a8a6199222820661f805c43340b5e16902feff
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354668
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2021-01-15 22:19:16 +00:00
Tyler Denniston
a25e1a38dd [svg] Implement feBlend filter
Note we are still not passing filters-blend-01-b because we don't yet
support feImage.

Bug: skia:10841
Change-Id: Ibca52c0e8e8d45e73473dea3b0252d6b81eaa584
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354657
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-15 19:45:56 +00:00
Tyler Denniston
a22d21e447 [svg] Fix incorrect optimization for opacity layer
When both filter and opacity attributes are set on a leaf node, the
opacity must be applied as a separate layer so that the results of the
filter are modified by the opacity. Previously in this circumstance we
were incorrectly applying the opacity to the paints only (without a
layer).

To illustrate:

<svg viewBox="0 0 1000 500" version="1.1"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <filter id="Green" x="0%" y="0%" width="100%" height="100%">
      <feFlood flood-color="lime" flood-opacity="1" />
    </filter>
  </defs>
  <rect x="30" y="20" width="400" height="100" fill="red" opacity="0.1"
        filter="url(#Green)"/>
  <g filter="url(#Green)">
    <rect x="30" y="200" width="400" height="100" fill="red" opacity="0.1"/>
  </g>
</svg>

The two rects should render differently. In the <g> case, the filter
output (opaque green) overrides the translucent red pixels of the rect.
In the <rect> case, the filter output overrides the translucent red
pixels with opaque green, but then is modified by the opacity on the
<rect>.

Relevant W3C test is filters-blend-01-b (and possibly others).

Change-Id: I165eed36c546f1f99457865cee58ee2b3bffe6f1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354879
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-15 18:55:16 +00:00
Florin Malita
b2aa04d184 [svg] Minor cleanup
Replace a bunch of no-op stubs with a default template impl.

Change-Id: I37b24361dcf3d7c247a12a7c20a9f3a967b6f9e6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354877
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Auto-Submit: Florin Malita <fmalita@chromium.org>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-15 17:32:16 +00:00
Florin Malita
73d57bf4e8 [svg] Add support for mask color-interpolation
https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperty

Bug: skia:10842
Change-Id: I3e97577ee257c9afe64d924c768c85badbfab07d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354220
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-15 15:19:40 +00:00
Tyler Denniston
5878ecef2f [svg] Implement feOffset filter
https://www.w3.org/TR/SVG11/filters.html#feOffsetElement

We should now be passing filters-felem-02-f W3C test.

Bug: skia:10841
Change-Id: I642cf3c8816b83bdf88066c55103e432ae9c9d5a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354216
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-15 15:04:30 +00:00
Florin Malita
cf1e2f3d9b [svg] Fix mask edge artifacts
Per spec, the explicit <mask> bounds [x,y,w,h] are used to also clip
the content (the actual mask geometry may extend beyond these bounds).

This clip is currently scoped such that it applies both to the mask
layer and the content layer.  When the clip is not pixel-aligned,
we're anti-aliasing both layers' edges -- which darkens the composition
result (producing dark hairlines around the mask).

Push the clip down such that it applies to content only.

Change-Id: I32169e2b6dc9685e50a51c6b22cfaaac1a897239
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354217
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-15 14:31:50 +00:00
Tyler Denniston
94730febf9 [svg] Handle std input case for filter subregion calculation
From the spec [1], if any inputs of a filter are one of the standard
inputs (SourceGraphic, FillPaint, etc. -- anything except another
filter), then the default filter primitive subregion is equal to the
filter effect region.

[1] https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion

Bug: skia:10841
Change-Id: I70632e5119861c46c9e48af944d2c7cfdfc3c351
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354119
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-14 22:04:48 +00:00
Tyler Denniston
3df6c20a05 [svg] Fix <use> bounds calculation
Previously we were using fX and fY as the top left of the returned
bounds. We need instead to offset the referenced node's bounds by fX,
fY.

While I was here I updated the attribute parsing to the new form and
changed the type of fHref from SkSVGString to SkSVGIRI.

Change-Id: I4bfb91bca62e47f5dabfbb4aad48cbb301a7ea36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/354118
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-14 21:35:58 +00:00
Florin Malita
3c10618d37 [svg] Add clipPathUnits support
https://www.w3.org/TR/SVG11/masking.html#ClipPathElementClipPathUnitsAttribute

Bug: skia:10842
Change-Id: Idf3b5b6da08dfaee165f0bbb549427f298a40cec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353713
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-14 20:18:15 +00:00
Florin Malita
4ea46b71ac [svg] Fix null text context crash
The input may contain invalid text constructs lacking a root <text> node
e.g.  <svg><tspan>foo</tspan></svg>

Since we don't perform content model validation at the moment and text
contexts are only instantiated for root nodes, we must guard against
this case at render time.

Bug: oss-fuzz:29558
Change-Id: I7e39c1c4048900ce5becb3549802dc66bb1d242b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353711
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-14 19:03:25 +00:00
Florin Malita
491911003e [svg] Mask support
https://www.w3.org/TR/SVG11/masking.html#Masking

Implement masking based on a classic two-layers + kSrcIn blending
approach.

An additional layer is used to filter the mask content (but could be
avoided in a pinch -- see inline comments).

Also consolidate the objectBoundingBox rect resolution logic as
SkSVGRenderContext::resolveOBBRect().

Bug: skia:10842
Change-Id: I273318e97cc28d599d1ecf01706b6117eecb62d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353631
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-14 18:50:46 +00:00
Tyler Denniston
8f78d55284 Reland "[svg] Perform colorspace conversions for filter effects"
This reverts commit 36acb7b10c.

Reason for revert: artifacts in 1010102 are expected

Original change's description:
> Revert "[svg] Perform colorspace conversions for filter effects"
>
> This reverts commit a0880eda22.
>
> Reason for revert: visual artifacts in 10-bit color depth (10-10-10-2)
>
> Original change's description:
> > [svg] Perform colorspace conversions for filter effects
> >
> > A filter effect can optionally be specified to operate in either sRGB
> > or linearRGB, according to the SVG spec:
> >
> > https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
> >
> > This CL adds any necessary conversion steps (SkColorFilters) while
> > constructing the filter DAG. The default filter effect color space is
> > linearRGB. We should now be passing the filters-gauss-* W3C tests.
> >
> > Specific changes:
> > - Tag filter effect results with their colorspace when storing them in
> >   the filter context map
> > - Add an SkColorFolor conversion step as necessary when resolving filter
> >   effect inputs
> >
> > Bug: skia:10841
> > Change-Id: Ide12698ea64c4d40f09df93a60718788809086fa
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353078
> > Commit-Queue: Tyler Denniston <tdenniston@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
>
> TBR=fmalita@chromium.org,tdenniston@google.com
>
> Change-Id: Id4a33c49643039cfb2d2867a1513e8ee1d7b181a
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:10841
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353630
> Reviewed-by: John Stiles <johnstiles@google.com>
> Commit-Queue: John Stiles <johnstiles@google.com>

TBR=fmalita@chromium.org,tdenniston@google.com,johnstiles@google.com

# Not skipping CQ checks because this is a reland.

Bug: skia:10841
Change-Id: Id6d9e01d9b18ebfb6f9a6cb74518ad5cd73ea00a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353777
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-14 15:02:23 +00:00
John Stiles
36acb7b10c Revert "[svg] Perform colorspace conversions for filter effects"
This reverts commit a0880eda22.

Reason for revert: visual artifacts in 10-bit color depth (10-10-10-2)

Original change's description:
> [svg] Perform colorspace conversions for filter effects
>
> A filter effect can optionally be specified to operate in either sRGB
> or linearRGB, according to the SVG spec:
>
> https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
>
> This CL adds any necessary conversion steps (SkColorFilters) while
> constructing the filter DAG. The default filter effect color space is
> linearRGB. We should now be passing the filters-gauss-* W3C tests.
>
> Specific changes:
> - Tag filter effect results with their colorspace when storing them in
>   the filter context map
> - Add an SkColorFolor conversion step as necessary when resolving filter
>   effect inputs
>
> Bug: skia:10841
> Change-Id: Ide12698ea64c4d40f09df93a60718788809086fa
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353078
> Commit-Queue: Tyler Denniston <tdenniston@google.com>
> Reviewed-by: Florin Malita <fmalita@chromium.org>

TBR=fmalita@chromium.org,tdenniston@google.com

Change-Id: Id4a33c49643039cfb2d2867a1513e8ee1d7b181a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10841
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353630
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-01-13 22:57:16 +00:00
Tyler Denniston
a0880eda22 [svg] Perform colorspace conversions for filter effects
A filter effect can optionally be specified to operate in either sRGB
or linearRGB, according to the SVG spec:

https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties

This CL adds any necessary conversion steps (SkColorFilters) while
constructing the filter DAG. The default filter effect color space is
linearRGB. We should now be passing the filters-gauss-* W3C tests.

Specific changes:
- Tag filter effect results with their colorspace when storing them in
  the filter context map
- Add an SkColorFolor conversion step as necessary when resolving filter
  effect inputs

Bug: skia:10841
Change-Id: Ide12698ea64c4d40f09df93a60718788809086fa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353078
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-13 22:15:26 +00:00
Tyler Denniston
7bb85dbb5e [svg] Add plumbing for color-interpolation-filters property
The default colorspace for filter effects is linear RGB, as specified in
https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties.
Currently we perform all filtering in the destination colorspace. This
CL adds the new presentation attribute with the default setting
(according to the spec) of linear RGB.

This CL does not actually implement any colorspace transformations for
filters.

Bug: skia:10841
Change-Id: Id778ad3fa5cb6e0aed756584a50880edd9d82e2b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352738
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-13 18:07:14 +00:00
Florin Malita
836c2ca6a1 [svg] Initial mask plumbing
Introduce SkSVGMask and plumb related attributes.

Also consolidate the clip/mask/filter property types - they all support
the same values: <funciri>|none|inherit.

Bug: skia:10842
Change-Id: If45a75cccc19b84d6547237336fe5d562a85d594
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353436
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-13 17:23:24 +00:00
Florin Malita
fc0ea0a4a5 [svg] TextPath support
- introduce SkSVGTextPath and update the text render logic to
    instantiate new SkSVGTextContexts in onRenderText() overrides
    instead of renderText() root -- this is to observe spec semantics
    [1] requiring <text> and <textPath> to always start a new chunk,
    regardless of their relative nesting.
  - expand SkSVGTextContext to also store PathData when used in the
    scope of a textPath
  - PathData caches SkContourMeasures, for path position lookup
  - update flushChunk() to apply path glyph adjustments [2]:

    * the horizontal glyph position (including relative offset dx),
      adjusted for the glyph center yields a path offset
    * if the offset is outside the path range, the glyph is skipped
    * otherwise the position is determined based on the path matrix
      at the computed offset

   - to support the logic above, the chunk starting position is no
     longer used as a global blob offset but instead is folded into
     individual glyph RSXforms (and the blob always draws at {0,0})

[1] https://www.w3.org/TR/SVG11/text.html#TextLayout
[2] https://www.w3.org/TR/SVG11/text.html#TextpathLayoutRules

Bug: skia:10840
Change-Id: I462eada7c086646afdc1bc84f08ec2368613f1c0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/349397
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-13 14:37:39 +00:00
Tyler Denniston
187d8117cb [svg] Implement feGaussianBlur
This filter implementation should be complete, but note we are still
not quite passing the W3C filters-gauss-* tests because our filters
currently operate in sRGB and not linear RGB (which is quite noticable
in some of the blur tests).

Bug: skia:10841
Change-Id: I706cde879ef6eb47ce586279999536cf67237f13
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352506
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-12 16:26:16 +00:00
Tyler Denniston
3a92f776b0 [svg] Implement onObjectBoundingBox for circle and path
Also removed an erroneous call to mapToRect() when returning bounds
for SkSVGContainer. The contexts in which we access object bounds are
always such that any transforms have already been applied.

Change-Id: Ieac488e1699d3ebff56038d6ada36737291671eb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345117
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2021-01-12 15:05:16 +00:00
Tyler Denniston
0a145b77f7 [svg] Compute and use filter primitive subregion
Spec: https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion

The filter primitive subregion restricts the output of a specific <fe*>
node in a filter DAG. By default it's equal to the union of subregions
of all input filters, or the filter region if no inputs exist. If
x/y/w/h are specified on the <fe*> node, those are used to bound the
primitive subregion instead.

In this CL:
- Implement the computation of the primitive subregion in
  SkSVGFe::resolveFilterSubregion
- Add primitiveUnits to filter context
- Change result registration (by string ID) in filter context to include
  the primitive subregion of that result. This is needed because filters
  referencing previous results need access to those primitive subregions
  to compute the union.

Bug: skia:10841
Change-Id: I66fbb4979e3c65cb5e5cc61f98286ec7ad023438
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/344666
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-11 17:42:57 +00:00
Florin Malita
736c992966 [svg] Deferred text position adjustments
Upcoming textPath changes require position adjustments (relative offset,
rotation) to be applied after mapping to path, at chunk flush time.

Bug: skia:10840
Change-Id: Ifccea2983d5d5c57876d0a25e1da113e4c9cd51a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350018
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-05 21:52:25 +00:00
Florin Malita
2d059fcc22 [svg] Text rotate support
Implement support for text 'rotate' attribute:
https://www.w3.org/TR/SVG11/text.html#TSpanElementRotateAttribute.

Unlike other character-positioning attributes (x/y/dx/dy), rotate

  - is not cumulative
  - only applies to its respective node scope (does not affect other
    fragments in the current chunk)
  - has different padding semantics: if there are fewer rotate
    values than characters, the remaining characters use the last
    specified value from the closest ancestor

To the last point, we now have to discriminate three states:

  - unspecified (default -> 0)
  - explicit value for the given character index
  - implicit value (last value in the closest ancestor)

Local implicit values override implicit ancestor values -- but not
explicit ancestor values.

High level changes:

  - plumb 'rotate' attribute
  - expand per-character position info (ShapeBuffer) to include rotation
  - expand per-glyph position info (RunRec) to include rotation
  - expand PosAttrs to include rotation and add specific inheritance
    rules (see above)
  - pass computed rotation values to RSX blob buffers

Bug: skia:10840
Change-Id: Ia19ec5e8bb6fea06d49a9bd72ace575c2ffd100e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348877
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
2021-01-05 17:43:51 +00:00
Florin Malita
e5a2171d6e [svg] Convert text rendering to RSX form
In preparation of per-character rotation support, switch to RSX text
blobs.

TBR=
Bug: skia:10840
Change-Id: Ia7de0983d1445e61e97caae9404d472cc3736730
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348880
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
2020-12-30 17:13:07 +00:00