summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java
blob: 0ba79d1f4244c7f90d21fe56d4f0b6ad4cd61f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * 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.graphics.SurfaceTexture;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.JNIObject;

/* package */ final class SurfaceTextureListener extends JNIObject
    implements SurfaceTexture.OnFrameAvailableListener {
  @WrapForJNI(calledFrom = "gecko")
  private SurfaceTextureListener() {}

  @WrapForJNI(dispatchTo = "gecko")
  @Override // JNIObject
  protected native void disposeNative();

  @Override
  protected void finalize() {
    disposeNative();
  }

  @WrapForJNI(stubName = "OnFrameAvailable")
  private native void nativeOnFrameAvailable();

  @Override // SurfaceTexture.OnFrameAvailableListener
  public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
    try {
      nativeOnFrameAvailable();
    } catch (final NullPointerException e) {
      // Ignore exceptions caused by a disposed object, i.e.
      // getting a callback after this listener is no longer in use.
    }
  }
}