From 00a358ff70e5dadb58bd529d337dbe273d3282c6 Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Mon, 30 Sep 2013 09:07:16 +0200 Subject: [PATCH] Bug 913985: Part 2 - Add annotations to all remaining JNI entry points, marking them for generations. r=kats --- mobile/android/base/GeckoEvent.java | 4 +++ mobile/android/base/SurfaceBits.java | 3 ++ .../android/base/gfx/DisplayPortMetrics.java | 4 +++ mobile/android/base/gfx/GeckoLayerClient.java | 28 ++++++++++--------- .../base/gfx/ImmutableViewportMetrics.java | 4 ++- mobile/android/base/gfx/LayerRenderer.java | 8 +++++- .../base/gfx/ProgressiveUpdateData.java | 3 ++ mobile/android/base/gfx/ViewTransform.java | 3 ++ mobile/android/base/mozglue/NativeZip.java | 3 ++ .../android/base/sqlite/MatrixBlobCursor.java | 7 +++++ .../base/sqlite/SQLiteBridgeException.java | 3 ++ mobile/android/base/util/Clipboard.java | 19 +++++++++++++ 12 files changed, 74 insertions(+), 15 deletions(-) diff --git a/mobile/android/base/GeckoEvent.java b/mobile/android/base/GeckoEvent.java index 3ed9310ddb8..3c671d94d8f 100644 --- a/mobile/android/base/GeckoEvent.java +++ b/mobile/android/base/GeckoEvent.java @@ -7,6 +7,8 @@ package org.mozilla.gecko; import org.mozilla.gecko.gfx.DisplayPortMetrics; import org.mozilla.gecko.gfx.ImmutableViewportMetrics; +import org.mozilla.gecko.mozglue.generatorannotations.GeneratorOptions; +import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI; import android.content.res.Resources; import android.graphics.Point; @@ -83,6 +85,8 @@ public class GeckoEvent { * The DomKeyLocation enum encapsulates the DOM KeyboardEvent's constants. * @see https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent#Key_location_constants */ + @GeneratorOptions(generatedClassName = "JavaDomKeyLocation") + @WrapEntireClassForJNI public enum DomKeyLocation { DOM_KEY_LOCATION_STANDARD(0), DOM_KEY_LOCATION_LEFT(1), diff --git a/mobile/android/base/SurfaceBits.java b/mobile/android/base/SurfaceBits.java index 52370b24ad8..5d481e1fb3d 100644 --- a/mobile/android/base/SurfaceBits.java +++ b/mobile/android/base/SurfaceBits.java @@ -4,8 +4,11 @@ package org.mozilla.gecko; +import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI; + import java.nio.ByteBuffer; +@WrapEntireClassForJNI public class SurfaceBits { public int width; public int height; diff --git a/mobile/android/base/gfx/DisplayPortMetrics.java b/mobile/android/base/gfx/DisplayPortMetrics.java index 91f8d05f001..4bb5e8de801 100644 --- a/mobile/android/base/gfx/DisplayPortMetrics.java +++ b/mobile/android/base/gfx/DisplayPortMetrics.java @@ -5,6 +5,7 @@ package org.mozilla.gecko.gfx; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; import org.mozilla.gecko.util.FloatUtils; import android.graphics.RectF; @@ -18,13 +19,16 @@ import android.graphics.RectF; * subsection of that with compositor scaling. */ public final class DisplayPortMetrics { + @WrapElementForJNI public final float resolution; + @WrapElementForJNI private final RectF mPosition; public DisplayPortMetrics() { this(0, 0, 0, 0, 1); } + @WrapElementForJNI public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) { this.resolution = resolution; mPosition = new RectF(left, top, right, bottom); diff --git a/mobile/android/base/gfx/GeckoLayerClient.java b/mobile/android/base/gfx/GeckoLayerClient.java index 9470119cb09..ec0b3c405f9 100644 --- a/mobile/android/base/gfx/GeckoLayerClient.java +++ b/mobile/android/base/gfx/GeckoLayerClient.java @@ -11,6 +11,7 @@ import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.Tab; import org.mozilla.gecko.Tabs; import org.mozilla.gecko.ZoomConstraints; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; import org.mozilla.gecko.util.EventDispatcher; import org.mozilla.gecko.util.FloatUtils; import org.mozilla.gecko.util.ThreadUtils; @@ -413,7 +414,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget return mDisplayPort; } - /* This is invoked by JNI on the gecko thread */ + @WrapElementForJNI DisplayPortMetrics getDisplayPort(boolean pageSizeUpdate, boolean isBrowserContentDisplayed, int tabId, ImmutableViewportMetrics metrics) { Tabs tabs = Tabs.getInstance(); if (tabs.isSelectedTab(tabs.getTab(tabId)) && isBrowserContentDisplayed) { @@ -430,12 +431,12 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget } } - /* This is invoked by JNI on the gecko thread */ + @WrapElementForJNI void contentDocumentChanged() { mContentDocumentIsDisplayed = false; } - /* This is invoked by JNI on the gecko thread */ + @WrapElementForJNI boolean isContentDocumentDisplayed() { return mContentDocumentIsDisplayed; } @@ -445,6 +446,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget // to abort the current update and continue with any subsequent ones. This // is useful for slow-to-render pages when the display-port starts lagging // behind enough that continuing to draw it is wasted effort. + @WrapElementForJNI(allowMultithread = true) public ProgressiveUpdateData progressiveUpdateCallback(boolean aHasPendingNewThebesContent, float x, float y, float width, float height, float resolution, boolean lowPrecision) { @@ -552,13 +554,13 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget } } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. - * The compositor invokes this function just before compositing a frame where the document + /** The compositor invokes this function just before compositing a frame where the document * is different from the document composited on the last frame. In these cases, the viewport * information we have in Java is no longer valid and needs to be replaced with the new * viewport information provided. setPageRect will never be invoked on the same frame that * this function is invoked on; and this function will always be called prior to syncViewportInfo. */ + @WrapElementForJNI(allowMultithread = true) public void setFirstPaintViewport(float offsetX, float offsetY, float zoom, float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) { synchronized (getLock()) { @@ -611,12 +613,12 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget mContentDocumentIsDisplayed = true; } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. - * The compositor invokes this function whenever it determines that the page rect + /** The compositor invokes this function whenever it determines that the page rect * has changed (based on the information it gets from layout). If setFirstPaintViewport * is invoked on a frame, then this function will not be. For any given frame, this * function will be invoked before syncViewportInfo. */ + @WrapElementForJNI(allowMultithread = true) public void setPageRect(float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) { synchronized (getLock()) { RectF cssPageRect = new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom); @@ -629,8 +631,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget } } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. - * The compositor invokes this function on every frame to figure out what part of the + /** The compositor invokes this function on every frame to figure out what part of the * page to display, and to inform Java of the current display port. Since it is called * on every frame, it needs to be ultra-fast. * It avoids taking any locks or allocating any objects. We keep around a @@ -638,6 +639,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget * everytime we're called. NOTE: we might be able to return a ImmutableViewportMetrics * which would avoid the copy into mCurrentViewTransform. */ + @WrapElementForJNI(allowMultithread = true) public ViewTransform syncViewportInfo(int x, int y, int width, int height, float resolution, boolean layersUpdated) { // getViewportMetrics is thread safe so we don't need to synchronize. // We save the viewport metrics here, so we later use it later in @@ -691,7 +693,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget return mCurrentViewTransform; } - /* Invoked by JNI from the compositor thread */ + @WrapElementForJNI(allowMultithread = true) public ViewTransform syncFrameMetrics(float offsetX, float offsetY, float zoom, float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom, boolean layersUpdated, int x, int y, int width, int height, float resolution, @@ -705,7 +707,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget return syncViewportInfo(x, y, width, height, resolution, layersUpdated); } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public LayerRenderer.Frame createFrame() { // Create the shaders and textures if necessary. if (!mLayerRendererInitialized) { @@ -717,12 +719,12 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget return mLayerRenderer.createFrame(mFrameMetrics); } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void activateProgram() { mLayerRenderer.activateDefaultProgram(); } - /** This function is invoked by Gecko via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void deactivateProgram() { mLayerRenderer.deactivateDefaultProgram(); } diff --git a/mobile/android/base/gfx/ImmutableViewportMetrics.java b/mobile/android/base/gfx/ImmutableViewportMetrics.java index 1b1c25a7320..817190c6c45 100644 --- a/mobile/android/base/gfx/ImmutableViewportMetrics.java +++ b/mobile/android/base/gfx/ImmutableViewportMetrics.java @@ -5,6 +5,7 @@ package org.mozilla.gecko.gfx; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; import org.mozilla.gecko.util.FloatUtils; import android.graphics.PointF; @@ -52,7 +53,8 @@ public class ImmutableViewportMetrics { /** This constructor is used by native code in AndroidJavaWrappers.cpp, be * careful when modifying the signature. */ - private ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop, + @WrapElementForJNI(allowMultithread = true) + public ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop, float aPageRectRight, float aPageRectBottom, float aCssPageRectLeft, float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom, float aViewportRectLeft, float aViewportRectTop, float aViewportRectRight, diff --git a/mobile/android/base/gfx/LayerRenderer.java b/mobile/android/base/gfx/LayerRenderer.java index b1882fe3ce7..000dbb69624 100644 --- a/mobile/android/base/gfx/LayerRenderer.java +++ b/mobile/android/base/gfx/LayerRenderer.java @@ -12,6 +12,8 @@ import org.mozilla.gecko.Tabs; import org.mozilla.gecko.gfx.Layer.RenderContext; import org.mozilla.gecko.gfx.RenderTask; import org.mozilla.gecko.mozglue.DirectBufferAllocator; +import org.mozilla.gecko.mozglue.generatorannotations.GeneratorOptions; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; import android.content.Context; import android.content.SharedPreferences; @@ -19,7 +21,6 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; -import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; @@ -437,6 +438,7 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener { } } + @GeneratorOptions(generatedClassName = "LayerRendererFrame") public class Frame { // The timestamp recording the start of this frame. private long mFrameStartTime; @@ -490,6 +492,7 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener { } /** This function is invoked via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void beginDrawing() { mFrameStartTime = System.nanoTime(); @@ -579,6 +582,7 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener { } /** This function is invoked via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void drawBackground() { GLES20.glDisable(GLES20.GL_SCISSOR_TEST); @@ -611,6 +615,7 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener { } /** This function is invoked via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void drawForeground() { /* Draw any extra layers that were added (likely plugins) */ if (mExtraLayers.size() > 0) { @@ -661,6 +666,7 @@ public class LayerRenderer implements Tabs.OnTabsChangedListener { } /** This function is invoked via JNI; be careful when modifying signature. */ + @WrapElementForJNI(allowMultithread = true) public void endDrawing() { // If a layer update requires further work, schedule another redraw if (!mUpdated) diff --git a/mobile/android/base/gfx/ProgressiveUpdateData.java b/mobile/android/base/gfx/ProgressiveUpdateData.java index 187dad74568..7571658803d 100644 --- a/mobile/android/base/gfx/ProgressiveUpdateData.java +++ b/mobile/android/base/gfx/ProgressiveUpdateData.java @@ -5,12 +5,15 @@ package org.mozilla.gecko.gfx; +import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI; + /** * This is the data structure that's returned by the progressive tile update * callback function. It encompasses the current viewport and a boolean value * representing whether the front-end is interested in the current progressive * update continuing. */ +@WrapEntireClassForJNI public class ProgressiveUpdateData { public float x; public float y; diff --git a/mobile/android/base/gfx/ViewTransform.java b/mobile/android/base/gfx/ViewTransform.java index d9ec6252882..7243aef6dc9 100644 --- a/mobile/android/base/gfx/ViewTransform.java +++ b/mobile/android/base/gfx/ViewTransform.java @@ -5,6 +5,9 @@ package org.mozilla.gecko.gfx; +import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI; + +@WrapEntireClassForJNI public class ViewTransform { public float x; public float y; diff --git a/mobile/android/base/mozglue/NativeZip.java b/mobile/android/base/mozglue/NativeZip.java index a8c0ce85531..74a3a03d304 100644 --- a/mobile/android/base/mozglue/NativeZip.java +++ b/mobile/android/base/mozglue/NativeZip.java @@ -5,6 +5,8 @@ package org.mozilla.gecko.mozglue; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; + import java.io.InputStream; import java.nio.ByteBuffer; import java.util.zip.Inflater; @@ -68,6 +70,7 @@ public class NativeZip implements NativeReference { private static native void _release(long obj); private native InputStream _getInputStream(long obj, String path); + @WrapElementForJNI private InputStream createInputStream(ByteBuffer buffer, int compression) { if (compression != STORE && compression != DEFLATE) { throw new IllegalArgumentException("Unexpected compression: " + compression); diff --git a/mobile/android/base/sqlite/MatrixBlobCursor.java b/mobile/android/base/sqlite/MatrixBlobCursor.java index 1c6618054a3..daddade8250 100644 --- a/mobile/android/base/sqlite/MatrixBlobCursor.java +++ b/mobile/android/base/sqlite/MatrixBlobCursor.java @@ -17,6 +17,8 @@ package org.mozilla.gecko.sqlite; +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; + import android.database.AbstractCursor; import android.database.CursorIndexOutOfBoundsException; @@ -50,6 +52,7 @@ public class MatrixBlobCursor extends AbstractCursor { * determines column ordering elsewhere in this cursor * @param initialCapacity in rows */ + @WrapElementForJNI public MatrixBlobCursor(String[] columnNames, int initialCapacity) { this.columnNames = columnNames; this.columnCount = columnNames.length; @@ -67,6 +70,7 @@ public class MatrixBlobCursor extends AbstractCursor { * @param columnNames names of the columns, the ordering of which * determines column ordering elsewhere in this cursor */ + @WrapElementForJNI public MatrixBlobCursor(String[] columnNames) { this(columnNames, 16); } @@ -112,6 +116,7 @@ public class MatrixBlobCursor extends AbstractCursor { * @param columnValues in the same order as the the column names specified * at cursor construction time */ + @WrapElementForJNI public void addRow(Object[] columnValues) { if (columnValues.length != columnCount) { throw new IllegalArgumentException("columnNames.length = " @@ -133,6 +138,7 @@ public class MatrixBlobCursor extends AbstractCursor { * @param columnValues in the same order as the the column names specified * at cursor construction time */ + @WrapElementForJNI public void addRow(Iterable columnValues) { int start = rowCount * columnCount; int end = start + columnCount; @@ -165,6 +171,7 @@ public class MatrixBlobCursor extends AbstractCursor { } /** Optimization for {@link ArrayList}. */ + @WrapElementForJNI private void addRow(ArrayList columnValues, int start) { int size = columnValues.size(); if (size != columnCount) { diff --git a/mobile/android/base/sqlite/SQLiteBridgeException.java b/mobile/android/base/sqlite/SQLiteBridgeException.java index c4e55805548..e7deca1da5c 100644 --- a/mobile/android/base/sqlite/SQLiteBridgeException.java +++ b/mobile/android/base/sqlite/SQLiteBridgeException.java @@ -5,6 +5,9 @@ package org.mozilla.gecko.sqlite; +import org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI; + +@WrapEntireClassForJNI public class SQLiteBridgeException extends RuntimeException { static final long serialVersionUID = 1L; diff --git a/mobile/android/base/util/Clipboard.java b/mobile/android/base/util/Clipboard.java index 6c255cd9f36..4ea6db05697 100644 --- a/mobile/android/base/util/Clipboard.java +++ b/mobile/android/base/util/Clipboard.java @@ -79,6 +79,25 @@ public final class Clipboard { }); } + /** + * Returns true if the clipboard is nonempty, false otherwise. + * + * @return true if the clipboard is nonempty, false otherwise. + */ + @WrapElementForJNI + public static boolean hasText() { + String text = getText(); + return text != null; + } + + /** + * Deletes all text from the clipboard. + */ + @WrapElementForJNI + public static void clearText() { + setText(null); + } + private static android.content.ClipboardManager getClipboardManager11(Context context) { // In API Level 11 and above, CLIPBOARD_SERVICE returns android.content.ClipboardManager, // which is a subclass of android.text.ClipboardManager.