Comments (2)
Clipping to integer pixel axis aligned rects has a very different implementation than arbitrary geometry.
Is the idea that this method would only allow integer coords, and wouldn't be affected by the context's CTM, like getImageData
and putImageData
do?
If so, that naming sounds too close to fillRect()
and strokeRect()
which are affected by the current CTM and can be drawn at non integer coordinates.
From what I can tell, Skia's and CoreGraphics's versions also are affected by the context's transform and both accept floating point coords for their rect
param.
If there is indeed a very different implementation for "integer pixel axis aligned rects", and assuming it's more performant, shouldn't this be part of an implementation's optimizations rather than a new method on the already "well-stocked" API?
Looking a bit on the internets, it seems that ctx.rect(...); ctx.clip();
was somehow confusing to some web-devs who forgot to call beginPath()
, but I believe the Path2D
interface solves this issue, and if one really wants a fillRect()
version of clip()
they could write one really easily, so I'm not entirely sure there would be much benefit for such a method.
function clipRect(ctx, x, y, w, h) {
const path = new Path2D();
path.rect(x, y, w, h);
ctx.clip(path);
}
from canvas2d.
The proposed function would have the same semantics as:
function clipRect(ctx, x, y, w, h) {
const path = new Path2D();
path.rect(x, y, w, h);
ctx.clip(path);
}
The advantage is that it's more performant than the more general JS implementation:
- It avoids the object allocation (it's unlikely escape analysis would be able to do this because
path
escapes intoclip()
) - It avoids having to do rectangle detection on the path: https://searchfox.org/mozilla-central/rev/17aeb39742eba71e0936ae44a51a54197100166d/gfx/skia/skia/src/core/SkPath.cpp#3562
- It gives more predictable performance. Firefox doesn't currently detect and fast path clipping to a rectangle when using Direct2D for canvas on Windows.
from canvas2d.
Related Issues (20)
- Serialization of CanvasFilters HOT 1
- CanvasFilters - Even <feImage>?
- CanvasFilters - How do we set the dimensions of the filter? HOT 3
- Reset / Clear
- Text Modifiers — Variable Fonts HOT 1
- Color Input - P3 examples HOT 1
- Proposals HOT 11
- roundRect requiring an array HOT 6
- Make CSS filters work with `CanvasFilter` HOT 3
- Use GLES fragment shader as filters
- Gradient spread methods
- Arbitrary gradient transforms HOT 3
- Integer only coordinate space mode. HOT 7
- `beginLayer` vs `beginFilter` HOT 2
- Web platform brianstorm meeting in California
- Make canvas2d faster than Webgl
- [Mesh2D] Triangle order HOT 2
- [Mesh] constructors vs factory functions HOT 1
- [Mesh] are the objects necessary at all? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvas2d.