Commit Graph

992 Commits

Author SHA1 Message Date
Andrew Osmond
7e6fe784f1 Bug 1794442 - Avoid reusing CanvasImageCache entries for different backends. r=lsalzman
We optimize the surface contents in CanvasImageCache for the particular
DrawTarget backend used by the canvas. If different backends are
intermixed, then the cache may not be properly optimized (e.g. Skia and
Direct2D). This can have performance implications.

This patch adds the backend type to the cache entries, so that we ignore
cache entries created with a different backend type.

Differential Revision: https://phabricator.services.mozilla.com/D159388
2022-10-14 20:40:11 +00:00
Kelsey Gilbert
2e6f219a3b Bug 1795193 - Remove unused chrome-only API MozGetIPCContext. r=gfx-reviewers,jrmuizel,emilio
And also remove SetIsIPC.

Differential Revision: https://phabricator.services.mozilla.com/D159351
2022-10-14 18:02:28 +00:00
Olli Pettay
048bd344c4 Bug 1777574, automate CC zone handling, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D155084
2022-09-07 11:22:51 +00:00
Andrew Osmond
84bdcd48a4 Bug 1780042 - Set CanvasPattern principal for main thread OffscreenCanvas. r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D152710
2022-08-02 15:51:45 +00:00
Andrew Osmond
9e1a4d668d Bug 1782552 - Make CanvasRenderingContext2D::sErrorTarget threadsafe. r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D153374
2022-08-01 18:11:16 +00:00
Nika Layzell
bea3f71955 Bug 1772006 - Part 6: Simplify and move the find+replace methods from ns[T]StringObsolete, r=xpcom-reviewers,barret
The remaining methods in ns[T]StringObsolete are all find+replace methods for
nsTSubstring. These were migrated in a similar way to the find methods, and
partially updated to avoid using methods from nsStringObsolete.cpp.

This change removes the ns[T]StringObsolete.cpp files completely, as they are
no longer necessary.

Differential Revision: https://phabricator.services.mozilla.com/D148301
2022-07-30 00:12:49 +00:00
Chun-Min Chang
5bd99e209b Bug 1776796 - Rename MarkAsContentSource r=media-playback-reviewers,alwu
`HTMLMediaElement::MarkAsContentSource` [1] was added in Bug 1299718 to
monitor the visibility / invisibility of various usage of video element.
However, that telemetry had been removed in Bug 1356046.
`MarkAsContentSource` is only used for logging currently. It's better to
reword its name and related comments to bring the code in line with the
current status.

[1] https://searchfox.org/mozilla-central/rev/5b2d2863bd315f232a3f769f76e0eb16cdca7cb0/dom/html/HTMLMediaElement.h#799

Differential Revision: https://phabricator.services.mozilla.com/D150434
2022-07-27 00:20:45 +00:00
Norisz Fay
18951e0035 Backed out changeset ad83f5251083 (bug 1780042) for causing wpt failures on nsICanvasRenderingContextInternal.cpp 2022-07-26 09:58:19 +03:00
Andrew Osmond
4065edfc09 Bug 1780042 - Set CanvasPattern principal for main thread OffscreenCanvas. r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D152710
2022-07-26 02:00:57 +00:00
Emilio Cobos Álvarez
d787c45764 Bug 1780385 - Remove canvas hit region api. r=jrmuizel
Add a pref for MouseEvent.region since that wasn't un-exposed. No other
browser supports it so we can probably safely remove it, but just in
case.

Differential Revision: https://phabricator.services.mozilla.com/D152274
2022-07-20 16:52:47 +00:00
Andrew Osmond
a1c24f6dc1 Bug 1779570. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D151857
2022-07-14 20:17:10 +00:00
Andrew Osmond
66c6bad8f6 Bug 1779519 - gfxFontCache expiration tracker operations should be more atomic. r=jfkthame
gfxFontCache acquires and releases its mutex during various operations.
In order to keep the state internally consistent, we should only release
the lock after the full operation is complete. This involves moving the
deletion of gfxFont to outside the lock via a temporary discard array.

