1 /*
2  * Copyright (C) 2011 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 
18 /*
19  * Graphics Test Library
20  */
21 
22 #include <glTestLib.h>
23 
24 #include <EGL/egl.h>
25 #include <EGL/eglext.h>
26 #include <GLES2/gl2.h>
27 #include <GLES2/gl2ext.h>
28 
29 #include "EGLUtils.h"
30 
31 #include <utils/Log.h>
32 #include <testUtil.h>
33 
34 using namespace std;
35 using namespace android;
36 
glTestPrintGLString(const char * name,GLenum s)37 void glTestPrintGLString(const char *name, GLenum s)
38 {
39     const char *v = (const char *) glGetString(s);
40 
41     if (v == NULL) {
42         testPrintI("GL %s unknown", name);
43     } else {
44         testPrintI("GL %s = %s", name, v);
45     }
46 }
47 
glTestCheckEglError(const char * op,EGLBoolean returnVal)48 void glTestCheckEglError(const char* op, EGLBoolean returnVal)
49 {
50     if (returnVal != EGL_TRUE) {
51         testPrintE("%s() returned %d", op, returnVal);
52     }
53 
54     for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
55             = eglGetError()) {
56         testPrintE("after %s() eglError %s (0x%x)",
57                    op, EGLUtils::strerror(error), error);
58     }
59 }
60 
glTestCheckGlError(const char * op)61 void glTestCheckGlError(const char* op)
62 {
63     for (GLint error = glGetError(); error; error
64             = glGetError()) {
65         testPrintE("after %s() glError (0x%x)", op, error);
66     }
67 }
68 
glTestPrintEGLConfiguration(EGLDisplay dpy,EGLConfig config)69 void glTestPrintEGLConfiguration(EGLDisplay dpy, EGLConfig config)
70 {
71 
72 #define X(VAL) {VAL, #VAL}
73     struct {EGLint attribute; const char* name;} names[] = {
74     X(EGL_BUFFER_SIZE),
75     X(EGL_ALPHA_SIZE),
76     X(EGL_BLUE_SIZE),
77     X(EGL_GREEN_SIZE),
78     X(EGL_RED_SIZE),
79     X(EGL_DEPTH_SIZE),
80     X(EGL_STENCIL_SIZE),
81     X(EGL_CONFIG_CAVEAT),
82     X(EGL_CONFIG_ID),
83     X(EGL_LEVEL),
84     X(EGL_MAX_PBUFFER_HEIGHT),
85     X(EGL_MAX_PBUFFER_PIXELS),
86     X(EGL_MAX_PBUFFER_WIDTH),
87     X(EGL_NATIVE_RENDERABLE),
88     X(EGL_NATIVE_VISUAL_ID),
89     X(EGL_NATIVE_VISUAL_TYPE),
90     X(EGL_SAMPLES),
91     X(EGL_SAMPLE_BUFFERS),
92     X(EGL_SURFACE_TYPE),
93     X(EGL_TRANSPARENT_TYPE),
94     X(EGL_TRANSPARENT_RED_VALUE),
95     X(EGL_TRANSPARENT_GREEN_VALUE),
96     X(EGL_TRANSPARENT_BLUE_VALUE),
97     X(EGL_BIND_TO_TEXTURE_RGB),
98     X(EGL_BIND_TO_TEXTURE_RGBA),
99     X(EGL_MIN_SWAP_INTERVAL),
100     X(EGL_MAX_SWAP_INTERVAL),
101     X(EGL_LUMINANCE_SIZE),
102     X(EGL_ALPHA_MASK_SIZE),
103     X(EGL_COLOR_BUFFER_TYPE),
104     X(EGL_RENDERABLE_TYPE),
105     X(EGL_CONFORMANT),
106    };
107 #undef X
108 
109     for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) {
110         EGLint value = -1;
111         EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute,
112                                               &value);
113         EGLint error = eglGetError();
114         if (returnVal && error == EGL_SUCCESS) {
115             testPrintI(" %s: %d (%#x)", names[j].name, value, value);
116         }
117     }
118     testPrintI("");
119 }
120