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 19namespace android { 20namespace uirenderer { 21namespace debug { 22 23sk_sp<const GrGLInterface> NullGlesDriver::getSkiaInterface() { 24 sk_sp<const GrGLInterface> skiaInterface(GrGLCreateNullInterface()); 25 return skiaInterface; 26} 27 28struct { 29 GLboolean scissorEnabled; 30} gState; 31 32static 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 40void NullGlesDriver::glGenBuffers_(GLsizei n, GLuint* buffers) { 41 nullglGenCommon(n, buffers); 42} 43 44void NullGlesDriver::glGenFramebuffers_(GLsizei n, GLuint* framebuffers) { 45 nullglGenCommon(n, framebuffers); 46} 47 48void NullGlesDriver::glGenRenderbuffers_(GLsizei n, GLuint* renderbuffers) { 49 nullglGenCommon(n, renderbuffers); 50} 51 52void NullGlesDriver::glGenTextures_(GLsizei n, GLuint* textures) { 53 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 66void 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 79void NullGlesDriver::glGetProgramInfoLog_(GLuint program, GLsizei bufSize, GLsizei* length, 80 GLchar* infoLog) { 81 *length = snprintf(infoLog, bufSize, "success"); 82 if (*length >= bufSize) { 83 *length = bufSize - 1; 84 } 85} 86 87void NullGlesDriver::glGetShaderiv_(GLuint shader, GLenum pname, GLint* params) { 88 switch (pname) { 89 case GL_COMPILE_STATUS: 90 case GL_DELETE_STATUS: 91 *params = GL_TRUE; 92 } 93} 94 95void NullGlesDriver::glGetShaderInfoLog_(GLuint shader, GLsizei bufSize, GLsizei* length, 96 GLchar* infoLog) { 97 *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) { 105 case GL_SCISSOR_TEST: 106 gState.scissorEnabled = value; 107 break; 108 } 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) { 121 case GL_SCISSOR_TEST: 122 return gState.scissorEnabled; 123 default: 124 return GL_FALSE; 125 } 126} 127 128void NullGlesDriver::glGetIntegerv_(GLenum pname, GLint* data) { 129 switch (pname) { 130 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; 138 } 139} 140 141GLenum NullGlesDriver::glCheckFramebufferStatus_(GLenum target) { 142 switch (target) { 143 case GL_FRAMEBUFFER: 144 return GL_FRAMEBUFFER_COMPLETE; 145 default: 146 return 0; // error case 147 } 148} 149 150static const char* getString(GLenum name) { 151 switch (name) { 152 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 ""; 163 } 164} 165 166const GLubyte* NullGlesDriver::glGetString_(GLenum name) { 167 return (GLubyte*)getString(name); 168} 169 170} // namespace debug 171} // namespace uirenderer 172} // namespace android 173