The expiration state should not be protected by the gfxFont's mutex
since we don't hold it during most operations. Instead we should hold
gfxFontCache's mutex because then we can guarantee the operation is
atomic, particularly when a worker wants a font, and the main thread is
aging the generations.

When a font is returned from gfxFontCache, we now return it already
removed from the tracker, and with its refcount updated. This avoids any
potential races between the expiration timer and a worker accessing the
font, as well as simplying the callers so they don't need to be aware of
addref-ing manually in case the result is to be discarded (so that it
gets readded to the tracker).

Differential Revision: https://phabricator.services.mozilla.com/D151821
2022-07-14 19:53:09 +00:00
criss
380e3e436f Backed out changeset e4cd98b5984d (bug 1779519) for causing build bustages. CLOSED TREE 2022-07-14 22:06:53 +03:00
Andrew Osmond
8cb302b7c5 Bug 1779519 - gfxFontCache expiration tracker operations should be more atomic. r=jfkthame
gfxFontCache acquires and releases its mutex during various operations.
In order to keep the state internally consistent, we should only release
the lock after the full operation is complete. This involves moving the
deletion of gfxFont to outside the lock via a temporary discard array.

The expiration state should not be protected by the gfxFont's mutex
since we don't hold it during most operations. Instead we should hold
gfxFontCache's mutex because then we can guarantee the operation is
atomic, particularly when a worker wants a font, and the main thread is
aging the generations.

When a font is returned from gfxFontCache, we now return it already
removed from the tracker, and with its refcount updated. This avoids any
potential races between the expiration timer and a worker accessing the
font, as well as simplying the callers so they don't need to be aware of
addref-ing manually in case the result is to be discarded (so that it
gets readded to the tracker).

Differential Revision: https://phabricator.services.mozilla.com/D151821
2022-07-14 18:35:49 +00:00
Emilio Cobos Álvarez
893e093b01 Bug 1779598 - Stop passing around Maybe<SVGImageContext>. r=aosmond
All its members are optional, so we can just use it as a plain struct
rather than Maybe<> all around, which simplifies the code and prevents
silly bugs like bug 1779592.

Mostly automatic via:

  rg -l 'SVGImageContext' . | xargs sed -i 's/Maybe<SVGImageContext>/SVGImageContext/g'

With trivial build fixes.

Not intended to change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D151846
2022-07-14 16:03:25 +00:00
Jonathan Kew
2b3ff28901 Bug 1778908 - Implement the fontKerning attribute for Canvas2d text. r=gfx-reviewers,aosmond,emilio
Per spec, the value of fontKerning should be an enum, not a string, but currently we handle
all the keyword-valued canvas attributes in this way. We may want to convert them to enums
(which will mean that unrecognized values throw an error instead of being ignored), but I
think that should be done for all the attributes together as a separate bug. For now, using
a string here provides consistency with the rest of the canvas APIs.

Note that Blink's current implementation and the existing WPT tests have some problems:
they treat the values of fontKerning as case-insensitive, which is wrong. I have filed
https://bugs.chromium.org/p/chromium/issues/detail?id=1343333 about this.

Differential Revision: https://phabricator.services.mozilla.com/D151755
2022-07-13 18:55:37 +00:00
Jonathan Kew
9d8923ed16 Bug 1779227 - Enable the font attribute to be set on a disconnected <canvas> element without throwing an error. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D151627
2022-07-12 18:36:32 +00:00
Razvan Cojocaru
20109814bf Bug 1773387 - Change local variables of type gfxSize, which actually represent scales, to MatrixScalesDouble. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D149565
2022-06-20 19:17:14 +00:00
criss
c1b045ddda Backed out 9 changesets (bug 1772006) causing build bustages on nsTString.cpp. CLOSED TREE
Backed out changeset f17c7565707b (bug 1772006)
Backed out changeset c725fe1f5882 (bug 1772006)
Backed out changeset d19663161261 (bug 1772006)
Backed out changeset b6611ab002d9 (bug 1772006)
Backed out changeset 790f42b64af9 (bug 1772006)
Backed out changeset 79a734b4e4d9 (bug 1772006)
Backed out changeset 42730aae16ea (bug 1772006)
Backed out changeset b2542aef3054 (bug 1772006)
Backed out changeset 962bfea4a309 (bug 1772006)
2022-06-11 01:13:42 +03:00
Nika Layzell
cac50a3711 Bug 1772006 - Part 7: Simplify and move the find+replace methods from ns[T]StringObsolete, r=xpcom-reviewers,barret
The remaining methods in ns[T]StringObsolete are all find+replace methods for
nsTSubstring. These were migrated in a similar way to the find methods, and
partially updated to avoid using methods from nsStringObsolete.cpp.

