summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/SurfaceTextureListener.java
blob: 560674e4fbdd41e2256e878babfcc0c893d83ecd (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;

import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.JNIObject;

import android.graphics.SurfaceTexture;

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

    @Override
    protected void disposeNative() {
        // SurfaceTextureListener is disposed inside AndroidSurfaceTexture.
        throw new IllegalStateException("unreachable code");
    }

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

    @Override // SurfaceTexture.OnFrameAvailableListener
    public void onFrameAvailable(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.
        }
    }
}