Commit Graph

119 Commits

Author SHA1 Message Date
Lee Salzman
defc1793b9 Bug 1777849 - Don't attempt to recreate DrawTargetWebgl's SharedContext again if WebGL initialization fails. r=ahale
If the user does not actually support WebGL 2, attempting to create a DrawTargetWebgl will always fail.
However, each time it goes to create a DrawTargetWebgl, it will try to initialize a WebGL 2 context again.
Each time it does this, if the user is using GLX, it will call XCreatePixmap and glXCreateContextAttribs,
which can run afoul of a libX11 race condition. This will happen on every page load where a new canvas is
encountered.

It would be better to note that the failure is non-recoverable and not try to use DrawTargetWebgl on
subsequent attempts. Here we set the sContextInitError value to indicate there are non-recoverable
errors, after which it will bypass attempting creation the next time.

This means the worst exposure the user will have to the libX11 race condition is once per process lifetime,
which should greatly reduce the incidence.

Differential Revision: https://phabricator.services.mozilla.com/D171016
2023-02-26 07:20:19 +00:00
Lee Salzman
f9b677c590 Bug 1817873 - Use line join for closed single line paths. r=aosmond
If we choose to accelerate a single line path, we need to take care not to use
the line cap when the path is closed. When the path is closed, we need to use
the line join instead.

Differential Revision: https://phabricator.services.mozilla.com/D170469
2023-02-21 18:03:37 +00:00
Lee Salzman
809ea4c52b Bug 1817455 - Limit rect precision to avoid shader rounding diverging from path fallback. r=gfx-reviewers,aosmond
Rectangle with large floating-point values can start to lose mantissa bits when transformed directly
by the vertex shader, pushed through the viewport transform, and then clipped later. OTOH, the path
fallback (WGR/AA-Stroke or Skia) does not stress floating-point precision as much, so generally
returns more correct results in these cases. This becomes noticeable when the same rectangle is
filled and then subsequently stroked, since the fill may use the rect shader, while the the stroke
will fall back to using a path.

To avoid hitting this issue, this checks if a rect's coordinate are outside as certain reasonable
limit, and if so, falls back to relying on path geometry to handle transform and clipping safely.
If within the limit, the shader precision loss doesn't noticeably impact the results so it is still
safe to use the fast-path.

Differential Revision: https://phabricator.services.mozilla.com/D170270
2023-02-20 21:30:08 +00:00
Jeff Muizelaar
1280a5a7ef Bug 1813774 - Actually hook up rasterization truncation support. r=lsalzman
I think this got blown away after my previous session debugging
why it didn't work.

Differential Revision: https://phabricator.services.mozilla.com/D168308
2023-01-31 14:38:03 +00:00
Lee Salzman
d243580bc7 Bug 1812970 - Avoid using Skia's deprecated clip ops. r=jrmuizel
Skia upstream removed deprecated clip ops that could be used to replace
the clipping stack and bypass clips. We shouldn't really need to do this
anymore, as we can work around it just using public APIs.

The only SkCanvas operation that allows us to bypass clipping is
writePixels, which still allows us to implement CopySurface/putImageData.

Other instances where we were using the replace op for DrawTargetWebgl
layering support can just be worked around by creating a separate
DrawTargetSkia pointing to the same pixel data, but on which no clipping
or transforms are applied so that we can freely do drawing operations
on it to the base layer pixel data regardless of any user-applied clipping.

Differential Revision: https://phabricator.services.mozilla.com/D168039
2023-01-28 11:24:54 +00:00
Jeff Muizelaar
57a1004505 Bug 1803375. Use different coordinates when running on AMD. r=lsalzman,jgilbert
This updates the version wpf-gpu-raster which adds support for
GPUs/drivers that use truncation instead of rounding when converting
vertices to fixed point.

It also adds the GL vendor to InitContextResult so that we can detect
AMD on macOS and tell wpf-gpu-raster that truncation is going to happen.

