Home | History | Annotate | Download | only in gl
      1 // Copyright 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.gl;
      6 
      7 import android.graphics.SurfaceTexture;
      8 
      9 import org.chromium.base.JNINamespace;
     10 
     11 /**
     12  * Listener to an android SurfaceTexture object for frame availability.
     13  */
     14 @JNINamespace("gfx")
     15 class SurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener {
     16     // Used to determine the class instance to dispatch the native call to.
     17     private final long mNativeSurfaceTextureListener;
     18 
     19     SurfaceTextureListener(long nativeSurfaceTextureListener) {
     20         assert nativeSurfaceTextureListener != 0;
     21         mNativeSurfaceTextureListener = nativeSurfaceTextureListener;
     22     }
     23 
     24     @Override
     25     public void onFrameAvailable(SurfaceTexture surfaceTexture) {
     26         nativeFrameAvailable(mNativeSurfaceTextureListener);
     27     }
     28 
     29     @Override
     30     protected void finalize() throws Throwable {
     31         try {
     32             nativeDestroy(mNativeSurfaceTextureListener);
     33         } finally {
     34             super.finalize();
     35         }
     36     }
     37 
     38     private native void nativeFrameAvailable(long nativeSurfaceTextureListener);
     39     private native void nativeDestroy(long nativeSurfaceTextureListener);
     40 }
     41