Open Bug 1562214 Opened 7 years ago Updated 1 year ago

DOMMatrix does not keep sign bit with -0

Categories

(Core :: DOM: Core & HTML, defect, P3)

69 Branch
defect

Tracking

()

Tracking Status
firefox69 --- affected

People

(Reporter: saschanaz, Unassigned)

References

(Blocks 1 open bug, )

Details

(Whiteboard: [domcore-bugbash-triaged])

const x = new DOMMatrix();
x.m13 = -0;
x.is2D // true as expected
x.m13 // expected -0, actual 0

This is because we don't store 3D elements on a 2D matrix and instead always return the default values for them. Fixing this doesn't seem to be simple and pretty, maybe we have to always use a 3D matrix, or we define dedicated members for the sign bits, either way not very pretty.

:bzbarsky, What do you think?

Flags: needinfo?(bzbarsky)

I need to think about this a bit...

So I guess one question is: is there a good reason to store the 2d case as a 2d matrix? Does it really materially affect performance of anything? I guess it saves a bit of memory...

Kip, do you know who might know this? You seem to be somewhat familiar with the 3d matrix code....

Flags: needinfo?(bzbarsky) → needinfo?(kgilbert)

When implementing fixes for CSS 3d transforms some time back, I encountered this code. IIUC, other than the performance / memory overhead of handing the additional members, the 2d operations could be performed with the same functions by populating the top 3x3 portion of the Matrix4x4. Some functions may be missing in the Matrix4x4; however, and need to be implemented -- integer rounding functions come to mind.

At the time, I did not have the confidence to unify the code, but could certainly see some advantages to doing so.

I would expect much of the overhead being introduced by code in Matrix4x4 that deals with various edge cases such as reversing projection matrices and calculating bounds of transformed homogeneous coordinates. Perhaps checks for these cases are not needed so much for the 2d variants.

I hope this helps!

Flags: needinfo?(kgilbert)
Priority: -- → P3

So I think we have the following options, at least:

  1. When -0 is set, switch to a Matrix4x4, but keep claiming "is2d" is true to script while working with the Matrix4x4 under the hood.

  2. Keep track of the -0 out-of-band, with 8 booleans that can be set to true to indicate that the relevant property is -0 instead of 0, and modify accessors for the relevant properties and the DOMMatrixReadOnly::Ensure3DMatrix code to consult those booleans.

Thoughts on which of those would work better? Any other ideas? This is our last DOMMatrix test failure so it might be nice to wrap it up...

Flags: needinfo?(kgilbert)

I suspect that adding so many booleans and conditional logic would be less performant than just doing the math on the whole 4x4 matrix every time. I've got to dig in a bit deeper to see what is precisely happening, so will leave NI up and follow up further.

Another option is to change the spec to match what Gecko does, or to set is2D to false when assigning -0.

to set is2D to false when assigning -0.

I like this, as a 2D matrix containing 3D information is just nonsense.

Simon, if there's interest in that from other browsers, that would be just fine, obviously. :)

Clearing NI. Answer was in Comment 3.

Flags: needinfo?(kgilbert)
Severity: normal normal → S3 S3
Whiteboard: [domcore-bugbash-triaged]
You need to log in before you can comment on or make changes to this bug.