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