Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Alex Sakhartchouk | e23d239 | 2012-03-09 09:24:39 -0800 | [diff] [blame] | 17 | #include "rs.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 18 | #include "rsDevice.h" |
| 19 | #include "rsContext.h" |
| 20 | #include "rsThreadIO.h" |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 21 | |
Tim Murray | 397b0b1 | 2014-01-07 15:35:08 -0800 | [diff] [blame] | 22 | #include "rsgApiStructs.h" |
| 23 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 24 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | 4edf030 | 2012-03-09 10:47:27 -0800 | [diff] [blame] | 25 | #include "rsMesh.h" |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 26 | #include <gui/DisplayEventReceiver.h> |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 27 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <sys/resource.h> |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 31 | #include <sched.h> |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 32 | |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 33 | #include <sys/syscall.h> |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 34 | #include <string.h> |
Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame] | 35 | #include <dlfcn.h> |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 36 | #include <inttypes.h> |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 37 | #include <unistd.h> |
Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame] | 38 | |
Stephen Hines | 1664780 | 2013-08-15 16:28:01 -0700 | [diff] [blame] | 39 | #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) && \ |
Elliott Hughes | e5e18cc | 2015-08-12 16:37:22 -0700 | [diff] [blame] | 40 | defined(__ANDROID__) |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 41 | #include <cutils/properties.h> |
| 42 | #endif |
| 43 | |
Stephen Hines | 6dfe684 | 2013-08-14 17:56:38 -0700 | [diff] [blame] | 44 | #ifdef RS_COMPATIBILITY_LIB |
| 45 | #include "rsCompatibilityLib.h" |
| 46 | #endif |
| 47 | |
Stephen McGroarty | d5164d5 | 2015-05-08 15:31:49 +0100 | [diff] [blame] | 48 | int gDebuggerPresent = 0; |
| 49 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 50 | #ifdef RS_SERVER |
| 51 | // Android exposes gettid(), standard Linux does not |
| 52 | static pid_t gettid() { |
| 53 | return syscall(SYS_gettid); |
| 54 | } |
| 55 | #endif |
| 56 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 57 | using namespace android; |
| 58 | using namespace android::renderscript; |
| 59 | |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 60 | pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER; |
Jason Sams | 4961cce | 2013-04-11 16:11:46 -0700 | [diff] [blame] | 61 | pthread_mutex_t Context::gMessageMutex = PTHREAD_MUTEX_INITIALIZER; |
Stephen Hines | ca3f09c | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 62 | pthread_mutex_t Context::gLibMutex = PTHREAD_MUTEX_INITIALIZER; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 64 | bool Context::initGLThread() { |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 65 | pthread_mutex_lock(&gInitMutex); |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 66 | |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 67 | if (!mHal.funcs.initGraphics(this)) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 68 | pthread_mutex_unlock(&gInitMutex); |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 69 | ALOGE("%p initGraphics failed", this); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 70 | return false; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 73 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 74 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 77 | void Context::deinitEGL() { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 78 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 79 | mHal.funcs.shutdownGraphics(this); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 80 | #endif |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 83 | Context::PushState::PushState(Context *con) { |
| 84 | mRsc = con; |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 85 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | c946b61 | 2011-02-23 14:47:17 -0800 | [diff] [blame] | 86 | if (con->mIsGraphicsContext) { |
| 87 | mFragment.set(con->getProgramFragment()); |
| 88 | mVertex.set(con->getProgramVertex()); |
| 89 | mStore.set(con->getProgramStore()); |
| 90 | mRaster.set(con->getProgramRaster()); |
| 91 | mFont.set(con->getFont()); |
| 92 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 93 | #endif |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | Context::PushState::~PushState() { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 97 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | c946b61 | 2011-02-23 14:47:17 -0800 | [diff] [blame] | 98 | if (mRsc->mIsGraphicsContext) { |
| 99 | mRsc->setProgramFragment(mFragment.get()); |
| 100 | mRsc->setProgramVertex(mVertex.get()); |
| 101 | mRsc->setProgramStore(mStore.get()); |
| 102 | mRsc->setProgramRaster(mRaster.get()); |
| 103 | mRsc->setFont(mFont.get()); |
| 104 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 105 | #endif |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 108 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 109 | uint32_t Context::runScript(Script *s) { |
Shih-wei Liao | da3b58d | 2012-08-03 04:24:33 -0700 | [diff] [blame] | 110 | PushState ps(this); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 111 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 112 | uint32_t ret = s->run(this); |
Jason Sams | c9d43db | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 113 | return ret; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 116 | uint32_t Context::runRootScript() { |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 117 | timerSet(RS_TIMER_SCRIPT); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 118 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 119 | mStateFragmentStore.mLast.clear(); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 120 | #endif |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 121 | watchdog.inRoot = true; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 122 | uint32_t ret = runScript(mRootScript.get()); |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 123 | watchdog.inRoot = false; |
Jason Sams | 8cfdd24 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 124 | |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 125 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 128 | uint64_t Context::getTime() const { |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 129 | #ifndef ANDROID_RS_SERIALIZE |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 130 | struct timespec t; |
| 131 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 132 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 133 | #else |
| 134 | return 0; |
| 135 | #endif //ANDROID_RS_SERIALIZE |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 138 | void Context::timerReset() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 139 | for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { |
| 140 | mTimers[ct] = 0; |
| 141 | } |
| 142 | } |
| 143 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 144 | void Context::timerInit() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 145 | mTimeLast = getTime(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 146 | mTimeFrame = mTimeLast; |
| 147 | mTimeLastFrame = mTimeLast; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 148 | mTimerActive = RS_TIMER_INTERNAL; |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 149 | mAverageFPSFrameCount = 0; |
| 150 | mAverageFPSStartTime = mTimeLast; |
| 151 | mAverageFPS = 0; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 152 | timerReset(); |
| 153 | } |
| 154 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 155 | void Context::timerFrame() { |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 156 | mTimeLastFrame = mTimeFrame; |
| 157 | mTimeFrame = getTime(); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 158 | // Update average fps |
| 159 | const uint64_t averageFramerateInterval = 1000 * 1000000; |
| 160 | mAverageFPSFrameCount ++; |
| 161 | uint64_t inverval = mTimeFrame - mAverageFPSStartTime; |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 162 | if (inverval >= averageFramerateInterval) { |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 163 | inverval = inverval / 1000000; |
| 164 | mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval; |
| 165 | mAverageFPSFrameCount = 0; |
| 166 | mAverageFPSStartTime = mTimeFrame; |
| 167 | } |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 170 | void Context::timerSet(Timers tm) { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 171 | uint64_t last = mTimeLast; |
| 172 | mTimeLast = getTime(); |
| 173 | mTimers[mTimerActive] += mTimeLast - last; |
| 174 | mTimerActive = tm; |
| 175 | } |
| 176 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 177 | void Context::timerPrint() { |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 178 | double total = 0; |
| 179 | for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { |
| 180 | total += mTimers[ct]; |
| 181 | } |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 182 | uint64_t frame = mTimeFrame - mTimeLastFrame; |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 183 | mTimeMSLastFrame = frame / 1000000; |
| 184 | mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; |
| 185 | mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 186 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 187 | |
| 188 | if (props.mLogTimes) { |
Ian Rogers | f8852d0 | 2014-01-29 15:35:17 -0800 | [diff] [blame] | 189 | ALOGV("RS: Frame (%i), Script %2.1f%% (%i), Swap %2.1f%% (%i), Idle %2.1f%% (%" PRIi64 "), " |
| 190 | "Internal %2.1f%% (%" PRIi64 "), Avg fps: %u", |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 191 | mTimeMSLastFrame, |
| 192 | 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, |
| 193 | 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, |
| 194 | 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 195 | 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000, |
| 196 | mAverageFPS); |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 197 | } |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 200 | bool Context::setupCheck() { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 201 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 202 | mFragmentStore->setup(this, &mStateFragmentStore); |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 203 | mFragment->setup(this, &mStateFragment); |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 204 | mRaster->setup(this, &mStateRaster); |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 205 | mVertex->setup(this, &mStateVertex); |
| 206 | mFBOCache.setup(this); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 207 | #endif |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 208 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 211 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | 889fe50 | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 212 | void Context::setupProgramStore() { |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 213 | mFragmentStore->setup(this, &mStateFragmentStore); |
Alex Sakhartchouk | 889fe50 | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 214 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 215 | #endif |
Alex Sakhartchouk | 889fe50 | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 216 | |
Jason Sams | d1f7da6 | 2012-03-15 19:18:03 -0700 | [diff] [blame] | 217 | static uint32_t getProp(const char *str) { |
Elliott Hughes | e5e18cc | 2015-08-12 16:37:22 -0700 | [diff] [blame] | 218 | #if !defined(RS_SERVER) && defined(__ANDROID__) |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 219 | char buf[PROPERTY_VALUE_MAX]; |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 220 | property_get(str, buf, "0"); |
Jason Sams | d1f7da6 | 2012-03-15 19:18:03 -0700 | [diff] [blame] | 221 | return atoi(buf); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 222 | #else |
| 223 | return 0; |
| 224 | #endif |
Joe Onorato | 76371ff | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 225 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 226 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 227 | void Context::displayDebugStats() { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 228 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 229 | char buffer[128]; |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 230 | sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript); |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 231 | float oldR, oldG, oldB, oldA; |
| 232 | mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA); |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 233 | uint32_t bufferLen = strlen(buffer); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 234 | |
Alex Sakhartchouk | 1809bde | 2011-03-17 13:49:38 -0700 | [diff] [blame] | 235 | ObjectBaseRef<Font> lastFont(getFont()); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 236 | setFont(nullptr); |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 237 | float shadowCol = 0.1f; |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 238 | mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 239 | mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 240 | |
Alex Sakhartchouk | 09c6735 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 241 | mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f); |
Alex Sakhartchouk | c8fb69e | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 242 | mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7); |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 243 | |
Alex Sakhartchouk | 1809bde | 2011-03-17 13:49:38 -0700 | [diff] [blame] | 244 | setFont(lastFont.get()); |
Alex Sakhartchouk | ca5a454 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 245 | mStateFont.setFontColor(oldR, oldG, oldB, oldA); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 246 | #endif |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 249 | void * Context::threadProc(void *vrsc) { |
| 250 | Context *rsc = static_cast<Context *>(vrsc); |
Jason Sams | cfaec17 | 2015-01-23 13:42:43 -0800 | [diff] [blame] | 251 | |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 252 | #ifndef ANDROID_RS_SERIALIZE |
| 253 | rsc->mNativeThreadId = gettid(); |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 254 | #endif //ANDROID_RS_SERIALIZE |
Jason Sams | cfaec17 | 2015-01-23 13:42:43 -0800 | [diff] [blame] | 255 | |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 256 | rsc->props.mLogTimes = getProp("debug.rs.profile") != 0; |
| 257 | rsc->props.mLogScripts = getProp("debug.rs.script") != 0; |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 258 | rsc->props.mLogShaders = getProp("debug.rs.shader") != 0; |
| 259 | rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes") != 0; |
| 260 | rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms") != 0; |
| 261 | rsc->props.mLogVisual = getProp("debug.rs.visual") != 0; |
| 262 | rsc->props.mDebugMaxThreads = getProp("debug.rs.max-threads"); |
| 263 | |
Jason Sams | 2d8030a | 2014-07-24 18:47:34 -0700 | [diff] [blame] | 264 | if (getProp("debug.rs.debug") != 0) { |
| 265 | ALOGD("Forcing debug context due to debug.rs.debug."); |
| 266 | rsc->mContextType = RS_CONTEXT_TYPE_DEBUG; |
Jason Sams | 0ca7cba | 2015-03-11 15:22:38 -0700 | [diff] [blame] | 267 | rsc->mForceCpu = true; |
Jason Sams | 2d8030a | 2014-07-24 18:47:34 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Jason Sams | 0ca7cba | 2015-03-11 15:22:38 -0700 | [diff] [blame] | 270 | bool forceCpu = getProp("debug.rs.default-CPU-driver") != 0; |
| 271 | if (forceCpu) { |
| 272 | ALOGD("Skipping hardware driver and loading default CPU driver"); |
| 273 | rsc->mForceCpu = true; |
Tim Murray | 0c66f07 | 2012-10-23 14:05:02 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Jason Sams | 0ca7cba | 2015-03-11 15:22:38 -0700 | [diff] [blame] | 276 | rsc->mForceCpu |= rsc->mIsGraphicsContext; |
| 277 | rsc->loadDriver(rsc->mForceCpu); |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 278 | |
Jason Sams | cfaec17 | 2015-01-23 13:42:43 -0800 | [diff] [blame] | 279 | if (!rsc->isSynchronous()) { |
| 280 | // Due to legacy we default to normal_graphics |
| 281 | // setPriority will make the adjustments as needed. |
| 282 | rsc->setPriority(RS_THREAD_PRIORITY_NORMAL_GRAPHICS); |
| 283 | } |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 284 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 285 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 286 | if (rsc->mIsGraphicsContext) { |
Jason Sams | d3e7107 | 2011-05-03 15:01:58 -0700 | [diff] [blame] | 287 | if (!rsc->initGLThread()) { |
| 288 | rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 289 | return nullptr; |
Jason Sams | d3e7107 | 2011-05-03 15:01:58 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 292 | rsc->mStateRaster.init(rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 293 | rsc->setProgramRaster(nullptr); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 294 | rsc->mStateVertex.init(rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 295 | rsc->setProgramVertex(nullptr); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 296 | rsc->mStateFragment.init(rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 297 | rsc->setProgramFragment(nullptr); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 298 | rsc->mStateFragmentStore.init(rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 299 | rsc->setProgramStore(nullptr); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 300 | rsc->mStateFont.init(rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 301 | rsc->setFont(nullptr); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 302 | rsc->mStateSampler.init(rsc); |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 303 | rsc->mFBOCache.init(rsc); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 304 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 305 | #endif |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 306 | |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 307 | rsc->mRunning = true; |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 308 | |
| 309 | if (rsc->isSynchronous()) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 310 | return nullptr; |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 313 | if (!rsc->mIsGraphicsContext) { |
| 314 | while (!rsc->mExit) { |
Jason Sams | 963a2fb | 2012-02-09 14:36:14 -0800 | [diff] [blame] | 315 | rsc->mIO.playCoreCommands(rsc, -1); |
Jason Sams | e0aab4a | 2011-08-12 15:05:15 -0700 | [diff] [blame] | 316 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 317 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 318 | } else { |
| 319 | #ifndef ANDROID_RS_SERIALIZE |
| 320 | DisplayEventReceiver displayEvent; |
| 321 | DisplayEventReceiver::Event eventBuffer[1]; |
| 322 | #endif |
| 323 | int vsyncRate = 0; |
| 324 | int targetRate = 0; |
Jason Sams | e0aab4a | 2011-08-12 15:05:15 -0700 | [diff] [blame] | 325 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 326 | bool drawOnce = false; |
| 327 | while (!rsc->mExit) { |
| 328 | rsc->timerSet(RS_TIMER_IDLE); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 329 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 330 | #ifndef ANDROID_RS_SERIALIZE |
Jason Sams | 9afd9a5 | 2012-02-17 16:59:50 -0800 | [diff] [blame] | 331 | if (!rsc->mRootScript.get() || !rsc->mHasSurface || rsc->mPaused) { |
| 332 | targetRate = 0; |
| 333 | } |
| 334 | |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 335 | if (vsyncRate != targetRate) { |
| 336 | displayEvent.setVsyncRate(targetRate); |
| 337 | vsyncRate = targetRate; |
| 338 | } |
| 339 | if (targetRate) { |
Jason Sams | 963a2fb | 2012-02-09 14:36:14 -0800 | [diff] [blame] | 340 | drawOnce |= rsc->mIO.playCoreCommands(rsc, displayEvent.getFd()); |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 341 | while (displayEvent.getEvents(eventBuffer, 1) != 0) { |
| 342 | //ALOGE("vs2 time past %lld", (rsc->getTime() - eventBuffer[0].header.timestamp) / 1000000); |
| 343 | } |
| 344 | } else |
| 345 | #endif |
| 346 | { |
Jason Sams | 963a2fb | 2012-02-09 14:36:14 -0800 | [diff] [blame] | 347 | drawOnce |= rsc->mIO.playCoreCommands(rsc, -1); |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 348 | } |
Alex Sakhartchouk | 0cae59f | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 349 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 350 | if ((rsc->mRootScript.get() != nullptr) && rsc->mHasSurface && |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 351 | (targetRate || drawOnce) && !rsc->mPaused) { |
| 352 | |
| 353 | drawOnce = false; |
| 354 | targetRate = ((rsc->runRootScript() + 15) / 16); |
| 355 | |
| 356 | if (rsc->props.mLogVisual) { |
| 357 | rsc->displayDebugStats(); |
| 358 | } |
| 359 | |
| 360 | rsc->timerSet(RS_TIMER_CLEAR_SWAP); |
| 361 | rsc->mHal.funcs.swap(rsc); |
| 362 | rsc->timerFrame(); |
| 363 | rsc->timerSet(RS_TIMER_INTERNAL); |
| 364 | rsc->timerPrint(); |
| 365 | rsc->timerReset(); |
| 366 | } |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 367 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 368 | #endif |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 369 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 370 | |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 371 | //ALOGV("%p RS Thread exiting", rsc); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 372 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 373 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 374 | if (rsc->mIsGraphicsContext) { |
| 375 | pthread_mutex_lock(&gInitMutex); |
| 376 | rsc->deinitEGL(); |
| 377 | pthread_mutex_unlock(&gInitMutex); |
| 378 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 379 | #endif |
Jason Sams | 33b6e3b | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 380 | |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 381 | //ALOGV("%p RS Thread exited", rsc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 382 | return nullptr; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 385 | void Context::destroyWorkerThreadResources() { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 386 | //ALOGV("destroyWorkerThreadResources 1"); |
Jason Sams | 2e8665d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 387 | ObjectBase::zeroAllUserRef(this); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 388 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 389 | if (mIsGraphicsContext) { |
| 390 | mRaster.clear(); |
| 391 | mFragment.clear(); |
| 392 | mVertex.clear(); |
| 393 | mFragmentStore.clear(); |
| 394 | mFont.clear(); |
| 395 | mRootScript.clear(); |
| 396 | mStateRaster.deinit(this); |
| 397 | mStateVertex.deinit(this); |
| 398 | mStateFragment.deinit(this); |
| 399 | mStateFragmentStore.deinit(this); |
| 400 | mStateFont.deinit(this); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 401 | mStateSampler.deinit(this); |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 402 | mFBOCache.deinit(this); |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 403 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 404 | #endif |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 405 | ObjectBase::freeAllChildren(this); |
Jason Sams | cf912de | 2011-01-09 16:09:51 -0800 | [diff] [blame] | 406 | mExit = true; |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 407 | //ALOGV("destroyWorkerThreadResources 2"); |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 410 | void Context::printWatchdogInfo(void *ctx) { |
| 411 | Context *rsc = (Context *)ctx; |
Jason Sams | ee80344 | 2011-10-13 16:05:27 -0700 | [diff] [blame] | 412 | if (rsc->watchdog.command && rsc->watchdog.file) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 413 | ALOGE("RS watchdog timeout: %i %s line %i %s", rsc->watchdog.inRoot, |
Jason Sams | ee80344 | 2011-10-13 16:05:27 -0700 | [diff] [blame] | 414 | rsc->watchdog.command, rsc->watchdog.line, rsc->watchdog.file); |
| 415 | } else { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 416 | ALOGE("RS watchdog timeout: %i", rsc->watchdog.inRoot); |
Jason Sams | ee80344 | 2011-10-13 16:05:27 -0700 | [diff] [blame] | 417 | } |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 421 | void Context::setPriority(int32_t p) { |
Jason Sams | cfaec17 | 2015-01-23 13:42:43 -0800 | [diff] [blame] | 422 | switch (p) { |
| 423 | // The public API will always send NORMAL_GRAPHICS |
| 424 | // for normal, we adjust here |
| 425 | case RS_THREAD_PRIORITY_NORMAL_GRAPHICS: |
| 426 | if (mIsGraphicsContext) { |
| 427 | break; |
| 428 | } else { |
| 429 | if (mHal.flags & RS_CONTEXT_LOW_LATENCY) { |
| 430 | p = RS_THREAD_PRIORITY_LOW_LATENCY; |
| 431 | } else { |
| 432 | p = RS_THREAD_PRIORITY_NORMAL; |
| 433 | } |
| 434 | } |
| 435 | case RS_THREAD_PRIORITY_LOW: |
| 436 | break; |
| 437 | } |
| 438 | |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 439 | // Note: If we put this in the proper "background" policy |
| 440 | // the wallpapers can become completly unresponsive at times. |
| 441 | // This is probably not what we want for something the user is actively |
| 442 | // looking at. |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 443 | mThreadPriority = p; |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 444 | setpriority(PRIO_PROCESS, mNativeThreadId, p); |
Jason Sams | 9719bd4 | 2012-01-12 14:22:21 -0800 | [diff] [blame] | 445 | mHal.funcs.setPriority(this, mThreadPriority); |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 448 | Context::Context() { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 449 | mDev = nullptr; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 450 | mRunning = false; |
| 451 | mExit = false; |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 452 | mPaused = false; |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 453 | mObjHead = nullptr; |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 454 | mError = RS_ERROR_NONE; |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 455 | mTargetSdkVersion = 14; |
Alex Sakhartchouk | 7b3e9bd | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 456 | mDPI = 96; |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 457 | mIsContextLite = false; |
Stephen Hines | 86c6b5f | 2011-10-31 14:07:54 -0700 | [diff] [blame] | 458 | memset(&watchdog, 0, sizeof(watchdog)); |
Jason Sams | f274827 | 2013-11-26 18:10:59 -0800 | [diff] [blame] | 459 | memset(&mHal, 0, sizeof(mHal)); |
Tim Murray | 0e92fa3 | 2012-11-06 14:36:38 -0800 | [diff] [blame] | 460 | mForceCpu = false; |
Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 461 | mContextType = RS_CONTEXT_TYPE_NORMAL; |
verena beckham | f502980 | 2015-05-22 16:51:42 +0100 | [diff] [blame] | 462 | mOptLevel = 3; |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 463 | mSynchronous = false; |
Jason Sams | 4efe3d3 | 2015-03-18 18:28:06 -0700 | [diff] [blame] | 464 | mFatalErrorOccured = false; |
Jason Sams | 95fe644 | 2015-05-18 18:40:47 -0700 | [diff] [blame] | 465 | |
| 466 | memset(mCacheDir, 0, sizeof(mCacheDir)); |
| 467 | #ifdef RS_COMPATIBILITY_LIB |
| 468 | memset(nativeLibDir, 0, sizeof(nativeLibDir)); |
| 469 | #endif |
Tim Murray | 0e92fa3 | 2012-11-06 14:36:38 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Jason Sams | 95fe644 | 2015-05-18 18:40:47 -0700 | [diff] [blame] | 472 | void Context::setCacheDir(const char * cacheDir_arg, uint32_t length) { |
| 473 | if (!hasSetCacheDir) { |
| 474 | if (length <= PATH_MAX) { |
| 475 | memcpy(mCacheDir, cacheDir_arg, length); |
| 476 | mCacheDir[length] = 0; |
| 477 | hasSetCacheDir = true; |
| 478 | } else { |
| 479 | setError(RS_ERROR_BAD_VALUE, "Invalid path"); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
Stephen McGroarty | d5164d5 | 2015-05-08 15:31:49 +0100 | [diff] [blame] | 484 | void Context::waitForDebugger() { |
| 485 | while (!gDebuggerPresent) { |
| 486 | sleep(0); |
| 487 | } |
| 488 | } |
Jason Sams | 95fe644 | 2015-05-18 18:40:47 -0700 | [diff] [blame] | 489 | |
Tim Murray | 0e92fa3 | 2012-11-06 14:36:38 -0800 | [diff] [blame] | 490 | Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc, |
Tim Murray | 84e3dea | 2013-09-09 16:12:51 -0700 | [diff] [blame] | 491 | RsContextType ct, uint32_t flags) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 492 | Context * rsc = new Context(); |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 493 | |
Tim Murray | 84e3dea | 2013-09-09 16:12:51 -0700 | [diff] [blame] | 494 | if (flags & RS_CONTEXT_LOW_LATENCY) { |
| 495 | rsc->mForceCpu = true; |
| 496 | } |
| 497 | if (flags & RS_CONTEXT_SYNCHRONOUS) { |
| 498 | rsc->mSynchronous = true; |
| 499 | } |
Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 500 | rsc->mContextType = ct; |
Jason Sams | 416f4b6 | 2014-06-25 15:45:36 -0700 | [diff] [blame] | 501 | rsc->mHal.flags = flags; |
Tim Murray | 0e92fa3 | 2012-11-06 14:36:38 -0800 | [diff] [blame] | 502 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 503 | if (!rsc->initContext(dev, sc)) { |
| 504 | delete rsc; |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 505 | return nullptr; |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 506 | } |
Stephen McGroarty | d5164d5 | 2015-05-08 15:31:49 +0100 | [diff] [blame] | 507 | |
| 508 | if (flags & RS_CONTEXT_WAIT_FOR_ATTACH) { |
| 509 | rsc->waitForDebugger(); |
| 510 | } |
| 511 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 512 | return rsc; |
| 513 | } |
| 514 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 515 | Context * Context::createContextLite() { |
| 516 | Context * rsc = new Context(); |
| 517 | rsc->mIsContextLite = true; |
| 518 | return rsc; |
| 519 | } |
| 520 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 521 | bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 522 | pthread_mutex_lock(&gInitMutex); |
| 523 | |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 524 | mIO.init(); |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 525 | mIO.setTimeoutCallback(printWatchdogInfo, this, 2e9); |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 526 | |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 527 | dev->addContext(this); |
| 528 | mDev = dev; |
Jason Sams | 6b8552a | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 529 | if (sc) { |
| 530 | mUserSurfaceConfig = *sc; |
| 531 | } else { |
| 532 | memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig)); |
| 533 | } |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 534 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 535 | mIsGraphicsContext = sc != nullptr; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 536 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 537 | int status; |
| 538 | pthread_attr_t threadAttr; |
| 539 | |
Jason Sams | fb03a22 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 540 | pthread_mutex_unlock(&gInitMutex); |
| 541 | |
| 542 | // Global init done at this point. |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 543 | |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 544 | status = pthread_attr_init(&threadAttr); |
| 545 | if (status) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 546 | ALOGE("Failed to init thread attribute."); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 547 | return false; |
Jason Sams | a658e90 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 550 | mHasSurface = false; |
Stephen Hines | 4c368af | 2015-05-06 00:43:02 -0700 | [diff] [blame] | 551 | mDriverName = NULL; |
Jason Sams | 992a0b7 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 552 | |
Jason Sams | 24371d9 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 553 | timerInit(); |
Jason Sams | a891933 | 2009-09-24 15:42:52 -0700 | [diff] [blame] | 554 | timerSet(RS_TIMER_INTERNAL); |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 555 | if (mSynchronous) { |
| 556 | threadProc(this); |
Xiaofei Wan | fea96e8 | 2014-03-31 16:43:15 +0800 | [diff] [blame] | 557 | |
| 558 | if (mError != RS_ERROR_NONE) { |
| 559 | ALOGE("Errors during thread init (sync mode)"); |
| 560 | return false; |
| 561 | } |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 562 | } else { |
| 563 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
| 564 | if (status) { |
| 565 | ALOGE("Failed to start rs context thread."); |
| 566 | return false; |
| 567 | } |
| 568 | while (!mRunning && (mError == RS_ERROR_NONE)) { |
| 569 | usleep(100); |
| 570 | } |
Jason Sams | 5086938 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 571 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 572 | if (mError != RS_ERROR_NONE) { |
| 573 | ALOGE("Errors during thread init"); |
| 574 | return false; |
| 575 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 576 | |
Tim Murray | 4d252d6 | 2012-11-29 14:37:59 -0800 | [diff] [blame] | 577 | pthread_attr_destroy(&threadAttr); |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 578 | } |
Jason Sams | 5c1c79a | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 579 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 582 | Context::~Context() { |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 583 | //ALOGV("%p Context::~Context", this); |
Jason Sams | cf912de | 2011-01-09 16:09:51 -0800 | [diff] [blame] | 584 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 585 | if (!mIsContextLite) { |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 586 | mPaused = false; |
| 587 | void *res; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 588 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 589 | mIO.shutdown(); |
Sangkyu Lee | bcba6f6 | 2014-04-01 15:22:13 +0900 | [diff] [blame] | 590 | if (!mSynchronous) { |
| 591 | pthread_join(mThreadId, &res); |
| 592 | } |
Jason Sams | 5f27d6f | 2012-02-07 15:32:08 -0800 | [diff] [blame] | 593 | rsAssert(mExit); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 594 | |
Xiaofei Wan | fea96e8 | 2014-03-31 16:43:15 +0800 | [diff] [blame] | 595 | if (mHal.funcs.shutdownDriver && mHal.drv) { |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 596 | mHal.funcs.shutdownDriver(this); |
| 597 | } |
| 598 | |
| 599 | // Global structure cleanup. |
| 600 | pthread_mutex_lock(&gInitMutex); |
| 601 | if (mDev) { |
| 602 | mDev->removeContext(this); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 603 | mDev = nullptr; |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 604 | } |
| 605 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 51462c5 | 2011-01-25 00:26:25 -0800 | [diff] [blame] | 606 | } |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 607 | //ALOGV("%p Context::~Context done", this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 610 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 611 | void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 612 | rsAssert(mIsGraphicsContext); |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 613 | mHal.funcs.setSurface(this, w, h, sur); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 614 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 615 | mHasSurface = sur != nullptr; |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 616 | mWidth = w; |
| 617 | mHeight = h; |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 618 | |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 619 | if (mWidth && mHeight) { |
Jason Sams | 771565f | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 620 | mStateVertex.updateSize(this); |
Alex Sakhartchouk | a544b63 | 2011-07-19 17:50:29 -0700 | [diff] [blame] | 621 | mFBOCache.updateSize(); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 625 | uint32_t Context::getCurrentSurfaceWidth() const { |
| 626 | for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 627 | if (mFBOCache.mHal.state.colorTargets[i] != nullptr) { |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 628 | return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimX(); |
| 629 | } |
| 630 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 631 | if (mFBOCache.mHal.state.depthTarget != nullptr) { |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 632 | return mFBOCache.mHal.state.depthTarget->getType()->getDimX(); |
| 633 | } |
| 634 | return mWidth; |
| 635 | } |
| 636 | |
| 637 | uint32_t Context::getCurrentSurfaceHeight() const { |
| 638 | for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 639 | if (mFBOCache.mHal.state.colorTargets[i] != nullptr) { |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 640 | return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimY(); |
| 641 | } |
| 642 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 643 | if (mFBOCache.mHal.state.depthTarget != nullptr) { |
Alex Sakhartchouk | a74a8f6 | 2011-11-16 12:22:10 -0800 | [diff] [blame] | 644 | return mFBOCache.mHal.state.depthTarget->getType()->getDimY(); |
| 645 | } |
| 646 | return mHeight; |
| 647 | } |
| 648 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 649 | void Context::pause() { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 650 | rsAssert(mIsGraphicsContext); |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 651 | mPaused = true; |
| 652 | } |
| 653 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 654 | void Context::resume() { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 655 | rsAssert(mIsGraphicsContext); |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 656 | mPaused = false; |
| 657 | } |
| 658 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 659 | void Context::setRootScript(Script *s) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 660 | rsAssert(mIsGraphicsContext); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 661 | mRootScript.set(s); |
| 662 | } |
| 663 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 664 | void Context::setProgramStore(ProgramStore *pfs) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 665 | rsAssert(mIsGraphicsContext); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 666 | if (pfs == nullptr) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 667 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 668 | } else { |
| 669 | mFragmentStore.set(pfs); |
| 670 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 673 | void Context::setProgramFragment(ProgramFragment *pf) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 674 | rsAssert(mIsGraphicsContext); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 675 | if (pf == nullptr) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 676 | mFragment.set(mStateFragment.mDefault); |
| 677 | } else { |
| 678 | mFragment.set(pf); |
| 679 | } |
Jason Sams | cfb1d11 | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 682 | void Context::setProgramRaster(ProgramRaster *pr) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 683 | rsAssert(mIsGraphicsContext); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 684 | if (pr == nullptr) { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 685 | mRaster.set(mStateRaster.mDefault); |
| 686 | } else { |
| 687 | mRaster.set(pr); |
| 688 | } |
| 689 | } |
| 690 | |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 691 | void Context::setProgramVertex(ProgramVertex *pv) { |
Jason Sams | 4820e8b | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 692 | rsAssert(mIsGraphicsContext); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 693 | if (pv == nullptr) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 694 | mVertex.set(mStateVertex.mDefault); |
| 695 | } else { |
| 696 | mVertex.set(pv); |
| 697 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 700 | void Context::setFont(Font *f) { |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 701 | rsAssert(mIsGraphicsContext); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 702 | if (f == nullptr) { |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 703 | mFont.set(mStateFont.mDefault); |
| 704 | } else { |
| 705 | mFont.set(f); |
| 706 | } |
| 707 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 708 | #endif |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 709 | |
Jason Sams | f274827 | 2013-11-26 18:10:59 -0800 | [diff] [blame] | 710 | void Context::finish() { |
| 711 | if (mHal.funcs.finish) { |
| 712 | mHal.funcs.finish(this); |
| 713 | } |
| 714 | } |
| 715 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 716 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 717 | rsAssert(!obj->getName()); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 718 | obj->setName(name, len); |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 719 | mNames.add(obj); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 722 | void Context::removeName(ObjectBase *obj) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 723 | for (size_t ct=0; ct < mNames.size(); ct++) { |
| 724 | if (obj == mNames[ct]) { |
| 725 | mNames.removeAt(ct); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 726 | return; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 731 | RsMessageToClientType Context::peekMessageToClient(size_t *receiveLen, uint32_t *subID) { |
| 732 | return (RsMessageToClientType)mIO.getClientHeader(receiveLen, subID); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 735 | RsMessageToClientType Context::getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen) { |
| 736 | return (RsMessageToClientType)mIO.getClientPayload(data, receiveLen, subID, bufferLen); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 739 | bool Context::sendMessageToClient(const void *data, RsMessageToClientType cmdID, |
| 740 | uint32_t subID, size_t len, bool waitForSpace) const { |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 741 | |
Jason Sams | 4961cce | 2013-04-11 16:11:46 -0700 | [diff] [blame] | 742 | pthread_mutex_lock(&gMessageMutex); |
| 743 | bool ret = mIO.sendToClient(cmdID, subID, data, len, waitForSpace); |
| 744 | pthread_mutex_unlock(&gMessageMutex); |
| 745 | return ret; |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 748 | void Context::initToClient() { |
| 749 | while (!mRunning) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 750 | usleep(100); |
| 751 | } |
| 752 | } |
| 753 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 754 | void Context::deinitToClient() { |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 755 | mIO.clientShutdown(); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 756 | } |
Jason Sams | 5086938 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 757 | |
Jason Sams | 87319de | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 758 | void Context::setError(RsError e, const char *msg) const { |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 759 | mError = e; |
Jason Sams | 4efe3d3 | 2015-03-18 18:28:06 -0700 | [diff] [blame] | 760 | |
| 761 | if (mError >= RS_ERROR_FATAL_DEBUG) { |
| 762 | // If a FATAL error occurred, set the flag to indicate the process |
| 763 | // will be goign down |
| 764 | mFatalErrorOccured = true; |
| 765 | } |
| 766 | |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 767 | sendMessageToClient(msg, RS_MESSAGE_TO_CLIENT_ERROR, e, strlen(msg) + 1, true); |
Jason Sams | a2cf755 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 771 | void Context::dumpDebug() const { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 772 | ALOGE("RS Context debug %p", this); |
| 773 | ALOGE("RS Context debug"); |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 774 | |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 775 | ALOGE(" RS width %i, height %i", mWidth, mHeight); |
| 776 | ALOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused); |
| 777 | ALOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId); |
Jason Sams | 13e2634 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 778 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 779 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 780 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a44cb29 | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 781 | // |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 782 | |
| 783 | namespace android { |
| 784 | namespace renderscript { |
| 785 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 786 | void rsi_ContextFinish(Context *rsc) { |
Jason Sams | f274827 | 2013-11-26 18:10:59 -0800 | [diff] [blame] | 787 | rsc->finish(); |
Jason Sams | 8c88090 | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 788 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 789 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 790 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 791 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 792 | Script *s = static_cast<Script *>(vs); |
| 793 | rsc->setRootScript(s); |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 794 | #endif |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Tim Murray | ea6e062 | 2015-04-07 15:43:11 -0700 | [diff] [blame] | 797 | void rsi_ContextSetCacheDir(Context *rsc, const char *cacheDir, size_t cacheDir_length) { |
| 798 | rsc->setCacheDir(cacheDir, cacheDir_length); |
| 799 | } |
| 800 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 801 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 802 | Sampler *s = static_cast<Sampler *>(vs); |
| 803 | |
| 804 | if (slot > RS_MAX_SAMPLER_SLOT) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 805 | ALOGE("Invalid sampler slot"); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | |
| 809 | s->bindToContext(&rsc->mStateSampler, slot); |
| 810 | } |
| 811 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 812 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 813 | void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) { |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 814 | ProgramStore *pfs = static_cast<ProgramStore *>(vpfs); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 815 | rsc->setProgramStore(pfs); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 818 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 819 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 820 | rsc->setProgramFragment(pf); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 823 | void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 824 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 825 | rsc->setProgramRaster(pr); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 828 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 829 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 830 | rsc->setProgramVertex(pv); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 833 | void rsi_ContextBindFont(Context *rsc, RsFont vfont) { |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 834 | Font *font = static_cast<Font *>(vfont); |
| 835 | rsc->setFont(font); |
| 836 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 837 | #endif |
Alex Sakhartchouk | d3e0ad4 | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 838 | |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 839 | void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 840 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Alex Sakhartchouk | 70b83c1 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 841 | rsc->assignName(ob, name, name_length); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 842 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 843 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 844 | void rsi_ObjDestroy(Context *rsc, void *optr) { |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 845 | ObjectBase *ob = static_cast<ObjectBase *>(optr); |
Jason Sams | 707aaf3 | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 846 | rsc->removeName(ob); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 847 | ob->decUserRef(); |
Jason Sams | 707aaf3 | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 850 | #ifndef RS_COMPATIBILITY_LIB |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 851 | void rsi_ContextPause(Context *rsc) { |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 852 | rsc->pause(); |
| 853 | } |
| 854 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 855 | void rsi_ContextResume(Context *rsc) { |
Jason Sams | 86f1b23 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 856 | rsc->resume(); |
| 857 | } |
| 858 | |
Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 859 | void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, RsNativeWindow sur) { |
Mathias Agopian | fa40286 | 2010-02-12 14:04:35 -0800 | [diff] [blame] | 860 | rsc->setSurface(w, h, sur); |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 861 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 862 | #endif |
Jason Sams | 613cad1 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 863 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 864 | void rsi_ContextSetPriority(Context *rsc, int32_t p) { |
Jason Sams | 1583244 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 865 | rsc->setPriority(p); |
Jason Sams | 458f2dc | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 868 | void rsi_ContextDump(Context *rsc, int32_t bits) { |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 869 | ObjectBase::dumpAll(rsc); |
| 870 | } |
| 871 | |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 872 | void rsi_ContextDestroyWorker(Context *rsc) { |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 873 | rsc->destroyWorkerThreadResources(); |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 876 | void rsi_ContextDestroy(Context *rsc) { |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 877 | //ALOGE("%p rsContextDestroy", rsc); |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 878 | rsContextDestroyWorker(rsc); |
Jason Sams | 1dcefab | 2010-12-09 12:19:46 -0800 | [diff] [blame] | 879 | delete rsc; |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 880 | //ALOGV("%p rsContextDestroy done", rsc); |
Jason Sams | 1dcefab | 2010-12-09 12:19:46 -0800 | [diff] [blame] | 881 | } |
| 882 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 883 | RsMessageToClientType rsi_ContextPeekMessage(Context *rsc, |
Jason Sams | 186e591 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 884 | size_t * receiveLen, size_t receiveLen_length, |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 885 | uint32_t * subID, size_t subID_length) { |
| 886 | return rsc->peekMessageToClient(receiveLen, subID); |
Jason Sams | aad4bc5 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 889 | RsMessageToClientType rsi_ContextGetMessage(Context *rsc, void * data, size_t data_length, |
Jason Sams | 186e591 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 890 | size_t * receiveLen, size_t receiveLen_length, |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 891 | uint32_t * subID, size_t subID_length) { |
Jason Sams | 186e591 | 2011-04-26 14:50:00 -0700 | [diff] [blame] | 892 | rsAssert(subID_length == sizeof(uint32_t)); |
| 893 | rsAssert(receiveLen_length == sizeof(size_t)); |
Jason Sams | 1a4efa3 | 2011-05-17 15:01:29 -0700 | [diff] [blame] | 894 | return rsc->getMessageToClient(data, receiveLen, subID, data_length); |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 897 | void rsi_ContextInitToClient(Context *rsc) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 898 | rsc->initToClient(); |
| 899 | } |
| 900 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 901 | void rsi_ContextDeinitToClient(Context *rsc) { |
Jason Sams | 8c401ef | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 902 | rsc->deinitToClient(); |
| 903 | } |
| 904 | |
Jason Sams | 7026520 | 2013-02-05 19:20:47 -0800 | [diff] [blame] | 905 | void rsi_ContextSendMessage(Context *rsc, uint32_t id, const uint8_t *data, size_t len) { |
| 906 | rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, id, len, true); |
| 907 | } |
| 908 | |
Tim Murray | 397b0b1 | 2014-01-07 15:35:08 -0800 | [diff] [blame] | 909 | // implementation of handcode LF_ObjDestroy |
| 910 | // required so nObjDestroy can be run from finalizer without blocking |
| 911 | void LF_ObjDestroy_handcode(const Context *rsc, RsAsyncVoidPtr objPtr) { |
| 912 | if (((Context *)rsc)->isSynchronous()) { |
| 913 | rsi_ObjDestroy((Context *)rsc, objPtr); |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | // struct has two parts: |
| 918 | // RsPlaybackRemoteHeader (cmdID and bytes) |
| 919 | // RS_CMD_ObjDestroy (ptr) |
| 920 | struct destroyCmd { |
| 921 | uint32_t cmdID; |
| 922 | uint32_t bytes; |
| 923 | RsAsyncVoidPtr ptr; |
| 924 | }; |
| 925 | |
| 926 | destroyCmd cmd; |
| 927 | cmd.cmdID = RS_CMD_ID_ObjDestroy; |
| 928 | cmd.bytes = sizeof(RsAsyncVoidPtr); |
| 929 | cmd.ptr = objPtr; |
| 930 | ThreadIO *io = &((Context *)rsc)->mIO; |
| 931 | io->coreWrite((void*)&cmd, sizeof(destroyCmd)); |
| 932 | |
| 933 | } |
| 934 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Tim Murray | c2ce707 | 2013-07-17 18:38:53 -0700 | [diff] [blame] | 938 | extern "C" RsContext rsContextCreate(RsDevice vdev, uint32_t version, uint32_t sdkVersion, |
Tim Murray | 84e3dea | 2013-09-09 16:12:51 -0700 | [diff] [blame] | 939 | RsContextType ct, uint32_t flags) { |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 940 | //ALOGV("rsContextCreate dev=%p", vdev); |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 941 | Device * dev = static_cast<Device *>(vdev); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 942 | Context *rsc = Context::createContext(dev, nullptr, ct, flags); |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 943 | if (rsc) { |
| 944 | rsc->setTargetSdkVersion(sdkVersion); |
| 945 | } |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 946 | return rsc; |
| 947 | } |
| 948 | |
Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 949 | extern "C" void rsaContextSetNativeLibDir(RsContext con, char *libDir, size_t length) { |
Miao Wang | 9a6afb6 | 2015-03-27 14:24:00 -0700 | [diff] [blame] | 950 | #ifdef RS_COMPATIBILITY_LIB |
Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 951 | Context *rsc = static_cast<Context *>(con); |
| 952 | rsc->setNativeLibDir(libDir, length); |
Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 953 | #endif |
Miao Wang | 9a6afb6 | 2015-03-27 14:24:00 -0700 | [diff] [blame] | 954 | } |
Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 955 | |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 956 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 957 | RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 958 | uint32_t sdkVersion, RsSurfaceConfig sc, |
| 959 | uint32_t dpi) { |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 960 | //ALOGV("rsContextCreateGL dev=%p", vdev); |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 961 | Device * dev = static_cast<Device *>(vdev); |
| 962 | Context *rsc = Context::createContext(dev, &sc); |
Jason Sams | 9544f76 | 2011-07-13 16:09:42 -0700 | [diff] [blame] | 963 | if (rsc) { |
Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 964 | rsc->setTargetSdkVersion(sdkVersion); |
Jason Sams | 9544f76 | 2011-07-13 16:09:42 -0700 | [diff] [blame] | 965 | rsc->setDPI(dpi); |
| 966 | } |
Tim Murray | 20f62ca | 2013-05-09 11:57:35 -0700 | [diff] [blame] | 967 | //ALOGV("%p rsContextCreateGL ret", rsc); |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 968 | return rsc; |
| 969 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 970 | #endif |
Jason Sams | 789ca83 | 2011-05-18 17:36:02 -0700 | [diff] [blame] | 971 | |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 972 | // Only to be called at a3d load time, before object is visible to user |
| 973 | // not thread safe |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 974 | void rsaGetName(RsContext con, void * obj, const char **name) { |
Alex Sakhartchouk | dc763f3 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 975 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 976 | (*name) = ob->getName(); |
| 977 | } |