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> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> |
| 24 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
| 27 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | using namespace android; |
| 29 | using namespace android::renderscript; |
| 30 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 31 | pthread_key_t Context::gThreadTLSKey = 0; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | |
| 33 | void Context::initEGL() |
| 34 | { |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 35 | mEGL.mNumConfigs = -1; |
| 36 | EGLint configAttribs[128]; |
| 37 | EGLint *configAttribsPtr = configAttribs; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 39 | memset(configAttribs, 0, sizeof(configAttribs)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 41 | configAttribsPtr[0] = EGL_SURFACE_TYPE; |
| 42 | configAttribsPtr[1] = EGL_WINDOW_BIT; |
| 43 | configAttribsPtr += 2; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 45 | if (mUseDepth) { |
| 46 | configAttribsPtr[0] = EGL_DEPTH_SIZE; |
| 47 | configAttribsPtr[1] = 16; |
| 48 | configAttribsPtr += 2; |
| 49 | } |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 50 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 51 | if (mDev->mForceSW) { |
| 52 | configAttribsPtr[0] = EGL_CONFIG_CAVEAT; |
| 53 | configAttribsPtr[1] = EGL_SLOW_CONFIG; |
| 54 | configAttribsPtr += 2; |
| 55 | } |
| 56 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 57 | configAttribsPtr[0] = EGL_NONE; |
| 58 | rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint)))); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 59 | |
Jason Sams | 6a17e16 | 2009-10-08 12:55:06 -0700 | [diff] [blame] | 60 | LOGV("initEGL start"); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 61 | mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 62 | eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion); |
| 63 | |
| 64 | status_t err = EGLUtils::selectConfigForNativeWindow(mEGL.mDisplay, configAttribs, mWndSurface, &mEGL.mConfig); |
| 65 | if (err) { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 66 | LOGE("couldn't find an EGLConfig matching the screen format\n"); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 67 | } |
| 68 | //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs); |
| 69 | |
| 70 | if (mWndSurface) { |
| 71 | mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL); |
| 72 | } else { |
| 73 | mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, |
| 74 | android_createDisplaySurface(), |
| 75 | NULL); |
| 76 | } |
| 77 | |
| 78 | mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, NULL, NULL); |
| 79 | eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext); |
| 80 | eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth); |
| 81 | eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight); |
| 82 | |
| 83 | |
| 84 | mGL.mVersion = glGetString(GL_VERSION); |
| 85 | mGL.mVendor = glGetString(GL_VENDOR); |
| 86 | mGL.mRenderer = glGetString(GL_RENDERER); |
| 87 | mGL.mExtensions = glGetString(GL_EXTENSIONS); |
| 88 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 89 | LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion); |
| 90 | LOGV("GL Version %s", mGL.mVersion); |
| 91 | LOGV("GL Vendor %s", mGL.mVendor); |
| 92 | LOGV("GL Renderer %s", mGL.mRenderer); |
| 93 | LOGV("GL Extensions %s", mGL.mExtensions); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 94 | |
Jason Sams | 67c6844 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 95 | if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) { |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 96 | LOGE("Error, OpenGL ES Lite not supported"); |
Jason Sams | 67c6844 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 97 | } else { |
| 98 | sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 99 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 102 | bool Context::runScript(Script *s, uint32_t launchID) |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 103 | { |
| 104 | ObjectBaseRef<ProgramFragment> frag(mFragment); |
| 105 | ObjectBaseRef<ProgramVertex> vtx(mVertex); |
| 106 | ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 107 | ObjectBaseRef<ProgramRaster> raster(mRaster); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 108 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 109 | bool ret = s->run(this, launchID); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 110 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 111 | mFragment.set(frag); |
| 112 | mVertex.set(vtx); |
| 113 | mFragmentStore.set(store); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 114 | mRaster.set(raster); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 115 | return ret; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 119 | bool Context::runRootScript() |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 120 | { |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 121 | if (props.mLogTimes) { |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 122 | timerSet(RS_TIMER_CLEAR_SWAP); |
| 123 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 124 | rsAssert(mRootScript->mEnviroment.mIsRoot); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 125 | |
Jason Sams | 59038ca | 2009-09-22 12:26:53 -0700 | [diff] [blame] | 126 | eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth); |
| 127 | eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 128 | glViewport(0, 0, mEGL.mWidth, mEGL.mHeight); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 129 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 130 | |
Jason Sams | 928f5cf | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 131 | glClearColor(mRootScript->mEnviroment.mClearColor[0], |
| 132 | mRootScript->mEnviroment.mClearColor[1], |
| 133 | mRootScript->mEnviroment.mClearColor[2], |
| 134 | mRootScript->mEnviroment.mClearColor[3]); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 135 | if (mUseDepth) { |
| 136 | glDepthMask(GL_TRUE); |
| 137 | glClearDepthf(mRootScript->mEnviroment.mClearDepth); |
| 138 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 139 | } else { |
| 140 | glClear(GL_COLOR_BUFFER_BIT); |
| 141 | } |
Jason Sams | 67c6844 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 142 | |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 143 | if (this->props.mLogTimes) { |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 144 | timerSet(RS_TIMER_SCRIPT); |
| 145 | } |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 146 | mStateFragmentStore.mLast.clear(); |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 147 | bool ret = runScript(mRootScript.get(), 0); |
Jason Sams | c7412b3 | 2009-10-14 15:43:53 -0700 | [diff] [blame^] | 148 | |
| 149 | GLenum err = glGetError(); |
| 150 | if (err != GL_NO_ERROR) { |
| 151 | LOGE("Pending GL Error, 0x%x", err); |
| 152 | } |
| 153 | |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 154 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 157 | uint64_t Context::getTime() const |
| 158 | { |
| 159 | struct timespec t; |
| 160 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 161 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); |
| 162 | } |
| 163 | |
| 164 | void Context::timerReset() |
| 165 | { |
| 166 | for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { |
| 167 | mTimers[ct] = 0; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void Context::timerInit() |
| 172 | { |
| 173 | mTimeLast = getTime(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 174 | mTimeFrame = mTimeLast; |
| 175 | mTimeLastFrame = mTimeLast; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 176 | mTimerActive = RS_TIMER_INTERNAL; |
| 177 | timerReset(); |
| 178 | } |
| 179 | |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 180 | void Context::timerFrame() |
| 181 | { |
| 182 | mTimeLastFrame = mTimeFrame; |
| 183 | mTimeFrame = getTime(); |
| 184 | } |
| 185 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 186 | void Context::timerSet(Timers tm) |
| 187 | { |
| 188 | uint64_t last = mTimeLast; |
| 189 | mTimeLast = getTime(); |
| 190 | mTimers[mTimerActive] += mTimeLast - last; |
| 191 | mTimerActive = tm; |
| 192 | } |
| 193 | |
| 194 | void Context::timerPrint() |
| 195 | { |
| 196 | double total = 0; |
| 197 | for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { |
| 198 | total += mTimers[ct]; |
| 199 | } |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 200 | uint64_t frame = mTimeFrame - mTimeLastFrame; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 201 | |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 202 | LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)", |
| 203 | frame / 1000000, |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 204 | 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000, |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 205 | 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimers[RS_TIMER_CLEAR_SWAP] / 1000000, |
| 206 | 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, |
| 207 | 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000); |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 210 | void Context::setupCheck() |
| 211 | { |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 212 | mFragmentStore->setupGL(this, &mStateFragmentStore); |
| 213 | mFragment->setupGL(this, &mStateFragment); |
| 214 | mRaster->setupGL(this, &mStateRaster); |
| 215 | mVertex->setupGL(this, &mStateVertex); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 218 | static bool getProp(const char *str) |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 219 | { |
| 220 | char buf[PROPERTY_VALUE_MAX]; |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 221 | property_get(str, buf, "0"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 222 | return 0 != strcmp(buf, "0"); |
| 223 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 224 | |
| 225 | void * Context::threadProc(void *vrsc) |
| 226 | { |
| 227 | Context *rsc = static_cast<Context *>(vrsc); |
| 228 | |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 229 | rsc->props.mLogTimes = getProp("debug.rs.profile"); |
| 230 | rsc->props.mLogScripts = getProp("debug.rs.script"); |
| 231 | rsc->props.mLogObjects = getProp("debug.rs.objects"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 232 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 233 | rsc->initEGL(); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 234 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 235 | ScriptTLSStruct *tlsStruct = new ScriptTLSStruct; |
| 236 | if (!tlsStruct) { |
| 237 | LOGE("Error allocating tls storage"); |
| 238 | return NULL; |
| 239 | } |
| 240 | tlsStruct->mContext = rsc; |
| 241 | tlsStruct->mScript = NULL; |
| 242 | int status = pthread_setspecific(rsc->gThreadTLSKey, tlsStruct); |
| 243 | if (status) { |
| 244 | LOGE("pthread_setspecific %i", status); |
| 245 | } |
| 246 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 247 | rsc->mStateRaster.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight); |
| 248 | rsc->setRaster(NULL); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 249 | rsc->mStateVertex.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 250 | rsc->setVertex(NULL); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 251 | rsc->mStateFragment.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 252 | rsc->setFragment(NULL); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 253 | rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 254 | rsc->setFragmentStore(NULL); |
| 255 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 256 | rsc->mRunning = true; |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 257 | bool mDraw = true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 258 | while (!rsc->mExit) { |
Jason Sams | bc948de | 2009-08-17 18:35:48 -0700 | [diff] [blame] | 259 | mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw); |
Jason Sams | 5f7fc27 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 260 | mDraw &= (rsc->mRootScript.get() != NULL); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 261 | |
Jason Sams | 5f7fc27 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 262 | if (mDraw) { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 263 | mDraw = rsc->runRootScript() && !rsc->mPaused; |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 264 | if (rsc->props.mLogTimes) { |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 265 | rsc->timerSet(RS_TIMER_CLEAR_SWAP); |
| 266 | } |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 267 | eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 268 | if (rsc->props.mLogTimes) { |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 269 | rsc->timerFrame(); |
| 270 | rsc->timerSet(RS_TIMER_INTERNAL); |
| 271 | rsc->timerPrint(); |
| 272 | rsc->timerReset(); |
| 273 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 274 | } |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 275 | if (rsc->mObjDestroy.mNeedToEmpty) { |
| 276 | rsc->objDestroyOOBRun(); |
| 277 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 280 | LOGV("RS Thread exiting"); |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 281 | rsc->mRaster.clear(); |
| 282 | rsc->mFragment.clear(); |
| 283 | rsc->mVertex.clear(); |
| 284 | rsc->mFragmentStore.clear(); |
| 285 | rsc->mRootScript.clear(); |
| 286 | rsc->mStateRaster.deinit(rsc); |
| 287 | rsc->mStateVertex.deinit(rsc); |
| 288 | rsc->mStateFragment.deinit(rsc); |
| 289 | rsc->mStateFragmentStore.deinit(rsc); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 290 | ObjectBase::zeroAllUserRef(rsc); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 291 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 292 | glClearColor(0,0,0,0); |
| 293 | glClear(GL_COLOR_BUFFER_BIT); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 294 | eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface); |
| 295 | eglTerminate(rsc->mEGL.mDisplay); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 296 | rsc->objDestroyOOBRun(); |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 297 | LOGV("RS Thread exited"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 298 | return NULL; |
| 299 | } |
| 300 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 301 | Context::Context(Device *dev, Surface *sur, bool useDepth) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 302 | { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 303 | dev->addContext(this); |
| 304 | mDev = dev; |
| 305 | mRunning = false; |
| 306 | mExit = false; |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 307 | mUseDepth = useDepth; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 308 | mPaused = false; |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 309 | mObjHead = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 310 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 311 | int status; |
| 312 | pthread_attr_t threadAttr; |
| 313 | |
Jason Sams | 996db8d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 314 | if (!gThreadTLSKey) { |
| 315 | status = pthread_key_create(&gThreadTLSKey, NULL); |
| 316 | if (status) { |
| 317 | LOGE("Failed to init thread tls key."); |
| 318 | return; |
| 319 | } |
| 320 | } else { |
| 321 | // HACK: workaround gl hang on start |
| 322 | exit(-1); |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 325 | status = pthread_attr_init(&threadAttr); |
| 326 | if (status) { |
| 327 | LOGE("Failed to init thread attribute."); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | sched_param sparam; |
| 332 | sparam.sched_priority = ANDROID_PRIORITY_DISPLAY; |
| 333 | pthread_attr_setschedparam(&threadAttr, &sparam); |
| 334 | |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 335 | mWndSurface = sur; |
| 336 | |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 337 | objDestroyOOBInit(); |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 338 | timerInit(); |
Jason Sams | d3f2eaf | 2009-09-24 15:42:52 -0700 | [diff] [blame] | 339 | timerSet(RS_TIMER_INTERNAL); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 340 | |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 341 | LOGV("RS Launching thread"); |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 342 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 343 | if (status) { |
| 344 | LOGE("Failed to start rs context thread."); |
| 345 | } |
| 346 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 347 | while(!mRunning) { |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 348 | usleep(100); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 349 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 350 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 351 | pthread_attr_destroy(&threadAttr); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | Context::~Context() |
| 355 | { |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 356 | LOGV("Context::~Context"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 357 | mExit = true; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 358 | mPaused = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 359 | void *res; |
| 360 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 361 | mIO.shutdown(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 362 | int status = pthread_join(mThreadId, &res); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 363 | objDestroyOOBRun(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 364 | |
| 365 | if (mDev) { |
| 366 | mDev->removeContext(this); |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 367 | pthread_key_delete(gThreadTLSKey); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 368 | } |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 369 | |
| 370 | objDestroyOOBDestroy(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 373 | void Context::pause() |
| 374 | { |
| 375 | mPaused = true; |
| 376 | } |
| 377 | |
| 378 | void Context::resume() |
| 379 | { |
| 380 | mPaused = false; |
| 381 | } |
| 382 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 383 | void Context::setRootScript(Script *s) |
| 384 | { |
| 385 | mRootScript.set(s); |
| 386 | } |
| 387 | |
| 388 | void Context::setFragmentStore(ProgramFragmentStore *pfs) |
| 389 | { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 390 | if (pfs == NULL) { |
| 391 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 392 | } else { |
| 393 | mFragmentStore.set(pfs); |
| 394 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void Context::setFragment(ProgramFragment *pf) |
| 398 | { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 399 | if (pf == NULL) { |
| 400 | mFragment.set(mStateFragment.mDefault); |
| 401 | } else { |
| 402 | mFragment.set(pf); |
| 403 | } |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 406 | void Context::setRaster(ProgramRaster *pr) |
| 407 | { |
| 408 | if (pr == NULL) { |
| 409 | mRaster.set(mStateRaster.mDefault); |
| 410 | } else { |
| 411 | mRaster.set(pr); |
| 412 | } |
| 413 | } |
| 414 | |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 415 | void Context::allocationCheck(const Allocation *a) |
| 416 | { |
| 417 | mVertex->checkUpdatedAllocation(a); |
| 418 | mFragment->checkUpdatedAllocation(a); |
| 419 | mFragmentStore->checkUpdatedAllocation(a); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void Context::setVertex(ProgramVertex *pv) |
| 423 | { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 424 | if (pv == NULL) { |
| 425 | mVertex.set(mStateVertex.mDefault); |
| 426 | } else { |
| 427 | mVertex.set(pv); |
| 428 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 431 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 432 | { |
| 433 | rsAssert(!obj->getName()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 434 | obj->setName(name, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 435 | mNames.add(obj); |
| 436 | } |
| 437 | |
| 438 | void Context::removeName(ObjectBase *obj) |
| 439 | { |
| 440 | for(size_t ct=0; ct < mNames.size(); ct++) { |
| 441 | if (obj == mNames[ct]) { |
| 442 | mNames.removeAt(ct); |
| 443 | return; |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | ObjectBase * Context::lookupName(const char *name) const |
| 449 | { |
| 450 | for(size_t ct=0; ct < mNames.size(); ct++) { |
| 451 | if (!strcmp(name, mNames[ct]->getName())) { |
| 452 | return mNames[ct]; |
| 453 | } |
| 454 | } |
| 455 | return NULL; |
| 456 | } |
| 457 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 458 | void Context::appendNameDefines(String8 *str) const |
| 459 | { |
| 460 | char buf[256]; |
| 461 | for (size_t ct=0; ct < mNames.size(); ct++) { |
| 462 | str->append("#define NAMED_"); |
| 463 | str->append(mNames[ct]->getName()); |
| 464 | str->append(" "); |
| 465 | sprintf(buf, "%i\n", (int)mNames[ct]); |
| 466 | str->append(buf); |
| 467 | } |
| 468 | } |
| 469 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 470 | void Context::appendVarDefines(String8 *str) const |
| 471 | { |
| 472 | char buf[256]; |
| 473 | for (size_t ct=0; ct < mInt32Defines.size(); ct++) { |
| 474 | str->append("#define "); |
| 475 | str->append(mInt32Defines.keyAt(ct)); |
| 476 | str->append(" "); |
| 477 | sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct)); |
| 478 | str->append(buf); |
| 479 | |
| 480 | } |
| 481 | for (size_t ct=0; ct < mFloatDefines.size(); ct++) { |
| 482 | str->append("#define "); |
| 483 | str->append(mFloatDefines.keyAt(ct)); |
| 484 | str->append(" "); |
| 485 | sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct)); |
| 486 | str->append(buf); |
| 487 | } |
| 488 | } |
| 489 | |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 490 | bool Context::objDestroyOOBInit() |
| 491 | { |
| 492 | int status = pthread_mutex_init(&mObjDestroy.mMutex, NULL); |
| 493 | if (status) { |
| 494 | LOGE("Context::ObjDestroyOOBInit mutex init failure"); |
| 495 | return false; |
| 496 | } |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | void Context::objDestroyOOBRun() |
| 501 | { |
| 502 | if (mObjDestroy.mNeedToEmpty) { |
| 503 | int status = pthread_mutex_lock(&mObjDestroy.mMutex); |
| 504 | if (status) { |
| 505 | LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | for (size_t ct = 0; ct < mObjDestroy.mDestroyList.size(); ct++) { |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 510 | mObjDestroy.mDestroyList[ct]->decUserRef(); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 511 | } |
| 512 | mObjDestroy.mDestroyList.clear(); |
| 513 | mObjDestroy.mNeedToEmpty = false; |
| 514 | |
| 515 | status = pthread_mutex_unlock(&mObjDestroy.mMutex); |
| 516 | if (status) { |
| 517 | LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status); |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void Context::objDestroyOOBDestroy() |
| 523 | { |
| 524 | rsAssert(!mObjDestroy.mNeedToEmpty); |
| 525 | pthread_mutex_destroy(&mObjDestroy.mMutex); |
| 526 | } |
| 527 | |
| 528 | void Context::objDestroyAdd(ObjectBase *obj) |
| 529 | { |
| 530 | int status = pthread_mutex_lock(&mObjDestroy.mMutex); |
| 531 | if (status) { |
| 532 | LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status); |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | mObjDestroy.mNeedToEmpty = true; |
| 537 | mObjDestroy.mDestroyList.add(obj); |
| 538 | |
| 539 | status = pthread_mutex_unlock(&mObjDestroy.mMutex); |
| 540 | if (status) { |
| 541 | LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status); |
| 542 | } |
| 543 | } |
| 544 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 545 | uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait) |
| 546 | { |
| 547 | //LOGE("getMessageToClient %i %i", bufferLen, wait); |
| 548 | if (!wait) { |
| 549 | if (mIO.mToClient.isEmpty()) { |
| 550 | // No message to get and not going to wait for one. |
| 551 | receiveLen = 0; |
| 552 | return 0; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | //LOGE("getMessageToClient 2 con=%p", this); |
| 557 | uint32_t bytesData = 0; |
| 558 | uint32_t commandID = 0; |
| 559 | const void *d = mIO.mToClient.get(&commandID, &bytesData); |
| 560 | //LOGE("getMessageToClient 3 %i %i", commandID, bytesData); |
| 561 | |
| 562 | *receiveLen = bytesData; |
| 563 | if (bufferLen >= bytesData) { |
| 564 | memcpy(data, d, bytesData); |
| 565 | mIO.mToClient.next(); |
| 566 | return commandID; |
| 567 | } |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | bool Context::sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace) |
| 572 | { |
| 573 | //LOGE("sendMessageToClient %i %i %i", cmdID, len, waitForSpace); |
| 574 | if (cmdID == 0) { |
| 575 | LOGE("Attempting to send invalid command 0 to client."); |
| 576 | return false; |
| 577 | } |
| 578 | if (!waitForSpace) { |
| 579 | if (mIO.mToClient.getFreeSpace() < len) { |
| 580 | // Not enough room, and not waiting. |
| 581 | return false; |
| 582 | } |
| 583 | } |
| 584 | //LOGE("sendMessageToClient 2"); |
| 585 | void *p = mIO.mToClient.reserve(len); |
| 586 | memcpy(p, data, len); |
| 587 | mIO.mToClient.commit(cmdID, len); |
| 588 | //LOGE("sendMessageToClient 3"); |
| 589 | return true; |
| 590 | } |
| 591 | |
| 592 | void Context::initToClient() |
| 593 | { |
| 594 | while(!mRunning) { |
| 595 | usleep(100); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void Context::deinitToClient() |
| 600 | { |
| 601 | mIO.mToClient.shutdown(); |
| 602 | } |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 603 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 604 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 605 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 606 | // |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 607 | |
| 608 | namespace android { |
| 609 | namespace renderscript { |
| 610 | |
| 611 | |
| 612 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) |
| 613 | { |
| 614 | Script *s = static_cast<Script *>(vs); |
| 615 | rsc->setRootScript(s); |
| 616 | } |
| 617 | |
| 618 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) |
| 619 | { |
| 620 | Sampler *s = static_cast<Sampler *>(vs); |
| 621 | |
| 622 | if (slot > RS_MAX_SAMPLER_SLOT) { |
| 623 | LOGE("Invalid sampler slot"); |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | s->bindToContext(&rsc->mStateSampler, slot); |
| 628 | } |
| 629 | |
| 630 | void rsi_ContextBindProgramFragmentStore(Context *rsc, RsProgramFragmentStore vpfs) |
| 631 | { |
| 632 | ProgramFragmentStore *pfs = static_cast<ProgramFragmentStore *>(vpfs); |
| 633 | rsc->setFragmentStore(pfs); |
| 634 | } |
| 635 | |
| 636 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) |
| 637 | { |
| 638 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
| 639 | rsc->setFragment(pf); |
| 640 | } |
| 641 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 642 | void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) |
| 643 | { |
| 644 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 645 | rsc->setRaster(pr); |
| 646 | } |
| 647 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 648 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) |
| 649 | { |
| 650 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
| 651 | rsc->setVertex(pv); |
| 652 | } |
| 653 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 654 | 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] | 655 | { |
| 656 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 657 | rsc->assignName(ob, name, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 658 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 659 | |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 660 | void rsi_ObjDestroy(Context *rsc, void *obj) |
| 661 | { |
| 662 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 663 | rsc->removeName(ob); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 664 | ob->decUserRef(); |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 667 | void rsi_ContextSetDefineF(Context *rsc, const char* name, float value) |
| 668 | { |
| 669 | rsc->addInt32Define(name, value); |
| 670 | } |
| 671 | |
| 672 | void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value) |
| 673 | { |
| 674 | rsc->addFloatDefine(name, value); |
| 675 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 676 | |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 677 | void rsi_ContextPause(Context *rsc) |
| 678 | { |
| 679 | rsc->pause(); |
| 680 | } |
| 681 | |
| 682 | void rsi_ContextResume(Context *rsc) |
| 683 | { |
| 684 | rsc->resume(); |
| 685 | } |
| 686 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 691 | RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version, bool useDepth) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 692 | { |
| 693 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | b13ada5 | 2009-08-25 11:34:49 -0700 | [diff] [blame] | 694 | Context *rsc = new Context(dev, (Surface *)sur, useDepth); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 695 | return rsc; |
| 696 | } |
| 697 | |
| 698 | void rsContextDestroy(RsContext vrsc) |
| 699 | { |
| 700 | Context * rsc = static_cast<Context *>(vrsc); |
| 701 | delete rsc; |
| 702 | } |
| 703 | |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 704 | void rsObjDestroyOOB(RsContext vrsc, void *obj) |
| 705 | { |
| 706 | Context * rsc = static_cast<Context *>(vrsc); |
| 707 | rsc->objDestroyAdd(static_cast<ObjectBase *>(obj)); |
| 708 | } |
| 709 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 710 | uint32_t rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, size_t bufferLen, bool wait) |
| 711 | { |
| 712 | Context * rsc = static_cast<Context *>(vrsc); |
| 713 | return rsc->getMessageToClient(data, receiveLen, bufferLen, wait); |
| 714 | } |
| 715 | |
| 716 | void rsContextInitToClient(RsContext vrsc) |
| 717 | { |
| 718 | Context * rsc = static_cast<Context *>(vrsc); |
| 719 | rsc->initToClient(); |
| 720 | } |
| 721 | |
| 722 | void rsContextDeinitToClient(RsContext vrsc) |
| 723 | { |
| 724 | Context * rsc = static_cast<Context *>(vrsc); |
| 725 | rsc->deinitToClient(); |
| 726 | } |
| 727 | |