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 22 import android.os.Bundle; 23 import android.util.Log; 24 import android.view.Window; 25 import android.view.WindowManager; 26 27 import java.lang.InterruptedException; 28 import java.util.concurrent.CountDownLatch; 29 import java.util.concurrent.TimeUnit; 30 31 import javax.microedition.khronos.egl.EGLConfig; 32 import javax.microedition.khronos.opengles.GL10; 33 34 public class OpenGLES20NativeActivityOne extends Activity { 35 36 public static final String EXTRA_VIEW_TYPE = "viewType"; 37 public static final String EXTRA_VIEW_INDEX = "viewIndex"; 38 39 int mValue; 40 41 OpenGLES20View view; 42 GL2Renderer mRenderer; 43 int mRendererType; 44 45 private CountDownLatch mLatch = new CountDownLatch(1); 46 47 /** 48 * Called when the activity is first created. 49 */ 50 @Override 51 public void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 Window window = getWindow(); 54 window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 55 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 56 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 57 | WindowManager.LayoutParams.FLAG_FULLSCREEN 58 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 59 int viewType = getIntent().getIntExtra(EXTRA_VIEW_TYPE, -1); 60 int viewIndex = getIntent().getIntExtra(EXTRA_VIEW_INDEX, -1); 61 62 view = new OpenGLES20View(this, viewType, viewIndex, mLatch); 63 setContentView(view); 64 } 65 66 public boolean waitForFrameDrawn() { 67 boolean result = false; 68 try { 69 result = mLatch.await(10L, TimeUnit.SECONDS); 70 } catch (InterruptedException e) { 71 // just return false 72 } 73 return result; 74 } 75 76 @Override 77 protected void onPause() { 78 super.onPause(); 79 view.onPause(); 80 } 81 82 @Override 83 protected void onResume() { 84 super.onResume(); 85 if(view != null) { 86 view.onResume(); 87 } 88 } 89 90 class OpenGLES20View extends GLSurfaceView { 91 public OpenGLES20View(Context context, int category, int testCase, CountDownLatch latch) { 92 super(context); 93 setEGLContextClientVersion(2); 94 mRenderer = new GL2Renderer(category, testCase, latch); 95 setRenderer(mRenderer); 96 } 97 98 @Override 99 public void setEGLContextClientVersion(int version) { 100 super.setEGLContextClientVersion(version); 101 } 102 103 public GL2Renderer getRenderer() { 104 return mRenderer; 105 } 106 } 107 } 108 class GL2Renderer implements GLSurfaceView.Renderer { 109 private String TAG = "GL2Renderer"; 110 private int mCategory = -1; 111 private int mTestCase = -1; 112 int mAttachShaderError = -1; 113 int mShaderCount = -1; 114 115 private CountDownLatch mLatch; 116 117 public GL2Renderer(int category, int testcase, CountDownLatch latch) { 118 this.mCategory = category; 119 this.mTestCase = testcase; 120 mLatch = latch; 121 } 122 123 public void onDrawFrame(GL10 gl) { 124 125 } 126 127 public void onSurfaceChanged(GL10 gl, int width, int height) { 128 Log.i(TAG ,"onSurfaceCreated"); 129 GL2JniLibOne.init(mCategory, mTestCase, width, height); 130 this.mAttachShaderError = GL2JniLibOne.getAttachShaderError(); 131 Log.i(TAG,"error:" + mAttachShaderError); 132 this.mShaderCount = GL2JniLibOne.getAttachedShaderCount(); 133 Log.i(TAG,"ShaderCount:" + mShaderCount); 134 mLatch.countDown(); 135 } 136 137 public void onSurfaceCreated(GL10 gl, EGLConfig config) { 138 139 } 140 } 141