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