Replace NULL macros with nullptr literals.

Change-Id: I918c40879aa547438f77e7d1a95fa2aa33bec398
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;