Differential Revision: https://phabricator.services.mozilla.com/D167503
2023-01-27 01:45:17 +00:00
Lee Salzman
70ba777d1a Bug 1806392 - Add a debug indicator for Accelerated Canvas2D. r=aosmond
This adds a debug indicator controlled by the pref gfx.canvas.accelerated.debug.
A green square is drawn in the upper right corner of the canvas to let us know if
acceleration is being used or not.

Differential Revision: https://phabricator.services.mozilla.com/D165018
2022-12-19 13:59:14 +00:00
Lee Salzman
53ada74867 Bug 1806058 - Add blocklist for Accelerated Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D164881
2022-12-16 20:15:49 +00:00
Lee Salzman
940e74869b Bug 1805231 - Handle zero-length capped lines. r=aosmond
Avoid causing a divide-by-zero when a stroked line is zero-length and only the cap is rendered.

Differential Revision: https://phabricator.services.mozilla.com/D164536
2022-12-13 18:43:06 +00:00
Lee Salzman
1dd5ff25d5 Bug 1752841 - Add ExtractSubrect API to SourceSurface. r=jrmuizel
CanvasRenderingContext2D relies upon CreateSimilarDrawTarget to create extract
a subrect from a surface to draw. However, DrawTargetWebgl does not return an
accelerated DT for that API as creating an entirely new context can be quite
expensive.

To work around this, this adds a specific ExtractSubrect API for SourceSurface
that can bypass the entire need to create a temporary DrawTarget to copy into.

Differential Revision: https://phabricator.services.mozilla.com/D164118
2022-12-07 21:06:32 +00:00
Lee Salzman
489c98bb18 Bug 1804340 - Generate path vertexes into pre-allocated output buffer. r=jrmuizel
This pre-allocates a vertex output buffer in DrawTargetWebgl so that we can generate
wpf-gpu-raster and aa-stroke output into it. This way, they don't have to realloc
a Vec for pushes or changing into a boxed slice. This can net 5-10% on profiles for
the demos noted in the bug.

Depends on D163989

Differential Revision: https://phabricator.services.mozilla.com/D163990
2022-12-07 00:53:55 +00:00
Lee Salzman
fc0208ec9c Bug 1803843 - Improve path cache reuse in DrawTargetWebgl. r=jrmuizel
This increases the amount of quantization applied to path cache entries
to 0.25 increments (2 bits of subpixel precision), leading to 4x4=16
subpixel buckets in total along both axes.

Differential Revision: https://phabricator.services.mozilla.com/D163749
2022-12-03 08:47:24 +00:00
Lee Salzman
8e69c8b8ca Bug 1803604 - Use aa-stroke to accelerate stroked paths in Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D163609
2022-12-03 08:21:50 +00:00
Cosmin Sabou
83bb7f69c7 Backed out 2 changesets (bug 1803604) for causing talos crashes on pdfpaint.
Backed out changeset 0be171a7d6ac (bug 1803604)
Backed out changeset 9c9e6c4e7864 (bug 1803604)
2022-12-03 02:59:04 +02:00
Lee Salzman
8f780c31c9 Bug 1803604 - Use aa-stroke to accelerate stroked paths in Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D163609
2022-12-02 19:49:38 +00:00
Lee Salzman
70d581c04f Bug 1802625 - Allow strokes to be cached as textures even when GPU stroking is off. r=jrmuizel
This fixes an incidental bug with the pref to turn off GPU stroking. It's not supposed to disable
caching strokes as textures. This allows that to work again even if prefed off.

Differential Revision: https://phabricator.services.mozilla.com/D163307
2022-11-29 20:26:41 +00:00
Lee Salzman
7e9ef6f378 Bug 1802625 - Hide GPU path stroking behind a pref. r=jrmuizel
It seems like this is slow for now until we implement a better way than WPF-gpu-raster
for stroking paths. Just hide this behind a pref so we can at least test it but not
impact performance as badly.

