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             mEglDisplay(EGL_NO_DISPLAY),
39             mEglSurface(EGL_NO_SURFACE),
40             mEglContext(EGL_NO_CONTEXT) {
41     }
42 
43     virtual void SetUp();
44     virtual void TearDown();
45 
46     virtual EGLint const* getConfigAttribs();
47     virtual EGLint const* getContextAttribs();
48     virtual EGLint getSurfaceWidth();
49     virtual EGLint getSurfaceHeight();
50     virtual EGLSurface createWindowSurface(EGLDisplay display, EGLConfig config,
51                                            sp<ANativeWindow>& window) const;
52 
53     ::testing::AssertionResult checkPixel(int x, int y,
54             int r, int g, int b, int a, int tolerance = 2);
55     ::testing::AssertionResult assertRectEq(const Rect &r1, const Rect &r2,
56             int tolerance = 1);
57 
58     int mDisplaySecs;
59     sp<SurfaceComposerClient> mComposerClient;
60     sp<SurfaceControl> mSurfaceControl;
61 
62     EGLDisplay mEglDisplay;
63     EGLSurface mEglSurface;
64     EGLContext mEglContext;
65     EGLConfig  mGlConfig;
66 };
67 
68 } // namespace android
69 
70 #endif
71