This change removes the ns[T]StringObsolete.cpp files completely, as they are
no longer necessary.

Differential Revision: https://phabricator.services.mozilla.com/D148301
2022-06-10 21:12:08 +00:00
Emilio Cobos Álvarez
1c58e2a928 Bug 1773070 - Unify Gecko and Servo EventState/ElementState bits. r=smaug
Add a dom/base/rust crate called just "dom" where we can share these.

Most of the changes are automatic:

  s/mozilla::EventStates/mozilla::dom::ElementState/
  s/EventStates/ElementState/
  s/NS_EVENT_STATE_/ElementState::/
  s/NS_DOCUMENT_STATE_/DocumentState::/

And so on. This requires a new cbindgen version to avoid ugly casts for
large shifts.

Differential Revision: https://phabricator.services.mozilla.com/D148537
2022-06-07 23:09:52 +00:00
Emilio Cobos Álvarez
e48bb99524 Bug 1771564 - Constify ComputedStyle usage in nsComputedDOMStyle. r=dholbert
None of the consumer need to mutate styles, and this saves some ugly
const_casting on the next patch.

Doesn't change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D147555
2022-05-28 01:04:24 +00:00
Jonathan Kew
f16408a881 Bug 1770006 - Ensure the fontGroup is recreated if necessary in CanvasRenderingContext2D::GetCurrentFontStyle. r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D146788
2022-05-23 15:18:51 +00:00
Lee Salzman
fefc642a8b Bug 1768521 - Limit pattern dimensions independently in Canvas2D FillRect. r=gfx-reviewers,gw
Bug 1719886 tried to simplify this code by using Rect::Intersect, but that had the
side-effect of it trying to detect if either width OR height was <= 0, and if so,
setting both width AND height to 0. Pattern dimensions need to be limited independently
here for correct behavior, so we just default to inlining the code for each dimension
without the incorrect final behavior of zeroing the rectangle.

Differential Revision: https://phabricator.services.mozilla.com/D146144
2022-05-13 03:51:15 +00:00
Lee Salzman
d58d4113be Bug 1760928 - Evict cached textures on memory pressure. r=aosmond
Since we're going to be keeping around empty cache pages, which can further
increase memory pressure, it would be nice if we respond to memory pressure
events by evicting the empty cache pages.

Differential Revision: https://phabricator.services.mozilla.com/D145499
2022-05-11 17:22:22 +00:00
Lee Salzman
e997edb2e3 Bug 1767365 - Clip image data transfers. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D145674
2022-05-10 05:26:44 +00:00
Jonathan Kew
a1c81aa9f7 Bug 1110580 - patch 1 - Accelerate canvas2d.fillText for simple unidirectional strings by reusing the same textrun to draw as we created to measure the text. r=lsalzman
In general, the canvas text-drawing code makes two passes over the string, one to measure it and the second to draw.
Each time, it has to find individual direction runs and create a separate gfxTextRun for each.
However, in the (common) case of a simple unidirectional string, we're only going to have a single run,
so it's wasteful to construct it twice; the CanvasBidiProcessor can just re-use the run from the measurement
pass when it needs to draw.

In particular, this will apply to pdf.js drawing, where each glyph is handled in a separate fillText call.
Many other uses of canvas text should also benefit somewhat.

