Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 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.vr.cts;
     17 
     18 import android.content.Context;
     19 import android.content.Intent;
     20 import android.opengl.EGL14;
     21 import android.opengl.GLES32;
     22 import android.test.ActivityInstrumentationTestCase2;
     23 import android.util.DisplayMetrics;
     24 import android.view.WindowManager;
     25 
     26 import java.nio.IntBuffer;
     27 import com.android.compatibility.common.util.CddTest;
     28 
     29 public class VrDisplayTest extends ActivityInstrumentationTestCase2<OpenGLESActivity> {
     30 
     31     private OpenGLESActivity mActivity;
     32 
     33     public VrDisplayTest() {
     34         super(OpenGLESActivity.class);
     35     }
     36 
     37     private OpenGLESActivity getGlEsActivity(int latchCount, int viewIndex) {
     38         Intent intent = new Intent();
     39         intent.putExtra(OpenGLESActivity.EXTRA_LATCH_COUNT, latchCount);
     40         intent.putExtra(OpenGLESActivity.EXTRA_VIEW_INDEX, viewIndex);
     41         intent.putExtra(OpenGLESActivity.EXTRA_PROTECTED, 0);
     42         intent.putExtra(OpenGLESActivity.EXTRA_PRIORITY, 0);
     43         setActivityIntent(intent);
     44         OpenGLESActivity activity = getActivity();
     45         if (latchCount == 1) {
     46           assertTrue(activity.waitForFrameDrawn());
     47         }
     48         return activity;
     49     }
     50 
     51     /**
     52      * Tests that the refresh rate is at least 60Hz.
     53      */
     54      @CddTest(requirement="7.9.2/C-1-15")
     55     public void testRefreshRateIsAtLeast60Hz() throws Throwable {
     56         final int NUM_FRAMES = 200;
     57         // Add an extra frame to allow the activity to start up.
     58         mActivity = getGlEsActivity(NUM_FRAMES + 1, OpenGLESActivity.RENDERER_REFRESHRATE);
     59         if (!mActivity.supportsVrHighPerformance())
     60             return;
     61 
     62         // Skip the first frame to allow for startup time.
     63         mActivity.waitForFrameDrawn();
     64 
     65         // Render a few hundred frames.
     66         long startNanos = System.nanoTime();
     67         while (!mActivity.waitForFrameDrawn());
     68         long endNanos = System.nanoTime();
     69         int error = mActivity.glGetError();
     70         assertEquals(GLES32.GL_NO_ERROR, error);
     71 
     72         double fps = NUM_FRAMES / (double)(endNanos - startNanos) * 1e9;
     73         assertTrue(fps >= 59.);
     74     }
     75 
     76     /**
     77      * Tests that the display resolution is at least 1080p.
     78      */
     79     @CddTest(requirement="7.9.2/C-1-14")
     80     public void testDisplayResolution() {
     81         mActivity = getGlEsActivity(1, OpenGLESActivity.RENDERER_BASIC);
     82         if (!mActivity.supportsVrHighPerformance())
     83             return;
     84 
     85         WindowManager windowManager = (WindowManager)mActivity.getSystemService(
     86             Context.WINDOW_SERVICE);
     87         DisplayMetrics metrics = new DisplayMetrics();
     88 
     89         // Find the real screen size.
     90         int displayWidth;
     91         int displayHeight;
     92         windowManager.getDefaultDisplay().getRealMetrics(metrics);
     93         if (metrics.widthPixels > metrics.heightPixels) {
     94           displayWidth = metrics.widthPixels;
     95           displayHeight = metrics.heightPixels;
     96         } else {
     97           displayWidth = metrics.heightPixels;
     98           displayHeight = metrics.widthPixels;
     99         }
    100         assertTrue(displayWidth >= 1920);
    101         assertTrue(displayHeight >= 1080);
    102     }
    103 
    104 }
    105