Commit Graph

104 Commits

Author SHA1 Message Date
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
Lee Salzman
4836bb7fca Bug 1784315 - Ensure the clipping applied to glyph cache entries matches. r=aosmond,gfx-reviewers
If viewport clipping is applied to the bounds of glyphs, we can end up finding the
wrong entry if the clipping would differ, since we no longer compare the bounds to
the entry bounds when searching for a matching entry in an effort to reduce the
amount of bounds computations in the common case.

To workaround this, each entry now remembers its full, unclipped bounds. Upon
finding a candidate entry, we offset the full bounds to the new offset and reapply
clipping. If the bounds then match with the old clipped bounds with the new offset
applied, then we know the amount of applied clipping is the same, and it is safe
to reuse the entry.

Differential Revision: https://phabricator.services.mozilla.com/D154490
2022-08-16 03:05:45 +00:00
Lee Salzman
8ded3213c0 Bug 1783717 - Faster allocation of TexturePacker children. r=aosmond,gfx-reviewers
Rather than allocating TexturePacker children individually, allocate an array
of all the children at once to cut the number of memory allocations in half.

Depends on D154118

Differential Revision: https://phabricator.services.mozilla.com/D154182
2022-08-10 02:57:26 +00:00
Lee Salzman
bc968abdf7 Bug 1783717 - Only compute glyph bounds on cache insertion. r=aosmond,gfx-reviewers
Now that we're actually hitting cache entries in the glyph cache, it turns out
always computing the local glyph bounds can be expensive, especially since they
should never really change. Instead, rely on the bounds that were initially
computed when an entry is inserted into the cache, and just change their relative
offset based on the current transform. This way, in the common case of a cache
hit, we never need to compute the bounds.

Differential Revision: https://phabricator.services.mozilla.com/D154118
2022-08-10 02:57:26 +00:00
Lee Salzman
c7d7028c95 Bug 1783717 - Fix glyph cache entry bounds comparisons in DrawTargetWebgl. r=aosmond
Offsets were being specified in quantized space (i.e. scaled 1-4x) whereas bounds were
still in the original coordinate space. The bounds need to be transformed by the same
quantization scale so that glyph cache entries compare correctly. This was preventing
cache entries from being properly reused.

Differential Revision: https://phabricator.services.mozilla.com/D154102
2022-08-10 02:57:25 +00:00
Lee Salzman
33952d449f Bug 1783717 - Use hash chaining for DrawTargetWebgl cache entries. r=aosmond,bradwerth
This implements a rudimentary form of hash chaining for cache entries that reduces
the number of entry comparisons by about an order of magnitude. It's a bit of a bother
to use an actual hash table here since right now the code expects to be able to have
random access to cache entries in the list, and the MFBT hash table is not quite set
up for this. Instead, this just adds a reasonable fixed number of buckets to bring
the list size better under control.

Differential Revision: https://phabricator.services.mozilla.com/D154101
2022-08-10 02:57:23 +00:00
Lee Salzman
bfc0683742 Bug 1782443 - Call MarkSkiaChanged in DrawTargetWebgl::LockBits. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D153317
2022-08-01 15:29:49 +00:00
Lee Salzman
487e1aeb94 Bug 1771007 - Avoid sending SourceSurfaceWebgl off-thread. r=jrmuizel,gfx-reviewers
BorrowSnapshot can be called by OffScreenCanvas in various places that may send
a SourceSurfaceWebgl to the main thread. If it did not originate from the main
thread, then this can cause multiple threads to use it. In general we want to
avoid this. For now, override BorrowSnapshot and make it always force a Skia
snapshot that can be safely shared between threads instead of SourceSurfaceWebgl.

Differential Revision: https://phabricator.services.mozilla.com/D152417
2022-07-26 01:28:48 +00:00
Lee Salzman
edcd6c3cd2 Bug 1780574 - Support imageSmoothingEnabled in DrawTargetWebgl. r=jrmuizel,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D152415
2022-07-26 01:27:04 +00:00
Lee Salzman
f20e7f0794 Bug 1779766 - Ensure DrawTargetWebgl is done using shmem before dealloc. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D151957
2022-07-15 20:34:19 +00:00
Lee Salzman
d2d65a7503 Bug 1779804 - Check for valid target in DrawTargetWebgl before accessing shmem. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D151938
2022-07-15 16:34:02 +00:00
Lee Salzman
34bc182ee2 Bug 1779342 - Force any Skia snapshots to copy the shmem before it deallocs. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D151876
2022-07-14 21:15:45 +00:00
Lee Salzman
ff19bc4536 Bug 1777872 - Use Shmem for backing DrawTargetWebgl's Skia target. r=jgilbert
When rendering large and/or fullscreen Canvas2Ds, excessive time can be spent
in calls to TexImage/ReadPixels copying into and out of Shmems to the separate
buffer for DrawTargetSkia. To alleviate this, we can make the DrawTargetSkia
directly wrap the Shmem, so that calls to TexImage/ReadPixels then directly
read or write to this without any separate copy. We modify RawTexImage to use
the IPDL SendTexImage path so that Shmems can be sent via SurfaceDescriptor.
Since SendTexImage is nominally async (which is beneficial), we rely on a
call to GetError later to verify that the Shmem processing is completely before
we further modify the DrawTargetSkia. We further add a ReadPixelsIntoShmem IPDL
call to allow sending the Shmem in the other direction directly.

Differential Revision: https://phabricator.services.mozilla.com/D151286
2022-07-12 09:25:35 +00:00
Bogdan Szekely
0e7144b825 Backed out changeset 458aae4c5d0a (bug 1777872) for causing mochitest failures on Shmem.cpp CLOSED TREE 2022-07-12 12:03:35 +03:00
Lee Salzman
1b5b2600b4 Bug 1777872 - Use Shmem for backing DrawTargetWebgl's Skia target. r=jgilbert
When rendering large and/or fullscreen Canvas2Ds, excessive time can be spent
in calls to TexImage/ReadPixels copying into and out of Shmems to the separate
buffer for DrawTargetSkia. To alleviate this, we can make the DrawTargetSkia
directly wrap the Shmem, so that calls to TexImage/ReadPixels then directly
read or write to this without any separate copy. We modify RawTexImage to use
the IPDL SendTexImage path so that Shmems can be sent via SurfaceDescriptor.
Since SendTexImage is nominally async (which is beneficial), we rely on a
call to GetError later to verify that the Shmem processing is completely before
we further modify the DrawTargetSkia. We further add a ReadPixelsIntoShmem IPDL
call to allow sending the Shmem in the other direction directly.

Differential Revision: https://phabricator.services.mozilla.com/D151286
2022-07-12 08:32:40 +00:00
Lee Salzman
8a48ab77dd Bug 1779010 - Rely on WebGL zero initializing buffers in DrawTargetWebgl. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D151511
2022-07-12 08:11:06 +00:00