Replace reinterpret_cast with safer or no cast

When casting types to one another in C++, the weaker the cast,
the better.

This change replaces instances of reinterpret_cast with static_cast
or no cast where it safe and correct to do so.

BUG=angleproject:2683

Change-Id: I99c9033614a65282ae1d78cf0f4b80fabd75877a
Reviewed-on: https://chromium-review.googlesource.com/1109396
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/DeviceD3D.cpp b/src/libANGLE/renderer/d3d/DeviceD3D.cpp
index 7d3d004..cfc0dec 100644
--- a/src/libANGLE/renderer/d3d/DeviceD3D.cpp
+++ b/src/libANGLE/renderer/d3d/DeviceD3D.cpp
@@ -28,7 +28,7 @@
     if (mIsInitialized && mDeviceType == EGL_D3D11_DEVICE_ANGLE)
     {
         // DeviceD3D holds a ref to an externally-sourced D3D11 device. We must release it.
-        ID3D11Device *device = reinterpret_cast<ID3D11Device *>(mDevice);
+        ID3D11Device *device = static_cast<ID3D11Device *>(mDevice);
         device->Release();
     }
 #endif
@@ -49,7 +49,7 @@
     if (mDeviceType == EGL_D3D11_DEVICE_ANGLE)
     {
         // Validate the device
-        IUnknown *iunknown = reinterpret_cast<IUnknown *>(mDevice);
+        IUnknown *iunknown = static_cast<IUnknown *>(mDevice);
 
         ID3D11Device *d3dDevice = nullptr;
         HRESULT hr =
diff --git a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
index 1aca71b..53274ae 100644
--- a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
+++ b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
@@ -270,7 +270,7 @@
         (area.x - origArea.x) * sizedFormatInfo.pixelBytes + (area.y - origArea.y) * outputPitch;
 
     return readPixelsImpl(context, area, format, type, outputPitch, packState,
-                          reinterpret_cast<uint8_t *>(pixels) + outputSkipBytes);
+                          static_cast<uint8_t *>(pixels) + outputSkipBytes);
 }
 
 gl::Error FramebufferD3D::blit(const gl::Context *context,
diff --git a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
index b387650..db0bffb 100644
--- a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
+++ b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp
@@ -217,7 +217,7 @@
 
         if (errorMessage)
         {
-            std::string message = reinterpret_cast<const char*>(errorMessage->GetBufferPointer());
+            std::string message = static_cast<const char *>(errorMessage->GetBufferPointer());
             SafeRelease(errorMessage);
 
             infoLog.appendSanitized(message.c_str());
@@ -314,7 +314,7 @@
 
     if (SUCCEEDED(result))
     {
-        *disassemblyOut = std::string(reinterpret_cast<const char*>(disassembly->GetBufferPointer()));
+        *disassemblyOut = std::string(static_cast<const char *>(disassembly->GetBufferPointer()));
     }
     else
     {
diff --git a/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp b/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
index bcc85e0..59b0e94 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp
@@ -1134,7 +1134,7 @@
     ANGLE_TRY(
         mRenderer->mapResource(mSwizzleCB.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));
 
-    unsigned int *swizzleIndices = reinterpret_cast<unsigned int *>(mappedResource.pData);
+    unsigned int *swizzleIndices = static_cast<unsigned int *>(mappedResource.pData);
     swizzleIndices[0]            = GetSwizzleIndex(swizzleTarget.swizzleRed);
     swizzleIndices[1]            = GetSwizzleIndex(swizzleTarget.swizzleGreen);
     swizzleIndices[2]            = GetSwizzleIndex(swizzleTarget.swizzleBlue);
diff --git a/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp b/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
index a8a3407..80110c9 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
@@ -718,8 +718,7 @@
     switch (clearParams.colorType)
     {
         case GL_FLOAT:
-            dirtyCb = UpdateDataCache(reinterpret_cast<RtvDsvClearInfo<float> *>(&mShaderData),
-                                      clearParams.colorF, zValue, numRtvs, colorMask);
+            dirtyCb = UpdateDataCache(&mShaderData, clearParams.colorF, zValue, numRtvs, colorMask);
             break;
         case GL_UNSIGNED_INT:
             dirtyCb = UpdateDataCache(reinterpret_cast<RtvDsvClearInfo<uint32_t> *>(&mShaderData),
diff --git a/src/libANGLE/renderer/d3d/d3d11/Image11.cpp b/src/libANGLE/renderer/d3d/d3d11/Image11.cpp
index e3281eb..b2073f0 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Image11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Image11.cpp
@@ -62,8 +62,8 @@
         return error;
     }
 
-    const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(srcMapped.pData);
-    uint8_t *destData         = reinterpret_cast<uint8_t *>(destMapped.pData);
+    const uint8_t *sourceData = static_cast<const uint8_t *>(srcMapped.pData);
+    uint8_t *destData         = static_cast<uint8_t *>(destMapped.pData);
 
     auto mipGenerationFunction =
         d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format().mipGenerationFunction;
@@ -112,10 +112,10 @@
         gl::GetSizedInternalFormatInfo(destFormat.fboImplementationInternalFormat);
     GLuint destPixelBytes = destFormatInfo.pixelBytes;
 
-    const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(srcMapped.pData) +
+    const uint8_t *sourceData = static_cast<const uint8_t *>(srcMapped.pData) +
                                 sourceRect.x * sourcePixelBytes + sourceRect.y * srcMapped.RowPitch;
-    uint8_t *destData = reinterpret_cast<uint8_t *>(destMapped.pData) +
-                        destOffset.x * destPixelBytes + destOffset.y * destMapped.RowPitch;
+    uint8_t *destData = static_cast<uint8_t *>(destMapped.pData) + destOffset.x * destPixelBytes +
+                        destOffset.y * destMapped.RowPitch;
 
     CopyImageCHROMIUM(sourceData, srcMapped.RowPitch, sourcePixelBytes,
                       sourceFormat.colorReadFunction, destData, destMapped.RowPitch, destPixelBytes,
@@ -304,11 +304,11 @@
     D3D11_MAPPED_SUBRESOURCE mappedImage;
     ANGLE_TRY(map(context, D3D11_MAP_WRITE, &mappedImage));
 
-    uint8_t *offsetMappedData = (reinterpret_cast<uint8_t *>(mappedImage.pData) +
+    uint8_t *offsetMappedData = (static_cast<uint8_t *>(mappedImage.pData) +
                                  (area.y * mappedImage.RowPitch + area.x * outputPixelSize +
                                   area.z * mappedImage.DepthPitch));
     loadFunction(area.width, area.height, area.depth,
-                 reinterpret_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch,
+                 static_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch,
                  inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
 
     unmap();
@@ -343,11 +343,11 @@
     ANGLE_TRY(map(context, D3D11_MAP_WRITE, &mappedImage));
 
     uint8_t *offsetMappedData =
-        reinterpret_cast<uint8_t *>(mappedImage.pData) +
+        static_cast<uint8_t *>(mappedImage.pData) +
         ((area.y / outputBlockHeight) * mappedImage.RowPitch +
          (area.x / outputBlockWidth) * outputPixelSize + area.z * mappedImage.DepthPitch);
 
-    loadFunction(area.width, area.height, area.depth, reinterpret_cast<const uint8_t *>(input),
+    loadFunction(area.width, area.height, area.depth, static_cast<const uint8_t *>(input),
                  inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch,
                  mappedImage.DepthPitch);
 
diff --git a/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp b/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp
index cde2b51..d520469 100644
--- a/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/IndexBuffer11.cpp
@@ -75,7 +75,7 @@
     ANGLE_TRY(
         mRenderer->mapResource(mBuffer.get(), 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource));
 
-    *outMappedMemory = reinterpret_cast<char*>(mappedResource.pData) + offset;
+    *outMappedMemory = static_cast<char *>(mappedResource.pData) + offset;
     return gl::NoError();
 }
 
diff --git a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
index d4b7a9f..4a41a4f 100644
--- a/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
@@ -807,7 +807,7 @@
         void *device = nullptr;
         ANGLE_TRY(deviceD3D->getDevice(&device));
 
-        ID3D11Device *d3dDevice = reinterpret_cast<ID3D11Device *>(device);
+        ID3D11Device *d3dDevice = static_cast<ID3D11Device *>(device);
         if (FAILED(d3dDevice->GetDeviceRemovedReason()))
         {
             return egl::EglNotInitialized() << "Inputted D3D11 device has been lost.";
@@ -1400,7 +1400,7 @@
 
 void *Renderer11::getD3DDevice()
 {
-    return reinterpret_cast<void *>(mDevice);
+    return mDevice;
 }
 
 gl::Error Renderer11::drawWithGeometryShaderAndTransformFeedback(const gl::Context *context,
@@ -2792,7 +2792,7 @@
         return gl::NoError();
     }
 
-    gl::Error error = loadExecutable(reinterpret_cast<const uint8_t *>(binary->GetBufferPointer()),
+    gl::Error error = loadExecutable(static_cast<const uint8_t *>(binary->GetBufferPointer()),
                                      binary->GetBufferSize(), type, streamOutVaryings,
                                      separatedOutputBuffers, outExectuable);
 
diff --git a/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp b/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
index e9c3bea..ac9a1be 100644
--- a/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/StateManager11.cpp
@@ -518,7 +518,7 @@
         renderer->mapResource(driverConstantBuffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapping));
 
     memcpy(mapping.pData, data, dataSize);
-    memcpy(reinterpret_cast<uint8_t *>(mapping.pData) + dataSize, samplerData,
+    memcpy(static_cast<uint8_t *>(mapping.pData) + dataSize, samplerData,
            sizeof(SamplerMetadata) * numSamplers);
 
     renderer->getDeviceContext()->Unmap(driverConstantBuffer.get(), 0);
diff --git a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
index 3649cbe..441baa1 100644
--- a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
@@ -75,7 +75,7 @@
         ANGLE_TRY(mRenderer->mapResource(mBuffer.get(), 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0,
                                          &mappedResource));
 
-        mMappedResourceData = reinterpret_cast<uint8_t *>(mappedResource.pData);
+        mMappedResourceData = static_cast<uint8_t *>(mappedResource.pData);
     }
 
     return gl::NoError();
diff --git a/src/libANGLE/renderer/d3d/d3d9/Framebuffer9.cpp b/src/libANGLE/renderer/d3d/d3d9/Framebuffer9.cpp
index 3f7db02..28d29b6 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Framebuffer9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/Framebuffer9.cpp
@@ -184,7 +184,7 @@
         return gl::OutOfMemory() << "Failed to lock internal render target.";
     }
 
-    uint8_t *source = reinterpret_cast<uint8_t *>(lock.pBits);
+    uint8_t *source = static_cast<uint8_t *>(lock.pBits);
     int inputPitch  = lock.Pitch;
 
     const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
diff --git a/src/libANGLE/renderer/d3d/d3d9/Image9.cpp b/src/libANGLE/renderer/d3d/d3d9/Image9.cpp
index 817a40a..bf2cf72 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Image9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/Image9.cpp
@@ -87,8 +87,8 @@
                                  << gl::FmtHR(result);
     }
 
-    const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(sourceLocked.pBits);
-    uint8_t *destData = reinterpret_cast<uint8_t*>(destLocked.pBits);
+    const uint8_t *sourceData = static_cast<const uint8_t *>(sourceLocked.pBits);
+    uint8_t *destData         = static_cast<uint8_t *>(destLocked.pBits);
 
     ASSERT(sourceData && destData);
 
@@ -217,10 +217,10 @@
                                  << gl::FmtHR(result);
     }
 
-    const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(sourceLocked.pBits) +
+    const uint8_t *sourceData = static_cast<const uint8_t *>(sourceLocked.pBits) +
                                 sourceRect.x * sourceD3DFormatInfo.pixelBytes +
                                 sourceRect.y * sourceLocked.Pitch;
-    uint8_t *destData = reinterpret_cast<uint8_t *>(destLocked.pBits) +
+    uint8_t *destData = static_cast<uint8_t *>(destLocked.pBits) +
                         destOffset.x * destD3DFormatInfo.pixelBytes +
                         destOffset.y * destLocked.Pitch;
     ASSERT(sourceData && destData);
@@ -325,8 +325,8 @@
                 return gl::OutOfMemory() << "Failed to lock image surface, " << gl::FmtHR(result);
             }
 
-            d3dFormatInfo.dataInitializerFunction(mWidth, mHeight, 1, reinterpret_cast<uint8_t*>(lockedRect.pBits),
-                                                  lockedRect.Pitch, 0);
+            d3dFormatInfo.dataInitializerFunction(
+                mWidth, mHeight, 1, static_cast<uint8_t *>(lockedRect.pBits), lockedRect.Pitch, 0);
 
             result = newSurface->UnlockRect();
             ASSERT(SUCCEEDED(result));
@@ -579,8 +579,8 @@
     }
 
     d3dFormatInfo.loadFunction(area.width, area.height, area.depth,
-                               reinterpret_cast<const uint8_t *>(input), inputRowPitch, 0,
-                               reinterpret_cast<uint8_t *>(locked.pBits), locked.Pitch, 0);
+                               static_cast<const uint8_t *>(input), inputRowPitch, 0,
+                               static_cast<uint8_t *>(locked.pBits), locked.Pitch, 0);
 
     unlock();
 
@@ -622,8 +622,8 @@
     }
 
     d3d9FormatInfo.loadFunction(area.width, area.height, area.depth,
-                                reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch,
-                                reinterpret_cast<uint8_t*>(locked.pBits), locked.Pitch, 0);
+                                static_cast<const uint8_t *>(input), inputRowPitch, inputDepthPitch,
+                                static_cast<uint8_t *>(locked.pBits), locked.Pitch, 0);
 
     unlock();
 
