Move to smart pointers for refcounting RS contexts

Change-Id: I0dc6adc4e02c7427a4234c549d3555a501fe5f90
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp
index 889f27b..3160b4d 100644
--- a/cpp/RenderScript.cpp
+++ b/cpp/RenderScript.cpp
@@ -19,6 +19,7 @@
 #include <utils/Log.h>
 #include <malloc.h>
 #include <string.h>
+#include <pthread.h>
 
 #include "RenderScript.h"
 #include "rs.h"
@@ -26,10 +27,10 @@
 using namespace android;
 using namespace renderscriptCpp;
 
-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 @@
     memset(&mElements, 0, sizeof(mElements));
 }
 
-RenderScript::~RenderScript() {
+RS::~RS() {
     mMessageRun = false;
 
     rsContextDeinitToClient(mContext);
@@ -53,7 +54,11 @@
     mDev = NULL;
 }
 
-bool RenderScript::init(int targetApi) {
+bool RS::init() {
+    return RS::init(RS_VERSION);
+}
+
+bool RS::init(int targetApi) {
     mDev = rsDeviceCreate();
     if (mDev == 0) {
         ALOGE("Device creation failed");
@@ -66,12 +71,11 @@
         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 @@
     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 @@
             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,21 @@
             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() {
-
-}
-
-