diff options
Diffstat (limited to 'cpp/RenderScript.cpp')
| -rw-r--r-- | cpp/RenderScript.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp index 889f27b5..ffc0ce67 100644 --- a/cpp/RenderScript.cpp +++ b/cpp/RenderScript.cpp @@ -19,17 +19,18 @@ #include <utils/Log.h> #include <malloc.h> #include <string.h> +#include <pthread.h> #include "RenderScript.h" #include "rs.h" using namespace android; -using namespace renderscriptCpp; +using namespace RSC; -bool RenderScript::gInitialized = false; -pthread_mutex_t RenderScript::gInitMutex = PTHREAD_MUTEX_INITIALIZER; +bool RS::gInitialized = false; +pthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER; -RenderScript::RenderScript() { +RS::RS() { mDev = NULL; mContext = NULL; mErrorFunc = NULL; @@ -39,7 +40,7 @@ RenderScript::RenderScript() { memset(&mElements, 0, sizeof(mElements)); } -RenderScript::~RenderScript() { +RS::~RS() { mMessageRun = false; rsContextDeinitToClient(mContext); @@ -53,25 +54,28 @@ RenderScript::~RenderScript() { mDev = NULL; } -bool RenderScript::init(int targetApi) { +bool RS::init(bool forceCpu) { + return RS::init(RS_VERSION, forceCpu); +} + +bool RS::init(int targetApi, bool forceCpu) { mDev = rsDeviceCreate(); if (mDev == 0) { ALOGE("Device creation failed"); return false; } - mContext = rsContextCreate(mDev, 0, targetApi); + mContext = rsContextCreate(mDev, 0, targetApi, forceCpu); if (mContext == 0) { ALOGE("Context creation failed"); return false; } - pid_t mNativeMessageThreadId; int status = pthread_create(&mMessageThreadId, NULL, threadProc, this); if (status) { - ALOGE("Failed to start RenderScript message thread."); + ALOGE("Failed to start RS message thread."); return false; } // Wait for the message thread to be active. @@ -82,15 +86,15 @@ bool RenderScript::init(int targetApi) { return true; } -void RenderScript::throwError(const char *err) const { +void RS::throwError(const char *err) const { ALOGE("RS CPP error: %s", err); int * v = NULL; v[0] = 0; } -void * RenderScript::threadProc(void *vrsc) { - RenderScript *rs = static_cast<RenderScript *>(vrsc); +void * RS::threadProc(void *vrsc) { + RS *rs = static_cast<RS *>(vrsc); size_t rbuf_size = 256; void * rbuf = malloc(rbuf_size); @@ -110,7 +114,7 @@ void * RenderScript::threadProc(void *vrsc) { rbuf = realloc(rbuf, rbuf_size); } if (!rbuf) { - ALOGE("RenderScript::message handler realloc error %zu", rbuf_size); + ALOGE("RS::message handler realloc error %zu", rbuf_size); // No clean way to recover now? } rsContextGetMessage(rs->mContext, rbuf, rbuf_size, &receiveLen, sizeof(receiveLen), @@ -139,30 +143,25 @@ void * RenderScript::threadProc(void *vrsc) { break; default: - ALOGE("RenderScript unknown message type %i", r); + ALOGE("RS unknown message type %i", r); } } if (rbuf) { free(rbuf); } - ALOGE("RenderScript Message thread exiting."); + ALOGE("RS Message thread exiting."); return NULL; } -void RenderScript::setErrorHandler(ErrorHandlerFunc_t func) { +void RS::setErrorHandler(ErrorHandlerFunc_t func) { mErrorFunc = func; } -void RenderScript::setMessageHandler(MessageHandlerFunc_t func) { +void RS::setMessageHandler(MessageHandlerFunc_t func) { mMessageFunc = func; } -void RenderScript::contextDump() { -} - -void RenderScript::finish() { - +void RS::finish() { + rsContextFinish(mContext); } - - |