diff --git a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
index e39e57f..1b72e26 100644
--- a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
@@ -837,7 +837,7 @@
 
 void *Renderer9::getD3DDevice()
 {
-    return reinterpret_cast<void *>(mDevice);
+    return mDevice;
 }
 
 gl::Error Renderer9::allocateEventQuery(IDirect3DQuery9 **outQuery)
@@ -1506,7 +1506,7 @@
         }
 
         startIndex         = static_cast<unsigned int>(offset) / 4;
-        unsigned int *data = reinterpret_cast<unsigned int *>(mappedMemory);
+        unsigned int *data = static_cast<unsigned int *>(mappedMemory);
 
         switch (type)
         {
@@ -1589,7 +1589,7 @@
         }
 
         startIndex           = static_cast<unsigned int>(offset) / 2;
-        unsigned short *data = reinterpret_cast<unsigned short *>(mappedMemory);
+        unsigned short *data = static_cast<unsigned short *>(mappedMemory);
 
         switch (type)
         {
@@ -1716,7 +1716,7 @@
             void *mappedMemory = nullptr;
             ANGLE_TRY(mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, nullptr));
 
-            unsigned short *data = reinterpret_cast<unsigned short *>(mappedMemory);
+            unsigned short *data = static_cast<unsigned short *>(mappedMemory);
             for (size_t i = 0; i < count; i++)
             {
                 data[i] = static_cast<unsigned short>(i);
@@ -1738,7 +1738,7 @@
             void *mappedMemory = nullptr;
             ANGLE_TRY(mCountingIB->mapBuffer(spaceNeeded, &mappedMemory, nullptr));
 
-            unsigned int *data = reinterpret_cast<unsigned int *>(mappedMemory);
+            unsigned int *data = static_cast<unsigned int *>(mappedMemory);
             for (unsigned int i = 0; i < count; i++)
             {
                 data[i] = i;