blob: 281f830d328a4d35b67dfd5430fd1ab6087105fc [file] [log] [blame]
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -08001// Copyright (C) 2011 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma version(1)
16
17#pragma rs java_package_name(com.android.perftest)
18
19#include "rs_graphics.rsh"
20#include "subtest_def.rsh"
21
22rs_program_vertex gProgVertex;
23rs_program_fragment gProgFragmentTexture;
Jason Samsc3cff152012-01-06 17:30:29 -080024rs_program_fragment gProgFragmentTextureModulate;
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -080025rs_program_fragment gProgFragmentMultitex;
26
27rs_program_store gProgStoreBlendNone;
28rs_program_store gProgStoreBlendAlpha;
29
30rs_allocation gTexOpaque;
31rs_allocation gTexTorus;
32rs_allocation gTexTransparent;
33rs_allocation gTexChecker;
34
35rs_sampler gLinearClamp;
36rs_sampler gLinearWrap;
37
38typedef struct FillTestData_s {
39 int testId;
40 int blend;
41 int quadCount;
42} FillTestData;
43FillTestData *gData;
44
Jason Samsc3cff152012-01-06 17:30:29 -080045typedef struct FillTestFragData_s {
46 float4 modulate;
47} FillTestFragData;
48FillTestFragData *gFragData;
49
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -080050static float gDt = 0.0f;
51
52void init() {
53}
54
55static int gRenderSurfaceW = 1280;
56static int gRenderSurfaceH = 720;
57
58static void bindProgramVertexOrtho() {
59 // Default vertex shader
60 rsgBindProgramVertex(gProgVertex);
61 // Setup the projection matrix
62 rs_matrix4x4 proj;
63 rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
64 rsgProgramVertexLoadProjectionMatrix(&proj);
65}
66
Jason Samsc3cff152012-01-06 17:30:29 -080067static void displaySingletexFill(bool blend, int quadCount, bool modulate) {
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -080068 bindProgramVertexOrtho();
69 rs_matrix4x4 matrix;
70 rsMatrixLoadIdentity(&matrix);
71 rsgProgramVertexLoadModelMatrix(&matrix);
72
73 // Fragment shader with texture
74 if (!blend) {
75 rsgBindProgramStore(gProgStoreBlendNone);
76 } else {
77 rsgBindProgramStore(gProgStoreBlendAlpha);
78 }
Jason Samsc3cff152012-01-06 17:30:29 -080079 if (modulate) {
80 rsgBindProgramFragment(gProgFragmentTextureModulate);
81 rsgBindSampler(gProgFragmentTextureModulate, 0, gLinearClamp);
82 rsgBindTexture(gProgFragmentTextureModulate, 0, gTexOpaque);
83
84 gFragData->modulate.r = 0.8f;
85 gFragData->modulate.g = 0.7f;
86 gFragData->modulate.b = 0.8f;
87 gFragData->modulate.a = 0.5f;
88 rsgAllocationSyncAll(rsGetAllocation(gFragData));
89 } else {
90 rsgBindProgramFragment(gProgFragmentTexture);
91 rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
92 rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
93 }
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -080094
95 for (int i = 0; i < quadCount; i ++) {
96 float startX = 5 * i, startY = 5 * i;
97 float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
98 rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
99 startX, startY + height, 0, 0, 1,
100 startX + width, startY + height, 0, 1, 1,
101 startX + width, startY, 0, 1, 0);
102 }
103}
104
105static void displayMultitextureSample(bool blend, int quadCount) {
106 bindProgramVertexOrtho();
107 rs_matrix4x4 matrix;
108 rsMatrixLoadIdentity(&matrix);
109 rsgProgramVertexLoadModelMatrix(&matrix);
110
111 // Fragment shader with texture
112 if (!blend) {
113 rsgBindProgramStore(gProgStoreBlendNone);
114 } else {
115 rsgBindProgramStore(gProgStoreBlendAlpha);
116 }
117 rsgBindProgramFragment(gProgFragmentMultitex);
118 rsgBindSampler(gProgFragmentMultitex, 0, gLinearClamp);
119 rsgBindSampler(gProgFragmentMultitex, 1, gLinearWrap);
120 rsgBindSampler(gProgFragmentMultitex, 2, gLinearClamp);
121 rsgBindTexture(gProgFragmentMultitex, 0, gTexChecker);
122 rsgBindTexture(gProgFragmentMultitex, 1, gTexTorus);
123 rsgBindTexture(gProgFragmentMultitex, 2, gTexTransparent);
124
125 for (int i = 0; i < quadCount; i ++) {
126 float startX = 10 * i, startY = 10 * i;
127 float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
128 rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
129 startX, startY + height, 0, 0, 1,
130 startX + width, startY + height, 0, 1, 1,
131 startX + width, startY, 0, 1, 0);
132 }
133}
134
135
136void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
137 TestData *testData = (TestData*)usrData;
138 gRenderSurfaceW = testData->renderSurfaceW;
139 gRenderSurfaceH = testData->renderSurfaceH;
140 gDt = testData->dt;
141
142 gData = (FillTestData*)v_in;
143
144 switch(gData->testId) {
145 case 0:
146 displayMultitextureSample(gData->blend == 1 ? true : false, gData->quadCount);
147 break;
148 case 1:
Jason Samsc3cff152012-01-06 17:30:29 -0800149 displaySingletexFill(gData->blend == 1 ? true : false, gData->quadCount, false);
150 break;
151 case 2:
152 displaySingletexFill(gData->blend == 1 ? true : false, gData->quadCount, true);
Alex Sakhartchouk1fe2ef02011-11-10 15:27:51 -0800153 break;
154 default:
155 rsDebug("Wrong test number", 0);
156 break;
157 }
158}