f32: add Affine2D.Split

splitTransform func was creating multiple copies of f32.Affine2D
due to not having access to the internal and passing around non-pointer.

This makes splitTransform from ~8ns to .Split ~2ns.

It seems that the non-pointer receiver was ~0.6ns slower in this case.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2022-07-01 22:30:40 +03:00
committed by Elias Naur
parent 3670f70c01
commit 9de13e37e9
2 changed files with 11 additions and 11 deletions
+9
View File
@@ -112,6 +112,15 @@ func (a Affine2D) Elems() (sx, hx, ox, hy, sy, oy float32) {
return a.a + 1, a.b, a.c, a.d, a.e + 1, a.f
}
// Split a transform into two parts, one which is pure offset and the
// other representing the scaling, shearing and rotation part.
func (a *Affine2D) Split() (srs Affine2D, offset Point) {
return Affine2D{
a: a.a, b: a.b, c: 0,
d: a.d, e: a.e, f: 0,
}, Point{X: a.c, Y: a.f}
}
func (a Affine2D) scale(factor Point) Affine2D {
return Affine2D{
(a.a+1)*factor.X - 1, a.b * factor.X, a.c * factor.X,
+2 -11
View File
@@ -821,15 +821,6 @@ func (d *drawOps) addClipPath(state *drawState, aux []byte, auxKey opKey, bounds
state.cpath = npath
}
// split a transform into two parts, one which is pure offset and the
// other representing the scaling, shearing and rotation part
func splitTransform(t f32.Affine2D) (srs f32.Affine2D, offset f32.Point) {
sx, hx, ox, hy, sy, oy := t.Elems()
offset = f32.Point{X: ox, Y: oy}
srs = f32.NewAffine2D(sx, hx, 0, hy, sy, 0)
return
}
func (d *drawOps) save(id int, state f32.Affine2D) {
if extra := id - len(d.states) + 1; extra > 0 {
d.states = append(d.states, make([]f32.Affine2D, extra)...)
@@ -889,7 +880,7 @@ loop:
op.Decode(encOp.Data)
quads.key.outline = op.Outline
bounds := f32.FRect(op.Bounds)
trans, off := splitTransform(state.t)
trans, off := state.t.Split()
if len(quads.aux) > 0 {
// There is a clipping path, build the gpu data and update the
// cache key such that it will be equal only if the transform is the
@@ -935,7 +926,7 @@ loop:
// Transform (if needed) the painting rectangle and if so generate a clip path,
// for those cases also compute a partialTrans that maps texture coordinates between
// the new bounding rectangle and the transformed original paint rectangle.
t, off := splitTransform(state.t)
t, off := state.t.Split()
// Fill the clip area, unless the material is a (bounded) image.
// TODO: Find a tighter bound.
inf := float32(1e6)