Home | History | Annotate | Download | only in getinfo
      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 glVersion the version of GLES API to use 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             String vendor;
     62             String renderer;
     63             if (mGLVersion == 2) {
     64                 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
     65                 vendor = GLES20.glGetString(GLES20.GL_VENDOR);
     66                 renderer = GLES20.glGetString(GLES20.GL_RENDERER);
     67             } else if (mGLVersion == 3) {
     68                 extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS);
     69                 vendor = GLES30.glGetString(GLES30.GL_VENDOR);
     70                 renderer = GLES30.glGetString(GLES30.GL_RENDERER);
     71             } else {
     72                 extensions = gl.glGetString(GL10.GL_EXTENSIONS);
     73                 vendor = gl.glGetString(GL10.GL_VENDOR);
     74                 renderer = gl.glGetString(GL10.GL_RENDERER);
     75             }
     76             Log.i(TAG, "extensions : " + extensions);
     77             Log.i(TAG, "vendor : " + vendor);
     78             Log.i(TAG, "renderer : " + renderer);
     79             mParent.setGraphicsInfo(vendor, renderer);
     80             Scanner scanner = new Scanner(extensions);
     81             scanner.useDelimiter(" ");
     82             while (scanner.hasNext()) {
     83                 String ext = scanner.next();
     84                 if (ext.contains("texture")) {
     85                     if (ext.contains("compression") || ext.contains("compressed")) {
     86                         Log.i(TAG, "Compression supported: " + ext);
     87                         mParent.addCompressedTextureFormat(ext);
     88                     }
     89                 }
     90             }
     91 
     92             mDone.countDown();
     93         }
     94 
     95         @Override
     96         public void onSurfaceChanged(GL10 gl, int width, int height) {
     97 
     98         }
     99 
    100         @Override
    101         public void onDrawFrame(GL10 gl) {
    102 
    103         }
    104 
    105     }
    106 }
    107