Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 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 | */ |
| 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 |
| 56 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { |
| 57 | String extensions; |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 58 | String vendor; |
| 59 | String renderer; |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 60 | if (mUseGL20) { |
| 61 | extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 62 | vendor = GLES20.glGetString(GLES20.GL_VENDOR); |
| 63 | renderer = GLES20.glGetString(GLES20.GL_RENDERER); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 64 | } else { |
| 65 | extensions = gl.glGetString(GL10.GL_EXTENSIONS); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 66 | vendor = gl.glGetString(GL10.GL_VENDOR); |
| 67 | renderer = gl.glGetString(GL10.GL_RENDERER); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 68 | } |
| 69 | Log.i(TAG, "extensions : " + extensions); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 70 | Log.i(TAG, "vendor : " + vendor); |
| 71 | Log.i(TAG, "renderer : " + renderer); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 72 | Scanner scanner = new Scanner(extensions); |
| 73 | scanner.useDelimiter(" "); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 74 | StringBuilder extensionsBuilder = new StringBuilder(); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 75 | StringBuilder builder = new StringBuilder(); |
| 76 | while (scanner.hasNext()) { |
| 77 | String ext = scanner.next(); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 78 | extensionsBuilder.append(ext).append(";"); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 79 | if (ext.contains("texture")) { |
| 80 | if (ext.contains("compression") || ext.contains("compressed")) { |
| 81 | Log.i(TAG, "Compression supported: " + ext); |
| 82 | builder.append(ext); |
| 83 | builder.append(";"); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | DeviceInfoInstrument.addResult( |
| 89 | DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS, |
| 90 | builder.toString()); |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 91 | DeviceInfoInstrument.addResult( |
| 92 | DeviceInfoConstants.OPEN_GL_EXTENSIONS, |
| 93 | extensionsBuilder.toString()); |
| 94 | DeviceInfoInstrument.addResult( |
| 95 | DeviceInfoConstants.GRAPHICS_VENDOR, |
| 96 | vendor); |
| 97 | DeviceInfoInstrument.addResult( |
| 98 | DeviceInfoConstants.GRAPHICS_RENDERER, |
| 99 | renderer); |
Keun young Park | 88e5d1f | 2011-12-14 14:01:01 -0800 | [diff] [blame] | 100 | |
| 101 | mDone.countDown(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void onSurfaceChanged(GL10 gl, int width, int height) { |
| 106 | |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void onDrawFrame(GL10 gl) { |
| 111 | |
| 112 | } |
| 113 | |
| 114 | } |
Nicholas Sauer | a0de8fd | 2014-02-19 09:47:08 -0800 | [diff] [blame] | 115 | } |