1 /* 2 * Copyright (C) 2012 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 package android.opengl.cts; 17 18 import android.app.Activity; 19 import android.content.Context; 20 import android.opengl.GLSurfaceView; 21 import android.opengl.GLSurfaceView.Renderer; 22 import android.os.Bundle; 23 import android.view.Window; 24 import android.view.WindowManager; 25 26 import java.lang.InterruptedException; 27 import java.lang.UnsupportedOperationException; 28 import java.util.concurrent.CountDownLatch; 29 import java.util.concurrent.TimeUnit; 30 31 public class OpenGLES20NativeActivityTwo extends Activity { 32 OpenGLES20View view; 33 Renderer mRenderer; 34 int mRendererType; 35 36 private CountDownLatch mLatch = new CountDownLatch(1); 37 38 @Override onCreate(Bundle savedInstanceState)39 public void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 } 42 waitForFrameDrawn()43 public boolean waitForFrameDrawn() { 44 boolean result = false; 45 try { 46 result = mLatch.await(10L, TimeUnit.SECONDS); 47 } catch (InterruptedException e) { 48 // just return false 49 } 50 return result; 51 } 52 setView(int type, int i, float[] vertexColors )53 public void setView(int type, int i, float[] vertexColors ) { 54 // Note: Flags should be modified before the content view is set 55 Window window = getWindow(); 56 window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 57 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 58 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 59 | WindowManager.LayoutParams.FLAG_FULLSCREEN 60 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 61 view = new OpenGLES20View(this,type,i, vertexColors, mLatch); 62 setContentView(view); 63 } 64 setView(int type, int i)65 public void setView(int type, int i) { 66 throw new UnsupportedOperationException("No views without vertexColors, please!"); 67 } 68 getNoOfAttachedShaders()69 public int getNoOfAttachedShaders() { 70 return ((RendererBase)mRenderer).mShaderCount[0]; 71 } 72 glGetError()73 public int glGetError() { 74 return ((RendererBase)mRenderer).mError; 75 } 76 77 @Override onPause()78 protected void onPause() { 79 super.onPause(); 80 if(view != null) { 81 view.onPause(); 82 } 83 84 } 85 86 @Override onResume()87 protected void onResume() { 88 super.onResume(); 89 if(view != null) { 90 view.onResume(); 91 } 92 } 93 getActualColor()94 public float[] getActualColor() { 95 return ((RendererBase) mRenderer).mColorOne; 96 } 97 98 class OpenGLES20View extends GLSurfaceView { 99 100 @Override onPause()101 public void onPause() { 102 super.onPause(); 103 } 104 105 @Override onResume()106 public void onResume() { 107 super.onResume(); 108 } 109 OpenGLES20View(Context context, int type, int index, float[] rgba, CountDownLatch latch)110 public OpenGLES20View(Context context, int type, int index, float[] rgba, 111 CountDownLatch latch) { 112 super(context); 113 setEGLContextClientVersion(2); 114 if(type == Constants.COLOR) { 115 if(index == 1) { 116 mRenderer = new NativeRendererOneColorBufferTest(context, rgba, latch); 117 }else { 118 throw new RuntimeException(); 119 } 120 } 121 setRenderer(mRenderer); 122 } 123 124 @Override setEGLContextClientVersion(int version)125 public void setEGLContextClientVersion(int version) { 126 super.setEGLContextClientVersion(version); 127 } 128 129 } 130 } 131