• 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 // Viewport settings to attempt
23 static const std::vector<GLint> kGLES2TestViewport = {10, 10, 100, 100};
24 
25 // Depth range settings to attempt
26 static const std::vector<GLclampf> kGLES2TestDepthRange = {0.2f, 0.8f};
27 
28 class SnapshotGlViewportTest
29     : public SnapshotPreserveTest,
30       public ::testing::WithParamInterface<std::vector<GLint>> {
defaultStateCheck()31     void defaultStateCheck() override {
32         GLint viewport[4] = {};
33         gl->glGetIntegerv(GL_VIEWPORT, viewport);
34         // initial viewport should match surface size
35         EXPECT_EQ(kTestSurfaceSize[0], viewport[2]);
36         EXPECT_EQ(kTestSurfaceSize[1], viewport[3]);
37     }
changedStateCheck()38     void changedStateCheck() override {
39         EXPECT_TRUE(compareGlobalGlIntv(gl, GL_VIEWPORT, GetParam()));
40     }
stateChange()41     void stateChange() override {
42         gl->glViewport(GetParam()[0], GetParam()[1], GetParam()[2],
43                        GetParam()[3]);
44     }
45 };
46 
TEST_P(SnapshotGlViewportTest,SetViewport)47 TEST_P(SnapshotGlViewportTest, SetViewport) {
48     doCheckedSnapshot();
49 }
50 
51 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotTransformation,
52                          SnapshotGlViewportTest,
53                          ::testing::Values(kGLES2TestViewport));
54 
55 class SnapshotGlDepthRangeTest
56     : public SnapshotSetValueTest<std::vector<GLclampf>>,
57       public ::testing::WithParamInterface<std::vector<GLclampf>> {
stateCheck(std::vector<GLclampf> expected)58     void stateCheck(std::vector<GLclampf> expected) override {
59         EXPECT_TRUE(compareGlobalGlFloatv(gl, GL_DEPTH_RANGE, expected));
60     }
stateChange()61     void stateChange() override {
62         std::vector<GLclampf> testRange = GetParam();
63         gl->glDepthRangef(testRange[0], testRange[1]);
64     }
65 };
66 
TEST_P(SnapshotGlDepthRangeTest,SetDepthRange)67 TEST_P(SnapshotGlDepthRangeTest, SetDepthRange) {
68     std::vector<GLclampf> defaultRange = {0.0f, 1.0f};
69     setExpectedValues(defaultRange, GetParam());
70     doCheckedSnapshot();
71 }
72 
73 INSTANTIATE_TEST_SUITE_P(GLES2SnapshotTransformation,
74                          SnapshotGlDepthRangeTest,
75                          ::testing::Values(kGLES2TestDepthRange));
76 
77 }  // namespace emugl
78