Bug 1415994 - 2. Introduce GeckoDisplay; r=snorp draft
authorJim Chen <nchen@mozilla.com>
Tue, 14 Nov 2017 18:18:34 -0500
changeset 697876 282b27a1f7c11cf4e559b1f25946c3f4574e900a
parent 697875 04827eb61d6304d4782a7a935d5528013255726f
child 697877 eaf42122db1238c99b0da1e689bc365180a2835f
push id89133
push userbmo:nchen@mozilla.com
push dateTue, 14 Nov 2017 23:19:10 +0000
reviewerssnorp
bugs1415994
milestone59.0a1
Bug 1415994 - 2. Introduce GeckoDisplay; r=snorp Introduce a GeckoDisplay interface for interaction with GeckoSession. MozReview-Commit-ID: 13prgWaPqKU
mobile/android/base/moz.build
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoDisplay.java
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -392,16 +392,17 @@ gvjar.sources += [geckoview_source_dir +
     'GeckoView.java',
     'GeckoVRManager.java',
     'gfx/BitmapUtils.java',
     'gfx/BufferedImage.java',
     'gfx/BufferedImageGLInfo.java',
     'gfx/DynamicToolbarAnimator.java',
     'gfx/FloatSize.java',
     'gfx/FullScreenState.java',
+    'gfx/GeckoDisplay.java',
     'gfx/GeckoLayerClient.java',
     'gfx/GeckoSurface.java',
     'gfx/GeckoSurfaceTexture.java',
     'gfx/ImmutableViewportMetrics.java',
     'gfx/IntSize.java',
     'gfx/LayerView.java',
     'gfx/NativePanZoomController.java',
     'gfx/Overscroll.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoDisplay.java
@@ -0,0 +1,64 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * vim: ts=4 sw=4 expandtab:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.gfx;
+
+import android.view.Surface;
+
+/**
+ * Displays implement this interface to provide GeckoSession
+ * with a Surface for displaying content.
+ */
+public interface GeckoDisplay {
+    /**
+     * Displays notify GeckoSession of changes to its Surface through this interface that
+     * GeckoSession implements. To ensure drawing only happens on a valid Surface,
+     * GeckoSession will only use the provided Surface after
+     * {@link #surfaceChanged(Surface, int, int) surfaceChanged} is called and
+     * before {@link #surfaceDestroyed() surfaceDestroyed} returns.
+     */
+    interface Listener {
+        /**
+         * The display's Surface has been created or changed. Must be called on the
+         * application main thread. GeckoSession may block this call to ensure the Surface
+         * is valid while resuming drawing.
+         *
+         * @param surface The new Surface.
+         * @param width New width of the Surface.
+         * @param height New height of the Surface.
+         */
+        void surfaceChanged(Surface surface, int width, int height);
+
+        /**
+         * The display's Surface has been destroyed. Must be called on the application
+         * main thread. GeckoSession may block this call to ensure the Surface is valid
+         * while pausing drawing.
+         */
+        void surfaceDestroyed();
+    }
+
+    /**
+     * Get the current listener attached to this display. Must be called on the
+     * application main thread.
+     *
+     * @return Current listener or null if there is no listener.
+     */
+    Listener getListener();
+
+    /**
+     * Set a new listener attached to this display. Must be called on the
+     * application main thread. When attaching a new listener, and there is an
+     * existing valid Surface, the display must call {@link
+     * Listener#screenOriginChanged(int, int) screenOriginChanged} and {@link
+     * Listener#surfaceChanged(Surface, int, int) surfaceChanged} on the new
+     * listener. Similarly, when detaching a previous listener, and there is an
+     * existing valid Surface, the display must call {@link
+     * Listener#surfaceDestroyed() surfaceDestroyed} on the previous listener.
+     *
+     * @param listener New listener or null if detaching previous listener.
+     */
+    void setListener(Listener listener);
+}