Differential Revision: https://phabricator.services.mozilla.com/D163248
2022-11-28 20:31:02 +00:00
Lee Salzman
61d16aa3be Bug 1801539 - Attempt to cache the state of the clip mask for when mask is regenerated. r=aosmond
For use-cases that repeatedly pop and re-push the same clips over and over, we can regenerate the
same mask that is already still stored, because we only detect that clip state changed, rather than
that it changed to exactly the same state it was previously.

This just remembers the previous state of the clip stack at the time the clip mask was generated
so that we can compare the previous and current state. If they're the same, we can assume there
is no need to regenerate the clip mask again and simply reuse it.

Differential Revision: https://phabricator.services.mozilla.com/D162699
2022-11-28 17:55:07 +00:00
Lee Salzman
6964f87eaf Bug 1801584 - Avoid relying on WebGL line smoothing. r=jrmuizel
WebGL doesn't reliably implement line smoothing, so we can't rely on it, making it
useless for canvas lines. Instead, just fall back to emulating it manually with paths.

Differential Revision: https://phabricator.services.mozilla.com/D162540
2022-11-28 17:54:44 +00:00
Lee Salzman
18e352a611 Bug 1801588 - Ensure region outside mask but inside clip is cleared for copy op. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D162536
2022-11-28 17:54:29 +00:00
Lee Salzman
d2518aee80 Bug 1801548 - Ignore round cap-style for sufficiently thin lines. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D162498
2022-11-28 17:54:14 +00:00
Lee Salzman
2b59df83a4 Bug 1801446 - Limit the maximum complexity of paths used with wpf-gpu-raster. r=jrmuizel
Some paths may contain so many types that their vertex representation far exceeds their
software rasterized representation in memory size. As a sanity-check, we should just set
a hard limit on the maximum allowed complexity of a path that we attempt to supply to
wpf-gpu-raster. Beyond that, we will instead just rasterize in software and upload
to a texture which can be more performant.

Differential Revision: https://phabricator.services.mozilla.com/D162481
2022-11-22 05:25:59 +00:00
Lee Salzman
44cc796509 Bug 1800826 - Remove all clips when reusing a target in Canvas2D. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D162237
2022-11-17 03:10:35 +00:00
Lee Salzman
56e89ddb81 Bug 1800581 - Use optimized snapshots for drawImage if canvases share internal context. r=aosmond
By default, BorrowSnapshot is pessimistic and forces DrawTargetWebgl to return a data snapshot on
the assumption that the snapshot might be used off thread. However, if we actually know the DrawTarget
we're going to be drawing the snapshot to, then we can check if they're both DrawTargetWebgls with
the same internal SharedContext. In that case, we can use a SourceSurfaceWebgl snapshot which can
pass through a GPU texture to the target. This requires us to plumb the DrawTarget down through
SurfaceFromElement all the way to DrawTargetWebgl to make this decision.

Differential Revision: https://phabricator.services.mozilla.com/D162176
2022-11-17 03:07:18 +00:00
Lee Salzman
954f87098c Bug 1799402 - Use WGR to rasterize paths in DrawTargetWebgl. r=jrmuizel
This adds a path vertex buffer where triangle list output from WGR is stored.
Each PathCacheEntry can potentially reference a range of vertexes in this buffer
corresponding to triangles for that entry. When this buffer is full, it gets
orphaned and clears corresponding cache entries, so that it can start anew.

Differential Revision: https://phabricator.services.mozilla.com/D161479
2022-11-12 08:06:44 +00:00
Iulian Moraru
f876a9fbe3 Backed out 3 changesets (bug 1799402) for causing windows build bustages. CLOSED TREE
Backed out changeset e51cd76008ef (bug 1799402)
Backed out changeset 3ff660b475ff (bug 1799402)
Backed out changeset 9cfa7581565e (bug 1799402)
2022-11-12 08:33:24 +02:00
Lee Salzman
d603ff9f26 Bug 1799402 - Use WGR to rasterize paths in DrawTargetWebgl. r=jrmuizel
This adds a path vertex buffer where triangle list output from WGR is stored.
Each PathCacheEntry can potentially reference a range of vertexes in this buffer
corresponding to triangles for that entry. When this buffer is full, it gets
orphaned and clears corresponding cache entries, so that it can start anew.

