1 /* 2 * Copyright 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_GL_TEST_H 18 #define ANDROID_GL_TEST_H 19 20 #include <gtest/gtest.h> 21 22 #include <gui/SurfaceComposerClient.h> 23 24 #include <EGL/egl.h> 25 #include <GLES/gl.h> 26 27 namespace android { 28 29 class GLTest : public ::testing::Test { 30 public: 31 static void loadShader(GLenum shaderType, const char* pSource, 32 GLuint* outShader); 33 static void createProgram(const char* pVertexSource, 34 const char* pFragmentSource, GLuint* outPgm); 35 36 protected: GLTest()37 GLTest() : 38 mDisplaySecs(0), 39 mEglDisplay(EGL_NO_DISPLAY), 40 mEglSurface(EGL_NO_SURFACE), 41 mEglContext(EGL_NO_CONTEXT), 42 mGlConfig(nullptr) { 43 } 44 45 virtual void SetUp(); 46 virtual void TearDown(); 47 48 virtual EGLint const* getConfigAttribs(); 49 virtual EGLint const* getContextAttribs(); 50 virtual EGLint getSurfaceWidth(); 51 virtual EGLint getSurfaceHeight(); 52 virtual EGLSurface createWindowSurface(EGLDisplay display, EGLConfig config, 53 sp<ANativeWindow>& window) const; 54 55 ::testing::AssertionResult checkPixel(int x, int y, 56 int r, int g, int b, int a, int tolerance = 2); 57 ::testing::AssertionResult assertRectEq(const Rect &r1, const Rect &r2, 58 int tolerance = 1); 59 60 int mDisplaySecs; 61 sp<SurfaceComposerClient> mComposerClient; 62 sp<SurfaceControl> mSurfaceControl; 63 64 EGLDisplay mEglDisplay; 65 EGLSurface mEglSurface; 66 EGLContext mEglContext; 67 EGLConfig mGlConfig; 68 }; 69 70 } // namespace android 71 72 #endif 73