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