Differential Revision: https://phabricator.services.mozilla.com/D161479
2022-11-12 05:42:30 +00:00
Lee Salzman
35c8c81b94 Bug 1799495 - Ensure WaitForShmem has a valid DrawTargetWebgl to access. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D161554
2022-11-08 16:23:56 +00:00
Razvan Cojocaru
363946e17f Bug 1060421 - Change the type of [Int]PointTyped::[x|y] back to [Int]CoordTyped. r=botond
[Int]CoordTyped no longer inherits Units because otherwise
instances of [Int]IntPointTyped may get one Base subobject because
it inherits Units, and others because of BasePoint's Coord members,
which end up increasing the [Int]CoordTyped's objects size (since
according to the ISO C++ standard, different Base subobject are
required to have different addresses).

Differential Revision: https://phabricator.services.mozilla.com/D160713
2022-11-04 18:29:35 +00:00
Lee Salzman
8edfa8e4f9 Bug 1793887 - Limit the size of stroked path uploads. r=aosmond
If we have stroked paths whose bounds cover a lot of screen area, that can lead
to a lot of empty area in the interior that bloats the path cache textures up
with unused pixels that still need to be uploaded. Try to avoid this by not
trying to accelerate paths with the path cache that take up a large amount
of screen area.

Differential Revision: https://phabricator.services.mozilla.com/D160023
2022-10-25 17:46:22 +00:00
Lee Salzman
0f0f627527 Bug 1797099 - Ensure the SurfacePattern transform is invertible. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D160091
2022-10-25 17:42:05 +00:00
Lee Salzman
3802824293 Bug 1793769 - Avoid recreating the main DrawTargetWebgl SharedContext. r=aosmond
For canvas users that rapidly create and destroy canvases, we may end up creating
a new SharedContext (and hence ClientWebGLContext) if there are no more canvases
left between destruction and creation. To work around this, just keep alive the
SharedContext for the main thread (other threads are unfortunately a bit tricky
to support) so that canvas creation remains fast in this instance.

Differential Revision: https://phabricator.services.mozilla.com/D158904
2022-10-14 20:06:20 +00:00
Lee Salzman
bb8e0fa721 Bug 1793769 - Avoid trying to create DrawTargetWebgl if shader compilation failed. r=aosmond
If we fail to compile DrawTargetWebgl's shaders, we bail out to a normal software canvas.
However, it will still try to create a DrawTargetWebgl every time we need to create a canvas.
To avoid this, remember if shader compilation failed in the process, and don't try to create
an accelerated canvas again in that case.

Differential Revision: https://phabricator.services.mozilla.com/D158903
2022-10-14 20:06:20 +00:00
Norisz Fay
9a400a5c8d Backed out 2 changesets (bug 1793769) for causing multiple WebGL related failures CLOSED TREE
Backed out changeset f824c70961a7 (bug 1793769)
Backed out changeset 01a92b6503fe (bug 1793769)
2022-10-14 22:33:11 +03:00
Lee Salzman
a868992f5b Bug 1793769 - Avoid recreating the main DrawTargetWebgl SharedContext. r=aosmond
For canvas users that rapidly create and destroy canvases, we may end up creating
a new SharedContext (and hence ClientWebGLContext) if there are no more canvases
left between destruction and creation. To work around this, just keep alive the
SharedContext for the main thread (other threads are unfortunately a bit tricky
to support) so that canvas creation remains fast in this instance.

Differential Revision: https://phabricator.services.mozilla.com/D158904
2022-10-14 18:26:23 +00:00
Lee Salzman
238488d87b Bug 1793769 - Avoid trying to create DrawTargetWebgl if shader compilation failed. r=aosmond
If we fail to compile DrawTargetWebgl's shaders, we bail out to a normal software canvas.
However, it will still try to create a DrawTargetWebgl every time we need to create a canvas.
To avoid this, remember if shader compilation failed in the process, and don't try to create
an accelerated canvas again in that case.

