1 /* 2 * Copyright (C) 2019 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.gameperformance; 17 18 import javax.microedition.khronos.opengles.GL; 19 import javax.microedition.khronos.opengles.GL10; 20 21 import android.annotation.NonNull; 22 import android.gameperformance.CustomOpenGLView.FrameDrawer; 23 24 /** 25 * Base class for all OpenGL based tests. 26 */ 27 public abstract class OpenGLTest extends BaseTest { OpenGLTest(@onNull GamePerformanceActivity activity)28 public OpenGLTest(@NonNull GamePerformanceActivity activity) { 29 super(activity); 30 } 31 32 @NonNull getView()33 public CustomOpenGLView getView() { 34 return getActivity().getOpenGLView(); 35 } 36 37 // Performs test drawing. draw(GL gl)38 protected abstract void draw(GL gl); 39 40 // Initializes the test on first draw call. 41 private class ParamFrameDrawer implements FrameDrawer { 42 private final double mUnitCount; 43 private boolean mInited; 44 ParamFrameDrawer(double unitCount)45 public ParamFrameDrawer(double unitCount) { 46 mUnitCount = unitCount; 47 mInited = false; 48 } 49 50 @Override drawFrame(GL10 gl)51 public void drawFrame(GL10 gl) { 52 if (!mInited) { 53 initUnits(mUnitCount); 54 mInited = true; 55 } 56 draw(gl); 57 } 58 } 59 60 @Override initProbePass(int probe)61 protected void initProbePass(int probe) { 62 try { 63 getActivity().attachOpenGLView(); 64 } catch (InterruptedException e) { 65 Thread.currentThread().interrupt(); 66 return; 67 } 68 getView().waitRenderReady(); 69 getView().setFrameDrawer(new ParamFrameDrawer(probe * getUnitScale())); 70 } 71 72 @Override freeProbePass()73 protected void freeProbePass() { 74 getView().setFrameDrawer(null); 75 } 76 }