1 /* 2 * Copyright (C) 2011 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 package android.tests.getinfo; 18 19 import android.content.Context; 20 import android.opengl.GLES20; 21 import android.opengl.GLES30; 22 import android.opengl.GLSurfaceView; 23 import android.util.Log; 24 25 import java.util.Scanner; 26 import java.util.concurrent.CountDownLatch; 27 28 import javax.microedition.khronos.egl.EGLConfig; 29 import javax.microedition.khronos.opengles.GL10; 30 31 class GLESSurfaceView extends GLSurfaceView { 32 private static final String TAG = "GLESSurfaceView"; 33 34 private int mGLVersion;//1, 2, 3 35 private CountDownLatch mDone; 36 private DeviceInfoActivity mParent; 37 /** 38 * 39 * @param parent 40 * @param useGL20 whether to use GLES2.0 API or not inside the view 41 * @param done to notify the completion of the task 42 */ 43 public GLESSurfaceView(DeviceInfoActivity parent, int glVersion, CountDownLatch done){ 44 super(parent); 45 46 mParent = parent; 47 mGLVersion = glVersion; 48 mDone = done; 49 if (glVersion > 1) { 50 // Default is 1 so only set if bigger than 1 51 setEGLContextClientVersion(glVersion); 52 } 53 setRenderer(new OpenGLESRenderer()); 54 } 55 56 public class OpenGLESRenderer implements GLSurfaceView.Renderer { 57 58 @Override 59 public void onSurfaceCreated(GL10 gl, EGLConfig config) { 60 String extensions; 61 if (mGLVersion == 2) { 62 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS); 63 } else if (mGLVersion == 3) { 64 extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS); 65 } else { 66 extensions = gl.glGetString(GL10.GL_EXTENSIONS); 67 } 68 Log.i(TAG, "extensions : " + extensions); 69 Scanner scanner = new Scanner(extensions); 70 scanner.useDelimiter(" "); 71 while (scanner.hasNext()) { 72 String ext = scanner.next(); 73 if (ext.contains("texture")) { 74 if (ext.contains("compression") || ext.contains("compressed")) { 75 Log.i(TAG, "Compression supported: " + ext); 76 mParent.addCompressedTextureFormat(ext); 77 } 78 } 79 } 80 81 mDone.countDown(); 82 } 83 84 @Override 85 public void onSurfaceChanged(GL10 gl, int width, int height) { 86 87 } 88 89 @Override 90 public void onDrawFrame(GL10 gl) { 91 92 } 93 94 } 95 } 96