Differential Revision: https://phabricator.services.mozilla.com/D158903
2022-10-14 18:26:22 +00:00
Sandor Molnar
bd73e3f17e Backed out 2 changesets (bug 1793769) for causing crashes in @ std::_Hashtable<unsigned int, std::pair<unsigned int const, RefPtr<mozilla::WebGLTextureJS> CLOSED TREE
Backed out changeset 6387a6e7bbd5 (bug 1793769)
Backed out changeset 0737cb829b7e (bug 1793769)
2022-10-13 20:34:00 +03:00
Lee Salzman
d937394c27 Bug 1793769 - Avoid recreating the main DrawTargetWebgl SharedContext. r=aosmond
For canvas users that rapidly create and destroy canvases, we may end up creating
a new SharedContext (and hence ClientWebGLContext) if there are no more canvases
left between destruction and creation. To work around this, just keep alive the
SharedContext for the main thread (other threads are unfortunately a bit tricky
to support) so that canvas creation remains fast in this instance.

Depends on D158903

Differential Revision: https://phabricator.services.mozilla.com/D158904
2022-10-13 16:44:24 +00:00
Lee Salzman
83f70779e1 Bug 1793769 - Avoid trying to create DrawTargetWebgl if shader compilation failed. r=aosmond
If we fail to compile DrawTargetWebgl's shaders, we bail out to a normal software canvas.
However, it will still try to create a DrawTargetWebgl every time we need to create a canvas.
To avoid this, remember if shader compilation failed in the process, and don't try to create
an accelerated canvas again in that case.

Differential Revision: https://phabricator.services.mozilla.com/D158903
2022-10-13 16:44:23 +00:00
sotaro
352f148a02 Bug 1790169 - Add buffer size check to DrawTargetWebgl::Init() r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D157085
2022-09-13 02:59:28 +00:00
Lee Salzman
0ae0ae9068 Bug 1789849 - Use a separate DrawTargetSkia for rendering clip masks. r=aosmond
Previously we were reusing the framebuffer's Skia DT to render the clip mask.
This was the path of least resistance since SkCanvas does not allow exporting
clip information, and there is no way to reset the bitmap storage inside an
SkCanvas temporarily.

However, this can cause a feedback cycle of unnecessary WaitForShmem operations,
since we need to wait before we can generate the clip mask into the Skia target,
and then anything else after it needs to wait for the clip mask to finish uploading
before the Skia DT can be used again.

To alleviate this, we just allocate a new DrawTargetSkia to render the clip mask
into. We carefully clip the size of the DT so that in the common case we avoid
having to upload a surface the size of the entire framebuffer. Further, since
this is a completely different DT, we can now use an A8 format (1/4 the memory
overhead) instead of a BGRA8 format for the clip mask, which gives a further
memory usage gain.

A further complication is that we need to log the current clip stack state so
that we can replay it onto the new DrawTargetSkia. This avoids having to add
a mechanism to SkCanvas to export clip information.

Differential Revision: https://phabricator.services.mozilla.com/D157050
2022-09-12 15:26:03 +00:00
Lee Salzman
2774b7d98a Bug 1789849 - Increment profile counters for a few more expensive events. r=aosmond
Certain events like waiting on a round-trip to verify that the HostWebGLContext is
done using a shmem, or pushing a Skia layer which will need to be flatten later, can
be expensive, especially if they are used many times throughout a frame. However,
we weren't currently incremening the profile counters for these situations which can
lead to accelerated rendering persisting even when it would be more judicious to
fallback to software rendering.

Differential Revision: https://phabricator.services.mozilla.com/D157049
2022-09-12 15:26:02 +00:00
Lee Salzman
a3b9153624 Bug 1789849 - Avoid regenerating clip mask unless necessary. r=aosmond
Sometimes the clip state is thrashed when we need to temporarily override
clipping to disable it. However, in this case, the clip mask itself remains
unchanged. The current invalidation scheme doesn't discern between generation
of the clip mask itself and setting the clip state for the shader, leading to
unnecessary regeneration of the clip mask.

