• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include <debug/NullGlesDriver.h>
18 
19 namespace android {
20 namespace uirenderer {
21 namespace debug {
22 
getSkiaInterface()23 sk_sp<const GrGLInterface> NullGlesDriver::getSkiaInterface() {
24     sk_sp<const GrGLInterface> skiaInterface(GrGLCreateNullInterface());
25     return skiaInterface;
26 }
27 
28 struct {
29     GLboolean scissorEnabled;
30 } gState;
31 
nullglGenCommon(GLsizei n,GLuint * buffers)32 static void nullglGenCommon(GLsizei n, GLuint *buffers) {
33     static GLuint nextId = 0;
34     int i;
35     for(i = 0; i < n; i++) {
36         buffers[i] = ++nextId;
37     }
38 }
39 
glGenBuffers_(GLsizei n,GLuint * buffers)40 void NullGlesDriver::glGenBuffers_(GLsizei n, GLuint *buffers) {
41     nullglGenCommon(n, buffers);
42 }
43 
glGenFramebuffers_(GLsizei n,GLuint * framebuffers)44 void NullGlesDriver::glGenFramebuffers_(GLsizei n, GLuint *framebuffers) {
45     nullglGenCommon(n, framebuffers);
46 }
47 
glGenRenderbuffers_(GLsizei n,GLuint * renderbuffers)48 void NullGlesDriver::glGenRenderbuffers_(GLsizei n, GLuint *renderbuffers) {
49     nullglGenCommon(n, renderbuffers);
50 }
51 
glGenTextures_(GLsizei n,GLuint * textures)52 void NullGlesDriver::glGenTextures_(GLsizei n, GLuint *textures) {
53     nullglGenCommon(n, textures);
54 }
55 
glCreateProgram_(void)56 GLuint NullGlesDriver::glCreateProgram_(void) {
57     static GLuint nextProgram = 0;
58     return ++nextProgram;
59 }
60 
glCreateShader_(GLenum type)61 GLuint NullGlesDriver::glCreateShader_(GLenum type) {
62     static GLuint nextShader = 0;
63     return ++nextShader;
64 }
65 
glGetProgramiv_(GLuint program,GLenum pname,GLint * params)66 void NullGlesDriver::glGetProgramiv_(GLuint program, GLenum pname, GLint *params) {
67     switch (pname) {
68     case GL_DELETE_STATUS:
69     case GL_LINK_STATUS:
70     case GL_VALIDATE_STATUS:
71         *params = GL_TRUE;
72         break;
73     case GL_INFO_LOG_LENGTH:
74         *params = 16;
75         break;
76     }
77 }
78 
glGetProgramInfoLog_(GLuint program,GLsizei bufSize,GLsizei * length,GLchar * infoLog)79 void NullGlesDriver::glGetProgramInfoLog_(GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) {
80     *length = snprintf(infoLog, bufSize, "success");
81     if (*length >= bufSize) {
82         *length = bufSize - 1;
83     }
84 }
85 
glGetShaderiv_(GLuint shader,GLenum pname,GLint * params)86 void NullGlesDriver::glGetShaderiv_(GLuint shader, GLenum pname, GLint *params) {
87     switch (pname) {
88     case GL_COMPILE_STATUS:
89     case GL_DELETE_STATUS:
90         *params = GL_TRUE;
91     }
92 }
93 
glGetShaderInfoLog_(GLuint shader,GLsizei bufSize,GLsizei * length,GLchar * infoLog)94 void NullGlesDriver::glGetShaderInfoLog_(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) {
95     *length = snprintf(infoLog, bufSize, "success");
96     if (*length >= bufSize) {
97         *length = bufSize - 1;
98     }
99 }
100 
setBooleanState(GLenum cap,GLboolean value)101 void setBooleanState(GLenum cap, GLboolean value) {
102     switch (cap) {
103     case GL_SCISSOR_TEST:
104         gState.scissorEnabled = value;
105         break;
106     }
107 }
108 
glEnable_(GLenum cap)109 void NullGlesDriver::glEnable_(GLenum cap) {
110     setBooleanState(cap, GL_TRUE);
111 }
112 
glDisable_(GLenum cap)113 void NullGlesDriver::glDisable_(GLenum cap) {
114     setBooleanState(cap, GL_FALSE);
115 }
116 
glIsEnabled_(GLenum cap)117 GLboolean NullGlesDriver::glIsEnabled_(GLenum cap) {
118     switch (cap) {
119     case GL_SCISSOR_TEST:
120         return gState.scissorEnabled;
121     default:
122         return GL_FALSE;
123     }
124 }
125 
glGetIntegerv_(GLenum pname,GLint * data)126 void NullGlesDriver::glGetIntegerv_(GLenum pname, GLint *data) {
127     switch (pname) {
128     case GL_MAX_TEXTURE_SIZE:
129         *data = 2048;
130         break;
131     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
132         *data = 4;
133         break;
134     default:
135         *data = 0;
136     }
137 }
138 
glCheckFramebufferStatus_(GLenum target)139 GLenum NullGlesDriver::glCheckFramebufferStatus_(GLenum target) {
140     switch (target) {
141     case GL_FRAMEBUFFER:
142         return GL_FRAMEBUFFER_COMPLETE;
143     default:
144         return 0; // error case
145     }
146 }
147 
getString(GLenum name)148 static const char* getString(GLenum name) {
149     switch (name) {
150     case GL_VENDOR:
151         return "android";
152     case GL_RENDERER:
153         return "null";
154     case GL_VERSION:
155         return "OpenGL ES 2.0 rev1";
156     case GL_SHADING_LANGUAGE_VERSION:
157         return "OpenGL ES GLSL ES 2.0 rev1";
158     case GL_EXTENSIONS:
159     default:
160         return "";
161     }
162 }
163 
glGetString_(GLenum name)164 const GLubyte* NullGlesDriver::glGetString_(GLenum name) {
165     return (GLubyte*) getString(name);
166 }
167 
168 } // namespace debug
169 } // namespace uirenderer
170 } // namespace android
171