• 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 "GLSnapshotTestDispatch.h"
16 #include "GLSnapshotTesting.h"
17 #include "Standalone.h"
18 #include "HelloTriangle.h"
19 #include "host-common/GraphicsAgentFactory.h"
20 #include "host-common/testing/MockGraphicsAgentFactory.h"
21 
22 #include <gtest/gtest.h>
23 
24 namespace gfxstream {
25 namespace gl {
26 namespace {
27 
TEST(SnapshotGlRenderingSampleTest,OverrideDispatch)28 TEST(SnapshotGlRenderingSampleTest, OverrideDispatch) {
29     const GLESv2Dispatch* gl = LazyLoadedGLESv2Dispatch::get();
30     const GLESv2Dispatch* testGl = getSnapshotTestDispatch();
31     EXPECT_NE(nullptr, gl);
32     EXPECT_NE(nullptr, testGl);
33     EXPECT_NE(gl->glDrawArrays, testGl->glDrawArrays);
34     EXPECT_NE(gl->glDrawElements, testGl->glDrawElements);
35 }
36 
37 class SnapshotTestTriangle : public HelloTriangle {
38 public:
~SnapshotTestTriangle()39     virtual ~SnapshotTestTriangle() {}
40 
drawLoop()41     void drawLoop() {
42         this->initialize();
43         while (mFrameCount < 5) {
44             this->draw();
45             mFrameCount++;
46             mFb->flushEmulatedEglWindowSurfaceColorBuffer(mSurface);
47             if (mUseSubWindow) {
48                 mFb->post(mColorBuffer);
49                 mWindow->messageLoop();
50             }
51         }
52     }
53 
54 protected:
getGlDispatch()55     const GLESv2Dispatch* getGlDispatch() { return getSnapshotTestDispatch(); }
56 
57     int mFrameCount = 0;
58 };
59 
60 template <typename T>
61 class SnapshotGlRenderingSampleTest : public ::testing::Test {
62 protected:
SetUpTestSuite()63     static void SetUpTestSuite() {
64         android::emulation::injectGraphicsAgents(
65                 android::emulation::MockGraphicsAgentFactory());
66     }
67 
TearDownTestSuite()68     static void TearDownTestSuite() { }
69 
SetUp()70     virtual void SetUp() override {
71         // setupStandaloneLibrarySearchPaths();
72         emugl::set_emugl_window_operations(*getGraphicsAgents()->emu);
73         //const EGLDispatch* egl = LazyLoadedEGLDispatch::get();
74 
75         gl::LazyLoadedGLESv2Dispatch::get();
76         getSnapshotTestDispatch();
77 
78         mApp.reset(new T());
79     }
80 
TearDown()81     virtual void TearDown() override {
82         mApp.reset();
83         EXPECT_EQ(EGL_SUCCESS, LazyLoadedEGLDispatch::get()->eglGetError())
84                 << "SnapshotGlRenderingSampleTest TearDown found an EGL error";
85     }
86 
87     std::unique_ptr<T> mApp;
88 };
89 
90 // To test with additional SampleApplications, extend them to override drawLoop
91 // and getGlDispatch, then add the type to TestSampleApps.
92 using TestSampleApps = ::testing::Types<SnapshotTestTriangle>;
93 TYPED_TEST_SUITE(SnapshotGlRenderingSampleTest, TestSampleApps);
94 
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawOnce)95 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawOnce) {
96     this->mApp->drawOnce();
97 }
98 
TYPED_TEST(SnapshotGlRenderingSampleTest,SnapshotDrawLoop)99 TYPED_TEST(SnapshotGlRenderingSampleTest, SnapshotDrawLoop) {
100     if (this->mApp->isSwANGLE()) {
101         GTEST_SKIP() << "b/254523418 Fails on SwANGLE.";
102     }
103     this->mApp->drawLoop();
104 }
105 
106 }  // namespace
107 }  // namespace gl
108 }  // namespace gfxstream
109