Home | History | Annotate | Download | only in cts
      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.opengl.cts;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.opengl.GLSurfaceView;
     22 import android.os.Bundle;
     23 import android.view.WindowManager;
     24 
     25 import java.util.concurrent.CountDownLatch;
     26 import java.util.concurrent.TimeUnit;
     27 
     28 /**
     29  * {@link Activity} with a {@link GLSurfaceView} that chooses a specific configuration.
     30  */
     31 public class EglConfigCtsActivity extends Activity {
     32 
     33     public static final String CONFIG_ID_EXTRA = "eglConfigId";
     34 
     35     public static final String CONTEXT_CLIENT_VERSION_EXTRA = "eglContextClientVersion";
     36 
     37     private EglConfigGLSurfaceView mView;
     38 
     39     private CountDownLatch mFinishedDrawing;
     40 
     41     @Override
     42     protected void onCreate(Bundle savedInstanceState) {
     43         super.onCreate(savedInstanceState);
     44         int configId = getConfigId();
     45         int contextClientVersion = getContextClientVersion();
     46         setTitle("EGL Config Id: " + configId + " Client Version: " + contextClientVersion);
     47 
     48         // Dismiss keyguard and keep screen on while this test is on.
     49         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
     50                 WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
     51                 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     52 
     53         mFinishedDrawing = new CountDownLatch(1);
     54         mView = new EglConfigGLSurfaceView(this, configId, contextClientVersion, new Runnable() {
     55             @Override
     56             public void run() {
     57                 mFinishedDrawing.countDown();
     58             }
     59         });
     60         setContentView(mView);
     61     }
     62 
     63     private int getConfigId() {
     64         Intent intent = getIntent();
     65         if (intent != null) {
     66             return intent.getIntExtra(CONFIG_ID_EXTRA, 0);
     67         } else {
     68             return 0;
     69         }
     70     }
     71 
     72     private int getContextClientVersion() {
     73         Intent intent = getIntent();
     74         if (intent != null) {
     75             return intent.getIntExtra(CONTEXT_CLIENT_VERSION_EXTRA, 0);
     76         } else {
     77             return 0;
     78         }
     79     }
     80 
     81     @Override
     82     protected void onResume() {
     83         super.onResume();
     84         mView.onResume();
     85     }
     86 
     87     @Override
     88     protected void onPause() {
     89         super.onPause();
     90         mView.onPause();
     91     }
     92 
     93     public void waitToFinishDrawing() throws InterruptedException {
     94         if (!mFinishedDrawing.await(3, TimeUnit.SECONDS)) {
     95             throw new IllegalStateException("Coudn't finish drawing frames!");
     96         }
     97     }
     98 }
     99