• 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 #pragma once
16 
17 #include "OpenGLESDispatch/OpenGLDispatchLoader.h"
18 
19 #include "base/testing/TestSystem.h"
20 
21 namespace emugl {
22 
23 // Global dispatch object with functions overridden for snapshot testing
24 const GLESv2Dispatch* getSnapshotTestDispatch();
25 
26 // SnapshotTestDispatch - a GL dispatcher with some of its functions overridden
27 // that can act as a drop-in replacement for GLESv2Dispatch. These functions are
28 // given wrappers that perform a test of the GL snapshot when they are called.
29 //
30 // It uses the FrameBuffer to perform the snapshot; thus will only work in an
31 // environment where the FrameBuffer exists.
32 class SnapshotTestDispatch : public GLESv2Dispatch {
33 public:
34     SnapshotTestDispatch();
35 
36 protected:
37     void overrideFunctions();
38 
39     void saveSnapshot();
40 
41     void loadSnapshot();
42 
43     static void testDraw(std::function<void()> doDraw);
44 
test_glDrawArrays(GLenum mode,GLint first,GLsizei count)45     static void test_glDrawArrays(GLenum mode, GLint first, GLsizei count) {
46         testDraw([&] {
47             LazyLoadedGLESv2Dispatch::get()->glDrawArrays(mode, first, count);
48         });
49     }
50 
test_glDrawElements(GLenum mode,GLsizei count,GLenum type,const GLvoid * indices)51     static void test_glDrawElements(GLenum mode,
52                                     GLsizei count,
53                                     GLenum type,
54                                     const GLvoid* indices) {
55         testDraw([&] {
56             LazyLoadedGLESv2Dispatch::get()->glDrawElements(mode, count, type,
57                                                             indices);
58         });
59     }
60 
61     bool mValid = false;
62 
63     int mLoadCount = 0;
64 
65     android::base::TestSystem mTestSystem;
66     std::string mSnapshotPath = {};
67     std::string mSnapshotFile = {};
68     std::string mTextureFile = {};
69 };
70 
71 }  // namespace emugl
72