Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 "rsDevice.h" |
| 18 | #include "rsContext.h" |
| 19 | #include "rsThreadIO.h" |
Mathias Agopian | 5ae678f | 2009-06-22 18:01:09 -0700 | [diff] [blame] | 20 | #include <ui/FramebufferNativeWindow.h> |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 21 | #include <ui/PixelFormat.h> |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 22 | #include <ui/EGLUtils.h> |
Mathias Agopian | 9b97c29 | 2010-02-12 12:00:38 -0800 | [diff] [blame] | 23 | #include <ui/egl/android_natives.h> |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/resource.h> |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 27 | #include <sched.h> |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 28 | |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 29 | #include <cutils/properties.h> |
| 30 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 31 | #include <GLES/gl.h> |
| 32 | #include <GLES/glext.h> |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 33 | #include <GLES2/gl2.h> |
| 34 | #include <GLES2/gl2ext.h> |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 35 | |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 36 | #include <cutils/sched_policy.h> |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 37 | #include <sys/syscall.h> |
| 38 | #include <string.h> |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 39 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | using namespace android; |
| 41 | using namespace android::renderscript; |
| 42 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 43 | pthread_key_t Context::gThreadTLSKey = 0; |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 44 | uint32_t Context::gThreadTLSKeyCount = 0; |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 45 | uint32_t Context::gGLContextCount = 0; |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 46 | pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 47 | |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 48 | static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) { |
| 49 | if (returnVal != EGL_TRUE) { |
| 50 | fprintf(stderr, "%s() returned %d\n", op, returnVal); |
| 51 | } |
| 52 | |
| 53 | for (EGLint error = eglGetError(); error != EGL_SUCCESS; error |
| 54 | = eglGetError()) { |
| 55 | fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error), |
| 56 | error); |
| 57 | } |
| 58 | } |
| 59 | |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 60 | void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) { |
| 61 | |
| 62 | #define X(VAL) {VAL, #VAL} |
| 63 | struct {EGLint attribute; const char* name;} names[] = { |
| 64 | X(EGL_BUFFER_SIZE), |
| 65 | X(EGL_ALPHA_SIZE), |
| 66 | X(EGL_BLUE_SIZE), |
| 67 | X(EGL_GREEN_SIZE), |
| 68 | X(EGL_RED_SIZE), |
| 69 | X(EGL_DEPTH_SIZE), |
| 70 | X(EGL_STENCIL_SIZE), |
| 71 | X(EGL_CONFIG_CAVEAT), |
| 72 | X(EGL_CONFIG_ID), |
| 73 | X(EGL_LEVEL), |
| 74 | X(EGL_MAX_PBUFFER_HEIGHT), |
| 75 | X(EGL_MAX_PBUFFER_PIXELS), |
| 76 | X(EGL_MAX_PBUFFER_WIDTH), |
| 77 | X(EGL_NATIVE_RENDERABLE), |
| 78 | X(EGL_NATIVE_VISUAL_ID), |
| 79 | X(EGL_NATIVE_VISUAL_TYPE), |
| 80 | X(EGL_SAMPLES), |
| 81 | X(EGL_SAMPLE_BUFFERS), |
| 82 | X(EGL_SURFACE_TYPE), |
| 83 | X(EGL_TRANSPARENT_TYPE), |
| 84 | X(EGL_TRANSPARENT_RED_VALUE), |
| 85 | X(EGL_TRANSPARENT_GREEN_VALUE), |
| 86 | X(EGL_TRANSPARENT_BLUE_VALUE), |
| 87 | X(EGL_BIND_TO_TEXTURE_RGB), |
| 88 | X(EGL_BIND_TO_TEXTURE_RGBA), |
| 89 | X(EGL_MIN_SWAP_INTERVAL), |
| 90 | X(EGL_MAX_SWAP_INTERVAL), |
| 91 | X(EGL_LUMINANCE_SIZE), |
| 92 | X(EGL_ALPHA_MASK_SIZE), |
| 93 | X(EGL_COLOR_BUFFER_TYPE), |
| 94 | X(EGL_RENDERABLE_TYPE), |
| 95 | X(EGL_CONFORMANT), |
| 96 | }; |
| 97 | #undef X |
| 98 | |
| 99 | for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) { |
| 100 | EGLint value = -1; |
| 101 | EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value); |
| 102 | EGLint error = eglGetError(); |
| 103 | if (returnVal && error == EGL_SUCCESS) { |
| 104 | LOGV(" %s: %d (0x%x)", names[j].name, value, value); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 110 | bool Context::initGLThread() { |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 111 | pthread_mutex_lock(&gInitMutex); |
| 112 | LOGV("initGLThread start %p", this); |
| 113 | |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 114 | mEGL.mNumConfigs = -1; |
| 115 | EGLint configAttribs[128]; |
| 116 | EGLint *configAttribsPtr = configAttribs; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 117 | EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 118 | |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 119 | memset(configAttribs, 0, sizeof(configAttribs)); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 120 | |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 121 | configAttribsPtr[0] = EGL_SURFACE_TYPE; |
| 122 | configAttribsPtr[1] = EGL_WINDOW_BIT; |
| 123 | configAttribsPtr += 2; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 124 | |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 125 | configAttribsPtr[0] = EGL_RENDERABLE_TYPE; |
| 126 | configAttribsPtr[1] = EGL_OPENGL_ES2_BIT; |
| 127 | configAttribsPtr += 2; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 128 | |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 129 | if (mUserSurfaceConfig.depthMin > 0) { |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 130 | configAttribsPtr[0] = EGL_DEPTH_SIZE; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 131 | configAttribsPtr[1] = mUserSurfaceConfig.depthMin; |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 132 | configAttribsPtr += 2; |
| 133 | } |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 134 | |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 135 | if (mDev->mForceSW) { |
| 136 | configAttribsPtr[0] = EGL_CONFIG_CAVEAT; |
| 137 | configAttribsPtr[1] = EGL_SLOW_CONFIG; |
| 138 | configAttribsPtr += 2; |
| 139 | } |
| 140 | |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 141 | configAttribsPtr[0] = EGL_NONE; |
| 142 | rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint)))); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 143 | |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 144 | LOGV("%p initEGL start", this); |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 145 | mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 146 | checkEglError("eglGetDisplay"); |
| 147 | |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 148 | eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion); |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 149 | checkEglError("eglInitialize"); |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 150 | |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 151 | #if 1 |
| 152 | PixelFormat pf = PIXEL_FORMAT_RGBA_8888; |
| 153 | if (mUserSurfaceConfig.alphaMin == 0) { |
| 154 | pf = PIXEL_FORMAT_RGBX_8888; |
| 155 | } |
| 156 | |
| 157 | status_t err = EGLUtils::selectConfigForPixelFormat(mEGL.mDisplay, configAttribs, pf, &mEGL.mConfig); |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 158 | if (err) { |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 159 | LOGE("%p, couldn't find an EGLConfig matching the screen format\n", this); |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 160 | } |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 161 | if (props.mLogVisual) { |
| 162 | printEGLConfiguration(mEGL.mDisplay, mEGL.mConfig); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 163 | } |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 164 | #else |
| 165 | eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs); |
| 166 | #endif |
| 167 | |
| 168 | mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2); |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 169 | checkEglError("eglCreateContext"); |
| 170 | if (mEGL.mContext == EGL_NO_CONTEXT) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 171 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 172 | LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", this); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 173 | return false; |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 174 | } |
| 175 | gGLContextCount++; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 176 | |
| 177 | |
| 178 | EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; |
| 179 | mEGL.mSurfaceDefault = eglCreatePbufferSurface(mEGL.mDisplay, mEGL.mConfig, pbuffer_attribs); |
| 180 | checkEglError("eglCreatePbufferSurface"); |
| 181 | if (mEGL.mSurfaceDefault == EGL_NO_SURFACE) { |
| 182 | LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE"); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 183 | pthread_mutex_unlock(&gInitMutex); |
| 184 | deinitEGL(); |
| 185 | return false; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | EGLBoolean ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurfaceDefault, mEGL.mSurfaceDefault, mEGL.mContext); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 189 | if (ret == EGL_FALSE) { |
| 190 | LOGE("eglMakeCurrent returned EGL_FALSE"); |
| 191 | checkEglError("eglMakeCurrent", ret); |
| 192 | pthread_mutex_unlock(&gInitMutex); |
| 193 | deinitEGL(); |
| 194 | return false; |
| 195 | } |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 196 | |
| 197 | mGL.mVersion = glGetString(GL_VERSION); |
| 198 | mGL.mVendor = glGetString(GL_VENDOR); |
| 199 | mGL.mRenderer = glGetString(GL_RENDERER); |
| 200 | mGL.mExtensions = glGetString(GL_EXTENSIONS); |
| 201 | |
| 202 | //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion); |
| 203 | LOGV("GL Version %s", mGL.mVersion); |
| 204 | //LOGV("GL Vendor %s", mGL.mVendor); |
| 205 | LOGV("GL Renderer %s", mGL.mRenderer); |
| 206 | //LOGV("GL Extensions %s", mGL.mExtensions); |
| 207 | |
| 208 | const char *verptr = NULL; |
| 209 | if (strlen((const char *)mGL.mVersion) > 9) { |
| 210 | if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) { |
| 211 | verptr = (const char *)mGL.mVersion + 12; |
| 212 | } |
| 213 | if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) { |
| 214 | verptr = (const char *)mGL.mVersion + 9; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if (!verptr) { |
| 219 | LOGE("Error, OpenGL ES Lite not supported"); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 220 | pthread_mutex_unlock(&gInitMutex); |
| 221 | deinitEGL(); |
| 222 | return false; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 223 | } else { |
| 224 | sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion); |
| 225 | } |
| 226 | |
| 227 | glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs); |
| 228 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors); |
| 229 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits); |
| 230 | |
| 231 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors); |
| 232 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits); |
| 233 | |
| 234 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits); |
| 235 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors); |
| 236 | |
| 237 | mGL.OES_texture_npot = NULL != strstr((const char *)mGL.mExtensions, "GL_OES_texture_npot"); |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 238 | mGL.GL_NV_texture_npot_2D_mipmap = NULL != strstr((const char *)mGL.mExtensions, "GL_NV_texture_npot_2D_mipmap"); |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 239 | mGL.EXT_texture_max_aniso = 1.0f; |
| 240 | bool hasAniso = NULL != strstr((const char *)mGL.mExtensions, "GL_EXT_texture_filter_anisotropic"); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 241 | if (hasAniso) { |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 242 | glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mGL.EXT_texture_max_aniso); |
| 243 | } |
| 244 | |
| 245 | LOGV("initGLThread end %p", this); |
| 246 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 247 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 250 | void Context::deinitEGL() { |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 251 | LOGV("%p, deinitEGL", this); |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 252 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 253 | if (mEGL.mContext != EGL_NO_CONTEXT) { |
| 254 | eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, mEGL.mContext); |
| 255 | eglDestroyContext(mEGL.mDisplay, mEGL.mContext); |
| 256 | checkEglError("eglDestroyContext"); |
| 257 | } |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 258 | |
| 259 | gGLContextCount--; |
| 260 | if (!gGLContextCount) { |
| 261 | eglTerminate(mEGL.mDisplay); |
| 262 | } |
| 263 | } |
| 264 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 265 | Context::PushState::PushState(Context *con) { |
| 266 | mRsc = con; |
| 267 | mFragment.set(con->getProgramFragment()); |
| 268 | mVertex.set(con->getProgramVertex()); |
| 269 | mStore.set(con->getProgramStore()); |
| 270 | mRaster.set(con->getProgramRaster()); |
Alex Sakhartchouk | 5c0912b | 2010-11-18 16:36:47 -0800 | [diff] [blame] | 271 | mFont.set(con->getFont()); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | Context::PushState::~PushState() { |
| 275 | mRsc->setProgramFragment(mFragment.get()); |
| 276 | mRsc->setProgramVertex(mVertex.get()); |
| 277 | mRsc->setProgramStore(mStore.get()); |
| 278 | mRsc->setProgramRaster(mRaster.get()); |
| 279 | mRsc->setFont(mFont.get()); |
| 280 | } |
| 281 | |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 282 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 283 | uint32_t Context::runScript(Script *s) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 284 | PushState(this); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 285 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 286 | uint32_t ret = s->run(this); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 287 | return ret; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame^] | 290 | void Context::checkError(const char *msg, bool isFatal) const { |
| 291 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 292 | GLenum err = glGetError(); |
| 293 | if (err != GL_NO_ERROR) { |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame^] | 294 | char buf[1024]; |
| 295 | snprintf(buf, sizeof(buf), "GL Error = 0x%08x, from: %s", err, msg); |
| 296 | |
| 297 | if (isFatal) { |
| 298 | setError(RS_ERROR_FATAL_DRIVER, buf); |
| 299 | } else { |
| 300 | switch (err) { |
| 301 | case GL_OUT_OF_MEMORY: |
| 302 | setError(RS_ERROR_OUT_OF_MEMORY, buf); |
| 303 | break; |
| 304 | default: |
| 305 | setError(RS_ERROR_DRIVER, buf); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | LOGE("%p, %s", this, buf); |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 313 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 314 | uint32_t Context::runRootScript() { |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 315 | glViewport(0, 0, mWidth, mHeight); |
Jason Sams | 306fb23 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 316 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 317 | timerSet(RS_TIMER_SCRIPT); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 318 | mStateFragmentStore.mLast.clear(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 319 | uint32_t ret = runScript(mRootScript.get()); |
Jason Sams | 8cfdd24 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 320 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 321 | checkError("runRootScript"); |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 322 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 325 | uint64_t Context::getTime() const { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 326 | struct timespec t; |
| 327 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 328 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); |
| 329 | } |
| 330 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 331 | void Context::timerReset() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 332 | for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { |
| 333 | mTimers[ct] = 0; |
| 334 | } |
| 335 | } |
| 336 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 337 | void Context::timerInit() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 338 | mTimeLast = getTime(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 339 | mTimeFrame = mTimeLast; |
| 340 | mTimeLastFrame = mTimeLast; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 341 | mTimerActive = RS_TIMER_INTERNAL; |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 342 | mAverageFPSFrameCount = 0; |
| 343 | mAverageFPSStartTime = mTimeLast; |
| 344 | mAverageFPS = 0; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 345 | timerReset(); |
| 346 | } |
| 347 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 348 | void Context::timerFrame() { |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 349 | mTimeLastFrame = mTimeFrame; |
| 350 | mTimeFrame = getTime(); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 351 | // Update average fps |
| 352 | const uint64_t averageFramerateInterval = 1000 * 1000000; |
| 353 | mAverageFPSFrameCount ++; |
| 354 | uint64_t inverval = mTimeFrame - mAverageFPSStartTime; |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 355 | if (inverval >= averageFramerateInterval) { |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 356 | inverval = inverval / 1000000; |
| 357 | mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval; |
| 358 | mAverageFPSFrameCount = 0; |
| 359 | mAverageFPSStartTime = mTimeFrame; |
| 360 | } |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 363 | void Context::timerSet(Timers tm) { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 364 | uint64_t last = mTimeLast; |
| 365 | mTimeLast = getTime(); |
| 366 | mTimers[mTimerActive] += mTimeLast - last; |
| 367 | mTimerActive = tm; |
| 368 | } |
| 369 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 370 | void Context::timerPrint() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 371 | double total = 0; |
| 372 | for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { |
| 373 | total += mTimers[ct]; |
| 374 | } |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 375 | uint64_t frame = mTimeFrame - mTimeLastFrame; |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 376 | mTimeMSLastFrame = frame / 1000000; |
| 377 | mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; |
| 378 | mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 379 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 380 | |
| 381 | if (props.mLogTimes) { |
Alex Sakhartchouk | 64cd98e | 2010-10-18 17:18:50 -0700 | [diff] [blame] | 382 | LOGV("RS: Frame (%i), Script %2.1f%% (%i), Swap %2.1f%% (%i), Idle %2.1f%% (%lli), Internal %2.1f%% (%lli), Avg fps: %u", |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 383 | mTimeMSLastFrame, |
| 384 | 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, |
| 385 | 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, |
| 386 | 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 387 | 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000, |
| 388 | mAverageFPS); |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 389 | } |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 392 | bool Context::setupCheck() { |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 393 | if (!mShaderCache.lookup(this, mVertex.get(), mFragment.get())) { |
| 394 | LOGE("Context::setupCheck() 1 fail"); |
| 395 | return false; |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 396 | } |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 397 | |
| 398 | mFragmentStore->setupGL2(this, &mStateFragmentStore); |
| 399 | mFragment->setupGL2(this, &mStateFragment, &mShaderCache); |
| 400 | mRaster->setupGL2(this, &mStateRaster); |
| 401 | mVertex->setupGL2(this, &mStateVertex, &mShaderCache); |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 402 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Alex Sakhartchouk | 889fe50 | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 405 | void Context::setupProgramStore() { |
| 406 | mFragmentStore->setupGL2(this, &mStateFragmentStore); |
| 407 | } |
| 408 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 409 | static bool getProp(const char *str) { |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 410 | char buf[PROPERTY_VALUE_MAX]; |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 411 | property_get(str, buf, "0"); |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 412 | return 0 != strcmp(buf, "0"); |
| 413 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 414 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 415 | void Context::displayDebugStats() { |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 416 | char buffer[128]; |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 417 | sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript); |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 418 | float oldR, oldG, oldB, oldA; |
| 419 | mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA); |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 420 | uint32_t bufferLen = strlen(buffer); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 421 | |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 422 | float shadowCol = 0.1f; |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 423 | mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 424 | mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 425 | |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 426 | mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 427 | mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 428 | |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 429 | mStateFont.setFontColor(oldR, oldG, oldB, oldA); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 432 | void * Context::threadProc(void *vrsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 433 | Context *rsc = static_cast<Context *>(vrsc); |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 434 | rsc->mNativeThreadId = gettid(); |
| 435 | |
| 436 | setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 437 | rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 438 | |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 439 | rsc->props.mLogTimes = getProp("debug.rs.profile"); |
| 440 | rsc->props.mLogScripts = getProp("debug.rs.script"); |
Jason Sams | 433eca3 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 441 | rsc->props.mLogObjects = getProp("debug.rs.object"); |
| 442 | rsc->props.mLogShaders = getProp("debug.rs.shader"); |
Alex Sakhartchouk | 886f11a | 2010-09-29 09:49:13 -0700 | [diff] [blame] | 443 | rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes"); |
| 444 | rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms"); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 445 | rsc->props.mLogVisual = getProp("debug.rs.visual"); |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 446 | |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 447 | rsc->mTlsStruct = new ScriptTLSStruct; |
| 448 | if (!rsc->mTlsStruct) { |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 449 | LOGE("Error allocating tls storage"); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 450 | rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed allocation for TLS"); |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 451 | return NULL; |
| 452 | } |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 453 | rsc->mTlsStruct->mContext = rsc; |
| 454 | rsc->mTlsStruct->mScript = NULL; |
| 455 | int status = pthread_setspecific(rsc->gThreadTLSKey, rsc->mTlsStruct); |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 456 | if (status) { |
| 457 | LOGE("pthread_setspecific %i", status); |
| 458 | } |
| 459 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 460 | if (!rsc->initGLThread()) { |
| 461 | rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL"); |
| 462 | return NULL; |
| 463 | } |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 464 | |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 465 | rsc->mScriptC.init(rsc); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 466 | if (rsc->mIsGraphicsContext) { |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 467 | rsc->mStateRaster.init(rsc); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 468 | rsc->setProgramRaster(NULL); |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 469 | rsc->mStateVertex.init(rsc); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 470 | rsc->setProgramVertex(NULL); |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 471 | rsc->mStateFragment.init(rsc); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 472 | rsc->setProgramFragment(NULL); |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 473 | rsc->mStateFragmentStore.init(rsc); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 474 | rsc->setProgramStore(NULL); |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 475 | rsc->mStateFont.init(rsc); |
| 476 | rsc->setFont(NULL); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 477 | rsc->mStateVertexArray.init(rsc); |
| 478 | } |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 479 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 480 | rsc->mRunning = true; |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 481 | bool mDraw = true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 482 | while (!rsc->mExit) { |
Jason Sams | fcd3192 | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 483 | mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw); |
Jason Sams | 732f1c0 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 484 | mDraw &= (rsc->mRootScript.get() != NULL); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 485 | mDraw &= (rsc->mWndSurface != NULL); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 486 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 487 | uint32_t targetTime = 0; |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 488 | if (mDraw && rsc->mIsGraphicsContext) { |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 489 | targetTime = rsc->runRootScript(); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 490 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 491 | if (rsc->props.mLogVisual) { |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 492 | rsc->displayDebugStats(); |
| 493 | } |
| 494 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 495 | mDraw = targetTime && !rsc->mPaused; |
| 496 | rsc->timerSet(RS_TIMER_CLEAR_SWAP); |
Jason Sams | afcb25c | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 497 | eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 498 | rsc->timerFrame(); |
| 499 | rsc->timerSet(RS_TIMER_INTERNAL); |
| 500 | rsc->timerPrint(); |
| 501 | rsc->timerReset(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 502 | } |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 503 | if (targetTime > 1) { |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 504 | int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000; |
| 505 | if (t > 0) { |
| 506 | usleep(t); |
| 507 | } |
| 508 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 511 | LOGV("%p, RS Thread exiting", rsc); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 512 | if (rsc->mIsGraphicsContext) { |
| 513 | rsc->mRaster.clear(); |
| 514 | rsc->mFragment.clear(); |
| 515 | rsc->mVertex.clear(); |
| 516 | rsc->mFragmentStore.clear(); |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 517 | rsc->mFont.clear(); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 518 | rsc->mRootScript.clear(); |
| 519 | rsc->mStateRaster.deinit(rsc); |
| 520 | rsc->mStateVertex.deinit(rsc); |
| 521 | rsc->mStateFragment.deinit(rsc); |
| 522 | rsc->mStateFragmentStore.deinit(rsc); |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 523 | rsc->mStateFont.deinit(rsc); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 524 | } |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 525 | ObjectBase::zeroAllUserRef(rsc); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 526 | |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 527 | if (rsc->mIsGraphicsContext) { |
| 528 | pthread_mutex_lock(&gInitMutex); |
| 529 | rsc->deinitEGL(); |
| 530 | pthread_mutex_unlock(&gInitMutex); |
| 531 | } |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 532 | delete rsc->mTlsStruct; |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 533 | |
Jason Sams | 4c5f99e | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 534 | LOGV("%p, RS Thread exited", rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 535 | return NULL; |
| 536 | } |
| 537 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 538 | void * Context::helperThreadProc(void *vrsc) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 539 | Context *rsc = static_cast<Context *>(vrsc); |
| 540 | uint32_t idx = (uint32_t)android_atomic_inc(&rsc->mWorkers.mLaunchCount); |
| 541 | |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 542 | LOGV("RS helperThread starting %p idx=%i", rsc, idx); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 543 | |
| 544 | rsc->mWorkers.mLaunchSignals[idx].init(); |
| 545 | rsc->mWorkers.mNativeThreadId[idx] = gettid(); |
| 546 | |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 547 | #if 0 |
| 548 | typedef struct {uint64_t bits[1024 / 64]; } cpu_set_t; |
| 549 | cpu_set_t cpuset; |
| 550 | memset(&cpuset, 0, sizeof(cpuset)); |
| 551 | cpuset.bits[idx / 64] |= 1ULL << (idx % 64); |
| 552 | int ret = syscall(241, rsc->mWorkers.mNativeThreadId[idx], |
Alex Sakhartchouk | 886f11a | 2010-09-29 09:49:13 -0700 | [diff] [blame] | 553 | sizeof(cpuset), &cpuset); |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 554 | LOGE("SETAFFINITY ret = %i %s", ret, EGLUtils::strerror(ret)); |
| 555 | #endif |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 556 | |
| 557 | setpriority(PRIO_PROCESS, rsc->mWorkers.mNativeThreadId[idx], rsc->mThreadPriority); |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 558 | int status = pthread_setspecific(rsc->gThreadTLSKey, rsc->mTlsStruct); |
| 559 | if (status) { |
| 560 | LOGE("pthread_setspecific %i", status); |
| 561 | } |
| 562 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 563 | while (rsc->mRunning) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 564 | rsc->mWorkers.mLaunchSignals[idx].wait(); |
| 565 | if (rsc->mWorkers.mLaunchCallback) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 566 | rsc->mWorkers.mLaunchCallback(rsc->mWorkers.mLaunchData, idx); |
| 567 | } |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 568 | android_atomic_dec(&rsc->mWorkers.mRunningCount); |
| 569 | rsc->mWorkers.mCompleteSignal.set(); |
| 570 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 571 | |
| 572 | LOGV("RS helperThread exiting %p idx=%i", rsc, idx); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 573 | return NULL; |
| 574 | } |
| 575 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 576 | void Context::launchThreads(WorkerCallback_t cbk, void *data) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 577 | mWorkers.mLaunchData = data; |
| 578 | mWorkers.mLaunchCallback = cbk; |
| 579 | mWorkers.mRunningCount = (int)mWorkers.mCount; |
| 580 | for (uint32_t ct = 0; ct < mWorkers.mCount; ct++) { |
| 581 | mWorkers.mLaunchSignals[ct].set(); |
| 582 | } |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 583 | while (mWorkers.mRunningCount) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 584 | mWorkers.mCompleteSignal.wait(); |
| 585 | } |
| 586 | } |
| 587 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 588 | void Context::setPriority(int32_t p) { |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 589 | // Note: If we put this in the proper "background" policy |
| 590 | // the wallpapers can become completly unresponsive at times. |
| 591 | // This is probably not what we want for something the user is actively |
| 592 | // looking at. |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 593 | mThreadPriority = p; |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 594 | #if 0 |
| 595 | SchedPolicy pol = SP_FOREGROUND; |
| 596 | if (p > 0) { |
| 597 | pol = SP_BACKGROUND; |
| 598 | } |
| 599 | if (!set_sched_policy(mNativeThreadId, pol)) { |
| 600 | // success; reset the priority as well |
| 601 | } |
| 602 | #else |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 603 | setpriority(PRIO_PROCESS, mNativeThreadId, p); |
| 604 | for (uint32_t ct=0; ct < mWorkers.mCount; ct++) { |
| 605 | setpriority(PRIO_PROCESS, mWorkers.mNativeThreadId[ct], p); |
| 606 | } |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 607 | #endif |
| 608 | } |
| 609 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 610 | Context::Context() { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 611 | mDev = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 612 | mRunning = false; |
| 613 | mExit = false; |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 614 | mPaused = false; |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 615 | mObjHead = NULL; |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 616 | mError = RS_ERROR_NONE; |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 619 | Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 620 | Context * rsc = new Context(); |
| 621 | if (!rsc->initContext(dev, sc)) { |
| 622 | delete rsc; |
| 623 | return NULL; |
| 624 | } |
| 625 | return rsc; |
| 626 | } |
| 627 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 628 | bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 629 | pthread_mutex_lock(&gInitMutex); |
| 630 | |
| 631 | dev->addContext(this); |
| 632 | mDev = dev; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 633 | if (sc) { |
| 634 | mUserSurfaceConfig = *sc; |
| 635 | } else { |
| 636 | memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig)); |
| 637 | } |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 638 | |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 639 | memset(&mEGL, 0, sizeof(mEGL)); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 640 | memset(&mGL, 0, sizeof(mGL)); |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 641 | mIsGraphicsContext = sc != NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 642 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 643 | int status; |
| 644 | pthread_attr_t threadAttr; |
| 645 | |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 646 | if (!gThreadTLSKeyCount) { |
Jason Sams | 9e4e13d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 647 | status = pthread_key_create(&gThreadTLSKey, NULL); |
| 648 | if (status) { |
| 649 | LOGE("Failed to init thread tls key."); |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 650 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 651 | return false; |
Jason Sams | 9e4e13d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 652 | } |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 653 | } |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 654 | gThreadTLSKeyCount++; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 655 | |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 656 | pthread_mutex_unlock(&gInitMutex); |
| 657 | |
| 658 | // Global init done at this point. |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 659 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 660 | status = pthread_attr_init(&threadAttr); |
| 661 | if (status) { |
| 662 | LOGE("Failed to init thread attribute."); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 663 | return false; |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 666 | mWndSurface = NULL; |
Jason Sams | 992a0b7 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 667 | |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 668 | timerInit(); |
Jason Sams | a891933 | 2009-09-24 15:42:52 -0700 | [diff] [blame] | 669 | timerSet(RS_TIMER_INTERNAL); |
Jason Sams | 5086938 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 670 | |
Jason Sams | 7c7c78a | 2010-07-26 17:12:55 -0700 | [diff] [blame] | 671 | int cpu = sysconf(_SC_NPROCESSORS_ONLN); |
| 672 | LOGV("RS Launching thread(s), reported CPU count %i", cpu); |
| 673 | if (cpu < 2) cpu = 0; |
| 674 | |
| 675 | mWorkers.mCount = (uint32_t)cpu; |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 676 | mWorkers.mThreadId = (pthread_t *) calloc(mWorkers.mCount, sizeof(pthread_t)); |
| 677 | mWorkers.mNativeThreadId = (pid_t *) calloc(mWorkers.mCount, sizeof(pid_t)); |
| 678 | mWorkers.mLaunchSignals = new Signal[mWorkers.mCount]; |
| 679 | mWorkers.mLaunchCallback = NULL; |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 680 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 681 | if (status) { |
| 682 | LOGE("Failed to start rs context thread."); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 683 | return false; |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 684 | } |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 685 | while (!mRunning && (mError == RS_ERROR_NONE)) { |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 686 | usleep(100); |
| 687 | } |
| 688 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 689 | if (mError != RS_ERROR_NONE) { |
| 690 | return false; |
| 691 | } |
| 692 | |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 693 | mWorkers.mCompleteSignal.init(); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 694 | mWorkers.mRunningCount = 0; |
| 695 | mWorkers.mLaunchCount = 0; |
| 696 | for (uint32_t ct=0; ct < mWorkers.mCount; ct++) { |
| 697 | status = pthread_create(&mWorkers.mThreadId[ct], &threadAttr, helperThreadProc, this); |
| 698 | if (status) { |
| 699 | mWorkers.mCount = ct; |
| 700 | LOGE("Created fewer than expected number of RS threads."); |
| 701 | break; |
| 702 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 703 | } |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 704 | pthread_attr_destroy(&threadAttr); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 705 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 708 | Context::~Context() { |
Jason Sams | 8c0ee65 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 709 | LOGV("Context::~Context"); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 710 | mExit = true; |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 711 | mPaused = false; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 712 | void *res; |
| 713 | |
Jason Sams | 8c0ee65 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 714 | mIO.shutdown(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 715 | int status = pthread_join(mThreadId, &res); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 716 | |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 717 | // Global structure cleanup. |
| 718 | pthread_mutex_lock(&gInitMutex); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 719 | if (mDev) { |
| 720 | mDev->removeContext(this); |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 721 | --gThreadTLSKeyCount; |
| 722 | if (!gThreadTLSKeyCount) { |
| 723 | pthread_key_delete(gThreadTLSKey); |
| 724 | } |
Jason Sams | bf3c14e | 2009-11-02 14:25:10 -0800 | [diff] [blame] | 725 | mDev = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 726 | } |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 727 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 730 | void Context::setSurface(uint32_t w, uint32_t h, ANativeWindow *sur) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 731 | rsAssert(mIsGraphicsContext); |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 732 | |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 733 | EGLBoolean ret; |
| 734 | if (mEGL.mSurface != NULL) { |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 735 | ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurfaceDefault, mEGL.mSurfaceDefault, mEGL.mContext); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 736 | checkEglError("eglMakeCurrent", ret); |
| 737 | |
| 738 | ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface); |
| 739 | checkEglError("eglDestroySurface", ret); |
| 740 | |
| 741 | mEGL.mSurface = NULL; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 742 | mWidth = 1; |
| 743 | mHeight = 1; |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | mWndSurface = sur; |
| 747 | if (mWndSurface != NULL) { |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 748 | mWidth = w; |
| 749 | mHeight = h; |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 750 | |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 751 | mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL); |
| 752 | checkEglError("eglCreateWindowSurface"); |
| 753 | if (mEGL.mSurface == EGL_NO_SURFACE) { |
| 754 | LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE"); |
| 755 | } |
| 756 | |
| 757 | ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext); |
| 758 | checkEglError("eglMakeCurrent", ret); |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 759 | |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 760 | mStateVertex.updateSize(this); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 764 | void Context::pause() { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 765 | rsAssert(mIsGraphicsContext); |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 766 | mPaused = true; |
| 767 | } |
| 768 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 769 | void Context::resume() { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 770 | rsAssert(mIsGraphicsContext); |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 771 | mPaused = false; |
| 772 | } |
| 773 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 774 | void Context::setRootScript(Script *s) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 775 | rsAssert(mIsGraphicsContext); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 776 | mRootScript.set(s); |
| 777 | } |
| 778 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 779 | void Context::setProgramStore(ProgramStore *pfs) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 780 | rsAssert(mIsGraphicsContext); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 781 | if (pfs == NULL) { |
| 782 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 783 | } else { |
| 784 | mFragmentStore.set(pfs); |
| 785 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 788 | void Context::setProgramFragment(ProgramFragment *pf) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 789 | rsAssert(mIsGraphicsContext); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 790 | if (pf == NULL) { |
| 791 | mFragment.set(mStateFragment.mDefault); |
| 792 | } else { |
| 793 | mFragment.set(pf); |
| 794 | } |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 797 | void Context::setProgramRaster(ProgramRaster *pr) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 798 | rsAssert(mIsGraphicsContext); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 799 | if (pr == NULL) { |
| 800 | mRaster.set(mStateRaster.mDefault); |
| 801 | } else { |
| 802 | mRaster.set(pr); |
| 803 | } |
| 804 | } |
| 805 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 806 | void Context::setProgramVertex(ProgramVertex *pv) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 807 | rsAssert(mIsGraphicsContext); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 808 | if (pv == NULL) { |
| 809 | mVertex.set(mStateVertex.mDefault); |
| 810 | } else { |
| 811 | mVertex.set(pv); |
| 812 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 815 | void Context::setFont(Font *f) { |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 816 | rsAssert(mIsGraphicsContext); |
| 817 | if (f == NULL) { |
| 818 | mFont.set(mStateFont.mDefault); |
| 819 | } else { |
| 820 | mFont.set(f); |
| 821 | } |
| 822 | } |
| 823 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 824 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 825 | rsAssert(!obj->getName()); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 826 | obj->setName(name, len); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 827 | mNames.add(obj); |
| 828 | } |
| 829 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 830 | void Context::removeName(ObjectBase *obj) { |
| 831 | for (size_t ct=0; ct < mNames.size(); ct++) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 832 | if (obj == mNames[ct]) { |
| 833 | mNames.removeAt(ct); |
| 834 | return; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 839 | RsMessageToClientType Context::peekMessageToClient(size_t *receiveLen, uint32_t *subID, bool wait) { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 840 | *receiveLen = 0; |
| 841 | if (!wait && mIO.mToClient.isEmpty()) { |
| 842 | return RS_MESSAGE_TO_CLIENT_NONE; |
| 843 | } |
| 844 | |
| 845 | uint32_t bytesData = 0; |
| 846 | uint32_t commandID = 0; |
| 847 | const uint32_t *d = (const uint32_t *)mIO.mToClient.get(&commandID, &bytesData); |
| 848 | *receiveLen = bytesData - sizeof(uint32_t); |
| 849 | if (bytesData) { |
| 850 | *subID = d[0]; |
| 851 | } |
| 852 | return (RsMessageToClientType)commandID; |
| 853 | } |
| 854 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 855 | RsMessageToClientType Context::getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen, bool wait) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 856 | //LOGE("getMessageToClient %i %i", bufferLen, wait); |
Jason Sams | 39cd317 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 857 | *receiveLen = 0; |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 858 | if (!wait && mIO.mToClient.isEmpty()) { |
| 859 | return RS_MESSAGE_TO_CLIENT_NONE; |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | //LOGE("getMessageToClient 2 con=%p", this); |
| 863 | uint32_t bytesData = 0; |
| 864 | uint32_t commandID = 0; |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 865 | const uint32_t *d = (const uint32_t *)mIO.mToClient.get(&commandID, &bytesData); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 866 | //LOGE("getMessageToClient 3 %i %i", commandID, bytesData); |
| 867 | |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 868 | *receiveLen = bytesData - sizeof(uint32_t); |
| 869 | *subID = d[0]; |
| 870 | |
| 871 | //LOGE("getMessageToClient %i %i", commandID, *subID); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 872 | if (bufferLen >= bytesData) { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 873 | memcpy(data, d+1, *receiveLen); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 874 | mIO.mToClient.next(); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 875 | return (RsMessageToClientType)commandID; |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 876 | } |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 877 | return RS_MESSAGE_TO_CLIENT_RESIZE; |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame^] | 880 | bool Context::sendMessageToClient(const void *data, RsMessageToClientType cmdID, |
| 881 | uint32_t subID, size_t len, bool waitForSpace) const { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 882 | //LOGE("sendMessageToClient %i %i %i %i", cmdID, subID, len, waitForSpace); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 883 | if (cmdID == 0) { |
| 884 | LOGE("Attempting to send invalid command 0 to client."); |
| 885 | return false; |
| 886 | } |
| 887 | if (!waitForSpace) { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 888 | if (!mIO.mToClient.makeSpaceNonBlocking(len + 12)) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 889 | // Not enough room, and not waiting. |
| 890 | return false; |
| 891 | } |
| 892 | } |
| 893 | //LOGE("sendMessageToClient 2"); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 894 | uint32_t *p = (uint32_t *)mIO.mToClient.reserve(len + sizeof(subID)); |
| 895 | p[0] = subID; |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 896 | if (len > 0) { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 897 | memcpy(p+1, data, len); |
Jason Sams | ef5867a | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 898 | } |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 899 | mIO.mToClient.commit(cmdID, len + sizeof(subID)); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 900 | //LOGE("sendMessageToClient 3"); |
| 901 | return true; |
| 902 | } |
| 903 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 904 | void Context::initToClient() { |
| 905 | while (!mRunning) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 906 | usleep(100); |
| 907 | } |
| 908 | } |
| 909 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 910 | void Context::deinitToClient() { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 911 | mIO.mToClient.shutdown(); |
| 912 | } |
Jason Sams | 5086938 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 913 | |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame^] | 914 | void Context::setError(RsError e, const char *msg) const { |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 915 | mError = e; |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 916 | sendMessageToClient(msg, RS_MESSAGE_TO_CLIENT_ERROR, e, strlen(msg) + 1, true); |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 920 | void Context::dumpDebug() const { |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 921 | LOGE("RS Context debug %p", this); |
| 922 | LOGE("RS Context debug"); |
| 923 | |
| 924 | LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 925 | LOGE(" EGL context %p surface %p, Display=%p", mEGL.mContext, mEGL.mSurface, mEGL.mDisplay); |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 926 | LOGE(" GL vendor: %s", mGL.mVendor); |
| 927 | LOGE(" GL renderer: %s", mGL.mRenderer); |
| 928 | LOGE(" GL Version: %s", mGL.mVersion); |
| 929 | LOGE(" GL Extensions: %s", mGL.mExtensions); |
| 930 | LOGE(" GL int Versions %i %i", mGL.mMajorVersion, mGL.mMinorVersion); |
| 931 | LOGE(" RS width %i, height %i", mWidth, mHeight); |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 932 | LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused); |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 933 | LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId); |
| 934 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 935 | LOGV("MAX Textures %i, %i %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits); |
| 936 | LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs); |
| 937 | LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors); |
| 938 | LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors); |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 939 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 940 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 941 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 942 | // |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 943 | |
| 944 | namespace android { |
| 945 | namespace renderscript { |
| 946 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 947 | void rsi_ContextFinish(Context *rsc) { |
Jason Sams | 8c88090 | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 948 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 949 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 950 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 951 | Script *s = static_cast<Script *>(vs); |
| 952 | rsc->setRootScript(s); |
| 953 | } |
| 954 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 955 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 956 | Sampler *s = static_cast<Sampler *>(vs); |
| 957 | |
| 958 | if (slot > RS_MAX_SAMPLER_SLOT) { |
| 959 | LOGE("Invalid sampler slot"); |
| 960 | return; |
| 961 | } |
| 962 | |
| 963 | s->bindToContext(&rsc->mStateSampler, slot); |
| 964 | } |
| 965 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 966 | void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) { |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 967 | ProgramStore *pfs = static_cast<ProgramStore *>(vpfs); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 968 | rsc->setProgramStore(pfs); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 971 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 972 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 973 | rsc->setProgramFragment(pf); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 976 | void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 977 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 978 | rsc->setProgramRaster(pr); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 981 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 982 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 983 | rsc->setProgramVertex(pv); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 986 | void rsi_ContextBindFont(Context *rsc, RsFont vfont) { |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 987 | Font *font = static_cast<Font *>(vfont); |
| 988 | rsc->setFont(font); |
| 989 | } |
| 990 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 991 | void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 992 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 993 | rsc->assignName(ob, name, len); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 994 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 995 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 996 | void rsi_ObjDestroy(Context *rsc, void *optr) { |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 997 | ObjectBase *ob = static_cast<ObjectBase *>(optr); |
Jason Sams | 707aaf3 | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 998 | rsc->removeName(ob); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 999 | ob->decUserRef(); |
Jason Sams | 707aaf3 | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1002 | void rsi_ContextPause(Context *rsc) { |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 1003 | rsc->pause(); |
| 1004 | } |
| 1005 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1006 | void rsi_ContextResume(Context *rsc) { |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 1007 | rsc->resume(); |
| 1008 | } |
| 1009 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1010 | void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, ANativeWindow *sur) { |
Mathias Agopian | fa40286 | 2010-02-12 14:04:35 -0800 | [diff] [blame] | 1011 | rsc->setSurface(w, h, sur); |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1014 | void rsi_ContextSetPriority(Context *rsc, int32_t p) { |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 1015 | rsc->setPriority(p); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1018 | void rsi_ContextDump(Context *rsc, int32_t bits) { |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 1019 | ObjectBase::dumpAll(rsc); |
| 1020 | } |
| 1021 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1026 | RsContext rsContextCreate(RsDevice vdev, uint32_t version) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1027 | LOGV("rsContextCreate %p", vdev); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1028 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 1029 | Context *rsc = Context::createContext(dev, NULL); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1030 | return rsc; |
| 1031 | } |
| 1032 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1033 | RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, RsSurfaceConfig sc) { |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 1034 | LOGV("rsContextCreateGL %p", vdev); |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 1035 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 1036 | Context *rsc = Context::createContext(dev, &sc); |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 1037 | LOGV("rsContextCreateGL ret %p ", rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1038 | return rsc; |
| 1039 | } |
| 1040 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1041 | void rsContextDestroy(RsContext vrsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1042 | Context * rsc = static_cast<Context *>(vrsc); |
| 1043 | delete rsc; |
| 1044 | } |
| 1045 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1046 | RsMessageToClientType rsContextPeekMessage(RsContext vrsc, size_t *receiveLen, uint32_t *subID, bool wait) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1047 | Context * rsc = static_cast<Context *>(vrsc); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1048 | return rsc->peekMessageToClient(receiveLen, subID, wait); |
| 1049 | } |
| 1050 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1051 | RsMessageToClientType rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen, bool wait) { |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 1052 | Context * rsc = static_cast<Context *>(vrsc); |
| 1053 | return rsc->getMessageToClient(data, receiveLen, subID, bufferLen, wait); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1056 | void rsContextInitToClient(RsContext vrsc) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1057 | Context * rsc = static_cast<Context *>(vrsc); |
| 1058 | rsc->initToClient(); |
| 1059 | } |
| 1060 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1061 | void rsContextDeinitToClient(RsContext vrsc) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1062 | Context * rsc = static_cast<Context *>(vrsc); |
| 1063 | rsc->deinitToClient(); |
| 1064 | } |
| 1065 | |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1066 | // Only to be called at a3d load time, before object is visible to user |
| 1067 | // not thread safe |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 1068 | void rsaGetName(RsContext con, void * obj, const char **name) { |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 1069 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 1070 | (*name) = ob->getName(); |
| 1071 | } |