blob: 1d3bf7f890585e91879696fff3af95885eea8511 [file] [log] [blame]
Keun young Park88e5d1f2011-12-14 14:01:01 -08001/*
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
17package android.tests.getinfo;
18
19import android.content.Context;
20import android.opengl.GLES20;
Stuart Scottb95af322013-10-09 14:57:23 -070021import android.opengl.GLES30;
Keun young Park88e5d1f2011-12-14 14:01:01 -080022import android.opengl.GLSurfaceView;
23import android.util.Log;
24
25import java.util.Scanner;
26import java.util.concurrent.CountDownLatch;
27
28import javax.microedition.khronos.egl.EGLConfig;
29import javax.microedition.khronos.opengles.GL10;
30
31class GLESSurfaceView extends GLSurfaceView {
32 private static final String TAG = "GLESSurfaceView";
33
Stuart Scottb95af322013-10-09 14:57:23 -070034 private int mGLVersion;//1, 2, 3
35 private CountDownLatch mDone;
36 private DeviceInfoActivity mParent;
Keun young Park88e5d1f2011-12-14 14:01:01 -080037 /**
38 *
Stuart Scottb95af322013-10-09 14:57:23 -070039 * @param parent
Stuart Scott0845b982013-10-15 14:16:23 -070040 * @param glVersion the version of GLES API to use inside the view
Keun young Park88e5d1f2011-12-14 14:01:01 -080041 * @param done to notify the completion of the task
42 */
Stuart Scottb95af322013-10-09 14:57:23 -070043 public GLESSurfaceView(DeviceInfoActivity parent, int glVersion, CountDownLatch done){
44 super(parent);
Keun young Park88e5d1f2011-12-14 14:01:01 -080045
Stuart Scottb95af322013-10-09 14:57:23 -070046 mParent = parent;
47 mGLVersion = glVersion;
Keun young Park88e5d1f2011-12-14 14:01:01 -080048 mDone = done;
Stuart Scottb95af322013-10-09 14:57:23 -070049 if (glVersion > 1) {
50 // Default is 1 so only set if bigger than 1
51 setEGLContextClientVersion(glVersion);
Keun young Park88e5d1f2011-12-14 14:01:01 -080052 }
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;
Stuart Scott0845b982013-10-15 14:16:23 -070061 String vendor;
62 String renderer;
Stuart Scottb95af322013-10-09 14:57:23 -070063 if (mGLVersion == 2) {
Keun young Park88e5d1f2011-12-14 14:01:01 -080064 extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
Stuart Scott0845b982013-10-15 14:16:23 -070065 vendor = GLES20.glGetString(GLES20.GL_VENDOR);
66 renderer = GLES20.glGetString(GLES20.GL_RENDERER);
Stuart Scottb95af322013-10-09 14:57:23 -070067 } else if (mGLVersion == 3) {
68 extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS);
Stuart Scott0845b982013-10-15 14:16:23 -070069 vendor = GLES30.glGetString(GLES30.GL_VENDOR);
70 renderer = GLES30.glGetString(GLES30.GL_RENDERER);
Keun young Park88e5d1f2011-12-14 14:01:01 -080071 } else {
72 extensions = gl.glGetString(GL10.GL_EXTENSIONS);
Stuart Scott0845b982013-10-15 14:16:23 -070073 vendor = gl.glGetString(GL10.GL_VENDOR);
74 renderer = gl.glGetString(GL10.GL_RENDERER);
Keun young Park88e5d1f2011-12-14 14:01:01 -080075 }
76 Log.i(TAG, "extensions : " + extensions);
Stuart Scott0845b982013-10-15 14:16:23 -070077 Log.i(TAG, "vendor : " + vendor);
78 Log.i(TAG, "renderer : " + renderer);
79 mParent.setGraphicsInfo(vendor, renderer);
Keun young Park88e5d1f2011-12-14 14:01:01 -080080 Scanner scanner = new Scanner(extensions);
81 scanner.useDelimiter(" ");
Keun young Park88e5d1f2011-12-14 14:01:01 -080082 while (scanner.hasNext()) {
83 String ext = scanner.next();
Nicholas Sauere350b3b2014-02-14 17:48:12 -080084 mParent.addOpenGlExtension(ext);
Keun young Park88e5d1f2011-12-14 14:01:01 -080085 if (ext.contains("texture")) {
86 if (ext.contains("compression") || ext.contains("compressed")) {
87 Log.i(TAG, "Compression supported: " + ext);
Stuart Scottb95af322013-10-09 14:57:23 -070088 mParent.addCompressedTextureFormat(ext);
Keun young Park88e5d1f2011-12-14 14:01:01 -080089 }
90 }
91 }
92
Keun young Park88e5d1f2011-12-14 14:01:01 -080093 mDone.countDown();
94 }
95
96 @Override
97 public void onSurfaceChanged(GL10 gl, int width, int height) {
98
99 }
100
101 @Override
102 public void onDrawFrame(GL10 gl) {
103
104 }
105
106 }
Stuart Scottb95af322013-10-09 14:57:23 -0700107}