Replace NULL macros with nullptr literals.

Change-Id: I918c40879aa547438f77e7d1a95fa2aa33bec398
diff --git a/api/gen_runtime.cpp b/api/gen_runtime.cpp
index 6a46f35..65682e5 100644
--- a/api/gen_runtime.cpp
+++ b/api/gen_runtime.cpp
@@ -693,7 +693,7 @@
     mLargestVersionNumber = 0;
     while (1) {
         Specification* spec = Specification::scanSpecification(specFile);
-        if (spec == NULL) {
+        if (spec == nullptr) {
             break;
         }
         getFunction(spec->getCleanName())->addSpecification(spec);
@@ -974,7 +974,7 @@
                 return spec;
             } else {
                 delete spec;
-                return NULL;
+                return nullptr;
             }
         }
 
@@ -1037,7 +1037,7 @@
     }
 
     delete spec;
-    return NULL;
+    return nullptr;
 }
 
 void Specification::writeFiles(ofstream& headerFile, ofstream& rsFile, ofstream& javaFile,
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index 91ccbd1..50ae239 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -64,7 +64,7 @@
     mType = t;
     mUsage = usage;
 
-    if (t != NULL) {
+    if (t != nullptr) {
         updateCacheInfo(t);
     }
 
@@ -125,7 +125,7 @@
     BaseObj::updateFromNative();
 
     const void *typeID = RS::dispatch->AllocationGetType(mRS->getContext(), getID());
-    if(typeID != NULL) {
+    if(typeID != nullptr) {
         sp<const Type> old = mType;
         sp<Type> t = new Type((void *)typeID, mRS);
         t->updateFromNative();
@@ -170,23 +170,23 @@
 }
 
 void * Allocation::getPointer(size_t *stride) {
-    void *p = NULL;
+    void *p = nullptr;
     if (!(mUsage & RS_ALLOCATION_USAGE_SHARED)) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Allocation does not support USAGE_SHARED.");
-        return NULL;
+        return nullptr;
     }
 
     // FIXME: decide if lack of getPointer should cause compat mode
-    if (RS::dispatch->AllocationGetPointer == NULL) {
+    if (RS::dispatch->AllocationGetPointer == nullptr) {
         mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Can't use getPointer on older APIs");
-        return NULL;
+        return nullptr;
     }
 
     p = RS::dispatch->AllocationGetPointer(mRS->getContext(), getIDSafe(), 0,
                                            RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0, stride);
     if (mRS->getError() != RS_SUCCESS) {
         mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation lock failed");
-        p = NULL;
+        p = nullptr;
     }
     return p;
 }
@@ -241,7 +241,7 @@
 
 
 void Allocation::validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h) {
-    if (mAdaptedAllocation != NULL) {
+    if (mAdaptedAllocation != nullptr) {
 
     } else {
         if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) {
@@ -303,7 +303,7 @@
 
 void Allocation::validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
                                  uint32_t h, uint32_t d) {
-    if (mAdaptedAllocation != NULL) {
+    if (mAdaptedAllocation != nullptr) {
 
     } else {
         if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) {
@@ -338,7 +338,7 @@
     }
     if (id == 0) {
         rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed");
-        return NULL;
+        return nullptr;
     }
     return new Allocation(id, rs, type, usage);
 }
@@ -353,7 +353,7 @@
     }
     if (id == 0) {
         rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed");
-        return NULL;
+        return nullptr;
     }
     return new Allocation(id, rs, type, usage);
 }
diff --git a/cpp/Android.mk b/cpp/Android.mk
index a170a5e..b062b32 100644
--- a/cpp/Android.mk
+++ b/cpp/Android.mk
@@ -14,7 +14,7 @@
 
 include frameworks/compile/slang/rs_version.mk
 local_cflags_for_rs_cpp += $(RS_VERSION_DEFINE)
-local_cflags_for_rs_cpp += -Wno-unused-parameter
+local_cflags_for_rs_cpp += -Wno-unused-parameter -std=c++11
 
 LOCAL_SRC_FILES := $(rs_cpp_SRC_FILES)
 
diff --git a/cpp/BaseObj.cpp b/cpp/BaseObj.cpp
index 2e0a637..e32d0a6 100644
--- a/cpp/BaseObj.cpp
+++ b/cpp/BaseObj.cpp
@@ -21,14 +21,14 @@
 using namespace RSC;
 
 void * BaseObj::getID() const {
-    if (mID == NULL) {
+    if (mID == nullptr) {
         ALOGE("Internal error: Object id 0.");
     }
     return mID;
 }
 
 void * BaseObj::getObjID(sp<const BaseObj> o) {
-    return o == NULL ? NULL : o->getID();
+    return o == nullptr ? nullptr : o->getID();
 }
 
 
@@ -47,12 +47,12 @@
     if (mRS && mRS->getContext()) {
         RS::dispatch->ObjDestroy(mRS->getContext(), mID);
     }
-    mRS = NULL;
-    mID = NULL;
+    mRS = nullptr;
+    mID = nullptr;
 }
 
 void BaseObj::updateFromNative() {
-    const char *name = NULL;
+    const char *name = nullptr;
     RS::dispatch->GetName(mRS->getContext(), mID, &name);
     mName = name;
 }
diff --git a/cpp/Element.cpp b/cpp/Element.cpp
index b122926..b019b0e 100644
--- a/cpp/Element.cpp
+++ b/cpp/Element.cpp
@@ -26,11 +26,11 @@
 android::RSC::sp<const Element> Element::getSubElement(uint32_t index) {
     if (!mVisibleElementMap.size()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Element contains no sub-elements");
-        return NULL;
+        return nullptr;
     }
     if (index >= mVisibleElementMap.size()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Illegal sub-element index");
-        return NULL;
+        return nullptr;
     }
     return mElements[mVisibleElementMap[index]];
 }
@@ -38,11 +38,11 @@
 const char * Element::getSubElementName(uint32_t index) {
     if (!mVisibleElementMap.size()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Element contains no sub-elements");
-        return NULL;
+        return nullptr;
     }
     if (index >= mVisibleElementMap.size()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Illegal sub-element index");
-        return NULL;
+        return nullptr;
     }
     return mElementNames[mVisibleElementMap[index]].c_str();
 }
@@ -73,7 +73,7 @@
 
 
 #define CREATE_USER(N, T) android::RSC::sp<const Element> Element::N(android::RSC::sp<RS> rs) { \
-    if (rs->mElements.N == NULL) {                                  \
+    if (rs->mElements.N == nullptr) {                               \
         rs->mElements.N = (createUser(rs, RS_TYPE_##T));            \
     }                                                               \
     return rs->mElements.N;                                         \
@@ -100,10 +100,10 @@
 CREATE_USER(MATRIX_2X2, MATRIX_2X2);
 
 #define CREATE_PIXEL(N, T, K) android::RSC::sp<const Element> Element::N(android::RSC::sp<RS> rs) { \
-    if (rs->mElements.N == NULL) {                                  \
-        rs->mElements.N = createPixel(rs, RS_TYPE_##T, RS_KIND_##K);    \
-    }                                                                   \
-    return rs->mElements.N;                                             \
+    if (rs->mElements.N == nullptr) {                                \
+        rs->mElements.N = createPixel(rs, RS_TYPE_##T, RS_KIND_##K); \
+    }                                                                \
+    return rs->mElements.N;                                          \
 }
 
 CREATE_PIXEL(A_8, UNSIGNED_8, PIXEL_A);
@@ -115,22 +115,22 @@
 CREATE_PIXEL(RGBA_5551, UNSIGNED_5_5_5_1, PIXEL_RGBA);
 
 #define CREATE_VECTOR(N, T) android::RSC::sp<const Element> Element::N##_2(android::RSC::sp<RS> rs) { \
-    if (rs->mElements.N##_2 == NULL) {                                  \
-        rs->mElements.N##_2 = createVector(rs, RS_TYPE_##T, 2);         \
-    }                                                                   \
-    return rs->mElements.N##_2;                                         \
-}                                                                       \
+    if (rs->mElements.N##_2 == nullptr) {                                 \
+        rs->mElements.N##_2 = createVector(rs, RS_TYPE_##T, 2);           \
+    }                                                                     \
+    return rs->mElements.N##_2;                                           \
+}                                                                         \
 android::RSC::sp<const Element> Element::N##_3(android::RSC::sp<RS> rs) { \
-    if (rs->mElements.N##_3 == NULL) {                                  \
-        rs->mElements.N##_3 = createVector(rs, RS_TYPE_##T, 3);         \
-    }                                                                   \
-    return rs->mElements.N##_3;                                         \
+    if (rs->mElements.N##_3 == nullptr) {                                 \
+        rs->mElements.N##_3 = createVector(rs, RS_TYPE_##T, 3);           \
+    }                                                                     \
+    return rs->mElements.N##_3;                                           \
 } \
 android::RSC::sp<const Element> Element::N##_4(android::RSC::sp<RS> rs) { \
-    if (rs->mElements.N##_4 == NULL) {                                  \
-        rs->mElements.N##_4 = createVector(rs, RS_TYPE_##T, 4);         \
-    }                                                                   \
-    return rs->mElements.N##_4;                                         \
+    if (rs->mElements.N##_4 == nullptr) {                                 \
+        rs->mElements.N##_4 = createVector(rs, RS_TYPE_##T, 4);           \
+    }                                                                     \
+    return rs->mElements.N##_4;                                           \
 }
 CREATE_VECTOR(U8, UNSIGNED_8);
 CREATE_VECTOR(I8, SIGNED_8);
@@ -279,7 +279,7 @@
 android::RSC::sp<const Element> Element::createVector(android::RSC::sp<RS> rs, RsDataType dt, uint32_t size) {
     if (size < 2 || size > 4) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Vector size out of range 2-4.");
-        return NULL;
+        return nullptr;
     }
     void *id = RS::dispatch->ElementCreate(rs->getContext(), dt, RS_KIND_USER, false, size);
     return new Element(id, rs, dt, RS_KIND_USER, false, size);
@@ -293,7 +293,7 @@
           dk == RS_KIND_PIXEL_RGBA ||
           dk == RS_KIND_PIXEL_DEPTH)) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Unsupported DataKind");
-        return NULL;
+        return nullptr;
     }
     if (!(dt == RS_TYPE_UNSIGNED_8 ||
           dt == RS_TYPE_UNSIGNED_16 ||
@@ -301,23 +301,23 @@
           dt == RS_TYPE_UNSIGNED_4_4_4_4 ||
           dt == RS_TYPE_UNSIGNED_5_5_5_1)) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Unsupported DataType");
-        return NULL;
+        return nullptr;
     }
     if (dt == RS_TYPE_UNSIGNED_5_6_5 && dk != RS_KIND_PIXEL_RGB) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Bad kind and type combo");
-        return NULL;
+        return nullptr;
     }
     if (dt == RS_TYPE_UNSIGNED_5_5_5_1 && dk != RS_KIND_PIXEL_RGBA) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Bad kind and type combo");
-        return NULL;
+        return nullptr;
     }
     if (dt == RS_TYPE_UNSIGNED_4_4_4_4 && dk != RS_KIND_PIXEL_RGBA) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Bad kind and type combo");
-        return NULL;
+        return nullptr;
     }
     if (dt == RS_TYPE_UNSIGNED_16 && dk != RS_KIND_PIXEL_DEPTH) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Bad kind and type combo");
-        return NULL;
+        return nullptr;
     }
 
     int size = 1;
@@ -411,4 +411,3 @@
     free(elementArray);
     return new Element(id, mRS, mElements, mElementNames, mArraySizes);
 }
-
diff --git a/cpp/RenderScript.cpp b/cpp/RenderScript.cpp
index 25a2990..27cb3e8 100644
--- a/cpp/RenderScript.cpp
+++ b/cpp/RenderScript.cpp
@@ -38,14 +38,14 @@
 bool RS::gInitialized = false;
 bool RS::usingNative = false;
 pthread_mutex_t RS::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
-dispatchTable* RS::dispatch = NULL;
+dispatchTable* RS::dispatch = nullptr;
 static int gInitError = 0;
 
 RS::RS() {
-    mDev = NULL;
-    mContext = NULL;
-    mErrorFunc = NULL;
-    mMessageFunc = NULL;
+    mDev = nullptr;
+    mContext = nullptr;
+    mErrorFunc = nullptr;
+    mMessageFunc = nullptr;
     mMessageRun = false;
     mInit = false;
     mCurrentError = RS_SUCCESS;
@@ -61,15 +61,15 @@
         if (mContext) {
             RS::dispatch->ContextDeinitToClient(mContext);
 
-            void *res = NULL;
+            void *res = nullptr;
             int status = pthread_join(mMessageThreadId, &res);
 
             RS::dispatch->ContextDestroy(mContext);
-            mContext = NULL;
+            mContext = nullptr;
         }
         if (mDev) {
             RS::dispatch->DeviceDestroy(mDev);
-            mDev = NULL;
+            mDev = nullptr;
         }
     }
 }
