blob: e94aece2ed59ca64547ca33eb2a4753f5287bf73 [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>
Mathias Agopian9b97c292010-02-12 12:00:38 -080022#include <ui/egl/android_natives.h>
Jason Sams326e0dd2009-05-22 14:03:28 -070023
Jason Sams15832442009-11-15 12:14:26 -080024#include <sys/types.h>
25#include <sys/resource.h>
26
Joe Onorato76371ff2009-09-23 16:37:36 -070027#include <cutils/properties.h>
28
Jason Sams1aa5a4e2009-06-22 17:15:15 -070029#include <GLES/gl.h>
30#include <GLES/glext.h>
Jason Sams4815c0d2009-12-15 12:58:36 -080031#include <GLES2/gl2.h>
32#include <GLES2/gl2ext.h>
Jason Sams1aa5a4e2009-06-22 17:15:15 -070033
Jason Sams15832442009-11-15 12:14:26 -080034#include <cutils/sched_policy.h>
35
Jason Sams326e0dd2009-05-22 14:03:28 -070036using namespace android;
37using namespace android::renderscript;
38
Jason Samse5769102009-06-19 16:03:18 -070039pthread_key_t Context::gThreadTLSKey = 0;
Jason Samsfb03a222009-10-15 16:47:31 -070040uint32_t Context::gThreadTLSKeyCount = 0;
Jason Sams33b6e3b2009-10-27 14:44:31 -070041uint32_t Context::gGLContextCount = 0;
Jason Samsfb03a222009-10-15 16:47:31 -070042pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
Jason Sams326e0dd2009-05-22 14:03:28 -070043
Jason Sams33b6e3b2009-10-27 14:44:31 -070044static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
45 if (returnVal != EGL_TRUE) {
46 fprintf(stderr, "%s() returned %d\n", op, returnVal);
47 }
48
49 for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
50 = eglGetError()) {
51 fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error),
52 error);
53 }
54}
55
Jason Samsc460e552009-11-25 13:22:07 -080056void Context::initEGL(bool useGL2)
Jason Sams326e0dd2009-05-22 14:03:28 -070057{
Jason Samsafcb25c2009-08-25 11:34:49 -070058 mEGL.mNumConfigs = -1;
59 EGLint configAttribs[128];
60 EGLint *configAttribsPtr = configAttribs;
Jason Samsc460e552009-11-25 13:22:07 -080061 EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
Jason Sams326e0dd2009-05-22 14:03:28 -070062
Jason Samsafcb25c2009-08-25 11:34:49 -070063 memset(configAttribs, 0, sizeof(configAttribs));
Jason Sams326e0dd2009-05-22 14:03:28 -070064
Jason Samsafcb25c2009-08-25 11:34:49 -070065 configAttribsPtr[0] = EGL_SURFACE_TYPE;
66 configAttribsPtr[1] = EGL_WINDOW_BIT;
67 configAttribsPtr += 2;
Jason Sams326e0dd2009-05-22 14:03:28 -070068
Jason Samsc460e552009-11-25 13:22:07 -080069 if (useGL2) {
70 configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
71 configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
72 configAttribsPtr += 2;
73 }
74
Jason Samsafcb25c2009-08-25 11:34:49 -070075 if (mUseDepth) {
76 configAttribsPtr[0] = EGL_DEPTH_SIZE;
77 configAttribsPtr[1] = 16;
78 configAttribsPtr += 2;
79 }
Jason Sams9397e302009-08-27 20:23:34 -070080
Jason Sams5fd09d82009-09-23 13:57:02 -070081 if (mDev->mForceSW) {
82 configAttribsPtr[0] = EGL_CONFIG_CAVEAT;
83 configAttribsPtr[1] = EGL_SLOW_CONFIG;
84 configAttribsPtr += 2;
85 }
86
Jason Samsafcb25c2009-08-25 11:34:49 -070087 configAttribsPtr[0] = EGL_NONE;
88 rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
Jason Sams326e0dd2009-05-22 14:03:28 -070089
Jason Sams6d751ef2009-10-08 12:55:06 -070090 LOGV("initEGL start");
Jason Samsafcb25c2009-08-25 11:34:49 -070091 mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Jason Sams33b6e3b2009-10-27 14:44:31 -070092 checkEglError("eglGetDisplay");
93
Jason Samsafcb25c2009-08-25 11:34:49 -070094 eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion);
Jason Sams33b6e3b2009-10-27 14:44:31 -070095 checkEglError("eglInitialize");
Jason Samsafcb25c2009-08-25 11:34:49 -070096
97 status_t err = EGLUtils::selectConfigForNativeWindow(mEGL.mDisplay, configAttribs, mWndSurface, &mEGL.mConfig);
98 if (err) {
Jason Sams9397e302009-08-27 20:23:34 -070099 LOGE("couldn't find an EGLConfig matching the screen format\n");
Jason Samsafcb25c2009-08-25 11:34:49 -0700100 }
101 //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
102
Jason Samsafcb25c2009-08-25 11:34:49 -0700103
Jason Samsc460e552009-11-25 13:22:07 -0800104 if (useGL2) {
105 mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
106 } else {
107 mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
108 }
Jason Sams33b6e3b2009-10-27 14:44:31 -0700109 checkEglError("eglCreateContext");
110 if (mEGL.mContext == EGL_NO_CONTEXT) {
111 LOGE("eglCreateContext returned EGL_NO_CONTEXT");
112 }
113 gGLContextCount++;
Jason Sams326e0dd2009-05-22 14:03:28 -0700114}
115
Jason Sams33b6e3b2009-10-27 14:44:31 -0700116void Context::deinitEGL()
117{
Jason Sams613cad12009-11-12 15:10:25 -0800118 LOGV("deinitEGL");
119 setSurface(0, 0, NULL);
Jason Sams33b6e3b2009-10-27 14:44:31 -0700120 eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
121 checkEglError("eglDestroyContext");
122
123 gGLContextCount--;
124 if (!gGLContextCount) {
125 eglTerminate(mEGL.mDisplay);
126 }
127}
128
129
Jason Sams2dca84d2009-12-09 11:05:45 -0800130uint32_t Context::runScript(Script *s, uint32_t launchID)
Jason Sams10308932009-06-09 12:15:30 -0700131{
132 ObjectBaseRef<ProgramFragment> frag(mFragment);
133 ObjectBaseRef<ProgramVertex> vtx(mVertex);
134 ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
Jason Samsb681c8a2009-09-28 18:12:56 -0700135 ObjectBaseRef<ProgramRaster> raster(mRaster);
Jason Sams10308932009-06-09 12:15:30 -0700136
Jason Sams2dca84d2009-12-09 11:05:45 -0800137 uint32_t ret = s->run(this, launchID);
Jason Sams10308932009-06-09 12:15:30 -0700138
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700139 mFragment.set(frag);
140 mVertex.set(vtx);
141 mFragmentStore.set(store);
Jason Samsb681c8a2009-09-28 18:12:56 -0700142 mRaster.set(raster);
Jason Samsc9d43db2009-07-28 12:02:16 -0700143 return ret;
Jason Sams10308932009-06-09 12:15:30 -0700144}
145
Jason Samsd01d9702009-12-23 14:35:29 -0800146void Context::checkError(const char *msg) const
147{
148 GLenum err = glGetError();
149 if (err != GL_NO_ERROR) {
150 LOGE("GL Error, 0x%x, from %s", err, msg);
151 }
152}
Jason Sams10308932009-06-09 12:15:30 -0700153
Jason Sams2dca84d2009-12-09 11:05:45 -0800154uint32_t Context::runRootScript()
Jason Sams326e0dd2009-05-22 14:03:28 -0700155{
Jason Sams2dca84d2009-12-09 11:05:45 -0800156 timerSet(RS_TIMER_CLEAR_SWAP);
Jason Sams10308932009-06-09 12:15:30 -0700157 rsAssert(mRootScript->mEnviroment.mIsRoot);
Jason Sams326e0dd2009-05-22 14:03:28 -0700158
Jason Sams8c9534b2009-09-22 12:26:53 -0700159 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
160 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
Jason Samsafcb25c2009-08-25 11:34:49 -0700161 glViewport(0, 0, mEGL.mWidth, mEGL.mHeight);
Jason Sams326e0dd2009-05-22 14:03:28 -0700162 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
163
Jason Sams928b7342009-06-08 18:50:13 -0700164 glClearColor(mRootScript->mEnviroment.mClearColor[0],
165 mRootScript->mEnviroment.mClearColor[1],
166 mRootScript->mEnviroment.mClearColor[2],
167 mRootScript->mEnviroment.mClearColor[3]);
Jason Samsafcb25c2009-08-25 11:34:49 -0700168 if (mUseDepth) {
169 glDepthMask(GL_TRUE);
170 glClearDepthf(mRootScript->mEnviroment.mClearDepth);
171 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
172 } else {
173 glClear(GL_COLOR_BUFFER_BIT);
174 }
Jason Sams306fb232009-08-25 17:09:59 -0700175
Jason Sams2dca84d2009-12-09 11:05:45 -0800176 timerSet(RS_TIMER_SCRIPT);
Jason Sams8c401ef2009-10-06 13:58:47 -0700177 mStateFragmentStore.mLast.clear();
Jason Sams2dca84d2009-12-09 11:05:45 -0800178 uint32_t ret = runScript(mRootScript.get(), 0);
Jason Sams8cfdd242009-10-14 15:43:53 -0700179
Jason Samsd01d9702009-12-23 14:35:29 -0800180 checkError("runRootScript");
Jason Samscfb1d112009-08-05 13:57:03 -0700181 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700182}
183
Jason Sams24371d92009-08-19 12:17:14 -0700184uint64_t Context::getTime() const
185{
186 struct timespec t;
187 clock_gettime(CLOCK_MONOTONIC, &t);
188 return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000);
189}
190
191void Context::timerReset()
192{
193 for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) {
194 mTimers[ct] = 0;
195 }
196}
197
198void Context::timerInit()
199{
200 mTimeLast = getTime();
Jason Sams1d54f102009-09-03 15:43:13 -0700201 mTimeFrame = mTimeLast;
202 mTimeLastFrame = mTimeLast;
Jason Sams24371d92009-08-19 12:17:14 -0700203 mTimerActive = RS_TIMER_INTERNAL;
204 timerReset();
205}
206
Jason Sams1d54f102009-09-03 15:43:13 -0700207void Context::timerFrame()
208{
209 mTimeLastFrame = mTimeFrame;
210 mTimeFrame = getTime();
211}
212
Jason Sams24371d92009-08-19 12:17:14 -0700213void Context::timerSet(Timers tm)
214{
215 uint64_t last = mTimeLast;
216 mTimeLast = getTime();
217 mTimers[mTimerActive] += mTimeLast - last;
218 mTimerActive = tm;
219}
220
221void Context::timerPrint()
222{
223 double total = 0;
224 for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) {
225 total += mTimers[ct];
226 }
Jason Sams1d54f102009-09-03 15:43:13 -0700227 uint64_t frame = mTimeFrame - mTimeLastFrame;
Jason Sams2dca84d2009-12-09 11:05:45 -0800228 mTimeMSLastFrame = frame / 1000000;
229 mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000;
230 mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000;
Jason Sams24371d92009-08-19 12:17:14 -0700231
Jason Sams2dca84d2009-12-09 11:05:45 -0800232
233 if (props.mLogTimes) {
234 LOGV("RS: Frame (%i), Script %2.1f (%i), Clear & Swap %2.1f (%i), Idle %2.1f (%lli), Internal %2.1f (%lli)",
235 mTimeMSLastFrame,
236 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
237 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
238 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
239 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
240 }
Jason Sams24371d92009-08-19 12:17:14 -0700241}
242
Jason Sams326e0dd2009-05-22 14:03:28 -0700243void Context::setupCheck()
244{
Jason Samsc460e552009-11-25 13:22:07 -0800245 if (checkVersion2_0()) {
Jason Samscd506532009-12-15 19:10:11 -0800246 mShaderCache.lookup(this, mVertex.get(), mFragment.get());
Jason Samsc460e552009-11-25 13:22:07 -0800247
248 mFragmentStore->setupGL2(this, &mStateFragmentStore);
249 mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
250 mRaster->setupGL2(this, &mStateRaster);
251 mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
252
253 } else {
254 mFragmentStore->setupGL(this, &mStateFragmentStore);
255 mFragment->setupGL(this, &mStateFragment);
256 mRaster->setupGL(this, &mStateRaster);
257 mVertex->setupGL(this, &mStateVertex);
258 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700259}
260
Jason Sams1fddd902009-09-25 15:25:00 -0700261static bool getProp(const char *str)
Joe Onorato76371ff2009-09-23 16:37:36 -0700262{
263 char buf[PROPERTY_VALUE_MAX];
Jason Sams1fddd902009-09-25 15:25:00 -0700264 property_get(str, buf, "0");
Joe Onorato76371ff2009-09-23 16:37:36 -0700265 return 0 != strcmp(buf, "0");
266}
Jason Sams326e0dd2009-05-22 14:03:28 -0700267
268void * Context::threadProc(void *vrsc)
269{
270 Context *rsc = static_cast<Context *>(vrsc);
Jason Sams15832442009-11-15 12:14:26 -0800271 rsc->mNativeThreadId = gettid();
272
273 setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
Jason Sams2dca84d2009-12-09 11:05:45 -0800274 rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
Jason Sams326e0dd2009-05-22 14:03:28 -0700275
Jason Sams1fddd902009-09-25 15:25:00 -0700276 rsc->props.mLogTimes = getProp("debug.rs.profile");
277 rsc->props.mLogScripts = getProp("debug.rs.script");
Jason Sams433eca32010-01-06 11:57:52 -0800278 rsc->props.mLogObjects = getProp("debug.rs.object");
279 rsc->props.mLogShaders = getProp("debug.rs.shader");
Joe Onorato76371ff2009-09-23 16:37:36 -0700280
Jason Samse5769102009-06-19 16:03:18 -0700281 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 Sams4820e8b2010-02-09 16:05:07 -0800293 if (rsc->mIsGraphicsContext) {
294 rsc->mStateRaster.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
295 rsc->setRaster(NULL);
296 rsc->mStateVertex.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
297 rsc->setVertex(NULL);
298 rsc->mStateFragment.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
299 rsc->setFragment(NULL);
300 rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
301 rsc->setFragmentStore(NULL);
302 rsc->mStateVertexArray.init(rsc);
303 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700304
Jason Sams326e0dd2009-05-22 14:03:28 -0700305 rsc->mRunning = true;
Jason Samsa44cb292009-06-04 17:58:03 -0700306 bool mDraw = true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700307 while (!rsc->mExit) {
Jason Samsfcd31922009-08-17 18:35:48 -0700308 mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw);
Jason Sams732f1c02009-06-18 16:58:42 -0700309 mDraw &= (rsc->mRootScript.get() != NULL);
Jason Sams458f2dc2009-11-03 13:58:36 -0800310 mDraw &= (rsc->mWndSurface != NULL);
Jason Sams326e0dd2009-05-22 14:03:28 -0700311
Jason Sams2dca84d2009-12-09 11:05:45 -0800312 uint32_t targetTime = 0;
Jason Sams4820e8b2010-02-09 16:05:07 -0800313 if (mDraw && rsc->mIsGraphicsContext) {
Jason Sams2dca84d2009-12-09 11:05:45 -0800314 targetTime = rsc->runRootScript();
315 mDraw = targetTime && !rsc->mPaused;
316 rsc->timerSet(RS_TIMER_CLEAR_SWAP);
Jason Samsafcb25c2009-08-25 11:34:49 -0700317 eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
Jason Sams2dca84d2009-12-09 11:05:45 -0800318 rsc->timerFrame();
319 rsc->timerSet(RS_TIMER_INTERNAL);
320 rsc->timerPrint();
321 rsc->timerReset();
Jason Sams326e0dd2009-05-22 14:03:28 -0700322 }
Jason Sams24371d92009-08-19 12:17:14 -0700323 if (rsc->mObjDestroy.mNeedToEmpty) {
324 rsc->objDestroyOOBRun();
325 }
Jason Sams2dca84d2009-12-09 11:05:45 -0800326 if (rsc->mThreadPriority > 0 && targetTime) {
327 int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000;
328 if (t > 0) {
329 usleep(t);
330 }
331 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700332 }
333
Jason Sams8c0ee652009-08-25 14:49:07 -0700334 LOGV("RS Thread exiting");
Jason Sams4820e8b2010-02-09 16:05:07 -0800335 if (rsc->mIsGraphicsContext) {
336 rsc->mRaster.clear();
337 rsc->mFragment.clear();
338 rsc->mVertex.clear();
339 rsc->mFragmentStore.clear();
340 rsc->mRootScript.clear();
341 rsc->mStateRaster.deinit(rsc);
342 rsc->mStateVertex.deinit(rsc);
343 rsc->mStateFragment.deinit(rsc);
344 rsc->mStateFragmentStore.deinit(rsc);
345 }
Jason Samse514b452009-09-25 14:51:22 -0700346 ObjectBase::zeroAllUserRef(rsc);
Jason Samse514b452009-09-25 14:51:22 -0700347
Jason Samse402ed32009-11-03 11:25:42 -0800348 rsc->mObjDestroy.mNeedToEmpty = true;
349 rsc->objDestroyOOBRun();
350
Jason Sams4820e8b2010-02-09 16:05:07 -0800351 if (rsc->mIsGraphicsContext) {
352 pthread_mutex_lock(&gInitMutex);
353 rsc->deinitEGL();
354 pthread_mutex_unlock(&gInitMutex);
355 }
Jason Sams33b6e3b2009-10-27 14:44:31 -0700356
Jason Sams8c0ee652009-08-25 14:49:07 -0700357 LOGV("RS Thread exited");
Jason Sams326e0dd2009-05-22 14:03:28 -0700358 return NULL;
359}
360
Jason Sams15832442009-11-15 12:14:26 -0800361void Context::setPriority(int32_t p)
362{
363 // Note: If we put this in the proper "background" policy
364 // the wallpapers can become completly unresponsive at times.
365 // This is probably not what we want for something the user is actively
366 // looking at.
Jason Sams2dca84d2009-12-09 11:05:45 -0800367 mThreadPriority = p;
Jason Sams15832442009-11-15 12:14:26 -0800368#if 0
369 SchedPolicy pol = SP_FOREGROUND;
370 if (p > 0) {
371 pol = SP_BACKGROUND;
372 }
373 if (!set_sched_policy(mNativeThreadId, pol)) {
374 // success; reset the priority as well
375 }
376#else
377 setpriority(PRIO_PROCESS, mNativeThreadId, p);
378#endif
379}
380
Jason Sams4820e8b2010-02-09 16:05:07 -0800381Context::Context(Device *dev, bool isGraphics, bool useDepth)
Jason Sams326e0dd2009-05-22 14:03:28 -0700382{
Jason Samsfb03a222009-10-15 16:47:31 -0700383 pthread_mutex_lock(&gInitMutex);
384
Jason Sams326e0dd2009-05-22 14:03:28 -0700385 dev->addContext(this);
386 mDev = dev;
387 mRunning = false;
388 mExit = false;
Jason Samsafcb25c2009-08-25 11:34:49 -0700389 mUseDepth = useDepth;
Jason Sams86f1b232009-09-24 17:38:20 -0700390 mPaused = false;
Jason Samse514b452009-09-25 14:51:22 -0700391 mObjHead = NULL;
Jason Sams613cad12009-11-12 15:10:25 -0800392 memset(&mEGL, 0, sizeof(mEGL));
Jason Sams4820e8b2010-02-09 16:05:07 -0800393 memset(&mGL, 0, sizeof(mGL));
394 mIsGraphicsContext = isGraphics;
Jason Sams326e0dd2009-05-22 14:03:28 -0700395
Jason Samsa658e902009-06-04 14:35:01 -0700396 int status;
397 pthread_attr_t threadAttr;
398
Jason Samsfb03a222009-10-15 16:47:31 -0700399 if (!gThreadTLSKeyCount) {
Jason Sams9e4e13d2009-10-06 17:16:55 -0700400 status = pthread_key_create(&gThreadTLSKey, NULL);
401 if (status) {
402 LOGE("Failed to init thread tls key.");
Jason Samsfb03a222009-10-15 16:47:31 -0700403 pthread_mutex_unlock(&gInitMutex);
Jason Sams9e4e13d2009-10-06 17:16:55 -0700404 return;
405 }
Jason Samse5769102009-06-19 16:03:18 -0700406 }
Jason Samsfb03a222009-10-15 16:47:31 -0700407 gThreadTLSKeyCount++;
408 pthread_mutex_unlock(&gInitMutex);
409
410 // Global init done at this point.
Jason Samse5769102009-06-19 16:03:18 -0700411
Jason Samsa658e902009-06-04 14:35:01 -0700412 status = pthread_attr_init(&threadAttr);
413 if (status) {
414 LOGE("Failed to init thread attribute.");
415 return;
416 }
417
Jason Sams613cad12009-11-12 15:10:25 -0800418 mWndSurface = NULL;
Jason Sams992a0b72009-06-23 12:22:47 -0700419
Jason Sams50869382009-08-18 17:07:09 -0700420 objDestroyOOBInit();
Jason Sams24371d92009-08-19 12:17:14 -0700421 timerInit();
Jason Samsa8919332009-09-24 15:42:52 -0700422 timerSet(RS_TIMER_INTERNAL);
Jason Sams50869382009-08-18 17:07:09 -0700423
Jason Sams992a0b72009-06-23 12:22:47 -0700424 LOGV("RS Launching thread");
Jason Samsa658e902009-06-04 14:35:01 -0700425 status = pthread_create(&mThreadId, &threadAttr, threadProc, this);
Jason Sams326e0dd2009-05-22 14:03:28 -0700426 if (status) {
427 LOGE("Failed to start rs context thread.");
428 }
429
Jason Sams326e0dd2009-05-22 14:03:28 -0700430 while(!mRunning) {
Jason Samsada7f272009-09-24 14:55:38 -0700431 usleep(100);
Jason Sams326e0dd2009-05-22 14:03:28 -0700432 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700433
Jason Samsa658e902009-06-04 14:35:01 -0700434 pthread_attr_destroy(&threadAttr);
Jason Sams326e0dd2009-05-22 14:03:28 -0700435}
436
437Context::~Context()
438{
Jason Sams8c0ee652009-08-25 14:49:07 -0700439 LOGV("Context::~Context");
Jason Sams326e0dd2009-05-22 14:03:28 -0700440 mExit = true;
Jason Sams86f1b232009-09-24 17:38:20 -0700441 mPaused = false;
Jason Sams326e0dd2009-05-22 14:03:28 -0700442 void *res;
443
Jason Sams8c0ee652009-08-25 14:49:07 -0700444 mIO.shutdown();
Jason Sams326e0dd2009-05-22 14:03:28 -0700445 int status = pthread_join(mThreadId, &res);
Jason Samsbf3c14e2009-11-02 14:25:10 -0800446 mObjDestroy.mNeedToEmpty = true;
Jason Sams50869382009-08-18 17:07:09 -0700447 objDestroyOOBRun();
Jason Sams326e0dd2009-05-22 14:03:28 -0700448
Jason Samsfb03a222009-10-15 16:47:31 -0700449 // Global structure cleanup.
450 pthread_mutex_lock(&gInitMutex);
Jason Sams326e0dd2009-05-22 14:03:28 -0700451 if (mDev) {
452 mDev->removeContext(this);
Jason Samsfb03a222009-10-15 16:47:31 -0700453 --gThreadTLSKeyCount;
454 if (!gThreadTLSKeyCount) {
455 pthread_key_delete(gThreadTLSKey);
456 }
Jason Samsbf3c14e2009-11-02 14:25:10 -0800457 mDev = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700458 }
Jason Samsfb03a222009-10-15 16:47:31 -0700459 pthread_mutex_unlock(&gInitMutex);
Jason Sams50869382009-08-18 17:07:09 -0700460
461 objDestroyOOBDestroy();
Jason Sams326e0dd2009-05-22 14:03:28 -0700462}
463
Mathias Agopian9b97c292010-02-12 12:00:38 -0800464void Context::setSurface(uint32_t w, uint32_t h, android_native_window_t *sur)
Jason Sams458f2dc2009-11-03 13:58:36 -0800465{
Jason Sams4820e8b2010-02-09 16:05:07 -0800466 rsAssert(mIsGraphicsContext);
Jason Sams613cad12009-11-12 15:10:25 -0800467
Jason Sams458f2dc2009-11-03 13:58:36 -0800468 EGLBoolean ret;
469 if (mEGL.mSurface != NULL) {
470 ret = eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
471 checkEglError("eglMakeCurrent", ret);
472
473 ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface);
474 checkEglError("eglDestroySurface", ret);
475
476 mEGL.mSurface = NULL;
Jason Sams613cad12009-11-12 15:10:25 -0800477 mEGL.mWidth = 0;
478 mEGL.mHeight = 0;
479 mWidth = 0;
480 mHeight = 0;
Jason Sams458f2dc2009-11-03 13:58:36 -0800481 }
482
483 mWndSurface = sur;
484 if (mWndSurface != NULL) {
Jason Sams613cad12009-11-12 15:10:25 -0800485 bool first = false;
486 if (!mEGL.mContext) {
487 first = true;
488 pthread_mutex_lock(&gInitMutex);
Jason Samsf2a5d732009-11-30 14:49:55 -0800489 initEGL(true);
Jason Sams613cad12009-11-12 15:10:25 -0800490 pthread_mutex_unlock(&gInitMutex);
491 }
492
Jason Sams458f2dc2009-11-03 13:58:36 -0800493 mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
494 checkEglError("eglCreateWindowSurface");
495 if (mEGL.mSurface == EGL_NO_SURFACE) {
496 LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
497 }
498
499 ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
500 checkEglError("eglMakeCurrent", ret);
Jason Sams613cad12009-11-12 15:10:25 -0800501
502 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
503 eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
504 mWidth = w;
505 mHeight = h;
Jason Samse18844a2009-11-12 16:09:45 -0800506 mStateVertex.updateSize(this, w, h);
Jason Sams613cad12009-11-12 15:10:25 -0800507
508 if ((int)mWidth != mEGL.mWidth || (int)mHeight != mEGL.mHeight) {
509 LOGE("EGL/Surface mismatch EGL (%i x %i) SF (%i x %i)", mEGL.mWidth, mEGL.mHeight, mWidth, mHeight);
510 }
511
512 if (first) {
513 mGL.mVersion = glGetString(GL_VERSION);
514 mGL.mVendor = glGetString(GL_VENDOR);
515 mGL.mRenderer = glGetString(GL_RENDERER);
516 mGL.mExtensions = glGetString(GL_EXTENSIONS);
517
518 //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
519 LOGV("GL Version %s", mGL.mVersion);
Jason Samsc460e552009-11-25 13:22:07 -0800520 //LOGV("GL Vendor %s", mGL.mVendor);
Jason Sams613cad12009-11-12 15:10:25 -0800521 LOGV("GL Renderer %s", mGL.mRenderer);
522 //LOGV("GL Extensions %s", mGL.mExtensions);
523
Jason Samsc460e552009-11-25 13:22:07 -0800524 const char *verptr = NULL;
525 if (strlen((const char *)mGL.mVersion) > 9) {
526 if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
527 verptr = (const char *)mGL.mVersion + 12;
528 }
529 if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) {
530 verptr = (const char *)mGL.mVersion + 9;
531 }
532 }
533
534 if (!verptr) {
Jason Sams613cad12009-11-12 15:10:25 -0800535 LOGE("Error, OpenGL ES Lite not supported");
536 } else {
Jason Samsc460e552009-11-25 13:22:07 -0800537 sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
Jason Sams613cad12009-11-12 15:10:25 -0800538 }
Jason Sams4815c0d2009-12-15 12:58:36 -0800539
540 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs);
541 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors);
542 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits);
543
544 glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors);
545 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits);
546
547 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits);
548 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors);
Jason Sams613cad12009-11-12 15:10:25 -0800549 }
550
Jason Sams458f2dc2009-11-03 13:58:36 -0800551 }
552}
553
Jason Sams86f1b232009-09-24 17:38:20 -0700554void Context::pause()
555{
Jason Sams4820e8b2010-02-09 16:05:07 -0800556 rsAssert(mIsGraphicsContext);
Jason Sams86f1b232009-09-24 17:38:20 -0700557 mPaused = true;
558}
559
560void Context::resume()
561{
Jason Sams4820e8b2010-02-09 16:05:07 -0800562 rsAssert(mIsGraphicsContext);
Jason Sams86f1b232009-09-24 17:38:20 -0700563 mPaused = false;
564}
565
Jason Sams326e0dd2009-05-22 14:03:28 -0700566void Context::setRootScript(Script *s)
567{
Jason Sams4820e8b2010-02-09 16:05:07 -0800568 rsAssert(mIsGraphicsContext);
Jason Sams326e0dd2009-05-22 14:03:28 -0700569 mRootScript.set(s);
570}
571
572void Context::setFragmentStore(ProgramFragmentStore *pfs)
573{
Jason Sams4820e8b2010-02-09 16:05:07 -0800574 rsAssert(mIsGraphicsContext);
Jason Sams8ce125b2009-06-17 16:52:59 -0700575 if (pfs == NULL) {
576 mFragmentStore.set(mStateFragmentStore.mDefault);
577 } else {
578 mFragmentStore.set(pfs);
579 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700580}
581
582void Context::setFragment(ProgramFragment *pf)
583{
Jason Sams4820e8b2010-02-09 16:05:07 -0800584 rsAssert(mIsGraphicsContext);
Jason Sams8ce125b2009-06-17 16:52:59 -0700585 if (pf == NULL) {
586 mFragment.set(mStateFragment.mDefault);
587 } else {
588 mFragment.set(pf);
589 }
Jason Samscfb1d112009-08-05 13:57:03 -0700590}
591
Jason Sams5fd09d82009-09-23 13:57:02 -0700592void Context::setRaster(ProgramRaster *pr)
593{
Jason Sams4820e8b2010-02-09 16:05:07 -0800594 rsAssert(mIsGraphicsContext);
Jason Sams5fd09d82009-09-23 13:57:02 -0700595 if (pr == NULL) {
596 mRaster.set(mStateRaster.mDefault);
597 } else {
598 mRaster.set(pr);
599 }
600}
601
Jason Sams326e0dd2009-05-22 14:03:28 -0700602void Context::setVertex(ProgramVertex *pv)
603{
Jason Sams4820e8b2010-02-09 16:05:07 -0800604 rsAssert(mIsGraphicsContext);
Jason Sams8ce125b2009-06-17 16:52:59 -0700605 if (pv == NULL) {
606 mVertex.set(mStateVertex.mDefault);
607 } else {
608 mVertex.set(pv);
609 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700610}
611
Jason Samsa4a54e42009-06-10 18:39:40 -0700612void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700613{
614 rsAssert(!obj->getName());
Jason Samsa4a54e42009-06-10 18:39:40 -0700615 obj->setName(name, len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700616 mNames.add(obj);
617}
618
619void Context::removeName(ObjectBase *obj)
620{
621 for(size_t ct=0; ct < mNames.size(); ct++) {
622 if (obj == mNames[ct]) {
623 mNames.removeAt(ct);
624 return;
625 }
626 }
627}
628
629ObjectBase * Context::lookupName(const char *name) const
630{
631 for(size_t ct=0; ct < mNames.size(); ct++) {
632 if (!strcmp(name, mNames[ct]->getName())) {
633 return mNames[ct];
634 }
635 }
636 return NULL;
637}
638
Jason Samsa4a54e42009-06-10 18:39:40 -0700639void Context::appendNameDefines(String8 *str) const
640{
641 char buf[256];
642 for (size_t ct=0; ct < mNames.size(); ct++) {
643 str->append("#define NAMED_");
644 str->append(mNames[ct]->getName());
645 str->append(" ");
646 sprintf(buf, "%i\n", (int)mNames[ct]);
647 str->append(buf);
648 }
649}
650
Jason Sams50869382009-08-18 17:07:09 -0700651bool Context::objDestroyOOBInit()
652{
653 int status = pthread_mutex_init(&mObjDestroy.mMutex, NULL);
654 if (status) {
655 LOGE("Context::ObjDestroyOOBInit mutex init failure");
656 return false;
657 }
658 return true;
659}
660
661void Context::objDestroyOOBRun()
662{
663 if (mObjDestroy.mNeedToEmpty) {
664 int status = pthread_mutex_lock(&mObjDestroy.mMutex);
665 if (status) {
666 LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
667 return;
668 }
669
670 for (size_t ct = 0; ct < mObjDestroy.mDestroyList.size(); ct++) {
Jason Sams9397e302009-08-27 20:23:34 -0700671 mObjDestroy.mDestroyList[ct]->decUserRef();
Jason Sams50869382009-08-18 17:07:09 -0700672 }
673 mObjDestroy.mDestroyList.clear();
674 mObjDestroy.mNeedToEmpty = false;
675
676 status = pthread_mutex_unlock(&mObjDestroy.mMutex);
677 if (status) {
678 LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
679 }
680 }
681}
682
683void Context::objDestroyOOBDestroy()
684{
685 rsAssert(!mObjDestroy.mNeedToEmpty);
686 pthread_mutex_destroy(&mObjDestroy.mMutex);
687}
688
689void Context::objDestroyAdd(ObjectBase *obj)
690{
691 int status = pthread_mutex_lock(&mObjDestroy.mMutex);
692 if (status) {
693 LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
694 return;
695 }
696
697 mObjDestroy.mNeedToEmpty = true;
698 mObjDestroy.mDestroyList.add(obj);
699
700 status = pthread_mutex_unlock(&mObjDestroy.mMutex);
701 if (status) {
702 LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
703 }
704}
705
Jason Sams8c401ef2009-10-06 13:58:47 -0700706uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait)
707{
708 //LOGE("getMessageToClient %i %i", bufferLen, wait);
709 if (!wait) {
710 if (mIO.mToClient.isEmpty()) {
711 // No message to get and not going to wait for one.
712 receiveLen = 0;
713 return 0;
714 }
715 }
716
717 //LOGE("getMessageToClient 2 con=%p", this);
718 uint32_t bytesData = 0;
719 uint32_t commandID = 0;
720 const void *d = mIO.mToClient.get(&commandID, &bytesData);
721 //LOGE("getMessageToClient 3 %i %i", commandID, bytesData);
722
723 *receiveLen = bytesData;
724 if (bufferLen >= bytesData) {
725 memcpy(data, d, bytesData);
726 mIO.mToClient.next();
727 return commandID;
728 }
729 return 0;
730}
731
732bool Context::sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace)
733{
734 //LOGE("sendMessageToClient %i %i %i", cmdID, len, waitForSpace);
735 if (cmdID == 0) {
736 LOGE("Attempting to send invalid command 0 to client.");
737 return false;
738 }
739 if (!waitForSpace) {
740 if (mIO.mToClient.getFreeSpace() < len) {
741 // Not enough room, and not waiting.
742 return false;
743 }
744 }
745 //LOGE("sendMessageToClient 2");
746 void *p = mIO.mToClient.reserve(len);
747 memcpy(p, data, len);
748 mIO.mToClient.commit(cmdID, len);
749 //LOGE("sendMessageToClient 3");
750 return true;
751}
752
753void Context::initToClient()
754{
755 while(!mRunning) {
756 usleep(100);
757 }
758}
759
760void Context::deinitToClient()
761{
762 mIO.mToClient.shutdown();
763}
Jason Sams50869382009-08-18 17:07:09 -0700764
Jason Sams13e26342009-11-24 12:26:35 -0800765void Context::dumpDebug() const
766{
767 LOGE("RS Context debug %p", this);
768 LOGE("RS Context debug");
769
770 LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
771 LOGE(" EGL context %p surface %p, w=%i h=%i Display=%p", mEGL.mContext,
772 mEGL.mSurface, mEGL.mWidth, mEGL.mHeight, mEGL.mDisplay);
773 LOGE(" GL vendor: %s", mGL.mVendor);
774 LOGE(" GL renderer: %s", mGL.mRenderer);
775 LOGE(" GL Version: %s", mGL.mVersion);
776 LOGE(" GL Extensions: %s", mGL.mExtensions);
777 LOGE(" GL int Versions %i %i", mGL.mMajorVersion, mGL.mMinorVersion);
778 LOGE(" RS width %i, height %i", mWidth, mHeight);
779 LOGE(" RS running %i, exit %i, useDepth %i, paused %i", mRunning, mExit, mUseDepth, mPaused);
780 LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
781
Jason Sams4815c0d2009-12-15 12:58:36 -0800782 LOGV("MAX Textures %i, %i %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits);
783 LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs);
784 LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors);
785 LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors);
Jason Sams13e26342009-11-24 12:26:35 -0800786}
Jason Samsa4a54e42009-06-10 18:39:40 -0700787
Jason Sams326e0dd2009-05-22 14:03:28 -0700788///////////////////////////////////////////////////////////////////////////////////////////
Jason Samsa44cb292009-06-04 17:58:03 -0700789//
Jason Sams326e0dd2009-05-22 14:03:28 -0700790
791namespace android {
792namespace renderscript {
793
794
795void rsi_ContextBindRootScript(Context *rsc, RsScript vs)
796{
797 Script *s = static_cast<Script *>(vs);
798 rsc->setRootScript(s);
799}
800
801void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs)
802{
803 Sampler *s = static_cast<Sampler *>(vs);
804
805 if (slot > RS_MAX_SAMPLER_SLOT) {
806 LOGE("Invalid sampler slot");
807 return;
808 }
809
810 s->bindToContext(&rsc->mStateSampler, slot);
811}
812
813void rsi_ContextBindProgramFragmentStore(Context *rsc, RsProgramFragmentStore vpfs)
814{
815 ProgramFragmentStore *pfs = static_cast<ProgramFragmentStore *>(vpfs);
816 rsc->setFragmentStore(pfs);
817}
818
819void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf)
820{
821 ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
822 rsc->setFragment(pf);
823}
824
Jason Sams5fd09d82009-09-23 13:57:02 -0700825void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr)
826{
827 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
828 rsc->setRaster(pr);
829}
830
Jason Sams326e0dd2009-05-22 14:03:28 -0700831void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv)
832{
833 ProgramVertex *pv = static_cast<ProgramVertex *>(vpv);
834 rsc->setVertex(pv);
835}
836
Jason Samsa4a54e42009-06-10 18:39:40 -0700837void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len)
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700838{
839 ObjectBase *ob = static_cast<ObjectBase *>(obj);
Jason Samsa4a54e42009-06-10 18:39:40 -0700840 rsc->assignName(ob, name, len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700841}
Jason Sams326e0dd2009-05-22 14:03:28 -0700842
Jason Sams707aaf32009-08-18 14:14:24 -0700843void rsi_ObjDestroy(Context *rsc, void *obj)
844{
845 ObjectBase *ob = static_cast<ObjectBase *>(obj);
846 rsc->removeName(ob);
Jason Sams9397e302009-08-27 20:23:34 -0700847 ob->decUserRef();
Jason Sams707aaf32009-08-18 14:14:24 -0700848}
849
Jason Sams86f1b232009-09-24 17:38:20 -0700850void rsi_ContextPause(Context *rsc)
851{
852 rsc->pause();
853}
854
855void rsi_ContextResume(Context *rsc)
856{
857 rsc->resume();
858}
859
Jason Sams613cad12009-11-12 15:10:25 -0800860void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, void *sur)
Jason Sams458f2dc2009-11-03 13:58:36 -0800861{
Mathias Agopian9b97c292010-02-12 12:00:38 -0800862 rsc->setSurface(w, h, (android_native_window_t *)sur);
Jason Sams613cad12009-11-12 15:10:25 -0800863}
864
Jason Sams15832442009-11-15 12:14:26 -0800865void rsi_ContextSetPriority(Context *rsc, int32_t p)
Jason Sams613cad12009-11-12 15:10:25 -0800866{
Jason Sams15832442009-11-15 12:14:26 -0800867 rsc->setPriority(p);
Jason Sams458f2dc2009-11-03 13:58:36 -0800868}
869
Jason Samsc21cf402009-11-17 17:26:46 -0800870void rsi_ContextDump(Context *rsc, int32_t bits)
871{
872 ObjectBase::dumpAll(rsc);
873}
874
Jason Sams326e0dd2009-05-22 14:03:28 -0700875}
876}
877
878
Jason Sams4820e8b2010-02-09 16:05:07 -0800879RsContext rsContextCreate(RsDevice vdev, uint32_t version)
Jason Sams326e0dd2009-05-22 14:03:28 -0700880{
Jason Sams4820e8b2010-02-09 16:05:07 -0800881 LOGV("rsContextCreate %p", vdev);
Jason Sams326e0dd2009-05-22 14:03:28 -0700882 Device * dev = static_cast<Device *>(vdev);
Jason Sams4820e8b2010-02-09 16:05:07 -0800883 Context *rsc = new Context(dev, false, false);
884 return rsc;
885}
886
887RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, bool useDepth)
888{
889 LOGV("rsContextCreateGL %p, %i", vdev, useDepth);
890 Device * dev = static_cast<Device *>(vdev);
891 Context *rsc = new Context(dev, true, useDepth);
Jason Sams326e0dd2009-05-22 14:03:28 -0700892 return rsc;
893}
894
895void rsContextDestroy(RsContext vrsc)
896{
897 Context * rsc = static_cast<Context *>(vrsc);
898 delete rsc;
899}
900
Jason Sams50869382009-08-18 17:07:09 -0700901void rsObjDestroyOOB(RsContext vrsc, void *obj)
902{
903 Context * rsc = static_cast<Context *>(vrsc);
904 rsc->objDestroyAdd(static_cast<ObjectBase *>(obj));
905}
906
Jason Sams8c401ef2009-10-06 13:58:47 -0700907uint32_t rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, size_t bufferLen, bool wait)
908{
909 Context * rsc = static_cast<Context *>(vrsc);
910 return rsc->getMessageToClient(data, receiveLen, bufferLen, wait);
911}
912
913void rsContextInitToClient(RsContext vrsc)
914{
915 Context * rsc = static_cast<Context *>(vrsc);
916 rsc->initToClient();
917}
918
919void rsContextDeinitToClient(RsContext vrsc)
920{
921 Context * rsc = static_cast<Context *>(vrsc);
922 rsc->deinitToClient();
923}
924