blob: 53d497004fc627c68486947dea5b18be7fea0c8d [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
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 Agopian3142f4f2009-06-22 18:01:09 -070020#include <ui/FramebufferNativeWindow.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070021
Jason Sams7d787b42009-11-15 12:14:26 -080022#include <sys/types.h>
23#include <sys/resource.h>
Jason Sams8e6c17f2010-07-19 15:38:19 -070024#include <sched.h>
Jason Sams7d787b42009-11-15 12:14:26 -080025
Joe Onorato9ac2c662009-09-23 16:37:36 -070026#include <cutils/properties.h>
27
Jason Sams7d787b42009-11-15 12:14:26 -080028#include <cutils/sched_policy.h>
Jason Samsf3470ed2010-09-28 14:41:22 -070029#include <sys/syscall.h>
30#include <string.h>
Jason Sams7d787b42009-11-15 12:14:26 -080031
Jason Samsd19f10d2009-05-22 14:03:28 -070032using namespace android;
33using namespace android::renderscript;
34
Jason Sams41c19db92009-10-15 16:47:31 -070035pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
Stephen Hines1ac9da62011-01-07 15:11:30 -080036pthread_mutex_t Context::gLibMutex = PTHREAD_MUTEX_INITIALIZER;
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080038bool Context::initGLThread() {
Jason Sams11c8af92010-10-13 15:31:10 -070039 pthread_mutex_lock(&gInitMutex);
Jason Sams11c8af92010-10-13 15:31:10 -070040
Jason Sams803626f2011-04-06 17:52:23 -070041 if (!mHal.funcs.initGraphics(this)) {
Jason Samsd5f06302010-11-03 14:27:11 -070042 pthread_mutex_unlock(&gInitMutex);
Jason Sams8410b142011-09-20 16:59:22 -070043 LOGE("%p initGraphics failed", this);
Jason Samsd5f06302010-11-03 14:27:11 -070044 return false;
Jason Sams11c8af92010-10-13 15:31:10 -070045 }
46
Jason Sams11c8af92010-10-13 15:31:10 -070047 pthread_mutex_unlock(&gInitMutex);
Jason Samsd5f06302010-11-03 14:27:11 -070048 return true;
Jason Samsd19f10d2009-05-22 14:03:28 -070049}
50
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080051void Context::deinitEGL() {
Jason Sams803626f2011-04-06 17:52:23 -070052 mHal.funcs.shutdownGraphics(this);
Jason Sams71362202009-10-27 14:44:31 -070053}
54
Jason Samsa17af042010-11-17 15:29:32 -080055Context::PushState::PushState(Context *con) {
56 mRsc = con;
Jason Sams07078e32011-02-23 14:47:17 -080057 if (con->mIsGraphicsContext) {
58 mFragment.set(con->getProgramFragment());
59 mVertex.set(con->getProgramVertex());
60 mStore.set(con->getProgramStore());
61 mRaster.set(con->getProgramRaster());
62 mFont.set(con->getFont());
63 }
Jason Samsa17af042010-11-17 15:29:32 -080064}
65
66Context::PushState::~PushState() {
Jason Sams07078e32011-02-23 14:47:17 -080067 if (mRsc->mIsGraphicsContext) {
68 mRsc->setProgramFragment(mFragment.get());
69 mRsc->setProgramVertex(mVertex.get());
70 mRsc->setProgramStore(mStore.get());
71 mRsc->setProgramRaster(mRaster.get());
72 mRsc->setFont(mFont.get());
73 }
Jason Samsa17af042010-11-17 15:29:32 -080074}
75
Jason Sams71362202009-10-27 14:44:31 -070076
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080077uint32_t Context::runScript(Script *s) {
Jason Samsa17af042010-11-17 15:29:32 -080078 PushState(this);
Jason Samsda423d82009-06-09 12:15:30 -070079
Jason Samsf17bccc2010-05-28 18:23:22 -070080 uint32_t ret = s->run(this);
Jason Samsb0ec1b42009-07-28 12:02:16 -070081 return ret;
Jason Samsda423d82009-06-09 12:15:30 -070082}
83
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080084uint32_t Context::runRootScript() {
Jason Samsb9d5c572009-12-09 11:05:45 -080085 timerSet(RS_TIMER_SCRIPT);
Jason Sams516c3192009-10-06 13:58:47 -070086 mStateFragmentStore.mLast.clear();
Jason Sams5316b9e2011-09-13 15:41:01 -070087 watchdog.inRoot = true;
Jason Samsf17bccc2010-05-28 18:23:22 -070088 uint32_t ret = runScript(mRootScript.get());
Jason Sams5316b9e2011-09-13 15:41:01 -070089 watchdog.inRoot = false;
Jason Samsc7412b32009-10-14 15:43:53 -070090
Jason Sams9bee51c2009-08-05 13:57:03 -070091 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -070092}
93
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080094uint64_t Context::getTime() const {
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -070095#ifndef ANDROID_RS_SERIALIZE
Jason Samsf4d16062009-08-19 12:17:14 -070096 struct timespec t;
97 clock_gettime(CLOCK_MONOTONIC, &t);
98 return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000);
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -070099#else
100 return 0;
101#endif //ANDROID_RS_SERIALIZE
Jason Samsf4d16062009-08-19 12:17:14 -0700102}
103
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800104void Context::timerReset() {
Jason Samsf4d16062009-08-19 12:17:14 -0700105 for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) {
106 mTimers[ct] = 0;
107 }
108}
109
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800110void Context::timerInit() {
Jason Samsf4d16062009-08-19 12:17:14 -0700111 mTimeLast = getTime();
Jason Sams2525a812009-09-03 15:43:13 -0700112 mTimeFrame = mTimeLast;
113 mTimeLastFrame = mTimeLast;
Jason Samsf4d16062009-08-19 12:17:14 -0700114 mTimerActive = RS_TIMER_INTERNAL;
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700115 mAverageFPSFrameCount = 0;
116 mAverageFPSStartTime = mTimeLast;
117 mAverageFPS = 0;
Jason Samsf4d16062009-08-19 12:17:14 -0700118 timerReset();
119}
120
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800121void Context::timerFrame() {
Jason Sams2525a812009-09-03 15:43:13 -0700122 mTimeLastFrame = mTimeFrame;
123 mTimeFrame = getTime();
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700124 // Update average fps
125 const uint64_t averageFramerateInterval = 1000 * 1000000;
126 mAverageFPSFrameCount ++;
127 uint64_t inverval = mTimeFrame - mAverageFPSStartTime;
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800128 if (inverval >= averageFramerateInterval) {
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700129 inverval = inverval / 1000000;
130 mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval;
131 mAverageFPSFrameCount = 0;
132 mAverageFPSStartTime = mTimeFrame;
133 }
Jason Sams2525a812009-09-03 15:43:13 -0700134}
135
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800136void Context::timerSet(Timers tm) {
Jason Samsf4d16062009-08-19 12:17:14 -0700137 uint64_t last = mTimeLast;
138 mTimeLast = getTime();
139 mTimers[mTimerActive] += mTimeLast - last;
140 mTimerActive = tm;
141}
142
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800143void Context::timerPrint() {
Jason Samsf4d16062009-08-19 12:17:14 -0700144 double total = 0;
145 for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) {
146 total += mTimers[ct];
147 }
Jason Sams2525a812009-09-03 15:43:13 -0700148 uint64_t frame = mTimeFrame - mTimeLastFrame;
Jason Samsb9d5c572009-12-09 11:05:45 -0800149 mTimeMSLastFrame = frame / 1000000;
150 mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000;
151 mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000;
Jason Samsf4d16062009-08-19 12:17:14 -0700152
Jason Samsb9d5c572009-12-09 11:05:45 -0800153
154 if (props.mLogTimes) {
Alex Sakhartchouk98bfe5d2010-10-18 17:18:50 -0700155 LOGV("RS: Frame (%i), Script %2.1f%% (%i), Swap %2.1f%% (%i), Idle %2.1f%% (%lli), Internal %2.1f%% (%lli), Avg fps: %u",
Jason Samsb9d5c572009-12-09 11:05:45 -0800156 mTimeMSLastFrame,
157 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
158 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
159 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700160 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000,
161 mAverageFPS);
Jason Samsb9d5c572009-12-09 11:05:45 -0800162 }
Jason Samsf4d16062009-08-19 12:17:14 -0700163}
164
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800165bool Context::setupCheck() {
Jason Samsd081fff2010-09-16 18:18:29 -0700166
Jason Sams331bf9b2011-04-06 11:23:54 -0700167 mFragmentStore->setup(this, &mStateFragmentStore);
Alex Sakhartchouk407cae92011-05-06 14:59:45 -0700168 mFragment->setup(this, &mStateFragment);
Jason Sams331bf9b2011-04-06 11:23:54 -0700169 mRaster->setup(this, &mStateRaster);
Alex Sakhartchouk407cae92011-05-06 14:59:45 -0700170 mVertex->setup(this, &mStateVertex);
171 mFBOCache.setup(this);
Jason Sams156cce62010-03-03 13:03:18 -0800172 return true;
Jason Samsd19f10d2009-05-22 14:03:28 -0700173}
174
Alex Sakhartchoukfeede2a2010-10-01 10:54:06 -0700175void Context::setupProgramStore() {
Jason Sams331bf9b2011-04-06 11:23:54 -0700176 mFragmentStore->setup(this, &mStateFragmentStore);
Alex Sakhartchoukfeede2a2010-10-01 10:54:06 -0700177}
178
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800179static bool getProp(const char *str) {
Joe Onorato9ac2c662009-09-23 16:37:36 -0700180 char buf[PROPERTY_VALUE_MAX];
Jason Sams66b27712009-09-25 15:25:00 -0700181 property_get(str, buf, "0");
Joe Onorato9ac2c662009-09-23 16:37:36 -0700182 return 0 != strcmp(buf, "0");
183}
Jason Samsd19f10d2009-05-22 14:03:28 -0700184
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800185void Context::displayDebugStats() {
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700186 char buffer[128];
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700187 sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript);
Alex Sakhartchouk55e81982010-08-05 11:24:14 -0700188 float oldR, oldG, oldB, oldA;
189 mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA);
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700190 uint32_t bufferLen = strlen(buffer);
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700191
Alex Sakhartchouk20a93542011-03-17 13:49:38 -0700192 ObjectBaseRef<Font> lastFont(getFont());
193 setFont(NULL);
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700194 float shadowCol = 0.1f;
Alex Sakhartchouk55e81982010-08-05 11:24:14 -0700195 mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f);
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700196 mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6);
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700197
Alex Sakhartchouk10825a02010-10-05 11:33:27 -0700198 mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f);
Alex Sakhartchouk76322af2010-10-05 13:23:55 -0700199 mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7);
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700200
Alex Sakhartchouk20a93542011-03-17 13:49:38 -0700201 setFont(lastFont.get());
Alex Sakhartchouk55e81982010-08-05 11:24:14 -0700202 mStateFont.setFontColor(oldR, oldG, oldB, oldA);
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700203}
204
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800205void * Context::threadProc(void *vrsc) {
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700206 Context *rsc = static_cast<Context *>(vrsc);
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700207#ifndef ANDROID_RS_SERIALIZE
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700208 rsc->mNativeThreadId = gettid();
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700209 setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
210 rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700211#endif //ANDROID_RS_SERIALIZE
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700212 rsc->props.mLogTimes = getProp("debug.rs.profile");
213 rsc->props.mLogScripts = getProp("debug.rs.script");
214 rsc->props.mLogObjects = getProp("debug.rs.object");
215 rsc->props.mLogShaders = getProp("debug.rs.shader");
216 rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes");
217 rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms");
218 rsc->props.mLogVisual = getProp("debug.rs.visual");
Joe Onorato9ac2c662009-09-23 16:37:36 -0700219
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700220 if (!rsdHalInit(rsc, 0, 0)) {
Jason Sams26985362011-05-03 15:01:58 -0700221 rsc->setError(RS_ERROR_FATAL_DRIVER, "Failed initializing GL");
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700222 LOGE("Hal init failed");
223 return NULL;
224 }
225 rsc->mHal.funcs.setPriority(rsc, rsc->mThreadPriority);
Jason Sams462d11b2009-06-19 16:03:18 -0700226
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700227 if (rsc->mIsGraphicsContext) {
Jason Sams26985362011-05-03 15:01:58 -0700228 if (!rsc->initGLThread()) {
229 rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL");
230 return NULL;
231 }
232
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700233 rsc->mStateRaster.init(rsc);
234 rsc->setProgramRaster(NULL);
235 rsc->mStateVertex.init(rsc);
236 rsc->setProgramVertex(NULL);
237 rsc->mStateFragment.init(rsc);
238 rsc->setProgramFragment(NULL);
239 rsc->mStateFragmentStore.init(rsc);
240 rsc->setProgramStore(NULL);
241 rsc->mStateFont.init(rsc);
242 rsc->setFont(NULL);
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -0700243 rsc->mStateSampler.init(rsc);
Alex Sakhartchouk2f6964f2011-05-13 14:53:34 -0700244 rsc->mFBOCache.init(rsc);
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700245 }
Jason Sams9c54bdb2009-06-17 16:52:59 -0700246
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700247 rsc->mRunning = true;
248 bool mDraw = true;
Jason Samsbfc78912011-08-12 15:05:15 -0700249 bool doWait = true;
250
251 uint64_t targetTime = rsc->getTime();
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700252 while (!rsc->mExit) {
Jason Samsbfc78912011-08-12 15:05:15 -0700253 uint64_t waitTime = 0;
254 uint64_t now = rsc->getTime();
Jason Sams85deb782011-08-17 17:15:23 -0700255 if (!doWait) {
256 if (now < targetTime) {
257 waitTime = targetTime - now;
258 doWait = true;
259 }
Jason Samsbfc78912011-08-12 15:05:15 -0700260 }
261
262 mDraw |= rsc->mIO.playCoreCommands(rsc, doWait, waitTime);
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700263 mDraw &= (rsc->mRootScript.get() != NULL);
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700264 mDraw &= rsc->mHasSurface;
Jason Samsd19f10d2009-05-22 14:03:28 -0700265
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700266 if (mDraw && rsc->mIsGraphicsContext) {
Jason Samsbfc78912011-08-12 15:05:15 -0700267 uint64_t delay = rsc->runRootScript() * 1000000;
268 targetTime = rsc->getTime() + delay;
Jason Sams85deb782011-08-17 17:15:23 -0700269 doWait = (delay == 0);
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700270
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700271 if (rsc->props.mLogVisual) {
272 rsc->displayDebugStats();
273 }
Alex Sakhartchouk6de55502010-08-03 12:03:16 -0700274
Jason Samsbfc78912011-08-12 15:05:15 -0700275 mDraw = !rsc->mPaused;
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700276 rsc->timerSet(RS_TIMER_CLEAR_SWAP);
277 rsc->mHal.funcs.swap(rsc);
278 rsc->timerFrame();
279 rsc->timerSet(RS_TIMER_INTERNAL);
280 rsc->timerPrint();
281 rsc->timerReset();
282 }
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700283 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700284
Jason Sams8410b142011-09-20 16:59:22 -0700285 LOGV("%p RS Thread exiting", rsc);
Jason Samsa9e7a052009-09-25 14:51:22 -0700286
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700287 if (rsc->mIsGraphicsContext) {
288 pthread_mutex_lock(&gInitMutex);
289 rsc->deinitEGL();
290 pthread_mutex_unlock(&gInitMutex);
291 }
Jason Sams71362202009-10-27 14:44:31 -0700292
Jason Sams8410b142011-09-20 16:59:22 -0700293 LOGV("%p RS Thread exited", rsc);
Jason Samsbe8ac6a2011-04-21 11:46:50 -0700294 return NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -0700295}
296
Jason Sams5c68a712010-12-24 14:38:39 -0800297void Context::destroyWorkerThreadResources() {
Jason Samsc55de662011-01-23 17:48:45 -0800298 //LOGV("destroyWorkerThreadResources 1");
Jason Sams38f8d9d2011-01-27 00:14:13 -0800299 ObjectBase::zeroAllUserRef(this);
Jason Sams5c68a712010-12-24 14:38:39 -0800300 if (mIsGraphicsContext) {
301 mRaster.clear();
302 mFragment.clear();
303 mVertex.clear();
304 mFragmentStore.clear();
305 mFont.clear();
306 mRootScript.clear();
307 mStateRaster.deinit(this);
308 mStateVertex.deinit(this);
309 mStateFragment.deinit(this);
310 mStateFragmentStore.deinit(this);
311 mStateFont.deinit(this);
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -0700312 mStateSampler.deinit(this);
Alex Sakhartchouk2f6964f2011-05-13 14:53:34 -0700313 mFBOCache.deinit(this);
Jason Sams5c68a712010-12-24 14:38:39 -0800314 }
Jason Sams777ec262011-08-18 18:01:33 -0700315 ObjectBase::freeAllChildren(this);
Jason Samsc55de662011-01-23 17:48:45 -0800316 //LOGV("destroyWorkerThreadResources 2");
Jason Sams84035ff2011-01-09 16:09:51 -0800317 mExit = true;
Jason Sams5c68a712010-12-24 14:38:39 -0800318}
319
Jason Sams5316b9e2011-09-13 15:41:01 -0700320void Context::printWatchdogInfo(void *ctx) {
321 Context *rsc = (Context *)ctx;
322 LOGE("RS watchdog timeout: %i %s line %i %s", rsc->watchdog.inRoot,
323 rsc->watchdog.command, rsc->watchdog.line, rsc->watchdog.file);
324}
325
326
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800327void Context::setPriority(int32_t p) {
Jason Sams7d787b42009-11-15 12:14:26 -0800328 // Note: If we put this in the proper "background" policy
329 // the wallpapers can become completly unresponsive at times.
330 // This is probably not what we want for something the user is actively
331 // looking at.
Jason Samsb9d5c572009-12-09 11:05:45 -0800332 mThreadPriority = p;
Jason Sams7d787b42009-11-15 12:14:26 -0800333#if 0
334 SchedPolicy pol = SP_FOREGROUND;
335 if (p > 0) {
336 pol = SP_BACKGROUND;
337 }
338 if (!set_sched_policy(mNativeThreadId, pol)) {
339 // success; reset the priority as well
340 }
341#else
Jason Sams8e6c17f2010-07-19 15:38:19 -0700342 setpriority(PRIO_PROCESS, mNativeThreadId, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800343#endif
344}
345
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800346Context::Context() {
Jason Samsd5f06302010-11-03 14:27:11 -0700347 mDev = NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -0700348 mRunning = false;
349 mExit = false;
Jason Sams65e7aa52009-09-24 17:38:20 -0700350 mPaused = false;
Jason Samsa9e7a052009-09-25 14:51:22 -0700351 mObjHead = NULL;
Jason Sams156cce62010-03-03 13:03:18 -0800352 mError = RS_ERROR_NONE;
Stephen Hines4382467a2011-08-01 15:02:34 -0700353 mTargetSdkVersion = 14;
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700354 mDPI = 96;
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700355 mIsContextLite = false;
Jason Samsd5f06302010-11-03 14:27:11 -0700356}
357
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800358Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) {
Jason Samsd5f06302010-11-03 14:27:11 -0700359 Context * rsc = new Context();
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700360
Jason Samsd5f06302010-11-03 14:27:11 -0700361 if (!rsc->initContext(dev, sc)) {
362 delete rsc;
363 return NULL;
364 }
365 return rsc;
366}
367
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700368Context * Context::createContextLite() {
369 Context * rsc = new Context();
370 rsc->mIsContextLite = true;
371 return rsc;
372}
373
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800374bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) {
Jason Samsd5f06302010-11-03 14:27:11 -0700375 pthread_mutex_lock(&gInitMutex);
376
Jason Samsedbfabd2011-05-17 15:01:29 -0700377 mIO.init();
Jason Sams5316b9e2011-09-13 15:41:01 -0700378 mIO.setTimoutCallback(printWatchdogInfo, this, 2e9);
Jason Samsedbfabd2011-05-17 15:01:29 -0700379
Jason Samsd5f06302010-11-03 14:27:11 -0700380 dev->addContext(this);
381 mDev = dev;
Jason Sams11c8af92010-10-13 15:31:10 -0700382 if (sc) {
383 mUserSurfaceConfig = *sc;
384 } else {
385 memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig));
386 }
Jason Sams156cce62010-03-03 13:03:18 -0800387
Jason Sams11c8af92010-10-13 15:31:10 -0700388 mIsGraphicsContext = sc != NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -0700389
Jason Sams8ad00102009-06-04 14:35:01 -0700390 int status;
391 pthread_attr_t threadAttr;
392
Jason Sams41c19db92009-10-15 16:47:31 -0700393 pthread_mutex_unlock(&gInitMutex);
394
395 // Global init done at this point.
Jason Sams462d11b2009-06-19 16:03:18 -0700396
Jason Sams8ad00102009-06-04 14:35:01 -0700397 status = pthread_attr_init(&threadAttr);
398 if (status) {
399 LOGE("Failed to init thread attribute.");
Jason Samsd5f06302010-11-03 14:27:11 -0700400 return false;
Jason Sams8ad00102009-06-04 14:35:01 -0700401 }
402
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700403 mHasSurface = false;
Jason Samsf29ca502009-06-23 12:22:47 -0700404
Jason Samsf4d16062009-08-19 12:17:14 -0700405 timerInit();
Jason Samsd3f2eaf2009-09-24 15:42:52 -0700406 timerSet(RS_TIMER_INTERNAL);
Jason Sams730ee652009-08-18 17:07:09 -0700407
Jason Sams8ad00102009-06-04 14:35:01 -0700408 status = pthread_create(&mThreadId, &threadAttr, threadProc, this);
Jason Samsd19f10d2009-05-22 14:03:28 -0700409 if (status) {
410 LOGE("Failed to start rs context thread.");
Jason Samsd5f06302010-11-03 14:27:11 -0700411 return false;
Jason Sams8e6c17f2010-07-19 15:38:19 -0700412 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800413 while (!mRunning && (mError == RS_ERROR_NONE)) {
Jason Samsc7f4e412010-07-20 15:09:00 -0700414 usleep(100);
415 }
416
Jason Samsd5f06302010-11-03 14:27:11 -0700417 if (mError != RS_ERROR_NONE) {
Jason Sams80e29cf2011-03-18 17:08:54 -0700418 LOGE("Errors during thread init");
Jason Samsd5f06302010-11-03 14:27:11 -0700419 return false;
420 }
421
Jason Sams8ad00102009-06-04 14:35:01 -0700422 pthread_attr_destroy(&threadAttr);
Jason Samsd5f06302010-11-03 14:27:11 -0700423 return true;
Jason Samsd19f10d2009-05-22 14:03:28 -0700424}
425
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800426Context::~Context() {
Jason Sams8410b142011-09-20 16:59:22 -0700427 LOGV("%p Context::~Context", this);
Jason Sams84035ff2011-01-09 16:09:51 -0800428
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700429 if (!mIsContextLite) {
430 mIO.coreFlush();
431 rsAssert(mExit);
432 mExit = true;
433 mPaused = false;
434 void *res;
Jason Samsd19f10d2009-05-22 14:03:28 -0700435
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700436 mIO.shutdown();
437 int status = pthread_join(mThreadId, &res);
Jason Samsd19f10d2009-05-22 14:03:28 -0700438
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700439 if (mHal.funcs.shutdownDriver) {
440 mHal.funcs.shutdownDriver(this);
441 }
442
443 // Global structure cleanup.
444 pthread_mutex_lock(&gInitMutex);
445 if (mDev) {
446 mDev->removeContext(this);
447 mDev = NULL;
448 }
449 pthread_mutex_unlock(&gInitMutex);
Jason Sams03855bb2011-01-25 00:26:25 -0800450 }
Jason Sams8410b142011-09-20 16:59:22 -0700451 LOGV("%p Context::~Context done", this);
Jason Samsd19f10d2009-05-22 14:03:28 -0700452}
453
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700454void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) {
Jason Sams704ff642010-02-09 16:05:07 -0800455 rsAssert(mIsGraphicsContext);
Jason Sams803626f2011-04-06 17:52:23 -0700456 mHal.funcs.setSurface(this, w, h, sur);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800457
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700458 mHasSurface = sur != NULL;
Jason Sams803626f2011-04-06 17:52:23 -0700459 mWidth = w;
460 mHeight = h;
Jason Sams3bc47d42009-11-12 15:10:25 -0800461
Jason Sams803626f2011-04-06 17:52:23 -0700462 if (mWidth && mHeight) {
Jason Samsf603d212010-05-14 15:30:29 -0700463 mStateVertex.updateSize(this);
Alex Sakhartchouk10ed049352011-07-19 17:50:29 -0700464 mFBOCache.updateSize();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800465 }
466}
467
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800468void Context::pause() {
Jason Sams704ff642010-02-09 16:05:07 -0800469 rsAssert(mIsGraphicsContext);
Jason Sams65e7aa52009-09-24 17:38:20 -0700470 mPaused = true;
471}
472
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800473void Context::resume() {
Jason Sams704ff642010-02-09 16:05:07 -0800474 rsAssert(mIsGraphicsContext);
Jason Sams65e7aa52009-09-24 17:38:20 -0700475 mPaused = false;
476}
477
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800478void Context::setRootScript(Script *s) {
Jason Sams704ff642010-02-09 16:05:07 -0800479 rsAssert(mIsGraphicsContext);
Jason Samsd19f10d2009-05-22 14:03:28 -0700480 mRootScript.set(s);
481}
482
Jason Samsa17af042010-11-17 15:29:32 -0800483void Context::setProgramStore(ProgramStore *pfs) {
Jason Sams704ff642010-02-09 16:05:07 -0800484 rsAssert(mIsGraphicsContext);
Jason Sams9c54bdb2009-06-17 16:52:59 -0700485 if (pfs == NULL) {
486 mFragmentStore.set(mStateFragmentStore.mDefault);
487 } else {
488 mFragmentStore.set(pfs);
489 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700490}
491
Jason Samsa17af042010-11-17 15:29:32 -0800492void Context::setProgramFragment(ProgramFragment *pf) {
Jason Sams704ff642010-02-09 16:05:07 -0800493 rsAssert(mIsGraphicsContext);
Jason Sams9c54bdb2009-06-17 16:52:59 -0700494 if (pf == NULL) {
495 mFragment.set(mStateFragment.mDefault);
496 } else {
497 mFragment.set(pf);
498 }
Jason Sams9bee51c2009-08-05 13:57:03 -0700499}
500
Jason Samsa17af042010-11-17 15:29:32 -0800501void Context::setProgramRaster(ProgramRaster *pr) {
Jason Sams704ff642010-02-09 16:05:07 -0800502 rsAssert(mIsGraphicsContext);
Jason Samsebfb4362009-09-23 13:57:02 -0700503 if (pr == NULL) {
504 mRaster.set(mStateRaster.mDefault);
505 } else {
506 mRaster.set(pr);
507 }
508}
509
Jason Samsa17af042010-11-17 15:29:32 -0800510void Context::setProgramVertex(ProgramVertex *pv) {
Jason Sams704ff642010-02-09 16:05:07 -0800511 rsAssert(mIsGraphicsContext);
Jason Sams9c54bdb2009-06-17 16:52:59 -0700512 if (pv == NULL) {
513 mVertex.set(mStateVertex.mDefault);
514 } else {
515 mVertex.set(pv);
516 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700517}
518
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800519void Context::setFont(Font *f) {
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700520 rsAssert(mIsGraphicsContext);
521 if (f == NULL) {
522 mFont.set(mStateFont.mDefault);
523 } else {
524 mFont.set(f);
525 }
526}
527
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800528void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) {
Jason Sams3eaa3382009-06-10 15:04:38 -0700529 rsAssert(!obj->getName());
Jason Samsd5680f92009-06-10 18:39:40 -0700530 obj->setName(name, len);
Jason Sams3eaa3382009-06-10 15:04:38 -0700531 mNames.add(obj);
532}
533
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800534void Context::removeName(ObjectBase *obj) {
535 for (size_t ct=0; ct < mNames.size(); ct++) {
Jason Sams3eaa3382009-06-10 15:04:38 -0700536 if (obj == mNames[ct]) {
537 mNames.removeAt(ct);
538 return;
539 }
540 }
541}
542
Jason Samsedbfabd2011-05-17 15:01:29 -0700543RsMessageToClientType Context::peekMessageToClient(size_t *receiveLen, uint32_t *subID) {
544 return (RsMessageToClientType)mIO.getClientHeader(receiveLen, subID);
Jason Sams1c415172010-11-08 17:06:46 -0800545}
546
Jason Samsedbfabd2011-05-17 15:01:29 -0700547RsMessageToClientType Context::getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen) {
548 return (RsMessageToClientType)mIO.getClientPayload(data, receiveLen, subID, bufferLen);
Jason Sams516c3192009-10-06 13:58:47 -0700549}
550
Jason Samsadd9d962010-11-22 16:20:16 -0800551bool Context::sendMessageToClient(const void *data, RsMessageToClientType cmdID,
552 uint32_t subID, size_t len, bool waitForSpace) const {
Jason Samsedbfabd2011-05-17 15:01:29 -0700553
554 return mIO.sendToClient(cmdID, subID, data, len, waitForSpace);
Jason Sams516c3192009-10-06 13:58:47 -0700555}
556
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800557void Context::initToClient() {
558 while (!mRunning) {
Jason Sams516c3192009-10-06 13:58:47 -0700559 usleep(100);
560 }
561}
562
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800563void Context::deinitToClient() {
Jason Samsedbfabd2011-05-17 15:01:29 -0700564 mIO.clientShutdown();
Jason Sams516c3192009-10-06 13:58:47 -0700565}
Jason Sams730ee652009-08-18 17:07:09 -0700566
Jason Samsadd9d962010-11-22 16:20:16 -0800567void Context::setError(RsError e, const char *msg) const {
Jason Sams156cce62010-03-03 13:03:18 -0800568 mError = e;
Jason Sams1c415172010-11-08 17:06:46 -0800569 sendMessageToClient(msg, RS_MESSAGE_TO_CLIENT_ERROR, e, strlen(msg) + 1, true);
Jason Sams156cce62010-03-03 13:03:18 -0800570}
571
572
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800573void Context::dumpDebug() const {
Jason Sams9dab6672009-11-24 12:26:35 -0800574 LOGE("RS Context debug %p", this);
575 LOGE("RS Context debug");
576
Jason Sams9dab6672009-11-24 12:26:35 -0800577 LOGE(" RS width %i, height %i", mWidth, mHeight);
Jason Sams11c8af92010-10-13 15:31:10 -0700578 LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused);
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700579 LOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId);
Jason Sams9dab6672009-11-24 12:26:35 -0800580}
Jason Samsd5680f92009-06-10 18:39:40 -0700581
Jason Samsd19f10d2009-05-22 14:03:28 -0700582///////////////////////////////////////////////////////////////////////////////////////////
Jason Samsa09f11d2009-06-04 17:58:03 -0700583//
Jason Samsd19f10d2009-05-22 14:03:28 -0700584
585namespace android {
586namespace renderscript {
587
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800588void rsi_ContextFinish(Context *rsc) {
Jason Sams96ed4cf2010-06-15 12:15:57 -0700589}
Jason Samsd19f10d2009-05-22 14:03:28 -0700590
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800591void rsi_ContextBindRootScript(Context *rsc, RsScript vs) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700592 Script *s = static_cast<Script *>(vs);
593 rsc->setRootScript(s);
594}
595
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800596void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700597 Sampler *s = static_cast<Sampler *>(vs);
598
599 if (slot > RS_MAX_SAMPLER_SLOT) {
600 LOGE("Invalid sampler slot");
601 return;
602 }
603
604 s->bindToContext(&rsc->mStateSampler, slot);
605}
606
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800607void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) {
Jason Sams54db59c2010-05-13 18:30:11 -0700608 ProgramStore *pfs = static_cast<ProgramStore *>(vpfs);
Jason Samsa17af042010-11-17 15:29:32 -0800609 rsc->setProgramStore(pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -0700610}
611
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800612void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700613 ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
Jason Samsa17af042010-11-17 15:29:32 -0800614 rsc->setProgramFragment(pf);
Jason Samsd19f10d2009-05-22 14:03:28 -0700615}
616
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800617void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) {
Jason Samsebfb4362009-09-23 13:57:02 -0700618 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
Jason Samsa17af042010-11-17 15:29:32 -0800619 rsc->setProgramRaster(pr);
Jason Samsebfb4362009-09-23 13:57:02 -0700620}
621
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800622void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700623 ProgramVertex *pv = static_cast<ProgramVertex *>(vpv);
Jason Samsa17af042010-11-17 15:29:32 -0800624 rsc->setProgramVertex(pv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700625}
626
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800627void rsi_ContextBindFont(Context *rsc, RsFont vfont) {
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700628 Font *font = static_cast<Font *>(vfont);
629 rsc->setFont(font);
630}
631
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700632void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) {
Jason Sams3eaa3382009-06-10 15:04:38 -0700633 ObjectBase *ob = static_cast<ObjectBase *>(obj);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700634 rsc->assignName(ob, name, name_length);
Jason Sams3eaa3382009-06-10 15:04:38 -0700635}
Jason Samsd19f10d2009-05-22 14:03:28 -0700636
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800637void rsi_ObjDestroy(Context *rsc, void *optr) {
Jason Sams3b9c52a2010-10-14 17:48:46 -0700638 ObjectBase *ob = static_cast<ObjectBase *>(optr);
Jason Sams7ce033d2009-08-18 14:14:24 -0700639 rsc->removeName(ob);
Jason Sams07ae4062009-08-27 20:23:34 -0700640 ob->decUserRef();
Jason Sams7ce033d2009-08-18 14:14:24 -0700641}
642
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800643void rsi_ContextPause(Context *rsc) {
Jason Sams65e7aa52009-09-24 17:38:20 -0700644 rsc->pause();
645}
646
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800647void rsi_ContextResume(Context *rsc) {
Jason Sams65e7aa52009-09-24 17:38:20 -0700648 rsc->resume();
649}
650
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700651void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, RsNativeWindow sur) {
Mathias Agopian128ce4b2010-02-12 14:04:35 -0800652 rsc->setSurface(w, h, sur);
Jason Sams3bc47d42009-11-12 15:10:25 -0800653}
654
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800655void rsi_ContextSetPriority(Context *rsc, int32_t p) {
Jason Sams7d787b42009-11-15 12:14:26 -0800656 rsc->setPriority(p);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800657}
658
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800659void rsi_ContextDump(Context *rsc, int32_t bits) {
Jason Sams715333b2009-11-17 17:26:46 -0800660 ObjectBase::dumpAll(rsc);
661}
662
Jason Sams5c68a712010-12-24 14:38:39 -0800663void rsi_ContextDestroyWorker(Context *rsc) {
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700664 rsc->destroyWorkerThreadResources();
Jason Sams5c68a712010-12-24 14:38:39 -0800665}
666
Jason Samsc5765372011-04-28 18:26:48 -0700667void rsi_ContextDestroy(Context *rsc) {
Jason Sams8410b142011-09-20 16:59:22 -0700668 LOGV("%p rsContextDestroy", rsc);
Jason Sams5c68a712010-12-24 14:38:39 -0800669 rsContextDestroyWorker(rsc);
Jason Sams546f01b2010-12-09 12:19:46 -0800670 delete rsc;
Jason Sams8410b142011-09-20 16:59:22 -0700671 LOGV("%p rsContextDestroy done", rsc);
Jason Sams546f01b2010-12-09 12:19:46 -0800672}
673
Jason Samsd19f10d2009-05-22 14:03:28 -0700674
Jason Samsc5765372011-04-28 18:26:48 -0700675RsMessageToClientType rsi_ContextPeekMessage(Context *rsc,
Jason Sams65bdaf12011-04-26 14:50:00 -0700676 size_t * receiveLen, size_t receiveLen_length,
Jason Samsedbfabd2011-05-17 15:01:29 -0700677 uint32_t * subID, size_t subID_length) {
678 return rsc->peekMessageToClient(receiveLen, subID);
Jason Sams1c415172010-11-08 17:06:46 -0800679}
680
Jason Samsc5765372011-04-28 18:26:48 -0700681RsMessageToClientType rsi_ContextGetMessage(Context *rsc, void * data, size_t data_length,
Jason Sams65bdaf12011-04-26 14:50:00 -0700682 size_t * receiveLen, size_t receiveLen_length,
Jason Samsedbfabd2011-05-17 15:01:29 -0700683 uint32_t * subID, size_t subID_length) {
Jason Sams65bdaf12011-04-26 14:50:00 -0700684 rsAssert(subID_length == sizeof(uint32_t));
685 rsAssert(receiveLen_length == sizeof(size_t));
Jason Samsedbfabd2011-05-17 15:01:29 -0700686 return rsc->getMessageToClient(data, receiveLen, subID, data_length);
Jason Sams516c3192009-10-06 13:58:47 -0700687}
688
Jason Samsc5765372011-04-28 18:26:48 -0700689void rsi_ContextInitToClient(Context *rsc) {
Jason Sams516c3192009-10-06 13:58:47 -0700690 rsc->initToClient();
691}
692
Jason Samsc5765372011-04-28 18:26:48 -0700693void rsi_ContextDeinitToClient(Context *rsc) {
Jason Sams516c3192009-10-06 13:58:47 -0700694 rsc->deinitToClient();
695}
696
Jason Samsc5765372011-04-28 18:26:48 -0700697}
698}
699
Stephen Hines4382467a2011-08-01 15:02:34 -0700700RsContext rsContextCreate(RsDevice vdev, uint32_t version,
701 uint32_t sdkVersion) {
Jason Sams8410b142011-09-20 16:59:22 -0700702 LOGV("rsContextCreate dev=%p", vdev);
Jason Samsd9d37cc2011-05-18 17:36:02 -0700703 Device * dev = static_cast<Device *>(vdev);
704 Context *rsc = Context::createContext(dev, NULL);
Stephen Hines4382467a2011-08-01 15:02:34 -0700705 if (rsc) {
706 rsc->setTargetSdkVersion(sdkVersion);
707 }
Jason Samsd9d37cc2011-05-18 17:36:02 -0700708 return rsc;
709}
710
711RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
Stephen Hines4382467a2011-08-01 15:02:34 -0700712 uint32_t sdkVersion, RsSurfaceConfig sc,
713 uint32_t dpi) {
Jason Sams8410b142011-09-20 16:59:22 -0700714 LOGV("rsContextCreateGL dev=%p", vdev);
Jason Samsd9d37cc2011-05-18 17:36:02 -0700715 Device * dev = static_cast<Device *>(vdev);
716 Context *rsc = Context::createContext(dev, &sc);
Jason Samsfb06b7a2011-07-13 16:09:42 -0700717 if (rsc) {
Stephen Hines4382467a2011-08-01 15:02:34 -0700718 rsc->setTargetSdkVersion(sdkVersion);
Jason Samsfb06b7a2011-07-13 16:09:42 -0700719 rsc->setDPI(dpi);
720 }
Jason Sams8410b142011-09-20 16:59:22 -0700721 LOGV("%p rsContextCreateGL ret", rsc);
Jason Samsd9d37cc2011-05-18 17:36:02 -0700722 return rsc;
723}
724
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700725// Only to be called at a3d load time, before object is visible to user
726// not thread safe
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800727void rsaGetName(RsContext con, void * obj, const char **name) {
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700728 ObjectBase *ob = static_cast<ObjectBase *>(obj);
729 (*name) = ob->getName();
730}