@@ -81,332 +81,332 @@
 static bool loadSymbols(void* handle) {
 
     RS::dispatch->AllocationGetType = (AllocationGetTypeFnPtr)dlsym(handle, "rsaAllocationGetType");
-    if (RS::dispatch->AllocationGetType == NULL) {
+    if (RS::dispatch->AllocationGetType == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationGetType");
         return false;
     }
     RS::dispatch->TypeGetNativeData = (TypeGetNativeDataFnPtr)dlsym(handle, "rsaTypeGetNativeData");
-    if (RS::dispatch->TypeGetNativeData == NULL) {
+    if (RS::dispatch->TypeGetNativeData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->TypeGetNativeData");
         return false;
     }
     RS::dispatch->ElementGetNativeData = (ElementGetNativeDataFnPtr)dlsym(handle, "rsaElementGetNativeData");
-    if (RS::dispatch->ElementGetNativeData == NULL) {
+    if (RS::dispatch->ElementGetNativeData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ElementGetNativeData");
         return false;
     }
     RS::dispatch->ElementGetSubElements = (ElementGetSubElementsFnPtr)dlsym(handle, "rsaElementGetSubElements");
-    if (RS::dispatch->ElementGetSubElements == NULL) {
+    if (RS::dispatch->ElementGetSubElements == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ElementGetSubElements");
         return false;
     }
     RS::dispatch->DeviceCreate = (DeviceCreateFnPtr)dlsym(handle, "rsDeviceCreate");
-    if (RS::dispatch->DeviceCreate == NULL) {
+    if (RS::dispatch->DeviceCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->DeviceCreate");
         return false;
     }
     RS::dispatch->DeviceDestroy = (DeviceDestroyFnPtr)dlsym(handle, "rsDeviceDestroy");
-    if (RS::dispatch->DeviceDestroy == NULL) {
+    if (RS::dispatch->DeviceDestroy == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->DeviceDestroy");
         return false;
     }
     RS::dispatch->DeviceSetConfig = (DeviceSetConfigFnPtr)dlsym(handle, "rsDeviceSetConfig");
-    if (RS::dispatch->DeviceSetConfig == NULL) {
+    if (RS::dispatch->DeviceSetConfig == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->DeviceSetConfig");
         return false;
     }
     RS::dispatch->ContextCreate = (ContextCreateFnPtr)dlsym(handle, "rsContextCreate");;
-    if (RS::dispatch->ContextCreate == NULL) {
+    if (RS::dispatch->ContextCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextCreate");
         return false;
     }
     RS::dispatch->GetName = (GetNameFnPtr)dlsym(handle, "rsaGetName");;
-    if (RS::dispatch->GetName == NULL) {
+    if (RS::dispatch->GetName == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->GetName");
         return false;
     }
     RS::dispatch->ContextDestroy = (ContextDestroyFnPtr)dlsym(handle, "rsContextDestroy");
-    if (RS::dispatch->ContextDestroy == NULL) {
+    if (RS::dispatch->ContextDestroy == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextDestroy");
         return false;
     }
     RS::dispatch->ContextGetMessage = (ContextGetMessageFnPtr)dlsym(handle, "rsContextGetMessage");
-    if (RS::dispatch->ContextGetMessage == NULL) {
+    if (RS::dispatch->ContextGetMessage == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextGetMessage");
         return false;
     }
     RS::dispatch->ContextPeekMessage = (ContextPeekMessageFnPtr)dlsym(handle, "rsContextPeekMessage");
-    if (RS::dispatch->ContextPeekMessage == NULL) {
+    if (RS::dispatch->ContextPeekMessage == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextPeekMessage");
         return false;
     }
     RS::dispatch->ContextSendMessage = (ContextSendMessageFnPtr)dlsym(handle, "rsContextSendMessage");
-    if (RS::dispatch->ContextSendMessage == NULL) {
+    if (RS::dispatch->ContextSendMessage == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextSendMessage");
         return false;
     }
     RS::dispatch->ContextInitToClient = (ContextInitToClientFnPtr)dlsym(handle, "rsContextInitToClient");
-    if (RS::dispatch->ContextInitToClient == NULL) {
+    if (RS::dispatch->ContextInitToClient == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextInitToClient");
         return false;
     }
     RS::dispatch->ContextDeinitToClient = (ContextDeinitToClientFnPtr)dlsym(handle, "rsContextDeinitToClient");
-    if (RS::dispatch->ContextDeinitToClient == NULL) {
+    if (RS::dispatch->ContextDeinitToClient == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextDeinitToClient");
         return false;
     }
     RS::dispatch->TypeCreate = (TypeCreateFnPtr)dlsym(handle, "rsTypeCreate");
-    if (RS::dispatch->TypeCreate == NULL) {
+    if (RS::dispatch->TypeCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->TypeCreate");
         return false;
     }
     RS::dispatch->AllocationCreateTyped = (AllocationCreateTypedFnPtr)dlsym(handle, "rsAllocationCreateTyped");
-    if (RS::dispatch->AllocationCreateTyped == NULL) {
+    if (RS::dispatch->AllocationCreateTyped == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCreateTyped");
         return false;
     }
     RS::dispatch->AllocationCreateFromBitmap = (AllocationCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCreateFromBitmap");
-    if (RS::dispatch->AllocationCreateFromBitmap == NULL) {
+    if (RS::dispatch->AllocationCreateFromBitmap == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCreateFromBitmap");
         return false;
     }
     RS::dispatch->AllocationCubeCreateFromBitmap = (AllocationCubeCreateFromBitmapFnPtr)dlsym(handle, "rsAllocationCubeCreateFromBitmap");
-    if (RS::dispatch->AllocationCubeCreateFromBitmap == NULL) {
+    if (RS::dispatch->AllocationCubeCreateFromBitmap == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCubeCreateFromBitmap");
         return false;
     }
     RS::dispatch->AllocationGetSurface = (AllocationGetSurfaceFnPtr)dlsym(handle, "rsAllocationGetSurface");
-    if (RS::dispatch->AllocationGetSurface == NULL) {
+    if (RS::dispatch->AllocationGetSurface == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationGetSurface");
         return false;
     }
     RS::dispatch->AllocationSetSurface = (AllocationSetSurfaceFnPtr)dlsym(handle, "rsAllocationSetSurface");
-    if (RS::dispatch->AllocationSetSurface == NULL) {
+    if (RS::dispatch->AllocationSetSurface == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationSetSurface");
         return false;
     }
     RS::dispatch->ContextFinish = (ContextFinishFnPtr)dlsym(handle, "rsContextFinish");
-    if (RS::dispatch->ContextFinish == NULL) {
+    if (RS::dispatch->ContextFinish == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextFinish");
         return false;
     }
     RS::dispatch->ContextDump = (ContextDumpFnPtr)dlsym(handle, "rsContextDump");
-    if (RS::dispatch->ContextDump == NULL) {
+    if (RS::dispatch->ContextDump == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextDump");
         return false;
     }
     RS::dispatch->ContextSetPriority = (ContextSetPriorityFnPtr)dlsym(handle, "rsContextSetPriority");
-    if (RS::dispatch->ContextSetPriority == NULL) {
+    if (RS::dispatch->ContextSetPriority == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ContextSetPriority");
         return false;
     }
     RS::dispatch->AssignName = (AssignNameFnPtr)dlsym(handle, "rsAssignName");
-    if (RS::dispatch->AssignName == NULL) {
+    if (RS::dispatch->AssignName == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AssignName");
         return false;
     }
     RS::dispatch->ObjDestroy = (ObjDestroyFnPtr)dlsym(handle, "rsObjDestroy");
-    if (RS::dispatch->ObjDestroy == NULL) {
+    if (RS::dispatch->ObjDestroy == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ObjDestroy");
         return false;
     }
     RS::dispatch->ElementCreate = (ElementCreateFnPtr)dlsym(handle, "rsElementCreate");
-    if (RS::dispatch->ElementCreate == NULL) {
+    if (RS::dispatch->ElementCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ElementCreate");
         return false;
     }
     RS::dispatch->ElementCreate2 = (ElementCreate2FnPtr)dlsym(handle, "rsElementCreate2");
-    if (RS::dispatch->ElementCreate2 == NULL) {
+    if (RS::dispatch->ElementCreate2 == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ElementCreate2");
         return false;
     }
     RS::dispatch->AllocationCopyToBitmap = (AllocationCopyToBitmapFnPtr)dlsym(handle, "rsAllocationCopyToBitmap");
-    if (RS::dispatch->AllocationCopyToBitmap == NULL) {
+    if (RS::dispatch->AllocationCopyToBitmap == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCopyToBitmap");
         return false;
     }
     RS::dispatch->Allocation1DData = (Allocation1DDataFnPtr)dlsym(handle, "rsAllocation1DData");
-    if (RS::dispatch->Allocation1DData == NULL) {
+    if (RS::dispatch->Allocation1DData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation1DData");
         return false;
     }
     RS::dispatch->Allocation1DElementData = (Allocation1DElementDataFnPtr)dlsym(handle, "rsAllocation1DElementData");
-    if (RS::dispatch->Allocation1DElementData == NULL) {
+    if (RS::dispatch->Allocation1DElementData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation1DElementData");
         return false;
     }
     RS::dispatch->Allocation2DData = (Allocation2DDataFnPtr)dlsym(handle, "rsAllocation2DData");
-    if (RS::dispatch->Allocation2DData == NULL) {
+    if (RS::dispatch->Allocation2DData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation2DData");
         return false;
     }
     RS::dispatch->Allocation3DData = (Allocation3DDataFnPtr)dlsym(handle, "rsAllocation3DData");
-    if (RS::dispatch->Allocation3DData == NULL) {
+    if (RS::dispatch->Allocation3DData == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation3DData");
         return false;
     }
     RS::dispatch->AllocationGenerateMipmaps = (AllocationGenerateMipmapsFnPtr)dlsym(handle, "rsAllocationGenerateMipmaps");
-    if (RS::dispatch->AllocationGenerateMipmaps == NULL) {
+    if (RS::dispatch->AllocationGenerateMipmaps == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationGenerateMipmaps");
         return false;
     }
     RS::dispatch->AllocationRead = (AllocationReadFnPtr)dlsym(handle, "rsAllocationRead");
-    if (RS::dispatch->AllocationRead == NULL) {
+    if (RS::dispatch->AllocationRead == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationRead");
         return false;
     }
     RS::dispatch->Allocation1DRead = (Allocation1DReadFnPtr)dlsym(handle, "rsAllocation1DRead");
-    if (RS::dispatch->Allocation1DRead == NULL) {
+    if (RS::dispatch->Allocation1DRead == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation1DRead");
         return false;
     }
     RS::dispatch->Allocation2DRead = (Allocation2DReadFnPtr)dlsym(handle, "rsAllocation2DRead");
-    if (RS::dispatch->Allocation2DRead == NULL) {
+    if (RS::dispatch->Allocation2DRead == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->Allocation2DRead");
         return false;
     }
     RS::dispatch->AllocationSyncAll = (AllocationSyncAllFnPtr)dlsym(handle, "rsAllocationSyncAll");
-    if (RS::dispatch->AllocationSyncAll == NULL) {
+    if (RS::dispatch->AllocationSyncAll == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationSyncAll");
         return false;
     }
     RS::dispatch->AllocationResize1D = (AllocationResize1DFnPtr)dlsym(handle, "rsAllocationResize1D");
-    if (RS::dispatch->AllocationResize1D == NULL) {
+    if (RS::dispatch->AllocationResize1D == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationResize1D");
         return false;
     }
     RS::dispatch->AllocationCopy2DRange = (AllocationCopy2DRangeFnPtr)dlsym(handle, "rsAllocationCopy2DRange");
-    if (RS::dispatch->AllocationCopy2DRange == NULL) {
+    if (RS::dispatch->AllocationCopy2DRange == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCopy2DRange");
         return false;
     }
     RS::dispatch->AllocationCopy3DRange = (AllocationCopy3DRangeFnPtr)dlsym(handle, "rsAllocationCopy3DRange");
-    if (RS::dispatch->AllocationCopy3DRange == NULL) {
+    if (RS::dispatch->AllocationCopy3DRange == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationCopy3DRange");
         return false;
     }
     RS::dispatch->SamplerCreate = (SamplerCreateFnPtr)dlsym(handle, "rsSamplerCreate");
-    if (RS::dispatch->SamplerCreate == NULL) {
+    if (RS::dispatch->SamplerCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->SamplerCreate");
         return false;
     }
     RS::dispatch->ScriptBindAllocation = (ScriptBindAllocationFnPtr)dlsym(handle, "rsScriptBindAllocation");
-    if (RS::dispatch->ScriptBindAllocation == NULL) {
+    if (RS::dispatch->ScriptBindAllocation == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptBindAllocation");
         return false;
     }
     RS::dispatch->ScriptSetTimeZone = (ScriptSetTimeZoneFnPtr)dlsym(handle, "rsScriptSetTimeZone");
-    if (RS::dispatch->ScriptSetTimeZone == NULL) {
+    if (RS::dispatch->ScriptSetTimeZone == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetTimeZone");
         return false;
     }
     RS::dispatch->ScriptInvoke = (ScriptInvokeFnPtr)dlsym(handle, "rsScriptInvoke");
-    if (RS::dispatch->ScriptInvoke == NULL) {
+    if (RS::dispatch->ScriptInvoke == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptInvoke");
         return false;
     }
     RS::dispatch->ScriptInvokeV = (ScriptInvokeVFnPtr)dlsym(handle, "rsScriptInvokeV");
-    if (RS::dispatch->ScriptInvokeV == NULL) {
+    if (RS::dispatch->ScriptInvokeV == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptInvokeV");
         return false;
     }
     RS::dispatch->ScriptForEach = (ScriptForEachFnPtr)dlsym(handle, "rsScriptForEach");
-    if (RS::dispatch->ScriptForEach == NULL) {
+    if (RS::dispatch->ScriptForEach == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptForEach");
         return false;
     }
     RS::dispatch->ScriptSetVarI = (ScriptSetVarIFnPtr)dlsym(handle, "rsScriptSetVarI");
-    if (RS::dispatch->ScriptSetVarI == NULL) {
+    if (RS::dispatch->ScriptSetVarI == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarI");
         return false;
     }
     RS::dispatch->ScriptSetVarObj = (ScriptSetVarObjFnPtr)dlsym(handle, "rsScriptSetVarObj");
-    if (RS::dispatch->ScriptSetVarObj == NULL) {
+    if (RS::dispatch->ScriptSetVarObj == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarObj");
         return false;
     }
     RS::dispatch->ScriptSetVarJ = (ScriptSetVarJFnPtr)dlsym(handle, "rsScriptSetVarJ");
-    if (RS::dispatch->ScriptSetVarJ == NULL) {
+    if (RS::dispatch->ScriptSetVarJ == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarJ");
         return false;
     }
     RS::dispatch->ScriptSetVarF = (ScriptSetVarFFnPtr)dlsym(handle, "rsScriptSetVarF");
-    if (RS::dispatch->ScriptSetVarF == NULL) {
+    if (RS::dispatch->ScriptSetVarF == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarF");
         return false;
     }
     RS::dispatch->ScriptSetVarD = (ScriptSetVarDFnPtr)dlsym(handle, "rsScriptSetVarD");
-    if (RS::dispatch->ScriptSetVarD == NULL) {
+    if (RS::dispatch->ScriptSetVarD == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarD");
         return false;
     }
     RS::dispatch->ScriptSetVarV = (ScriptSetVarVFnPtr)dlsym(handle, "rsScriptSetVarV");
-    if (RS::dispatch->ScriptSetVarV == NULL) {
+    if (RS::dispatch->ScriptSetVarV == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarV");
         return false;
     }
     RS::dispatch->ScriptGetVarV = (ScriptGetVarVFnPtr)dlsym(handle, "rsScriptGetVarV");
-    if (RS::dispatch->ScriptGetVarV == NULL) {
+    if (RS::dispatch->ScriptGetVarV == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptGetVarV");
         return false;
     }
     RS::dispatch->ScriptSetVarVE = (ScriptSetVarVEFnPtr)dlsym(handle, "rsScriptSetVarVE");
-    if (RS::dispatch->ScriptSetVarVE == NULL) {
+    if (RS::dispatch->ScriptSetVarVE == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptSetVarVE");
         return false;
     }
     RS::dispatch->ScriptCCreate = (ScriptCCreateFnPtr)dlsym(handle, "rsScriptCCreate");
-    if (RS::dispatch->ScriptCCreate == NULL) {
+    if (RS::dispatch->ScriptCCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptCCreate");
         return false;
     }
     RS::dispatch->ScriptIntrinsicCreate = (ScriptIntrinsicCreateFnPtr)dlsym(handle, "rsScriptIntrinsicCreate");
-    if (RS::dispatch->ScriptIntrinsicCreate == NULL) {
+    if (RS::dispatch->ScriptIntrinsicCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptIntrinsicCreate");
         return false;
     }
     RS::dispatch->ScriptKernelIDCreate = (ScriptKernelIDCreateFnPtr)dlsym(handle, "rsScriptKernelIDCreate");
-    if (RS::dispatch->ScriptKernelIDCreate == NULL) {
+    if (RS::dispatch->ScriptKernelIDCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptKernelIDCreate");
         return false;
     }
     RS::dispatch->ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
-    if (RS::dispatch->ScriptFieldIDCreate == NULL) {
+    if (RS::dispatch->ScriptFieldIDCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptFieldIDCreate");
         return false;
     }
     RS::dispatch->ScriptGroupCreate = (ScriptGroupCreateFnPtr)dlsym(handle, "rsScriptGroupCreate");
-    if (RS::dispatch->ScriptGroupCreate == NULL) {
+    if (RS::dispatch->ScriptGroupCreate == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptGroupCreate");
         return false;
     }
     RS::dispatch->ScriptGroupSetOutput = (ScriptGroupSetOutputFnPtr)dlsym(handle, "rsScriptGroupSetOutput");
-    if (RS::dispatch->ScriptGroupSetOutput == NULL) {
+    if (RS::dispatch->ScriptGroupSetOutput == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetOutput");
         return false;
     }
     RS::dispatch->ScriptGroupSetInput = (ScriptGroupSetInputFnPtr)dlsym(handle, "rsScriptGroupSetInput");
-    if (RS::dispatch->ScriptGroupSetInput == NULL) {
+    if (RS::dispatch->ScriptGroupSetInput == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptGroupSetInput");
         return false;
     }
     RS::dispatch->ScriptGroupExecute = (ScriptGroupExecuteFnPtr)dlsym(handle, "rsScriptGroupExecute");
-    if (RS::dispatch->ScriptGroupExecute == NULL) {
+    if (RS::dispatch->ScriptGroupExecute == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->ScriptGroupExecute");
         return false;
     }
     RS::dispatch->AllocationIoSend = (AllocationIoSendFnPtr)dlsym(handle, "rsAllocationIoSend");
-    if (RS::dispatch->AllocationIoSend == NULL) {
+    if (RS::dispatch->AllocationIoSend == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationIoSend");
         return false;
     }
     RS::dispatch->AllocationIoReceive = (AllocationIoReceiveFnPtr)dlsym(handle, "rsAllocationIoReceive");
-    if (RS::dispatch->AllocationIoReceive == NULL) {
+    if (RS::dispatch->AllocationIoReceive == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationIoReceive");
         return false;
     }
     RS::dispatch->AllocationGetPointer = (AllocationGetPointerFnPtr)dlsym(handle, "rsAllocationGetPointer");
-    if (RS::dispatch->AllocationGetPointer == NULL) {
+    if (RS::dispatch->AllocationGetPointer == nullptr) {
         ALOGV("Couldn't initialize RS::dispatch->AllocationGetPointer");
         //return false;
     }
@@ -418,7 +418,7 @@
 // because that's when we changed libRS to extern "C" entry points
 static bool loadSO(const char* filename) {
     void* handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
-    if (handle == NULL) {
+    if (handle == nullptr) {
         ALOGV("couldn't dlopen %s, %s", filename, dlerror());
         return false;
     }
@@ -507,7 +507,7 @@
 
     pid_t mNativeMessageThreadId;
 
-    int status = pthread_create(&mMessageThreadId, NULL, threadProc, this);
+    int status = pthread_create(&mMessageThreadId, nullptr, threadProc, this);
     if (status) {
         ALOGE("Failed to start RS message thread.");
         return false;
@@ -567,7 +567,7 @@
         case RS_MESSAGE_TO_CLIENT_ERROR:
             ALOGE("RS Error %s", (const char *)rbuf);
             rs->throwError(RS_ERROR_RUNTIME_ERROR, "Error returned from runtime");
-            if(rs->mMessageFunc != NULL) {
+            if(rs->mMessageFunc != nullptr) {
                 rs->mErrorFunc(usrID, (const char *)rbuf);
             }
             break;
@@ -581,7 +581,7 @@
             usleep(1000);
             break;
         case RS_MESSAGE_TO_CLIENT_USER:
-            if(rs->mMessageFunc != NULL) {
+            if(rs->mMessageFunc != nullptr) {
                 rs->mMessageFunc(usrID, rbuf, receiveLen);
             } else {
                 ALOGE("Received a message from the script with no message handler installed.");
@@ -597,7 +597,7 @@
         free(rbuf);
     }
     ALOGV("RS Message thread exiting.");
-    return NULL;
+    return nullptr;
 }
 
 void RS::setErrorHandler(ErrorHandlerFunc_t func) {
diff --git a/cpp/Sampler.cpp b/cpp/Sampler.cpp
index 767d626..bf99125 100644
--- a/cpp/Sampler.cpp
+++ b/cpp/Sampler.cpp
@@ -56,10 +56,10 @@
 }
 
 #define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(sp<RS> rs) { \
-        if (rs->mSamplers.N == NULL) {                                  \
+        if (rs->mSamplers.N == nullptr) {                                \
             rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)); \
-        }                                                               \
-        return rs->mSamplers.N;                                         \
+        }                                                                \
+        return rs->mSamplers.N;                                          \
     }
 
 CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST);
diff --git a/cpp/Script.cpp b/cpp/Script.cpp
index 8e1af54..889bb02 100644
--- a/cpp/Script.cpp
+++ b/cpp/Script.cpp
@@ -28,12 +28,12 @@
 
 void Script::forEach(uint32_t slot, sp<const Allocation> ain, sp<const Allocation> aout,
                        const void *usr, size_t usrLen) const {
-    if ((ain == NULL) && (aout == NULL)) {
+    if ((ain == nullptr) && (aout == nullptr)) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "At least one of ain or aout is required to be non-null.");
     }
     void *in_id = BaseObj::getObjID(ain);
     void *out_id = BaseObj::getObjID(aout);
-    tryDispatch(mRS, RS::dispatch->ScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, NULL, 0));
+    tryDispatch(mRS, RS::dispatch->ScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, nullptr, 0));
 }
 
 
@@ -47,7 +47,7 @@
 
 
 void Script::setVar(uint32_t index, sp<const BaseObj> o) const {
-    tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == NULL) ? 0 : o->getID()));
+    tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == nullptr) ? 0 : o->getID()));
 }
 
 void Script::setVar(uint32_t index, const void *v, size_t len) const {
diff --git a/cpp/ScriptC.cpp b/cpp/ScriptC.cpp
index 69d3bd5..d431355 100644
--- a/cpp/ScriptC.cpp
+++ b/cpp/ScriptC.cpp
@@ -23,7 +23,7 @@
                  const void *codeTxt, size_t codeLength,
                  const char *cachedName, size_t cachedNameLength,
                  const char *cacheDir, size_t cacheDirLength)
-: Script(NULL, rs) {
+: Script(nullptr, rs) {
     mID = RS::dispatch->ScriptCCreate(rs->getContext(), cachedName, cachedNameLength,
                                       rs->mCacheDir.c_str(), rs->mCacheDir.length(), (const char *)codeTxt, codeLength);
 }
diff --git a/cpp/ScriptIntrinsics.cpp b/cpp/ScriptIntrinsics.cpp
index ba1e5f4..42903ce 100644
--- a/cpp/ScriptIntrinsics.cpp
+++ b/cpp/ScriptIntrinsics.cpp
@@ -23,7 +23,7 @@
 using namespace RSC;
 
 ScriptIntrinsic::ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e)
-    : Script(NULL, rs) {
+    : Script(nullptr, rs) {
     mID = createDispatch(rs, RS::dispatch->ScriptIntrinsicCreate(rs->getContext(), id, e->getID()));
     mElement = e;
 }
@@ -35,7 +35,7 @@
 sp<ScriptIntrinsic3DLUT> ScriptIntrinsic3DLUT::create(sp<RS> rs, sp<const Element> e) {
     if (e->isCompatible(Element::U8_4(rs)) == false) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Element not supported for intrinsic");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsic3DLUT(rs, e);
 }
@@ -50,7 +50,7 @@
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "3DLUT forEach element mismatch");
         return;
     }
-    Script::forEach(0, ain, aout, NULL, 0);
+    Script::forEach(0, ain, aout, nullptr, 0);
 }
 void ScriptIntrinsic3DLUT::setLUT(sp<Allocation> lut) {
     sp<const Type> t = lut->getType();
@@ -69,7 +69,7 @@
 sp<ScriptIntrinsicBlend> ScriptIntrinsicBlend::create(sp<RS> rs, sp<const Element> e) {
     if (e->isCompatible(Element::U8_4(rs)) == false) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Element not supported for intrinsic");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsicBlend(rs, e);
 }
@@ -83,7 +83,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(0, in, out, NULL, 0);
+    Script::forEach(0, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSrc(sp<Allocation> in, sp<Allocation> out) {
@@ -91,7 +91,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(1, in, out, NULL, 0);
+    Script::forEach(1, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachDst(sp<Allocation> in, sp<Allocation> out) {
@@ -99,7 +99,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(2, in, out, NULL, 0);
+    Script::forEach(2, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSrcOver(sp<Allocation> in, sp<Allocation> out) {
@@ -107,7 +107,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(3, in, out, NULL, 0);
+    Script::forEach(3, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachDstOver(sp<Allocation> in, sp<Allocation> out) {
@@ -115,7 +115,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(4, in, out, NULL, 0);
+    Script::forEach(4, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSrcIn(sp<Allocation> in, sp<Allocation> out) {
@@ -123,7 +123,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(5, in, out, NULL, 0);
+    Script::forEach(5, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachDstIn(sp<Allocation> in, sp<Allocation> out) {
@@ -131,7 +131,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(6, in, out, NULL, 0);
+    Script::forEach(6, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSrcOut(sp<Allocation> in, sp<Allocation> out) {
@@ -139,7 +139,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(7, in, out, NULL, 0);
+    Script::forEach(7, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachDstOut(sp<Allocation> in, sp<Allocation> out) {
@@ -147,7 +147,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(8, in, out, NULL, 0);
+    Script::forEach(8, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSrcAtop(sp<Allocation> in, sp<Allocation> out) {
@@ -155,7 +155,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(9, in, out, NULL, 0);
+    Script::forEach(9, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachDstAtop(sp<Allocation> in, sp<Allocation> out) {
@@ -163,7 +163,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(10, in, out, NULL, 0);
+    Script::forEach(10, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachXor(sp<Allocation> in, sp<Allocation> out) {
@@ -171,7 +171,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(11, in, out, NULL, 0);
+    Script::forEach(11, in, out, nullptr, 0);
 }
 
 // Numbering jumps here
@@ -180,7 +180,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(14, in, out, NULL, 0);
+    Script::forEach(14, in, out, nullptr, 0);
 }
 
 // Numbering jumps here
@@ -189,7 +189,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(34, in, out, NULL, 0);
+    Script::forEach(34, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlend::forEachSubtract(sp<Allocation> in, sp<Allocation> out) {
@@ -197,7 +197,7 @@
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
     }
-    Script::forEach(35, in, out, NULL, 0);
+    Script::forEach(35, in, out, nullptr, 0);
 }
 
 
@@ -207,7 +207,7 @@
     if ((e->isCompatible(Element::U8_4(rs)) == false) &&
         (e->isCompatible(Element::U8(rs)) == false)) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blur");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsicBlur(rs, e);
 }
@@ -230,7 +230,7 @@
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blur output");
         return;
     }
-    Script::forEach(0, NULL, out, NULL, 0);
+    Script::forEach(0, nullptr, out, nullptr, 0);
 }
 
 void ScriptIntrinsicBlur::setRadius(float radius) {
@@ -279,7 +279,7 @@
         return;
     }
 
-    Script::forEach(0, in, out, NULL, 0);
+    Script::forEach(0, in, out, nullptr, 0);
 }
 
 void ScriptIntrinsicColorMatrix::setAdd(float* add) {
@@ -346,7 +346,7 @@
         !(e->isCompatible(Element::F32_3(rs))) &&
         !(e->isCompatible(Element::F32_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for Convolve3x3");
-        return NULL;
+        return nullptr;
     }
 
     return new ScriptIntrinsicConvolve3x3(rs, e);
@@ -370,7 +370,7 @@
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Element mismatch in Convolve3x3");
         return;
     }
-    Script::forEach(0, NULL, out, NULL, 0);
+    Script::forEach(0, nullptr, out, nullptr, 0);
 }
 
 void ScriptIntrinsicConvolve3x3::setCoefficients(float* v) {
@@ -387,7 +387,7 @@
         !(e->isCompatible(Element::F32_3(rs))) &&
         !(e->isCompatible(Element::F32_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for Convolve5x5");
-        return NULL;
+        return nullptr;
     }
 
     return new ScriptIntrinsicConvolve5x5(rs, e);
@@ -412,7 +412,7 @@
         return;
     }
 
-    Script::forEach(0, NULL, out, NULL, 0);
+    Script::forEach(0, nullptr, out, nullptr, 0);
 }
 
 void ScriptIntrinsicConvolve5x5::setCoefficients(float* v) {
@@ -420,7 +420,7 @@
 }
 
 sp<ScriptIntrinsicHistogram> ScriptIntrinsicHistogram::create(sp<RS> rs) {
-    return new ScriptIntrinsicHistogram(rs, NULL);
+    return new ScriptIntrinsicHistogram(rs, nullptr);
 }
 
 ScriptIntrinsicHistogram::ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e)
@@ -483,7 +483,7 @@
         return;
     }
 
-    Script::forEach(0, ain, NULL, NULL, 0);
+    Script::forEach(0, ain, nullptr, nullptr, 0);
 }
 
 
@@ -501,13 +501,13 @@
         return;
     }
 
-    Script::forEach(1, ain, NULL, NULL, 0);
+    Script::forEach(1, ain, nullptr, nullptr, 0);
 }
 
 sp<ScriptIntrinsicLUT> ScriptIntrinsicLUT::create(sp<RS> rs, sp<const Element> e) {
     if (!(e->isCompatible(Element::U8_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for LUT");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsicLUT(rs, e);
 }
@@ -534,7 +534,7 @@
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for LUT");
         return;
     }
-    Script::forEach(0, ain, aout, NULL, 0);
+    Script::forEach(0, ain, aout, nullptr, 0);
 
 }
 
@@ -572,7 +572,7 @@
 sp<ScriptIntrinsicYuvToRGB> ScriptIntrinsicYuvToRGB::create(sp<RS> rs, sp<const Element> e) {
     if (!(e->isCompatible(Element::U8_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for YuvToRGB");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsicYuvToRGB(rs, e);
 }
@@ -596,13 +596,13 @@
         return;
     }
 
-    Script::forEach(0, NULL, out, NULL, 0);
+    Script::forEach(0, nullptr, out, nullptr, 0);
 }
 
 sp<ScriptIntrinsicVP9LoopFilter> ScriptIntrinsicVP9LoopFilter::create(sp<RS> rs, sp<const Element> e) {
     if (!(e->isCompatible(Element::U8(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for Vp9LoopFilter");
-        return NULL;
+        return nullptr;
     }
     return new ScriptIntrinsicVP9LoopFilter(rs, e);
 }
@@ -610,7 +610,8 @@
 ScriptIntrinsicVP9LoopFilter::ScriptIntrinsicVP9LoopFilter(sp<RS> rs, sp<const Element> e)
     : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_LOOP_FILTER, e) {
     sp<const Type> t_pad = Type::create(rs, e, 1, 0, 0);
-    mPadAlloc = Allocation::createTyped(rs, t_pad, RS_ALLOCATION_MIPMAP_NONE, RS_ALLOCATION_USAGE_SCRIPT, NULL);
+    mPadAlloc = Allocation::createTyped(rs, t_pad, RS_ALLOCATION_MIPMAP_NONE,
+                                        RS_ALLOCATION_USAGE_SCRIPT, nullptr);
 }
 
 void ScriptIntrinsicVP9LoopFilter::setLoopFilterDomain(int start, int stop, int numPlanes, int miRows, int miCols) {
@@ -641,5 +642,5 @@
         return;
     }
     Script::setVar(4, frameBuffer);
-    Script::forEach(0, mPadAlloc, NULL, NULL, 0);
+    Script::forEach(0, mPadAlloc, nullptr, nullptr, 0);
 }
diff --git a/cpp/Type.cpp b/cpp/Type.cpp
index d053730..bc28165 100644
--- a/cpp/Type.cpp
+++ b/cpp/Type.cpp
@@ -72,7 +72,7 @@
     mDimZ = 0;
     mDimMipmaps = false;
     mDimFaces = false;
-    mElement = NULL;
+    mElement = nullptr;
     mYuvFormat = RS_YUV_NONE;
 }
 
diff --git a/cpp/rsCppInternal.h b/cpp/rsCppInternal.h
index ae43d47..81b690f 100644
--- a/cpp/rsCppInternal.h
+++ b/cpp/rsCppInternal.h
@@ -26,7 +26,7 @@
     }
 
 #define createDispatch(rs, dispatch) \
-    rs->getError() == RS_SUCCESS ? dispatch : NULL
+    rs->getError() == RS_SUCCESS ? dispatch : nullptr
 
 #undef LOG_TAG
 #undef LOG_NDEBUG
diff --git a/cpp/util/RefBase.h b/cpp/util/RefBase.h
index 5993e28..01c0b5f 100644
--- a/cpp/util/RefBase.h
+++ b/cpp/util/RefBase.h
@@ -374,7 +374,7 @@
 wp<T>& wp<T>::operator = (const sp<T>& other)
 {
     weakref_type* newRefs =
-        other != NULL ? other->createWeak(this) : 0;
+        other != NULL ? other->createWeak(this) : NULL;
     T* otherPtr(other.m_ptr);
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = otherPtr;
@@ -386,7 +386,7 @@
 wp<T>& wp<T>::operator = (U* other)
 {
     weakref_type* newRefs =
-        other ? other->createWeak(this) : 0;
+        other ? other->createWeak(this) : NULL;
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = other;
     m_refs = newRefs;
@@ -409,7 +409,7 @@
 wp<T>& wp<T>::operator = (const sp<U>& other)
 {
     weakref_type* newRefs =
-        other != NULL ? other->createWeak(this) : 0;
+        other != NULL ? other->createWeak(this) : NULL;
     U* otherPtr(other.m_ptr);
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = otherPtr;
diff --git a/cpu_ref/linkloader/android/librsloader.cpp b/cpu_ref/linkloader/android/librsloader.cpp
index 7fbaa7c..fa74a7d 100644
--- a/cpu_ref/linkloader/android/librsloader.cpp
+++ b/cpu_ref/linkloader/android/librsloader.cpp
@@ -53,12 +53,12 @@
                                         void *find_symbol_context) {
   RSExecRef object = rsloaderLoadExecutable(buf, buf_size);
   if (!object) {
-    return NULL;
+    return nullptr;
   }
 
   if (!rsloaderRelocateExecutable(object, find_symbol, find_symbol_context)) {
     rsloaderDisposeExec(object);
-    return NULL;
+    return nullptr;
   }
 
   return object;
@@ -75,7 +75,7 @@
 #endif
   if (!object) {
     ALOGE("Unable to load the ELF object.");
-    return NULL;
+    return nullptr;
   }
 
   return wrap(object.release());
@@ -156,7 +156,7 @@
 #endif
 
   if (!symtab) {
-    return NULL;
+    return nullptr;
   }
 
 #if defined(__LP64__) || defined(__x86_64__)
@@ -167,7 +167,7 @@
 
   if (!symbol) {
     ALOGV("Symbol not found: %s\n", name);
-    return NULL;
+    return nullptr;
   }
 
   int machine = object->getHeader()->getMachine();
diff --git a/cpu_ref/linkloader/include/ELFHeader.h b/cpu_ref/linkloader/include/ELFHeader.h
index e6c66f6..e6535f0 100644
--- a/cpu_ref/linkloader/include/ELFHeader.h
+++ b/cpu_ref/linkloader/include/ELFHeader.h
@@ -149,19 +149,19 @@
   static ELFHeader *read(Archiver &AR) {
     if (!AR) {
       // Archiver is in bad state before calling read function.
-      // Return NULL and do nothing.
-      return 0;
+      // Return nullptr and do nothing.
+      return nullptr;
     }
 
     std::unique_ptr<ELFHeader> header(new ELFHeader());
     if (!header->serialize(AR)) {
-      // Unable to read the structure.  Return NULL.
-      return 0;
+      // Unable to read the structure.  Return nullptr.
+      return nullptr;
     }
 
     if (!header->isValid()) {
-      // Header read from archiver is not valid.  Return NULL.
-      return 0;
+      // Header read from archiver is not valid.  Return nullptr.
+      return nullptr;
     }
 
     return header.release();
diff --git a/cpu_ref/linkloader/include/ELFObject.h b/cpu_ref/linkloader/include/ELFObject.h
index 86ac6bf..0910067 100644
--- a/cpu_ref/linkloader/include/ELFObject.h
+++ b/cpu_ref/linkloader/include/ELFObject.h
@@ -54,7 +54,7 @@
   }
 
 private:
-  ELFObject() : SHNCommonDataPtr(NULL), missingSymbols(false) { }
+  ELFObject() : SHNCommonDataPtr(nullptr), missingSymbols(false) { }
 
 public:
   template <typename Archiver>
@@ -92,7 +92,7 @@
 
     // Ensure the free size is sufficient
     if (SHNCommonDataFreeSize < size) {
-      return NULL;
+      return nullptr;
     }
 
     // Allcoate
diff --git a/cpu_ref/linkloader/include/ELFSectionBits.h b/cpu_ref/linkloader/include/ELFSectionBits.h
index b6e4590..33b4259 100644
--- a/cpu_ref/linkloader/include/ELFSectionBits.h
+++ b/cpu_ref/linkloader/include/ELFSectionBits.h
@@ -28,7 +28,7 @@
   MemChunk chunk;
 
 protected:
-  ELFSectionBits() : sh(NULL) { }
+  ELFSectionBits() : sh(nullptr) { }
 
 public:
   virtual void print() const;
diff --git a/cpu_ref/linkloader/include/ELFSectionProgBits.h b/cpu_ref/linkloader/include/ELFSectionProgBits.h
index a642b16..9c1d428 100644
--- a/cpu_ref/linkloader/include/ELFSectionProgBits.h
+++ b/cpu_ref/linkloader/include/ELFSectionProgBits.h
@@ -64,7 +64,7 @@
       break;
 
     default:
-      stubs = NULL;
+      stubs = nullptr;
     }
   }
 
diff --git a/cpu_ref/linkloader/lib/MemChunk.cpp b/cpu_ref/linkloader/lib/MemChunk.cpp
index 5d6c102..8a9b548 100644
--- a/cpu_ref/linkloader/lib/MemChunk.cpp
+++ b/cpu_ref/linkloader/lib/MemChunk.cpp
@@ -41,10 +41,10 @@
 static uintptr_t StartAddr = 0x7e000000UL;
 #endif
 
-AllocFunc MemChunk::VendorAlloc = NULL;
-FreeFunc MemChunk::VendorFree = NULL;
+AllocFunc MemChunk::VendorAlloc = nullptr;
+FreeFunc MemChunk::VendorFree = nullptr;
 
-MemChunk::MemChunk() : buf(NULL), buf_size(0), bVendorBuf(true) {
+MemChunk::MemChunk() : buf(nullptr), buf_size(0), bVendorBuf(true) {
 }
 
 MemChunk::~MemChunk() {
diff --git a/cpu_ref/linkloader/lib/StubLayout.cpp b/cpu_ref/linkloader/lib/StubLayout.cpp
index dd4b139..1ff9e16 100644
--- a/cpu_ref/linkloader/lib/StubLayout.cpp
+++ b/cpu_ref/linkloader/lib/StubLayout.cpp
@@ -23,7 +23,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 
-StubLayout::StubLayout() : table(NULL), count(0) {
+StubLayout::StubLayout() : table(nullptr), count(0) {
 }
 
 void StubLayout::initStubTable(unsigned char *table_, size_t count_) {
@@ -42,7 +42,7 @@
   // We have to create a new stub
   if (count == 0) {
     // No free stub slot is available
-    return NULL;
+    return nullptr;
   }
 
   // Initialize the stub
diff --git a/cpu_ref/linkloader/main.cpp b/cpu_ref/linkloader/main.cpp
index 072595f..011e1d7 100644
--- a/cpu_ref/linkloader/main.cpp
+++ b/cpu_ref/linkloader/main.cpp
@@ -54,7 +54,7 @@
 
   // Open the file
   int fd = -1;
-  unsigned char const *image = NULL;
+  unsigned char const *image = nullptr;
   size_t image_size = 0;
 
   if (!open_mmap_file(filename, fd, image, image_size)) {
@@ -135,7 +135,7 @@
   }
 
   assert(0 && "Can't find symbol.");
-  return 0;
+  return nullptr;
 }
 
 template <unsigned Bitwidth, typename Archiver>
diff --git a/cpu_ref/linkloader/utils/serialize.h b/cpu_ref/linkloader/utils/serialize.h
index 3d15158..49ba400 100644
--- a/cpu_ref/linkloader/utils/serialize.h
+++ b/cpu_ref/linkloader/utils/serialize.h
@@ -66,21 +66,21 @@
   bool good;
 
 public:
-  ArchiveReader(unsigned char const *buf = NULL, size_t size = 0)
+  ArchiveReader(unsigned char const *buf = nullptr, size_t size = 0)
   : buf_begin(buf), buf_end(buf + size),
-    cursor(buf), cursor_base(NULL), good(buf != NULL) {
+    cursor(buf), cursor_base(nullptr), good(buf != nullptr) {
   }
 
   void prologue(size_t size) {
-    rsl_assert(cursor_base == NULL);
+    rsl_assert(cursor_base == nullptr);
     cursor_base = cursor;
   }
 
   void epilogue(size_t size) {
-    rsl_assert(cursor_base != NULL);
+    rsl_assert(cursor_base != nullptr);
     rsl_assert(cursor_base + size >= cursor);
     cursor = cursor_base + size;
-    cursor_base = NULL;
+    cursor_base = nullptr;
   }
 
   void seek(off_t off, bool from_begin = false) {
diff --git a/cpu_ref/rsCpuCore.cpp b/cpu_ref/rsCpuCore.cpp
index ee4d1e6..f40f411 100644
--- a/cpu_ref/rsCpuCore.cpp
+++ b/cpu_ref/rsCpuCore.cpp
@@ -72,11 +72,11 @@
 
     RsdCpuReferenceImpl *cpu = new RsdCpuReferenceImpl(rsc);
     if (!cpu) {
-        return NULL;
+        return nullptr;
     }
     if (!cpu->init(version_major, version_minor, lfn, slfn)) {
         delete cpu;
-        return NULL;
+        return nullptr;
     }
 
 #ifndef RS_COMPATIBILITY_LIB
@@ -116,9 +116,9 @@
     memset(&mTlsStruct, 0, sizeof(mTlsStruct));
     mExit = false;
 #ifndef RS_COMPATIBILITY_LIB
-    mLinkRuntimeCallback = NULL;
-    mSelectRTCallback = NULL;
-    mSetupCompilerCallback = NULL;
+    mLinkRuntimeCallback = nullptr;
+    mSelectRTCallback = nullptr;
+    mSetupCompilerCallback = nullptr;
 #endif
 }
 
@@ -160,7 +160,7 @@
     }
 
     //ALOGV("RS helperThread exited %p idx=%i", dc, idx);
-    return NULL;
+    return nullptr;
 }
 
 void RsdCpuReferenceImpl::launchThreads(WorkerCallback_t cbk, void *data) {
@@ -246,7 +246,7 @@
 
     lockMutex();
     if (!gThreadTLSKeyCount) {
-        int status = pthread_key_create(&gThreadTLSKey, NULL);
+        int status = pthread_key_create(&gThreadTLSKey, nullptr);
         if (status) {
             ALOGE("Failed to init thread tls key.");
             unlockMutex();
@@ -257,7 +257,7 @@
     unlockMutex();
 
     mTlsStruct.mContext = mRSC;
-    mTlsStruct.mScript = NULL;
+    mTlsStruct.mScript = nullptr;
     int status = pthread_setspecific(gThreadTLSKey, &mTlsStruct);
     if (status) {
         ALOGE("pthread_setspecific %i", status);
@@ -282,7 +282,7 @@
     mWorkers.mThreadId = (pthread_t *) calloc(mWorkers.mCount, sizeof(pthread_t));
     mWorkers.mNativeThreadId = (pid_t *) calloc(mWorkers.mCount, sizeof(pid_t));
     mWorkers.mLaunchSignals = new Signal[mWorkers.mCount];
-    mWorkers.mLaunchCallback = NULL;
+    mWorkers.mLaunchCallback = nullptr;
 
     mWorkers.mCompleteSignal.init();
 
@@ -322,8 +322,8 @@
 
 RsdCpuReferenceImpl::~RsdCpuReferenceImpl() {
     mExit = true;
-    mWorkers.mLaunchData = NULL;
-    mWorkers.mLaunchCallback = NULL;
+    mWorkers.mLaunchData = nullptr;
+    mWorkers.mLaunchCallback = nullptr;
     mWorkers.mRunningCount = mWorkers.mCount;
     __sync_synchronize();
     for (uint32_t ct = 0; ct < mWorkers.mCount; ct++) {
@@ -569,7 +569,7 @@
     if (sc) {
         tls->mScript = sc->getScript();
     } else {
-        tls->mScript = NULL;
+        tls->mScript = nullptr;
     }
     return old;
 }
@@ -591,7 +591,7 @@
 #endif
         )) {
         delete i;
-        return NULL;
+        return nullptr;
     }
     return i;
 }
@@ -622,7 +622,7 @@
 RsdCpuReference::CpuScript * RsdCpuReferenceImpl::createIntrinsic(const Script *s,
                                     RsScriptIntrinsicID iid, Element *e) {
 
-    RsdCpuScriptImpl *i = NULL;
+    RsdCpuScriptImpl *i = nullptr;
     switch (iid) {
     case RS_SCRIPT_INTRINSIC_ID_3DLUT:
         i = rsdIntrinsic_3DLUT(this, s, e);
@@ -671,7 +671,7 @@
     CpuScriptGroupImpl *sgi = new CpuScriptGroupImpl(this, sg);
     if (!sgi->init()) {
         delete sgi;
-        return NULL;
+        return nullptr;
     }
     return sgi;
 }
diff --git a/cpu_ref/rsCpuCore.h b/cpu_ref/rsCpuCore.h
index 2fea3fc..bfd5e51 100644
--- a/cpu_ref/rsCpuCore.h
+++ b/cpu_ref/rsCpuCore.h
@@ -65,11 +65,11 @@
 
     ~RsExpandKernelDriverInfo() {
         if (heapAllocatedArrays) {
-            if (inPtrs != NULL) {
+            if (inPtrs != nullptr) {
                 delete[] inPtrs;
             }
 
-            if (inStrides != NULL) {
+            if (inStrides != nullptr) {
                 delete[] inStrides;
             }
         }
diff --git a/cpu_ref/rsCpuIntrinsicBlur.cpp b/cpu_ref/rsCpuIntrinsicBlur.cpp
index 7f888e9..3214d42 100644
--- a/cpu_ref/rsCpuIntrinsicBlur.cpp
+++ b/cpu_ref/rsCpuIntrinsicBlur.cpp
@@ -414,7 +414,7 @@
                                                      const Script *s, const Element *e)
             : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_BLUR) {
 
-    mRootPtr = NULL;
+    mRootPtr = nullptr;
     if (e->getType() == RS_TYPE_UNSIGNED_8) {
         switch (e->getVectorSize()) {
         case 1:
diff --git a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
index f072e52..af75701 100644
--- a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
+++ b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
@@ -464,7 +464,7 @@
 
 void * selectKernel(Key_t key)
 {
-    void * kernel = NULL;
+    void * kernel = nullptr;
 
     // inType, outType float if nonzero
     if (!(key.u.inType || key.u.outType)) {
@@ -491,7 +491,7 @@
     }
 
     uint8_t *buf = mBuf;
-    uint8_t *buf2 = NULL;
+    uint8_t *buf2 = nullptr;
 
     int ops[5][4];  // 0=unused, 1 = set, 2 = accumulate, 3 = final
     int opInit[4] = {0, 0, 0, 0};
@@ -901,7 +901,7 @@
     if(x2 > x1) {
         int32_t len = x2 - x1;
         if (gArchUseSIMD) {
-            if((cp->mOptKernel != NULL) && (len >= 4)) {
+            if((cp->mOptKernel != nullptr) && (len >= 4)) {
                 // The optimized kernel processes 4 pixels at once
                 // and requires a minimum of 1 chunk of 4
                 cp->mOptKernel(out, in, cp->ip, len >> 2);
@@ -963,17 +963,17 @@
     Key_t key = computeKey(ein, eout);
 
 #if defined(ARCH_X86_HAVE_SSSE3)
-    if ((mOptKernel == NULL) || (mLastKey.key != key.key)) {
+    if ((mOptKernel == nullptr) || (mLastKey.key != key.key)) {
         // FIXME: Disable mOptKernel to pass RS color matrix CTS cases
         // mOptKernel = (void (*)(void *, const void *, const short *, uint32_t)) selectKernel(key);
         mLastKey = key;
     }
 
 #else //if !defined(ARCH_X86_HAVE_SSSE3)
-    if ((mOptKernel == NULL) || (mLastKey.key != key.key)) {
+    if ((mOptKernel == nullptr) || (mLastKey.key != key.key)) {
         if (mBuf) munmap(mBuf, mBufSize);
-        mBuf = NULL;
-        mOptKernel = NULL;
+        mBuf = nullptr;
+        mOptKernel = nullptr;
         if (build(key)) {
             mOptKernel = (void (*)(void *, const void *, const short *, uint32_t)) mBuf;
         }
@@ -1008,9 +1008,9 @@
             : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_COLOR_MATRIX) {
 
     mLastKey.key = 0;
-    mBuf = NULL;
+    mBuf = nullptr;
     mBufSize = 0;
-    mOptKernel = NULL;
+    mOptKernel = nullptr;
     const static float defaultMatrix[] = {
         1.f, 0.f, 0.f, 0.f,
         0.f, 1.f, 0.f, 0.f,
@@ -1024,8 +1024,8 @@
 
 RsdCpuScriptIntrinsicColorMatrix::~RsdCpuScriptIntrinsicColorMatrix() {
     if (mBuf) munmap(mBuf, mBufSize);
-    mBuf = NULL;
-    mOptKernel = NULL;
+    mBuf = nullptr;
+    mOptKernel = nullptr;
 }
 
 void RsdCpuScriptIntrinsicColorMatrix::populateScript(Script *s) {
diff --git a/cpu_ref/rsCpuIntrinsicHistogram.cpp b/cpu_ref/rsCpuIntrinsicHistogram.cpp
index d3dce6d..4779187 100644
--- a/cpu_ref/rsCpuIntrinsicHistogram.cpp
+++ b/cpu_ref/rsCpuIntrinsicHistogram.cpp
@@ -299,7 +299,7 @@
                                                      const Script *s, const Element *e)
             : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_HISTOGRAM) {
 
-    mRootPtr = NULL;
+    mRootPtr = nullptr;
     mSums = new int[256 * 4 * mCtx->getThreadCount()];
     mDot[0] = 0.299f;
     mDot[1] = 0.587f;
diff --git a/cpu_ref/rsCpuIntrinsicLoopFilter.cpp b/cpu_ref/rsCpuIntrinsicLoopFilter.cpp
index 05ccfd6..d6fb6c1 100644
--- a/cpu_ref/rsCpuIntrinsicLoopFilter.cpp
+++ b/cpu_ref/rsCpuIntrinsicLoopFilter.cpp
@@ -248,7 +248,7 @@
         pthread_cond_signal(&mPrch.start_cond[i]);
     }
     for (i = 0; i < mWorkerCount; ++i) {
-        pthread_join(mPrch.tid[i], NULL);
+        pthread_join(mPrch.tid[i], nullptr);
     }
     free(mPrch.tid);
 }
@@ -1127,7 +1127,7 @@
         pthread_cond_wait(&param->start_cond[wid], &param->mutex[wid]);
         pthread_mutex_unlock(&param->mutex[wid]);
 
-        if (android_atomic_release_load(&param->quit)) return NULL;
+        if (android_atomic_release_load(&param->quit)) return nullptr;
 
         buf_start[0] = param->buffer_alloc + buf_info->y_offset;
         buf_start[1] = param->buffer_alloc + buf_info->u_offset;
@@ -1196,7 +1196,7 @@
         pthread_mutex_unlock(param->hmutex);
     }
 
-    return NULL;
+    return nullptr;
 }
 
 RsdCpuScriptIntrinsicLoopFilter::RsdCpuScriptIntrinsicLoopFilter(
@@ -1221,14 +1221,14 @@
     mPrch.finish = (pthread_cond_t *) (mPrch.hmutex + 1);
     int i = 0;
     int rv = 0;
-    pthread_mutex_init(mPrch.hmutex, NULL);
-    pthread_cond_init(mPrch.finish, NULL);
+    pthread_mutex_init(mPrch.hmutex, nullptr);
+    pthread_cond_init(mPrch.finish, nullptr);
     for (i = 0; i < mWorkerCount; ++i) {
-        pthread_mutex_init(&mPrch.mutex[i], NULL);
-        pthread_cond_init(&mPrch.start_cond[i], NULL);
+        pthread_mutex_init(&mPrch.mutex[i], nullptr);
+        pthread_cond_init(&mPrch.start_cond[i], nullptr);
     }
     for (i = 0; i < mWorkerCount; ++i) {
-        rv = pthread_create(&mPrch.tid[i], NULL, &vp9_loop_filter_rows_work_proc, &mPrch);
+        rv = pthread_create(&mPrch.tid[i], nullptr, &vp9_loop_filter_rows_work_proc, &mPrch);
         rsAssert(rv == 0);
     }
 }
diff --git a/cpu_ref/rsCpuIntrinsicYuvToRGB.cpp b/cpu_ref/rsCpuIntrinsicYuvToRGB.cpp
index 390ca3c..497e19c 100644
--- a/cpu_ref/rsCpuIntrinsicYuvToRGB.cpp
+++ b/cpu_ref/rsCpuIntrinsicYuvToRGB.cpp
@@ -110,7 +110,7 @@
         return;
     }
     const uchar *pinY = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
-    if (pinY == NULL) {
+    if (pinY == nullptr) {
         ALOGE("YuvToRGB executed without data, skipping");
         return;
     }
@@ -143,7 +143,7 @@
     //ALOGE("dimX, %d, dimY, %d", cp->alloc->mHal.drvState.lod[0].dimX, cp->alloc->mHal.drvState.lod[0].dimY);
     //ALOGE("p->dimX, %d, p->dimY, %d", p->dimX, p->dimY);
 
-    if (pinU == NULL) {
+    if (pinU == nullptr) {
         // Legacy yuv support didn't fill in uv
         v = ((uint8_t *)cp->alloc->mHal.drvState.lod[0].mallocPtr) +
             (strideY * p->dimY) +
diff --git a/cpu_ref/rsCpuRuntimeMath.cpp b/cpu_ref/rsCpuRuntimeMath.cpp
index db8cee9..5e66bbd 100644
--- a/cpu_ref/rsCpuRuntimeMath.cpp
+++ b/cpu_ref/rsCpuRuntimeMath.cpp
@@ -312,7 +312,7 @@
     { "_Z6rsRandff", (void *)&SC_randf2, true },
     { "_Z6rsFracf", (void *)&SC_frac, true },
 
-    { NULL, NULL, false }
+    { nullptr, nullptr, false }
 };
 
 const RsdCpuReference::CpuSymbol * RsdCpuScriptImpl::lookupSymbolMath(const char *sym) {
@@ -324,6 +324,6 @@
         }
         syms++;
     }
-    return NULL;
+    return nullptr;
 }
 
diff --git a/cpu_ref/rsCpuRuntimeStubs.cpp b/cpu_ref/rsCpuRuntimeStubs.cpp
index 6210f33..6dc3688 100644
--- a/cpu_ref/rsCpuRuntimeStubs.cpp
+++ b/cpu_ref/rsCpuRuntimeStubs.cpp
@@ -301,14 +301,14 @@
     { "_Z7rsDebugPKcPKDv4_y", (void *)&SC_debugUL4, true },
     { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
 
-    { NULL, NULL, false }
+    { nullptr, nullptr, false }
 };
 
 
 void * RsdCpuScriptImpl::lookupRuntimeStub(void* pContext, char const* name) {
     RsdCpuScriptImpl *s = (RsdCpuScriptImpl *)pContext;
     const RsdCpuReference::CpuSymbol *syms = gSyms;
-    const RsdCpuReference::CpuSymbol *sym = NULL;
+    const RsdCpuReference::CpuSymbol *sym = nullptr;
 
     sym = s->mCtx->symLookup(name);
     if (!sym) {
@@ -328,7 +328,7 @@
         return sym->fnPtr;
     }
     ALOGE("ScriptC sym lookup failed for %s", name);
-    return NULL;
+    return nullptr;
 }
 
 
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index e0b4004..a89e38d 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -92,11 +92,11 @@
     // independent).
     static std::set<std::string> LoadedLibraries;
 
-    void *loaded = NULL;
+    void *loaded = nullptr;
 
     // Skip everything if we don't even have the original library available.
     if (access(origName, F_OK) != 0) {
-        return NULL;
+        return nullptr;
     }
 
     // Common path is that we have not loaded this Script/library before.
@@ -113,7 +113,7 @@
 
     if (!ensureCacheDirExists(newName.c_str())) {
         ALOGE("Could not verify or create cache dir: %s", cacheDir);
-        return NULL;
+        return nullptr;
     }
 
     // Construct an appropriately randomized filename for the symlink.
@@ -126,7 +126,7 @@
     int r = symlink(origName, newName.c_str());
     if (r != 0) {
         ALOGE("Could not create symlink %s -> %s", newName.c_str(), origName);
-        return NULL;
+        return nullptr;
     }
     loaded = dlopen(newName.c_str(), RTLD_NOW | RTLD_LOCAL);
     r = unlink(newName.c_str());
@@ -146,7 +146,7 @@
 // This is required behavior to implement script instancing for the support
 // library, since shared objects are loaded and de-duped by name only.
 static void *loadSharedLibrary(const char *cacheDir, const char *resName) {
-    void *loaded = NULL;
+    void *loaded = nullptr;
     //arc4random_stir();
 #ifndef RS_SERVER
     std::string scriptSOName(cacheDir);
@@ -167,7 +167,7 @@
     // location for shared libraries first.
     loaded = loadSOHelper(scriptSOName.c_str(), cacheDir, resName);
 
-    if (loaded == NULL) {
+    if (loaded == nullptr) {
         ALOGE("Unable to open shared library (%s): %s",
               scriptSOName.c_str(), dlerror());
 
@@ -181,7 +181,7 @@
         scriptSONameSystem.append(".so");
         loaded = loadSOHelper(scriptSONameSystem.c_str(), cacheDir,
                               resName);
-        if (loaded == NULL) {
+        if (loaded == nullptr) {
             ALOGE("Unable to open system shared library (%s): %s",
                   scriptSONameSystem.c_str(), dlerror());
         }
@@ -245,7 +245,7 @@
     }
 
     args->push_back(bcFileName.c_str());
-    args->push_back(NULL);
+    args->push_back(nullptr);
 }
 
 static bool compileBitcode(const std::string &bcFileName,
@@ -318,10 +318,10 @@
 #define OBJECT_SLOT_STR "objectSlotCount: "
 
 // Copy up to a newline or size chars from str -> s, updating str
-// Returns s when successful and NULL when '\0' is finally reached.
+// Returns s when successful and nullptr when '\0' is finally reached.
 static char* strgets(char *s, int size, const char **ppstr) {
     if (!ppstr || !*ppstr || **ppstr == '\0' || size < 1) {
-        return NULL;
+        return nullptr;
     }
 
     int i;
@@ -348,27 +348,27 @@
     mScript = s;
 
 #ifdef RS_COMPATIBILITY_LIB
-    mScriptSO = NULL;
-    mInvokeFunctions = NULL;
-    mForEachFunctions = NULL;
-    mFieldAddress = NULL;
-    mFieldIsObject = NULL;
-    mForEachSignatures = NULL;
+    mScriptSO = nullptr;
+    mInvokeFunctions = nullptr;
+    mForEachFunctions = nullptr;
+    mFieldAddress = nullptr;
+    mFieldIsObject = nullptr;
+    mForEachSignatures = nullptr;
 #else
-    mCompilerContext = NULL;
-    mCompilerDriver = NULL;
-    mExecutable = NULL;
+    mCompilerContext = nullptr;
+    mCompilerDriver = nullptr;
+    mExecutable = nullptr;
 #endif
 
 
-    mRoot = NULL;
-    mRootExpand = NULL;
-    mInit = NULL;
-    mFreeChildren = NULL;
+    mRoot = nullptr;
+    mRootExpand = nullptr;
+    mInit = nullptr;
+    mFreeChildren = nullptr;
 
 
-    mBoundAllocs = NULL;
-    mIntrinsicData = NULL;
+    mBoundAllocs = nullptr;
+    mIntrinsicData = nullptr;
     mIsThreadable = true;
 }
 
@@ -383,19 +383,19 @@
 #ifndef RS_COMPATIBILITY_LIB
     bool useRSDebugContext = false;
 
-    mCompilerContext = NULL;
-    mCompilerDriver = NULL;
-    mExecutable = NULL;
+    mCompilerContext = nullptr;
+    mCompilerDriver = nullptr;
+    mExecutable = nullptr;
 
     mCompilerContext = new bcc::BCCContext();
-    if (mCompilerContext == NULL) {
+    if (mCompilerContext == nullptr) {
         ALOGE("bcc: FAILS to create compiler context (out of memory)");
         mCtx->unlockMutex();
         return false;
     }
 
     mCompilerDriver = new bcc::RSCompilerDriver();
-    if (mCompilerDriver == NULL) {
+    if (mCompilerDriver == nullptr) {
         ALOGE("bcc: FAILS to create compiler driver (out of memory)");
         mCtx->unlockMutex();
         return false;
@@ -410,7 +410,7 @@
     // Run any compiler setup functions we have been provided with.
     RSSetupCompilerCallback setupCompilerCallback =
             mCtx->getSetupCompilerCallback();
-    if (setupCompilerCallback != NULL) {
+    if (setupCompilerCallback != nullptr) {
         setupCompilerCallback(mCompilerDriver);
     }
 
@@ -436,7 +436,7 @@
     std::vector<const char*> compileArguments;
     setCompileArguments(&compileArguments, bcFileName, cacheDir, resName, core_lib,
                         useRSDebugContext, bccPluginName);
-    // The last argument of compileArguments ia a NULL, so remove 1 from the size.
+    // The last argument of compileArguments ia a nullptr, so remove 1 from the size.
     std::string compileCommandLine =
                 bcc::getCommandLine(compileArguments.size() - 1, compileArguments.data());
 
@@ -449,7 +449,7 @@
 
     // If we can't, it's either not there or out of date.  We compile the bit code and try loading
     // again.
-    if (mExecutable == NULL) {
+    if (mExecutable == nullptr) {
         if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize, compileArguments.data(),
                             compileCommandLine)) {
             ALOGE("bcc: FAILS to compile '%s'", resName);
@@ -459,7 +459,7 @@
         mExecutable = bcc::RSCompilerDriver::loadScript(cacheDir, resName, (const char*)bitcode,
                                                         bitcodeSize, compileCommandLine.c_str(),
                                                         mResolver);
-        if (mExecutable == NULL) {
+        if (mExecutable == nullptr) {
             ALOGE("bcc: FAILS to load freshly compiled executable for '%s'", resName);
             mCtx->unlockMutex();
             return false;
@@ -519,7 +519,7 @@
         }
 
         size_t varCount = 0;
-        if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+        if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
             goto error;
         }
         if (sscanf(line, EXPORT_VAR_STR "%zu", &varCount) != 1) {
@@ -533,16 +533,16 @@
             // Start by creating/zeroing this member, since we don't want to
             // accidentally clean up invalid pointers later (if we error out).
             mFieldIsObject = new bool[varCount];
-            if (mFieldIsObject == NULL) {
+            if (mFieldIsObject == nullptr) {
                 goto error;
             }
             memset(mFieldIsObject, 0, varCount * sizeof(*mFieldIsObject));
             mFieldAddress = new void*[varCount];
-            if (mFieldAddress == NULL) {
+            if (mFieldAddress == nullptr) {
                 goto error;
             }
             for (size_t i = 0; i < varCount; ++i) {
-                if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+                if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
                     goto error;
                 }
                 char *c = strrchr(line, '\n');
@@ -550,7 +550,7 @@
                     *c = '\0';
                 }
                 mFieldAddress[i] = dlsym(mScriptSO, line);
-                if (mFieldAddress[i] == NULL) {
+                if (mFieldAddress[i] == nullptr) {
                     ALOGE("Failed to find variable address for %s: %s",
                           line, dlerror());
                     // Not a critical error if we don't find a global variable.
@@ -563,7 +563,7 @@
         }
 
         size_t funcCount = 0;
-        if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+        if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
             goto error;
         }
         if (sscanf(line, EXPORT_FUNC_STR "%zu", &funcCount) != 1) {
@@ -576,11 +576,11 @@
 
         if (funcCount > 0) {
             mInvokeFunctions = new InvokeFunc_t[funcCount];
-            if (mInvokeFunctions == NULL) {
+            if (mInvokeFunctions == nullptr) {
                 goto error;
             }
             for (size_t i = 0; i < funcCount; ++i) {
-                if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+                if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
                     goto error;
                 }
                 char *c = strrchr(line, '\n');
@@ -589,7 +589,7 @@
                 }
 
                 mInvokeFunctions[i] = (InvokeFunc_t) dlsym(mScriptSO, line);
-                if (mInvokeFunctions[i] == NULL) {
+                if (mInvokeFunctions[i] == nullptr) {
                     ALOGE("Failed to get function address for %s(): %s",
                           line, dlerror());
                     goto error;
@@ -601,7 +601,7 @@
         }
 
         size_t forEachCount = 0;
-        if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+        if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
             goto error;
         }
         if (sscanf(line, EXPORT_FOREACH_STR "%zu", &forEachCount) != 1) {
@@ -612,18 +612,18 @@
         if (forEachCount > 0) {
 
             mForEachSignatures = new uint32_t[forEachCount];
-            if (mForEachSignatures == NULL) {
+            if (mForEachSignatures == nullptr) {
                 goto error;
             }
             mForEachFunctions = new ForEachFunc_t[forEachCount];
-            if (mForEachFunctions == NULL) {
+            if (mForEachFunctions == nullptr) {
                 goto error;
             }
             for (size_t i = 0; i < forEachCount; ++i) {
                 unsigned int tmpSig = 0;
                 char tmpName[MAXLINE];
 
-                if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+                if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
                     goto error;
                 }
                 if (sscanf(line, "%u - %" MAKE_STR(MAXLINE) "s",
@@ -637,7 +637,7 @@
                 mForEachSignatures[i] = tmpSig;
                 mForEachFunctions[i] =
                         (ForEachFunc_t) dlsym(mScriptSO, tmpName);
-                if (i != 0 && mForEachFunctions[i] == NULL) {
+                if (i != 0 && mForEachFunctions[i] == nullptr) {
                     // Ignore missing root.expand functions.
                     // root() is always specified at location 0.
                     ALOGE("Failed to find forEach function address for %s: %s",
@@ -651,7 +651,7 @@
         }
 
         size_t objectSlotCount = 0;
-        if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+        if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
             goto error;
         }
         if (sscanf(line, OBJECT_SLOT_STR "%zu", &objectSlotCount) != 1) {
@@ -663,7 +663,7 @@
             rsAssert(varCount > 0);
             for (size_t i = 0; i < objectSlotCount; ++i) {
                 uint32_t varNum = 0;
-                if (strgets(line, MAXLINE, &rsInfo) == NULL) {
+                if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
                     goto error;
                 }
                 if (sscanf(line, "%u", &varNum) != 1) {
@@ -728,7 +728,7 @@
 
     // If a callback has been registered to specify a library, use that.
     RSSelectRTCallback selectRTCallback = mCtx->getSelectRTCallback();
-    if (selectRTCallback != NULL) {
+    if (selectRTCallback != nullptr) {
         return selectRTCallback((const char*)bitcode, bitcodeSize);
     }
 
@@ -804,14 +804,18 @@
         const Allocation* ain = ains[index];
 
         // possible for this to occur if IO_OUTPUT/IO_INPUT with no bound surface
-        if (ain != NULL && (const uint8_t *)ain->mHal.drvState.lod[0].mallocPtr == NULL) {
+        if (ain != nullptr &&
+            (const uint8_t *)ain->mHal.drvState.lod[0].mallocPtr == nullptr) {
+
             mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
                                          "rsForEach called with null in allocations");
             return;
         }
     }
 
-    if (aout && (const uint8_t *)aout->mHal.drvState.lod[0].mallocPtr == NULL) {
+    if (aout &&
+        (const uint8_t *)aout->mHal.drvState.lod[0].mallocPtr == nullptr) {
+
         mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
                                      "rsForEach called with null out allocations");
         return;
@@ -834,7 +838,7 @@
             }
         }
 
-    } else if (aout != NULL) {
+    } else if (aout != nullptr) {
         const Type *outType = aout->getType();
 
         mtls->fep.dimX = outType->getDimX();
@@ -847,7 +851,7 @@
         return;
     }
 
-    if (inLen > 0 && aout != NULL) {
+    if (inLen > 0 && aout != nullptr) {
         if (!ains[0]->hasSameDims(aout)) {
             mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
               "Failed to launch kernel; dimensions of input and output allocations do not match.");
@@ -904,8 +908,8 @@
     mtls->mSliceSize = 1;
     mtls->mSliceNum  = 0;
 
-    mtls->fep.inPtrs    = NULL;
-    mtls->fep.inStrides = NULL;
+    mtls->fep.inPtrs    = nullptr;
+    mtls->fep.inStrides = nullptr;
     mtls->isThreadable  = mIsThreadable;
 
     if (inLen > 0) {
@@ -935,10 +939,10 @@
         }
     }
 
-    mtls->fep.outPtr            = NULL;
+    mtls->fep.outPtr            = nullptr;
     mtls->fep.outStride.eStride = 0;
     mtls->fep.outStride.yStride = 0;
-    if (aout != NULL) {
+    if (aout != nullptr) {
         mtls->fep.outPtr = (uint8_t *)aout->mHal.drvState.lod[0].mallocPtr;
 
         mtls->fep.outStride.eStride = aout->getType()->getElementSizeBytes();
@@ -972,11 +976,11 @@
     rsAssert(slot < mExecutable->getExportForeachFuncAddrs().size());
     mtls->kernel = reinterpret_cast<ForEachFunc_t>(
                       mExecutable->getExportForeachFuncAddrs()[slot]);
-    rsAssert(mtls->kernel != NULL);
+    rsAssert(mtls->kernel != nullptr);
     mtls->sig = mExecutable->getInfo().getExportForeachFuncs()[slot].second;
 #else
     mtls->kernel = reinterpret_cast<ForEachFunc_t>(mForEachFunctions[slot]);
-    rsAssert(mtls->kernel != NULL);
+    rsAssert(mtls->kernel != nullptr);
     mtls->sig = mForEachSignatures[slot];
 #endif
 }
@@ -1112,7 +1116,7 @@
         return;
     }
 
-    void *ptr = NULL;
+    void *ptr = nullptr;
     mBoundAllocs[slot] = data;
     if(data) {
         ptr = data->mHal.drvState.lod[0].mallocPtr;
@@ -1155,12 +1159,12 @@
 
         while ((var_addr_iter != var_addr_end) &&
                (is_object_iter != is_object_end)) {
-            // The field address can be NULL if the script-side has optimized
+            // The field address can be nullptr if the script-side has optimized
             // the corresponding global variable away.
             rs_object_base *obj_addr =
                 reinterpret_cast<rs_object_base *>(*var_addr_iter);
             if (*is_object_iter) {
-                if (*var_addr_iter != NULL && mCtx->getContext() != NULL) {
+                if (*var_addr_iter != nullptr && mCtx->getContext() != nullptr) {
                     rsrClearObject(mCtx->getContext(), obj_addr);
                 }
             }
@@ -1189,7 +1193,7 @@
     if (mFieldIsObject) {
         for (size_t i = 0; i < mExportedVariableCount; ++i) {
             if (mFieldIsObject[i]) {
-                if (mFieldAddress[i] != NULL) {
+                if (mFieldAddress[i] != nullptr) {
                     rs_object_base *obj_addr =
                         reinterpret_cast<rs_object_base *>(mFieldAddress[i]);
                     rsrClearObject(mCtx->getContext(), obj_addr);
@@ -1212,7 +1216,7 @@
 
 Allocation * RsdCpuScriptImpl::getAllocationForPointer(const void *ptr) const {
     if (!ptr) {
-        return NULL;
+        return nullptr;
     }
 
     for (uint32_t ct=0; ct < mScript->mHal.info.exportedVariableCount; ct++) {
@@ -1223,7 +1227,7 @@
         }
     }
     ALOGE("rsGetAllocation, failed to find %p", ptr);
-    return NULL;
+    return nullptr;
 }
 
 void RsdCpuScriptImpl::preLaunch(uint32_t slot, const Allocation ** ains,
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index c5fc183..78111ea 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -59,7 +59,7 @@
 
     bool init(char const *resName, char const *cacheDir,
               uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
-              char const *bccPluginName = NULL);
+              char const *bccPluginName = nullptr);
     virtual void populateScript(Script *);
 
     virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index 1d26f59..751bafb 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -87,7 +87,7 @@
             }
 
         } else {
-            localIns[0]    = NULL;
+            localIns[0]    = nullptr;
             localStride[0] = 0;
         }
 
@@ -109,7 +109,7 @@
                   sl->outs[ct]->mHal.drvState.lod[0].stride * kparams->lid;
             }
         } else {
-            mkparams->out = NULL;
+            mkparams->out = nullptr;
             ostep         = 0;
         }
 
@@ -153,8 +153,8 @@
 
         for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) {
             const ScriptKernelID *k = n->mKernels[ct2];
-            Allocation *ain = NULL;
-            Allocation *aout = NULL;
+            Allocation *ain = nullptr;
+            Allocation *aout = nullptr;
             bool inExt = false;
             bool outExt = false;
 
@@ -164,7 +164,7 @@
                     break;
                 }
             }
-            if (ain == NULL) {
+            if (ain == nullptr) {
                 for (size_t ct3=0; ct3 < mSG->mInputs.size(); ct3++) {
                     if (mSG->mInputs[ct3]->mKernel == k) {
                         ain = mSG->mInputs[ct3]->mAlloc.get();
@@ -177,13 +177,13 @@
             for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) {
                 if (n->mOutputs[ct3]->mSource.get() == k) {
                     aout = n->mOutputs[ct3]->mAlloc.get();
-                    if(n->mOutputs[ct3]->mDstField.get() != NULL) {
+                    if(n->mOutputs[ct3]->mDstField.get() != nullptr) {
                         fieldDep = true;
                     }
                     break;
                 }
             }
-            if (aout == NULL) {
+            if (aout == nullptr) {
                 for (size_t ct3=0; ct3 < mSG->mOutputs.size(); ct3++) {
                     if (mSG->mOutputs[ct3]->mKernel == k) {
                         aout = mSG->mOutputs[ct3]->mAlloc.get();
@@ -193,8 +193,8 @@
                 }
             }
 
-            rsAssert((k->mHasKernelOutput == (aout != NULL)) &&
-                     (k->mHasKernelInput == (ain != NULL)));
+            rsAssert((k->mHasKernelOutput == (aout != nullptr)) &&
+                     (k->mHasKernelInput == (ain != nullptr)));
 
             ins.push_back(ain);
             inExts.push_back(inExt);
@@ -216,24 +216,24 @@
             uint32_t inLen;
             const Allocation **ains;
 
-            if (ins[ct] == NULL) {
+            if (ins[ct] == nullptr) {
                 inLen = 0;
-                ains  = NULL;
+                ains  = nullptr;
 
             } else {
                 inLen = 1;
                 ains  = const_cast<const Allocation**>(&ins[ct]);
             }
 
-            si->forEachMtlsSetup(ains, inLen, outs[ct], NULL, 0, NULL, &mtls);
+            si->forEachMtlsSetup(ains, inLen, outs[ct], nullptr, 0, nullptr, &mtls);
 
             si->forEachKernelSetup(slot, &mtls);
             si->preLaunch(slot, ains, inLen, outs[ct], mtls.fep.usr,
-                          mtls.fep.usrLen, NULL);
+                          mtls.fep.usrLen, nullptr);
 
-            mCtx->launchThreads(ains, inLen, outs[ct], NULL, &mtls);
+            mCtx->launchThreads(ains, inLen, outs[ct], nullptr, &mtls);
 
-            si->postLaunch(slot, ains, inLen, outs[ct], NULL, 0, NULL);
+            si->postLaunch(slot, ains, inLen, outs[ct], nullptr, 0, nullptr);
         }
     } else {
         ScriptList sl;
@@ -251,9 +251,9 @@
         uint32_t inLen;
         const Allocation **ains;
 
-        if (ins[0] == NULL) {
+        if (ins[0] == nullptr) {
             inLen = 0;
-            ains  = NULL;
+            ains  = nullptr;
 
         } else {
             inLen = 1;
@@ -272,7 +272,7 @@
             usrPtrs.push_back(mtls.fep.usr);
             sigs.push_back(mtls.fep.usrLen);
             si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct],
-                          mtls.fep.usr, mtls.fep.usrLen, NULL);
+                          mtls.fep.usr, mtls.fep.usrLen, nullptr);
         }
 
         sl.sigs    = &sigs.front();
@@ -285,19 +285,19 @@
         Script *s = kernels[0]->mScript;
         RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
 
-        si->forEachMtlsSetup(ains, inLen, outs[0], NULL, 0, NULL, &mtls);
+        si->forEachMtlsSetup(ains, inLen, outs[0], nullptr, 0, nullptr, &mtls);
 
-        mtls.script = NULL;
+        mtls.script = nullptr;
         mtls.kernel = (void (*)())&scriptGroupRoot;
         mtls.fep.usr = &sl;
 
-        mCtx->launchThreads(ains, inLen, outs[0], NULL, &mtls);
+        mCtx->launchThreads(ains, inLen, outs[0], nullptr, &mtls);
 
         for (size_t ct=0; ct < kernels.size(); ct++) {
             Script *s = kernels[ct]->mScript;
             RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
-            si->postLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct], NULL, 0,
-                           NULL);
+            si->postLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct], nullptr, 0,
+                           nullptr);
         }
     }
 }
diff --git a/cpu_ref/rsd_cpu.h b/cpu_ref/rsd_cpu.h
index 4728b7c..b0e924e 100644
--- a/cpu_ref/rsd_cpu.h
+++ b/cpu_ref/rsd_cpu.h
@@ -112,9 +112,9 @@
     static RsdCpuReference * create(Context *c, uint32_t version_major,
                                     uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
 #ifndef RS_COMPATIBILITY_LIB
-                                    , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = NULL,
-                                    RSSelectRTCallback pSelectRTCallback = NULL,
-                                    const char *pBccPluginName = NULL
+                                    , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr,
+                                    RSSelectRTCallback pSelectRTCallback = nullptr,
+                                    const char *pBccPluginName = nullptr
 #endif
                                     );
     virtual ~RsdCpuReference();
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index bbe0d7a..e34d0c3 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -193,7 +193,7 @@
     if (!(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
         if (alloc->mHal.drvState.lod[0].mallocPtr) {
             free(alloc->mHal.drvState.lod[0].mallocPtr);
-            alloc->mHal.drvState.lod[0].mallocPtr = NULL;
+            alloc->mHal.drvState.lod[0].mallocPtr = nullptr;
         }
     }
     rsdGLCheckError(rsc, "UploadToTexture");
@@ -360,7 +360,7 @@
     // We align all allocations to a 16-byte boundary.
     uint8_t* ptr = (uint8_t *)memalign(16, allocSize);
     if (!ptr) {
-        return NULL;
+        return nullptr;
     }
     if (forceZero) {
         memset(ptr, 0, allocSize);
@@ -376,15 +376,15 @@
     alloc->mHal.drv = drv;
 
     // Calculate the object size.
-    size_t allocSize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), NULL);
+    size_t allocSize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), nullptr);
 
-    uint8_t * ptr = NULL;
+    uint8_t * ptr = nullptr;
     if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) {
 
     } else if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
         // Allocation is allocated when the surface is created
         // in getSurface
-    } else if (alloc->mHal.state.userProvidedPtr != NULL) {
+    } else if (alloc->mHal.state.userProvidedPtr != nullptr) {
         // user-provided allocation
         // limitations: no faces, no LOD, USAGE_SCRIPT or SCRIPT+TEXTURE only
         if (!(alloc->mHal.state.usageFlags == (RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED) ||
@@ -405,7 +405,7 @@
 
             ptr = allocAlignedMemory(allocSize, forceZero);
             if (!ptr) {
-                alloc->mHal.drv = NULL;
+                alloc->mHal.drv = nullptr;
                 free(drv);
                 return false;
             }
@@ -417,7 +417,7 @@
     } else {
         ptr = allocAlignedMemory(allocSize, forceZero);
         if (!ptr) {
-            alloc->mHal.drv = NULL;
+            alloc->mHal.drv = nullptr;
             free(drv);
             return false;
         }
@@ -456,7 +456,7 @@
     }
 
 
-    drv->readBackFBO = NULL;
+    drv->readBackFBO = nullptr;
 
     // fill out the initial state of the buffer if we couldn't use the user-provided ptr and USAGE_SHARED was accepted
     if ((alloc->mHal.state.userProvidedPtr != 0) && (drv->useUserProvidedPtr == false)) {
@@ -500,13 +500,13 @@
             !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT)) {
                 free(alloc->mHal.drvState.lod[0].mallocPtr);
         }
-        alloc->mHal.drvState.lod[0].mallocPtr = NULL;
+        alloc->mHal.drvState.lod[0].mallocPtr = nullptr;
     }
 
 #ifndef RS_COMPATIBILITY_LIB
-    if (drv->readBackFBO != NULL) {
+    if (drv->readBackFBO != nullptr) {
         delete drv->readBackFBO;
-        drv->readBackFBO = NULL;
+        drv->readBackFBO = nullptr;
     }
 
     if ((alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) &&
@@ -519,15 +519,15 @@
             mapper.unlock(drv->wndBuffer->handle);
             int32_t r = nw->queueBuffer(nw, drv->wndBuffer, -1);
 
-            drv->wndSurface = NULL;
+            drv->wndSurface = nullptr;
             native_window_api_disconnect(nw, NATIVE_WINDOW_API_CPU);
-            nw->decStrong(NULL);
+            nw->decStrong(nullptr);
         }
     }
 #endif
 
     free(drv);
-    alloc->mHal.drv = NULL;
+    alloc->mHal.drv = nullptr;
 }
 
 void rsdAllocationResize(const Context *rsc, const Allocation *alloc,
@@ -542,7 +542,7 @@
     }
     void * oldPtr = alloc->mHal.drvState.lod[0].mallocPtr;
     // Calculate the object size
-    size_t s = AllocationBuildPointerTable(rsc, alloc, newType, NULL);
+    size_t s = AllocationBuildPointerTable(rsc, alloc, newType, nullptr);
     uint8_t *ptr = (uint8_t *)realloc(oldPtr, s);
     // Build the relative pointer tables.
     size_t verifySize = AllocationBuildPointerTable(rsc, alloc, newType, ptr);
@@ -571,7 +571,7 @@
     if (!drv->textureID && !drv->renderTargetID) {
         return; // nothing was rendered here yet, so nothing to sync
     }
-    if (drv->readBackFBO == NULL) {
+    if (drv->readBackFBO == nullptr) {
         drv->readBackFBO = new RsdFrameBufferObj();
         drv->readBackFBO->setColorTarget(drv, 0);
         drv->readBackFBO->setDimensions(alloc->getType()->getDimX(),
@@ -656,7 +656,7 @@
     GraphicBufferMapper &mapper = GraphicBufferMapper::get();
     Rect bounds(drv->wndBuffer->width, drv->wndBuffer->height);
 
-    void *dst = NULL;
+    void *dst = nullptr;
     mapper.lock(drv->wndBuffer->handle,
             GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN,
             bounds, &dst);
@@ -674,7 +674,7 @@
     ANativeWindow *old = drv->wndSurface;
 
     if (nw) {
-        nw->incStrong(NULL);
+        nw->incStrong(nullptr);
     }
 
     if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
@@ -689,13 +689,13 @@
         GraphicBufferMapper &mapper = GraphicBufferMapper::get();
         mapper.unlock(drv->wndBuffer->handle);
         old->cancelBuffer(old, drv->wndBuffer, -1);
-        drv->wndSurface = NULL;
+        drv->wndSurface = nullptr;
 
         native_window_api_disconnect(old, NATIVE_WINDOW_API_CPU);
-        old->decStrong(NULL);
+        old->decStrong(nullptr);
     }
 
-    if (nw != NULL) {
+    if (nw != nullptr) {
         int32_t r;
         uint32_t flags = 0;
 
@@ -747,7 +747,7 @@
  error:
 
     if (nw) {
-        nw->decStrong(NULL);
+        nw->decStrong(nullptr);
     }
 
 
@@ -1202,14 +1202,14 @@
 {
     obj->p = alloc;
 #ifdef __LP64__
-    if (alloc != NULL) {
+    if (alloc != nullptr) {
         obj->r = alloc->mHal.drvState.lod[0].mallocPtr;
         obj->v1 = alloc->mHal.drv;
         obj->v2 = (void *)alloc->mHal.drvState.lod[0].stride;
     } else {
-        obj->r = NULL;
-        obj->v1 = NULL;
-        obj->v2 = NULL;
+        obj->r = nullptr;
+        obj->v1 = nullptr;
+        obj->v2 = nullptr;
     }
 #endif
 }
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp
index 419422a..811fa3e 100644
--- a/driver/rsdBcc.cpp
+++ b/driver/rsdBcc.cpp
@@ -47,7 +47,7 @@
     RsdCpuReference::CpuScript * cs =
         dc->mCpuRef->createScript(script, resName, cacheDir, bitcode,
                                   bitcodeSize, flags);
-    if (cs == NULL) {
+    if (cs == nullptr) {
         return false;
     }
     script->mHal.drv = cs;
@@ -59,7 +59,7 @@
                       Element *e) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
     RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
-    if (cs == NULL) {
+    if (cs == nullptr) {
         return false;
     }
     s->mHal.drv = cs;
@@ -76,8 +76,8 @@
                             size_t usrLen,
                             const RsScriptCall *sc) {
 
-    if (ain == NULL) {
-        rsdScriptInvokeForEachMulti(rsc, s, slot, NULL, 0, aout, usr, usrLen,
+    if (ain == nullptr) {
+        rsdScriptInvokeForEachMulti(rsc, s, slot, nullptr, 0, aout, usr, usrLen,
                                     sc);
     } else {
         const Allocation *ains[1] = {ain};
@@ -159,7 +159,7 @@
 void rsdScriptDestroy(const Context *dc, Script *s) {
     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
     delete cs;
-    s->mHal.drv = NULL;
+    s->mHal.drv = nullptr;
 }
 
 
@@ -176,12 +176,12 @@
 {
     obj->p = script;
 #ifdef __LP64__
-    obj->r = NULL;
-    if (script != NULL) {
+    obj->r = nullptr;
+    if (script != nullptr) {
         obj->v1 = script->mHal.drv;
     } else {
-        obj->v1 = NULL;
+        obj->v1 = nullptr;
     }
-    obj->v2 = NULL;
+    obj->v2 = nullptr;
 #endif
 }
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 37c9755..48959fd 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -53,7 +53,7 @@
 #ifndef RS_COMPATIBILITY_LIB
     #define NATIVE_FUNC(a) a
 #else
-    #define NATIVE_FUNC(a) NULL
+    #define NATIVE_FUNC(a) nullptr
 #endif
 
 
@@ -64,7 +64,7 @@
     NATIVE_FUNC(rsdGLSwap),
 
     Shutdown,
-    NULL,
+    nullptr,
     SetPriority,
     rsdAllocRuntimeMem,
     rsdFreeRuntimeMem,
@@ -169,7 +169,7 @@
         rsdScriptGroupSetOutput,
         rsdScriptGroupExecute,
         rsdScriptGroupDestroy,
-        NULL
+        nullptr
     },
 
     {
@@ -184,7 +184,7 @@
         rsdElementUpdateCachedObject
     },
 
-    NULL // finish
+    nullptr // finish
 };
 
 extern const RsdCpuReference::CpuSymbol * rsdLookupRuntimeStub(Context * pContext, char const* name);
@@ -209,7 +209,7 @@
                                           &rsdLookupRuntimeStub, &LookupScript);
     if (!dc->mCpuRef) {
         ALOGE("RsdCpuReference::create for driver hal failed.");
-        rsc->mHal.drv = NULL;
+        rsc->mHal.drv = nullptr;
         free(dc);
         return false;
     }
@@ -217,7 +217,7 @@
 #ifndef RS_COMPATIBILITY_LIB
     // Set a callback for compiler setup here.
     if (false) {
-        dc->mCpuRef->setSetupCompilerCallback(NULL);
+        dc->mCpuRef->setSetupCompilerCallback(nullptr);
     }
 
     // Set a callback for switching MemChunk's allocator here.
@@ -251,7 +251,7 @@
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
     delete dc->mCpuRef;
     free(dc);
-    rsc->mHal.drv = NULL;
+    rsc->mHal.drv = nullptr;
 }
 
 void* rsdAllocRuntimeMem(size_t size, uint32_t flags) {
diff --git a/driver/rsdElement.cpp b/driver/rsdElement.cpp
index c0413e4..06a0790 100644
--- a/driver/rsdElement.cpp
+++ b/driver/rsdElement.cpp
@@ -35,9 +35,9 @@
 {
     obj->p = element;
 #ifdef __LP64__
-    obj->r = NULL;
-    obj->v1 = NULL;
-    obj->v2 = NULL;
+    obj->r = nullptr;
+    obj->v1 = nullptr;
+    obj->v2 = nullptr;
 #endif
 }
 
diff --git a/driver/rsdFrameBuffer.cpp b/driver/rsdFrameBuffer.cpp
index bb07d29..f458bf9 100644
--- a/driver/rsdFrameBuffer.cpp
+++ b/driver/rsdFrameBuffer.cpp
@@ -32,8 +32,8 @@
 void setDepthAttachment(const Context *rsc, const FBOCache *fb) {
     RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
 
-    DrvAllocation *depth = NULL;
-    if (fb->mHal.state.depthTarget != NULL) {
+    DrvAllocation *depth = nullptr;
+    if (fb->mHal.state.depthTarget != nullptr) {
         depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
 
         if (depth->uploadDeferred) {
@@ -48,8 +48,8 @@
     RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
     // Now attach color targets
     for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
-        DrvAllocation *color = NULL;
-        if (fb->mHal.state.colorTargets[i] != NULL) {
+        DrvAllocation *color = nullptr;
+        if (fb->mHal.state.colorTargets[i] != nullptr) {
             color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
 
             if (color->uploadDeferred) {
@@ -63,7 +63,7 @@
 
 bool rsdFrameBufferInit(const Context *rsc, const FBOCache *fb) {
     RsdFrameBufferObj *fbo = new RsdFrameBufferObj();
-    if (fbo == NULL) {
+    if (fbo == nullptr) {
         return false;
     }
     fb->mHal.drv = fbo;
@@ -93,7 +93,7 @@
 void rsdFrameBufferDestroy(const Context *rsc, const FBOCache *fb) {
     RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
     delete fbo;
-    fb->mHal.drv = NULL;
+    fb->mHal.drv = nullptr;
 }
 
 
diff --git a/driver/rsdFrameBufferObj.cpp b/driver/rsdFrameBufferObj.cpp
index 7731aff..1e91c98 100644
--- a/driver/rsdFrameBufferObj.cpp
+++ b/driver/rsdFrameBufferObj.cpp
@@ -35,7 +35,7 @@
     for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
         mColorTargets[i] = 0;
     }
-    mDepthTarget = NULL;
+    mDepthTarget = nullptr;
     mDirty = true;
 }
 
@@ -73,7 +73,7 @@
 
 
 void RsdFrameBufferObj::setDepthAttachment() {
-    if (mDepthTarget != NULL) {
+    if (mDepthTarget != nullptr) {
         if (mDepthTarget->textureID) {
             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                                    GL_TEXTURE_2D, mDepthTarget->textureID, 0);
@@ -91,7 +91,7 @@
 void RsdFrameBufferObj::setColorAttachment() {
     // Now attach color targets
     for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
-        if (mColorTargets[i] != NULL) {
+        if (mColorTargets[i] != nullptr) {
             if (mColorTargets[i]->textureID) {
                 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
                                        GL_TEXTURE_2D, mColorTargets[i]->textureID, 0);
@@ -110,12 +110,12 @@
 }
 
 bool RsdFrameBufferObj::renderToFramebuffer() {
-    if (mDepthTarget != NULL) {
+    if (mDepthTarget != nullptr) {
         return false;
     }
 
     for (uint32_t i = 0; i < mColorTargetsCount; i ++) {
-        if (mColorTargets[i] != NULL) {
+        if (mColorTargets[i] != nullptr) {
             return false;
         }
     }
diff --git a/driver/rsdGL.cpp b/driver/rsdGL.cpp
index ff0c9a6..e803487 100644
--- a/driver/rsdGL.cpp
+++ b/driver/rsdGL.cpp
@@ -153,7 +153,7 @@
 void rsdGLShutdown(const Context *rsc) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
-    rsdGLSetSurface(rsc, 0, 0, NULL);
+    rsdGLSetSurface(rsc, 0, 0, nullptr);
     dc->gl.shaderCache->cleanupAll();
     delete dc->gl.shaderCache;
     delete dc->gl.vertexArrayState;
@@ -320,7 +320,7 @@
     checkEglError("eglCreateContext");
     if (dc->gl.egl.context == EGL_NO_CONTEXT) {
         ALOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", rsc);
-        rsc->setWatchdogGL(NULL, 0, NULL);
+        rsc->setWatchdogGL(nullptr, 0, nullptr);
         return false;
     }
     gGLContextCount++;
@@ -333,7 +333,7 @@
     if (dc->gl.egl.surfaceDefault == EGL_NO_SURFACE) {
         ALOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
         rsdGLShutdown(rsc);
-        rsc->setWatchdogGL(NULL, 0, NULL);
+        rsc->setWatchdogGL(nullptr, 0, nullptr);
         return false;
     }
 
@@ -344,7 +344,7 @@
         ALOGE("eglMakeCurrent returned EGL_FALSE");
         checkEglError("eglMakeCurrent", ret);
         rsdGLShutdown(rsc);
-        rsc->setWatchdogGL(NULL, 0, NULL);
+        rsc->setWatchdogGL(nullptr, 0, nullptr);
         return false;
     }
 
@@ -359,7 +359,7 @@
     //ALOGV("GL Renderer %s", mGL.mRenderer);
     //ALOGV("GL Extensions %s", mGL.mExtensions);
 
-    const char *verptr = NULL;
+    const char *verptr = nullptr;
     if (strlen((const char *)dc->gl.gl.version) > 9) {
         if (!memcmp(dc->gl.gl.version, "OpenGL ES-CM", 12)) {
             verptr = (const char *)dc->gl.gl.version + 12;
@@ -372,7 +372,7 @@
     if (!verptr) {
         ALOGE("Error, OpenGL ES Lite not supported");
         rsdGLShutdown(rsc);
-        rsc->setWatchdogGL(NULL, 0, NULL);
+        rsc->setWatchdogGL(nullptr, 0, nullptr);
         return false;
     } else {
         sscanf(verptr, " %i.%i", &dc->gl.gl.majorVersion, &dc->gl.gl.minorVersion);
@@ -388,14 +388,14 @@
     glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &dc->gl.gl.maxFragmentTextureImageUnits);
     glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &dc->gl.gl.maxFragmentUniformVectors);
 
-    dc->gl.gl.OES_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions,
+    dc->gl.gl.OES_texture_npot = nullptr != strstr((const char *)dc->gl.gl.extensions,
                                                 "GL_OES_texture_npot");
-    dc->gl.gl.IMG_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions,
+    dc->gl.gl.IMG_texture_npot = nullptr != strstr((const char *)dc->gl.gl.extensions,
                                                    "GL_IMG_texture_npot");
-    dc->gl.gl.NV_texture_npot_2D_mipmap = NULL != strstr((const char *)dc->gl.gl.extensions,
+    dc->gl.gl.NV_texture_npot_2D_mipmap = nullptr != strstr((const char *)dc->gl.gl.extensions,
                                                             "GL_NV_texture_npot_2D_mipmap");
     dc->gl.gl.EXT_texture_max_aniso = 1.0f;
-    bool hasAniso = NULL != strstr((const char *)dc->gl.gl.extensions,
+    bool hasAniso = nullptr != strstr((const char *)dc->gl.gl.extensions,
                                    "GL_EXT_texture_filter_anisotropic");
     if (hasAniso) {
         glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &dc->gl.gl.EXT_texture_max_aniso);
@@ -408,11 +408,11 @@
     dc->gl.shaderCache = new RsdShaderCache();
     dc->gl.vertexArrayState = new RsdVertexArrayState();
     dc->gl.vertexArrayState->init(dc->gl.gl.maxVertexAttribs);
-    dc->gl.currentFrameBuffer = NULL;
+    dc->gl.currentFrameBuffer = nullptr;
     dc->mHasGraphics = true;
 
     ALOGV("%p initGLThread end", rsc);
-    rsc->setWatchdogGL(NULL, 0, NULL);
+    rsc->setWatchdogGL(nullptr, 0, nullptr);
     return true;
 }
 
@@ -421,7 +421,7 @@
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
     EGLBoolean ret;
-    if (dc->gl.egl.surface != NULL) {
+    if (dc->gl.egl.surface != nullptr) {
         rsc->setWatchdogGL("eglMakeCurrent", __LINE__, __FILE__);
         ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
                              dc->gl.egl.surfaceDefault, dc->gl.egl.context);
@@ -431,20 +431,20 @@
         ret = eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
         checkEglError("eglDestroySurface", ret);
 
-        dc->gl.egl.surface = NULL;
+        dc->gl.egl.surface = nullptr;
     }
 
-    if (dc->gl.currentWndSurface != NULL) {
-        dc->gl.currentWndSurface->decStrong(NULL);
+    if (dc->gl.currentWndSurface != nullptr) {
+        dc->gl.currentWndSurface->decStrong(nullptr);
     }
 
     dc->gl.currentWndSurface = (ANativeWindow *)sur;
-    if (dc->gl.currentWndSurface != NULL) {
-        dc->gl.currentWndSurface->incStrong(NULL);
+    if (dc->gl.currentWndSurface != nullptr) {
+        dc->gl.currentWndSurface->incStrong(nullptr);
 
         rsc->setWatchdogGL("eglCreateWindowSurface", __LINE__, __FILE__);
         dc->gl.egl.surface = eglCreateWindowSurface(dc->gl.egl.display, dc->gl.egl.config,
-                                                    dc->gl.currentWndSurface, NULL);
+                                                    dc->gl.currentWndSurface, nullptr);
         checkEglError("eglCreateWindowSurface");
         if (dc->gl.egl.surface == EGL_NO_SURFACE) {
             ALOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
@@ -455,23 +455,23 @@
                              dc->gl.egl.surface, dc->gl.egl.context);
         checkEglError("eglMakeCurrent", ret);
     }
-    rsc->setWatchdogGL(NULL, 0, NULL);
+    rsc->setWatchdogGL(nullptr, 0, nullptr);
     return true;
 }
 
 bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, RsNativeWindow sur) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
-    if (dc->gl.wndSurface != NULL) {
-        dc->gl.wndSurface->decStrong(NULL);
-        dc->gl.wndSurface = NULL;
+    if (dc->gl.wndSurface != nullptr) {
+        dc->gl.wndSurface->decStrong(nullptr);
+        dc->gl.wndSurface = nullptr;
     }
     if(w && h) {
         // WAR: Some drivers fail to handle 0 size surfaces correctly. Use the
         // pbuffer to avoid this pitfall.
         dc->gl.wndSurface = (ANativeWindow *)sur;
-        if (dc->gl.wndSurface != NULL) {
-            dc->gl.wndSurface->incStrong(NULL);
+        if (dc->gl.wndSurface != nullptr) {
+            dc->gl.wndSurface->incStrong(nullptr);
         }
     }
 
diff --git a/driver/rsdGL.h b/driver/rsdGL.h
index 419c317..48c4c4e 100644
--- a/driver/rsdGL.h
+++ b/driver/rsdGL.h
@@ -20,7 +20,7 @@
 #include <rs_hal.h>
 #include <EGL/egl.h>
 
-#define RSD_CALL_GL(x, ...) rsc->setWatchdogGL(#x, __LINE__, __FILE__); x(__VA_ARGS__); rsc->setWatchdogGL(NULL, 0, NULL)
+#define RSD_CALL_GL(x, ...) rsc->setWatchdogGL(#x, __LINE__, __FILE__); x(__VA_ARGS__); rsc->setWatchdogGL(nullptr, 0, nullptr)
 
 class RsdShaderCache;
 class RsdVertexArrayState;
diff --git a/driver/rsdMesh.cpp b/driver/rsdMesh.cpp
index 50daf3e..01d2140 100644
--- a/driver/rsdMesh.cpp
+++ b/driver/rsdMesh.cpp
@@ -28,7 +28,7 @@
 using namespace android::renderscript;
 
 bool rsdMeshInit(const Context *rsc, const Mesh *m) {
-    RsdMeshObj *drv = NULL;
+    RsdMeshObj *drv = nullptr;
     if(m->mHal.drv) {
         drv = (RsdMeshObj*)m->mHal.drv;
         delete drv;
diff --git a/driver/rsdMeshObj.cpp b/driver/rsdMeshObj.cpp
index 8f072a5..ac1780c 100644
--- a/driver/rsdMeshObj.cpp
+++ b/driver/rsdMeshObj.cpp
@@ -32,9 +32,9 @@
 RsdMeshObj::RsdMeshObj(const Context *rsc, const Mesh *rsMesh) {
     mRSMesh = rsMesh;
 
-    mAttribs = NULL;
-    mAttribAllocationIndex = NULL;
-    mGLPrimitives = NULL;
+    mAttribs = nullptr;
+    mAttribAllocationIndex = nullptr;
+    mGLPrimitives = nullptr;
 
     mAttribCount = 0;
 }
@@ -86,8 +86,8 @@
     if (mAttribs) {
         delete [] mAttribs;
         delete [] mAttribAllocationIndex;
-        mAttribs = NULL;
-        mAttribAllocationIndex = NULL;
+        mAttribs = nullptr;
+        mAttribAllocationIndex = nullptr;
     }
     if (!mAttribCount) {
         return false;
@@ -148,7 +148,7 @@
 
         if (drvAlloc->bufferID) {
             mAttribs[ct].buffer = drvAlloc->bufferID;
-            mAttribs[ct].ptr = NULL;
+            mAttribs[ct].ptr = nullptr;
         } else {
             mAttribs[ct].buffer = 0;
             mAttribs[ct].ptr = (const uint8_t*)alloc->mHal.drvState.lod[0].mallocPtr;
diff --git a/driver/rsdPath.cpp b/driver/rsdPath.cpp
index ee5e3ad..1a9fa21 100644
--- a/driver/rsdPath.cpp
+++ b/driver/rsdPath.cpp
@@ -71,13 +71,13 @@
 
 bool rsdPathInitStatic(const Context *rsc, const Path *m,
                        const Allocation *vtx, const Allocation *loops) {
-    DrvPathStatic *drv = NULL;
+    DrvPathStatic *drv = nullptr;
     cleanup(rsc, m);
 
     DrvPathStatic *dps = new DrvPathStatic(vtx, loops);
     //LOGE("init path m %p,  %p", m, dps);
     m->mHal.drv = dps;
-    return dps != NULL;
+    return dps != nullptr;
 }
 
 bool rsdPathInitDynamic(const Context *rsc, const Path *m) {
@@ -97,7 +97,7 @@
 
 void rsdPathDestroy(const Context *rsc, const Path *m) {
     cleanup(rsc, m);
-    m->mHal.drv = NULL;
+    m->mHal.drv = nullptr;
 }
 
 
diff --git a/driver/rsdProgram.cpp b/driver/rsdProgram.cpp
index 132f7be..f2b5452 100644
--- a/driver/rsdProgram.cpp
+++ b/driver/rsdProgram.cpp
@@ -67,7 +67,7 @@
 void rsdProgramVertexDestroy(const Context *rsc, const ProgramVertex *pv) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
-    RsdShader *drv = NULL;
+    RsdShader *drv = nullptr;
     if(pv->mHal.drv) {
         drv = (RsdShader*)pv->mHal.drv;
         if (rsc->props.mLogShaders) {
@@ -101,7 +101,7 @@
 void rsdProgramFragmentDestroy(const Context *rsc, const ProgramFragment *pf) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
-    RsdShader *drv = NULL;
+    RsdShader *drv = nullptr;
     if(pf->mHal.drv) {
         drv = (RsdShader*)pf->mHal.drv;
         if (rsc->props.mLogShaders) {
diff --git a/driver/rsdProgramStore.cpp b/driver/rsdProgramStore.cpp
index c1295e8..79d2fdd 100644
--- a/driver/rsdProgramStore.cpp
+++ b/driver/rsdProgramStore.cpp
@@ -39,7 +39,7 @@
 
 bool rsdProgramStoreInit(const Context *rsc, const ProgramStore *ps) {
     DrvProgramStore *drv = (DrvProgramStore *)calloc(1, sizeof(DrvProgramStore));
-    if (drv == NULL) {
+    if (drv == nullptr) {
         return false;
     }
 
@@ -149,7 +149,7 @@
 
 error:
     free(drv);
-    ps->mHal.drv = NULL;
+    ps->mHal.drv = nullptr;
     return false;
 }
 
@@ -198,7 +198,7 @@
 
 void rsdProgramStoreDestroy(const Context *rsc, const ProgramStore *ps) {
     free(ps->mHal.drv);
-    ps->mHal.drv = NULL;
+    ps->mHal.drv = nullptr;
 }
 
 
diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp
index 2fd7ff8..8f5dbbe 100644
--- a/driver/rsdRuntimeStubs.cpp
+++ b/driver/rsdRuntimeStubs.cpp
@@ -532,7 +532,8 @@
                             android::renderscript::rs_allocation in,
                             android::renderscript::rs_allocation out) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, NULL, 0, NULL);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               nullptr, 0, nullptr);
 }
 #else
 static void SC_ForEach_SAA(android::renderscript::rs_script *target,
@@ -549,7 +550,8 @@
                             android::renderscript::rs_allocation out,
                             const void *usr) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, 0, NULL);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               usr, 0, nullptr);
 }
 #else
 static void SC_ForEach_SAAU(android::renderscript::rs_script *target,
@@ -588,7 +590,8 @@
                              const void *usr,
                              uint32_t usrLen) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, usrLen, NULL);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               usr, usrLen, nullptr);
 }
 #else
 static void SC_ForEach_SAAUL(android::renderscript::rs_script *target,
@@ -673,7 +676,7 @@
 
 static uint32_t SC_ToClient(int cmdID) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    return rsrToClient(rsc, cmdID, (const void *)NULL, 0);
+    return rsrToClient(rsc, cmdID, (const void *)nullptr, 0);
 }
 
 static uint32_t SC_ToClientBlocking2(int cmdID, const void *data, uint32_t len) {
@@ -683,7 +686,7 @@
 
 static uint32_t SC_ToClientBlocking(int cmdID) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    return rsrToClientBlocking(rsc, cmdID, (const void *)NULL, 0);
+    return rsrToClientBlocking(rsc, cmdID, (const void *)nullptr, 0);
 }
 
 
@@ -696,20 +699,20 @@
     if (x >= t->getLODDimX(0)) {
         sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (vecSize > 0) {
         if (vecSize != e->getVectorSize()) {
             sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
 
         if (dt != e->getType()) {
             sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -727,26 +730,26 @@
     if (x >= t->getLODDimX(0)) {
         sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (y >= t->getLODDimY(0)) {
         sprintf(buf, "Out range ElementAt Y %i of %i", y, t->getLODDimY(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (vecSize > 0) {
         if (vecSize != e->getVectorSize()) {
             sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
 
         if (dt != e->getType()) {
             sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -765,32 +768,32 @@
     if (x >= t->getLODDimX(0)) {
         sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (y >= t->getLODDimY(0)) {
         sprintf(buf, "Out range ElementAt Y %i of %i", y, t->getLODDimY(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (z >= t->getLODDimZ(0)) {
         sprintf(buf, "Out range ElementAt Z %i of %i", z, t->getLODDimZ(0));
         rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-        return NULL;
+        return nullptr;
     }
 
     if (vecSize > 0) {
         if (vecSize != e->getVectorSize()) {
             sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
 
         if (dt != e->getType()) {
             sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
             rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -814,7 +817,7 @@
     const Type *t = ((Allocation*)a.p)->getType();
     const Element *e = t->getElement();
     void *tmp = ElementAt1D((Allocation*)a.p, RS_TYPE_UNSIGNED_8, 0, x);
-    if (tmp != NULL) {
+    if (tmp != nullptr) {
         memcpy(tmp, ptr, e->getSizeBytes());
     }
 }
@@ -822,7 +825,7 @@
     const Type *t = ((Allocation*)a.p)->getType();
     const Element *e = t->getElement();
     void *tmp = ElementAt2D((Allocation*)a.p, RS_TYPE_UNSIGNED_8, 0, x, y);
-    if (tmp != NULL) {
+    if (tmp != nullptr) {
         memcpy(tmp, ptr, e->getSizeBytes());
     }
 }
@@ -830,41 +833,41 @@
     const Type *t = ((Allocation*)a.p)->getType();
     const Element *e = t->getElement();
     void *tmp = ElementAt3D((Allocation*)a.p, RS_TYPE_UNSIGNED_8, 0, x, y, z);
-    if (tmp != NULL) {
+    if (tmp != nullptr) {
         memcpy(tmp, ptr, e->getSizeBytes());
     }
 }
 
 #define ELEMENT_AT(T, DT, VS)                                               \
     static void SC_SetElementAt1_##T(android::renderscript::rs_allocation a, const T *val, uint32_t x) { \
-        void *r = ElementAt1D((Allocation*)a.p, DT, VS, x);               \
-        if (r != NULL) ((T *)r)[0] = *val;                               \
+        void *r = ElementAt1D((Allocation*)a.p, DT, VS, x);             \
+        if (r != nullptr) ((T *)r)[0] = *val;                           \
         else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
     }                                                                   \
     static void SC_SetElementAt2_##T(android::renderscript::rs_allocation a, const T * val, uint32_t x, uint32_t y) { \
-        void *r = ElementAt2D((Allocation*)a.p, DT, VS, x, y);            \
-        if (r != NULL) ((T *)r)[0] = *val;                               \
+        void *r = ElementAt2D((Allocation*)a.p, DT, VS, x, y);          \
+        if (r != nullptr) ((T *)r)[0] = *val;                           \
         else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
     }                                                                   \
     static void SC_SetElementAt3_##T(android::renderscript::rs_allocation a, const T * val, uint32_t x, uint32_t y, uint32_t z) { \
-        void *r = ElementAt3D((Allocation*)a.p, DT, VS, x, y, z);         \
-        if (r != NULL) ((T *)r)[0] = *val;                               \
+        void *r = ElementAt3D((Allocation*)a.p, DT, VS, x, y, z);       \
+        if (r != nullptr) ((T *)r)[0] = *val;                           \
         else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
     }                                                                   \
     static void SC_GetElementAt1_##T(android::renderscript::rs_allocation a, T *val, uint32_t x) {                  \
-        void *r = ElementAt1D((Allocation*)a.p, DT, VS, x);               \
-        if (r != NULL) *val = ((T *)r)[0];                              \
-        else ALOGE("Error from %s", __PRETTY_FUNCTION__);                    \
+        void *r = ElementAt1D((Allocation*)a.p, DT, VS, x);             \
+        if (r != nullptr) *val = ((T *)r)[0];                           \
+        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
     }                                                                   \
     static void SC_GetElementAt2_##T(android::renderscript::rs_allocation a, T *val, uint32_t x, uint32_t y) {      \
-        void *r = ElementAt2D((Allocation*)a.p, DT, VS, x, y);            \
-        if (r != NULL) *val = ((T *)r)[0];                              \
-        else ALOGE("Error from %s", __PRETTY_FUNCTION__);                    \
-    }                                                                   \
+        void *r = ElementAt2D((Allocation*)a.p, DT, VS, x, y);           \
+        if (r != nullptr) *val = ((T *)r)[0];                            \
+        else ALOGE("Error from %s", __PRETTY_FUNCTION__);                \
+    }                                                                    \
     static void SC_GetElementAt3_##T(android::renderscript::rs_allocation a, T *val, uint32_t x, uint32_t y, uint32_t z) { \
-        void *r = ElementAt3D((Allocation*)a.p, DT, VS, x, y, z);         \
-        if (r != NULL) *val = ((T *)r)[0];                              \
-        else ALOGE("Error from %s", __PRETTY_FUNCTION__);                    \
+        void *r = ElementAt3D((Allocation*)a.p, DT, VS, x, y, z);        \
+        if (r != nullptr) *val = ((T *)r)[0];                            \
+        else ALOGE("Error from %s", __PRETTY_FUNCTION__);                \
     }
 
 ELEMENT_AT(char, RS_TYPE_SIGNED_8, 1)
@@ -1367,7 +1370,7 @@
     { "_Z9rsgFinishv", (void *)&SC_Finish, false },
 #endif
 
-    { NULL, NULL, false }
+    { nullptr, nullptr, false }
 };
 
 #ifdef RS_COMPATIBILITY_LIB
@@ -1378,7 +1381,7 @@
 
 #define IS_CLEAR_SET_OBJ(t) \
     bool rsIsObject(t src) { \
-        return src.p != NULL; \
+        return src.p != nullptr; \
     } \
     void __attribute__((overloadable)) rsClearObject(t *dst) { \
         return SC_ClearObject(reinterpret_cast<rs_object_base *>(dst)); \
@@ -1398,7 +1401,8 @@
                            ::rs_allocation in,
                            ::rs_allocation out) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, NULL, 0, NULL);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               nullptr, 0, nullptr);
 }
 
 static void SC_ForEach_SAAUS(::rs_script target,
@@ -1407,7 +1411,8 @@
                              const void *usr,
                              const RsScriptCall *call) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, 0, call);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               usr, 0, call);
 }
 
 static void SC_ForEach_SAAUL(::rs_script target,
@@ -1416,7 +1421,8 @@
                              const void *usr,
                              uint32_t usrLen) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, usrLen, NULL);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               usr, usrLen, nullptr);
 }
 
 static void SC_ForEach_SAAULS(::rs_script target,
@@ -1426,7 +1432,8 @@
                               uint32_t usrLen,
                               const RsScriptCall *call) {
     Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, usrLen, call);
+    rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
+               usr, usrLen, call);
 }
 
 const Allocation * rsGetAllocation(const void *ptr) {
@@ -1897,7 +1904,7 @@
 extern const RsdCpuReference::CpuSymbol * rsdLookupRuntimeStub(Context * pContext, char const* name) {
     ScriptC *s = (ScriptC *)pContext;
     const RsdCpuReference::CpuSymbol *syms = gSyms;
-    const RsdCpuReference::CpuSymbol *sym = NULL;
+    const RsdCpuReference::CpuSymbol *sym = nullptr;
 
     if (!sym) {
         while (syms->fnPtr) {
@@ -1908,5 +1915,5 @@
         }
     }
 
-    return NULL;
+    return nullptr;
 }
diff --git a/driver/rsdSampler.cpp b/driver/rsdSampler.cpp
index 1a72fd4..28b594f 100644
--- a/driver/rsdSampler.cpp
+++ b/driver/rsdSampler.cpp
@@ -47,13 +47,13 @@
 {
     obj->p = alloc;
 #ifdef __LP64__
-    obj->r = NULL;
-    if (alloc != NULL) {
+    obj->r = nullptr;
+    if (alloc != nullptr) {
         obj->v1 = alloc->mHal.drv;
     } else {
-        obj->v1 = NULL;
+        obj->v1 = nullptr;
     }
-    obj->v2 = NULL;
+    obj->v2 = nullptr;
 #endif
 }
 
diff --git a/driver/rsdScriptGroup.cpp b/driver/rsdScriptGroup.cpp
index 6162c11..a7b2e77 100644
--- a/driver/rsdScriptGroup.cpp
+++ b/driver/rsdScriptGroup.cpp
@@ -32,7 +32,7 @@
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
 
     sg->mHal.drv = dc->mCpuRef->createScriptGroup(sg);
-    return sg->mHal.drv != NULL;
+    return sg->mHal.drv != nullptr;
 }
 
 void rsdScriptGroupSetInput(const Context *rsc, const ScriptGroup *sg,
@@ -59,13 +59,13 @@
 {
     obj->p = sg;
 #ifdef __LP64__
-    obj->r = NULL;
-    if (sg != NULL) {
+    obj->r = nullptr;
+    if (sg != nullptr) {
         obj->v1 = sg->mHal.drv;
     } else {
-        obj->v1 = NULL;
+        obj->v1 = nullptr;
     }
-    obj->v2 = NULL;
+    obj->v2 = nullptr;
 #endif
 }
 
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index d1a486b..7511883 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -65,16 +65,16 @@
     mAttribCount = 0;
     mUniformCount = 0;
 
-    mAttribNames = NULL;
-    mUniformNames = NULL;
-    mUniformArraySizes = NULL;
-    mCurrentState = NULL;
+    mAttribNames = nullptr;
+    mUniformNames = nullptr;
+    mUniformArraySizes = nullptr;
+    mCurrentState = nullptr;
 
     mIsValid = false;
 }
 
 RsdShader::StateBasedKey *RsdShader::getExistingState() {
-    RsdShader::StateBasedKey *returnKey = NULL;
+    RsdShader::StateBasedKey *returnKey = nullptr;
 
     for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
         returnKey = mStateBasedShaders[i];
@@ -92,7 +92,7 @@
                 texType = GL_TEXTURE_CUBE_MAP;
             }
             if (texType != returnKey->mTextureTargets[ct]) {
-                returnKey = NULL;
+                returnKey = nullptr;
                 break;
             }
         }
@@ -102,7 +102,7 @@
 
 uint32_t RsdShader::getStateBasedShaderID(const Context *rsc) {
     StateBasedKey *state = getExistingState();
-    if (state != NULL) {
+    if (state != nullptr) {
         mCurrentState = state;
         return mCurrentState->mShaderID;
     }
@@ -121,7 +121,7 @@
     uint32_t uniformCount = 0;
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
         initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames,
-                           NULL, &attribCount, RS_SHADER_ATTR);
+                           nullptr, &attribCount, RS_SHADER_ATTR);
     }
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
         initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(),
@@ -243,7 +243,7 @@
 
     if (mCurrentState->mShaderID) {
         const char * ss = mShader.c_str();
-        RSD_CALL_GL(glShaderSource, mCurrentState->mShaderID, 1, &ss, NULL);
+        RSD_CALL_GL(glShaderSource, mCurrentState->mShaderID, 1, &ss, nullptr);
         RSD_CALL_GL(glCompileShader, mCurrentState->mShaderID);
 
         GLint compiled = 0;
@@ -254,7 +254,7 @@
             if (infoLen) {
                 char* buf = (char*) malloc(infoLen);
                 if (buf) {
-                    RSD_CALL_GL(glGetShaderInfoLog, mCurrentState->mShaderID, infoLen, NULL, buf);
+                    RSD_CALL_GL(glGetShaderInfoLog, mCurrentState->mShaderID, infoLen, nullptr, buf);
                     rsc->setError(RS_ERROR_FATAL_PROGRAM_LINK, buf);
                     free(buf);
                 }
diff --git a/driver/rsdShaderCache.cpp b/driver/rsdShaderCache.cpp
index 0e36b49..608922c 100644
--- a/driver/rsdShaderCache.cpp
+++ b/driver/rsdShaderCache.cpp
@@ -166,7 +166,7 @@
             if (bufLength) {
                 char* buf = (char*) malloc(bufLength);
                 if (buf) {
-                    glGetProgramInfoLog(pgm, bufLength, NULL, buf);
+                    glGetProgramInfoLog(pgm, bufLength, nullptr, buf);
                     rsc->setError(RS_ERROR_FATAL_PROGRAM_LINK, buf);
                     free(buf);
                 }
@@ -189,7 +189,7 @@
         populateUniformData(frag, pgm, e->fragUniforms);
 
         // Only populate this list if we have arrays in our uniforms
-        UniformQueryData **uniformList = NULL;
+        UniformQueryData **uniformList = nullptr;
         GLint numUniforms = 0;
         bool hasArrays = hasArrayUniforms(vtx, frag);
         if (hasArrays) {
@@ -221,12 +221,12 @@
                                uniformList, (uint32_t)numUniforms);
 
         // Clean up the uniform data from GL
-        if (uniformList != NULL) {
+        if (uniformList != nullptr) {
             for (uint32_t ct = 0; ct < (uint32_t)numUniforms; ct++) {
                 delete uniformList[ct];
             }
             delete[] uniformList;
-            uniformList = NULL;
+            uniformList = nullptr;
         }
     }
 
diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h
index 9b45092..de195e6 100644
--- a/driver/rsdShaderCache.h
+++ b/driver/rsdShaderCache.h
@@ -78,16 +78,16 @@
         int32_t arraySize;
         uint32_t type;
         UniformQueryData(uint32_t maxName) {
-            name = NULL;
+            name = nullptr;
             nameLength = maxName;
             if (nameLength > 0 ) {
                 name = new char[nameLength];
             }
         }
         ~UniformQueryData() {
-            if (name != NULL) {
+            if (name != nullptr) {
                 delete[] name;
-                name = NULL;
+                name = nullptr;
             }
         }
     };
@@ -119,19 +119,19 @@
         ~ProgramEntry() {
             if (vtxAttrs) {
                 delete[] vtxAttrs;
-                vtxAttrs = NULL;
+                vtxAttrs = nullptr;
             }
             if (vtxUniforms) {
                 delete[] vtxUniforms;
-                vtxUniforms = NULL;
+                vtxUniforms = nullptr;
             }
             if (fragUniforms) {
                 delete[] fragUniforms;
-                fragUniforms = NULL;
+                fragUniforms = nullptr;
             }
             if (fragUniformIsSTO) {
                 delete[] fragUniformIsSTO;
-                fragUniformIsSTO = NULL;
+                fragUniformIsSTO = nullptr;
             }
         }
         uint32_t vtx;
diff --git a/driver/rsdType.cpp b/driver/rsdType.cpp
index fa7b46c..869a86d 100644
--- a/driver/rsdType.cpp
+++ b/driver/rsdType.cpp
@@ -46,9 +46,9 @@
 {
     obj->p = t;
 #ifdef __LP64__
-    obj->r = NULL;
-    obj->v1 = NULL;
-    obj->v2 = NULL;
+    obj->r = nullptr;
+    obj->v1 = nullptr;
+    obj->v2 = nullptr;
 #endif
 }
 
diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp
index d0a9b3e..c18a062 100644
--- a/driver/rsdVertexArray.cpp
+++ b/driver/rsdVertexArray.cpp
@@ -46,7 +46,7 @@
     type = 0;
     size = 0;
     stride = 0;
-    ptr = NULL;
+    ptr = nullptr;
     normalized = false;
     name = "";
 }
@@ -118,14 +118,14 @@
 }
 ////////////////////////////////////////////
 RsdVertexArrayState::RsdVertexArrayState() {
-    mAttrsEnabled = NULL;
+    mAttrsEnabled = nullptr;
     mAttrsEnabledSize = 0;
 }
 
 RsdVertexArrayState::~RsdVertexArrayState() {
     if (mAttrsEnabled) {
         delete[] mAttrsEnabled;
-        mAttrsEnabled = NULL;
+        mAttrsEnabled = nullptr;
     }
 }
 void RsdVertexArrayState::init(uint32_t maxAttrs) {
diff --git a/driver/runtime/rs_structs.h b/driver/runtime/rs_structs.h
index e35cd54..40f740a 100644
--- a/driver/runtime/rs_structs.h
+++ b/driver/runtime/rs_structs.h
@@ -275,7 +275,7 @@
             void **vertexBuffers;
             uint32_t vertexBuffersCount;
 
-            // indexBuffers[i] could be NULL, in which case only primitives[i] is used
+            // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
             void **indexBuffers;
             uint32_t indexBuffersCount;
             rs_primitive *primitives;
diff --git a/java/tests/HelloComputeNDK/Android.mk b/java/tests/HelloComputeNDK/Android.mk
index 58b95aa..5f1bd17 100644
--- a/java/tests/HelloComputeNDK/Android.mk
+++ b/java/tests/HelloComputeNDK/Android.mk
@@ -17,6 +17,8 @@
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
+LOCAL_CFLAGS := -std=c++11
+
 LOCAL_MODULE_TAGS := tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
diff --git a/java/tests/HelloComputeNDK/libhellocomputendk/Android.mk b/java/tests/HelloComputeNDK/libhellocomputendk/Android.mk
index 2b197f1..5f3a51d 100644
--- a/java/tests/HelloComputeNDK/libhellocomputendk/Android.mk
+++ b/java/tests/HelloComputeNDK/libhellocomputendk/Android.mk
@@ -28,6 +28,7 @@
 LOCAL_C_INCLUDES += frameworks/rs
 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS := -Wl,-Bsymbolic
 LOCAL_SHARED_LIBRARIES := libdl liblog libjnigraphics
 LOCAL_STATIC_LIBRARIES := libRScpp_static
diff --git a/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp b/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
index 4985664..1aab056 100644
--- a/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
+++ b/java/tests/HelloComputeNDK/libhellocomputendk/helloComputeNDK.cpp
@@ -27,13 +27,13 @@
                                                                        )
 {
 
-    void* inputPtr = NULL;
-    void* outputPtr = NULL;
+    void* inputPtr = nullptr;
+    void* outputPtr = nullptr;
 
     AndroidBitmap_lockPixels(env, jbitmapIn, &inputPtr);
     AndroidBitmap_lockPixels(env, jbitmapOut, &outputPtr);
 
-    const char * path = env->GetStringUTFChars(pathObj, NULL);
+    const char * path = env->GetStringUTFChars(pathObj, nullptr);
     sp<RS> rs = new RS();
     rs->init(path);
     env->ReleaseStringUTFChars(pathObj, path);
diff --git a/rsAdapter.cpp b/rsAdapter.cpp
index 9fd39f8..52d8ec7 100644
--- a/rsAdapter.cpp
+++ b/rsAdapter.cpp
@@ -45,7 +45,7 @@
 }
 
 Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 namespace android {
@@ -118,7 +118,7 @@
 }
 
 Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index f9e4266..fad26cd 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -55,7 +55,7 @@
 
     if (!allocMem) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation");
-        return NULL;
+        return nullptr;
     }
 
     Allocation *a = new (allocMem) Allocation(rsc, type, usages, mc, ptr);
@@ -63,7 +63,7 @@
     if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure");
         delete a;
-        return NULL;
+        return nullptr;
     }
 
     return a;
@@ -82,7 +82,7 @@
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
     if (mGrallocConsumer.get()) {
         mGrallocConsumer->unlockBuffer();
-        mGrallocConsumer = NULL;
+        mGrallocConsumer = nullptr;
     }
 #endif
 
@@ -101,12 +101,12 @@
         (z && (z >= mHal.drvState.lod[lod].dimZ)) ||
         ((face != RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X) && !mHal.state.hasFaces) ||
         (array != 0)) {
-        return NULL;
+        return nullptr;
     }
 
     size_t s = 0;
     //void *ptr = mRSC->mHal.funcs.allocation.lock1D(rsc, this);
-    if ((stride != NULL) && mHal.drvState.lod[0].dimY) {
+    if ((stride != nullptr) && mHal.drvState.lod[0].dimY) {
         *stride = mHal.drvState.lod[lod].stride;
     }
     return mHal.drvState.lod[lod].mallocPtr;
@@ -385,14 +385,14 @@
     if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
         rsc->setError(RS_ERROR_FATAL_DRIVER,
                       "allocation loading failed due to corrupt file. (invalid id)\n");
-        return NULL;
+        return nullptr;
     }
 
     const char *name = stream->loadString();
 
     Type *type = Type::createFromStream(rsc, stream);
     if (!type) {
-        return NULL;
+        return nullptr;
     }
     type->compute();
 
@@ -409,7 +409,7 @@
                       "allocation loading failed due to corrupt file. (invalid size)\n");
         ObjectBase::checkDelete(alloc);
         ObjectBase::checkDelete(type);
-        return NULL;
+        return nullptr;
     }
 
     alloc->assignName(name);
@@ -446,7 +446,7 @@
 }
 
 void Allocation::callUpdateCacheObject(const Context *rsc, void *dstObj) const {
-    if (rsc->mHal.funcs.allocation.updateCachedObject != NULL) {
+    if (rsc->mHal.funcs.allocation.updateCachedObject != nullptr) {
         rsc->mHal.funcs.allocation.updateCachedObject(rsc, this, (rs_allocation *)dstObj);
     } else {
         *((const void **)dstObj) = this;
@@ -495,7 +495,7 @@
 #ifndef RS_COMPATIBILITY_LIB
 void Allocation::NewBufferListener::onFrameAvailable() {
     intptr_t ip = (intptr_t)alloc;
-    rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_NEW_BUFFER, ip, 0, true);
+    rsc->sendMessageToClient(nullptr, RS_MESSAGE_TO_CLIENT_NEW_BUFFER, ip, 0, true);
 }
 #endif
 
@@ -505,7 +505,7 @@
     sp<BufferQueue> bq = new BufferQueue();
     mGrallocConsumer = new GrallocConsumer(this, bq);
     sp<IGraphicBufferProducer> bp = bq;
-    bp->incStrong(NULL);
+    bp->incStrong(nullptr);
 
     mBufferListener = new NewBufferListener();
     mBufferListener->rsc = rsc;
@@ -514,7 +514,7 @@
     mGrallocConsumer->setFrameAvailableListener(mBufferListener);
     return bp.get();
 #else
-    return NULL;
+    return nullptr;
 #endif
     //return rsc->mHal.funcs.allocation.getSurface(rsc, this);
 }
@@ -529,7 +529,7 @@
 }
 
 void Allocation::ioReceive(const Context *rsc) {
-    void *ptr = NULL;
+    void *ptr = nullptr;
     size_t stride = 0;
 #ifndef RS_COMPATIBILITY_LIB
     if (mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
@@ -643,7 +643,7 @@
                                        uint32_t usages, uintptr_t ptr) {
     Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mipmaps, (void*)ptr);
     if (!alloc) {
-        return NULL;
+        return nullptr;
     }
     alloc->incUserRef();
     return alloc;
@@ -656,9 +656,9 @@
 
     RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0);
     Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
-    if (texAlloc == NULL) {
+    if (texAlloc == nullptr) {
         ALOGE("Memory allocation failure");
-        return NULL;
+        return nullptr;
     }
 
     texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
@@ -681,9 +681,9 @@
     // Error checking is done in the java layer
     RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0);
     Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
-    if (texAlloc == NULL) {
+    if (texAlloc == nullptr) {
         ALOGE("Memory allocation failure");
-        return NULL;
+        return nullptr;
     }
 
     uint32_t faceSize = t->getDimX();
diff --git a/rsAnimation.cpp b/rsAnimation.cpp
index f6da138..964e7c1 100644
--- a/rsAnimation.cpp
+++ b/rsAnimation.cpp
@@ -25,7 +25,7 @@
 }
 
 Animation *Animation::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 /*
@@ -34,8 +34,8 @@
     mAllocFile = __FILE__;
     mAllocLine = __LINE__;
 
-    mValuesInput = NULL;
-    mValuesOutput = NULL;
+    mValuesInput = nullptr;
+    mValuesOutput = nullptr;
     mValueCount = 0;
     mInterpolation = RS_ANIMATION_INTERPOLATION_STEP;
     mEdgePre = RS_ANIMATION_EDGE_UNDEFINED;
@@ -51,22 +51,22 @@
 {
     if (valueCount < 2) {
         rsc->setError(RS_ERROR_BAD_VALUE, "Animations require more than 2 values.");
-        return NULL;
+        return nullptr;
     }
     Animation *a = new Animation(rsc);
     if (!a) {
         rsc->setError(RS_ERROR_OUT_OF_MEMORY);
-        return NULL;
+        return nullptr;
     }
 
     float *vin = (float *)malloc(valueCount * sizeof(float));
     float *vout = (float *)malloc(valueCount * sizeof(float));
     a->mValuesInput = vin;
     a->mValuesOutput = vout;
-    if (a->mValuesInput == NULL || a->mValuesOutput == NULL) {
+    if (a->mValuesInput == nullptr || a->mValuesOutput == nullptr) {
         delete a;
         rsc->setError(RS_ERROR_OUT_OF_MEMORY);
-        return NULL;
+        return nullptr;
     }
 
     a->mEdgePre = pre;
@@ -127,8 +127,8 @@
                                 RsAnimationEdge pre,
                                 RsAnimationEdge post) {
     //ALOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
-    Animation *a = NULL;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post);
-    if (a != NULL) {
+    Animation *a = nullptr;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post);
+    if (a != nullptr) {
         a->incUserRef();
     }
     return (RsAnimation)a;
diff --git a/rsContext.cpp b/rsContext.cpp
index 410ab35..a83eb9f 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -232,7 +232,7 @@
     uint32_t bufferLen = strlen(buffer);
 
     ObjectBaseRef<Font> lastFont(getFont());
-    setFont(NULL);
+    setFont(nullptr);
     float shadowCol = 0.1f;
     mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f);
     mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6);
@@ -248,10 +248,10 @@
 bool Context::loadRuntime(const char* filename, Context* rsc) {
 
     // TODO: store the driverSO somewhere so we can dlclose later
-    void *driverSO = NULL;
+    void *driverSO = nullptr;
 
     driverSO = dlopen(filename, RTLD_LAZY);
-    if (driverSO == NULL) {
+    if (driverSO == nullptr) {
         ALOGE("Failed loading RS driver: %s", dlerror());
         return false;
     }
@@ -262,13 +262,13 @@
     HalSig halInit = (HalSig) dlsym(driverSO, "rsdHalInit");
 
     // If we can't find the C variant, we go looking for the C++ version.
-    if (halInit == NULL) {
+    if (halInit == nullptr) {
         ALOGW("Falling back to find C++ rsdHalInit: %s", dlerror());
         halInit = (HalSig) dlsym(driverSO,
                 "_Z10rsdHalInitPN7android12renderscript7ContextEjj");
     }
 
-    if (halInit == NULL) {
+    if (halInit == nullptr) {
         dlclose(driverSO);
         ALOGE("Failed to find rsdHalInit: %s", dlerror());
         return false;
@@ -345,12 +345,12 @@
         if (!loadRuntime("libRSDriver.so", rsc)) {
             ALOGE("Failed to load default runtime!");
             rsc->setError(RS_ERROR_FATAL_DRIVER, "Failed loading RS driver");
-            return NULL;
+            return nullptr;
         }
     }
 #else // RS_COMPATIBILITY_LIB
     if (rsdHalInit(rsc, 0, 0) != true) {
-        return NULL;
+        return nullptr;
     }
 #endif
 
@@ -361,19 +361,19 @@
     if (rsc->mIsGraphicsContext) {
         if (!rsc->initGLThread()) {
             rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL");
-            return NULL;
+            return nullptr;
         }
 
         rsc->mStateRaster.init(rsc);
-        rsc->setProgramRaster(NULL);
+        rsc->setProgramRaster(nullptr);
         rsc->mStateVertex.init(rsc);
-        rsc->setProgramVertex(NULL);
+        rsc->setProgramVertex(nullptr);
         rsc->mStateFragment.init(rsc);
-        rsc->setProgramFragment(NULL);
+        rsc->setProgramFragment(nullptr);
         rsc->mStateFragmentStore.init(rsc);
-        rsc->setProgramStore(NULL);
+        rsc->setProgramStore(nullptr);
         rsc->mStateFont.init(rsc);
-        rsc->setFont(NULL);
+        rsc->setFont(nullptr);
         rsc->mStateSampler.init(rsc);
         rsc->mFBOCache.init(rsc);
     }
@@ -382,7 +382,7 @@
     rsc->mRunning = true;
 
     if (rsc->isSynchronous()) {
-        return NULL;
+        return nullptr;
     }
 
     if (!rsc->mIsGraphicsContext) {
@@ -422,7 +422,7 @@
                 drawOnce |= rsc->mIO.playCoreCommands(rsc, -1);
             }
 
-            if ((rsc->mRootScript.get() != NULL) && rsc->mHasSurface &&
+            if ((rsc->mRootScript.get() != nullptr) && rsc->mHasSurface &&
                 (targetRate || drawOnce) && !rsc->mPaused) {
 
                 drawOnce = false;
@@ -454,7 +454,7 @@
 #endif
 
     //ALOGV("%p RS Thread exited", rsc);
-    return NULL;
+    return nullptr;
 }
 
 void Context::destroyWorkerThreadResources() {
@@ -504,11 +504,11 @@
 }
 
 Context::Context() {
-    mDev = NULL;
+    mDev = nullptr;
     mRunning = false;
     mExit = false;
     mPaused = false;
-    mObjHead = NULL;
+    mObjHead = nullptr;
     mError = RS_ERROR_NONE;
     mTargetSdkVersion = 14;
     mDPI = 96;
@@ -535,7 +535,7 @@
 
     if (!rsc->initContext(dev, sc)) {
         delete rsc;
-        return NULL;
+        return nullptr;
     }
     return rsc;
 }
@@ -560,7 +560,7 @@
         memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig));
     }
 
-    mIsGraphicsContext = sc != NULL;
+    mIsGraphicsContext = sc != nullptr;
 
     int status;
     pthread_attr_t threadAttr;
@@ -627,7 +627,7 @@
         pthread_mutex_lock(&gInitMutex);
         if (mDev) {
             mDev->removeContext(this);
-            mDev = NULL;
+            mDev = nullptr;
         }
         pthread_mutex_unlock(&gInitMutex);
     }
@@ -639,7 +639,7 @@
     rsAssert(mIsGraphicsContext);
     mHal.funcs.setSurface(this, w, h, sur);
 
-    mHasSurface = sur != NULL;
+    mHasSurface = sur != nullptr;
     mWidth = w;
     mHeight = h;
 
@@ -651,11 +651,11 @@
 
 uint32_t Context::getCurrentSurfaceWidth() const {
     for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) {
-        if (mFBOCache.mHal.state.colorTargets[i] != NULL) {
+        if (mFBOCache.mHal.state.colorTargets[i] != nullptr) {
             return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimX();
         }
     }
-    if (mFBOCache.mHal.state.depthTarget != NULL) {
+    if (mFBOCache.mHal.state.depthTarget != nullptr) {
         return mFBOCache.mHal.state.depthTarget->getType()->getDimX();
     }
     return mWidth;
@@ -663,11 +663,11 @@
 
 uint32_t Context::getCurrentSurfaceHeight() const {
     for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) {
-        if (mFBOCache.mHal.state.colorTargets[i] != NULL) {
+        if (mFBOCache.mHal.state.colorTargets[i] != nullptr) {
             return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimY();
         }
     }
-    if (mFBOCache.mHal.state.depthTarget != NULL) {
+    if (mFBOCache.mHal.state.depthTarget != nullptr) {
         return mFBOCache.mHal.state.depthTarget->getType()->getDimY();
     }
     return mHeight;
@@ -690,7 +690,7 @@
 
 void Context::setProgramStore(ProgramStore *pfs) {
     rsAssert(mIsGraphicsContext);
-    if (pfs == NULL) {
+    if (pfs == nullptr) {
         mFragmentStore.set(mStateFragmentStore.mDefault);
     } else {
         mFragmentStore.set(pfs);
@@ -699,7 +699,7 @@
 
 void Context::setProgramFragment(ProgramFragment *pf) {
     rsAssert(mIsGraphicsContext);
-    if (pf == NULL) {
+    if (pf == nullptr) {
         mFragment.set(mStateFragment.mDefault);
     } else {
         mFragment.set(pf);
@@ -708,7 +708,7 @@
 
 void Context::setProgramRaster(ProgramRaster *pr) {
     rsAssert(mIsGraphicsContext);
-    if (pr == NULL) {
+    if (pr == nullptr) {
         mRaster.set(mStateRaster.mDefault);
     } else {
         mRaster.set(pr);
@@ -717,7 +717,7 @@
 
 void Context::setProgramVertex(ProgramVertex *pv) {
     rsAssert(mIsGraphicsContext);
-    if (pv == NULL) {
+    if (pv == nullptr) {
         mVertex.set(mStateVertex.mDefault);
     } else {
         mVertex.set(pv);
@@ -726,7 +726,7 @@
 
 void Context::setFont(Font *f) {
     rsAssert(mIsGraphicsContext);
-    if (f == NULL) {
+    if (f == nullptr) {
         mFont.set(mStateFont.mDefault);
     } else {
         mFont.set(f);
@@ -957,7 +957,7 @@
                                      RsContextType ct, uint32_t flags) {
     //ALOGV("rsContextCreate dev=%p", vdev);
     Device * dev = static_cast<Device *>(vdev);
-    Context *rsc = Context::createContext(dev, NULL, ct, flags);
+    Context *rsc = Context::createContext(dev, nullptr, ct, flags);
     if (rsc) {
         rsc->setTargetSdkVersion(sdkVersion);
     }
diff --git a/rsContext.h b/rsContext.h
index f750670..2e59cc7 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -234,7 +234,7 @@
     static void printWatchdogInfo(void *ctx);
 
     void dumpDebug() const;
-    void setError(RsError e, const char *msg = NULL) const;
+    void setError(RsError e, const char *msg = nullptr) const;
 
     mutable const ObjectBase * mObjHead;
 
diff --git a/rsCppUtils.h b/rsCppUtils.h
index 7432109..7f1d58c 100644
--- a/rsCppUtils.h
+++ b/rsCppUtils.h
@@ -78,7 +78,7 @@
     // we don't support the clocks here.
     struct timeval t;
     t.tv_sec = t.tv_usec = 0;
-    gettimeofday(&t, NULL);
+    gettimeofday(&t, nullptr);
     return nsecs_t(t.tv_sec)*1000000000LL + nsecs_t(t.tv_usec)*1000LL;
 #endif
 }
diff --git a/rsElement.cpp b/rsElement.cpp
index 0da8096..907e3d2 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -24,7 +24,7 @@
 Element::Element(Context *rsc) : ObjectBase(rsc) {
     mBits = 0;
     mBitsUnpadded = 0;
-    mFields = NULL;
+    mFields = nullptr;
     mFieldCount = 0;
     mHasReference = false;
     memset(&mHal, 0, sizeof(mHal));
@@ -61,7 +61,7 @@
         }
         delete [] mFields;
     }
-    mFields = NULL;
+    mFields = nullptr;
     mFieldCount = 0;
     mHasReference = false;
 
@@ -129,7 +129,7 @@
     RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
     if (classID != RS_A3D_CLASS_ID_ELEMENT) {
         ALOGE("element loading skipped due to invalid class id\n");
-        return NULL;
+        return nullptr;
     }
 
     const char *name = stream->loadString();
@@ -253,7 +253,7 @@
     void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Element), 0);
     if (!allocMem) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Element");
-        return NULL;
+        return nullptr;
     }
 
     Element *e = new (allocMem) Element(rsc);
@@ -317,7 +317,7 @@
     void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Element), 0);
     if (!allocMem) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Element");
-        return NULL;
+        return nullptr;
     }
 
     Element *e = new (allocMem) Element(rsc);
@@ -394,7 +394,7 @@
 }
 
 void Element::callUpdateCacheObject(const Context *rsc, void *dstObj) const {
-    if (rsc->mHal.funcs.element.updateCachedObject != NULL) {
+    if (rsc->mHal.funcs.element.updateCachedObject != nullptr) {
         rsc->mHal.funcs.element.updateCachedObject(rsc, this, (rs_element *)dstObj);
     } else {
         *((const void **)dstObj) = this;
diff --git a/rsElement.h b/rsElement.h
index 2ae9404..5c44ba0 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -125,8 +125,8 @@
     static const Element* create(Context *rsc, size_t count,
                                  const Element **ein,
                                  const char **nin,
-                                 const size_t * lengths = NULL,
-                                 const uint32_t *asin = NULL) {
+                                 const size_t * lengths = nullptr,
+                                 const uint32_t *asin = nullptr) {
         ObjectBaseRef<const Element> elem = createRef(rsc, count, ein, nin, lengths, asin);
         elem->incUserRef();
         return elem.get();
diff --git a/rsFBOCache.cpp b/rsFBOCache.cpp
index 1da327f..2185235 100644
--- a/rsFBOCache.cpp
+++ b/rsFBOCache.cpp
@@ -28,7 +28,7 @@
     mHal.state.colorTargetsCount = 1;
     mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
     mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
-    resetAll(NULL);
+    resetAll(nullptr);
 }
 
 FBOCache::~FBOCache() {
@@ -49,7 +49,7 @@
         ALOGE("Invalid render target index");
         return;
     }
-    if (a != NULL) {
+    if (a != nullptr) {
         if (!(a->getIsTexture() || (a->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT))) {
             ALOGE("Invalid Color Target");
             return;
@@ -61,7 +61,7 @@
 }
 
 void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
-    if (a != NULL) {
+    if (a != nullptr) {
         if (!a->getIsRenderTarget()) {
             ALOGE("Invalid Depth Target");
             return;
@@ -74,11 +74,11 @@
 
 void FBOCache::resetAll(Context *) {
     for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
-        mColorTargets[i].set(NULL);
-        mHal.state.colorTargets[i] = NULL;
+        mColorTargets[i].set(nullptr);
+        mHal.state.colorTargets[i] = nullptr;
     }
-    mDepthTarget.set(NULL);
-    mHal.state.depthTarget = NULL;
+    mDepthTarget.set(nullptr);
+    mHal.state.depthTarget = nullptr;
     mDirty = true;
 }
 
diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp
index ef5730f..6f14637 100644
--- a/rsFileA3D.cpp
+++ b/rsFileA3D.cpp
@@ -32,11 +32,11 @@
 using namespace android::renderscript;
 
 FileA3D::FileA3D(Context *rsc) : ObjectBase(rsc) {
-    mAlloc = NULL;
-    mData = NULL;
-    mWriteStream = NULL;
-    mReadStream = NULL;
-    mAsset = NULL;
+    mAlloc = nullptr;
+    mData = nullptr;
+    mWriteStream = nullptr;
+    mReadStream = nullptr;
+    mAsset = nullptr;
 
     mMajorVersion = 0;
     mMinorVersion = 1;
@@ -86,7 +86,7 @@
             entry->mOffset = headerStream->loadU32();
             entry->mLength = headerStream->loadU32();
         }
-        entry->mRsObj = NULL;
+        entry->mRsObj = nullptr;
         mIndex.push_back(entry);
     }
 }
@@ -225,17 +225,17 @@
     if (index < mIndex.size()) {
         return mIndex[index];
     }
-    return NULL;
+    return nullptr;
 }
 
 ObjectBase *FileA3D::initializeFromEntry(size_t index) {
     if (index >= mIndex.size()) {
-        return NULL;
+        return nullptr;
     }
 
     FileA3D::A3DIndexEntry *entry = mIndex[index];
     if (!entry) {
-        return NULL;
+        return nullptr;
     }
 
     if (entry->mRsObj) {
@@ -247,7 +247,7 @@
     mReadStream->reset(entry->mOffset);
     switch (entry->mType) {
         case RS_A3D_CLASS_ID_UNKNOWN:
-            return NULL;
+            return nullptr;
         case RS_A3D_CLASS_ID_MESH:
             entry->mRsObj = Mesh::createFromStream(mRSC, mReadStream);
             break;
@@ -389,7 +389,7 @@
     FileA3D *fa3d = static_cast<FileA3D *>(file);
     if (!fa3d) {
         ALOGE("Can't load entry. No valid file");
-        return NULL;
+        return nullptr;
     }
 
     ObjectBase *obj = fa3d->initializeFromEntry(index);
@@ -418,7 +418,7 @@
     }
 
     uint32_t numFileEntries = fa3d->getNumIndexEntries();
-    if (numFileEntries != numEntries || numEntries == 0 || fileEntries == NULL) {
+    if (numFileEntries != numEntries || numEntries == 0 || fileEntries == nullptr) {
         ALOGE("Can't load index entries. Invalid number requested");
         return;
     }
@@ -431,9 +431,9 @@
 }
 
 RsFile rsaFileA3DCreateFromMemory(RsContext con, const void *data, uint32_t len) {
-    if (data == NULL) {
-        ALOGE("File load failed. Asset stream is NULL");
-        return NULL;
+    if (data == nullptr) {
+        ALOGE("File load failed. Asset stream is nullptr");
+        return nullptr;
     }
 
     Context *rsc = static_cast<Context *>(con);
@@ -454,18 +454,18 @@
     fa3d->load(asset);
     return fa3d;
 #else
-    return NULL;
+    return nullptr;
 #endif
 }
 
 RsFile rsaFileA3DCreateFromFile(RsContext con, const char *path) {
-    if (path == NULL) {
-        ALOGE("File load failed. Path is NULL");
-        return NULL;
+    if (path == nullptr) {
+        ALOGE("File load failed. Path is nullptr");
+        return nullptr;
     }
 
     Context *rsc = static_cast<Context *>(con);
-    FileA3D *fa3d = NULL;
+    FileA3D *fa3d = nullptr;
 
     FILE *f = fopen(path, "rb");
     if (f) {
diff --git a/rsFont.cpp b/rsFont.cpp
index 71399af..2f09384 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -36,7 +36,7 @@
 Font::Font(Context *rsc) : ObjectBase(rsc) {
     mInitialized = false;
     mHasKerning = false;
-    mFace = NULL;
+    mFace = nullptr;
 }
 
 bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) {
@@ -47,7 +47,7 @@
     }
 
     FT_Error error = 0;
-    if (data != NULL && dataLen > 0) {
+    if (data != nullptr && dataLen > 0) {
         error = FT_New_Memory_Face(mRSC->mStateFont.getLib(), (const FT_Byte*)data, dataLen, 0, &mFace);
     } else {
         error = FT_New_Face(mRSC->mStateFont.getLib(), name, 0, &mFace);
@@ -166,12 +166,12 @@
                      uint32_t start, int32_t numGlyphs,
                      RenderMode mode, Rect *bounds,
                      uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH) {
-    if (!mInitialized || numGlyphs == 0 || text == NULL || len == 0) {
+    if (!mInitialized || numGlyphs == 0 || text == nullptr || len == 0) {
         return;
     }
 
     if (mode == Font::MEASURE) {
-        if (bounds == NULL) {
+        if (bounds == nullptr) {
             ALOGE("No return rectangle provided to measure text");
             return;
         }
@@ -229,7 +229,7 @@
 Font::CachedGlyphInfo* Font::getCachedUTFChar(int32_t utfChar) {
 
     CachedGlyphInfo *cachedGlyph = mCachedGlyphs[(uint32_t)utfChar];
-    if (cachedGlyph == NULL) {
+    if (cachedGlyph == nullptr) {
         cachedGlyph = cacheGlyph((uint32_t)utfChar);
     }
     // Is the glyph still in texture cache?
@@ -321,7 +321,7 @@
     }
 
     ObjectBase::checkDelete(newFont);
-    return NULL;
+    return nullptr;
 }
 
 Font::~Font() {
@@ -341,9 +341,9 @@
     mInitialized = false;
     mMaxNumberOfQuads = 1024;
     mCurrentQuadIndex = 0;
-    mRSC = NULL;
+    mRSC = nullptr;
 #ifndef ANDROID_RS_SERIALIZE
-    mLibrary = NULL;
+    mLibrary = nullptr;
 #endif //ANDROID_RS_SERIALIZE
 
     float gamma = DEFAULT_TEXT_GAMMA;
@@ -355,17 +355,17 @@
     char property[PROPERTY_VALUE_MAX];
 
     // Get the gamma
-    if (property_get(PROPERTY_TEXT_GAMMA, property, NULL) > 0) {
+    if (property_get(PROPERTY_TEXT_GAMMA, property, nullptr) > 0) {
         gamma = atof(property);
     }
 
     // Get the black gamma threshold
-    if (property_get(PROPERTY_TEXT_BLACK_GAMMA_THRESHOLD, property, NULL) > 0) {
+    if (property_get(PROPERTY_TEXT_BLACK_GAMMA_THRESHOLD, property, nullptr) > 0) {
         blackThreshold = atoi(property);
     }
 
     // Get the white gamma threshold
-    if (property_get(PROPERTY_TEXT_WHITE_GAMMA_THRESHOLD, property, NULL) > 0) {
+    if (property_get(PROPERTY_TEXT_WHITE_GAMMA_THRESHOLD, property, nullptr) > 0) {
         whiteThreshold = atoi(property);
     }
 #endif
@@ -393,7 +393,7 @@
         FT_Error error = FT_Init_FreeType(&mLibrary);
         if (error) {
             ALOGE("Unable to initialize freetype");
-            return NULL;
+            return nullptr;
         }
     }
 
@@ -852,7 +852,7 @@
 #ifndef ANDROID_RS_SERIALIZE
     if (mLibrary) {
         FT_Done_FreeType( mLibrary );
-        mLibrary = NULL;
+        mLibrary = nullptr;
     }
 #endif //ANDROID_RS_SERIALIZE
 }
diff --git a/rsFont.h b/rsFont.h
index 71e6fb4..bc343c1 100644
--- a/rsFont.h
+++ b/rsFont.h
@@ -74,7 +74,7 @@
     }
 
     static Font * create(Context *rsc, const char *name, float fontSize, uint32_t dpi,
-                         const void *data = NULL, uint32_t dataLen = 0);
+                         const void *data = nullptr, uint32_t dataLen = 0);
 
 protected:
 
@@ -85,8 +85,8 @@
     // Last two variables are the initial pen position
     void renderUTF(const char *text, uint32_t len, int32_t x, int32_t y,
                    uint32_t start, int32_t numGlyphs,
-                   RenderMode mode = FRAMEBUFFER, Rect *bounds = NULL,
-                   uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
+                   RenderMode mode = FRAMEBUFFER, Rect *bounds = nullptr,
+                   uint8_t *bitmap = nullptr, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
 
     void invalidateTextureCache();
     struct CachedGlyphInfo
@@ -118,7 +118,7 @@
     uint32_t mDpi;
 
     Font(Context *rsc);
-    bool init(const char *name, float fontSize, uint32_t dpi, const void *data = NULL, uint32_t dataLen = 0);
+    bool init(const char *name, float fontSize, uint32_t dpi, const void *data = nullptr, uint32_t dataLen = 0);
 
     virtual void preDestroy() const;
     FT_FaceRec_ *mFace;
@@ -149,8 +149,8 @@
     void renderText(const char *text, uint32_t len, int32_t x, int32_t y,
                     uint32_t startIndex = 0, int numGlyphs = -1,
                     Font::RenderMode mode = Font::FRAMEBUFFER,
-                    Font::Rect *bounds = NULL,
-                    uint8_t *bitmap = NULL, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
+                    Font::Rect *bounds = nullptr,
+                    uint8_t *bitmap = nullptr, uint32_t bitmapW = 0, uint32_t bitmapH = 0);
 
     void measureText(const char *text, uint32_t len, Font::Rect *bounds);
 
diff --git a/rsGrallocConsumer.cpp b/rsGrallocConsumer.cpp
index c5d37b2..ea333cc 100644
--- a/rsGrallocConsumer.cpp
+++ b/rsGrallocConsumer.cpp
@@ -87,7 +87,7 @@
         }
     }
 
-    void *bufferPointer = NULL;
+    void *bufferPointer = nullptr;
     android_ycbcr ycbcr = android_ycbcr();
 
     if (mSlots[buf].mGraphicBuffer->getPixelFormat() ==
@@ -182,7 +182,7 @@
     }
 
     mAcquiredBuffer.mSlot = BufferQueue::INVALID_BUFFER_SLOT;
-    mAcquiredBuffer.mBufferPointer = NULL;
+    mAcquiredBuffer.mBufferPointer = nullptr;
     mAcquiredBuffer.mGraphicBuffer.clear();
     return OK;
 }
diff --git a/rsGrallocConsumer.h b/rsGrallocConsumer.h
index 6f3f879..1f4daef 100644
--- a/rsGrallocConsumer.h
+++ b/rsGrallocConsumer.h
@@ -65,7 +65,7 @@
 
         AcquiredBuffer() :
                 mSlot(BufferQueue::INVALID_BUFFER_SLOT),
-                mBufferPointer(NULL) {
+                mBufferPointer(nullptr) {
         }
     };
     AcquiredBuffer mAcquiredBuffer;
diff --git a/rsMesh.cpp b/rsMesh.cpp
index 8decfc5..08d85fb 100644
--- a/rsMesh.cpp
+++ b/rsMesh.cpp
@@ -22,23 +22,23 @@
 using namespace android::renderscript;
 
 Mesh::Mesh(Context *rsc) : ObjectBase(rsc) {
-    mHal.drv = NULL;
-    mHal.state.primitives = NULL;
+    mHal.drv = nullptr;
+    mHal.state.primitives = nullptr;
     mHal.state.primitivesCount = 0;
-    mHal.state.indexBuffers = NULL;
+    mHal.state.indexBuffers = nullptr;
     mHal.state.indexBuffersCount = 0;
-    mHal.state.vertexBuffers = NULL;
+    mHal.state.vertexBuffers = nullptr;
     mHal.state.vertexBuffersCount = 0;
     mInitialized = false;
 
-    mVertexBuffers = NULL;
-    mIndexBuffers = NULL;
+    mVertexBuffers = nullptr;
+    mIndexBuffers = nullptr;
 }
 
 Mesh::Mesh(Context *rsc,
            uint32_t vertexBuffersCount,
            uint32_t primitivesCount) : ObjectBase(rsc) {
-    mHal.drv = NULL;
+    mHal.drv = nullptr;
     mHal.state.primitivesCount = primitivesCount;
     mHal.state.indexBuffersCount = primitivesCount;
     mHal.state.primitives = new RsPrimitive[mHal.state.primitivesCount];
@@ -47,12 +47,12 @@
         mHal.state.primitives[i] = RS_PRIMITIVE_POINT;
     }
     for (uint32_t i = 0; i < mHal.state.indexBuffersCount; i ++) {
-        mHal.state.indexBuffers[i] = NULL;
+        mHal.state.indexBuffers[i] = nullptr;
     }
     mHal.state.vertexBuffersCount = vertexBuffersCount;
     mHal.state.vertexBuffers = new Allocation *[mHal.state.vertexBuffersCount];
     for (uint32_t i = 0; i < mHal.state.vertexBuffersCount; i ++) {
-        mHal.state.vertexBuffers[i] = NULL;
+        mHal.state.vertexBuffers[i] = nullptr;
     }
 
     mVertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount];
@@ -108,13 +108,13 @@
     RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
     if (classID != RS_A3D_CLASS_ID_MESH) {
         ALOGE("mesh loading skipped due to invalid class id");
-        return NULL;
+        return nullptr;
     }
 
     const char *name = stream->loadString();
 
     uint32_t vertexBuffersCount = stream->loadU32();
-    ObjectBaseRef<Allocation> *vertexBuffers = NULL;
+    ObjectBaseRef<Allocation> *vertexBuffers = nullptr;
     if (vertexBuffersCount) {
         vertexBuffers = new ObjectBaseRef<Allocation>[vertexBuffersCount];
 
@@ -125,8 +125,8 @@
     }
 
     uint32_t primitivesCount = stream->loadU32();
-    ObjectBaseRef<Allocation> *indexBuffers = NULL;
-    RsPrimitive *primitives = NULL;
+    ObjectBaseRef<Allocation> *indexBuffers = nullptr;
+    RsPrimitive *primitives = nullptr;
     if (primitivesCount) {
         indexBuffers = new ObjectBaseRef<Allocation>[primitivesCount];
         primitives = new RsPrimitive[primitivesCount];
@@ -213,11 +213,11 @@
 }
 
 void Mesh::computeBBox(Context *rsc) {
-    float *posPtr = NULL;
+    float *posPtr = nullptr;
     uint32_t vectorSize = 0;
     uint32_t stride = 0;
     uint32_t numVerts = 0;
-    Allocation *posAlloc = NULL;
+    Allocation *posAlloc = nullptr;
     // First we need to find the position ptr and stride
     for (uint32_t ct=0; ct < mHal.state.vertexBuffersCount; ct++) {
         const Type *bufferType = mHal.state.vertexBuffers[ct]->getType();
diff --git a/rsMesh.h b/rsMesh.h
index 9b61ebe..c7ee088 100644
--- a/rsMesh.h
+++ b/rsMesh.h
@@ -45,7 +45,7 @@
             Allocation **vertexBuffers;
             uint32_t vertexBuffersCount;
 
-            // indexBuffers[i] could be NULL, in which case only primitives[i] is used
+            // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
             Allocation **indexBuffers;
             uint32_t indexBuffersCount;
             RsPrimitive *primitives;
diff --git a/rsMutex.cpp b/rsMutex.cpp
index 6512372..557c588 100644
--- a/rsMutex.cpp
+++ b/rsMutex.cpp
@@ -28,7 +28,7 @@
 }
 
 bool Mutex::init() {
-    int status = pthread_mutex_init(&mMutex, NULL);
+    int status = pthread_mutex_init(&mMutex, nullptr);
     if (status) {
         ALOGE("Mutex::Mutex init failure");
         return false;
diff --git a/rsObjectBase.cpp b/rsObjectBase.cpp
index 0a0961f..dc94bcc 100644
--- a/rsObjectBase.cpp
+++ b/rsObjectBase.cpp
@@ -26,10 +26,10 @@
     mUserRefCount = 0;
     mSysRefCount = 0;
     mRSC = rsc;
-    mNext = NULL;
-    mPrev = NULL;
-    mDH = NULL;
-    mName = NULL;
+    mNext = nullptr;
+    mPrev = nullptr;
+    mDH = nullptr;
+    mName = nullptr;
 
 #if RS_OBJECT_DEBUG
     mDH = new DebugHelper();
@@ -45,7 +45,7 @@
 #if RS_OBJECT_DEBUG
     mDH->dump();
     delete mDH;
-    mDH = NULL;
+    mDH = nullptr;
 #endif
 
     free(const_cast<char *>(mName));
@@ -203,8 +203,8 @@
     if (mNext) {
         mNext->mPrev = mPrev;
     }
-    mPrev = NULL;
-    mNext = NULL;
+    mPrev = nullptr;
+    mNext = nullptr;
 }
 
 void ObjectBase::zeroAllUserRef(Context *rsc) {
diff --git a/rsObjectBase.h b/rsObjectBase.h
index 66977a9..cd1b16e 100644
--- a/rsObjectBase.h
+++ b/rsObjectBase.h
@@ -96,7 +96,7 @@
 class ObjectBaseRef {
 public:
     ObjectBaseRef() {
-        mRef = NULL;
+        mRef = nullptr;
     }
 
     ObjectBaseRef(const ObjectBaseRef &ref) {
@@ -142,7 +142,7 @@
         if (mRef) {
             mRef->decSysRef();
         }
-        mRef = NULL;
+        mRef = nullptr;
     }
 
     inline T * get() const {
diff --git a/rsProgram.cpp b/rsProgram.cpp
index d5cb344..5b24c0d 100644
--- a/rsProgram.cpp
+++ b/rsProgram.cpp
@@ -103,21 +103,21 @@
     mHal.state.constantsCount = 0;
     mHal.state.texturesCount = 0;
 
-    if (mUserShader != NULL) {
+    if (mUserShader != nullptr) {
         delete[] mUserShader;
-        mUserShader = NULL;
+        mUserShader = nullptr;
     }
     mUserShaderLen = 0;
 }
 
 bool Program::freeChildren() {
     for (uint32_t ct=0; ct < mHal.state.constantsCount; ct++) {
-        bindAllocation(NULL, NULL, ct);
+        bindAllocation(nullptr, nullptr, ct);
     }
 
     for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) {
-        bindTexture(NULL, ct, NULL);
-        bindSampler(NULL, ct, NULL);
+        bindTexture(nullptr, ct, nullptr);
+        bindSampler(nullptr, ct, nullptr);
     }
     return false;
 }
@@ -125,32 +125,32 @@
 void Program::initMemberVars() {
     mDirty = true;
 
-    mHal.drv = NULL;
-    mHal.state.textures = NULL;
-    mHal.state.samplers = NULL;
-    mHal.state.textureTargets = NULL;
-    mHal.state.inputElements = NULL;
-    mHal.state.constantTypes = NULL;
-    mHal.state.constants = NULL;
+    mHal.drv = nullptr;
+    mHal.state.textures = nullptr;
+    mHal.state.samplers = nullptr;
+    mHal.state.textureTargets = nullptr;
+    mHal.state.inputElements = nullptr;
+    mHal.state.constantTypes = nullptr;
+    mHal.state.constants = nullptr;
 
     mHal.state.inputElementsCount = 0;
     mHal.state.constantsCount = 0;
     mHal.state.texturesCount = 0;
 
-    mTextures = NULL;
-    mSamplers = NULL;
-    mInputElements = NULL;
-    mConstantTypes = NULL;
-    mConstants = NULL;
+    mTextures = nullptr;
+    mSamplers = nullptr;
+    mInputElements = nullptr;
+    mConstantTypes = nullptr;
+    mConstants = nullptr;
 
     mIsInternal = false;
 
-    mUserShader = NULL;
+    mUserShader = nullptr;
     mUserShaderLen = 0;
 }
 
 void Program::bindAllocation(Context *rsc, Allocation *alloc, uint32_t slot) {
-    if (alloc != NULL) {
+    if (alloc != nullptr) {
         if (slot >= mHal.state.constantsCount) {
             ALOGE("Attempt to bind alloc at slot %u, on shader id %" PRIuPTR ", but const count is %u",
                  slot, (uintptr_t)this, mHal.state.constantsCount);
diff --git a/rsProgramFragment.cpp b/rsProgramFragment.cpp
index 360d3ab..7af6738 100644
--- a/rsProgramFragment.cpp
+++ b/rsProgramFragment.cpp
@@ -45,7 +45,7 @@
         rsc->setError(RS_ERROR_BAD_SHADER, "Cannot  set fixed function emulation color on user program");
         return;
     }
-    if (mHal.state.constants[0] == NULL) {
+    if (mHal.state.constants[0] == nullptr) {
         ALOGE("Unable to set fixed function emulation color because allocation is missing");
         rsc->setError(RS_ERROR_BAD_SHADER, "Unable to set fixed function emulation color because allocation is missing");
         return;
@@ -81,16 +81,16 @@
 }
 
 ProgramFragment *ProgramFragment::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 ProgramFragmentState::ProgramFragmentState() {
-    mPF = NULL;
+    mPF = nullptr;
 }
 
 ProgramFragmentState::~ProgramFragmentState() {
     ObjectBase::checkDelete(mPF);
-    mPF = NULL;
+    mPF = nullptr;
 }
 
 void ProgramFragmentState::init(Context *rsc) {
@@ -118,7 +118,7 @@
     Allocation *constAlloc = Allocation::createAllocation(rsc, inputType.get(),
                               RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS);
     ProgramFragment *pf = new ProgramFragment(rsc, shaderString, strlen(shaderString),
-                                              NULL, 0, NULL, tmp, 2);
+                                              nullptr, 0, nullptr, tmp, 2);
     pf->bindAllocation(rsc, constAlloc, 0);
     pf->setConstantColor(rsc, 1.0f, 1.0f, 1.0f, 1.0f);
 
diff --git a/rsProgramRaster.cpp b/rsProgramRaster.cpp
index d2d0602..d47e588 100644
--- a/rsProgramRaster.cpp
+++ b/rsProgramRaster.cpp
@@ -61,7 +61,7 @@
 }
 
 ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 ProgramRasterState::ProgramRasterState() {
diff --git a/rsProgramStore.cpp b/rsProgramStore.cpp
index b2d527e..b07f820 100644
--- a/rsProgramStore.cpp
+++ b/rsProgramStore.cpp
@@ -71,7 +71,7 @@
 }
 
 ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 void ProgramStore::init() {
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index 9c0f7fb..baf1fff 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -41,7 +41,7 @@
     }
 
     if (!isUserProgram()) {
-        if (mHal.state.constants[0] == NULL) {
+        if (mHal.state.constants[0] == nullptr) {
             rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                           "Unable to set fixed function emulation matrices because allocation is missing");
             return;
@@ -70,7 +70,7 @@
                       "Attempting to set fixed function emulation matrix projection on user program");
         return;
     }
-    if (mHal.state.constants[0] == NULL) {
+    if (mHal.state.constants[0] == nullptr) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix projection because allocation is missing");
         return;
@@ -88,7 +88,7 @@
                       "Attempting to set fixed function emulation matrix modelview on user program");
         return;
     }
-    if (mHal.state.constants[0] == NULL) {
+    if (mHal.state.constants[0] == nullptr) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix modelview because allocation is missing");
         return;
@@ -106,7 +106,7 @@
                       "Attempting to set fixed function emulation matrix texture on user program");
         return;
     }
-    if (mHal.state.constants[0] == NULL) {
+    if (mHal.state.constants[0] == nullptr) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix texture because allocation is missing");
         return;
@@ -124,7 +124,7 @@
                       "Attempting to get fixed function emulation matrix projection on user program");
         return;
     }
-    if (mHal.state.constants[0] == NULL) {
+    if (mHal.state.constants[0] == nullptr) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to get fixed function emulation matrix projection because allocation is missing");
         return;
@@ -152,7 +152,7 @@
 }
 
 ProgramVertex *ProgramVertex::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 
@@ -203,7 +203,7 @@
     tmp[3] = (uintptr_t)attrElem.get();
 
     ProgramVertex *pv = new ProgramVertex(rsc, shaderString, strlen(shaderString),
-                                          NULL, 0, NULL, tmp, 4);
+                                          nullptr, 0, nullptr, tmp, 4);
     Allocation *alloc = Allocation::createAllocation(rsc, inputType.get(),
                               RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS);
     pv->bindAllocation(rsc, alloc, 0);
diff --git a/rsSampler.cpp b/rsSampler.cpp
index 0ea9729..924ba86 100644
--- a/rsSampler.cpp
+++ b/rsSampler.cpp
@@ -76,7 +76,7 @@
 }
 
 Sampler *Sampler::createFromStream(Context *rsc, IStream *stream) {
-    return NULL;
+    return nullptr;
 }
 
 ObjectBaseRef<Sampler> Sampler::getSampler(Context *rsc,
@@ -105,7 +105,7 @@
     void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Sampler), 0);
     if (!allocMem) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation");
-        return NULL;
+        return nullptr;
     }
 
     Sampler *s = new (allocMem) Sampler(rsc, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
diff --git a/rsScript.cpp b/rsScript.cpp
index a4fa196..3059833 100644
--- a/rsScript.cpp
+++ b/rsScript.cpp
@@ -24,8 +24,8 @@
     memset(&mEnviroment, 0, sizeof(mEnviroment));
     memset(&mHal, 0, sizeof(mHal));
 
-    mSlots = NULL;
-    mTypes = NULL;
+    mSlots = nullptr;
+    mTypes = nullptr;
     mInitialized = false;
     mHasObjectSlots = false;
 }
@@ -33,11 +33,11 @@
 Script::~Script() {
     if (mSlots) {
         delete [] mSlots;
-        mSlots = NULL;
+        mSlots = nullptr;
     }
     if (mTypes) {
         delete [] mTypes;
-        mTypes = NULL;
+        mTypes = nullptr;
     }
 }
 
@@ -95,7 +95,7 @@
 }
 
 void Script::callUpdateCacheObject(const Context *rsc, void *dstObj) const {
-    if (rsc->mHal.funcs.script.updateCachedObject != NULL) {
+    if (rsc->mHal.funcs.script.updateCachedObject != nullptr) {
         rsc->mHal.funcs.script.updateCachedObject(rsc, this, (rs_script *)dstObj);
     } else {
         *((const void **)dstObj) = this;
@@ -170,7 +170,7 @@
 
 void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
     // We unfortunately need to make a new copy of the string, since it is
-    // not NULL-terminated. We then use setenv(), which properly handles
+    // not nullptr-terminated. We then use setenv(), which properly handles
     // freeing/duplicating the actual string for the environment.
     char *tz = (char *) malloc(length + 1);
     if (!tz) {
@@ -207,8 +207,8 @@
                        const void *params, size_t paramLen,
                        const RsScriptCall *sc, size_t scLen) {
 
-    if (vain == NULL) {
-        rsi_ScriptForEachMulti(rsc, vs, slot, NULL, 0, vaout, params, paramLen,
+    if (vain == nullptr) {
+        rsi_ScriptForEachMulti(rsc, vs, slot, nullptr, 0, vaout, params, paramLen,
                                sc, scLen);
     } else {
         RsAllocation ains[1] = {vain};
@@ -221,13 +221,13 @@
 
 void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
     Script *s = static_cast<Script *>(vs);
-    s->Invoke(rsc, slot, NULL, 0);
+    s->Invoke(rsc, slot, nullptr, 0);
 }
 
 
 void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
     Script *s = static_cast<Script *>(vs);
-    s->Invoke(rsc, slot, NULL, 0);
+    s->Invoke(rsc, slot, nullptr, 0);
 }
 
 void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
diff --git a/rsScript.h b/rsScript.h
index 2e232f0..1172dea 100644
--- a/rsScript.h
+++ b/rsScript.h
@@ -115,7 +115,7 @@
                             Allocation* aout,
                             const void* usr,
                             size_t usrBytes,
-                            const RsScriptCall *sc = NULL) = 0;
+                            const RsScriptCall *sc = nullptr) = 0;
 
     virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
     virtual void setupScript(Context *rsc) = 0;
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 96a771f..6255b44 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -54,7 +54,7 @@
 
 ScriptC::ScriptC(Context *rsc) : Script(rsc) {
 #if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
-    BT = NULL;
+    BT = nullptr;
 #endif
 }
 
@@ -62,7 +62,7 @@
 #if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
     if (BT) {
         delete BT;
-        BT = NULL;
+        BT = nullptr;
     }
 #endif
     if (mInitialized) {
@@ -160,7 +160,7 @@
 }
 
 uint32_t ScriptC::run(Context *rsc) {
-    if (mHal.info.root == NULL) {
+    if (mHal.info.root == nullptr) {
         rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
         return 0;
     }
@@ -195,7 +195,7 @@
     // Trace this function call.
     // To avoid overhead we only build the string if tracing is actually
     // enabled.
-    std::string *traceString = NULL;
+    std::string *traceString = nullptr;
     const char  *stringData  = "";
     if (ATRACE_ENABLED()) {
         traceString = new std::string("runForEach_");
@@ -209,7 +209,7 @@
     setupGLState(rsc);
     setupScript(rsc);
 
-    if (rsc->mHal.funcs.script.invokeForEachMulti != NULL) {
+    if (rsc->mHal.funcs.script.invokeForEachMulti != nullptr) {
         rsc->mHal.funcs.script.invokeForEachMulti(rsc, this, slot, ains, inLen,
                                                   aout, usr, usrBytes, sc);
 
@@ -276,7 +276,7 @@
     if (!BT->translate()) {
         ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
         delete BT;
-        BT = NULL;
+        BT = nullptr;
         return false;
     }
     bitcode = (const uint8_t *) BT->getTranslatedBitcode();
@@ -392,7 +392,7 @@
     if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
         // Error during compile, destroy s and return null.
         ObjectBase::checkDelete(s);
-        return NULL;
+        return nullptr;
     }
 
     s->incUserRef();
diff --git a/rsScriptC.h b/rsScriptC.h
index 5735bea..86de5b2 100644
--- a/rsScriptC.h
+++ b/rsScriptC.h
@@ -49,11 +49,11 @@
                             Allocation * aout,
                             const void * usr,
                             size_t usrBytes,
-                            const RsScriptCall *sc = NULL);
+                            const RsScriptCall *sc = nullptr);
 
     virtual void serialize(Context *rsc, OStream *stream) const {    }
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
-    static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
+    static Type *createFromStream(Context *rsc, IStream *stream) { return nullptr; }
 
     bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
                      const uint8_t *bitcode, size_t bitcodeLen);
diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp
index cacb37a..4bb0b1c 100644
--- a/rsScriptC_Lib.cpp
+++ b/rsScriptC_Lib.cpp
@@ -87,7 +87,7 @@
 
 tm* rsrLocalTime(Context *rsc, tm *local, time_t *timer) {
     if (!local) {
-      return NULL;
+      return nullptr;
     }
 
     // The native localtime function is not thread-safe, so we
@@ -151,7 +151,7 @@
     ObjectBase **odst = (ObjectBase **)dst;
     //ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
     SetObjectRef(rsc, odst[0], src);
-    if (src != NULL) {
+    if (src != nullptr) {
         src->callUpdateCacheObject(rsc, dst);
     }
 }
@@ -160,7 +160,7 @@
     ObjectBase **odst = (ObjectBase **)dst;
     //ALOGE("rsrSetObject (base) %p,%p  %p", dst, *odst, src);
     SetObjectRef(rsc, odst[0], src);
-    if (src != NULL) {
+    if (src != nullptr) {
         src->callUpdateCacheObject(rsc, dst);
     }
 }
@@ -173,7 +173,7 @@
         CHECK_OBJ(odst[0]);
         odst[0]->decSysRef();
     }
-    *odst = NULL;
+    *odst = nullptr;
 }
 
 void rsrClearObject(const Context *rsc, rs_object_base *dst) {
@@ -182,17 +182,17 @@
         CHECK_OBJ(dst->p);
         dst->p->decSysRef();
     }
-    dst->p = NULL;
+    dst->p = nullptr;
 }
 
 // Legacy, remove when drivers are updated
 bool rsrIsObject(const Context *, ObjectBase* src) {
     ObjectBase **osrc = (ObjectBase **)src;
-    return osrc != NULL;
+    return osrc != nullptr;
 }
 
 bool rsrIsObject(const Context *rsc, rs_object_base o) {
-    return o.p != NULL;
+    return o.p != nullptr;
 }
 
 
@@ -231,8 +231,8 @@
                 const void *usr, uint32_t usrBytes,
                 const RsScriptCall *call) {
 
-    if (in == NULL) {
-        target->runForEach(rsc, /* root slot */ 0, NULL, 0, out, usr,
+    if (in == nullptr) {
+        target->runForEach(rsc, /* root slot */ 0, nullptr, 0, out, usr,
                            usrBytes, call);
 
     } else {
diff --git a/rsScriptC_LibGL.cpp b/rsScriptC_LibGL.cpp
index dbf2336..5c55c6b 100644
--- a/rsScriptC_LibGL.cpp
+++ b/rsScriptC_LibGL.cpp
@@ -103,12 +103,12 @@
 }
 
 void rsrClearFrameBufferObjectColorTarget(Context *rsc, uint32_t slot) {
-    rsc->mFBOCache.bindColorTarget(rsc, NULL, slot);
+    rsc->mFBOCache.bindColorTarget(rsc, nullptr, slot);
     rsc->mStateVertex.updateSize(rsc);
 }
 
 void rsrClearFrameBufferObjectDepthTarget(Context *rsc) {
-    rsc->mFBOCache.bindDepthTarget(rsc, NULL);
+    rsc->mFBOCache.bindDepthTarget(rsc, nullptr);
     rsc->mStateVertex.updateSize(rsc);
 }
 
diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp
index f41c65d..618c28c 100644
--- a/rsScriptGroup.cpp
+++ b/rsScriptGroup.cpp
@@ -54,7 +54,7 @@
         }
     }
 
-    return NULL;
+    return nullptr;
 }
 
 bool ScriptGroup::calcOrderRecurse(Node *node0, int depth) {
@@ -65,7 +65,7 @@
     bool ret = true;
 
     for (auto link : node0->mOutputs) {
-        Node *node1 = NULL;
+        Node *node1 = nullptr;
         if (link->mDstField.get()) {
             node1 = findNode(link->mDstField->mScript);
         } else {
@@ -86,7 +86,7 @@
     for (auto kernelRef : mKernels) {
         const ScriptKernelID *kernel = kernelRef.get();
         Node *node = findNode(kernel->mScript);
-        if (node == NULL) {
+        if (node == nullptr) {
             node = new Node(kernel->mScript);
             mNodes.push_back(node);
         }
@@ -253,14 +253,14 @@
 
 bool ScriptGroup::validateInputAndOutput(Context *rsc) {
     for(size_t i = 0; i < mInputs.size(); i++) {
-        if (mInputs[i]->mAlloc.get() == NULL) {
+        if (mInputs[i]->mAlloc.get() == nullptr) {
             rsc->setError(RS_ERROR_BAD_VALUE, "ScriptGroup missing input.");
             return false;
         }
     }
 
     for(size_t i = 0; i < mOutputs.size(); i++) {
-        if (mOutputs[i]->mAlloc.get() == NULL) {
+        if (mOutputs[i]->mAlloc.get() == nullptr) {
             rsc->setError(RS_ERROR_BAD_VALUE, "ScriptGroup missing output.");
             return false;
         }
@@ -283,8 +283,8 @@
 
     for (auto node : mNodes) {
         for (auto kernel : node->mKernels) {
-            Allocation *ain  = NULL;
-            Allocation *aout = NULL;
+            Allocation *ain  = nullptr;
+            Allocation *aout = nullptr;
 
             for (auto nodeInput : node->mInputs) {
                 if (nodeInput->mDstKernel.get() == kernel) {
@@ -310,14 +310,14 @@
                 }
             }
 
-            if (ain == NULL) {
-                node->mScript->runForEach(rsc, kernel->mSlot, NULL, 0, aout,
-                                          NULL, 0);
+            if (ain == nullptr) {
+                node->mScript->runForEach(rsc, kernel->mSlot, nullptr, 0, aout,
+                                          nullptr, 0);
             } else {
                 const Allocation *ains[1] = {ain};
                 node->mScript->runForEach(rsc, kernel->mSlot, ains,
                                           sizeof(ains) / sizeof(RsAllocation),
-                                          aout, NULL, 0);
+                                          aout, nullptr, 0);
             }
         }
     }
diff --git a/rsScriptIntrinsic.cpp b/rsScriptIntrinsic.cpp
index 7461d34..ee9d73c 100644
--- a/rsScriptIntrinsic.cpp
+++ b/rsScriptIntrinsic.cpp
@@ -64,7 +64,7 @@
                          size_t usrBytes,
                          const RsScriptCall* sc) {
 
-    if (rsc->mHal.funcs.script.invokeForEachMulti != NULL) {
+    if (rsc->mHal.funcs.script.invokeForEachMulti != nullptr) {
         rsc->mHal.funcs.script.invokeForEachMulti(rsc, this, slot, ains, inLen,
                                                   aout, usr, usrBytes, sc);
 
@@ -98,7 +98,7 @@
     ScriptIntrinsic *si = new ScriptIntrinsic(rsc);
     if (!si->init(rsc, (RsScriptIntrinsicID)id, (Element *)ve)) {
         delete si;
-        return NULL;
+        return nullptr;
     }
     si->incUserRef();
     return si;
diff --git a/rsScriptIntrinsic.h b/rsScriptIntrinsic.h
index 87b7353..ac49325 100644
--- a/rsScriptIntrinsic.h
+++ b/rsScriptIntrinsic.h
@@ -47,7 +47,7 @@
                             Allocation* aout,
                             const void* usr,
                             size_t usrBytes,
-                            const RsScriptCall* sc = NULL);
+                            const RsScriptCall* sc = nullptr);
 
     virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
     virtual void setupScript(Context *rsc);
diff --git a/rsSignal.cpp b/rsSignal.cpp
index 658c0b7..bf25384 100644
--- a/rsSignal.cpp
+++ b/rsSignal.cpp
@@ -31,13 +31,13 @@
 }
 
 bool Signal::init() {
-    int status = pthread_mutex_init(&mMutex, NULL);
+    int status = pthread_mutex_init(&mMutex, nullptr);
     if (status) {
         ALOGE("LocklessFifo mutex init failure");
         return false;
     }
 
-    status = pthread_cond_init(&mCondition, NULL);
+    status = pthread_cond_init(&mCondition, nullptr);
     if (status) {
         ALOGE("LocklessFifo condition init failure");
         pthread_mutex_destroy(&mMutex);
diff --git a/rsThreadIO.cpp b/rsThreadIO.cpp
index 8a0a5dc..87ecdf2 100644
--- a/rsThreadIO.cpp
+++ b/rsThreadIO.cpp
@@ -79,7 +79,7 @@
 
 void ThreadIO::coreSetReturn(const void *data, size_t dataLen) {
     uint32_t buf;
-    if (data == NULL) {
+    if (data == nullptr) {
         data = &buf;
         dataLen = sizeof(buf);
     }
@@ -89,7 +89,7 @@
 
 void ThreadIO::coreGetReturn(void *data, size_t dataLen) {
     uint32_t buf;
-    if (data == NULL) {
+    if (data == nullptr) {
         data = &buf;
         dataLen = sizeof(buf);
     }
diff --git a/rsType.cpp b/rsType.cpp
index ba57617..d9d97b0 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -175,14 +175,14 @@
     RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
     if (classID != RS_A3D_CLASS_ID_TYPE) {
         ALOGE("type loading skipped due to invalid class id\n");
-        return NULL;
+        return nullptr;
     }
 
     const char *name = stream->loadString();
 
     Element *elem = Element::createFromStream(rsc, stream);
     if (!elem) {
-        return NULL;
+        return nullptr;
     }
 
     uint32_t x = stream->loadU32();
@@ -241,7 +241,7 @@
     void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Type), 0);
     if (!allocMem) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Type");
-        return NULL;
+        return nullptr;
     }
 
     Type *nt = new (allocMem) Type(rsc);
@@ -312,7 +312,7 @@
 }
 
 void Type::callUpdateCacheObject(const Context *rsc, void *dstObj) const {
-    if (rsc->mHal.funcs.type.updateCachedObject != NULL) {
+    if (rsc->mHal.funcs.type.updateCachedObject != nullptr) {
         rsc->mHal.funcs.type.updateCachedObject(rsc, this, (rs_type *)dstObj);
     } else {
         *((const void **)dstObj) = this;
diff --git a/server/RefBase.h b/server/RefBase.h
index e1e5007..81744a1 100644
--- a/server/RefBase.h
+++ b/server/RefBase.h
@@ -199,7 +199,7 @@
 public:
     typedef typename RefBase::weakref_type weakref_type;
 
-    inline wp() : m_ptr(0) { }
+    inline wp() : m_ptr(nullptr) { }
 
     wp(T* other);
     wp(const wp<T>& other);
@@ -350,7 +350,7 @@
 wp<T>& wp<T>::operator = (T* other)
 {
     weakref_type* newRefs =
-        other ? other->createWeak(this) : 0;
+        other ? other->createWeak(this) : nullptr;
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = other;
     m_refs = newRefs;
@@ -373,7 +373,7 @@
 wp<T>& wp<T>::operator = (const sp<T>& other)
 {
     weakref_type* newRefs =
-        other != NULL ? other->createWeak(this) : 0;
+        other != nullptr ? other->createWeak(this) : nullptr;
     T* otherPtr(other.m_ptr);
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = otherPtr;
@@ -385,7 +385,7 @@
 wp<T>& wp<T>::operator = (U* other)
 {
     weakref_type* newRefs =
-        other ? other->createWeak(this) : 0;
+        other ? other->createWeak(this) : nullptr;
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = other;
     m_refs = newRefs;
@@ -408,7 +408,7 @@
 wp<T>& wp<T>::operator = (const sp<U>& other)
 {
     weakref_type* newRefs =
-        other != NULL ? other->createWeak(this) : 0;
+        other != nullptr ? other->createWeak(this) : nullptr;
     U* otherPtr(other.m_ptr);
     if (m_ptr) m_refs->decWeak(this);
     m_ptr = otherPtr;
@@ -440,7 +440,7 @@
 {
     if (m_ptr) {
         m_refs->decWeak(this);
-        m_ptr = 0;
+        m_ptr = nullptr;
     }
 }
 
diff --git a/tests/cppallocation/Android.mk b/tests/cppallocation/Android.mk
index 2e46c9e..36ea7cb 100644
--- a/tests/cppallocation/Android.mk
+++ b/tests/cppallocation/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS += -llog -ldl
 
 LOCAL_MODULE:= rstest-cppallocation
diff --git a/tests/cppbasic-getpointer/Android.mk b/tests/cppbasic-getpointer/Android.mk
index eb4ac34..b2222c6 100644
--- a/tests/cppbasic-getpointer/Android.mk
+++ b/tests/cppbasic-getpointer/Android.mk
@@ -15,6 +15,8 @@
 
 intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
 
+LOCAL_CFLAGS := -std=c++11
+
 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
 LOCAL_C_INCLUDES += frameworks/rs/cpp
 LOCAL_C_INCLUDES += frameworks/rs
diff --git a/tests/cppbasic-shared/Android.mk b/tests/cppbasic-shared/Android.mk
index 63cd715..34826a0 100644
--- a/tests/cppbasic-shared/Android.mk
+++ b/tests/cppbasic-shared/Android.mk
@@ -15,6 +15,8 @@
 
 intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
 
+LOCAL_CFLAGS := -std=c++11
+
 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
 LOCAL_C_INCLUDES += frameworks/rs/cpp
 LOCAL_C_INCLUDES += frameworks/rs
diff --git a/tests/cppbasic-shared/compute.cpp b/tests/cppbasic-shared/compute.cpp
index d93b453..6741d7a 100644
--- a/tests/cppbasic-shared/compute.cpp
+++ b/tests/cppbasic-shared/compute.cpp
@@ -42,7 +42,7 @@
         sc->set_elem(e);
         sc->set_type(t);
         sc->set_script(sc);
-        sc->set_script(NULL);
+        sc->set_script(nullptr);
         sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
         sc->set_sampler(samp);
 
diff --git a/tests/cppbasic/Android.mk b/tests/cppbasic/Android.mk
index d4f7441..9e24dca 100644
--- a/tests/cppbasic/Android.mk
+++ b/tests/cppbasic/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS += -llog -ldl
 
 LOCAL_MODULE:= rstest-compute
diff --git a/tests/cppbasic/compute.cpp b/tests/cppbasic/compute.cpp
index d93b453..6741d7a 100644
--- a/tests/cppbasic/compute.cpp
+++ b/tests/cppbasic/compute.cpp
@@ -42,7 +42,7 @@
         sc->set_elem(e);
         sc->set_type(t);
         sc->set_script(sc);
-        sc->set_script(NULL);
+        sc->set_script(nullptr);
         sp<const Sampler> samp = Sampler::CLAMP_NEAREST(rs);
         sc->set_sampler(samp);
 
diff --git a/tests/cppstrided/Android.mk b/tests/cppstrided/Android.mk
index 9fb98a6..253a104 100644
--- a/tests/cppstrided/Android.mk
+++ b/tests/cppstrided/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS += -llog -ldl
 
 LOCAL_MODULE:= rstest-cppstrided
diff --git a/tests/latency/Android.mk b/tests/latency/Android.mk
index fdfa208..5200e5d 100644
--- a/tests/latency/Android.mk
+++ b/tests/latency/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS += -llog -ldl
 
 LOCAL_MODULE:= rstest-latency
diff --git a/tests/latency/latency.cpp b/tests/latency/latency.cpp
index 05337be..274a518 100644
--- a/tests/latency/latency.cpp
+++ b/tests/latency/latency.cpp
@@ -74,7 +74,7 @@
 
     struct timeval start, stop;
 
-    gettimeofday(&start, NULL);
+    gettimeofday(&start, nullptr);
 
     for (int i = 0; i < iters; i++) {
         sc->forEach_root(ain, aout);
@@ -82,13 +82,13 @@
 
     rs->finish();
 
-    gettimeofday(&stop, NULL);
+    gettimeofday(&stop, nullptr);
 
     long long elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
     printf("elapsed time : %lld microseconds\n", elapsed);
     printf("time per iter: %f microseconds\n", (double)elapsed / iters);
 
-    gettimeofday(&start, NULL);
+    gettimeofday(&start, nullptr);
 
     for (int i = 0; i < iters; i++) {
         ain->copy1DFrom(buf);
@@ -98,7 +98,7 @@
 
     rs->finish();
 
-    gettimeofday(&stop, NULL);
+    gettimeofday(&stop, nullptr);
     elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
     printf("elapsed time with copy : %lld microseconds\n", elapsed);
     printf("time per iter with copy: %f microseconds\n", (double)elapsed / iters);
diff --git a/tests/typecheck/Android.mk b/tests/typecheck/Android.mk
index c34e3e2..f63684e 100644
--- a/tests/typecheck/Android.mk
+++ b/tests/typecheck/Android.mk
@@ -11,6 +11,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
+LOCAL_CFLAGS := -std=c++11
 LOCAL_LDFLAGS += -llog -ldl
 
 LOCAL_MODULE:= rstest-typecheck