This code just tries to discern when this is happening so we can refresh the
clip state without having to regenerate the clip mask unless truly necessary.

Differential Revision: https://phabricator.services.mozilla.com/D157048
2022-09-12 15:26:02 +00:00
Lee Salzman
c093715333 Bug 1773280 - Fall back to DrawPath if we can't accelerate StrokeLike. r=aosmond
Sometimes we hit requests to stroke a path with a rounded line in it that can't
be accelerated inside StrokeLine. This causes it to push a layer which can be
expensive. Go through DrawPath instead in this case which will still try to
accelerate the drawing with a cached texture that does not use a layer.

Differential Revision: https://phabricator.services.mozilla.com/D156791
2022-09-08 20:02:17 +00:00
Lee Salzman
11b3e01801 Bug 1789683 - Fix non-stroked case in GlyphCacheEntry::MatchesGlyphs. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D156772
2022-09-08 17:49:20 +00:00
Lee Salzman
c5a44a2c28 Bug 1773280 - Explicitly delete clip mask in DrawTargetWebgl destructor. r=aosmond
The clip mask might not get deleted in a timely fashion and can be quite large.
Ensure it gets deleted promptly when DrawTargetWebgl goes away.

Differential Revision: https://phabricator.services.mozilla.com/D156644
2022-09-07 16:02:58 +00:00
Lee Salzman
5caf5cb4ea Bug 1773280 - Support complex clips in DrawTargetWebgl by using a mask texture. r=aosmond,gfx-reviewers
DrawTargetWebgl currently only supports aligned rectangular clips that can be approximated
with a scissor. However, many use-cases require complex clips like rounded rectangles or
not-aligned regions. We can support these cases more generally by using a mask texture that
modulates the shader color. The mask texture is generated by doing a solid fill in the Skia
target over a clear background, which is safe because the Skia target is not in use while
the WebGL target is being rendered to. This adds one unconditional texture lookup to the
shaders which shouldn't have a big performance impact. When no clip mask is needed, we just
default to using a 1x1 solid texture.

Depends on D156224

Differential Revision: https://phabricator.services.mozilla.com/D156225
2022-09-06 05:06:18 +00:00
Lee Salzman
3113669e84 Bug 1773280 - Extend DrawTargetWebgl's glyph cache to support stroked glyphs. r=aosmond,gfx-reviewers
Currently we only support filled glyphs in DrawTargetWebgl. PDF.js can often render PDFs
that have stroked glyphs, so support for stroked glyphs is useful to prevent fallbacks.
This just adds support for plumbing StrokeOptions through to GlyphCache.

Differential Revision: https://phabricator.services.mozilla.com/D156224
2022-09-06 05:06:17 +00:00
Lee Salzman
ba5d8b1040 Bug 1787721 - Only support clamp extend mode in DrawTargetWebgl. r=gfx-reviewers,jrmuizel
We currently don't support repeat modes in the DrawTargetWebgl's image shader.
This change makes it only explicitly accelerate clamped modes. Other extend
modes will just go to the path rasterization option which will pre-rasterize
the image as a filled path and then upload to the texture cache. This will
let us keep the clamp path simple and fast without worrying about uncommon
repeat usage for now. If it ever turns out to be the case that repeat modes
are highly necessary for performance, we can revisit this.

Differential Revision: https://phabricator.services.mozilla.com/D155860
2022-08-29 17:49:18 +00:00
Lee Salzman
aaca48b057 Bug 1784910 - Render bitmap fonts as light-on-dark text. r=aosmond
When we are rendering dark-on-light text, we invert the bitmap after
rendering to produce a standard white-on-black mask, since we must actually
render that as black-on-white to get CoreText to produce the correct dilation.

However, when we know we're rendering bitmap fonts for emoji, we don't actually
want this inversion to happen at all. So we need to ensure bitmaps go through
the normal light-on-dark path that doesn't do this.

Differential Revision: https://phabricator.services.mozilla.com/D154777
2022-08-16 16:49:10 +00:00