Closed Bug 1855742 Opened 1 year ago Closed 1 year ago

Make recording based canvases run on DOM workers

Categories

(Core :: Graphics: Canvas2D, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
125 Branch
Tracking Status
firefox125 --- fixed

People

(Reporter: aosmond, Assigned: aosmond)

References

(Blocks 2 open bugs)

Details

Attachments

(4 files, 9 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

In bug 1852145, we moved PCanvas to be managed by PCanvasManager. Now in this bug, we will complete the content process side work to make recordings work on DOM worker threads.

Blocks: 1795296
Depends on: 1855754

This patch adds/updates the thread assertion plumbing for CanvasChild
and DrawEventRecorder to ensure that we are always accessing them on the
owning thread. It also now makes these checks compatible with running in
a DOM worker context for OffscreenCanvas using recordings.

Depends on D189525

This patch allows us to create nsExpirationTracker objects off the main
thread, with the caveat that memory pressure events should/must be
handled directly by the creator rather than managed internally. With
that in mind, the threading assertions have also been updated to ensure
it is always the owning thread that accesses the tracker.

Depends on D189526

This patch adds support for allocationg shmem sections for
ImageBridgeChild. The recording infrastructure depends on it.

Depends on D189527

This patch makes the CanvasManagerChild creates/manager the
ActiveResourceTracker instead of the WebRenderBridgeChild. Since PCanvas
is now managed by PCanvasManager, and ActiveResourceTracker is only used
by the PCanvas recording plumbing, we need it on every thread that the
CanvasManagerChild can be created.

Depends on D189528

It is disabled in this patch via the gfx.canvas.remote.allow-offscreen
pref. A follow up patch will enable this by default.

Depends on D189531

Attachment #9355628 - Attachment description: Bug 1855742 - Part 5. Allow RecordedTextureData to be created on DOM workers. → Bug 1855742 - Part 5. Allow CanvasDrawEventRecorder to be created on DOM workers.
Attachment #9355629 - Attachment description: Bug 1855742 - Part 6. Allow SourceSurfaceCanvasRecording to be created on DOM workers. → Bug 1855742 - Part 6. Allow recording surfaces and textures to be created on DOM workers.

There are some r+ patches which didn't land and no activity in this bug for 2 weeks.
:aosmond, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.

Flags: needinfo?(lsalzman)
Flags: needinfo?(aosmond)

Not ready.

Flags: needinfo?(lsalzman)
Flags: needinfo?(aosmond)

Because we cannot control the ordering of shutdown notification from
WorkerRef, we need to choose one centralized point to begin shutdown of
the main thread or the owning DOM worker. Since there are other objects
owned by CanvasManagerChild, we also switch to a ThreadSafeWorkerRef.

If ImageBridgeChild is responsible for the textures being forwarded to
the compositor process, then the callback will happen on
ImageBridgeChild's thread instead of the main or DOM worker thread.

This allows us to create a TextureClient on a different thread than the
actor without special effort on the part of the allocator. Similarly, it
also allows us to destroy a TextureClient on a different thread if it
has a readlock bound to it.

Attachment #9355628 - Attachment description: Bug 1855742 - Part 5. Allow CanvasDrawEventRecorder to be created on DOM workers. → Bug 1855742 - Part 9. Allow CanvasDrawEventRecorder to be created on DOM workers.
Attachment #9355629 - Attachment description: Bug 1855742 - Part 6. Allow recording surfaces and textures to be created on DOM workers. → Bug 1855742 - Part 10. Allow recording surfaces and textures to be created on DOM workers.
Attachment #9355630 - Attachment description: Bug 1855742 - Part 7. Allow recording based canvases with OffscreenCanvas. → Bug 1855742 - Part 11. Allow recording based canvases with OffscreenCanvas.
Attachment #9366321 - Attachment description: Bug 1855742 - Part 7. Ensure TextureClient's mReadLock is only accessed on the IPDL actor thread. → Bug 1855742 - Part 7. Ensure TextureClient's mReadLock is only created on the IPDL actor thread.
Blocks: 1870128
Pushed by aosmond@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/711b3f47e380 Part 1. Add/update owning thread assertions to CanvasChild/DrawEventRecorder. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/4bfa0d4913a2 Part 2. Allow nsExpirationTracker to be created on any thread. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/13e806495fb8 Part 3. Implement ImageBridgeChild::GetTileLockAllocator. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/2028c7018977 Part 4. Make CanvasManagerChild manage ActiveResourceTracker. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/5b2a89a61f7f Part 5. Refactor canvas shutdown to be synchronized with CanvasManagerChild. r=lsalzman https://hg.mozilla.org/integration/autoland/rev/2061271c53e8 Part 6. Ensure that CanvasChild::OnTextureForwarded can be called from forwarder thread. r=lsalzman https://hg.mozilla.org/integration/autoland/rev/d4bfe15c07ec Part 7. Ensure TextureClient's mReadLock is only created on the IPDL actor thread. r=lsalzman https://hg.mozilla.org/integration/autoland/rev/40cba2c51b1c Part 8. Make OffscreenCanvas use PersistentBufferProvider on the display pipeline. r=lsalzman https://hg.mozilla.org/integration/autoland/rev/8ed51e7d1c98 Part 9. Allow CanvasDrawEventRecorder to be created on DOM workers. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/db60743295fb Part 10. Allow recording surfaces and textures to be created on DOM workers. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/7704291111b4 Part 11. Allow recording based canvases with OffscreenCanvas. r=gfx-reviewers,lsalzman

Backed out 12 changesets (Bug 1795296, Bug 1855742) as requested by aosmond a=backout
Link: https://hg.mozilla.org/mozilla-central/rev/3fd71c45d9fc05e5912ec6c9ba191a9a3a7f2038

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 123 Branch → ---
Depends on: 1870957

Comment on attachment 9355624 [details]
Bug 1855742 - Part 1. Add/update owning thread assertions to CanvasChild/DrawEventRecorder.

Revision D189526 was moved to bug 1870957. Setting attachment 9355624 [details] to obsolete.

Attachment #9355624 - Attachment is obsolete: true

Comment on attachment 9355625 [details]
Bug 1855742 - Part 2. Allow nsExpirationTracker to be created on any thread.

Revision D189527 was moved to bug 1870957. Setting attachment 9355625 [details] to obsolete.

Attachment #9355625 - Attachment is obsolete: true

Comment on attachment 9355627 [details]
Bug 1855742 - Part 4. Make CanvasManagerChild manage ActiveResourceTracker.

Revision D189529 was moved to bug 1870957. Setting attachment 9355627 [details] to obsolete.

Attachment #9355627 - Attachment is obsolete: true

Comment on attachment 9366318 [details]
Bug 1855742 - Part 5. Refactor canvas shutdown to be synchronized with CanvasManagerChild.

Revision D195120 was moved to bug 1870957. Setting attachment 9366318 [details] to obsolete.

Attachment #9366318 - Attachment is obsolete: true
Attachment #9355626 - Attachment description: Bug 1855742 - Part 3. Implement ImageBridgeChild::GetTileLockAllocator. → Bug 1855742 - Part 1. Implement ImageBridgeChild::GetTileLockAllocator.
Attachment #9366319 - Attachment description: Bug 1855742 - Part 6. Ensure that CanvasChild::OnTextureForwarded can be called from forwarder thread. → Bug 1855742 - Part 2. Ensure that CanvasChild::OnTextureForwarded can be called from forwarder thread.
Attachment #9366321 - Attachment description: Bug 1855742 - Part 7. Ensure TextureClient's mReadLock is only created on the IPDL actor thread. → Bug 1855742 - Part 3. Ensure TextureClient's mReadLock is only created on the IPDL actor thread.
Attachment #9366322 - Attachment description: Bug 1855742 - Part 8. Make OffscreenCanvas use PersistentBufferProvider on the display pipeline. → Bug 1855742 - Part 4. Make OffscreenCanvas use PersistentBufferProvider on the display pipeline.
Attachment #9355628 - Attachment description: Bug 1855742 - Part 9. Allow CanvasDrawEventRecorder to be created on DOM workers. → Bug 1855742 - Part 5. Allow CanvasDrawEventRecorder to be created on DOM workers.
Attachment #9355629 - Attachment description: Bug 1855742 - Part 10. Allow recording surfaces and textures to be created on DOM workers. → Bug 1855742 - Part 6. Allow recording surfaces and textures to be created on DOM workers.
Attachment #9355630 - Attachment description: Bug 1855742 - Part 11. Allow recording based canvases with OffscreenCanvas. → Bug 1855742 - Part 7. Allow recording based canvases with OffscreenCanvas.

Comment on attachment 9366322 [details]
Bug 1855742 - Part 4. Make OffscreenCanvas use PersistentBufferProvider on the display pipeline.

Revision D195124 was moved to bug 1870488. Setting attachment 9366322 [details] to obsolete.

Attachment #9366322 - Attachment is obsolete: true

Comment on attachment 9355626 [details]
Bug 1855742 - Part 1. Implement ImageBridgeChild::GetTileLockAllocator.

Revision D189528 was moved to bug 1870488. Setting attachment 9355626 [details] to obsolete.

Attachment #9355626 - Attachment is obsolete: true

Comment on attachment 9366321 [details]
Bug 1855742 - Part 3. Ensure TextureClient's mReadLock is only created on the IPDL actor thread.

Revision D195123 was moved to bug 1870488. Setting attachment 9366321 [details] to obsolete.

Attachment #9366321 - Attachment is obsolete: true

This patch makes us block on the DOM worker thread in order to
synchronize properly with canvas 2D recordings when toDataURL and toBlob
are called on an HTMLCanvasElement object which also called
transferControlToOffscreen and transferred it to a DOM worker.

Attachment #9355628 - Attachment description: Bug 1855742 - Part 5. Allow CanvasDrawEventRecorder to be created on DOM workers. → Bug 1855742 - Part 2. Allow CanvasDrawEventRecorder to be created on DOM workers.
Attachment #9355630 - Attachment description: Bug 1855742 - Part 7. Allow recording based canvases with OffscreenCanvas. → Bug 1855742 - Part 3. Allow recording based canvases with OffscreenCanvas.
Attachment #9366319 - Attachment is obsolete: true
Attachment #9355629 - Attachment is obsolete: true
Pushed by aosmond@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f66c5fdebb25 Part 1. Make HTMLCanvasElement toDataURL and toBlob compatible with recordings. r=lsalzman https://hg.mozilla.org/integration/autoland/rev/58bcf426c7f9 Part 2. Allow CanvasDrawEventRecorder to be created on DOM workers. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/b495e60e1b81 Part 3. Allow recording based canvases with OffscreenCanvas. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/008b68c8dccf Part 4. Enable accelerated canvas backend with OffscreenCanvas. r=lsalzman
Regressions: 1884737
Blocks: 1879833
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: