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.opengl.GLES20;
20 import android.opengl.GLES30;
21 import android.opengl.GLSurfaceView;
22 import android.util.Log;
23 
24 import java.util.Scanner;
25 import java.util.concurrent.CountDownLatch;
26 
27 import javax.microedition.khronos.egl.EGLConfig;
28 import javax.microedition.khronos.opengles.GL10;
29 
30 class GLESSurfaceView extends GLSurfaceView {
31     private static final String TAG = "GLESSurfaceView";
32 
33     private int mGLVersion;//1, 2, 3
34     private CountDownLatch mDone;
35     private DeviceInfoActivity mParent;
36     /**
37      *
38      * @param parent
39      * @param glVersion the version of GLES API to use inside the view
40      * @param done to notify the completion of the task
41      */
GLESSurfaceView(DeviceInfoActivity parent, int glVersion, CountDownLatch done)42     public GLESSurfaceView(DeviceInfoActivity parent, int glVersion, CountDownLatch done){
43         super(parent);
44 
45         mParent = parent;
46         mGLVersion = glVersion;
47         mDone = done;
48         if (glVersion > 1) {
49             // Default is 1 so only set if bigger than 1
50             setEGLContextClientVersion(glVersion);
51         }
52         setRenderer(new OpenGLESRenderer());
53     }
54 
55     public class OpenGLESRenderer implements GLSurfaceView.Renderer {
56 
57         @Override
onSurfaceCreated(GL10 gl, EGLConfig config)58         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
59             String extensions;
60             String vendor;
61             String renderer;
62             if (mGLVersion == 2) {
63                 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
64                 vendor = GLES20.glGetString(GLES20.GL_VENDOR);
65                 renderer = GLES20.glGetString(GLES20.GL_RENDERER);
66             } else if (mGLVersion == 3) {
67                 extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS);
68                 vendor = GLES30.glGetString(GLES30.GL_VENDOR);
69                 renderer = GLES30.glGetString(GLES30.GL_RENDERER);
70             } else {
71                 extensions = gl.glGetString(GL10.GL_EXTENSIONS);
72                 vendor = gl.glGetString(GL10.GL_VENDOR);
73                 renderer = gl.glGetString(GL10.GL_RENDERER);
74             }
75             Log.i(TAG, "extensions : " + extensions);
76             Log.i(TAG, "vendor : " + vendor);
77             Log.i(TAG, "renderer : " + renderer);
78             mParent.setGraphicsInfo(vendor, renderer);
79             Scanner scanner = new Scanner(extensions);
80             scanner.useDelimiter(" ");
81             while (scanner.hasNext()) {
82                 String ext = scanner.next();
83                 mParent.addOpenGlExtension(ext);
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             scanner.close();
92             mDone.countDown();
93         }
94 
95         @Override
onSurfaceChanged(GL10 gl, int width, int height)96         public void onSurfaceChanged(GL10 gl, int width, int height) {
97 
98         }
99 
100         @Override
onDrawFrame(GL10 gl)101         public void onDrawFrame(GL10 gl) {
102 
103         }
104 
105     }
106 }
107