Jason Sams | d19f10d | 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 | 3142f4f | 2009-06-22 18:01:09 -0700 | [diff] [blame] | 20 | #include <ui/FramebufferNativeWindow.h> |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 21 | #include <ui/EGLUtils.h> |
Mathias Agopian | 5cbb940 | 2010-02-12 12:00:38 -0800 | [diff] [blame] | 22 | #include <ui/egl/android_natives.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <sys/resource.h> |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 26 | #include <sched.h> |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 27 | |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 28 | #include <cutils/properties.h> |
| 29 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 30 | #include <GLES/gl.h> |
| 31 | #include <GLES/glext.h> |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 32 | #include <GLES2/gl2.h> |
| 33 | #include <GLES2/gl2ext.h> |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 34 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 35 | #include <cutils/sched_policy.h> |
| 36 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 37 | using namespace android; |
| 38 | using namespace android::renderscript; |
| 39 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 40 | pthread_key_t Context::gThreadTLSKey = 0; |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 41 | uint32_t Context::gThreadTLSKeyCount = 0; |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 42 | uint32_t Context::gGLContextCount = 0; |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 43 | pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 45 | static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) { |
| 46 | if (returnVal != EGL_TRUE) { |
| 47 | fprintf(stderr, "%s() returned %d\n", op, returnVal); |
| 48 | } |
| 49 | |
| 50 | for (EGLint error = eglGetError(); error != EGL_SUCCESS; error |
| 51 | = eglGetError()) { |
| 52 | fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error), |
| 53 | error); |
| 54 | } |
| 55 | } |
| 56 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 57 | void Context::initEGL(bool useGL2) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | { |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 59 | mEGL.mNumConfigs = -1; |
| 60 | EGLint configAttribs[128]; |
| 61 | EGLint *configAttribsPtr = configAttribs; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 62 | EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 64 | memset(configAttribs, 0, sizeof(configAttribs)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 65 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 66 | configAttribsPtr[0] = EGL_SURFACE_TYPE; |
| 67 | configAttribsPtr[1] = EGL_WINDOW_BIT; |
| 68 | configAttribsPtr += 2; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 70 | if (useGL2) { |
| 71 | configAttribsPtr[0] = EGL_RENDERABLE_TYPE; |
| 72 | configAttribsPtr[1] = EGL_OPENGL_ES2_BIT; |
| 73 | configAttribsPtr += 2; |
| 74 | } |
| 75 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 76 | if (mUseDepth) { |
| 77 | configAttribsPtr[0] = EGL_DEPTH_SIZE; |
| 78 | configAttribsPtr[1] = 16; |
| 79 | configAttribsPtr += 2; |
| 80 | } |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 81 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 82 | if (mDev->mForceSW) { |
| 83 | configAttribsPtr[0] = EGL_CONFIG_CAVEAT; |
| 84 | configAttribsPtr[1] = EGL_SLOW_CONFIG; |
| 85 | configAttribsPtr += 2; |
| 86 | } |
| 87 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 88 | configAttribsPtr[0] = EGL_NONE; |
| 89 | rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint)))); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
Jason Sams | 6a17e16 | 2009-10-08 12:55:06 -0700 | [diff] [blame] | 91 | LOGV("initEGL start"); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 92 | mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 93 | checkEglError("eglGetDisplay"); |
| 94 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 95 | eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion); |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 96 | checkEglError("eglInitialize"); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 97 | |
| 98 | status_t err = EGLUtils::selectConfigForNativeWindow(mEGL.mDisplay, configAttribs, mWndSurface, &mEGL.mConfig); |
| 99 | if (err) { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 100 | LOGE("couldn't find an EGLConfig matching the screen format\n"); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 101 | } |
| 102 | //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs); |
| 103 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 104 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 105 | if (useGL2) { |
| 106 | mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2); |
| 107 | } else { |
| 108 | mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL); |
| 109 | } |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 110 | checkEglError("eglCreateContext"); |
| 111 | if (mEGL.mContext == EGL_NO_CONTEXT) { |
| 112 | LOGE("eglCreateContext returned EGL_NO_CONTEXT"); |
| 113 | } |
| 114 | gGLContextCount++; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 117 | void Context::deinitEGL() |
| 118 | { |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 119 | LOGV("deinitEGL"); |
| 120 | setSurface(0, 0, NULL); |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 121 | eglDestroyContext(mEGL.mDisplay, mEGL.mContext); |
| 122 | checkEglError("eglDestroyContext"); |
| 123 | |
| 124 | gGLContextCount--; |
| 125 | if (!gGLContextCount) { |
| 126 | eglTerminate(mEGL.mDisplay); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 131 | uint32_t Context::runScript(Script *s) |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 132 | { |
| 133 | ObjectBaseRef<ProgramFragment> frag(mFragment); |
| 134 | ObjectBaseRef<ProgramVertex> vtx(mVertex); |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 135 | ObjectBaseRef<ProgramStore> store(mFragmentStore); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 136 | ObjectBaseRef<ProgramRaster> raster(mRaster); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 137 | ObjectBaseRef<Font> font(mFont); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 138 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 139 | uint32_t ret = s->run(this); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 140 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 141 | mFragment.set(frag); |
| 142 | mVertex.set(vtx); |
| 143 | mFragmentStore.set(store); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 144 | mRaster.set(raster); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 145 | mFont.set(font); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 146 | return ret; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 149 | void Context::checkError(const char *msg) const |
| 150 | { |
| 151 | GLenum err = glGetError(); |
| 152 | if (err != GL_NO_ERROR) { |
| 153 | LOGE("GL Error, 0x%x, from %s", err, msg); |
| 154 | } |
| 155 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 156 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 157 | uint32_t Context::runRootScript() |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 158 | { |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 159 | glViewport(0, 0, mWidth, mHeight); |
Jason Sams | 67c6844 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 160 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 161 | timerSet(RS_TIMER_SCRIPT); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 162 | mStateFragmentStore.mLast.clear(); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 163 | uint32_t ret = runScript(mRootScript.get()); |
Jason Sams | c7412b3 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 164 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 165 | checkError("runRootScript"); |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 166 | if (mError != RS_ERROR_NONE) { |
| 167 | // If we have an error condition we stop rendering until |
| 168 | // somthing changes that might fix it. |
| 169 | ret = 0; |
| 170 | } |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 171 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 174 | uint64_t Context::getTime() const |
| 175 | { |
| 176 | struct timespec t; |
| 177 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 178 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); |
| 179 | } |
| 180 | |
| 181 | void Context::timerReset() |
| 182 | { |
| 183 | for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { |
| 184 | mTimers[ct] = 0; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void Context::timerInit() |
| 189 | { |
| 190 | mTimeLast = getTime(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 191 | mTimeFrame = mTimeLast; |
| 192 | mTimeLastFrame = mTimeLast; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 193 | mTimerActive = RS_TIMER_INTERNAL; |
| 194 | timerReset(); |
| 195 | } |
| 196 | |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 197 | void Context::timerFrame() |
| 198 | { |
| 199 | mTimeLastFrame = mTimeFrame; |
| 200 | mTimeFrame = getTime(); |
| 201 | } |
| 202 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 203 | void Context::timerSet(Timers tm) |
| 204 | { |
| 205 | uint64_t last = mTimeLast; |
| 206 | mTimeLast = getTime(); |
| 207 | mTimers[mTimerActive] += mTimeLast - last; |
| 208 | mTimerActive = tm; |
| 209 | } |
| 210 | |
| 211 | void Context::timerPrint() |
| 212 | { |
| 213 | double total = 0; |
| 214 | for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { |
| 215 | total += mTimers[ct]; |
| 216 | } |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 217 | uint64_t frame = mTimeFrame - mTimeLastFrame; |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 218 | mTimeMSLastFrame = frame / 1000000; |
| 219 | mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; |
| 220 | mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 221 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 222 | |
| 223 | if (props.mLogTimes) { |
| 224 | LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)", |
| 225 | mTimeMSLastFrame, |
| 226 | 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, |
| 227 | 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, |
| 228 | 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, |
| 229 | 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000); |
| 230 | } |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 233 | bool Context::setupCheck() |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 234 | { |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 235 | if (checkVersion2_0()) { |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 236 | if (!mShaderCache.lookup(this, mVertex.get(), mFragment.get())) { |
| 237 | LOGE("Context::setupCheck() 1 fail"); |
| 238 | return false; |
| 239 | } |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 240 | |
| 241 | mFragmentStore->setupGL2(this, &mStateFragmentStore); |
| 242 | mFragment->setupGL2(this, &mStateFragment, &mShaderCache); |
| 243 | mRaster->setupGL2(this, &mStateRaster); |
| 244 | mVertex->setupGL2(this, &mStateVertex, &mShaderCache); |
| 245 | |
| 246 | } else { |
| 247 | mFragmentStore->setupGL(this, &mStateFragmentStore); |
| 248 | mFragment->setupGL(this, &mStateFragment); |
| 249 | mRaster->setupGL(this, &mStateRaster); |
| 250 | mVertex->setupGL(this, &mStateVertex); |
| 251 | } |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 252 | return true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 255 | static bool getProp(const char *str) |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 256 | { |
| 257 | char buf[PROPERTY_VALUE_MAX]; |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 258 | property_get(str, buf, "0"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 259 | return 0 != strcmp(buf, "0"); |
| 260 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 261 | |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 262 | void Context::displayDebugStats() |
| 263 | { |
| 264 | char buffer[128]; |
| 265 | sprintf(buffer, "Frame %i ms, Script %i ms", mTimeMSLastFrame, mTimeMSLastScript); |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 266 | float oldR, oldG, oldB, oldA; |
| 267 | mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 268 | |
| 269 | float shadowCol = 0.2f; |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 270 | mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 271 | mStateFont.renderText(buffer, 5, getHeight() - 5); |
| 272 | |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 273 | float textCol = 0.9f; |
| 274 | mStateFont.setFontColor(textCol, textCol, textCol, 1.0f); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 275 | mStateFont.renderText(buffer, 4, getHeight() - 6); |
| 276 | |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 277 | mStateFont.setFontColor(oldR, oldG, oldB, oldA); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 280 | void * Context::threadProc(void *vrsc) |
| 281 | { |
| 282 | Context *rsc = static_cast<Context *>(vrsc); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 283 | rsc->mNativeThreadId = gettid(); |
| 284 | |
| 285 | setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 286 | rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 287 | |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 288 | rsc->props.mLogTimes = getProp("debug.rs.profile"); |
| 289 | rsc->props.mLogScripts = getProp("debug.rs.script"); |
Jason Sams | a09a6e1 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 290 | rsc->props.mLogObjects = getProp("debug.rs.object"); |
| 291 | rsc->props.mLogShaders = getProp("debug.rs.shader"); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 292 | rsc->props.mLogVisual = getProp("debug.rs.visual"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 293 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 294 | ScriptTLSStruct *tlsStruct = new ScriptTLSStruct; |
| 295 | if (!tlsStruct) { |
| 296 | LOGE("Error allocating tls storage"); |
| 297 | return NULL; |
| 298 | } |
| 299 | tlsStruct->mContext = rsc; |
| 300 | tlsStruct->mScript = NULL; |
| 301 | int status = pthread_setspecific(rsc->gThreadTLSKey, tlsStruct); |
| 302 | if (status) { |
| 303 | LOGE("pthread_setspecific %i", status); |
| 304 | } |
| 305 | |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 306 | if (rsc->mIsGraphicsContext) { |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 307 | rsc->mStateRaster.init(rsc); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 308 | rsc->setRaster(NULL); |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 309 | rsc->mStateVertex.init(rsc); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 310 | rsc->setVertex(NULL); |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 311 | rsc->mStateFragment.init(rsc); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 312 | rsc->setFragment(NULL); |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 313 | rsc->mStateFragmentStore.init(rsc); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 314 | rsc->setFragmentStore(NULL); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 315 | rsc->mStateFont.init(rsc); |
| 316 | rsc->setFont(NULL); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 317 | rsc->mStateVertexArray.init(rsc); |
| 318 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 319 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 320 | rsc->mRunning = true; |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 321 | bool mDraw = true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 322 | while (!rsc->mExit) { |
Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 323 | mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw); |
Jason Sams | 5f7fc27 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 324 | mDraw &= (rsc->mRootScript.get() != NULL); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 325 | mDraw &= (rsc->mWndSurface != NULL); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 326 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 327 | uint32_t targetTime = 0; |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 328 | if (mDraw && rsc->mIsGraphicsContext) { |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 329 | targetTime = rsc->runRootScript(); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 330 | |
| 331 | if(rsc->props.mLogVisual) { |
| 332 | rsc->displayDebugStats(); |
| 333 | } |
| 334 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 335 | mDraw = targetTime && !rsc->mPaused; |
| 336 | rsc->timerSet(RS_TIMER_CLEAR_SWAP); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 337 | eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 338 | rsc->timerFrame(); |
| 339 | rsc->timerSet(RS_TIMER_INTERNAL); |
| 340 | rsc->timerPrint(); |
| 341 | rsc->timerReset(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 342 | } |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 343 | if (rsc->mThreadPriority > 0 && targetTime) { |
| 344 | int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000; |
| 345 | if (t > 0) { |
| 346 | usleep(t); |
| 347 | } |
| 348 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 351 | LOGV("RS Thread exiting"); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 352 | if (rsc->mIsGraphicsContext) { |
| 353 | rsc->mRaster.clear(); |
| 354 | rsc->mFragment.clear(); |
| 355 | rsc->mVertex.clear(); |
| 356 | rsc->mFragmentStore.clear(); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 357 | rsc->mFont.clear(); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 358 | rsc->mRootScript.clear(); |
| 359 | rsc->mStateRaster.deinit(rsc); |
| 360 | rsc->mStateVertex.deinit(rsc); |
| 361 | rsc->mStateFragment.deinit(rsc); |
| 362 | rsc->mStateFragmentStore.deinit(rsc); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 363 | rsc->mStateFont.deinit(rsc); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 364 | } |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 365 | ObjectBase::zeroAllUserRef(rsc); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 366 | |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 367 | if (rsc->mIsGraphicsContext) { |
| 368 | pthread_mutex_lock(&gInitMutex); |
| 369 | rsc->deinitEGL(); |
| 370 | pthread_mutex_unlock(&gInitMutex); |
| 371 | } |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 372 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 373 | LOGV("RS Thread exited"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 374 | return NULL; |
| 375 | } |
| 376 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 377 | void * Context::helperThreadProc(void *vrsc) |
| 378 | { |
| 379 | Context *rsc = static_cast<Context *>(vrsc); |
| 380 | uint32_t idx = (uint32_t)android_atomic_inc(&rsc->mWorkers.mLaunchCount); |
| 381 | |
Jason Sams | c7f4e41 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 382 | LOGV("RS helperThread starting %p idx=%i", rsc, idx); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 383 | |
| 384 | rsc->mWorkers.mLaunchSignals[idx].init(); |
| 385 | rsc->mWorkers.mNativeThreadId[idx] = gettid(); |
| 386 | |
| 387 | //cpu_set_t cpset[16]; |
| 388 | //int ret = sched_getaffinity(rsc->mWorkers.mNativeThreadId[idx], sizeof(cpset), &cpset); |
| 389 | //LOGE("ret = %i", ret); |
| 390 | |
| 391 | //sched_setaffinity |
| 392 | |
| 393 | setpriority(PRIO_PROCESS, rsc->mWorkers.mNativeThreadId[idx], rsc->mThreadPriority); |
| 394 | while(rsc->mRunning) { |
| 395 | rsc->mWorkers.mLaunchSignals[idx].wait(); |
| 396 | if (rsc->mWorkers.mLaunchCallback) { |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 397 | rsc->mWorkers.mLaunchCallback(rsc->mWorkers.mLaunchData, idx); |
| 398 | } |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 399 | android_atomic_dec(&rsc->mWorkers.mRunningCount); |
| 400 | rsc->mWorkers.mCompleteSignal.set(); |
| 401 | } |
Jason Sams | c7f4e41 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 402 | |
| 403 | LOGV("RS helperThread exiting %p idx=%i", rsc, idx); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 404 | return NULL; |
| 405 | } |
| 406 | |
| 407 | void Context::launchThreads(WorkerCallback_t cbk, void *data) |
| 408 | { |
| 409 | mWorkers.mLaunchData = data; |
| 410 | mWorkers.mLaunchCallback = cbk; |
| 411 | mWorkers.mRunningCount = (int)mWorkers.mCount; |
| 412 | for (uint32_t ct = 0; ct < mWorkers.mCount; ct++) { |
| 413 | mWorkers.mLaunchSignals[ct].set(); |
| 414 | } |
| 415 | while(mWorkers.mRunningCount) { |
| 416 | mWorkers.mCompleteSignal.wait(); |
| 417 | } |
| 418 | } |
| 419 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 420 | void Context::setPriority(int32_t p) |
| 421 | { |
| 422 | // Note: If we put this in the proper "background" policy |
| 423 | // the wallpapers can become completly unresponsive at times. |
| 424 | // This is probably not what we want for something the user is actively |
| 425 | // looking at. |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 426 | mThreadPriority = p; |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 427 | #if 0 |
| 428 | SchedPolicy pol = SP_FOREGROUND; |
| 429 | if (p > 0) { |
| 430 | pol = SP_BACKGROUND; |
| 431 | } |
| 432 | if (!set_sched_policy(mNativeThreadId, pol)) { |
| 433 | // success; reset the priority as well |
| 434 | } |
| 435 | #else |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 436 | setpriority(PRIO_PROCESS, mNativeThreadId, p); |
| 437 | for (uint32_t ct=0; ct < mWorkers.mCount; ct++) { |
| 438 | setpriority(PRIO_PROCESS, mWorkers.mNativeThreadId[ct], p); |
| 439 | } |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 440 | #endif |
| 441 | } |
| 442 | |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 443 | Context::Context(Device *dev, bool isGraphics, bool useDepth) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 444 | { |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 445 | pthread_mutex_lock(&gInitMutex); |
| 446 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 447 | dev->addContext(this); |
| 448 | mDev = dev; |
| 449 | mRunning = false; |
| 450 | mExit = false; |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 451 | mUseDepth = useDepth; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 452 | mPaused = false; |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 453 | mObjHead = NULL; |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 454 | mError = RS_ERROR_NONE; |
| 455 | mErrorMsg = NULL; |
| 456 | |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 457 | memset(&mEGL, 0, sizeof(mEGL)); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 458 | memset(&mGL, 0, sizeof(mGL)); |
| 459 | mIsGraphicsContext = isGraphics; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 460 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 461 | int status; |
| 462 | pthread_attr_t threadAttr; |
| 463 | |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 464 | if (!gThreadTLSKeyCount) { |
Jason Sams | 996db8d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 465 | status = pthread_key_create(&gThreadTLSKey, NULL); |
| 466 | if (status) { |
| 467 | LOGE("Failed to init thread tls key."); |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 468 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 996db8d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 469 | return; |
| 470 | } |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 471 | } |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 472 | gThreadTLSKeyCount++; |
| 473 | pthread_mutex_unlock(&gInitMutex); |
| 474 | |
| 475 | // Global init done at this point. |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 476 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 477 | status = pthread_attr_init(&threadAttr); |
| 478 | if (status) { |
| 479 | LOGE("Failed to init thread attribute."); |
| 480 | return; |
| 481 | } |
| 482 | |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 483 | mWndSurface = NULL; |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 484 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 485 | timerInit(); |
Jason Sams | d3f2eaf | 2009-09-24 15:42:52 -0700 | [diff] [blame] | 486 | timerSet(RS_TIMER_INTERNAL); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 487 | |
Jason Sams | 7f4d0c9 | 2010-07-26 17:12:55 -0700 | [diff] [blame] | 488 | int cpu = sysconf(_SC_NPROCESSORS_ONLN); |
| 489 | LOGV("RS Launching thread(s), reported CPU count %i", cpu); |
| 490 | if (cpu < 2) cpu = 0; |
| 491 | |
| 492 | mWorkers.mCount = (uint32_t)cpu; |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 493 | mWorkers.mThreadId = (pthread_t *) calloc(mWorkers.mCount, sizeof(pthread_t)); |
| 494 | mWorkers.mNativeThreadId = (pid_t *) calloc(mWorkers.mCount, sizeof(pid_t)); |
| 495 | mWorkers.mLaunchSignals = new Signal[mWorkers.mCount]; |
| 496 | mWorkers.mLaunchCallback = NULL; |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 497 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 498 | if (status) { |
| 499 | LOGE("Failed to start rs context thread."); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 500 | return; |
| 501 | } |
Jason Sams | c7f4e41 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 502 | while(!mRunning) { |
| 503 | usleep(100); |
| 504 | } |
| 505 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 506 | mWorkers.mRunningCount = 0; |
| 507 | mWorkers.mLaunchCount = 0; |
| 508 | for (uint32_t ct=0; ct < mWorkers.mCount; ct++) { |
| 509 | status = pthread_create(&mWorkers.mThreadId[ct], &threadAttr, helperThreadProc, this); |
| 510 | if (status) { |
| 511 | mWorkers.mCount = ct; |
| 512 | LOGE("Created fewer than expected number of RS threads."); |
| 513 | break; |
| 514 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 517 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 518 | pthread_attr_destroy(&threadAttr); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | Context::~Context() |
| 522 | { |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 523 | LOGV("Context::~Context"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 524 | mExit = true; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 525 | mPaused = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 526 | void *res; |
| 527 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 528 | mIO.shutdown(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 529 | int status = pthread_join(mThreadId, &res); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 530 | |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 531 | // Global structure cleanup. |
| 532 | pthread_mutex_lock(&gInitMutex); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 533 | if (mDev) { |
| 534 | mDev->removeContext(this); |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 535 | --gThreadTLSKeyCount; |
| 536 | if (!gThreadTLSKeyCount) { |
| 537 | pthread_key_delete(gThreadTLSKey); |
| 538 | } |
Jason Sams | b7a6c43 | 2009-11-02 14:25:10 -0800 | [diff] [blame] | 539 | mDev = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 540 | } |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 541 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 544 | void Context::setSurface(uint32_t w, uint32_t h, ANativeWindow *sur) |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 545 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 546 | rsAssert(mIsGraphicsContext); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 547 | |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 548 | EGLBoolean ret; |
| 549 | if (mEGL.mSurface != NULL) { |
| 550 | ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 551 | checkEglError("eglMakeCurrent", ret); |
| 552 | |
| 553 | ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface); |
| 554 | checkEglError("eglDestroySurface", ret); |
| 555 | |
| 556 | mEGL.mSurface = NULL; |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 557 | mWidth = 0; |
| 558 | mHeight = 0; |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | mWndSurface = sur; |
| 562 | if (mWndSurface != NULL) { |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 563 | mWidth = w; |
| 564 | mHeight = h; |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 565 | bool first = false; |
| 566 | if (!mEGL.mContext) { |
| 567 | first = true; |
| 568 | pthread_mutex_lock(&gInitMutex); |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 569 | initEGL(true); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 570 | pthread_mutex_unlock(&gInitMutex); |
| 571 | } |
| 572 | |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 573 | mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL); |
| 574 | checkEglError("eglCreateWindowSurface"); |
| 575 | if (mEGL.mSurface == EGL_NO_SURFACE) { |
| 576 | LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE"); |
| 577 | } |
| 578 | |
| 579 | ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext); |
| 580 | checkEglError("eglMakeCurrent", ret); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 581 | |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 582 | mStateVertex.updateSize(this); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 583 | |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 584 | if (first) { |
| 585 | mGL.mVersion = glGetString(GL_VERSION); |
| 586 | mGL.mVendor = glGetString(GL_VENDOR); |
| 587 | mGL.mRenderer = glGetString(GL_RENDERER); |
| 588 | mGL.mExtensions = glGetString(GL_EXTENSIONS); |
| 589 | |
| 590 | //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion); |
| 591 | LOGV("GL Version %s", mGL.mVersion); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 592 | //LOGV("GL Vendor %s", mGL.mVendor); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 593 | LOGV("GL Renderer %s", mGL.mRenderer); |
| 594 | //LOGV("GL Extensions %s", mGL.mExtensions); |
| 595 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 596 | const char *verptr = NULL; |
| 597 | if (strlen((const char *)mGL.mVersion) > 9) { |
| 598 | if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) { |
| 599 | verptr = (const char *)mGL.mVersion + 12; |
| 600 | } |
| 601 | if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) { |
| 602 | verptr = (const char *)mGL.mVersion + 9; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | if (!verptr) { |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 607 | LOGE("Error, OpenGL ES Lite not supported"); |
| 608 | } else { |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 609 | sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 610 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 611 | |
| 612 | glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs); |
| 613 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors); |
| 614 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits); |
| 615 | |
| 616 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors); |
| 617 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits); |
| 618 | |
| 619 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits); |
| 620 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors); |
Jason Sams | 2978bfc | 2010-02-22 15:37:51 -0800 | [diff] [blame] | 621 | |
| 622 | mGL.OES_texture_npot = NULL != strstr((const char *)mGL.mExtensions, "GL_OES_texture_npot"); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 623 | } |
| 624 | |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 628 | void Context::pause() |
| 629 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 630 | rsAssert(mIsGraphicsContext); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 631 | mPaused = true; |
| 632 | } |
| 633 | |
| 634 | void Context::resume() |
| 635 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 636 | rsAssert(mIsGraphicsContext); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 637 | mPaused = false; |
| 638 | } |
| 639 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 640 | void Context::setRootScript(Script *s) |
| 641 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 642 | rsAssert(mIsGraphicsContext); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 643 | mRootScript.set(s); |
| 644 | } |
| 645 | |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 646 | void Context::setFragmentStore(ProgramStore *pfs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 647 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 648 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 649 | if (pfs == NULL) { |
| 650 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 651 | } else { |
| 652 | mFragmentStore.set(pfs); |
| 653 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void Context::setFragment(ProgramFragment *pf) |
| 657 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 658 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 659 | if (pf == NULL) { |
| 660 | mFragment.set(mStateFragment.mDefault); |
| 661 | } else { |
| 662 | mFragment.set(pf); |
| 663 | } |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 666 | void Context::setRaster(ProgramRaster *pr) |
| 667 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 668 | rsAssert(mIsGraphicsContext); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 669 | if (pr == NULL) { |
| 670 | mRaster.set(mStateRaster.mDefault); |
| 671 | } else { |
| 672 | mRaster.set(pr); |
| 673 | } |
| 674 | } |
| 675 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 676 | void Context::setVertex(ProgramVertex *pv) |
| 677 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 678 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 679 | if (pv == NULL) { |
| 680 | mVertex.set(mStateVertex.mDefault); |
| 681 | } else { |
| 682 | mVertex.set(pv); |
| 683 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 686 | void Context::setFont(Font *f) |
| 687 | { |
| 688 | rsAssert(mIsGraphicsContext); |
| 689 | if (f == NULL) { |
| 690 | mFont.set(mStateFont.mDefault); |
| 691 | } else { |
| 692 | mFont.set(f); |
| 693 | } |
| 694 | } |
| 695 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 696 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 697 | { |
| 698 | rsAssert(!obj->getName()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 699 | obj->setName(name, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 700 | mNames.add(obj); |
| 701 | } |
| 702 | |
| 703 | void Context::removeName(ObjectBase *obj) |
| 704 | { |
| 705 | for(size_t ct=0; ct < mNames.size(); ct++) { |
| 706 | if (obj == mNames[ct]) { |
| 707 | mNames.removeAt(ct); |
| 708 | return; |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 713 | uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait) |
| 714 | { |
| 715 | //LOGE("getMessageToClient %i %i", bufferLen, wait); |
Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 716 | *receiveLen = 0; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 717 | if (!wait) { |
| 718 | if (mIO.mToClient.isEmpty()) { |
| 719 | // No message to get and not going to wait for one. |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | //LOGE("getMessageToClient 2 con=%p", this); |
| 725 | uint32_t bytesData = 0; |
| 726 | uint32_t commandID = 0; |
| 727 | const void *d = mIO.mToClient.get(&commandID, &bytesData); |
| 728 | //LOGE("getMessageToClient 3 %i %i", commandID, bytesData); |
| 729 | |
| 730 | *receiveLen = bytesData; |
| 731 | if (bufferLen >= bytesData) { |
| 732 | memcpy(data, d, bytesData); |
| 733 | mIO.mToClient.next(); |
| 734 | return commandID; |
| 735 | } |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | bool Context::sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace) |
| 740 | { |
| 741 | //LOGE("sendMessageToClient %i %i %i", cmdID, len, waitForSpace); |
| 742 | if (cmdID == 0) { |
| 743 | LOGE("Attempting to send invalid command 0 to client."); |
| 744 | return false; |
| 745 | } |
| 746 | if (!waitForSpace) { |
Jason Sams | d0cb106 | 2010-08-18 12:38:03 -0700 | [diff] [blame] | 747 | if (!mIO.mToClient.makeSpaceNonBlocking(len + 8)) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 748 | // Not enough room, and not waiting. |
| 749 | return false; |
| 750 | } |
| 751 | } |
| 752 | //LOGE("sendMessageToClient 2"); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 753 | if (len > 0) { |
| 754 | void *p = mIO.mToClient.reserve(len); |
| 755 | memcpy(p, data, len); |
| 756 | mIO.mToClient.commit(cmdID, len); |
| 757 | } else { |
| 758 | mIO.mToClient.commit(cmdID, 0); |
| 759 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 760 | //LOGE("sendMessageToClient 3"); |
| 761 | return true; |
| 762 | } |
| 763 | |
| 764 | void Context::initToClient() |
| 765 | { |
| 766 | while(!mRunning) { |
| 767 | usleep(100); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void Context::deinitToClient() |
| 772 | { |
| 773 | mIO.mToClient.shutdown(); |
| 774 | } |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 775 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 776 | const char * Context::getError(RsError *err) |
| 777 | { |
| 778 | *err = mError; |
| 779 | mError = RS_ERROR_NONE; |
| 780 | if (*err != RS_ERROR_NONE) { |
| 781 | return mErrorMsg; |
| 782 | } |
| 783 | return NULL; |
| 784 | } |
| 785 | |
| 786 | void Context::setError(RsError e, const char *msg) |
| 787 | { |
| 788 | mError = e; |
| 789 | mErrorMsg = msg; |
| 790 | } |
| 791 | |
| 792 | |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 793 | void Context::dumpDebug() const |
| 794 | { |
| 795 | LOGE("RS Context debug %p", this); |
| 796 | LOGE("RS Context debug"); |
| 797 | |
| 798 | LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 799 | LOGE(" EGL context %p surface %p, Display=%p", mEGL.mContext, mEGL.mSurface, mEGL.mDisplay); |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 800 | LOGE(" GL vendor: %s", mGL.mVendor); |
| 801 | LOGE(" GL renderer: %s", mGL.mRenderer); |
| 802 | LOGE(" GL Version: %s", mGL.mVersion); |
| 803 | LOGE(" GL Extensions: %s", mGL.mExtensions); |
| 804 | LOGE(" GL int Versions %i %i", mGL.mMajorVersion, mGL.mMinorVersion); |
| 805 | LOGE(" RS width %i, height %i", mWidth, mHeight); |
| 806 | LOGE(" RS running %i, exit %i, useDepth %i, paused %i", mRunning, mExit, mUseDepth, mPaused); |
| 807 | LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId); |
| 808 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 809 | LOGV("MAX Textures %i, %i %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits); |
| 810 | LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs); |
| 811 | LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors); |
| 812 | LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors); |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 813 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 814 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 815 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 816 | // |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 817 | |
| 818 | namespace android { |
| 819 | namespace renderscript { |
| 820 | |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 821 | void rsi_ContextFinish(Context *rsc) |
| 822 | { |
| 823 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 824 | |
| 825 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) |
| 826 | { |
| 827 | Script *s = static_cast<Script *>(vs); |
| 828 | rsc->setRootScript(s); |
| 829 | } |
| 830 | |
| 831 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) |
| 832 | { |
| 833 | Sampler *s = static_cast<Sampler *>(vs); |
| 834 | |
| 835 | if (slot > RS_MAX_SAMPLER_SLOT) { |
| 836 | LOGE("Invalid sampler slot"); |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | s->bindToContext(&rsc->mStateSampler, slot); |
| 841 | } |
| 842 | |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 843 | void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 844 | { |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 845 | ProgramStore *pfs = static_cast<ProgramStore *>(vpfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 846 | rsc->setFragmentStore(pfs); |
| 847 | } |
| 848 | |
| 849 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) |
| 850 | { |
| 851 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
| 852 | rsc->setFragment(pf); |
| 853 | } |
| 854 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 855 | void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) |
| 856 | { |
| 857 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 858 | rsc->setRaster(pr); |
| 859 | } |
| 860 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 861 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) |
| 862 | { |
| 863 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
| 864 | rsc->setVertex(pv); |
| 865 | } |
| 866 | |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 867 | void rsi_ContextBindFont(Context *rsc, RsFont vfont) |
| 868 | { |
| 869 | Font *font = static_cast<Font *>(vfont); |
| 870 | rsc->setFont(font); |
| 871 | } |
| 872 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 873 | void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len) |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 874 | { |
| 875 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 876 | rsc->assignName(ob, name, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 877 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 878 | |
Alex Sakhartchouk | fb10c16 | 2010-08-04 14:45:48 -0700 | [diff] [blame] | 879 | void rsi_GetName(Context *rsc, void * obj, const char **name) |
| 880 | { |
| 881 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 882 | (*name) = ob->getName(); |
| 883 | } |
| 884 | |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 885 | void rsi_ObjDestroy(Context *rsc, void *obj) |
| 886 | { |
| 887 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 888 | rsc->removeName(ob); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 889 | ob->decUserRef(); |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 892 | void rsi_ContextPause(Context *rsc) |
| 893 | { |
| 894 | rsc->pause(); |
| 895 | } |
| 896 | |
| 897 | void rsi_ContextResume(Context *rsc) |
| 898 | { |
| 899 | rsc->resume(); |
| 900 | } |
| 901 | |
Dianne Hackborn | 8b49bd1 | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 902 | void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, ANativeWindow *sur) |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 903 | { |
Mathias Agopian | 128ce4b | 2010-02-12 14:04:35 -0800 | [diff] [blame] | 904 | rsc->setSurface(w, h, sur); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 905 | } |
| 906 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 907 | void rsi_ContextSetPriority(Context *rsc, int32_t p) |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 908 | { |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 909 | rsc->setPriority(p); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 910 | } |
| 911 | |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 912 | void rsi_ContextDump(Context *rsc, int32_t bits) |
| 913 | { |
| 914 | ObjectBase::dumpAll(rsc); |
| 915 | } |
| 916 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 917 | const char * rsi_ContextGetError(Context *rsc, RsError *e) |
| 918 | { |
| 919 | const char *msg = rsc->getError(e); |
| 920 | if (*e != RS_ERROR_NONE) { |
| 921 | LOGE("RS Error %i %s", *e, msg); |
| 922 | } |
| 923 | return msg; |
| 924 | } |
| 925 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | |
| 929 | |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 930 | RsContext rsContextCreate(RsDevice vdev, uint32_t version) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 931 | { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 932 | LOGV("rsContextCreate %p", vdev); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 933 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 934 | Context *rsc = new Context(dev, false, false); |
| 935 | return rsc; |
| 936 | } |
| 937 | |
| 938 | RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, bool useDepth) |
| 939 | { |
| 940 | LOGV("rsContextCreateGL %p, %i", vdev, useDepth); |
| 941 | Device * dev = static_cast<Device *>(vdev); |
| 942 | Context *rsc = new Context(dev, true, useDepth); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 943 | return rsc; |
| 944 | } |
| 945 | |
| 946 | void rsContextDestroy(RsContext vrsc) |
| 947 | { |
| 948 | Context * rsc = static_cast<Context *>(vrsc); |
| 949 | delete rsc; |
| 950 | } |
| 951 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 952 | uint32_t rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, size_t bufferLen, bool wait) |
| 953 | { |
| 954 | Context * rsc = static_cast<Context *>(vrsc); |
| 955 | return rsc->getMessageToClient(data, receiveLen, bufferLen, wait); |
| 956 | } |
| 957 | |
| 958 | void rsContextInitToClient(RsContext vrsc) |
| 959 | { |
| 960 | Context * rsc = static_cast<Context *>(vrsc); |
| 961 | rsc->initToClient(); |
| 962 | } |
| 963 | |
| 964 | void rsContextDeinitToClient(RsContext vrsc) |
| 965 | { |
| 966 | Context * rsc = static_cast<Context *>(vrsc); |
| 967 | rsc->deinitToClient(); |
| 968 | } |
| 969 | |