Differential Revision: https://phabricator.services.mozilla.com/D145426
2022-05-05 08:14:11 +00:00
Jonathan Kew
4b0d21e7ed Bug 1759686 - patch 5 - Adapt canvas2d text methods to allow use from worker threads without a Document or PresShell. r=aosmond
This enables an offscreen-canvas Worker to do text rendering, but only with system-installed fonts
because we don't yet have a FontFaceSet available in the Worker. (That's bug 1758946.)

Differential Revision: https://phabricator.services.mozilla.com/D144188
2022-05-04 17:13:16 +00:00
Jonathan Kew
ee285bf4b2 Bug 1759686 - patch 3 - Ensure prefs that may be accessed by canvas2d text code are atomic. r=lsalzman
These need to be atomic so that they can be accessed by canvas code when running on a worker thread
without calling main-thread-only Preferences APIs.

Depends on D144185

Differential Revision: https://phabricator.services.mozilla.com/D144186
2022-05-03 12:39:09 +00:00
Jonathan Kew
da76cb6abd Bug 1759686 - patch 2 - Remove redundant null-checks in CanvasRenderingContext2D, as GetPresShell() will check these members. r=lsalzman
We don't need to null-check the mCanvasElement and mDocShell members in these methods,
and bail out if neither is provided, because in that case the following GetPresShell() call
will return null and we'll bail out there anyhow.

Removing these extra checks will simplify the changes involved in enabling the canvas code
to be used in a Worker context, where it is not connected to a document.

Depends on D144184

Differential Revision: https://phabricator.services.mozilla.com/D144185
2022-05-03 12:39:08 +00:00
Jonathan Kew
56d3ece01c Bug 1759686 - patch 1 - Remove unused mPresContext member from CanvasRenderingContext2D. r=lsalzman
Nothing uses this member, so remove it to make it clear we don't need to provide it
when setting up a CanvasRenderingContext2D.

Differential Revision: https://phabricator.services.mozilla.com/D144184
2022-05-03 12:39:08 +00:00
Dan Robertson
b3a76a25b6 Bug 1676299 Part 4: Modify BaseMatrix::ScaleFactors() to return a ScaleFactors2D. r=botond
This changes BaseMatrix::ScaleFactors() to return a ScaleFactors2D instead of
a SizeTyped.

Depends on D145041

Differential Revision: https://phabricator.services.mozilla.com/D144666
2022-04-30 01:35:24 +00:00
Jonathan Kew
b725ca49f5 Bug 1766356 - Replace the specified font-size with the computed value when serializing the canvas2d font attribute. r=hiro
This requires updating a couple of our old dom/canvas mochitests that assume the size element
of the font attribute will be serialized as specified, which conflicts with the current spec
requirement.

On the other hand, this also resolves a few current WPT test failures that are specifically
testing the behavior described in the spec (e.g. a size specified as percentage gets serialized
as the computed px value).

Differential Revision: https://phabricator.services.mozilla.com/D144812
2022-04-28 08:50:12 +00:00
Andrew Osmond
04864cae83 Bug 1765323 - Enable paint callbacks for OffscreenCanvas and Canvas 2D. r=gfx-reviewers,lsalzman
Canvas 2D needs paint callbacks from the OffscreenCanvas display
pipeline so that it knows when to reinvalidate. They were disabled which
meant only the first frame was rendered.

Differential Revision: https://phabricator.services.mozilla.com/D144006
2022-04-19 17:55:32 +00:00
Jonathan Kew
9601e50875 Bug 1728999 - Implement the CanvasRenderingContext2D.direction property. r=lsalzman,emilio
Differential Revision: https://phabricator.services.mozilla.com/D142701
2022-04-05 12:44:42 +00:00
Lee Salzman
b0e9930f95 Bug 1762523 - Add performance profiling to DrawTargetWebgl. r=aosmond,gfx-reviewers
This adds OnEvent hooks to DrawTargetWebgl for various events so that
profile counters may be maintained each frame. These profile counters
try to determine if a software fallback happened or an uncacheable event
occurs that requires either uploading data to the GPU or reading back
from the GPU, events which can cause substantial slowdown if they happen
repeatedly even without an explicit fallback to software rasterization.

