Closed Bug 1676299 Opened 4 years ago Closed 2 years ago

Modify BaseMatrix::ScaleFactors() to return a ScaleFactors2D

Categories

(Core :: Graphics, task, P5)

task

Tracking

()

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- fixed

People

(Reporter: botond, Assigned: dlrobertson, Mentored)

References

Details

(Whiteboard: [lang=c++])

Attachments

(5 files, 3 obsolete files)

BaseMatrix::ScaleFactors() returns a SizeTyped which represents a pair of x- and y-scales.

We now have a ScaleFactors2D type that's more suited for this purpose.

This is a good mentored bug for someone with a moderate level of C++ experience and some patience to propagate the effects of this change to other affected APIs.

Mentor: botond
Whiteboard: [lang=c++]
Severity: -- → N/A
Priority: -- → P5

Hi folks,

May I take this task?

Sure!

The first step would be to build Firefox from source using the instructions found here.

Once you've done that, please post here again and I'll provide some more details on how to go about this. If you're eager to get started with code reading and such, the function in question is defined here, and the Searchfox code browser tool is really helpful for things like finding all call sites of it.

Hi again,

I've just finished the build so I guess we can continue :-)

Great! I've assigned the bug to you.

So, if you take a look at the declaration of ScaleFactors() linked from comment 3, you can see its return type is MatrixSize.

If you click on "go to latest version" in the navigation sidebar, you'll get a view of the same code with additional code navigation features enabled. You can now do things like navigate to the definition of a name by left-clicking on it and choosing "Go to definition" in the context menu that comes up, and find all usages of a name by choosing "Search for function" or "Search for type" in the same context menu.

If we go to the definition of MatrixSize, we can see it's a typedef for SizeTyped<UnknownUnits, T>, where T is a template parameter of BaseMatrix, and UnknownUnits is a concrete type.

If you're wondering what UnknownUnits is, we have a set of tag types we use to represent quantities in different coordinate systems as different types. For example, we might use SizeTyped<CSSPixel, float> for a single-precision floating-point size in the "CSS" coordinate system, and SizeTyped<LayerPixel, float> for a single-precision floating-point size in the "Layer" coordinate system. CSSPixel and LayerPixel are just empty tag types used to achieve this type safety. Sometimes, however, we work with quantities that are not explicitly labelled as being in one of these tagges coordinate systems, so we have a catch-all UnknownUnits type for that.

BaseMatrix is also not parameterized on any unit types, only on the representation type (e.g. T=float), which is why it uses UnknownUnits for things like the return type of ScaleFactors(). We're not looking to change that in this bug, so in changing the return type from SizeTyped to ScaleFactors2D, we'll continue using UnknownUnits. For ScaleFactors2D, both of its template parameters are unit types (since it can potentially be used to convert between different coordinate systems), so we'll use UnknownUnits for both, i.e. ScaleFactors2D<UnknownUnits, UnknownUnits>.

So the idea here is:

  • Change the return type of ScaleFactors() from SizeTyped<UnknownUnits> to ScaleFactors2D<UnknownUnits, UnknownUnits>. Feel free to use a suitable typedef, such as MatrixScale. Update the implementation of the function accordingly.
  • Use Searchfox's find-references feature to find the callers of ScaleFactors(), and make any adjustments necessary to reflect the change in signature at each call site. Note that the current implementation stores the x-scale in SizeTyped::width and the y-scale in SizeTyped::height, so a lot of the changes will involve changing accesses to width and height to accesses to the ScaleFactors2D fields xScale and yScale.

That should be enough to get you started! If you have any questions, please feel free to ask here, or in the #apz chat channel.

Assignee: nobody → coderboncuk

