1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.ui.gfx; |
6 | |
7 | import android.graphics.SurfaceTexture; |
8 | |
9 | import org.chromium.base.CalledByNative; |
10 | import org.chromium.base.JNINamespace; |
11 | |
12 | /** |
13 | * Listener to an android SurfaceTexture object for frame availability. |
14 | */ |
15 | @JNINamespace("gfx") |
16 | class SurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener { |
17 | // Used to determine the class instance to dispatch the native call to. |
18 | private int mNativeSurfaceTextureListener = 0; |
19 | |
20 | private SurfaceTextureListener(int nativeSurfaceTextureListener) { |
21 | assert nativeSurfaceTextureListener != 0; |
22 | mNativeSurfaceTextureListener = nativeSurfaceTextureListener; |
23 | } |
24 | |
25 | @Override |
26 | public void onFrameAvailable(SurfaceTexture surfaceTexture) { |
27 | nativeFrameAvailable(mNativeSurfaceTextureListener); |
28 | } |
29 | |
30 | @Override |
31 | protected void finalize() throws Throwable { |
32 | try { |
33 | nativeDestroy(mNativeSurfaceTextureListener); |
34 | } finally { |
35 | super.finalize(); |
36 | } |
37 | } |
38 | |
39 | @CalledByNative |
40 | private static SurfaceTextureListener create(int nativeSurfaceTextureListener) { |
41 | return new SurfaceTextureListener(nativeSurfaceTextureListener); |
42 | } |
43 | |
44 | private native void nativeFrameAvailable(int nativeSurfaceTextureListener); |
45 | private native void nativeDestroy(int nativeSurfaceTextureListener); |
46 | } |