When it is determined a threshold has been reached (as controlled by
some prefs), RequiresRefresh() in PersistentBufferProvider is used to
signal that we should recreate the PersistentBufferProvider of a different
type and thus disable acceleration.

Differential Revision: https://phabricator.services.mozilla.com/D142646
2022-04-04 15:50:48 +00:00
Lee Salzman
99223db63d Bug 1761404 - Add DrawTarget DrawShadow API call. r=jrmuizel,gfx-reviewers
This implements a new DrawTarget API call, DrawShadow. This can be used to draw
the shadow of a given Path and Pattern. Unlike DrawSurfaceWithShadow, this only
draws the shadow to simplify the resulting implementation. DrawTarget provides
a default implementation that will draw a blurred shadow to a transient surface
before handing it off to DrawSurfaceWithShadow, allowing existing DrawTarget
implementations to function without having to implement the new API at all.

Within DrawTargetWebgl, DrawShadow allows direct caching of the shadow in the
existing PathCache mechanism, unlike DrawSurfaceWithShadow which would usually
be called with different transient surfaces every time, even if the input
patterns actually matched.

CanvasRenderingContext2D is modified to call DrawShadow when only a shadow
needs to be applied without any filter. AdjustedTarget is modified to wrap
the necessary DrawTarget draw calls so they can be dispatched appropriately.

Since a lot of redundant shadow parameters are shared between DrawShadow and
DrawSurfaceWithShadow, and since a lot of consumers of these functions need
to also pass around these parameters, this also bundles these into a new
ShadowOptions structure to make this easier.

Differential Revision: https://phabricator.services.mozilla.com/D142026
2022-04-01 19:03:29 +00:00
sotaro
072fc20833 Bug 1423850 - Take into account video's rotation metadata at context.drawImage() with <video> r=gfx-reviewers,bradwerth
Rotated video for reftest is re-used from bug1228601-video-rotation-90.html

Differential Revision: https://phabricator.services.mozilla.com/D140353
2022-03-18 00:01:02 +00:00
Lee Salzman
f347cf8f03 Bug 1757925 - Only warn for AdjustedTarget failure in canvas. r=bradwerth
Differential Revision: https://phabricator.services.mozilla.com/D140235
2022-03-03 20:36:24 +00:00
Lee Salzman
5e4c3cab75 Bug 1752456 - Check for non-finite adjusted target bounds. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D139913
2022-03-01 17:48:54 +00:00
Andrew Osmond
4370e54b02 Bug 1756186 - Fix Canvas2D CreatePattern and DrawImage with no context OffscreenCanvas. r=lsalzman
This patch ensures we return an empty surface as per the spec when
the OffscreenCanvas passed into CreatePattern and DrawImage has no
context bound to it.

Differential Revision: https://phabricator.services.mozilla.com/D139127
2022-02-22 21:16:16 +00:00
Lee Salzman
da1e98bca3 Bug 1754130 - Support presenting a WebGLFramebuffer to its own swap chain without opaque FB. r=aosmond,jgilbert
Most of the support for presenting a WebGLFramebuffer to a swap chain existed as part of the
mechanism for opaque WebXR framebuffer support. However, such "opaque" framebuffer are meant
to be opaque in the sense that their attachments can't be inspected or changed, which does
not provide the requisite level of control for efficiently implementing Canvas2D snapshots.

To this end, the existing Present mechanism is slightly extended to allow presenting to the
swap chain already present in WebGLFramebuffer without the existence of a corresponding
MozFramebuffer.

This also fixes a bug in that AsWebgl() was no longer being utilized in CanvasRenderer, such
that a new mechanism that routed GetFrontBuffer() was needed to fix the code rot.

There are also some efforts to remove a couple redundant copies I noticed in profiles along
the way.

