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" |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 20 | #include "utils/String8.h" |
Mathias Agopian | 5ae678f | 2009-06-22 18:01:09 -0700 | [diff] [blame] | 21 | #include <ui/FramebufferNativeWindow.h> |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 23 | #include <GLES/gl.h> |
| 24 | #include <GLES/glext.h> |
| 25 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
| 29 | Context * Context::gCon = NULL; |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 30 | pthread_key_t Context::gThreadTLSKey = 0; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | |
| 32 | void Context::initEGL() |
| 33 | { |
| 34 | mNumConfigs = -1; |
| 35 | |
| 36 | EGLint s_configAttribs[] = { |
| 37 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
Jason Sams | b80dfa7 | 2009-07-10 17:32:40 -0700 | [diff] [blame] | 38 | #if 1 |
| 39 | EGL_RED_SIZE, 8, |
| 40 | EGL_GREEN_SIZE, 8, |
| 41 | EGL_BLUE_SIZE, 8, |
| 42 | EGL_ALPHA_SIZE, 8, |
| 43 | #else |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | EGL_RED_SIZE, 5, |
| 45 | EGL_GREEN_SIZE, 6, |
| 46 | EGL_BLUE_SIZE, 5, |
Jason Sams | b80dfa7 | 2009-07-10 17:32:40 -0700 | [diff] [blame] | 47 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 48 | EGL_DEPTH_SIZE, 16, |
| 49 | EGL_NONE |
| 50 | }; |
| 51 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 53 | eglInitialize(mDisplay, &mMajorVersion, &mMinorVersion); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 54 | eglChooseConfig(mDisplay, s_configAttribs, &mConfig, 1, &mNumConfigs); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | |
| 56 | if (mWndSurface) { |
Mathias Agopian | 5ae678f | 2009-06-22 18:01:09 -0700 | [diff] [blame] | 57 | mSurface = eglCreateWindowSurface(mDisplay, mConfig, mWndSurface, |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | NULL); |
| 59 | } else { |
| 60 | mSurface = eglCreateWindowSurface(mDisplay, mConfig, |
| 61 | android_createDisplaySurface(), |
| 62 | NULL); |
| 63 | } |
| 64 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 65 | mContext = eglCreateContext(mDisplay, mConfig, NULL, NULL); |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 66 | eglMakeCurrent(mDisplay, mSurface, mSurface, mContext); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 67 | eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth); |
| 68 | eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 71 | bool Context::runScript(Script *s, uint32_t launchID) |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 72 | { |
| 73 | ObjectBaseRef<ProgramFragment> frag(mFragment); |
| 74 | ObjectBaseRef<ProgramVertex> vtx(mVertex); |
| 75 | ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore); |
| 76 | |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 77 | bool ret = s->run(this, launchID); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 78 | |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 79 | mFragment.set(frag); |
| 80 | mVertex.set(vtx); |
| 81 | mFragmentStore.set(store); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 82 | return ret; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 86 | bool Context::runRootScript() |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | { |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 88 | #if RS_LOG_TIMES |
| 89 | struct timespec beginTime; |
| 90 | clock_gettime(CLOCK_MONOTONIC, &beginTime); |
| 91 | #endif |
| 92 | |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 93 | rsAssert(mRootScript->mEnviroment.mIsRoot); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 94 | |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 95 | //glColor4f(1,1,1,1); |
| 96 | //glEnable(GL_LIGHT0); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 97 | glViewport(0, 0, mWidth, mHeight); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 98 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 99 | glDepthMask(GL_TRUE); |
| 100 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 101 | |
Jason Sams | 928b734 | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 102 | glClearColor(mRootScript->mEnviroment.mClearColor[0], |
| 103 | mRootScript->mEnviroment.mClearColor[1], |
| 104 | mRootScript->mEnviroment.mClearColor[2], |
| 105 | mRootScript->mEnviroment.mClearColor[3]); |
| 106 | glClearDepthf(mRootScript->mEnviroment.mClearDepth); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 107 | glClear(GL_COLOR_BUFFER_BIT); |
| 108 | glClear(GL_DEPTH_BUFFER_BIT); |
| 109 | |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 110 | #if RS_LOG_TIMES |
| 111 | struct timespec startTime; |
| 112 | clock_gettime(CLOCK_MONOTONIC, &startTime); |
| 113 | #endif |
| 114 | bool ret = runScript(mRootScript.get(), 0); |
| 115 | |
| 116 | #if RS_LOG_TIMES |
| 117 | struct timespec endTime; |
| 118 | clock_gettime(CLOCK_MONOTONIC, &endTime); |
| 119 | |
| 120 | int t1 = ((unsigned long)startTime.tv_nsec - (unsigned long)beginTime.tv_nsec) / 1000 / 1000; |
| 121 | int t2 = ((unsigned long)endTime.tv_nsec - (unsigned long)startTime.tv_nsec) / 1000 / 1000; |
| 122 | LOGE("times %i, %i", t1, t2); |
| 123 | #endif |
| 124 | |
| 125 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void Context::setupCheck() |
| 129 | { |
| 130 | if (mFragmentStore.get()) { |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 131 | mFragmentStore->setupGL(&mStateFragmentStore); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 132 | } |
| 133 | if (mFragment.get()) { |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 134 | mFragment->setupGL(&mStateFragment); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 135 | } |
| 136 | if (mVertex.get()) { |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 137 | mVertex->setupGL(&mStateVertex); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | } |
| 141 | |
| 142 | |
| 143 | void * Context::threadProc(void *vrsc) |
| 144 | { |
| 145 | Context *rsc = static_cast<Context *>(vrsc); |
| 146 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 147 | gIO = new ThreadIO(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 148 | rsc->initEGL(); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 149 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 150 | ScriptTLSStruct *tlsStruct = new ScriptTLSStruct; |
| 151 | if (!tlsStruct) { |
| 152 | LOGE("Error allocating tls storage"); |
| 153 | return NULL; |
| 154 | } |
| 155 | tlsStruct->mContext = rsc; |
| 156 | tlsStruct->mScript = NULL; |
| 157 | int status = pthread_setspecific(rsc->gThreadTLSKey, tlsStruct); |
| 158 | if (status) { |
| 159 | LOGE("pthread_setspecific %i", status); |
| 160 | } |
| 161 | |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 162 | rsc->mStateVertex.init(rsc, rsc->mWidth, rsc->mHeight); |
| 163 | rsc->setVertex(NULL); |
| 164 | rsc->mStateFragment.init(rsc, rsc->mWidth, rsc->mHeight); |
| 165 | rsc->setFragment(NULL); |
| 166 | rsc->mStateFragmentStore.init(rsc, rsc->mWidth, rsc->mHeight); |
| 167 | rsc->setFragmentStore(NULL); |
| 168 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 169 | rsc->mRunning = true; |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 170 | bool mDraw = true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 171 | while (!rsc->mExit) { |
Jason Sams | 732f1c0 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 172 | mDraw |= gIO->playCoreCommands(rsc, !mDraw); |
| 173 | mDraw &= (rsc->mRootScript.get() != NULL); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 174 | |
Jason Sams | 732f1c0 | 2009-06-18 16:58:42 -0700 | [diff] [blame] | 175 | if (mDraw) { |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 176 | mDraw = rsc->runRootScript(); |
| 177 | eglSwapBuffers(rsc->mDisplay, rsc->mSurface); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 178 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 181 | glClearColor(0,0,0,0); |
| 182 | glClear(GL_COLOR_BUFFER_BIT); |
| 183 | eglSwapBuffers(rsc->mDisplay, rsc->mSurface); |
| 184 | eglTerminate(rsc->mDisplay); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 185 | return NULL; |
| 186 | } |
| 187 | |
| 188 | Context::Context(Device *dev, Surface *sur) |
| 189 | { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 190 | dev->addContext(this); |
| 191 | mDev = dev; |
| 192 | mRunning = false; |
| 193 | mExit = false; |
| 194 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 195 | // see comment in header |
| 196 | gCon = this; |
| 197 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 198 | int status; |
| 199 | pthread_attr_t threadAttr; |
| 200 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 201 | status = pthread_key_create(&gThreadTLSKey, NULL); |
| 202 | if (status) { |
| 203 | LOGE("Failed to init thread tls key."); |
| 204 | return; |
| 205 | } |
| 206 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 207 | status = pthread_attr_init(&threadAttr); |
| 208 | if (status) { |
| 209 | LOGE("Failed to init thread attribute."); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | sched_param sparam; |
| 214 | sparam.sched_priority = ANDROID_PRIORITY_DISPLAY; |
| 215 | pthread_attr_setschedparam(&threadAttr, &sparam); |
| 216 | |
Jason Sams | 992a0b7 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 217 | mWndSurface = sur; |
| 218 | |
| 219 | LOGV("RS Launching thread"); |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 220 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 221 | if (status) { |
| 222 | LOGE("Failed to start rs context thread."); |
| 223 | } |
| 224 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 225 | while(!mRunning) { |
| 226 | sleep(1); |
| 227 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 228 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 229 | pthread_attr_destroy(&threadAttr); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | Context::~Context() |
| 233 | { |
| 234 | mExit = true; |
| 235 | void *res; |
| 236 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 237 | int status = pthread_join(mThreadId, &res); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 238 | |
| 239 | if (mDev) { |
| 240 | mDev->removeContext(this); |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 241 | pthread_key_delete(gThreadTLSKey); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 242 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void Context::swapBuffers() |
| 246 | { |
| 247 | eglSwapBuffers(mDisplay, mSurface); |
| 248 | } |
| 249 | |
| 250 | void rsContextSwap(RsContext vrsc) |
| 251 | { |
| 252 | Context *rsc = static_cast<Context *>(vrsc); |
| 253 | rsc->swapBuffers(); |
| 254 | } |
| 255 | |
| 256 | void Context::setRootScript(Script *s) |
| 257 | { |
| 258 | mRootScript.set(s); |
| 259 | } |
| 260 | |
| 261 | void Context::setFragmentStore(ProgramFragmentStore *pfs) |
| 262 | { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 263 | if (pfs == NULL) { |
| 264 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 265 | } else { |
| 266 | mFragmentStore.set(pfs); |
| 267 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void Context::setFragment(ProgramFragment *pf) |
| 271 | { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 272 | if (pf == NULL) { |
| 273 | mFragment.set(mStateFragment.mDefault); |
| 274 | } else { |
| 275 | mFragment.set(pf); |
| 276 | } |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void Context::allocationCheck(const Allocation *a) |
| 280 | { |
| 281 | mVertex->checkUpdatedAllocation(a); |
| 282 | mFragment->checkUpdatedAllocation(a); |
| 283 | mFragmentStore->checkUpdatedAllocation(a); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void Context::setVertex(ProgramVertex *pv) |
| 287 | { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 288 | if (pv == NULL) { |
| 289 | mVertex.set(mStateVertex.mDefault); |
| 290 | } else { |
| 291 | mVertex.set(pv); |
| 292 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 295 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 296 | { |
| 297 | rsAssert(!obj->getName()); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 298 | obj->setName(name, len); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 299 | mNames.add(obj); |
| 300 | } |
| 301 | |
| 302 | void Context::removeName(ObjectBase *obj) |
| 303 | { |
| 304 | for(size_t ct=0; ct < mNames.size(); ct++) { |
| 305 | if (obj == mNames[ct]) { |
| 306 | mNames.removeAt(ct); |
| 307 | return; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | ObjectBase * Context::lookupName(const char *name) const |
| 313 | { |
| 314 | for(size_t ct=0; ct < mNames.size(); ct++) { |
| 315 | if (!strcmp(name, mNames[ct]->getName())) { |
| 316 | return mNames[ct]; |
| 317 | } |
| 318 | } |
| 319 | return NULL; |
| 320 | } |
| 321 | |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 322 | void Context::appendNameDefines(String8 *str) const |
| 323 | { |
| 324 | char buf[256]; |
| 325 | for (size_t ct=0; ct < mNames.size(); ct++) { |
| 326 | str->append("#define NAMED_"); |
| 327 | str->append(mNames[ct]->getName()); |
| 328 | str->append(" "); |
| 329 | sprintf(buf, "%i\n", (int)mNames[ct]); |
| 330 | str->append(buf); |
| 331 | } |
| 332 | } |
| 333 | |
Joe Onorato | 57b79ce | 2009-08-09 22:57:44 -0700 | [diff] [blame^] | 334 | void Context::appendVarDefines(String8 *str) const |
| 335 | { |
| 336 | char buf[256]; |
| 337 | for (size_t ct=0; ct < mInt32Defines.size(); ct++) { |
| 338 | str->append("#define "); |
| 339 | str->append(mInt32Defines.keyAt(ct)); |
| 340 | str->append(" "); |
| 341 | sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct)); |
| 342 | str->append(buf); |
| 343 | |
| 344 | } |
| 345 | for (size_t ct=0; ct < mFloatDefines.size(); ct++) { |
| 346 | str->append("#define "); |
| 347 | str->append(mFloatDefines.keyAt(ct)); |
| 348 | str->append(" "); |
| 349 | sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct)); |
| 350 | str->append(buf); |
| 351 | } |
| 352 | } |
| 353 | |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 354 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 355 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 356 | // |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 357 | |
| 358 | namespace android { |
| 359 | namespace renderscript { |
| 360 | |
| 361 | |
| 362 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) |
| 363 | { |
| 364 | Script *s = static_cast<Script *>(vs); |
| 365 | rsc->setRootScript(s); |
| 366 | } |
| 367 | |
| 368 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) |
| 369 | { |
| 370 | Sampler *s = static_cast<Sampler *>(vs); |
| 371 | |
| 372 | if (slot > RS_MAX_SAMPLER_SLOT) { |
| 373 | LOGE("Invalid sampler slot"); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | s->bindToContext(&rsc->mStateSampler, slot); |
| 378 | } |
| 379 | |
| 380 | void rsi_ContextBindProgramFragmentStore(Context *rsc, RsProgramFragmentStore vpfs) |
| 381 | { |
| 382 | ProgramFragmentStore *pfs = static_cast<ProgramFragmentStore *>(vpfs); |
| 383 | rsc->setFragmentStore(pfs); |
| 384 | } |
| 385 | |
| 386 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) |
| 387 | { |
| 388 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
| 389 | rsc->setFragment(pf); |
| 390 | } |
| 391 | |
| 392 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) |
| 393 | { |
| 394 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
| 395 | rsc->setVertex(pv); |
| 396 | } |
| 397 | |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 398 | 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] | 399 | { |
| 400 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 401 | rsc->assignName(ob, name, len); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 402 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 403 | |
Joe Onorato | 57b79ce | 2009-08-09 22:57:44 -0700 | [diff] [blame^] | 404 | void rsi_ContextSetDefineF(Context *rsc, const char* name, float value) |
| 405 | { |
| 406 | rsc->addInt32Define(name, value); |
| 407 | } |
| 408 | |
| 409 | void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value) |
| 410 | { |
| 411 | rsc->addFloatDefine(name, value); |
| 412 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 413 | |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | |
| 418 | RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version) |
| 419 | { |
| 420 | Device * dev = static_cast<Device *>(vdev); |
| 421 | Context *rsc = new Context(dev, (Surface *)sur); |
| 422 | return rsc; |
| 423 | } |
| 424 | |
| 425 | void rsContextDestroy(RsContext vrsc) |
| 426 | { |
| 427 | Context * rsc = static_cast<Context *>(vrsc); |
| 428 | delete rsc; |
| 429 | } |
| 430 | |