blob: 212b24290e2294df49c1d3bb77a07b4c1755e5e3 [file] [log] [blame]
sergeyv8bd5edf2016-05-13 15:03:35 -07001/*
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
19namespace android {
20namespace uirenderer {
21namespace debug {
22
Derek Sollenberger7e044fe2016-11-07 10:57:59 -050023sk_sp<const GrGLInterface> NullGlesDriver::getSkiaInterface() {
24 sk_sp<const GrGLInterface> skiaInterface(GrGLCreateNullInterface());
25 return skiaInterface;
26}
27
sergeyv8bd5edf2016-05-13 15:03:35 -070028struct {
29 GLboolean scissorEnabled;
30} gState;
31
John Reck1bcacfd2017-11-03 10:12:19 -070032static void nullglGenCommon(GLsizei n, GLuint* buffers) {
sergeyv8bd5edf2016-05-13 15:03:35 -070033 static GLuint nextId = 0;
34 int i;
John Reck1bcacfd2017-11-03 10:12:19 -070035 for (i = 0; i < n; i++) {
sergeyv8bd5edf2016-05-13 15:03:35 -070036 buffers[i] = ++nextId;
37 }
38}
39
John Reck1bcacfd2017-11-03 10:12:19 -070040void NullGlesDriver::glGenBuffers_(GLsizei n, GLuint* buffers) {
sergeyv8bd5edf2016-05-13 15:03:35 -070041 nullglGenCommon(n, buffers);
42}
43
John Reck1bcacfd2017-11-03 10:12:19 -070044void NullGlesDriver::glGenFramebuffers_(GLsizei n, GLuint* framebuffers) {
sergeyv8bd5edf2016-05-13 15:03:35 -070045 nullglGenCommon(n, framebuffers);
46}
47
John Reck1bcacfd2017-11-03 10:12:19 -070048void NullGlesDriver::glGenRenderbuffers_(GLsizei n, GLuint* renderbuffers) {
sergeyv8bd5edf2016-05-13 15:03:35 -070049 nullglGenCommon(n, renderbuffers);
50}
51
John Reck1bcacfd2017-11-03 10:12:19 -070052void NullGlesDriver::glGenTextures_(GLsizei n, GLuint* textures) {
sergeyv8bd5edf2016-05-13 15:03:35 -070053 nullglGenCommon(n, textures);
54}
55
56GLuint NullGlesDriver::glCreateProgram_(void) {
57 static GLuint nextProgram = 0;
58 return ++nextProgram;
59}
60
61GLuint NullGlesDriver::glCreateShader_(GLenum type) {
62 static GLuint nextShader = 0;
63 return ++nextShader;
64}
65
John Reck1bcacfd2017-11-03 10:12:19 -070066void NullGlesDriver::glGetProgramiv_(GLuint program, GLenum pname, GLint* params) {
sergeyv8bd5edf2016-05-13 15:03:35 -070067 switch (pname) {
John Reck1bcacfd2017-11-03 10:12:19 -070068 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;
sergeyv8bd5edf2016-05-13 15:03:35 -070076 }
77}
78
John Reck1bcacfd2017-11-03 10:12:19 -070079void NullGlesDriver::glGetProgramInfoLog_(GLuint program, GLsizei bufSize, GLsizei* length,
80 GLchar* infoLog) {
sergeyv8bd5edf2016-05-13 15:03:35 -070081 *length = snprintf(infoLog, bufSize, "success");
82 if (*length >= bufSize) {
83 *length = bufSize - 1;
84 }
85}
86
John Reck1bcacfd2017-11-03 10:12:19 -070087void NullGlesDriver::glGetShaderiv_(GLuint shader, GLenum pname, GLint* params) {
sergeyv8bd5edf2016-05-13 15:03:35 -070088 switch (pname) {
John Reck1bcacfd2017-11-03 10:12:19 -070089 case GL_COMPILE_STATUS:
90 case GL_DELETE_STATUS:
91 *params = GL_TRUE;
sergeyv8bd5edf2016-05-13 15:03:35 -070092 }
93}
94
John Reck1bcacfd2017-11-03 10:12:19 -070095void NullGlesDriver::glGetShaderInfoLog_(GLuint shader, GLsizei bufSize, GLsizei* length,
96 GLchar* infoLog) {
sergeyv8bd5edf2016-05-13 15:03:35 -070097 *length = snprintf(infoLog, bufSize, "success");
98 if (*length >= bufSize) {
99 *length = bufSize - 1;
100 }
101}
102
103void setBooleanState(GLenum cap, GLboolean value) {
104 switch (cap) {
John Reck1bcacfd2017-11-03 10:12:19 -0700105 case GL_SCISSOR_TEST:
106 gState.scissorEnabled = value;
107 break;
sergeyv8bd5edf2016-05-13 15:03:35 -0700108 }
109}
110
111void NullGlesDriver::glEnable_(GLenum cap) {
112 setBooleanState(cap, GL_TRUE);
113}
114
115void NullGlesDriver::glDisable_(GLenum cap) {
116 setBooleanState(cap, GL_FALSE);
117}
118
119GLboolean NullGlesDriver::glIsEnabled_(GLenum cap) {
120 switch (cap) {
John Reck1bcacfd2017-11-03 10:12:19 -0700121 case GL_SCISSOR_TEST:
122 return gState.scissorEnabled;
123 default:
124 return GL_FALSE;
sergeyv8bd5edf2016-05-13 15:03:35 -0700125 }
126}
127
John Reck1bcacfd2017-11-03 10:12:19 -0700128void NullGlesDriver::glGetIntegerv_(GLenum pname, GLint* data) {
sergeyv8bd5edf2016-05-13 15:03:35 -0700129 switch (pname) {
John Reck1bcacfd2017-11-03 10:12:19 -0700130 case GL_MAX_TEXTURE_SIZE:
131 *data = 2048;
132 break;
133 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
134 *data = 4;
135 break;
136 default:
137 *data = 0;
sergeyv8bd5edf2016-05-13 15:03:35 -0700138 }
139}
140
141GLenum NullGlesDriver::glCheckFramebufferStatus_(GLenum target) {
142 switch (target) {
John Reck1bcacfd2017-11-03 10:12:19 -0700143 case GL_FRAMEBUFFER:
144 return GL_FRAMEBUFFER_COMPLETE;
145 default:
146 return 0; // error case
sergeyv8bd5edf2016-05-13 15:03:35 -0700147 }
148}
149
150static const char* getString(GLenum name) {
151 switch (name) {
John Reck1bcacfd2017-11-03 10:12:19 -0700152 case GL_VENDOR:
153 return "android";
154 case GL_RENDERER:
155 return "null";
156 case GL_VERSION:
157 return "OpenGL ES 2.0 rev1";
158 case GL_SHADING_LANGUAGE_VERSION:
159 return "OpenGL ES GLSL ES 2.0 rev1";
160 case GL_EXTENSIONS:
161 default:
162 return "";
sergeyv8bd5edf2016-05-13 15:03:35 -0700163 }
164}
165
166const GLubyte* NullGlesDriver::glGetString_(GLenum name) {
John Reck1bcacfd2017-11-03 10:12:19 -0700167 return (GLubyte*)getString(name);
sergeyv8bd5edf2016-05-13 15:03:35 -0700168}
169
John Reck1bcacfd2017-11-03 10:12:19 -0700170} // namespace debug
171} // namespace uirenderer
172} // namespace android