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.opengl.GLSurfaceView;
     21 import android.os.Bundle;
     22 
     23 import javax.microedition.khronos.egl.EGLConfig;
     24 import javax.microedition.khronos.opengles.GL10;
     25 
     26 /**
     27  * A minimal activity for testing {@link android.opengl.GLSurfaceView}.
     28  * Also accepts non-blank renderers to allow its use for more complex tests.
     29  */
     30 public class GLSurfaceViewStubActivity extends Activity {
     31 
     32     private static class Renderer implements GLSurfaceView.Renderer {
     33 
     34         public void onDrawFrame(GL10 gl) {
     35             // Do nothing.
     36         }
     37 
     38         public void onSurfaceChanged(GL10 gl, int width, int height) {
     39             // Do nothing.
     40         }
     41 
     42         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
     43             // Do nothing.
     44         }
     45     }
     46 
     47     private GLSurfaceView mView;
     48 
     49     /** To override the blank renderer, or other settings, these
     50      * static set* methods must be called before onCreate() is called.
     51      * If using ActivityInstrumentationTestCase2, that means the set
     52      * methods need to be called before calling getActivity in the
     53      * test setUp().
     54      */
     55     private static GLSurfaceView.Renderer mRenderer = null;
     56     public static void setRenderer(GLSurfaceView.Renderer renderer) {
     57         mRenderer = renderer;
     58     }
     59     public static void resetRenderer() {
     60         mRenderer = null;
     61     }
     62 
     63     private static int mRenderMode = 0;
     64     private static boolean mRenderModeSet = false;
     65     public static void setRenderMode(int renderMode) {
     66         mRenderModeSet = true;
     67         mRenderMode = renderMode;
     68     }
     69     public static void resetRenderMode() {
     70         mRenderModeSet = false;
     71         mRenderMode = 0;
     72     }
     73 
     74     private static int mGlVersion = 0;
     75     private static boolean mGlVersionSet = false;
     76     public static void setGlVersion(int glVersion) {
     77         mGlVersionSet = true;
     78         mGlVersion = glVersion;
     79     }
     80     public static void resetGlVersion() {
     81         mGlVersionSet = false;
     82         mGlVersion = 0;
     83     }
     84 
     85     @Override
     86     public void onCreate(Bundle savedInstanceState) {
     87         super.onCreate(savedInstanceState);
     88         mView = new GLSurfaceView(this);
     89         // Only set this if explicitly asked for
     90         if (mGlVersionSet) {
     91             mView.setEGLContextClientVersion(mGlVersion);
     92         }
     93         // Use no-op renderer by default
     94         if (mRenderer == null) {
     95             mView.setRenderer(new Renderer());
     96         } else {
     97             mView.setRenderer(mRenderer);
     98         }
     99         // Only set this if explicitly asked for
    100         if (mRenderModeSet) {
    101             mView.setRenderMode(mRenderMode);
    102         }
    103         setContentView(mView);
    104     }
    105 
    106     public GLSurfaceView getView() {
    107         return mView;
    108     }
    109 
    110     @Override
    111     protected void onResume() {
    112         super.onResume();
    113         mView.onResume();
    114     }
    115 
    116     @Override
    117     protected void onPause() {
    118         super.onPause();
    119         mView.onPause();
    120     }
    121 }
    122