processing / processing/p5.js

Add 'willReadFrequently' option to certain getContext('2d') calls

Open
#5,840 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Core Enhancement
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Increasing Access

Making canvas operations more performant would make sketches run better on mobile and lower-end hardware.

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)
Feature enhancement details

When using tint() I get a canvas2d warning that says:

Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true.

The canvas specs say that passing { willReadFrequently: true } to getContext() will disable hardware acceleration on the canvas, making it perform better with getImageData(). This looks like a recent addition for Chrome at least? It's discussed in a blog post here

Would this be something that would be helpful to add wherever getImageData() is called?

Below is an example that triggers this warning. In this case it's the Filters._toPixels() call in p5.Renderer2D.prototype._getTintedImageCanvas.

let pg0;

function setup() {
  createCanvas(400, 400);
  
  pg0 = createGraphics(400,400);

}

function draw() {
  background(220);
  
  tint(255, 100);
  image(pg0,0,0);
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by searching the rendering code for getImageData(), especially Filters._toPixels() and p5.Renderer2D.prototype._getTintedImageCanvas, which the report identifies as the warning path. Check the related canvas getContext('2d') calls and existing rendering tests, if present. Done means the affected readback path no longer produces the reported warning without changing the expected tint behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.