Closed Bug 809199 Opened 12 years ago Closed 12 years ago

Eliminate ViewportMetrics.java in favor of ImmutableViewportMetrics

Categories

(Firefox for Android Graveyard :: Toolbar, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 19

People

(Reporter: kats, Assigned: kats)

References

Details

Attachments

(10 files)

11.62 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
16.97 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
2.95 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
14.86 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
3.60 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
8.25 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
6.08 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
21.24 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
6.98 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
4.14 KB, patch
cwiiis
: review+
Details | Diff | Splinter Review
Since we added ImmutableViewportMetrics, the old ViewportMetrics class just sort of gets in the way. It's mutable so harder to reason about, and creates a bunch of internal RectF objects which adds to java heap stress. I'd like to get rid of the old ViewportMetrics and switch all of the code over to using ImmutableViewportMetrics. The patches do the job in pieces for (hopefully) easier reviewing. Intermediate patches may introduce some "new ViewportMetrics(immutableVersion)" and "new ImmutableViewportMetrics(mutableVersion)" calls but these temporary conversions get taken out in subsequent patches as more of the code gets converted.
Attachment #678881 - Flags: review?(chrislord.net)
Attachment #678888 - Flags: review?(chrislord.net)
Comment on attachment 678881 [details] [diff] [review] Part 1 - Move interpolation code to ImmutableViewportMetrics Review of attachment 678881 [details] [diff] [review]: ----------------------------------------------------------------- Looks fine to me.
Attachment #678881 - Flags: review?(chrislord.net) → review+
Comment on attachment 678883 [details] [diff] [review] Part 2 - Modify PanZoomTarget methods Review of attachment 678883 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me. ::: mobile/android/base/ui/PanZoomController.java @@ +259,5 @@ > public void pageRectUpdated() { > if (mState == PanZoomState.NOTHING) { > synchronized (mTarget.getLock()) { > + ImmutableViewportMetrics validated = getValidViewportMetrics(); > + if (! getMetrics().fuzzyEquals(validated)) { Do we normally put spaces after the ! ? Might be a good opportunity to get rid of it.
Attachment #678883 - Flags: review?(chrislord.net) → review+
Comment on attachment 678884 [details] [diff] [review] Part 3 - Add an offsetViewportBy function Review of attachment 678884 [details] [diff] [review]: ----------------------------------------------------------------- LGTM. ::: mobile/android/base/ui/PanZoomController.java @@ +486,5 @@ > } > > private void scrollBy(PointF point) { > + ImmutableViewportMetrics scrolled = getMetrics().offsetViewportBy(point); > + mTarget.setViewportMetrics(scrolled); This is much nicer... Not sure why we didn't add an offset convenience function before...
Attachment #678884 - Flags: review?(chrislord.net) → review+
Comment on attachment 678885 [details] [diff] [review] Part 4 - Remove ViewportMetrics from PZC Review of attachment 678885 [details] [diff] [review]: ----------------------------------------------------------------- Fine, but would like to see comments addressed if they aren't already in a later patch. ::: mobile/android/base/gfx/ImmutableViewportMetrics.java @@ +154,2 @@ > public ImmutableViewportMetrics offsetViewportBy(PointF delta) { > + return setViewportOrigin(new PointF(viewportRectLeft + delta.x, viewportRectTop + delta.y)); Wasn't part of the point of this to stop creating objects so much... But you're replacing the code you added here with a new PointF? @@ +178,5 @@ > + origin.x, origin.y, origin.x + getWidth(), origin.y + getHeight(), > + newZoomFactor); > + } > + > + /** Clamps the viewport to the page size. */ nit, would rather this said something along the lines of "Clamps the viewport to reamain within the page rect" ::: mobile/android/base/ui/PanZoomController.java @@ +727,3 @@ > } > > + private ImmutableViewportMetrics getValidViewportMetrics(ImmutableViewportMetrics viewportMetrics) { This now creates two sets of ViewportMetrics. It would be nice to be able to do this with just creating the returned metrics. @@ +1036,5 @@ > + ImmutableViewportMetrics finalMetrics = getMetrics(); > + finalMetrics = finalMetrics.setViewportOrigin( > + new PointF(zoomToRect.left * finalMetrics.zoomFactor, > + zoomToRect.top * finalMetrics.zoomFactor)); > + finalMetrics = finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f)); Same here.
Attachment #678885 - Flags: review?(chrislord.net) → review+
Comment on attachment 678886 [details] [diff] [review] Part 5 - Update createViewportEvent Review of attachment 678886 [details] [diff] [review]: ----------------------------------------------------------------- Yup.
Attachment #678886 - Flags: review?(chrislord.net) → review+
Comment on attachment 678887 [details] [diff] [review] Part 6 - Switch mGeckoViewport to be an IVM Review of attachment 678887 [details] [diff] [review]: ----------------------------------------------------------------- mmhmm.
Attachment #678887 - Flags: review?(chrislord.net) → review+
Comment on attachment 678888 [details] [diff] [review] Part 7 - Update JNI code Review of attachment 678888 [details] [diff] [review]: ----------------------------------------------------------------- I assume that after all these patches, the methods line up for the JNI change here to be correct.
Attachment #678888 - Flags: review?(chrislord.net) → review+
Comment on attachment 678890 [details] [diff] [review] Part 8 - Delete ViewportMetrics.java Review of attachment 678890 [details] [diff] [review]: ----------------------------------------------------------------- Great :) My last comment, the set* functions are a little confusingly named now as they don't set anything... But then, the class has 'Immutable' in the name, so I guess that ought to be obvious. Of course, now we only have ImmutableViewportMetrics, you could argue it should be renamed to ViewportMetrics, but I think that argument would, on the whole, be wrong. It's a shame that there is still an amount of copying going on here, but it's likely a lot less than before, so great! The code reads much nicer now too, so well done :)
Attachment #678890 - Flags: review?(chrislord.net) → review+
(In reply to Chris Lord [:cwiiis] from comment #10) > Do we normally put spaces after the ! ? Might be a good opportunity to get > rid of it. Fixed. That space was probably my fault - it's my non-Mozilla coding style leaking through :) (In reply to Chris Lord [:cwiiis] from comment #12) > Wasn't part of the point of this to stop creating objects so much... But > you're replacing the code you added here with a new PointF? Good point (pun!). I've modified the setViewportOrigin method to now take two floats instead of a PointF, which eliminates the unnecessary PointF object creation from both places it is called. > > + /** Clamps the viewport to the page size. */ > > nit, would rather this said something along the lines of "Clamps the > viewport to reamain within the page rect" Done. > > + private ImmutableViewportMetrics getValidViewportMetrics(ImmutableViewportMetrics viewportMetrics) { > > This now creates two sets of ViewportMetrics. It would be nice to be able to > do this with just creating the returned metrics. > > @@ +1036,5 @@ > > + ImmutableViewportMetrics finalMetrics = getMetrics(); > > + finalMetrics = finalMetrics.setViewportOrigin( > > + new PointF(zoomToRect.left * finalMetrics.zoomFactor, > > + zoomToRect.top * finalMetrics.zoomFactor)); > > + finalMetrics = finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f)); > > Same here. Agreed. I did think about that but it seemed like it would be pretty ugly since I would need a method on IVM that does both transformations, so I figured I would leave it like this for now and have another patch at the end that tries to remove as many of these extra object creations as possible. As it is this version creates fewer objects than the old one; they just happen to be IVMs instead of RectF and PointFs.
I would argue that this even makes better sense semantically since a PointF shouldn't be used to carry around a delta :) I can see a few more changes like these but a lot of the remaining functions are used throughout LayerRenderer, and I would like to clean up that code before tackling them, so I'll do that in a separate bug.
Attachment #679151 - Flags: review?(chrislord.net)
Comment on attachment 679150 [details] [diff] [review] Part 9 - Update setViewportSize to not use PointFs Review of attachment 679150 [details] [diff] [review]: ----------------------------------------------------------------- Great :)
Attachment #679150 - Flags: review?(chrislord.net) → review+
Comment on attachment 679151 [details] [diff] [review] Part 10 - Update offsetViewportBy to not take a PointF Review of attachment 679151 [details] [diff] [review]: ----------------------------------------------------------------- Great!
Attachment #679151 - Flags: review?(chrislord.net) → review+
Depends on: 810764
Depends on: 810933
This has triggered a major regression in ability to scroll pages; see bug 810933. Recommending back-out here.
Pushed a backout try to make sure it still builds and nothing else depends on it: https://tbpl.mozilla.org/?tree=Try&rev=c32396a03323. If it's green I'll push to inbound. Looking into why this breakage happened at all.
(In reply to Kartikaya Gupta (:kats) from comment #25) > Pushed a backout try to make sure it still builds and nothing else depends > on it: https://tbpl.mozilla.org/?tree=Try&rev=c32396a03323. If it's green > I'll push to inbound. Looking into why this breakage happened at all. I found the problem and have a patch on bug 801933. Will leave this closed and won't back it out.
No longer depends on: 810764
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: