Debian Codegraph @

tests/GamePerformance/src/android/gameperformance/FillRateOpenGLTest.java

raw symbols SCIP
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 java.util.ArrayList;
19 import java.util.List;
20
21 import javax.microedition.khronos.opengles.GL;
22
23 import android.annotation.NonNull;
24 import android.opengl.GLES20;
25
26 /**
27 * Tests that verifies maximum fill rate per frame can be used to keep FPS close to the device
28 * refresh rate. It works in two modes, blend disabled and blend enabled. This uses few big simple
29 * quad patches.
30 */
31 public class FillRateOpenGLTest extends RenderPatchOpenGLTest {
32 private final float[] BLEND_COLOR = new float[] { 1.0f, 1.0f, 1.0f, 0.2f };
33
34 private final boolean mTestBlend;
35
36 public FillRateOpenGLTest(@NonNull GamePerformanceActivity activity, boolean testBlend) {
37 super(activity);
38 mTestBlend = testBlend;
39 }
40
41 @Override
42 public String getName() {
43 return mTestBlend ? "blend_rate" : "fill_rate";
44 }
45
46 @Override
47 public String getUnitName() {
48 return "screens";
49 }
50
51 @Override
52 public double getUnitScale() {
53 return 0.2;
54 }
55
56 @Override
57 public void initUnits(double screens) {
58 final CustomOpenGLView view = getView();
59 final int pixelRate = (int)Math.round(screens * view.getHeight() * view.getWidth());
60 final int maxPerPath = view.getHeight() * view.getHeight();
61
62 final int patchCount = (int)(pixelRate + maxPerPath -1) / maxPerPath;
63 final float patchDimension =
64 (float)((Math.sqrt(2.0f) * pixelRate / patchCount) / maxPerPath);
65
66 final List<RenderPatchAnimation> renderPatches = new ArrayList<>();
67 final RenderPatch renderPatch = new RenderPatch(2 /* triangleCount for quad */,
68 patchDimension,
69 RenderPatch.TESSELLATION_BASE);
70 for (int i = 0; i < patchCount; ++i) {
71 renderPatches.add(new RenderPatchAnimation(renderPatch, getView().getRenderRatio()));
72 }
73 setRenderPatches(renderPatches);
74 }
75
76 @Override
77 public float[] getColor() {
78 return BLEND_COLOR;
79 }
80
81 @Override
82 public void onBeforeDraw(GL gl) {
83 if (!mTestBlend) {
84 return;
85 }
86
87 // Enable blend if needed.
88 GLES20.glEnable(GLES20.GL_BLEND);
89 OpenGLUtils.checkGlError("disableBlend");
90 GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
91 OpenGLUtils.checkGlError("blendFunction");
92 }
93 }