• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2018 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 #include "GLSnapshotTesting.h"
16 #include "OpenGLTestContext.h"
17 
18 #include <gtest/gtest.h>
19 
20 namespace emugl {
21 
22 struct GlStencilFunc {
23     GLenum func;
24     GLint ref;
25     GLuint mask;
26 };
27 
28 struct GlStencilOp {
29     GLenum sfail;
30     GLenum dpfail;
31     GLenum dppass;
32 };
33 
34 struct GlBlendFunc {
35     GLenum srcRGB;
36     GLenum dstRGB;
37     GLenum srcAlpha;
38     GLenum dstAlpha;
39 };
40 
41 // Scissor box settings to attempt
42 static const std::vector<GLint> kGLES2TestScissorBox = {2, 3, 10, 20};
43 
44 // Default stencil operation modes
45 static const GlStencilOp kGLES2DefaultStencilOp = {GL_KEEP, GL_KEEP, GL_KEEP};
46 
47 // Stencil reference value to attempt
48 static const GLint kGLES2TestStencilRef = 1;
49 
50 // Stencil mask values to attempt
51 static const GLuint kGLES2TestStencilMasks[] = {0, 1, 0x1000000, 0x7FFFFFFF};
52 
53 // Blend function settings to attempt
54 static const GlBlendFunc kGLES2TestBlendFuncs[] = {
55         {GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR,
56          GL_ONE_MINUS_DST_COLOR},
57         {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
58          GL_ONE_MINUS_DST_ALPHA},
59         {GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA,
60          GL_ONE_MINUS_CONSTANT_ALPHA},
61         {GL_SRC_ALPHA_SATURATE, GL_ONE, GL_SRC_ALPHA_SATURATE, GL_ONE}};
62 
63 class SnapshotGlScissorBoxTest
64     : public SnapshotSetValueTest<std::vector<GLint>>,
65       public ::testing::WithParamInterface<std::vector<GLint>> {
stateCheck(std::vector<GLint> expected)66     void stateCheck(std::vector<GLint> expected) override {
67         EXPECT_TRUE(compareGlobalGlIntv(gl, GL_SCISSOR_BOX, expected));
68     }
stateChange()69     void stateChange() override {
70         gl->glScissor(GetParam()[0], GetParam()[1], GetParam()[2],
71                       GetParam()[3]);
72     }
73 };
74 
TEST_P(SnapshotGlScissorBoxTest,SetScissorBox)75 TEST_P(SnapshotGlScissorBoxTest, SetScissorBox) {
76     // different drivers act differently; get the default scissorbox
77     std::vector<GLint> defaultBox;
78     defaultBox.resize(4);
79     gl->glGetIntegerv(GL_SCISSOR_BOX, &defaultBox[0]);
80     EXPECT_EQ(GL_NO_ERROR, gl->glGetError());
81 
82     setExpectedValues(defaultBox, GetParam());
83     doCheckedSnapshot();
84 }
85 
86 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
87                          SnapshotGlScissorBoxTest,
88                          ::testing::Values(kGLES2TestScissorBox));
89 
90 // Tests preservation of stencil test conditional state, set by glStencilFunc.
91 class SnapshotGlStencilConditionsTest
92     : public SnapshotSetValueTest<GlStencilFunc> {
stateCheck(GlStencilFunc expected)93     void stateCheck(GlStencilFunc expected) override {
94         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_FUNC, expected.func));
95         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_REF, expected.ref));
96         EXPECT_TRUE(
97                 compareGlobalGlInt(gl, GL_STENCIL_VALUE_MASK, expected.mask));
98         EXPECT_TRUE(
99                 compareGlobalGlInt(gl, GL_STENCIL_BACK_FUNC, expected.func));
100         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_BACK_REF, expected.ref));
101         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_BACK_VALUE_MASK,
102                                        expected.mask));
103     }
stateChange()104     void stateChange() override {
105         GlStencilFunc sFunc = *m_changed_value;
106         gl->glStencilFunc(sFunc.func, sFunc.ref, sFunc.mask);
107     }
108 };
109 
110 class SnapshotGlStencilFuncTest : public SnapshotGlStencilConditionsTest,
111                                   public ::testing::WithParamInterface<GLenum> {
112 };
113 
114 class SnapshotGlStencilMaskTest : public SnapshotGlStencilConditionsTest,
115                                   public ::testing::WithParamInterface<GLuint> {
116 };
117 
TEST_P(SnapshotGlStencilFuncTest,SetStencilFunc)118 TEST_P(SnapshotGlStencilFuncTest, SetStencilFunc) {
119     // different drivers act differently; get the default mask
120     GLint defaultStencilMask;
121     gl->glGetIntegerv(GL_STENCIL_VALUE_MASK, &defaultStencilMask);
122     EXPECT_EQ(GL_NO_ERROR, gl->glGetError());
123 
124     GlStencilFunc defaultStencilFunc = {GL_ALWAYS, 0,
125                                         (GLuint)defaultStencilMask};
126     GlStencilFunc testStencilFunc = {GetParam(), kGLES2TestStencilRef, 0};
127     setExpectedValues(defaultStencilFunc, testStencilFunc);
128     doCheckedSnapshot();
129 }
130 
TEST_P(SnapshotGlStencilMaskTest,SetStencilMask)131 TEST_P(SnapshotGlStencilMaskTest, SetStencilMask) {
132     // different drivers act differently; get the default mask
133     GLint defaultStencilMask;
134     gl->glGetIntegerv(GL_STENCIL_VALUE_MASK, &defaultStencilMask);
135     EXPECT_EQ(GL_NO_ERROR, gl->glGetError());
136 
137     GlStencilFunc defaultStencilFunc = {GL_ALWAYS, 0,
138                                         (GLuint)defaultStencilMask};
139     GlStencilFunc testStencilFunc = {GL_ALWAYS, kGLES2TestStencilRef,
140                                      GetParam()};
141     setExpectedValues(defaultStencilFunc, testStencilFunc);
142     doCheckedSnapshot();
143 }
144 
145 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
146                          SnapshotGlStencilFuncTest,
147                          ::testing::ValuesIn(kGLES2StencilFuncs));
148 
149 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
150                          SnapshotGlStencilMaskTest,
151                          ::testing::ValuesIn(kGLES2TestStencilMasks));
152 
153 class SnapshotGlStencilConsequenceTest
154     : public SnapshotSetValueTest<GlStencilOp> {
stateCheck(GlStencilOp expected)155     void stateCheck(GlStencilOp expected) override {
156         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_FAIL, expected.sfail));
157         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_PASS_DEPTH_FAIL,
158                                        expected.dpfail));
159         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_PASS_DEPTH_PASS,
160                                        expected.dppass));
161         EXPECT_TRUE(
162                 compareGlobalGlInt(gl, GL_STENCIL_BACK_FAIL, expected.sfail));
163         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_BACK_PASS_DEPTH_FAIL,
164                                        expected.dpfail));
165         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_BACK_PASS_DEPTH_PASS,
166                                        expected.dppass));
167     }
stateChange()168     void stateChange() override {
169         GlStencilOp sOp = *m_changed_value;
170         gl->glStencilOp(sOp.sfail, sOp.dpfail, sOp.dppass);
171     }
172 };
173 
174 class SnapshotGlStencilFailTest : public SnapshotGlStencilConsequenceTest,
175                                   public ::testing::WithParamInterface<GLenum> {
176 };
177 
178 class SnapshotGlStencilDepthFailTest
179     : public SnapshotGlStencilConsequenceTest,
180       public ::testing::WithParamInterface<GLenum> {};
181 
182 class SnapshotGlStencilDepthPassTest
183     : public SnapshotGlStencilConsequenceTest,
184       public ::testing::WithParamInterface<GLenum> {};
185 
TEST_P(SnapshotGlStencilFailTest,SetStencilOps)186 TEST_P(SnapshotGlStencilFailTest, SetStencilOps) {
187     GlStencilOp testStencilOp = {GetParam(), GL_KEEP, GL_KEEP};
188     setExpectedValues(kGLES2DefaultStencilOp, testStencilOp);
189     doCheckedSnapshot();
190 }
191 
TEST_P(SnapshotGlStencilDepthFailTest,SetStencilOps)192 TEST_P(SnapshotGlStencilDepthFailTest, SetStencilOps) {
193     GlStencilOp testStencilOp = {GL_KEEP, GetParam(), GL_KEEP};
194     setExpectedValues(kGLES2DefaultStencilOp, testStencilOp);
195     doCheckedSnapshot();
196 }
197 
TEST_P(SnapshotGlStencilDepthPassTest,SetStencilOps)198 TEST_P(SnapshotGlStencilDepthPassTest, SetStencilOps) {
199     GlStencilOp testStencilOp = {GL_KEEP, GL_KEEP, GetParam()};
200     setExpectedValues(kGLES2DefaultStencilOp, testStencilOp);
201     doCheckedSnapshot();
202 }
203 
204 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
205                          SnapshotGlStencilFailTest,
206                          ::testing::ValuesIn(kGLES2StencilOps));
207 
208 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
209                          SnapshotGlStencilDepthFailTest,
210                          ::testing::ValuesIn(kGLES2StencilOps));
211 
212 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
213                          SnapshotGlStencilDepthPassTest,
214                          ::testing::ValuesIn(kGLES2StencilOps));
215 
216 class SnapshotGlDepthFuncTest : public SnapshotSetValueTest<GLenum>,
217                                 public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)218     void stateCheck(GLenum expected) override {
219         EXPECT_TRUE(compareGlobalGlInt(gl, GL_DEPTH_FUNC, expected));
220     }
stateChange()221     void stateChange() override { gl->glDepthFunc(*m_changed_value); }
222 };
223 
TEST_P(SnapshotGlDepthFuncTest,SetDepthFunc)224 TEST_P(SnapshotGlDepthFuncTest, SetDepthFunc) {
225     setExpectedValues(GL_LESS, GetParam());
226     doCheckedSnapshot();
227 }
228 
229 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
230                          SnapshotGlDepthFuncTest,
231                          ::testing::ValuesIn(kGLES2StencilFuncs));
232 
233 class SnapshotGlBlendEquationTest
234     : public SnapshotSetValueTest<GLenum>,
235       public ::testing::WithParamInterface<GLenum> {
stateCheck(GLenum expected)236     void stateCheck(GLenum expected) override {
237         EXPECT_TRUE(compareGlobalGlInt(gl, GL_BLEND_EQUATION_RGB, expected));
238         EXPECT_TRUE(compareGlobalGlInt(gl, GL_BLEND_EQUATION_ALPHA, expected));
239     }
stateChange()240     void stateChange() override { gl->glBlendEquation(*m_changed_value); }
241 };
242 
TEST_P(SnapshotGlBlendEquationTest,SetBlendEquation)243 TEST_P(SnapshotGlBlendEquationTest, SetBlendEquation) {
244     setExpectedValues(GL_FUNC_ADD, GetParam());
245     doCheckedSnapshot();
246 }
247 
248 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
249                          SnapshotGlBlendEquationTest,
250                          ::testing::ValuesIn(kGLES2BlendEquations));
251 
252 class SnapshotGlBlendFuncTest
253     : public SnapshotSetValueTest<GlBlendFunc>,
254       public ::testing::WithParamInterface<GlBlendFunc> {
stateCheck(GlBlendFunc expected)255     void stateCheck(GlBlendFunc expected) {
256         EXPECT_TRUE(compareGlobalGlInt(gl, GL_BLEND_SRC_RGB, expected.srcRGB));
257         EXPECT_TRUE(compareGlobalGlInt(gl, GL_BLEND_DST_RGB, expected.dstRGB));
258         EXPECT_TRUE(
259                 compareGlobalGlInt(gl, GL_BLEND_SRC_ALPHA, expected.srcAlpha));
260         EXPECT_TRUE(
261                 compareGlobalGlInt(gl, GL_BLEND_DST_ALPHA, expected.dstAlpha));
262     }
stateChange()263     void stateChange() {
264         GlBlendFunc target = *m_changed_value;
265         gl->glBlendFuncSeparate(target.srcRGB, target.dstRGB, target.srcAlpha,
266                                 target.dstAlpha);
267     }
268 };
269 
TEST_P(SnapshotGlBlendFuncTest,SetBlendFunc)270 TEST_P(SnapshotGlBlendFuncTest, SetBlendFunc) {
271     GlBlendFunc defaultBlendFunc = {.srcRGB = GL_ONE,
272                                     .dstRGB = GL_ZERO,
273                                     .srcAlpha = GL_ONE,
274                                     .dstAlpha = GL_ZERO};
275     setExpectedValues(defaultBlendFunc, GetParam());
276     doCheckedSnapshot();
277 }
278 
279 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotPixelOps,
280                          SnapshotGlBlendFuncTest,
281                          ::testing::ValuesIn(kGLES2TestBlendFuncs));
282 
283 }  // namespace emugl
284