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