1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* Original code copied from NDK Native-media sample code */ 18 19 package android.mediastress.cts; 20 21 import android.content.Context; 22 import android.graphics.SurfaceTexture; 23 import android.opengl.GLSurfaceView; 24 import android.util.AttributeSet; 25 import android.view.SurfaceHolder; 26 27 public class SurfaceTextureGLSurfaceView extends GLSurfaceView { 28 29 private SurfaceTextureRenderer mRenderer; 30 private final OnSurfaceChangedListener mListener; 31 32 public SurfaceTextureGLSurfaceView(Context context, OnSurfaceChangedListener listener) { 33 this(context, null, listener); 34 } 35 36 public SurfaceTextureGLSurfaceView(Context context, AttributeSet attributeSet, 37 OnSurfaceChangedListener listener) { 38 super(context, attributeSet); 39 mListener = listener; 40 init(listener); 41 } 42 43 private void init(OnSurfaceChangedListener listener) { 44 setEGLContextClientVersion(2); 45 mRenderer = new SurfaceTextureRenderer(listener); 46 setRenderer(mRenderer); 47 } 48 49 public SurfaceTexture getSurfaceTexture() { 50 return mRenderer.getSurfaceTexture(); 51 } 52 53 @Override 54 public void surfaceDestroyed(SurfaceHolder holder) { 55 // ugly but renderer has no notification for surfaceDestroyed. 56 if (mListener != null) { 57 // surface destroyed long time ago, but let existing stuffs cleared 58 mListener.onSurfaceDestroyed(); 59 } 60 super.surfaceDestroyed(holder); 61 } 62 } 63 64