Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2010 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.opengl.cts;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.opengl.GLSurfaceView;
     22 import android.os.Bundle;
     23 
     24 import java.util.concurrent.CountDownLatch;
     25 import java.util.concurrent.TimeUnit;
     26 
     27 import javax.microedition.khronos.egl.EGLConfig;
     28 import javax.microedition.khronos.opengles.GL10;
     29 
     30 /**
     31  * {@link Activity} that queries the device's display attributes to determine what version of
     32  * OpenGL ES is supported and returns what the GL version string reports.
     33  */
     34 public class OpenGlEsVersionStubActivity extends Activity {
     35 
     36     private static final String EGL_CONTEXT_CLIENT_VERSION = "eglContextClientVersion";
     37 
     38     /** Timeout to wait for the surface to be created and the version queried. */
     39     private static final int TIMEOUT_SECONDS = 10;
     40 
     41     /** Version string reported by glGetString. */
     42     private String mVersionString;
     43 
     44     /** Latch that is unlocked when the activity is done finding the version. */
     45     private CountDownLatch mSurfaceCreatedLatch = new CountDownLatch(1);
     46 
     47     public static Intent createIntent(int eglContextClientVersion) {
     48         Intent intent = new Intent(Intent.ACTION_MAIN);
     49         intent.putExtra(EGL_CONTEXT_CLIENT_VERSION, eglContextClientVersion);
     50         return intent;
     51     }
     52 
     53     @Override
     54     protected void onCreate(Bundle savedInstanceState) {
     55         super.onCreate(savedInstanceState);
     56 
     57         GLSurfaceView view = new GLSurfaceView(this);
     58 
     59         Intent intent = getIntent();
     60         int eglContextClientVersion = intent.getIntExtra(EGL_CONTEXT_CLIENT_VERSION, -1);
     61         if (eglContextClientVersion > 0) {
     62             view.setEGLContextClientVersion(eglContextClientVersion);
     63         }
     64 
     65         view.setRenderer(new Renderer());
     66         setContentView(view);
     67     }
     68 
     69     public String getVersionString() throws InterruptedException {
     70         mSurfaceCreatedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
     71         synchronized (this) {
     72             return mVersionString;
     73         }
     74     }
     75 
     76     private class Renderer implements GLSurfaceView.Renderer {
     77 
     78         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
     79             synchronized (OpenGlEsVersionStubActivity.this) {
     80                 try {
     81                     mVersionString = gl.glGetString(GL10.GL_VERSION);
     82                 } finally {
     83                     mSurfaceCreatedLatch.countDown();
     84                 }
     85             }
     86         }
     87 
     88         public void onSurfaceChanged(GL10 gl, int width, int height) {
     89         }
     90 
     91         public void onDrawFrame(GL10 gl) {
     92         }
     93     }
     94 }
     95