• 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 
17 #include <gtest/gtest.h>
18 
19 namespace gfxstream {
20 namespace gl {
21 namespace {
22 
23 class SnapshotGlColorMaskTest
24     : public SnapshotSetValueTest<std::vector<GLboolean>> {
stateCheck(std::vector<GLboolean> expected)25     void stateCheck(std::vector<GLboolean> expected) override {
26         EXPECT_TRUE(compareGlobalGlBooleanv(gl, GL_COLOR_WRITEMASK, expected));
27     }
stateChange()28     void stateChange() override {
29         std::vector<GLboolean> mask = *m_changed_value;
30         gl->glColorMask(mask[0], mask[1], mask[2], mask[3]);
31     }
32 };
33 
TEST_F(SnapshotGlColorMaskTest,SetColorMask)34 TEST_F(SnapshotGlColorMaskTest, SetColorMask) {
35     setExpectedValues({true, true, true, true}, {false, false, false, false});
36     doCheckedSnapshot();
37 }
38 
39 class SnapshotGlDepthMaskTest : public SnapshotSetValueTest<GLboolean> {
stateCheck(GLboolean expected)40     void stateCheck(GLboolean expected) override {
41         EXPECT_TRUE(compareGlobalGlBoolean(gl, GL_DEPTH_WRITEMASK, expected));
42     }
stateChange()43     void stateChange() override { gl->glDepthMask(*m_changed_value); }
44 };
45 
TEST_F(SnapshotGlDepthMaskTest,SetDepthMask)46 TEST_F(SnapshotGlDepthMaskTest, SetDepthMask) {
47     setExpectedValues(true, false);
48     doCheckedSnapshot();
49 }
50 
51 // not to be confused with GL_STENCIL_VALUE_MASK
52 class SnapshotGlStencilWriteMaskTest : public SnapshotSetValueTest<GLuint> {
stateCheck(GLuint expected)53     void stateCheck(GLuint expected) override {
54         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_WRITEMASK, expected));
55         EXPECT_TRUE(
56                 compareGlobalGlInt(gl, GL_STENCIL_BACK_WRITEMASK, expected));
57     }
stateChange()58     void stateChange() override { gl->glStencilMask(*m_changed_value); }
59 };
60 
TEST_F(SnapshotGlStencilWriteMaskTest,SetStencilMask)61 TEST_F(SnapshotGlStencilWriteMaskTest, SetStencilMask) {
62     // different drivers act differently; get the default mask
63     GLint defaultWriteMask;
64     gl->glGetIntegerv(GL_STENCIL_WRITEMASK, &defaultWriteMask);
65     EXPECT_EQ(GL_NO_ERROR, gl->glGetError());
66 
67     setExpectedValues(defaultWriteMask, 0);
68     doCheckedSnapshot();
69 }
70 
71 class SnapshotGlColorClearValueTest
72     : public SnapshotSetValueTest<std::vector<GLclampf>> {
stateCheck(std::vector<GLclampf> expected)73     void stateCheck(std::vector<GLclampf> expected) override {
74         EXPECT_TRUE(compareGlobalGlFloatv(gl, GL_COLOR_CLEAR_VALUE, expected));
75     }
stateChange()76     void stateChange() override {
77         std::vector<GLclampf> color = *m_changed_value;
78         gl->glClearColor(color[0], color[1], color[2], color[3]);
79     }
80 };
81 
TEST_F(SnapshotGlColorClearValueTest,SetClearColor)82 TEST_F(SnapshotGlColorClearValueTest, SetClearColor) {
83     setExpectedValues({0, 0, 0, 0}, {1.0f, 0.2f, 0.7f, 0.8f});
84     doCheckedSnapshot();
85 }
86 
87 class SnapshotGlDepthClearValueTest : public SnapshotSetValueTest<GLclampf> {
stateCheck(GLclampf expected)88     void stateCheck(GLclampf expected) override {
89         EXPECT_TRUE(compareGlobalGlFloat(gl, GL_DEPTH_CLEAR_VALUE, expected));
90     }
stateChange()91     void stateChange() override { gl->glClearDepthf(*m_changed_value); }
92 };
93 
TEST_F(SnapshotGlDepthClearValueTest,SetClearDepth)94 TEST_F(SnapshotGlDepthClearValueTest, SetClearDepth) {
95     setExpectedValues(1.0f, 0.4f);
96     doCheckedSnapshot();
97 }
98 
99 class SnapshotGlStencilClearValueTest : public SnapshotSetValueTest<GLint> {
stateCheck(GLint expected)100     void stateCheck(GLint expected) override {
101         EXPECT_TRUE(compareGlobalGlInt(gl, GL_STENCIL_CLEAR_VALUE, expected));
102     }
stateChange()103     void stateChange() override { gl->glClearStencil(*m_changed_value); }
104 };
105 
TEST_F(SnapshotGlStencilClearValueTest,SetClearStencil)106 TEST_F(SnapshotGlStencilClearValueTest, SetClearStencil) {
107     setExpectedValues(0, 3);
108     doCheckedSnapshot();
109 }
110 
111 }  // namespace
112 }  // namespace gl
113 }  // namespace gfxstream
114