Closed
Bug 727352
Opened 14 years ago
Closed 14 years ago
don't use JSON for viewport meta data
Categories
(Firefox for Android Graveyard :: Toolbar, defect, P4)
Tracking
(blocking-fennec1.0 -)
RESOLVED
FIXED
Firefox 18
| Tracking | Status | |
|---|---|---|
| blocking-fennec1.0 | --- | - |
People
(Reporter: blassey, Assigned: blassey)
References
Details
(Whiteboard: [viewport])
Attachments
(1 file, 8 obsolete files)
|
20.16 KB,
patch
|
mfinkle
:
review+
kats
:
review+
|
Details | Diff | Splinter Review |
No description provided.
Attachment #597286 -
Flags: review?(mark.finkle)
Attachment #597286 -
Flags: review?(bugmail.mozilla)
Comment 1•14 years ago
|
||
Comment on attachment 597286 [details] [diff] [review]
patch
Review of attachment 597286 [details] [diff] [review]:
-----------------------------------------------------------------
Overall it looks ok, but this will make it much harder to change the viewport object. Do you know how much of an improvement you get with this? Also we should make sure this doesn't inadvertently break XUL Fennec.
::: mobile/android/base/GeckoAppShell.java
@@ +1437,2 @@
> {
> + ViewportMetrics metadata = new ViewportMetrics(metaX, metaY, metaWidth, metaHeight, pageWidth, pageHeight, offsetX, offsetY, zoom);
Can we create the ViewportMetrics object in native instead so we don't have massive parameter lists everywhere?
@@ +1460,2 @@
> {
> + ViewportMetrics metadata = new ViewportMetrics(metaX, metaY, metaWidth, metaHeight, pageWidth, pageHeight, offsetX, offsetY, zoom);
ditto
::: mobile/android/base/gfx/GeckoSoftwareLayerClient.java
@@ +191,5 @@
>
> public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight,
> + float metaX, float metaY, float metaWidth, float metaHeight,
> + float pageWidth, float pageHeight, float offsetX, float offsetY,
> + float zoom, boolean hasDirectTexture, String backgroundColorString) {
ditto
| Assignee | ||
Comment 2•14 years ago
|
||
Assignee: nobody → blassey.bugs
Attachment #597286 -
Attachment is obsolete: true
Attachment #597624 -
Flags: review?(mark.finkle)
Attachment #597624 -
Flags: review?(bugmail.mozilla)
Attachment #597286 -
Flags: review?(mark.finkle)
Attachment #597286 -
Flags: review?(bugmail.mozilla)
Comment 3•14 years ago
|
||
Comment on attachment 597624 [details] [diff] [review]
patch
Review of attachment 597624 [details] [diff] [review]:
-----------------------------------------------------------------
Much cleaner, thanks. r+ with the fix for GeckoAppShell.addPluginView and verifying mViewportMetricsClass doesn't break XUL, as noted below.
::: mobile/android/base/GeckoAppShell.java
@@ +1437,2 @@
> {
> + ViewportMetrics metadata = new ViewportMetrics(metaX, metaY, metaWidth, metaHeight, pageWidth, pageHeight, offsetX, offsetY, zoom);
This signature (GeckoAppShell.addPluginView, because Splinter won't include proper patch context) hasn't been updated to take a ViewportMetrics, even though the code in nsPluginInstanceOwner.cpp that calls it passes in a ViewportMetrics. This probably fails at runtime on a page with plugins.
::: widget/android/AndroidBridge.cpp
@@ +104,4 @@
> mHasNativeWindowAccess = false;
>
> mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
> + mViewportMetricsClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/ViewportMetrics"));
This might also need to be #ifdef MOZ_JAVA_COMPOSITOR or it may break XUL. It might also just assign mViewportMetricsClass to null, not sure.
::: widget/android/nsAppShell.cpp
@@ +453,5 @@
>
> + case AndroidGeckoEvent::VIEWPORT: {
> + nsTArray<nsIntPoint> size = curEvent->Points();
> + nsTArray<float> data = curEvent->ViewportData();
> + mBrowserFrontend->NotifyViewportChange(data[0], data[1], size[0].x, size[0].y, data[2], data[3], data[4], data[5], data[6]);
It would be nice if there were comments on these parameters, like
mBrowserFrontend->NotifyViewportChange(
data[0], /* viewport left */
data[1], /* viewport top */
...
);
Attachment #597624 -
Flags: review?(bugmail.mozilla) → review+
| Assignee | ||
Comment 4•14 years ago
|
||
ehsan is refactoring our viewport code, this should wait until he's done
Priority: -- → P4
Comment 5•14 years ago
|
||
I measured this line in beginDrawing:
'JSONObject viewportObject = new JSONObject(metadata);'
On an average of 10,000 calls, each call take 0.3ms which is unacceptable.
Blocking on bug 729391 because of that.
Blocks: 729391
Comment 6•14 years ago
|
||
Comment on attachment 597624 [details] [diff] [review]
patch
>diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js
>+ notifyViewportChange: function(x, y, width, height, pageWidth, pageHeight, offsetX, offsetY, zoom) {
>+
>+ this.selectedTab.viewport = {
Remove the blank line
>diff --git a/widget/android/nsIAndroidBridge.idl b/widget/android/nsIAndroidBridge.idl
>+[scriptable, uuid(59cfcb35-69b7-47b2-8155-32b193272666)]
>+interface nsIAndroidDrawMetadata : nsISupports {
>+ readonly attribute float x;
>+ readonly attribute float y;
>+ readonly attribute float width;
>+ readonly attribute float height;
>+ readonly attribute float pageWidth;
>+ readonly attribute float pageHeight;
>+ readonly attribute float offsetX;
>+ readonly attribute float offsetY;
>+ readonly attribute float zoom;
>+ readonly attribute AString backgroundColor;
>+};
> interface nsIBrowserFrontend : nsISupports {
> nsIDOMWindow getWindowForTab(in PRInt32 tabId);
>+ void notifyViewportChange(in float x, in float y, in PRInt32 width, in PRInt32 height, in float pageWidth, in float pageHeight, in float offsetX, in float offsetY, in float zoom);
It might be nicer to just pass a nsIAndroidDrawMetadata here instead of all the individual params. We could do that later.
I focused on the IDL and JS, only giving the Java a high level pass. Looks OK to me.
Attachment #597624 -
Flags: review?(mark.finkle) → review+
Comment 7•14 years ago
|
||
You have been bit rot a bit though.
Updated•14 years ago
|
blocking-fennec1.0: --- → ?
Whiteboard: [viewport]
| Assignee | ||
Updated•14 years ago
|
blocking-fennec1.0: ? → -
Comment 8•14 years ago
|
||
I do not believe we use JSON in places where performance matters that much anymore.
Updated•14 years ago
|
Blocks: checkerboarding
Comment 9•14 years ago
|
||
We do still decode JSON in the Viewport:Change handler in browser.js. See bug 742128.
Updated•14 years ago
|
Component: General → Graphics, Panning and Zooming
| Assignee | ||
Comment 10•14 years ago
|
||
Attachment #597624 -
Attachment is obsolete: true
Attachment #659877 -
Flags: review?(mark.finkle)
Attachment #659877 -
Flags: review?(bugmail.mozilla)
| Assignee | ||
Comment 11•14 years ago
|
||
Attachment #659877 -
Attachment is obsolete: true
Attachment #659877 -
Flags: review?(mark.finkle)
Attachment #659877 -
Flags: review?(bugmail.mozilla)
Attachment #659886 -
Flags: review?(mark.finkle)
Attachment #659886 -
Flags: review?(bugmail.mozilla)
| Assignee | ||
Comment 12•14 years ago
|
||
Attachment #659886 -
Attachment is obsolete: true
Attachment #659886 -
Flags: review?(mark.finkle)
Attachment #659886 -
Flags: review?(bugmail.mozilla)
Attachment #660116 -
Flags: review?(mark.finkle)
Attachment #660116 -
Flags: review?(bugmail.mozilla)
Comment 13•14 years ago
|
||
Testing this patch on the panda board, several Robocop tests fail with:
09-11 17:19:01.812 2107 2125 W dalvikvm: JNI WARNING: instance fieldID 0x56ea45cc not valid for class Landroid/graphics/RectF;
09-11 17:19:01.812 2107 2125 W dalvikvm: in Lorg/mozilla/gecko/GeckoAppShell;.nativeRun:(Ljava/lang/String;)V (GetIntField)
09-11 17:19:01.812 2107 2125 I dalvikvm: "Gecko" prio=5 tid=13 RUNNABLE
09-11 17:19:01.812 2107 2125 I dalvikvm: | group="main" sCount=0 dsCount=0 obj=0x412c01f0 self=0x206bd78
09-11 17:19:01.812 2107 2125 I dalvikvm: | sysTid=2125 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=33970320
09-11 17:19:01.812 2107 2125 I dalvikvm: | schedstat=( 0 0 0 ) utm=269 stm=55 core=1
09-11 17:19:01.812 2107 2125 I dalvikvm: at org.mozilla.gecko.GeckoAppShell.nativeRun(Native Method)
09-11 17:19:01.812 2107 2125 I dalvikvm: at org.mozilla.gecko.GeckoAppShell.nativeRun(Native Method)
09-11 17:19:01.812 2107 2125 I dalvikvm: at org.mozilla.gecko.GeckoAppShell.runGecko(GeckoAppShell.java:545)
09-11 17:19:01.812 2107 2125 I dalvikvm: at org.mozilla.gecko.GeckoThread.run(GeckoThread.java:82)
09-11 17:19:01.812 2107 2125 I dalvikvm:
09-11 17:19:01.812 2107 2125 E dalvikvm: VM aborting
09-11 17:19:01.812 2107 2125 F libc : Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
Comment 14•14 years ago
|
||
Comment 15•14 years ago
|
||
Comment on attachment 660116 [details] [diff] [review]
new patch
Review of attachment 660116 [details] [diff] [review]:
-----------------------------------------------------------------
::: widget/android/AndroidJavaWrappers.cpp
@@ +833,5 @@
> +
> +NS_IMPL_ISUPPORTS1(nsAndroidDisplayport, nsIAndroidDisplayport)
> +
> +void createDisplayPort(JNIEnv* env, jobject jobj, nsIAndroidDisplayport** displayPort) {
> + AndroidRect rect(env, env->CallObjectMethod(jobj, AndroidGeckoLayerClient::jDisplayportGetPosition));
jDisplayPortGetPosition returns an android.graphics.RectF (with float members), but AndroidRect uses integers and keeps a global ref to an android.graphics.Rect -- that's the source of the trouble on the panda board.
| Assignee | ||
Comment 16•14 years ago
|
||
Attachment #660116 -
Attachment is obsolete: true
Attachment #660116 -
Flags: review?(mark.finkle)
Attachment #660116 -
Flags: review?(bugmail.mozilla)
Attachment #660272 -
Flags: review?(mark.finkle)
Attachment #660272 -
Flags: review?(bugmail.mozilla)
| Assignee | ||
Comment 17•14 years ago
|
||
This should fix the issue that Geoff reported with his attached log. Geoff, could you please retest, because I could reproduce what you saw.
Attachment #660272 -
Attachment is obsolete: true
Attachment #660272 -
Flags: review?(mark.finkle)
Attachment #660272 -
Flags: review?(bugmail.mozilla)
Attachment #660282 -
Flags: review?(bugmail.mozilla)
| Assignee | ||
Updated•14 years ago
|
Attachment #660282 -
Flags: review?(mark.finkle)
Updated•14 years ago
|
Attachment #660149 -
Attachment is obsolete: true
Comment 18•14 years ago
|
||
The latest patch fixes the problem I reported. With this patch, we can run robocop tests on the pandas! :)
Comment 19•14 years ago
|
||
Comment on attachment 660282 [details] [diff] [review]
new patch
Looks really good overall. Minusing for now because of the missing error-checking in the AndroidGeckoLayerClient::GetDisplayPort function and the field vs method access, the rest of the things are mostly just nits.
>diff --git a/mobile/android/base/gfx/DisplayPortMetrics.java b/mobile/android/base/gfx/DisplayPortMetrics.java
>+
>+ public RectF getPosition() {
>+ return mPosition;
>+ }
>+
>+ public float getResolution() {
>+ return mResolution;
>+ }
Is there a reason we shouldn't just access the mPosition and mResolution fields from JNI directly? I'd rather not have to add these functions because now some other class could do getPosition().left = garbage; and corrupt the DisplayPortMetrics object (i.e. this allows DisplayPortMetrics to be mutated).
>diff --git a/mobile/android/base/gfx/GeckoLayerClient.java b/mobile/android/base/gfx/GeckoLayerClient.java
>+ public DisplayPortMetrics getDisplayPort(boolean pageSizeUpdate, boolean isBrowserContentDisplayed, int tabId, ViewportMetrics metrics) {
>+ Tabs tabs = Tabs.getInstance();
>+ if (tabs.isSelectedTab(tabs.getTab(tabId)) && isBrowserContentDisplayed) {
>+ return handleViewportMessage(metrics, pageSizeUpdate ? ViewportMessageType.UPDATE : ViewportMessageType.PAGE_SIZE);
>+ } else {
>+ ImmutableViewportMetrics newMetrics = new ImmutableViewportMetrics(metrics);
>+ return DisplayPortCalculator.calculate(newMetrics, null);
>+ }
> }
Could you copy over the comments from the browser.js code as well?
>diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js
>+ let viewport = this.getViewport();
>+ let displayPort = getBridge().getDisplayPort(aPageSizeUpdate, BrowserApp.isBrowserContentDocumentDisplayed(), this.id, viewport);
I assume this works, but just to make sure: the viewport object here is just a plain old JS object. Does it get automagically converted to an nsIAndroidViewport when you call this function?
>diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp
>+nsresult
>+AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort)
>+{
>+ JNIEnv* env = GetJNIEnv();
>+ if (!env)
>+ return NS_OK;
>+ AutoLocalJNIFrame jniFrame(env, 0);
>+ mLayerClient->GetDisplayPort(&jniFrame, aPageSizeUpdate, aIsBrowserContentDisplayed, tabId, metrics, displayPort);
>+
This should have a null check for mLayerClient.
>diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp
>+jobject ConvertToJavaVieportMetrics(JNIEnv* env, nsIAndroidViewport* metrics) {
This function name is missing the "w" in Viewport.
>+class nsAndroidDisplayport : public nsIAndroidDisplayport
>+{
[snip]
>+ float mLeft, mTop, mRight, mBottom, mResolution;
>+protected:
>+ /* additional members */
>+};
Don't need this empty protected section.
>+void
>+AndroidGeckoLayerClient::GetDisplayPort(AutoLocalJNIFrame *jniFrame, bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort)
>+{
>+ JNIEnv* env = jniFrame->GetEnv();
Fix indent.
>+ jobject jmetrics = ConvertToJavaVieportMetrics(env, metrics);
jmetrics could be null here in OOM cases, need to check for that.
>+ jobject jobj = env->CallObjectMethod(wrapped_obj, jGetDisplayPort, aPageSizeUpdate, aIsBrowserContentDisplayed, tabId, jmetrics);
>+ createDisplayPort(env, jobj, displayPort);
>+ (*displayPort)->AddRef();
I feel like this function needs to have more error checking in general, like more | if (jniFrame->CheckForException()) return; | things in it. For example, I think we'll end up in undefined behaviour if one of the functions createDisplayPort calls ends up throwing an exception for whatever reason. (Another reason to just make a field access rather than a method call).
>diff --git a/widget/android/AndroidJavaWrappers.h b/widget/android/AndroidJavaWrappers.h
>+public:
>+ static jclass jViewportClass;
>+ static jclass jDisplayportClass;
>+ static jmethodID jViewportCtor;
>+ static jmethodID jDisplayportGetPosition;
>+ static jmethodID jDisplayportGetResolution;
As mentioned before, I'd prefer if these last two jmethodID fields were just jfieldID field instances for the position and resolution fields.
Attachment #660282 -
Flags: review?(bugmail.mozilla) → review-
| Assignee | ||
Comment 20•14 years ago
|
||
> >diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js
> >+ let viewport = this.getViewport();
> >+ let displayPort = getBridge().getDisplayPort(aPageSizeUpdate, BrowserApp.isBrowserContentDocumentDisplayed(), this.id, viewport);
>
> I assume this works, but just to make sure: the viewport object here is just
> a plain old JS object. Does it get automagically converted to an
> nsIAndroidViewport when you call this function?
Yes, that's how XPCOM/XPConnect work. Though, that is is why I asked for finkle's review here. He knows the gotchas of this sort of code better than I.
| Assignee | ||
Comment 21•14 years ago
|
||
Attachment #660282 -
Attachment is obsolete: true
Attachment #660282 -
Flags: review?(mark.finkle)
Attachment #660582 -
Flags: review?(mark.finkle)
Attachment #660582 -
Flags: review?(bugmail.mozilla)
Comment 22•14 years ago
|
||
Comment on attachment 660582 [details] [diff] [review]
new patch
Review of attachment 660582 [details] [diff] [review]:
-----------------------------------------------------------------
r=me. with the extra null check added.
::: widget/android/AndroidJavaWrappers.cpp
@@ +869,5 @@
> + return;
> + jobject jobj = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jGetDisplayPort, aPageSizeUpdate, aIsBrowserContentDisplayed, tabId, jmetrics);
> + if (jniFrame->CheckForException()) return;
> + createDisplayPort(jniFrame, jobj, displayPort);
> + (*displayPort)->AddRef();
I think this needs another null check - displayPort could be null here.
Attachment #660582 -
Flags: review?(bugmail.mozilla) → review+
| Assignee | ||
Comment 23•14 years ago
|
||
locally:
- (*displayPort)->AddRef();
+ NS_IF_ADDREF(*displayPort);
Comment 24•14 years ago
|
||
(In reply to Brad Lassey [:blassey] from comment #20)
> > >diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js
> > >+ let viewport = this.getViewport();
> > >+ let displayPort = getBridge().getDisplayPort(aPageSizeUpdate, BrowserApp.isBrowserContentDocumentDisplayed(), this.id, viewport);
> >
> > I assume this works, but just to make sure: the viewport object here is just
> > a plain old JS object. Does it get automagically converted to an
> > nsIAndroidViewport when you call this function?
>
> Yes, that's how XPCOM/XPConnect work. Though, that is is why I asked for
> finkle's review here. He knows the gotchas of this sort of code better than
> I.
It should work as you are hoping. We do the same thing with nsIObserver params, and other interfaced-objects, in JS.
Updated•14 years ago
|
Attachment #660582 -
Flags: review?(mark.finkle) → review+
| Assignee | ||
Comment 25•14 years ago
|
||
Comment 26•14 years ago
|
||
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 18
Comment 27•14 years ago
|
||
It looks like this was backed out - perhaps accidentally? - by https://hg.mozilla.org/mozilla-central/rev/e60144694d56.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment 28•14 years ago
|
||
(In reply to Geoff Brown [:gbrown] from comment #27)
> It looks like this was backed out - perhaps accidentally? - by
> https://hg.mozilla.org/mozilla-central/rev/e60144694d56.
Hrm, I don't know what happened there... Sorry!
Comment 30•14 years ago
|
||
Comment 31•14 years ago
|
||
Status: REOPENED → RESOLVED
Closed: 14 years ago → 14 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Updated•5 years ago
|
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•