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 24 import java.lang.InterruptedException; 25 import java.util.concurrent.CountDownLatch; 26 import java.util.concurrent.TimeUnit; 27 28 public class OpenGLES20NativeActivityTwo extends Activity { 29 OpenGLES20View view; 30 Renderer mRenderer; 31 int mRendererType; 32 33 private CountDownLatch mLatch = new CountDownLatch(1); 34 35 @Override 36 public void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 } 39 40 public boolean waitForFrameDrawn() { 41 boolean result = false; 42 try { 43 result = mLatch.await(10L, TimeUnit.SECONDS); 44 } catch (InterruptedException e) { 45 // just return false 46 } 47 return result; 48 } 49 50 public void setView(int type, int i, float[] vertexColors ) { 51 view = new OpenGLES20View(this,type,i, vertexColors, mLatch); 52 setContentView(view); 53 } 54 55 public void setView(int type, int i) { 56 57 } 58 59 public int getNoOfAttachedShaders() { 60 return ((RendererBase)mRenderer).mShaderCount[0]; 61 } 62 63 public int glGetError() { 64 return ((RendererBase)mRenderer).mError; 65 } 66 67 @Override 68 protected void onPause() { 69 super.onPause(); 70 if(view != null) { 71 view.onPause(); 72 } 73 74 } 75 76 @Override 77 protected void onResume() { 78 super.onResume(); 79 if(view != null) { 80 view.onResume(); 81 } 82 } 83 84 public float[] getActualColor() { 85 return ((RendererBase) mRenderer).mColorOne; 86 } 87 88 class OpenGLES20View extends GLSurfaceView { 89 90 @Override 91 public void onPause() { 92 super.onPause(); 93 } 94 95 @Override 96 public void onResume() { 97 super.onResume(); 98 } 99 100 public OpenGLES20View(Context context, int type, int index, float[] rgba, 101 CountDownLatch latch) { 102 super(context); 103 setEGLContextClientVersion(2); 104 if(type == Constants.COLOR) { 105 if(index == 1) { 106 mRenderer = new NativeRendererOneColorBufferTest(context, rgba, latch); 107 }else { 108 throw new RuntimeException(); 109 } 110 } 111 setRenderer(mRenderer); 112 } 113 114 @Override 115 public void setEGLContextClientVersion(int version) { 116 super.setEGLContextClientVersion(version); 117 } 118 119 } 120 } 121