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 com.android.cts.verifier.sensors.sixdof.Renderer; 17 18 import android.content.Context; 19 20 import com.android.cts.verifier.sensors.sixdof.Renderer.Renderable.RectangleRenderable; 21 22 import javax.microedition.khronos.egl.EGLConfig; 23 import javax.microedition.khronos.opengles.GL10; 24 25 /** 26 * Renderer for the robustness test 27 */ 28 public class RobustnessRenderer extends BaseRenderer { 29 30 private float[] mRectanglePositionData; 31 private RectangleRenderable mRectangle; 32 RobustnessRenderer(Context context)33 public RobustnessRenderer(Context context) { 34 super(context); 35 } 36 37 @Override onSurfaceCreated(GL10 glUnused, EGLConfig config)38 public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { 39 super.onSurfaceCreated(glUnused, config); 40 mRectangle = new RectangleRenderable(); 41 } 42 43 @Override onSurfaceChanged(GL10 glUnused, int width, int height)44 public void onSurfaceChanged(GL10 glUnused, int width, int height) { 45 super.onSurfaceChanged(glUnused, width, height); 46 mRectangle.initialiseRectangle(mRectanglePositionData); 47 mProjectionMatrix = mFrustrumProjectionMatrix; 48 } 49 setLineColor(float[] newColor)50 public void setLineColor(float[] newColor) { 51 if (mIsValid) { 52 mRectangle.setLineColor(newColor); 53 } 54 } 55 updateCurrentAngle(float newAngle)56 public void updateCurrentAngle(float newAngle) { 57 if (mIsValid) { 58 mRectangle.setRotationAngle(newAngle); 59 } 60 } 61 updateTargetAngle(float newAngle)62 public void updateTargetAngle(float newAngle) { 63 if (mIsValid) { 64 mCameraPreview.setRotationAngle(newAngle); 65 } 66 } 67 68 @Override doPreRenderingSetup()69 protected void doPreRenderingSetup() { 70 // Set view matrix to one that doesn't move. 71 mViewMatrix = mOrthogonalViewMatrix; 72 // Set projection matrix to show camera preview slightly set back. 73 mProjectionMatrix = mFrustrumProjectionMatrix; 74 } 75 76 @Override doTestSpecificRendering()77 protected void doTestSpecificRendering() { 78 // Update the texture with the latest camera frame if there is an update pending. 79 updateCameraTexture(); 80 81 mDrawParameters.update(mViewMatrix, mProjectionMatrix); 82 mRectangle.draw(mDrawParameters); 83 } 84 85 @Override getCameraCoordinates(float left, float right, float bottom, float top)86 protected float[] getCameraCoordinates(float left, float right, float bottom, float top) { 87 // Set rectangle coordinates to be the exact same as the camera preview. 88 mRectanglePositionData = new float[]{ 89 2 * left, 2 * top, 0.0f, 90 2 * left, 2 * bottom, 0.0f, 91 92 2 * left, 2 * bottom, 0.0f, 93 2 * right, 2 * bottom, 0.0f, 94 95 2 * right, 2 * bottom, 0.0f, 96 2 * right, 2 * top, 0.0f, 97 98 2 * right, 2 * top, 0.0f, 99 2 * left, 2 * top, 0.0f, 100 }; 101 102 return new float[]{ 103 2 * left, 2 * top, 0.0f, 104 2 * left, 2 * bottom, 0.0f, 105 2 * right, 2 * top, 0.0f, 106 2 * left, 2 * bottom, 0.0f, 107 2 * right, 2 * bottom, 0.0f, 108 2 * right, 2 * top, 0.0f, 109 }; 110 } 111 } 112