Differential Revision: https://phabricator.services.mozilla.com/D138119
2022-02-11 19:49:56 +00:00
Marian-Vasile Laza
20f0f98e78 Backed out 3 changesets (bug 1754130) for causing mochitest failures. CLOSED TREE
Backed out changeset 7fea32057b92 (bug 1754130)
Backed out changeset 1ac8f10e0025 (bug 1754130)
Backed out changeset 3d56b847ddf9 (bug 1754130)
2022-02-11 18:30:11 +02:00
Lee Salzman
196c2dd584 Bug 1754130 - Support presenting a WebGLFramebuffer to its own swap chain without opaque FB. r=aosmond,jgilbert
Most of the support for presenting a WebGLFramebuffer to a swap chain existed as part of the
mechanism for opaque WebXR framebuffer support. However, such "opaque" framebuffer are meant
to be opaque in the sense that their attachments can't be inspected or changed, which does
not provide the requisite level of control for efficiently implementing Canvas2D snapshots.

To this end, the existing Present mechanism is slightly extended to allow presenting to the
swap chain already present in WebGLFramebuffer without the existence of a corresponding
MozFramebuffer.

This also fixes a bug in that AsWebgl() was no longer being utilized in CanvasRenderer, such
that a new mechanism that routed GetFrontBuffer() was needed to fix the code rot.

There are also some efforts to remove a couple redundant copies I noticed in profiles along
the way.

Differential Revision: https://phabricator.services.mozilla.com/D138119
2022-02-11 15:36:30 +00:00
Sylvestre Ledru
35a175aa33 Bug 1754767 - Remove duplicate includes r=media-playback-reviewers,padenot
Differential Revision: https://phabricator.services.mozilla.com/D138441
2022-02-11 10:01:15 +00:00
Andrew Osmond
85f36e63d5 Bug 1753657 - Make gCanvasAzureMemoryUsed atomic for OffscreenCanvas. r=gfx-reviewers,jrmuizel
This needs to be atomic since it can be updated by multiple threads.

Differential Revision: https://phabricator.services.mozilla.com/D137863
2022-02-04 14:42:00 +00:00
Andrew Osmond
67e3b5ea0c Bug 1746750 - Part 3. Implement partial OffscreenCanvasRenderingContext2D. r=lsalzman,webidl,smaug
This patch adds a partial OffscreenCanvasRenderingContext2D
implementation. It is missing anything text and UI related, including
CanvasFilters, CanvasUserInterface, CanvasText, CanvasTextDrawingStyles,
and CanvasHitRegions.

Differential Revision: https://phabricator.services.mozilla.com/D135354
2022-02-03 20:00:25 +00:00
Andrew Osmond
78a909efc9 Bug 1746750 - Part 2. Add new WebIDL method variants to support OffscreenCanvasRenderingContext2D. r=lsalzman
This patch is a non-functional change. It overloads some WebIDL methods
of CanvasRenderingContext2D to account for the difference between the
main thread and worker prototypes.

Differential Revision: https://phabricator.services.mozilla.com/D135353
2022-02-03 20:00:25 +00:00
Andrew Osmond
eb86e0ac07 Bug 1746750 - Part 1. Refactoring to support OffscreenCanvasRenderingContext2D. r=lsalzman
This patch is a non-functional change which allows the shutdown observer
to be overridden (since workers have a different mechanism). It also
fixes a static counter to be atomic, and adds mOffscreenCanvas to the
cycle collection tracking.

Differential Revision: https://phabricator.services.mozilla.com/D135352
2022-02-03 20:00:24 +00:00
Iulian Moraru
6d4e168ab0 Backed out 4 changesets (bug 1746750) as per request. CLOSED TREE
Backed out changeset bf79a6b72d87 (bug 1746750)
Backed out changeset 87dde3962558 (bug 1746750)
Backed out changeset 08e0ff1804f6 (bug 1746750)
Backed out changeset 4a3da2db3bc0 (bug 1746750)
2022-02-03 03:24:42 +02:00