(In reply to Botond Ballo [:botond] from comment #5)

Note that the current implementation stores the x-scale in SizeTyped::width and the y-scale in SizeTyped::height

I just noticed ScaleFactors() has an xMajor parameter which inverts the interpretation of width and height if it's set to false. However, all callers are passing in true. I would suggest simplifying the code by removing this parameter. It's probably easiest to do that in a first patch, and the change of return type in a second patch.

Attachment #9188119 - Attachment is obsolete: true
Pushed by bballo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/efac962c3870
Removed the xMajor parameter from BaseMatrix::ScaleFactors() r=botond

Adding leave-open keyword as this was just the first of two patches.

Keywords: leave-open

The leave-open keyword is there and there is no activity for 6 months.
:jimm, maybe it's time to close this bug?

Flags: needinfo?(jmathies)

The second patch needs to be updated and land before this bug can be closed.

Flags: needinfo?(jmathies)
Keywords: leave-open

The bug assignee didn't login in Bugzilla in the last 7 months.
:bhood, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: coderboncuk → nobody
Flags: needinfo?(bhood)
Flags: needinfo?(bhood)
Assignee: nobody → drobertson

Do we need to add another template parameter to ScaleFactors2D for this change? xScale and yScale are always float in ScaleFactors2D. Assuming we're dealing with a MatrixDouble we'd end up adding some type conversions here right? Or am I misreading something?

(In reply to Dan Robertson (:dlrobertson) from comment #16)

Do we need to add another template parameter to ScaleFactors2D for this change? xScale and yScale are always float in ScaleFactors2D. Assuming we're dealing with a MatrixDouble we'd end up adding some type conversions here right? Or am I misreading something?

Yep, good catch. I guess the proper solution is to give ScaleFactors2D an additional template parameter for the representation (possibly renaming the type to BaseScaleFactors2D, with ScaleFactors2D and ScaleFactors2DDouble template aliases).

It probably makes sense to do that first in one patch, and then change BaseMatrix::ScaleFactors() in a second patch?

Yeah that sounds good!

This renames ScaleFactors2D to BaseScaleFactors2D and adds a template
parameter to specify the floating point type to use. This lays the
groudwork for a later patch that will use ScaleFactors2D and
ScaleFactors2DDouble in some cases where SizedTyped is used.

This renames ScaleFactors2D to BaseScaleFactors2D and adds a template
parameter to specify the floating point type to use. This lays the
groudwork for a later patch that will use ScaleFactors2D and
ScaleFactors2DDouble where SizedTyped is used.

Attachment #9273553 - Attachment is obsolete: true

This changes BaseMatrix::ScaleFactors() to return a ScaleFactors2D instead of
a SizeTyped.

Depends on D144304

  • Ensure the xScale and yScale are both 1 before returning from
    PrescaleAndTileDrawable early.
  • Use ScaleFactors2D instead of converting the result of ScaleFactors to a
    SizeTyped.

Depends on D144666

Attachment #9273770 - Attachment description: Bug 1676299 Part 3: Modify PrescaleAndTileDrawable() to use a ScaleFactors2D. r=botond,mstange → Bug 1676299 Part 2: Check height before exiting PrescaleAndTileDrawable() early. r=botond,mstange

Only return early from PaintFilteredFrame if the scale matrix determinant will
be zero. This should only occur if both the height and width of the context
matrix scale factors are zero.

Depends on D144669

Attachment #9273767 - Attachment description: Bug 1676299 Part 2: Modify BaseMatrix::ScaleFactors() to return a ScaleFactors2D. r=botond → Bug 1676299 Part 4: Modify BaseMatrix::ScaleFactors() to return a ScaleFactors2D. r=botond
Attachment #9188945 - Attachment is obsolete: true
Pushed by bballo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/2c5e69bc5135
Part 1: Add the ScaleFactors2DDouble type definition. r=botond
https://hg.mozilla.org/integration/autoland/rev/6bfbe006c06b
Part 2: Check height before exiting PrescaleAndTileDrawable() early. r=mstange
https://hg.mozilla.org/integration/autoland/rev/f151d3e96557
Part 3: Limit early return from PaintFilteredFrame. r=botond
https://hg.mozilla.org/integration/autoland/rev/72ad6dabccc5
Part 4: Modify BaseMatrix::ScaleFactors() to return a ScaleFactors2D. r=botond
Blocks: 1767120
Blocks: 1767121
Blocks: 1767122
Blocks: 1767123
Blocks: 1767124
Blocks: 1767125
Blocks: 1767126
Blocks: 1767127
Blocks: 1770289
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: