blob: 8f56efa28e7151925025c8df8b1108c37b8632dd [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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 Agopian5ae678f2009-06-22 18:01:09 -070020#include <ui/FramebufferNativeWindow.h>
Jason Samsafcb25c2009-08-25 11:34:49 -070021#include <ui/EGLUtils.h>
Jason Sams326e0dd2009-05-22 14:03:28 -070022
Jason Sams15832442009-11-15 12:14:26 -080023#include <sys/types.h>
24#include <sys/resource.h>
25
Joe Onorato76371ff2009-09-23 16:37:36 -070026#include <cutils/properties.h>
27
Jason Sams1aa5a4e2009-06-22 17:15:15 -070028#include <GLES/gl.h>
29#include <GLES/glext.h>
Jason Sams4815c0d2009-12-15 12:58:36 -080030#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
Jason Sams1aa5a4e2009-06-22 17:15:15 -070032
Jason Sams15832442009-11-15 12:14:26 -080033#include <cutils/sched_policy.h>
34
Jason Sams326e0dd2009-05-22 14:03:28 -070035using namespace android;
36using namespace android::renderscript;
37
Jason Samse5769102009-06-19 16:03:18 -070038pthread_key_t Context::gThreadTLSKey = 0;
Jason Samsfb03a222009-10-15 16:47:31 -070039uint32_t Context::gThreadTLSKeyCount = 0;
Jason Sams33b6e3b2009-10-27 14:44:31 -070040uint32_t Context::gGLContextCount = 0;
Jason Samsfb03a222009-10-15 16:47:31 -070041pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
Jason Sams326e0dd2009-05-22 14:03:28 -070042
Jason Sams33b6e3b2009-10-27 14:44:31 -070043static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
44 if (returnVal != EGL_TRUE) {
45 fprintf(stderr, "%s() returned %d\n", op, returnVal);
46 }
47
48 for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
49 = eglGetError()) {
50 fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error),
51 error);
52 }
53}
54
Jason Samsc460e552009-11-25 13:22:07 -080055void Context::initEGL(bool useGL2)
Jason Sams326e0dd2009-05-22 14:03:28 -070056{
Jason Samsafcb25c2009-08-25 11:34:49 -070057 mEGL.mNumConfigs = -1;
58 EGLint configAttribs[128];
59 EGLint *configAttribsPtr = configAttribs;
Jason Samsc460e552009-11-25 13:22:07 -080060 EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
Jason Sams326e0dd2009-05-22 14:03:28 -070061
Jason Samsafcb25c2009-08-25 11:34:49 -070062 memset(configAttribs, 0, sizeof(configAttribs));
Jason Sams326e0dd2009-05-22 14:03:28 -070063
Jason Samsafcb25c2009-08-25 11:34:49 -070064 configAttribsPtr[0] = EGL_SURFACE_TYPE;
65 configAttribsPtr[1] = EGL_WINDOW_BIT;
66 configAttribsPtr += 2;
Jason Sams326e0dd2009-05-22 14:03:28 -070067
Jason Samsc460e552009-11-25 13:22:07 -080068 if (useGL2) {
69 configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
70 configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
71 configAttribsPtr += 2;
72 }
73
Jason Samsafcb25c2009-08-25 11:34:49 -070074 if (mUseDepth) {
75 configAttribsPtr[0] = EGL_DEPTH_SIZE;
76 configAttribsPtr[1] = 16;
77 configAttribsPtr += 2;
78 }
Jason Sams9397e302009-08-27 20:23:34 -070079
Jason Sams5fd09d82009-09-23 13:57:02 -070080 if (mDev->mForceSW) {
81 configAttribsPtr[0] = EGL_CONFIG_CAVEAT;
82 configAttribsPtr[1] = EGL_SLOW_CONFIG;
83 configAttribsPtr += 2;
84 }
85
Jason Samsafcb25c2009-08-25 11:34:49 -070086 configAttribsPtr[0] = EGL_NONE;
87 rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
Jason Sams326e0dd2009-05-22 14:03:28 -070088
Jason Sams6d751ef2009-10-08 12:55:06 -070089 LOGV("initEGL start");
Jason Samsafcb25c2009-08-25 11:34:49 -070090 mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Jason Sams33b6e3b2009-10-27 14:44:31 -070091 checkEglError("eglGetDisplay");
92
Jason Samsafcb25c2009-08-25 11:34:49 -070093 eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion);
Jason Sams33b6e3b2009-10-27 14:44:31 -070094 checkEglError("eglInitialize");
Jason Samsafcb25c2009-08-25 11:34:49 -070095
96 status_t err = EGLUtils::selectConfigForNativeWindow(mEGL.mDisplay, configAttribs, mWndSurface, &mEGL.mConfig);
97 if (err) {
Jason Sams9397e302009-08-27 20:23:34 -070098 LOGE("couldn't find an EGLConfig matching the screen format\n");
Jason Samsafcb25c2009-08-25 11:34:49 -070099 }
100 //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
101
Jason Samsafcb25c2009-08-25 11:34:49 -0700102
Jason Samsc460e552009-11-25 13:22:07 -0800103 if (useGL2) {
104 mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
105 } else {
106 mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
107 }
Jason Sams33b6e3b2009-10-27 14:44:31 -0700108 checkEglError("eglCreateContext");
109 if (mEGL.mContext == EGL_NO_CONTEXT) {
110 LOGE("eglCreateContext returned EGL_NO_CONTEXT");
111 }
112 gGLContextCount++;
Jason Sams326e0dd2009-05-22 14:03:28 -0700113}
114
Jason Sams33b6e3b2009-10-27 14:44:31 -0700115void Context::deinitEGL()
116{
Jason Sams613cad12009-11-12 15:10:25 -0800117 LOGV("deinitEGL");
118 setSurface(0, 0, NULL);
Jason Sams33b6e3b2009-10-27 14:44:31 -0700119 eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
120 checkEglError("eglDestroyContext");
121
122 gGLContextCount--;
123 if (!gGLContextCount) {
124 eglTerminate(mEGL.mDisplay);
125 }
126}
127
128
Jason Sams2dca84d2009-12-09 11:05:45 -0800129uint32_t Context::runScript(Script *s, uint32_t launchID)
Jason Sams10308932009-06-09 12:15:30 -0700130{
131 ObjectBaseRef<ProgramFragment> frag(mFragment);
132 ObjectBaseRef<ProgramVertex> vtx(mVertex);
133 ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
Jason Samsb681c8a2009-09-28 18:12:56 -0700134 ObjectBaseRef<ProgramRaster> raster(mRaster);
Jason Sams10308932009-06-09 12:15:30 -0700135
Jason Sams2dca84d2009-12-09 11:05:45 -0800136 uint32_t ret = s->run(this, launchID);
Jason Sams10308932009-06-09 12:15:30 -0700137
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700138 mFragment.set(frag);
139 mVertex.set(vtx);
140 mFragmentStore.set(store);
Jason Samsb681c8a2009-09-28 18:12:56 -0700141 mRaster.set(raster);
Jason Samsc9d43db2009-07-28 12:02:16 -0700142 return ret;
Jason Sams10308932009-06-09 12:15:30 -0700143}
144
145
Jason Sams2dca84d2009-12-09 11:05:45 -0800146uint32_t Context::runRootScript()
Jason Sams326e0dd2009-05-22 14:03:28 -0700147{
Jason Sams2dca84d2009-12-09 11:05:45 -0800148 timerSet(RS_TIMER_CLEAR_SWAP);
Jason Sams10308932009-06-09 12:15:30 -0700149 rsAssert(mRootScript->mEnviroment.mIsRoot);
Jason Sams326e0dd2009-05-22 14:03:28 -0700150
Jason Sams8c9534b2009-09-22 12:26:53 -0700151 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
152 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
Jason Samsafcb25c2009-08-25 11:34:49 -0700153 glViewport(0, 0, mEGL.mWidth, mEGL.mHeight);
Jason Sams326e0dd2009-05-22 14:03:28 -0700154 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
155
Jason Sams928b7342009-06-08 18:50:13 -0700156 glClearColor(mRootScript->mEnviroment.mClearColor[0],
157 mRootScript->mEnviroment.mClearColor[1],
158 mRootScript->mEnviroment.mClearColor[2],
159 mRootScript->mEnviroment.mClearColor[3]);
Jason Samsafcb25c2009-08-25 11:34:49 -0700160 if (mUseDepth) {
161 glDepthMask(GL_TRUE);
162 glClearDepthf(mRootScript->mEnviroment.mClearDepth);
163 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
164 } else {
165 glClear(GL_COLOR_BUFFER_BIT);
166 }
Jason Sams306fb232009-08-25 17:09:59 -0700167
Jason Sams2dca84d2009-12-09 11:05:45 -0800168 timerSet(RS_TIMER_SCRIPT);
Jason Sams8c401ef2009-10-06 13:58:47 -0700169 mStateFragmentStore.mLast.clear();
Jason Sams2dca84d2009-12-09 11:05:45 -0800170 uint32_t ret = runScript(mRootScript.get(), 0);
Jason Sams8cfdd242009-10-14 15:43:53 -0700171
172 GLenum err = glGetError();
173 if (err != GL_NO_ERROR) {
174 LOGE("Pending GL Error, 0x%x", err);
175 }
176
Jason Samscfb1d112009-08-05 13:57:03 -0700177 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700178}
179
Jason Sams24371d92009-08-19 12:17:14 -0700180uint64_t Context::getTime() const
181{
182 struct timespec t;
183 clock_gettime(CLOCK_MONOTONIC, &t);
184 return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000);
185}
186
187void Context::timerReset()
188{
189 for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) {
190 mTimers[ct] = 0;
191 }
192}
193
194void Context::timerInit()
195{
196 mTimeLast = getTime();
Jason Sams1d54f102009-09-03 15:43:13 -0700197 mTimeFrame = mTimeLast;
198 mTimeLastFrame = mTimeLast;
Jason Sams24371d92009-08-19 12:17:14 -0700199 mTimerActive = RS_TIMER_INTERNAL;
200 timerReset();
201}
202
Jason Sams1d54f102009-09-03 15:43:13 -0700203void Context::timerFrame()
204{
205 mTimeLastFrame = mTimeFrame;
206 mTimeFrame = getTime();
207}
208
Jason Sams24371d92009-08-19 12:17:14 -0700209void Context::timerSet(Timers tm)
210{
211 uint64_t last = mTimeLast;
212 mTimeLast = getTime();
213 mTimers[mTimerActive] += mTimeLast - last;
214 mTimerActive = tm;
215}
216
217void Context::timerPrint()
218{
219 double total = 0;
220 for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) {
221 total += mTimers[ct];
222 }
Jason Sams1d54f102009-09-03 15:43:13 -0700223 uint64_t frame = mTimeFrame - mTimeLastFrame;
Jason Sams2dca84d2009-12-09 11:05:45 -0800224 mTimeMSLastFrame = frame / 1000000;
225 mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000;
226 mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000;
Jason Sams24371d92009-08-19 12:17:14 -0700227
Jason Sams2dca84d2009-12-09 11:05:45 -0800228
229 if (props.mLogTimes) {
230 LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)",
231 mTimeMSLastFrame,
232 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
233 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
234 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
235 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
236 }
Jason Sams24371d92009-08-19 12:17:14 -0700237}
238
Jason Sams326e0dd2009-05-22 14:03:28 -0700239void Context::setupCheck()
240{
Jason Samsc460e552009-11-25 13:22:07 -0800241 if (checkVersion2_0()) {
Jason Samscd506532009-12-15 19:10:11 -0800242 mShaderCache.lookup(this, mVertex.get(), mFragment.get());
Jason Samsc460e552009-11-25 13:22:07 -0800243
244 mFragmentStore->setupGL2(this, &mStateFragmentStore);
245 mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
246 mRaster->setupGL2(this, &mStateRaster);
247 mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
248
249 } else {
250 mFragmentStore->setupGL(this, &mStateFragmentStore);
251 mFragment->setupGL(this, &mStateFragment);
252 mRaster->setupGL(this, &mStateRaster);
253 mVertex->setupGL(this, &mStateVertex);
254 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700255}
256
Jason Sams1fddd902009-09-25 15:25:00 -0700257static bool getProp(const char *str)
Joe Onorato76371ff2009-09-23 16:37:36 -0700258{
259 char buf[PROPERTY_VALUE_MAX];
Jason Sams1fddd902009-09-25 15:25:00 -0700260 property_get(str, buf, "0");
Joe Onorato76371ff2009-09-23 16:37:36 -0700261 return 0 != strcmp(buf, "0");
262}
Jason Sams326e0dd2009-05-22 14:03:28 -0700263
264void * Context::threadProc(void *vrsc)
265{
266 Context *rsc = static_cast<Context *>(vrsc);
Jason Sams15832442009-11-15 12:14:26 -0800267 rsc->mNativeThreadId = gettid();
268
269 setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
Jason Sams2dca84d2009-12-09 11:05:45 -0800270 rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
Jason Sams326e0dd2009-05-22 14:03:28 -0700271
Jason Sams1fddd902009-09-25 15:25:00 -0700272 rsc->props.mLogTimes = getProp("debug.rs.profile");
273 rsc->props.mLogScripts = getProp("debug.rs.script");
274 rsc->props.mLogObjects = getProp("debug.rs.objects");
Jason Samscd506532009-12-15 19:10:11 -0800275 rsc->props.mLogShaders = getProp("debug.rs.shaders");
Joe Onorato76371ff2009-09-23 16:37:36 -0700276
Jason Samse5769102009-06-19 16:03:18 -0700277 ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
278 if (!tlsStruct) {
279 LOGE("Error allocating tls storage");
280 return NULL;
281 }
282 tlsStruct->mContext = rsc;
283 tlsStruct->mScript = NULL;
284 int status = pthread_setspecific(rsc->gThreadTLSKey, tlsStruct);
285 if (status) {
286 LOGE("pthread_setspecific %i", status);
287 }
288
Jason Sams5fd09d82009-09-23 13:57:02 -0700289 rsc->mStateRaster.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
290 rsc->setRaster(NULL);
Jason Samsafcb25c2009-08-25 11:34:49 -0700291 rsc->mStateVertex.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
Jason Sams8ce125b2009-06-17 16:52:59 -0700292 rsc->setVertex(NULL);
Jason Samsafcb25c2009-08-25 11:34:49 -0700293 rsc->mStateFragment.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
Jason Sams8ce125b2009-06-17 16:52:59 -0700294 rsc->setFragment(NULL);
Jason Samsafcb25c2009-08-25 11:34:49 -0700295 rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
Jason Sams8ce125b2009-06-17 16:52:59 -0700296 rsc->setFragmentStore(NULL);
Jason Samsc460e552009-11-25 13:22:07 -0800297 rsc->mStateVertexArray.init(rsc);
Jason Sams8ce125b2009-06-17 16:52:59 -0700298
Jason Sams326e0dd2009-05-22 14:03:28 -0700299 rsc->mRunning = true;
Jason Samsa44cb292009-06-04 17:58:03 -0700300 bool mDraw = true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700301 while (!rsc->mExit) {
Jason Samsfcd31922009-08-17 18:35:48 -0700302 mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw);
Jason Sams732f1c02009-06-18 16:58:42 -0700303 mDraw &= (rsc->mRootScript.get() != NULL);
Jason Sams458f2dc2009-11-03 13:58:36 -0800304 mDraw &= (rsc->mWndSurface != NULL);
Jason Sams326e0dd2009-05-22 14:03:28 -0700305
Jason Sams2dca84d2009-12-09 11:05:45 -0800306 uint32_t targetTime = 0;
Jason Sams732f1c02009-06-18 16:58:42 -0700307 if (mDraw) {
Jason Sams2dca84d2009-12-09 11:05:45 -0800308 targetTime = rsc->runRootScript();
309 mDraw = targetTime && !rsc->mPaused;
310 rsc->timerSet(RS_TIMER_CLEAR_SWAP);
Jason Samsafcb25c2009-08-25 11:34:49 -0700311 eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
Jason Sams2dca84d2009-12-09 11:05:45 -0800312 rsc->timerFrame();
313 rsc->timerSet(RS_TIMER_INTERNAL);
314 rsc->timerPrint();
315 rsc->timerReset();
Jason Sams326e0dd2009-05-22 14:03:28 -0700316 }
Jason Sams24371d92009-08-19 12:17:14 -0700317 if (rsc->mObjDestroy.mNeedToEmpty) {
318 rsc->objDestroyOOBRun();
319 }
Jason Sams2dca84d2009-12-09 11:05:45 -0800320 if (rsc->mThreadPriority > 0 && targetTime) {
321 int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000;
322 if (t > 0) {
323 usleep(t);
324 }
325 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700326 }
327
Jason Sams8c0ee652009-08-25 14:49:07 -0700328 LOGV("RS Thread exiting");
Jason Samsf2649a92009-09-25 16:37:33 -0700329 rsc->mRaster.clear();
330 rsc->mFragment.clear();
331 rsc->mVertex.clear();
332 rsc->mFragmentStore.clear();
333 rsc->mRootScript.clear();
334 rsc->mStateRaster.deinit(rsc);
335 rsc->mStateVertex.deinit(rsc);
336 rsc->mStateFragment.deinit(rsc);
337 rsc->mStateFragmentStore.deinit(rsc);
Jason Samse514b452009-09-25 14:51:22 -0700338 ObjectBase::zeroAllUserRef(rsc);
Jason Samse514b452009-09-25 14:51:22 -0700339
Jason Samse402ed32009-11-03 11:25:42 -0800340 rsc->mObjDestroy.mNeedToEmpty = true;
341 rsc->objDestroyOOBRun();
342
Jason Sams326e0dd2009-05-22 14:03:28 -0700343 glClearColor(0,0,0,0);
344 glClear(GL_COLOR_BUFFER_BIT);
Jason Samsafcb25c2009-08-25 11:34:49 -0700345 eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
Jason Sams33b6e3b2009-10-27 14:44:31 -0700346
347 pthread_mutex_lock(&gInitMutex);
348 rsc->deinitEGL();
349 pthread_mutex_unlock(&gInitMutex);
350
Jason Sams8c0ee652009-08-25 14:49:07 -0700351 LOGV("RS Thread exited");
Jason Sams326e0dd2009-05-22 14:03:28 -0700352 return NULL;
353}
354
Jason Sams15832442009-11-15 12:14:26 -0800355void Context::setPriority(int32_t p)
356{
357 // Note: If we put this in the proper "background" policy
358 // the wallpapers can become completly unresponsive at times.
359 // This is probably not what we want for something the user is actively
360 // looking at.
Jason Sams2dca84d2009-12-09 11:05:45 -0800361 mThreadPriority = p;
Jason Sams15832442009-11-15 12:14:26 -0800362#if 0
363 SchedPolicy pol = SP_FOREGROUND;
364 if (p > 0) {
365 pol = SP_BACKGROUND;
366 }
367 if (!set_sched_policy(mNativeThreadId, pol)) {
368 // success; reset the priority as well
369 }
370#else
371 setpriority(PRIO_PROCESS, mNativeThreadId, p);
372#endif
373}
374
Jason Sams613cad12009-11-12 15:10:25 -0800375Context::Context(Device *dev, bool useDepth)
Jason Sams326e0dd2009-05-22 14:03:28 -0700376{
Jason Samsfb03a222009-10-15 16:47:31 -0700377 pthread_mutex_lock(&gInitMutex);
378
Jason Sams326e0dd2009-05-22 14:03:28 -0700379 dev->addContext(this);
380 mDev = dev;
381 mRunning = false;
382 mExit = false;
Jason Samsafcb25c2009-08-25 11:34:49 -0700383 mUseDepth = useDepth;
Jason Sams86f1b232009-09-24 17:38:20 -0700384 mPaused = false;
Jason Samse514b452009-09-25 14:51:22 -0700385 mObjHead = NULL;
Jason Sams613cad12009-11-12 15:10:25 -0800386 memset(&mEGL, 0, sizeof(mEGL));
Jason Sams326e0dd2009-05-22 14:03:28 -0700387
Jason Samsa658e902009-06-04 14:35:01 -0700388 int status;
389 pthread_attr_t threadAttr;
390
Jason Samsfb03a222009-10-15 16:47:31 -0700391 if (!gThreadTLSKeyCount) {
Jason Sams9e4e13d2009-10-06 17:16:55 -0700392 status = pthread_key_create(&gThreadTLSKey, NULL);
393 if (status) {
394 LOGE("Failed to init thread tls key.");
Jason Samsfb03a222009-10-15 16:47:31 -0700395 pthread_mutex_unlock(&gInitMutex);
Jason Sams9e4e13d2009-10-06 17:16:55 -0700396 return;
397 }
Jason Samse5769102009-06-19 16:03:18 -0700398 }
Jason Samsfb03a222009-10-15 16:47:31 -0700399 gThreadTLSKeyCount++;
400 pthread_mutex_unlock(&gInitMutex);
401
402 // Global init done at this point.
Jason Samse5769102009-06-19 16:03:18 -0700403
Jason Samsa658e902009-06-04 14:35:01 -0700404 status = pthread_attr_init(&threadAttr);
405 if (status) {
406 LOGE("Failed to init thread attribute.");
407 return;
408 }
409
Jason Sams613cad12009-11-12 15:10:25 -0800410 mWndSurface = NULL;
Jason Sams992a0b72009-06-23 12:22:47 -0700411
Jason Sams50869382009-08-18 17:07:09 -0700412 objDestroyOOBInit();
Jason Sams24371d92009-08-19 12:17:14 -0700413 timerInit();
Jason Samsa8919332009-09-24 15:42:52 -0700414 timerSet(RS_TIMER_INTERNAL);
Jason Sams50869382009-08-18 17:07:09 -0700415
Jason Sams992a0b72009-06-23 12:22:47 -0700416 LOGV("RS Launching thread");
Jason Samsa658e902009-06-04 14:35:01 -0700417 status = pthread_create(&mThreadId, &threadAttr, threadProc, this);
Jason Sams326e0dd2009-05-22 14:03:28 -0700418 if (status) {
419 LOGE("Failed to start rs context thread.");
420 }
421
Jason Sams326e0dd2009-05-22 14:03:28 -0700422 while(!mRunning) {
Jason Samsada7f272009-09-24 14:55:38 -0700423 usleep(100);
Jason Sams326e0dd2009-05-22 14:03:28 -0700424 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700425
Jason Samsa658e902009-06-04 14:35:01 -0700426 pthread_attr_destroy(&threadAttr);
Jason Sams326e0dd2009-05-22 14:03:28 -0700427}
428
429Context::~Context()
430{
Jason Sams8c0ee652009-08-25 14:49:07 -0700431 LOGV("Context::~Context");
Jason Sams326e0dd2009-05-22 14:03:28 -0700432 mExit = true;
Jason Sams86f1b232009-09-24 17:38:20 -0700433 mPaused = false;
Jason Sams326e0dd2009-05-22 14:03:28 -0700434 void *res;
435
Jason Sams8c0ee652009-08-25 14:49:07 -0700436 mIO.shutdown();
Jason Sams326e0dd2009-05-22 14:03:28 -0700437 int status = pthread_join(mThreadId, &res);
Jason Samsbf3c14e2009-11-02 14:25:10 -0800438 mObjDestroy.mNeedToEmpty = true;
Jason Sams50869382009-08-18 17:07:09 -0700439 objDestroyOOBRun();
Jason Sams326e0dd2009-05-22 14:03:28 -0700440
Jason Samsfb03a222009-10-15 16:47:31 -0700441 // Global structure cleanup.
442 pthread_mutex_lock(&gInitMutex);
Jason Sams326e0dd2009-05-22 14:03:28 -0700443 if (mDev) {
444 mDev->removeContext(this);
Jason Samsfb03a222009-10-15 16:47:31 -0700445 --gThreadTLSKeyCount;
446 if (!gThreadTLSKeyCount) {
447 pthread_key_delete(gThreadTLSKey);
448 }
Jason Samsbf3c14e2009-11-02 14:25:10 -0800449 mDev = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700450 }
Jason Samsfb03a222009-10-15 16:47:31 -0700451 pthread_mutex_unlock(&gInitMutex);
Jason Sams50869382009-08-18 17:07:09 -0700452
453 objDestroyOOBDestroy();
Jason Sams326e0dd2009-05-22 14:03:28 -0700454}
455
Jason Sams613cad12009-11-12 15:10:25 -0800456void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
Jason Sams458f2dc2009-11-03 13:58:36 -0800457{
Jason Sams613cad12009-11-12 15:10:25 -0800458 LOGV("setSurface %i %i %p", w, h, sur);
459
Jason Sams458f2dc2009-11-03 13:58:36 -0800460 EGLBoolean ret;
461 if (mEGL.mSurface != NULL) {
462 ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
463 checkEglError("eglMakeCurrent", ret);
464
465 ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface);
466 checkEglError("eglDestroySurface", ret);
467
468 mEGL.mSurface = NULL;
Jason Sams613cad12009-11-12 15:10:25 -0800469 mEGL.mWidth = 0;
470 mEGL.mHeight = 0;
471 mWidth = 0;
472 mHeight = 0;
Jason Sams458f2dc2009-11-03 13:58:36 -0800473 }
474
475 mWndSurface = sur;
476 if (mWndSurface != NULL) {
Jason Sams613cad12009-11-12 15:10:25 -0800477 bool first = false;
478 if (!mEGL.mContext) {
479 first = true;
480 pthread_mutex_lock(&gInitMutex);
Jason Samsf2a5d732009-11-30 14:49:55 -0800481 initEGL(true);
Jason Sams613cad12009-11-12 15:10:25 -0800482 pthread_mutex_unlock(&gInitMutex);
483 }
484
Jason Sams458f2dc2009-11-03 13:58:36 -0800485 mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
486 checkEglError("eglCreateWindowSurface");
487 if (mEGL.mSurface == EGL_NO_SURFACE) {
488 LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
489 }
490
491 ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
492 checkEglError("eglMakeCurrent", ret);
Jason Sams613cad12009-11-12 15:10:25 -0800493
494 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
495 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
496 mWidth = w;
497 mHeight = h;
Jason Samse18844a2009-11-12 16:09:45 -0800498 mStateVertex.updateSize(this, w, h);
Jason Sams613cad12009-11-12 15:10:25 -0800499
500 if ((int)mWidth != mEGL.mWidth || (int)mHeight != mEGL.mHeight) {
501 LOGE("EGL/Surface mismatch EGL (%i x %i) SF (%i x %i)", mEGL.mWidth, mEGL.mHeight, mWidth, mHeight);
502 }
503
504 if (first) {
505 mGL.mVersion = glGetString(GL_VERSION);
506 mGL.mVendor = glGetString(GL_VENDOR);
507 mGL.mRenderer = glGetString(GL_RENDERER);
508 mGL.mExtensions = glGetString(GL_EXTENSIONS);
509
510 //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
511 LOGV("GL Version %s", mGL.mVersion);
Jason Samsc460e552009-11-25 13:22:07 -0800512 //LOGV("GL Vendor %s", mGL.mVendor);
Jason Sams613cad12009-11-12 15:10:25 -0800513 LOGV("GL Renderer %s", mGL.mRenderer);
514 //LOGV("GL Extensions %s", mGL.mExtensions);
515
Jason Samsc460e552009-11-25 13:22:07 -0800516 const char *verptr = NULL;
517 if (strlen((const char *)mGL.mVersion) > 9) {
518 if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
519 verptr = (const char *)mGL.mVersion + 12;
520 }
521 if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) {
522 verptr = (const char *)mGL.mVersion + 9;
523 }
524 }
525
526 if (!verptr) {
Jason Sams613cad12009-11-12 15:10:25 -0800527 LOGE("Error, OpenGL ES Lite not supported");
528 } else {
Jason Samsc460e552009-11-25 13:22:07 -0800529 sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
Jason Sams613cad12009-11-12 15:10:25 -0800530 }
Jason Sams4815c0d2009-12-15 12:58:36 -0800531
532 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs);
533 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors);
534 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits);
535
536 glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors);
537 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits);
538
539 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits);
540 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors);
Jason Sams613cad12009-11-12 15:10:25 -0800541 }
542
Jason Sams458f2dc2009-11-03 13:58:36 -0800543 }
544}
545
Jason Sams86f1b232009-09-24 17:38:20 -0700546void Context::pause()
547{
548 mPaused = true;
549}
550
551void Context::resume()
552{
553 mPaused = false;
554}
555
Jason Sams326e0dd2009-05-22 14:03:28 -0700556void Context::setRootScript(Script *s)
557{
558 mRootScript.set(s);
559}
560
561void Context::setFragmentStore(ProgramFragmentStore *pfs)
562{
Jason Sams8ce125b2009-06-17 16:52:59 -0700563 if (pfs == NULL) {
564 mFragmentStore.set(mStateFragmentStore.mDefault);
565 } else {
566 mFragmentStore.set(pfs);
567 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700568}
569
570void Context::setFragment(ProgramFragment *pf)
571{
Jason Sams8ce125b2009-06-17 16:52:59 -0700572 if (pf == NULL) {
573 mFragment.set(mStateFragment.mDefault);
574 } else {
575 mFragment.set(pf);
576 }
Jason Samscfb1d112009-08-05 13:57:03 -0700577}
578
Jason Sams5fd09d82009-09-23 13:57:02 -0700579void Context::setRaster(ProgramRaster *pr)
580{
581 if (pr == NULL) {
582 mRaster.set(mStateRaster.mDefault);
583 } else {
584 mRaster.set(pr);
585 }
586}
587
Jason Sams326e0dd2009-05-22 14:03:28 -0700588void Context::setVertex(ProgramVertex *pv)
589{
Jason Sams8ce125b2009-06-17 16:52:59 -0700590 if (pv == NULL) {
591 mVertex.set(mStateVertex.mDefault);
592 } else {
593 mVertex.set(pv);
594 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700595}
596
Jason Samsa4a54e42009-06-10 18:39:40 -0700597void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700598{
599 rsAssert(!obj->getName());
Jason Samsa4a54e42009-06-10 18:39:40 -0700600 obj->setName(name, len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700601 mNames.add(obj);
602}
603
604void Context::removeName(ObjectBase *obj)
605{
606 for(size_t ct=0; ct < mNames.size(); ct++) {
607 if (obj == mNames[ct]) {
608 mNames.removeAt(ct);
609 return;
610 }
611 }
612}
613
614ObjectBase * Context::lookupName(const char *name) const
615{
616 for(size_t ct=0; ct < mNames.size(); ct++) {
617 if (!strcmp(name, mNames[ct]->getName())) {
618 return mNames[ct];
619 }
620 }
621 return NULL;
622}
623
Jason Samsa4a54e42009-06-10 18:39:40 -0700624void Context::appendNameDefines(String8 *str) const
625{
626 char buf[256];
627 for (size_t ct=0; ct < mNames.size(); ct++) {
628 str->append("#define NAMED_");
629 str->append(mNames[ct]->getName());
630 str->append(" ");
631 sprintf(buf, "%i\n", (int)mNames[ct]);
632 str->append(buf);
633 }
634}
635
Joe Onorato57b79ce2009-08-09 22:57:44 -0700636void Context::appendVarDefines(String8 *str) const
637{
638 char buf[256];
639 for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
640 str->append("#define ");
641 str->append(mInt32Defines.keyAt(ct));
642 str->append(" ");
643 sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
644 str->append(buf);
645
646 }
647 for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
648 str->append("#define ");
649 str->append(mFloatDefines.keyAt(ct));
650 str->append(" ");
651 sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
652 str->append(buf);
653 }
654}
655
Jason Sams50869382009-08-18 17:07:09 -0700656bool Context::objDestroyOOBInit()
657{
658 int status = pthread_mutex_init(&mObjDestroy.mMutex, NULL);
659 if (status) {
660 LOGE("Context::ObjDestroyOOBInit mutex init failure");
661 return false;
662 }
663 return true;
664}
665
666void Context::objDestroyOOBRun()
667{
668 if (mObjDestroy.mNeedToEmpty) {
669 int status = pthread_mutex_lock(&mObjDestroy.mMutex);
670 if (status) {
671 LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
672 return;
673 }
674
675 for (size_t ct = 0; ct < mObjDestroy.mDestroyList.size(); ct++) {
Jason Sams9397e302009-08-27 20:23:34 -0700676 mObjDestroy.mDestroyList[ct]->decUserRef();
Jason Sams50869382009-08-18 17:07:09 -0700677 }
678 mObjDestroy.mDestroyList.clear();
679 mObjDestroy.mNeedToEmpty = false;
680
681 status = pthread_mutex_unlock(&mObjDestroy.mMutex);
682 if (status) {
683 LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
684 }
685 }
686}
687
688void Context::objDestroyOOBDestroy()
689{
690 rsAssert(!mObjDestroy.mNeedToEmpty);
691 pthread_mutex_destroy(&mObjDestroy.mMutex);
692}
693
694void Context::objDestroyAdd(ObjectBase *obj)
695{
696 int status = pthread_mutex_lock(&mObjDestroy.mMutex);
697 if (status) {
698 LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
699 return;
700 }
701
702 mObjDestroy.mNeedToEmpty = true;
703 mObjDestroy.mDestroyList.add(obj);
704
705 status = pthread_mutex_unlock(&mObjDestroy.mMutex);
706 if (status) {
707 LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
708 }
709}
710
Jason Sams8c401ef2009-10-06 13:58:47 -0700711uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait)
712{
713 //LOGE("getMessageToClient %i %i", bufferLen, wait);
714 if (!wait) {
715 if (mIO.mToClient.isEmpty()) {
716 // No message to get and not going to wait for one.
717 receiveLen = 0;
718 return 0;
719 }
720 }
721
722 //LOGE("getMessageToClient 2 con=%p", this);
723 uint32_t bytesData = 0;
724 uint32_t commandID = 0;
725 const void *d = mIO.mToClient.get(&commandID, &bytesData);
726 //LOGE("getMessageToClient 3 %i %i", commandID, bytesData);
727
728 *receiveLen = bytesData;
729 if (bufferLen >= bytesData) {
730 memcpy(data, d, bytesData);
731 mIO.mToClient.next();
732 return commandID;
733 }
734 return 0;
735}
736
737bool Context::sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace)
738{
739 //LOGE("sendMessageToClient %i %i %i", cmdID, len, waitForSpace);
740 if (cmdID == 0) {
741 LOGE("Attempting to send invalid command 0 to client.");
742 return false;
743 }
744 if (!waitForSpace) {
745 if (mIO.mToClient.getFreeSpace() < len) {
746 // Not enough room, and not waiting.
747 return false;
748 }
749 }
750 //LOGE("sendMessageToClient 2");
751 void *p = mIO.mToClient.reserve(len);
752 memcpy(p, data, len);
753 mIO.mToClient.commit(cmdID, len);
754 //LOGE("sendMessageToClient 3");
755 return true;
756}
757
758void Context::initToClient()
759{
760 while(!mRunning) {
761 usleep(100);
762 }
763}
764
765void Context::deinitToClient()
766{
767 mIO.mToClient.shutdown();
768}
Jason Sams50869382009-08-18 17:07:09 -0700769
Jason Sams13e26342009-11-24 12:26:35 -0800770void Context::dumpDebug() const
771{
772 LOGE("RS Context debug %p", this);
773 LOGE("RS Context debug");
774
775 LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
776 LOGE(" EGL context %p surface %p, w=%i h=%i Display=%p", mEGL.mContext,
777 mEGL.mSurface, mEGL.mWidth, mEGL.mHeight, mEGL.mDisplay);
778 LOGE(" GL vendor: %s", mGL.mVendor);
779 LOGE(" GL renderer: %s", mGL.mRenderer);
780 LOGE(" GL Version: %s", mGL.mVersion);
781 LOGE(" GL Extensions: %s", mGL.mExtensions);
782 LOGE(" GL int Versions %i %i", mGL.mMajorVersion, mGL.mMinorVersion);
783 LOGE(" RS width %i, height %i", mWidth, mHeight);
784 LOGE(" RS running %i, exit %i, useDepth %i, paused %i", mRunning, mExit, mUseDepth, mPaused);
785 LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
786
Jason Sams4815c0d2009-12-15 12:58:36 -0800787 LOGV("MAX Textures %i, %i %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits);
788 LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs);
789 LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors);
790 LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors);
Jason Sams13e26342009-11-24 12:26:35 -0800791}
Jason Samsa4a54e42009-06-10 18:39:40 -0700792
Jason Sams326e0dd2009-05-22 14:03:28 -0700793///////////////////////////////////////////////////////////////////////////////////////////
Jason Samsa44cb292009-06-04 17:58:03 -0700794//
Jason Sams326e0dd2009-05-22 14:03:28 -0700795
796namespace android {
797namespace renderscript {
798
799
800void rsi_ContextBindRootScript(Context *rsc, RsScript vs)
801{
802 Script *s = static_cast<Script *>(vs);
803 rsc->setRootScript(s);
804}
805
806void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs)
807{
808 Sampler *s = static_cast<Sampler *>(vs);
809
810 if (slot > RS_MAX_SAMPLER_SLOT) {
811 LOGE("Invalid sampler slot");
812 return;
813 }
814
815 s->bindToContext(&rsc->mStateSampler, slot);
816}
817
818void rsi_ContextBindProgramFragmentStore(Context *rsc, RsProgramFragmentStore vpfs)
819{
820 ProgramFragmentStore *pfs = static_cast<ProgramFragmentStore *>(vpfs);
821 rsc->setFragmentStore(pfs);
822}
823
824void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf)
825{
826 ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
827 rsc->setFragment(pf);
828}
829
Jason Sams5fd09d82009-09-23 13:57:02 -0700830void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr)
831{
832 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
833 rsc->setRaster(pr);
834}
835
Jason Sams326e0dd2009-05-22 14:03:28 -0700836void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv)
837{
838 ProgramVertex *pv = static_cast<ProgramVertex *>(vpv);
839 rsc->setVertex(pv);
840}
841
Jason Samsa4a54e42009-06-10 18:39:40 -0700842void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len)
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700843{
844 ObjectBase *ob = static_cast<ObjectBase *>(obj);
Jason Samsa4a54e42009-06-10 18:39:40 -0700845 rsc->assignName(ob, name, len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700846}
Jason Sams326e0dd2009-05-22 14:03:28 -0700847
Jason Sams707aaf32009-08-18 14:14:24 -0700848void rsi_ObjDestroy(Context *rsc, void *obj)
849{
850 ObjectBase *ob = static_cast<ObjectBase *>(obj);
851 rsc->removeName(ob);
Jason Sams9397e302009-08-27 20:23:34 -0700852 ob->decUserRef();
Jason Sams707aaf32009-08-18 14:14:24 -0700853}
854
Joe Onorato57b79ce2009-08-09 22:57:44 -0700855void rsi_ContextSetDefineF(Context *rsc, const char* name, float value)
856{
857 rsc->addInt32Define(name, value);
858}
859
860void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value)
861{
862 rsc->addFloatDefine(name, value);
863}
Jason Sams326e0dd2009-05-22 14:03:28 -0700864
Jason Sams86f1b232009-09-24 17:38:20 -0700865void rsi_ContextPause(Context *rsc)
866{
867 rsc->pause();
868}
869
870void rsi_ContextResume(Context *rsc)
871{
872 rsc->resume();
873}
874
Jason Sams613cad12009-11-12 15:10:25 -0800875void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, void *sur)
Jason Sams458f2dc2009-11-03 13:58:36 -0800876{
Jason Sams613cad12009-11-12 15:10:25 -0800877 rsc->setSurface(w, h, (Surface *)sur);
878}
879
Jason Sams15832442009-11-15 12:14:26 -0800880void rsi_ContextSetPriority(Context *rsc, int32_t p)
Jason Sams613cad12009-11-12 15:10:25 -0800881{
Jason Sams15832442009-11-15 12:14:26 -0800882 rsc->setPriority(p);
Jason Sams458f2dc2009-11-03 13:58:36 -0800883}
884
Jason Samsc21cf402009-11-17 17:26:46 -0800885void rsi_ContextDump(Context *rsc, int32_t bits)
886{
887 ObjectBase::dumpAll(rsc);
888}
889
Jason Sams326e0dd2009-05-22 14:03:28 -0700890}
891}
892
893
Jason Sams613cad12009-11-12 15:10:25 -0800894RsContext rsContextCreate(RsDevice vdev, uint32_t version, bool useDepth)
Jason Sams326e0dd2009-05-22 14:03:28 -0700895{
896 Device * dev = static_cast<Device *>(vdev);
Jason Sams613cad12009-11-12 15:10:25 -0800897 Context *rsc = new Context(dev, useDepth);
Jason Sams326e0dd2009-05-22 14:03:28 -0700898 return rsc;
899}
900
901void rsContextDestroy(RsContext vrsc)
902{
903 Context * rsc = static_cast<Context *>(vrsc);
904 delete rsc;
905}
906
Jason Sams50869382009-08-18 17:07:09 -0700907void rsObjDestroyOOB(RsContext vrsc, void *obj)
908{
909 Context * rsc = static_cast<Context *>(vrsc);
910 rsc->objDestroyAdd(static_cast<ObjectBase *>(obj));
911}
912
Jason Sams8c401ef2009-10-06 13:58:47 -0700913uint32_t rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, size_t bufferLen, bool wait)
914{
915 Context * rsc = static_cast<Context *>(vrsc);
916 return rsc->getMessageToClient(data, receiveLen, bufferLen, wait);
917}
918
919void rsContextInitToClient(RsContext vrsc)
920{
921 Context * rsc = static_cast<Context *>(vrsc);
922 rsc->initToClient();
923}
924
925void rsContextDeinitToClient(RsContext vrsc)
926{
927 Context * rsc = static_cast<Context *>(vrsc);
928 rsc->deinitToClient();
929}
930