Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "rsDevice.h" |
| 18 | #include "rsContext.h" |
| 19 | #include "rsThreadIO.h" |
Mathias Agopian | 3142f4f | 2009-06-22 18:01:09 -0700 | [diff] [blame] | 20 | #include <ui/FramebufferNativeWindow.h> |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 21 | #include <ui/PixelFormat.h> |
Mathias Agopian | 5cbb940 | 2010-02-12 12:00:38 -0800 | [diff] [blame] | 22 | #include <ui/egl/android_natives.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <sys/resource.h> |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 26 | #include <sched.h> |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 27 | |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 28 | #include <cutils/properties.h> |
| 29 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 30 | #include <GLES/gl.h> |
| 31 | #include <GLES/glext.h> |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 32 | #include <GLES2/gl2.h> |
| 33 | #include <GLES2/gl2ext.h> |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 34 | |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 35 | #include <cutils/sched_policy.h> |
Jason Sams | f3470ed | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 36 | #include <sys/syscall.h> |
| 37 | #include <string.h> |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 38 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | using namespace android; |
| 40 | using namespace android::renderscript; |
| 41 | |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 42 | pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER; |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 43 | pthread_mutex_t Context::gLibMutex = PTHREAD_MUTEX_INITIALIZER; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 45 | bool Context::initGLThread() { |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 46 | pthread_mutex_lock(&gInitMutex); |
| 47 | LOGV("initGLThread start %p", this); |
| 48 | |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 49 | if (!mHal.funcs.initGraphics(this)) { |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 50 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 51 | LOGE("%p, initGraphics failed", this); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 52 | return false; |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 55 | const char * ext = (const char *)glGetString(GL_EXTENSIONS); |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 56 | |
| 57 | glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs); |
| 58 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors); |
| 59 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits); |
| 60 | |
| 61 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors); |
| 62 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits); |
| 63 | |
| 64 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits); |
| 65 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors); |
| 66 | |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 67 | mGL.OES_texture_npot = NULL != strstr(ext, "GL_OES_texture_npot"); |
| 68 | mGL.GL_IMG_texture_npot = NULL != strstr(ext, "GL_IMG_texture_npot"); |
| 69 | mGL.GL_NV_texture_npot_2D_mipmap = NULL != strstr(ext, "GL_NV_texture_npot_2D_mipmap"); |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 70 | mGL.EXT_texture_max_aniso = 1.0f; |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 71 | bool hasAniso = NULL != strstr(ext, "GL_EXT_texture_filter_anisotropic"); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 72 | if (hasAniso) { |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 73 | glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mGL.EXT_texture_max_aniso); |
| 74 | } |
| 75 | |
| 76 | LOGV("initGLThread end %p", this); |
| 77 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 78 | return true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 81 | void Context::deinitEGL() { |
Jason Sams | cfc0436 | 2010-09-14 14:59:03 -0700 | [diff] [blame] | 82 | LOGV("%p, deinitEGL", this); |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 83 | mHal.funcs.shutdownGraphics(this); |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 86 | Context::PushState::PushState(Context *con) { |
| 87 | mRsc = con; |
Jason Sams | 07078e3 | 2011-02-23 14:47:17 -0800 | [diff] [blame] | 88 | if (con->mIsGraphicsContext) { |
| 89 | mFragment.set(con->getProgramFragment()); |
| 90 | mVertex.set(con->getProgramVertex()); |
| 91 | mStore.set(con->getProgramStore()); |
| 92 | mRaster.set(con->getProgramRaster()); |
| 93 | mFont.set(con->getFont()); |
| 94 | } |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | Context::PushState::~PushState() { |
Jason Sams | 07078e3 | 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 | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 107 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 108 | uint32_t Context::runScript(Script *s) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 109 | PushState(this); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 110 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 111 | uint32_t ret = s->run(this); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 112 | return ret; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 115 | void Context::checkError(const char *msg, bool isFatal) const { |
| 116 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 117 | GLenum err = glGetError(); |
| 118 | if (err != GL_NO_ERROR) { |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 119 | char buf[1024]; |
| 120 | snprintf(buf, sizeof(buf), "GL Error = 0x%08x, from: %s", err, msg); |
| 121 | |
| 122 | if (isFatal) { |
| 123 | setError(RS_ERROR_FATAL_DRIVER, buf); |
| 124 | } else { |
| 125 | switch (err) { |
| 126 | case GL_OUT_OF_MEMORY: |
| 127 | setError(RS_ERROR_OUT_OF_MEMORY, buf); |
| 128 | break; |
| 129 | default: |
| 130 | setError(RS_ERROR_DRIVER, buf); |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | LOGE("%p, %s", this, buf); |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 136 | } |
| 137 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 138 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 139 | uint32_t Context::runRootScript() { |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 140 | glViewport(0, 0, mWidth, mHeight); |
Jason Sams | 67c6844 | 2009-08-25 17:09:59 -0700 | [diff] [blame] | 141 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 142 | timerSet(RS_TIMER_SCRIPT); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 143 | mStateFragmentStore.mLast.clear(); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 144 | uint32_t ret = runScript(mRootScript.get()); |
Jason Sams | c7412b3 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 145 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 146 | checkError("runRootScript"); |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 147 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 150 | uint64_t Context::getTime() const { |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 151 | struct timespec t; |
| 152 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 153 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); |
| 154 | } |
| 155 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 156 | void Context::timerReset() { |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 157 | for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { |
| 158 | mTimers[ct] = 0; |
| 159 | } |
| 160 | } |
| 161 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 162 | void Context::timerInit() { |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 163 | mTimeLast = getTime(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 164 | mTimeFrame = mTimeLast; |
| 165 | mTimeLastFrame = mTimeLast; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 166 | mTimerActive = RS_TIMER_INTERNAL; |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 167 | mAverageFPSFrameCount = 0; |
| 168 | mAverageFPSStartTime = mTimeLast; |
| 169 | mAverageFPS = 0; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 170 | timerReset(); |
| 171 | } |
| 172 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 173 | void Context::timerFrame() { |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 174 | mTimeLastFrame = mTimeFrame; |
| 175 | mTimeFrame = getTime(); |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 176 | // Update average fps |
| 177 | const uint64_t averageFramerateInterval = 1000 * 1000000; |
| 178 | mAverageFPSFrameCount ++; |
| 179 | uint64_t inverval = mTimeFrame - mAverageFPSStartTime; |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 180 | if (inverval >= averageFramerateInterval) { |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 181 | inverval = inverval / 1000000; |
| 182 | mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval; |
| 183 | mAverageFPSFrameCount = 0; |
| 184 | mAverageFPSStartTime = mTimeFrame; |
| 185 | } |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 188 | void Context::timerSet(Timers tm) { |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 189 | uint64_t last = mTimeLast; |
| 190 | mTimeLast = getTime(); |
| 191 | mTimers[mTimerActive] += mTimeLast - last; |
| 192 | mTimerActive = tm; |
| 193 | } |
| 194 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 195 | void Context::timerPrint() { |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 196 | double total = 0; |
| 197 | for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { |
| 198 | total += mTimers[ct]; |
| 199 | } |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 200 | uint64_t frame = mTimeFrame - mTimeLastFrame; |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 201 | mTimeMSLastFrame = frame / 1000000; |
| 202 | mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; |
| 203 | mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 204 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 205 | |
| 206 | if (props.mLogTimes) { |
Alex Sakhartchouk | 98bfe5d | 2010-10-18 17:18:50 -0700 | [diff] [blame] | 207 | LOGV("RS: Frame (%i), Script %2.1f%% (%i), Swap %2.1f%% (%i), Idle %2.1f%% (%lli), Internal %2.1f%% (%lli), Avg fps: %u", |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 208 | mTimeMSLastFrame, |
| 209 | 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, |
| 210 | 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, |
| 211 | 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 212 | 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000, |
| 213 | mAverageFPS); |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 214 | } |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 217 | bool Context::setupCheck() { |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 218 | if (!mShaderCache.lookup(this, mVertex.get(), mFragment.get())) { |
| 219 | LOGE("Context::setupCheck() 1 fail"); |
| 220 | return false; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 221 | } |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 222 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 223 | mFragmentStore->setup(this, &mStateFragmentStore); |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 224 | mFragment->setupGL2(this, &mStateFragment, &mShaderCache); |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 225 | mRaster->setup(this, &mStateRaster); |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 226 | mVertex->setupGL2(this, &mStateVertex, &mShaderCache); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 227 | mFBOCache.setupGL2(this); |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 228 | return true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 231 | void Context::setupProgramStore() { |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 232 | mFragmentStore->setup(this, &mStateFragmentStore); |
Alex Sakhartchouk | feede2a | 2010-10-01 10:54:06 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 235 | static bool getProp(const char *str) { |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 236 | char buf[PROPERTY_VALUE_MAX]; |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 237 | property_get(str, buf, "0"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 238 | return 0 != strcmp(buf, "0"); |
| 239 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 240 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 241 | void Context::displayDebugStats() { |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 242 | char buffer[128]; |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 243 | sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript); |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 244 | float oldR, oldG, oldB, oldA; |
| 245 | mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 246 | uint32_t bufferLen = strlen(buffer); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 247 | |
Alex Sakhartchouk | 20a9354 | 2011-03-17 13:49:38 -0700 | [diff] [blame] | 248 | ObjectBaseRef<Font> lastFont(getFont()); |
| 249 | setFont(NULL); |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 250 | float shadowCol = 0.1f; |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 251 | mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f); |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 252 | mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 253 | |
Alex Sakhartchouk | 10825a0 | 2010-10-05 11:33:27 -0700 | [diff] [blame] | 254 | mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f); |
Alex Sakhartchouk | 76322af | 2010-10-05 13:23:55 -0700 | [diff] [blame] | 255 | mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 256 | |
Alex Sakhartchouk | 20a9354 | 2011-03-17 13:49:38 -0700 | [diff] [blame] | 257 | setFont(lastFont.get()); |
Alex Sakhartchouk | 55e8198 | 2010-08-05 11:24:14 -0700 | [diff] [blame] | 258 | mStateFont.setFontColor(oldR, oldG, oldB, oldA); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 261 | void * Context::threadProc(void *vrsc) { |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 262 | Context *rsc = static_cast<Context *>(vrsc); |
| 263 | rsc->mNativeThreadId = gettid(); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 264 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 265 | setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); |
| 266 | rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 267 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 268 | rsc->props.mLogTimes = getProp("debug.rs.profile"); |
| 269 | rsc->props.mLogScripts = getProp("debug.rs.script"); |
| 270 | rsc->props.mLogObjects = getProp("debug.rs.object"); |
| 271 | rsc->props.mLogShaders = getProp("debug.rs.shader"); |
| 272 | rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes"); |
| 273 | rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms"); |
| 274 | rsc->props.mLogVisual = getProp("debug.rs.visual"); |
Joe Onorato | 9ac2c66 | 2009-09-23 16:37:36 -0700 | [diff] [blame] | 275 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 276 | if (!rsdHalInit(rsc, 0, 0)) { |
| 277 | LOGE("Hal init failed"); |
| 278 | return NULL; |
| 279 | } |
| 280 | rsc->mHal.funcs.setPriority(rsc, rsc->mThreadPriority); |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 281 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 282 | if (!rsc->initGLThread()) { |
| 283 | rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL"); |
| 284 | return NULL; |
| 285 | } |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 286 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 287 | if (rsc->mIsGraphicsContext) { |
| 288 | rsc->mStateRaster.init(rsc); |
| 289 | rsc->setProgramRaster(NULL); |
| 290 | rsc->mStateVertex.init(rsc); |
| 291 | rsc->setProgramVertex(NULL); |
| 292 | rsc->mStateFragment.init(rsc); |
| 293 | rsc->setProgramFragment(NULL); |
| 294 | rsc->mStateFragmentStore.init(rsc); |
| 295 | rsc->setProgramStore(NULL); |
| 296 | rsc->mStateFont.init(rsc); |
| 297 | rsc->setFont(NULL); |
| 298 | rsc->mStateVertexArray.init(rsc); |
| 299 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 300 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 301 | rsc->mRunning = true; |
| 302 | bool mDraw = true; |
| 303 | while (!rsc->mExit) { |
| 304 | mDraw |= rsc->mIO.playCoreCommands(rsc, !mDraw); |
| 305 | mDraw &= (rsc->mRootScript.get() != NULL); |
| 306 | mDraw &= (rsc->mWndSurface != NULL); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 307 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 308 | uint32_t targetTime = 0; |
| 309 | if (mDraw && rsc->mIsGraphicsContext) { |
| 310 | targetTime = rsc->runRootScript(); |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 311 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 312 | if (rsc->props.mLogVisual) { |
| 313 | rsc->displayDebugStats(); |
| 314 | } |
Alex Sakhartchouk | 6de5550 | 2010-08-03 12:03:16 -0700 | [diff] [blame] | 315 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 316 | mDraw = targetTime && !rsc->mPaused; |
| 317 | rsc->timerSet(RS_TIMER_CLEAR_SWAP); |
| 318 | rsc->mHal.funcs.swap(rsc); |
| 319 | rsc->timerFrame(); |
| 320 | rsc->timerSet(RS_TIMER_INTERNAL); |
| 321 | rsc->timerPrint(); |
| 322 | rsc->timerReset(); |
| 323 | } |
| 324 | if (targetTime > 1) { |
| 325 | int32_t t = (targetTime - (int32_t)(rsc->mTimeMSLastScript + rsc->mTimeMSLastSwap)) * 1000; |
| 326 | if (t > 0) { |
| 327 | usleep(t); |
| 328 | } |
| 329 | } |
| 330 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 331 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 332 | LOGV("%p, RS Thread exiting", rsc); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 333 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 334 | if (rsc->mIsGraphicsContext) { |
| 335 | pthread_mutex_lock(&gInitMutex); |
| 336 | rsc->deinitEGL(); |
| 337 | pthread_mutex_unlock(&gInitMutex); |
| 338 | } |
Jason Sams | 7136220 | 2009-10-27 14:44:31 -0700 | [diff] [blame] | 339 | |
Jason Sams | be8ac6a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 340 | LOGV("%p, RS Thread exited", rsc); |
| 341 | return NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 344 | void Context::destroyWorkerThreadResources() { |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 345 | //LOGV("destroyWorkerThreadResources 1"); |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 346 | ObjectBase::zeroAllUserRef(this); |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 347 | if (mIsGraphicsContext) { |
| 348 | mRaster.clear(); |
| 349 | mFragment.clear(); |
| 350 | mVertex.clear(); |
| 351 | mFragmentStore.clear(); |
| 352 | mFont.clear(); |
| 353 | mRootScript.clear(); |
| 354 | mStateRaster.deinit(this); |
| 355 | mStateVertex.deinit(this); |
| 356 | mStateFragment.deinit(this); |
| 357 | mStateFragmentStore.deinit(this); |
| 358 | mStateFont.deinit(this); |
Jason Sams | 49945c0 | 2011-01-05 03:37:48 -0800 | [diff] [blame] | 359 | mShaderCache.cleanupAll(); |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 360 | } |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 361 | //LOGV("destroyWorkerThreadResources 2"); |
Jason Sams | 84035ff | 2011-01-09 16:09:51 -0800 | [diff] [blame] | 362 | mExit = true; |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 365 | void Context::setPriority(int32_t p) { |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 366 | // Note: If we put this in the proper "background" policy |
| 367 | // the wallpapers can become completly unresponsive at times. |
| 368 | // This is probably not what we want for something the user is actively |
| 369 | // looking at. |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 370 | mThreadPriority = p; |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 371 | #if 0 |
| 372 | SchedPolicy pol = SP_FOREGROUND; |
| 373 | if (p > 0) { |
| 374 | pol = SP_BACKGROUND; |
| 375 | } |
| 376 | if (!set_sched_policy(mNativeThreadId, pol)) { |
| 377 | // success; reset the priority as well |
| 378 | } |
| 379 | #else |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 380 | setpriority(PRIO_PROCESS, mNativeThreadId, p); |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 381 | #endif |
| 382 | } |
| 383 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 384 | Context::Context() { |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 385 | mDev = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 386 | mRunning = false; |
| 387 | mExit = false; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 388 | mPaused = false; |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 389 | mObjHead = NULL; |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 390 | mError = RS_ERROR_NONE; |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 391 | mDPI = 96; |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 394 | Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) { |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 395 | Context * rsc = new Context(); |
| 396 | if (!rsc->initContext(dev, sc)) { |
| 397 | delete rsc; |
| 398 | return NULL; |
| 399 | } |
| 400 | return rsc; |
| 401 | } |
| 402 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 403 | bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 404 | pthread_mutex_lock(&gInitMutex); |
| 405 | |
| 406 | dev->addContext(this); |
| 407 | mDev = dev; |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 408 | if (sc) { |
| 409 | mUserSurfaceConfig = *sc; |
| 410 | } else { |
| 411 | memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig)); |
| 412 | } |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 413 | |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 414 | memset(&mGL, 0, sizeof(mGL)); |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 415 | mIsGraphicsContext = sc != NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 416 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 417 | int status; |
| 418 | pthread_attr_t threadAttr; |
| 419 | |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 420 | pthread_mutex_unlock(&gInitMutex); |
| 421 | |
| 422 | // Global init done at this point. |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 423 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 424 | status = pthread_attr_init(&threadAttr); |
| 425 | if (status) { |
| 426 | LOGE("Failed to init thread attribute."); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 427 | return false; |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 430 | mWndSurface = NULL; |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 431 | |
Jason Sams | f4d1606 | 2009-08-19 12:17:14 -0700 | [diff] [blame] | 432 | timerInit(); |
Jason Sams | d3f2eaf | 2009-09-24 15:42:52 -0700 | [diff] [blame] | 433 | timerSet(RS_TIMER_INTERNAL); |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 434 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 435 | status = pthread_create(&mThreadId, &threadAttr, threadProc, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 436 | if (status) { |
| 437 | LOGE("Failed to start rs context thread."); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 438 | return false; |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 439 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 440 | while (!mRunning && (mError == RS_ERROR_NONE)) { |
Jason Sams | c7f4e41 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 441 | usleep(100); |
| 442 | } |
| 443 | |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 444 | if (mError != RS_ERROR_NONE) { |
Jason Sams | 80e29cf | 2011-03-18 17:08:54 -0700 | [diff] [blame] | 445 | LOGE("Errors during thread init"); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 446 | return false; |
| 447 | } |
| 448 | |
Jason Sams | 8ad0010 | 2009-06-04 14:35:01 -0700 | [diff] [blame] | 449 | pthread_attr_destroy(&threadAttr); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 450 | return true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 453 | Context::~Context() { |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 454 | LOGV("Context::~Context"); |
Jason Sams | 84035ff | 2011-01-09 16:09:51 -0800 | [diff] [blame] | 455 | |
| 456 | mIO.mToCore.flush(); |
| 457 | rsAssert(mExit); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 458 | mExit = true; |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 459 | mPaused = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 460 | void *res; |
| 461 | |
Jason Sams | f5b4596 | 2009-08-25 14:49:07 -0700 | [diff] [blame] | 462 | mIO.shutdown(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 463 | int status = pthread_join(mThreadId, &res); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 464 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 465 | |
| 466 | if (mHal.funcs.shutdownDriver) { |
| 467 | mHal.funcs.shutdownDriver(this); |
Jason Sams | 03855bb | 2011-01-25 00:26:25 -0800 | [diff] [blame] | 468 | } |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 469 | |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 470 | // Global structure cleanup. |
| 471 | pthread_mutex_lock(&gInitMutex); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 472 | if (mDev) { |
| 473 | mDev->removeContext(this); |
Jason Sams | b7a6c43 | 2009-11-02 14:25:10 -0800 | [diff] [blame] | 474 | mDev = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 475 | } |
Jason Sams | 41c19db9 | 2009-10-15 16:47:31 -0700 | [diff] [blame] | 476 | pthread_mutex_unlock(&gInitMutex); |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 477 | LOGV("Context::~Context done"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 480 | void Context::setSurface(uint32_t w, uint32_t h, ANativeWindow *sur) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 481 | rsAssert(mIsGraphicsContext); |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 482 | mHal.funcs.setSurface(this, w, h, sur); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 483 | |
| 484 | mWndSurface = sur; |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 485 | mWidth = w; |
| 486 | mHeight = h; |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 487 | |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 488 | if (mWidth && mHeight) { |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 489 | mStateVertex.updateSize(this); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 493 | void Context::pause() { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 494 | rsAssert(mIsGraphicsContext); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 495 | mPaused = true; |
| 496 | } |
| 497 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 498 | void Context::resume() { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 499 | rsAssert(mIsGraphicsContext); |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 500 | mPaused = false; |
| 501 | } |
| 502 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 503 | void Context::setRootScript(Script *s) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 504 | rsAssert(mIsGraphicsContext); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 505 | mRootScript.set(s); |
| 506 | } |
| 507 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 508 | void Context::setProgramStore(ProgramStore *pfs) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 509 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 510 | if (pfs == NULL) { |
| 511 | mFragmentStore.set(mStateFragmentStore.mDefault); |
| 512 | } else { |
| 513 | mFragmentStore.set(pfs); |
| 514 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 517 | void Context::setProgramFragment(ProgramFragment *pf) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 518 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 519 | if (pf == NULL) { |
| 520 | mFragment.set(mStateFragment.mDefault); |
| 521 | } else { |
| 522 | mFragment.set(pf); |
| 523 | } |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 526 | void Context::setProgramRaster(ProgramRaster *pr) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 527 | rsAssert(mIsGraphicsContext); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 528 | if (pr == NULL) { |
| 529 | mRaster.set(mStateRaster.mDefault); |
| 530 | } else { |
| 531 | mRaster.set(pr); |
| 532 | } |
| 533 | } |
| 534 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 535 | void Context::setProgramVertex(ProgramVertex *pv) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 536 | rsAssert(mIsGraphicsContext); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 537 | if (pv == NULL) { |
| 538 | mVertex.set(mStateVertex.mDefault); |
| 539 | } else { |
| 540 | mVertex.set(pv); |
| 541 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 544 | void Context::setFont(Font *f) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 545 | rsAssert(mIsGraphicsContext); |
| 546 | if (f == NULL) { |
| 547 | mFont.set(mStateFont.mDefault); |
| 548 | } else { |
| 549 | mFont.set(f); |
| 550 | } |
| 551 | } |
| 552 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 553 | void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 554 | rsAssert(!obj->getName()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 555 | obj->setName(name, len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 556 | mNames.add(obj); |
| 557 | } |
| 558 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 559 | void Context::removeName(ObjectBase *obj) { |
| 560 | for (size_t ct=0; ct < mNames.size(); ct++) { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 561 | if (obj == mNames[ct]) { |
| 562 | mNames.removeAt(ct); |
| 563 | return; |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 568 | RsMessageToClientType Context::peekMessageToClient(size_t *receiveLen, uint32_t *subID, bool wait) { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 569 | *receiveLen = 0; |
| 570 | if (!wait && mIO.mToClient.isEmpty()) { |
| 571 | return RS_MESSAGE_TO_CLIENT_NONE; |
| 572 | } |
| 573 | |
| 574 | uint32_t bytesData = 0; |
| 575 | uint32_t commandID = 0; |
| 576 | const uint32_t *d = (const uint32_t *)mIO.mToClient.get(&commandID, &bytesData); |
| 577 | *receiveLen = bytesData - sizeof(uint32_t); |
| 578 | if (bytesData) { |
| 579 | *subID = d[0]; |
| 580 | } |
| 581 | return (RsMessageToClientType)commandID; |
| 582 | } |
| 583 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 584 | RsMessageToClientType Context::getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen, bool wait) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 585 | //LOGE("getMessageToClient %i %i", bufferLen, wait); |
Jason Sams | 1d45c47 | 2010-08-25 14:31:48 -0700 | [diff] [blame] | 586 | *receiveLen = 0; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 587 | if (!wait && mIO.mToClient.isEmpty()) { |
| 588 | return RS_MESSAGE_TO_CLIENT_NONE; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | //LOGE("getMessageToClient 2 con=%p", this); |
| 592 | uint32_t bytesData = 0; |
| 593 | uint32_t commandID = 0; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 594 | const uint32_t *d = (const uint32_t *)mIO.mToClient.get(&commandID, &bytesData); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 595 | //LOGE("getMessageToClient 3 %i %i", commandID, bytesData); |
| 596 | |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 597 | *receiveLen = bytesData - sizeof(uint32_t); |
| 598 | *subID = d[0]; |
| 599 | |
| 600 | //LOGE("getMessageToClient %i %i", commandID, *subID); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 601 | if (bufferLen >= bytesData) { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 602 | memcpy(data, d+1, *receiveLen); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 603 | mIO.mToClient.next(); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 604 | return (RsMessageToClientType)commandID; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 605 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 606 | return RS_MESSAGE_TO_CLIENT_RESIZE; |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 609 | bool Context::sendMessageToClient(const void *data, RsMessageToClientType cmdID, |
| 610 | uint32_t subID, size_t len, bool waitForSpace) const { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 611 | //LOGE("sendMessageToClient %i %i %i %i", cmdID, subID, len, waitForSpace); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 612 | if (cmdID == 0) { |
| 613 | LOGE("Attempting to send invalid command 0 to client."); |
| 614 | return false; |
| 615 | } |
| 616 | if (!waitForSpace) { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 617 | if (!mIO.mToClient.makeSpaceNonBlocking(len + 12)) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 618 | // Not enough room, and not waiting. |
| 619 | return false; |
| 620 | } |
| 621 | } |
| 622 | //LOGE("sendMessageToClient 2"); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 623 | uint32_t *p = (uint32_t *)mIO.mToClient.reserve(len + sizeof(subID)); |
| 624 | p[0] = subID; |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 625 | if (len > 0) { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 626 | memcpy(p+1, data, len); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 627 | } |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 628 | mIO.mToClient.commit(cmdID, len + sizeof(subID)); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 629 | //LOGE("sendMessageToClient 3"); |
| 630 | return true; |
| 631 | } |
| 632 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 633 | void Context::initToClient() { |
| 634 | while (!mRunning) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 635 | usleep(100); |
| 636 | } |
| 637 | } |
| 638 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 639 | void Context::deinitToClient() { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 640 | mIO.mToClient.shutdown(); |
| 641 | } |
Jason Sams | 730ee65 | 2009-08-18 17:07:09 -0700 | [diff] [blame] | 642 | |
Jason Sams | add9d96 | 2010-11-22 16:20:16 -0800 | [diff] [blame] | 643 | void Context::setError(RsError e, const char *msg) const { |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 644 | mError = e; |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 645 | sendMessageToClient(msg, RS_MESSAGE_TO_CLIENT_ERROR, e, strlen(msg) + 1, true); |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 649 | void Context::dumpDebug() const { |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 650 | LOGE("RS Context debug %p", this); |
| 651 | LOGE("RS Context debug"); |
| 652 | |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 653 | LOGE(" RS width %i, height %i", mWidth, mHeight); |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 654 | LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused); |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 655 | LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId); |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 656 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 657 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 658 | /////////////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 659 | // |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 660 | |
| 661 | namespace android { |
| 662 | namespace renderscript { |
| 663 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 664 | void rsi_ContextFinish(Context *rsc) { |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 665 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 666 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 667 | void rsi_ContextBindRootScript(Context *rsc, RsScript vs) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 668 | Script *s = static_cast<Script *>(vs); |
| 669 | rsc->setRootScript(s); |
| 670 | } |
| 671 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 672 | void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 673 | Sampler *s = static_cast<Sampler *>(vs); |
| 674 | |
| 675 | if (slot > RS_MAX_SAMPLER_SLOT) { |
| 676 | LOGE("Invalid sampler slot"); |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | s->bindToContext(&rsc->mStateSampler, slot); |
| 681 | } |
| 682 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 683 | void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) { |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 684 | ProgramStore *pfs = static_cast<ProgramStore *>(vpfs); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 685 | rsc->setProgramStore(pfs); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 688 | void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 689 | ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 690 | rsc->setProgramFragment(pf); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 693 | void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) { |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 694 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 695 | rsc->setProgramRaster(pr); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 698 | void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 699 | ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 700 | rsc->setProgramVertex(pv); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 703 | void rsi_ContextBindFont(Context *rsc, RsFont vfont) { |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 704 | Font *font = static_cast<Font *>(vfont); |
| 705 | rsc->setFont(font); |
| 706 | } |
| 707 | |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 708 | void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, uint32_t name_length) { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 709 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 710 | rsc->assignName(ob, name, name_length); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 711 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 712 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 713 | void rsi_ObjDestroy(Context *rsc, void *optr) { |
Jason Sams | 3b9c52a | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 714 | ObjectBase *ob = static_cast<ObjectBase *>(optr); |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 715 | rsc->removeName(ob); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 716 | ob->decUserRef(); |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 719 | void rsi_ContextPause(Context *rsc) { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 720 | rsc->pause(); |
| 721 | } |
| 722 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 723 | void rsi_ContextResume(Context *rsc) { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 724 | rsc->resume(); |
| 725 | } |
| 726 | |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 727 | void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, ANativeWindow *sur, size_t sur_length) { |
Mathias Agopian | 128ce4b | 2010-02-12 14:04:35 -0800 | [diff] [blame] | 728 | rsc->setSurface(w, h, sur); |
Jason Sams | 3bc47d4 | 2009-11-12 15:10:25 -0800 | [diff] [blame] | 729 | } |
| 730 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 731 | void rsi_ContextSetPriority(Context *rsc, int32_t p) { |
Jason Sams | 7d787b4 | 2009-11-15 12:14:26 -0800 | [diff] [blame] | 732 | rsc->setPriority(p); |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 735 | void rsi_ContextDump(Context *rsc, int32_t bits) { |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 736 | ObjectBase::dumpAll(rsc); |
| 737 | } |
| 738 | |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 739 | void rsi_ContextDestroyWorker(Context *rsc) { |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 740 | rsc->destroyWorkerThreadResources();; |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | void rsContextDestroy(RsContext vcon) { |
| 747 | LOGV("rsContextDestroy %p", vcon); |
| 748 | Context *rsc = static_cast<Context *>(vcon); |
| 749 | rsContextDestroyWorker(rsc); |
Jason Sams | 546f01b | 2010-12-09 12:19:46 -0800 | [diff] [blame] | 750 | delete rsc; |
Jason Sams | 5c68a71 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 751 | LOGV("rsContextDestroy 2 %p", vcon); |
Jason Sams | 546f01b | 2010-12-09 12:19:46 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 754 | RsContext rsContextCreate(RsDevice vdev, uint32_t version) { |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 755 | LOGV("rsContextCreate %p", vdev); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 756 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 757 | Context *rsc = Context::createContext(dev, NULL); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 758 | return rsc; |
| 759 | } |
| 760 | |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 761 | RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, |
| 762 | RsSurfaceConfig sc, uint32_t dpi) { |
Jason Sams | 11c8af9 | 2010-10-13 15:31:10 -0700 | [diff] [blame] | 763 | LOGV("rsContextCreateGL %p", vdev); |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 764 | Device * dev = static_cast<Device *>(vdev); |
Jason Sams | d5f0630 | 2010-11-03 14:27:11 -0700 | [diff] [blame] | 765 | Context *rsc = Context::createContext(dev, &sc); |
Alex Sakhartchouk | 2c74ad9 | 2011-03-16 19:28:25 -0700 | [diff] [blame] | 766 | rsc->setDPI(dpi); |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 767 | LOGV("rsContextCreateGL ret %p ", rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 768 | return rsc; |
| 769 | } |
| 770 | |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame^] | 771 | RsMessageToClientType rsContextPeekMessage(RsContext vrsc, |
| 772 | size_t * receiveLen, size_t receiveLen_length, |
| 773 | uint32_t * subID, size_t subID_length, bool wait) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 774 | Context * rsc = static_cast<Context *>(vrsc); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 775 | return rsc->peekMessageToClient(receiveLen, subID, wait); |
| 776 | } |
| 777 | |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame^] | 778 | RsMessageToClientType rsContextGetMessage(RsContext vrsc, void * data, size_t data_length, |
| 779 | size_t * receiveLen, size_t receiveLen_length, |
| 780 | uint32_t * subID, size_t subID_length, bool wait) { |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 781 | Context * rsc = static_cast<Context *>(vrsc); |
Jason Sams | 65bdaf1 | 2011-04-26 14:50:00 -0700 | [diff] [blame^] | 782 | rsAssert(subID_length == sizeof(uint32_t)); |
| 783 | rsAssert(receiveLen_length == sizeof(size_t)); |
| 784 | return rsc->getMessageToClient(data, receiveLen, subID, data_length, wait); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 787 | void rsContextInitToClient(RsContext vrsc) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 788 | Context * rsc = static_cast<Context *>(vrsc); |
| 789 | rsc->initToClient(); |
| 790 | } |
| 791 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 792 | void rsContextDeinitToClient(RsContext vrsc) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 793 | Context * rsc = static_cast<Context *>(vrsc); |
| 794 | rsc->deinitToClient(); |
| 795 | } |
| 796 | |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 797 | // Only to be called at a3d load time, before object is visible to user |
| 798 | // not thread safe |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 799 | void rsaGetName(RsContext con, void * obj, const char **name) { |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 800 | ObjectBase *ob = static_cast<ObjectBase *>(obj); |
| 801 | (*name) = ob->getName(); |
| 802 | } |