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