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