• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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 boolean mUseGL20;
34     CountDownLatch mDone;
35 
36     /**
37      *
38      * @param context
39      * @param useGL20 whether to use GLES2.0 API or not inside the view
40      * @param done to notify the completion of the task
41      */
GLESSurfaceView(Context context, boolean useGL20, CountDownLatch done)42     public GLESSurfaceView(Context context, boolean useGL20, CountDownLatch done){
43         super(context);
44 
45         mUseGL20 = useGL20;
46         mDone = done;
47         if (mUseGL20) {
48             setEGLContextClientVersion(2);
49         }
50         setRenderer(new OpenGLESRenderer());
51     }
52 
53     public class OpenGLESRenderer implements GLSurfaceView.Renderer {
54 
55         @Override
onSurfaceCreated(GL10 gl, EGLConfig config)56         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
57             String extensions;
58             if (mUseGL20) {
59                 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
60             } else {
61                 extensions = gl.glGetString(GL10.GL_EXTENSIONS);
62             }
63             Log.i(TAG, "extensions : " + extensions);
64             Scanner scanner = new Scanner(extensions);
65             scanner.useDelimiter(" ");
66             StringBuilder builder = new StringBuilder();
67             while (scanner.hasNext()) {
68                 String ext = scanner.next();
69                 if (ext.contains("texture")) {
70                     if (ext.contains("compression") || ext.contains("compressed")) {
71                         Log.i(TAG, "Compression supported: " + ext);
72                         builder.append(ext);
73                         builder.append(";");
74                     }
75                 }
76             }
77 
78             DeviceInfoInstrument.addResult(
79                     DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
80                     builder.toString());
81 
82             mDone.countDown();
83         }
84 
85         @Override
onSurfaceChanged(GL10 gl, int width, int height)86         public void onSurfaceChanged(GL10 gl, int width, int height) {
87 
88         }
89 
90         @Override
onDrawFrame(GL10 gl)91         public void onDrawFrame(GL10 gl) {
92 
93         }
94 
95     }
96 }