Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #14954 - Add willReadFrequently: true to CanvasLayerRenderer context generation settings #15497

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Menecats
Copy link

Fixes #14954 by adding willReadFrequently in context generation settings for CanvasLayerRenderer.

…ation settings in CanvasLayerRenderer
@Menecats Menecats marked this pull request as ready for review January 21, 2024 23:24
@mike-000
Copy link
Contributor

This will disable hardware acceleration and reduce rendering performance. What are you doing to produce the warning?

@Menecats
Copy link
Author

Hi @mike-000, I'm getting this message when reading the canvas image data directly inside a postrender event handler (see following partial code).

I've tought of adding a configuration option that would allow the user to specify the getContext options directly but I was unsure of where to place it. (my general idea was: new ImageLayer({ source: [...], contextSettings: {willReadFrequently: true}))

My code that produces the warning:

const layer = new ImageLayer({
  source: [...]
});

layer.on('prerender', e => {
  // Draw mask that will block part of the view

  e.context.globalCompositeOperation = 'source-in';
});

layer.on('postrender', e => {
  e.context.globalCompositeOperation = 'source-atop';

  // Tint part of the view

  const imageData = e.context.getImageData(0, 0, canvasWidth, canvasHeight);

  // Send the image data via presentation API to a chromecast or other low power casting device
});

@ahocevar
Copy link
Member

In this case the warning issued by the Developer Console is not appropriate. Because you create content on the canvas, read it, and then create new content and read it again. I don't think the willReadFrequently: true flag would improve the overall performance here. It would be interesting to benchmark this use case.

@Menecats Menecats marked this pull request as draft February 29, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canvas2D warning
3 participants