1/* 2 * Copyright (C) 2011 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" 20#include <ui/FramebufferNativeWindow.h> 21 22#include <sys/types.h> 23#include <sys/resource.h> 24#include <sched.h> 25 26#include <cutils/properties.h> 27 28#include <cutils/sched_policy.h> 29#include <sys/syscall.h> 30#include <string.h> 31 32using namespace android; 33using namespace android::renderscript; 34 35pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER; 36pthread_mutex_t Context::gLibMutex = PTHREAD_MUTEX_INITIALIZER; 37 38bool Context::initGLThread() { 39 pthread_mutex_lock(&gInitMutex); 40 41 if (!mHal.funcs.initGraphics(this)) { 42 pthread_mutex_unlock(&gInitMutex); 43 LOGE("%p initGraphics failed", this); 44 return false; 45 } 46 47 pthread_mutex_unlock(&gInitMutex); 48 return true; 49} 50 51void Context::deinitEGL() { 52 mHal.funcs.shutdownGraphics(this); 53} 54 55Context::PushState::PushState(Context *con) { 56 mRsc = con; 57 if (con->mIsGraphicsContext) { 58 mFragment.set(con->getProgramFragment()); 59 mVertex.set(con->getProgramVertex()); 60 mStore.set(con->getProgramStore()); 61 mRaster.set(con->getProgramRaster()); 62 mFont.set(con->getFont()); 63 } 64} 65 66Context::PushState::~PushState() { 67 if (mRsc->mIsGraphicsContext) { 68 mRsc->setProgramFragment(mFragment.get()); 69 mRsc->setProgramVertex(mVertex.get()); 70 mRsc->setProgramStore(mStore.get()); 71 mRsc->setProgramRaster(mRaster.get()); 72 mRsc->setFont(mFont.get()); 73 } 74} 75 76 77uint32_t Context::runScript(Script *s) { 78 PushState(this); 79 80 uint32_t ret = s->run(this); 81 return ret; 82} 83 84uint32_t Context::runRootScript() { 85 timerSet(RS_TIMER_SCRIPT); 86 mStateFragmentStore.mLast.clear(); 87 watchdog.inRoot = true; 88 uint32_t ret = runScript(mRootScript.get()); 89 watchdog.inRoot = false; 90 91 return ret; 92} 93 94uint64_t Context::getTime() const { 95#ifndef ANDROID_RS_SERIALIZE 96 struct timespec t; 97 clock_gettime(CLOCK_MONOTONIC, &t); 98 return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); 99#else 100 return 0; 101#endif //ANDROID_RS_SERIALIZE 102} 103 104void Context::timerReset() { 105 for (int ct=0; ct < _RS_TIMER_TOTAL; ct++) { 106 mTimers[ct] = 0; 107 } 108} 109 110void Context::timerInit() { 111 mTimeLast = getTime(); 112 mTimeFrame = mTimeLast; 113 mTimeLastFrame = mTimeLast; 114 mTimerActive = RS_TIMER_INTERNAL; 115 mAverageFPSFrameCount = 0; 116 mAverageFPSStartTime = mTimeLast; 117 mAverageFPS = 0; 118 timerReset(); 119} 120 121void Context::timerFrame() { 122 mTimeLastFrame = mTimeFrame; 123 mTimeFrame = getTime(); 124 // Update average fps 125 const uint64_t averageFramerateInterval = 1000 * 1000000; 126 mAverageFPSFrameCount ++; 127 uint64_t inverval = mTimeFrame - mAverageFPSStartTime; 128 if (inverval >= averageFramerateInterval) { 129 inverval = inverval / 1000000; 130 mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval; 131 mAverageFPSFrameCount = 0; 132 mAverageFPSStartTime = mTimeFrame; 133 } 134} 135 136void Context::timerSet(Timers tm) { 137 uint64_t last = mTimeLast; 138 mTimeLast = getTime(); 139 mTimers[mTimerActive] += mTimeLast - last; 140 mTimerActive = tm; 141} 142 143void Context::timerPrint() { 144 double total = 0; 145 for (int ct = 0; ct < _RS_TIMER_TOTAL; ct++) { 146 total += mTimers[ct]; 147 } 148 uint64_t frame = mTimeFrame - mTimeLastFrame; 149 mTimeMSLastFrame = frame / 1000000; 150 mTimeMSLastScript = mTimers[RS_TIMER_SCRIPT] / 1000000; 151 mTimeMSLastSwap = mTimers[RS_TIMER_CLEAR_SWAP] / 1000000; 152 153 154 if (props.mLogTimes) { 155 LOGV("RS: Frame (%i), Script %2.1f%% (%i), Swap %2.1f%% (%i), Idle %2.1f%% (%lli), Internal %2.1f%% (%lli), Avg fps: %u", 156 mTimeMSLastFrame, 157 100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript, 158 100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap, 159 100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000, 160 100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000, 161 mAverageFPS); 162 } 163} 164 165bool Context::setupCheck() { 166 167 mFragmentStore->setup(this, &mStateFragmentStore); 168 mFragment->setup(this, &mStateFragment); 169 mRaster->setup(this, &mStateRaster); 170 mVertex->setup(this, &mStateVertex); 171 mFBOCache.setup(this); 172 return true; 173} 174 175void Context::setupProgramStore() { 176 mFragmentStore->setup(this, &mStateFragmentStore); 177} 178 179static bool getProp(const char *str) { 180 char buf[PROPERTY_VALUE_MAX]; 181 property_get(str, buf, "0"); 182 return 0 != strcmp(buf, "0"); 183} 184 185void Context::displayDebugStats() { 186 char buffer[128]; 187 sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript); 188 float oldR, oldG, oldB, oldA; 189 mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA); 190 uint32_t bufferLen = strlen(buffer); 191 192 ObjectBaseRef<Font> lastFont(getFont()); 193 setFont(NULL); 194 float shadowCol = 0.1f; 195 mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f); 196 mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6); 197 198 mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f); 199 mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7); 200 201 setFont(lastFont.get()); 202 mStateFont.setFontColor(oldR, oldG, oldB, oldA); 203} 204 205void * Context::threadProc(void *vrsc) { 206 Context *rsc = static_cast<Context *>(vrsc); 207#ifndef ANDROID_RS_SERIALIZE 208 rsc->mNativeThreadId = gettid(); 209 setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY); 210 rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY; 211#endif //ANDROID_RS_SERIALIZE 212 rsc->props.mLogTimes = getProp("debug.rs.profile"); 213 rsc->props.mLogScripts = getProp("debug.rs.script"); 214 rsc->props.mLogObjects = getProp("debug.rs.object"); 215 rsc->props.mLogShaders = getProp("debug.rs.shader"); 216 rsc->props.mLogShadersAttr = getProp("debug.rs.shader.attributes"); 217 rsc->props.mLogShadersUniforms = getProp("debug.rs.shader.uniforms"); 218 rsc->props.mLogVisual = getProp("debug.rs.visual"); 219 220 if (!rsdHalInit(rsc, 0, 0)) { 221 rsc->setError(RS_ERROR_FATAL_DRIVER, "Failed initializing GL"); 222 LOGE("Hal init failed"); 223 return NULL; 224 } 225 rsc->mHal.funcs.setPriority(rsc, rsc->mThreadPriority); 226 227 if (rsc->mIsGraphicsContext) { 228 if (!rsc->initGLThread()) { 229 rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL"); 230 return NULL; 231 } 232 233 rsc->mStateRaster.init(rsc); 234 rsc->setProgramRaster(NULL); 235 rsc->mStateVertex.init(rsc); 236 rsc->setProgramVertex(NULL); 237 rsc->mStateFragment.init(rsc); 238 rsc->setProgramFragment(NULL); 239 rsc->mStateFragmentStore.init(rsc); 240 rsc->setProgramStore(NULL); 241 rsc->mStateFont.init(rsc); 242 rsc->setFont(NULL); 243 rsc->mStateSampler.init(rsc); 244 rsc->mFBOCache.init(rsc); 245 } 246 247 rsc->mRunning = true; 248 bool mDraw = true; 249 bool doWait = true; 250 251 uint64_t targetTime = rsc->getTime(); 252 while (!rsc->mExit) { 253 uint64_t waitTime = 0; 254 uint64_t now = rsc->getTime(); 255 if (!doWait) { 256 if (now < targetTime) { 257 waitTime = targetTime - now; 258 doWait = true; 259 } 260 } 261 262 mDraw |= rsc->mIO.playCoreCommands(rsc, doWait, waitTime); 263 mDraw &= (rsc->mRootScript.get() != NULL); 264 mDraw &= rsc->mHasSurface; 265 266 if (mDraw && rsc->mIsGraphicsContext) { 267 uint64_t delay = rsc->runRootScript() * 1000000; 268 targetTime = rsc->getTime() + delay; 269 doWait = (delay == 0); 270 271 if (rsc->props.mLogVisual) { 272 rsc->displayDebugStats(); 273 } 274 275 mDraw = !rsc->mPaused; 276 rsc->timerSet(RS_TIMER_CLEAR_SWAP); 277 rsc->mHal.funcs.swap(rsc); 278 rsc->timerFrame(); 279 rsc->timerSet(RS_TIMER_INTERNAL); 280 rsc->timerPrint(); 281 rsc->timerReset(); 282 } else { 283 doWait = true; 284 } 285 } 286 287 LOGV("%p RS Thread exiting", rsc); 288 289 if (rsc->mIsGraphicsContext) { 290 pthread_mutex_lock(&gInitMutex); 291 rsc->deinitEGL(); 292 pthread_mutex_unlock(&gInitMutex); 293 } 294 295 LOGV("%p RS Thread exited", rsc); 296 return NULL; 297} 298 299void Context::destroyWorkerThreadResources() { 300 //LOGV("destroyWorkerThreadResources 1"); 301 ObjectBase::zeroAllUserRef(this); 302 if (mIsGraphicsContext) { 303 mRaster.clear(); 304 mFragment.clear(); 305 mVertex.clear(); 306 mFragmentStore.clear(); 307 mFont.clear(); 308 mRootScript.clear(); 309 mStateRaster.deinit(this); 310 mStateVertex.deinit(this); 311 mStateFragment.deinit(this); 312 mStateFragmentStore.deinit(this); 313 mStateFont.deinit(this); 314 mStateSampler.deinit(this); 315 mFBOCache.deinit(this); 316 } 317 ObjectBase::freeAllChildren(this); 318 //LOGV("destroyWorkerThreadResources 2"); 319 mExit = true; 320} 321 322void Context::printWatchdogInfo(void *ctx) { 323 Context *rsc = (Context *)ctx; 324 if (rsc->watchdog.command && rsc->watchdog.file) { 325 LOGE("RS watchdog timeout: %i %s line %i %s", rsc->watchdog.inRoot, 326 rsc->watchdog.command, rsc->watchdog.line, rsc->watchdog.file); 327 } else { 328 LOGE("RS watchdog timeout: %i", rsc->watchdog.inRoot); 329 } 330} 331 332 333void Context::setPriority(int32_t p) { 334 // Note: If we put this in the proper "background" policy 335 // the wallpapers can become completly unresponsive at times. 336 // This is probably not what we want for something the user is actively 337 // looking at. 338 mThreadPriority = p; 339#if 0 340 SchedPolicy pol = SP_FOREGROUND; 341 if (p > 0) { 342 pol = SP_BACKGROUND; 343 } 344 if (!set_sched_policy(mNativeThreadId, pol)) { 345 // success; reset the priority as well 346 } 347#else 348 setpriority(PRIO_PROCESS, mNativeThreadId, p); 349#endif 350} 351 352Context::Context() { 353 mDev = NULL; 354 mRunning = false; 355 mExit = false; 356 mPaused = false; 357 mObjHead = NULL; 358 mError = RS_ERROR_NONE; 359 mTargetSdkVersion = 14; 360 mDPI = 96; 361 mIsContextLite = false; 362 memset(&watchdog, 0, sizeof(watchdog)); 363} 364 365Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) { 366 Context * rsc = new Context(); 367 368 if (!rsc->initContext(dev, sc)) { 369 delete rsc; 370 return NULL; 371 } 372 return rsc; 373} 374 375Context * Context::createContextLite() { 376 Context * rsc = new Context(); 377 rsc->mIsContextLite = true; 378 return rsc; 379} 380 381bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { 382 pthread_mutex_lock(&gInitMutex); 383 384 mIO.init(); 385 mIO.setTimoutCallback(printWatchdogInfo, this, 2e9); 386 387 dev->addContext(this); 388 mDev = dev; 389 if (sc) { 390 mUserSurfaceConfig = *sc; 391 } else { 392 memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig)); 393 } 394 395 mIsGraphicsContext = sc != NULL; 396 397 int status; 398 pthread_attr_t threadAttr; 399 400 pthread_mutex_unlock(&gInitMutex); 401 402 // Global init done at this point. 403 404 status = pthread_attr_init(&threadAttr); 405 if (status) { 406 LOGE("Failed to init thread attribute."); 407 return false; 408 } 409 410 mHasSurface = false; 411 412 timerInit(); 413 timerSet(RS_TIMER_INTERNAL); 414 415 status = pthread_create(&mThreadId, &threadAttr, threadProc, this); 416 if (status) { 417 LOGE("Failed to start rs context thread."); 418 return false; 419 } 420 while (!mRunning && (mError == RS_ERROR_NONE)) { 421 usleep(100); 422 } 423 424 if (mError != RS_ERROR_NONE) { 425 LOGE("Errors during thread init"); 426 return false; 427 } 428 429 pthread_attr_destroy(&threadAttr); 430 return true; 431} 432 433Context::~Context() { 434 LOGV("%p Context::~Context", this); 435 436 if (!mIsContextLite) { 437 mIO.coreFlush(); 438 rsAssert(mExit); 439 mExit = true; 440 mPaused = false; 441 void *res; 442 443 mIO.shutdown(); 444 int status = pthread_join(mThreadId, &res); 445 446 if (mHal.funcs.shutdownDriver) { 447 mHal.funcs.shutdownDriver(this); 448 } 449 450 // Global structure cleanup. 451 pthread_mutex_lock(&gInitMutex); 452 if (mDev) { 453 mDev->removeContext(this); 454 mDev = NULL; 455 } 456 pthread_mutex_unlock(&gInitMutex); 457 } 458 LOGV("%p Context::~Context done", this); 459} 460 461void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) { 462 rsAssert(mIsGraphicsContext); 463 mHal.funcs.setSurface(this, w, h, sur); 464 465 mHasSurface = sur != NULL; 466 mWidth = w; 467 mHeight = h; 468 469 if (mWidth && mHeight) { 470 mStateVertex.updateSize(this); 471 mFBOCache.updateSize(); 472 } 473} 474 475void Context::pause() { 476 rsAssert(mIsGraphicsContext); 477 mPaused = true; 478} 479 480void Context::resume() { 481 rsAssert(mIsGraphicsContext); 482 mPaused = false; 483} 484 485void Context::setRootScript(Script *s) { 486 rsAssert(mIsGraphicsContext); 487 mRootScript.set(s); 488} 489 490void Context::setProgramStore(ProgramStore *pfs) { 491 rsAssert(mIsGraphicsContext); 492 if (pfs == NULL) { 493 mFragmentStore.set(mStateFragmentStore.mDefault); 494 } else { 495 mFragmentStore.set(pfs); 496 } 497} 498 499void Context::setProgramFragment(ProgramFragment *pf) { 500 rsAssert(mIsGraphicsContext); 501 if (pf == NULL) { 502 mFragment.set(mStateFragment.mDefault); 503 } else { 504 mFragment.set(pf); 505 } 506} 507 508void Context::setProgramRaster(ProgramRaster *pr) { 509 rsAssert(mIsGraphicsContext); 510 if (pr == NULL) { 511 mRaster.set(mStateRaster.mDefault); 512 } else { 513 mRaster.set(pr); 514 } 515} 516 517void Context::setProgramVertex(ProgramVertex *pv) { 518 rsAssert(mIsGraphicsContext); 519 if (pv == NULL) { 520 mVertex.set(mStateVertex.mDefault); 521 } else { 522 mVertex.set(pv); 523 } 524} 525 526void Context::setFont(Font *f) { 527 rsAssert(mIsGraphicsContext); 528 if (f == NULL) { 529 mFont.set(mStateFont.mDefault); 530 } else { 531 mFont.set(f); 532 } 533} 534 535void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) { 536 rsAssert(!obj->getName()); 537 obj->setName(name, len); 538 mNames.add(obj); 539} 540 541void Context::removeName(ObjectBase *obj) { 542 for (size_t ct=0; ct < mNames.size(); ct++) { 543 if (obj == mNames[ct]) { 544 mNames.removeAt(ct); 545 return; 546 } 547 } 548} 549 550RsMessageToClientType Context::peekMessageToClient(size_t *receiveLen, uint32_t *subID) { 551 return (RsMessageToClientType)mIO.getClientHeader(receiveLen, subID); 552} 553 554RsMessageToClientType Context::getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen) { 555 return (RsMessageToClientType)mIO.getClientPayload(data, receiveLen, subID, bufferLen); 556} 557 558bool Context::sendMessageToClient(const void *data, RsMessageToClientType cmdID, 559 uint32_t subID, size_t len, bool waitForSpace) const { 560 561 return mIO.sendToClient(cmdID, subID, data, len, waitForSpace); 562} 563 564void Context::initToClient() { 565 while (!mRunning) { 566 usleep(100); 567 } 568} 569 570void Context::deinitToClient() { 571 mIO.clientShutdown(); 572} 573 574void Context::setError(RsError e, const char *msg) const { 575 mError = e; 576 sendMessageToClient(msg, RS_MESSAGE_TO_CLIENT_ERROR, e, strlen(msg) + 1, true); 577} 578 579 580void Context::dumpDebug() const { 581 LOGE("RS Context debug %p", this); 582 LOGE("RS Context debug"); 583 584 LOGE(" RS width %i, height %i", mWidth, mHeight); 585 LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused); 586 LOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId); 587} 588 589/////////////////////////////////////////////////////////////////////////////////////////// 590// 591 592namespace android { 593namespace renderscript { 594 595void rsi_ContextFinish(Context *rsc) { 596} 597 598void rsi_ContextBindRootScript(Context *rsc, RsScript vs) { 599 Script *s = static_cast<Script *>(vs); 600 rsc->setRootScript(s); 601} 602 603void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) { 604 Sampler *s = static_cast<Sampler *>(vs); 605 606 if (slot > RS_MAX_SAMPLER_SLOT) { 607 LOGE("Invalid sampler slot"); 608 return; 609 } 610 611 s->bindToContext(&rsc->mStateSampler, slot); 612} 613 614void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) { 615 ProgramStore *pfs = static_cast<ProgramStore *>(vpfs); 616 rsc->setProgramStore(pfs); 617} 618 619void rsi_ContextBindProgramFragment(Context *rsc, RsProgramFragment vpf) { 620 ProgramFragment *pf = static_cast<ProgramFragment *>(vpf); 621 rsc->setProgramFragment(pf); 622} 623 624void rsi_ContextBindProgramRaster(Context *rsc, RsProgramRaster vpr) { 625 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 626 rsc->setProgramRaster(pr); 627} 628 629void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv) { 630 ProgramVertex *pv = static_cast<ProgramVertex *>(vpv); 631 rsc->setProgramVertex(pv); 632} 633 634void rsi_ContextBindFont(Context *rsc, RsFont vfont) { 635 Font *font = static_cast<Font *>(vfont); 636 rsc->setFont(font); 637} 638 639void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) { 640 ObjectBase *ob = static_cast<ObjectBase *>(obj); 641 rsc->assignName(ob, name, name_length); 642} 643 644void rsi_ObjDestroy(Context *rsc, void *optr) { 645 ObjectBase *ob = static_cast<ObjectBase *>(optr); 646 rsc->removeName(ob); 647 ob->decUserRef(); 648} 649 650void rsi_ContextPause(Context *rsc) { 651 rsc->pause(); 652} 653 654void rsi_ContextResume(Context *rsc) { 655 rsc->resume(); 656} 657 658void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, RsNativeWindow sur) { 659 rsc->setSurface(w, h, sur); 660} 661 662void rsi_ContextSetPriority(Context *rsc, int32_t p) { 663 rsc->setPriority(p); 664} 665 666void rsi_ContextDump(Context *rsc, int32_t bits) { 667 ObjectBase::dumpAll(rsc); 668} 669 670void rsi_ContextDestroyWorker(Context *rsc) { 671 rsc->destroyWorkerThreadResources(); 672} 673 674void rsi_ContextDestroy(Context *rsc) { 675 LOGV("%p rsContextDestroy", rsc); 676 rsContextDestroyWorker(rsc); 677 delete rsc; 678 LOGV("%p rsContextDestroy done", rsc); 679} 680 681 682RsMessageToClientType rsi_ContextPeekMessage(Context *rsc, 683 size_t * receiveLen, size_t receiveLen_length, 684 uint32_t * subID, size_t subID_length) { 685 return rsc->peekMessageToClient(receiveLen, subID); 686} 687 688RsMessageToClientType rsi_ContextGetMessage(Context *rsc, void * data, size_t data_length, 689 size_t * receiveLen, size_t receiveLen_length, 690 uint32_t * subID, size_t subID_length) { 691 rsAssert(subID_length == sizeof(uint32_t)); 692 rsAssert(receiveLen_length == sizeof(size_t)); 693 return rsc->getMessageToClient(data, receiveLen, subID, data_length); 694} 695 696void rsi_ContextInitToClient(Context *rsc) { 697 rsc->initToClient(); 698} 699 700void rsi_ContextDeinitToClient(Context *rsc) { 701 rsc->deinitToClient(); 702} 703 704} 705} 706 707RsContext rsContextCreate(RsDevice vdev, uint32_t version, 708 uint32_t sdkVersion) { 709 LOGV("rsContextCreate dev=%p", vdev); 710 Device * dev = static_cast<Device *>(vdev); 711 Context *rsc = Context::createContext(dev, NULL); 712 if (rsc) { 713 rsc->setTargetSdkVersion(sdkVersion); 714 } 715 return rsc; 716} 717 718RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, 719 uint32_t sdkVersion, RsSurfaceConfig sc, 720 uint32_t dpi) { 721 LOGV("rsContextCreateGL dev=%p", vdev); 722 Device * dev = static_cast<Device *>(vdev); 723 Context *rsc = Context::createContext(dev, &sc); 724 if (rsc) { 725 rsc->setTargetSdkVersion(sdkVersion); 726 rsc->setDPI(dpi); 727 } 728 LOGV("%p rsContextCreateGL ret", rsc); 729 return rsc; 730} 731 732// Only to be called at a3d load time, before object is visible to user 733// not thread safe 734void rsaGetName(RsContext con, void * obj, const char **name) { 735 ObjectBase *ob = static_cast<ObjectBase *>(obj); 736 (*name) = ob->getName(); 737} 738