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