Bug 1250710 - Clean up formatting. - r=jrmuizel draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 14 Jun 2016 09:02:01 -0700
changeset 379631 24ecc5eba5f30652fe5c6d1d27f4a245fd4425f8
parent 379630 5478c80e19f3f8be0c9dca8691852c95d82f4ad8
child 379632 cbda2feb951346cf6007b1613a061b99411913f4
push id21016
push userbmo:jgilbert@mozilla.com
push dateThu, 16 Jun 2016 14:33:55 +0000
reviewersjrmuizel
bugs1250710
milestone50.0a1
Bug 1250710 - Clean up formatting. - r=jrmuizel MozReview-Commit-ID: 1ZYXDiG6R69
dom/canvas/WebGL2ContextBuffers.cpp
--- a/dom/canvas/WebGL2ContextBuffers.cpp
+++ b/dom/canvas/WebGL2ContextBuffers.cpp
@@ -7,36 +7,36 @@
 
 #include "GLContext.h"
 #include "WebGLBuffer.h"
 #include "WebGLTransformFeedback.h"
 
 namespace mozilla {
 
 bool
-WebGL2Context::ValidateBufferTarget(GLenum target, const char* info)
+WebGL2Context::ValidateBufferTarget(GLenum target, const char* funcName)
 {
     switch (target) {
     case LOCAL_GL_ARRAY_BUFFER:
     case LOCAL_GL_COPY_READ_BUFFER:
     case LOCAL_GL_COPY_WRITE_BUFFER:
     case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
     case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
     case LOCAL_GL_UNIFORM_BUFFER:
         return true;
 
     case LOCAL_GL_PIXEL_PACK_BUFFER:
     case LOCAL_GL_PIXEL_UNPACK_BUFFER:
         ErrorInvalidOperation("%s: PBOs are still under development, and are currently"
                               " disabled.",
-                              info);
+                              funcName);
         return false;
 
     default:
-        ErrorInvalidEnumInfo(info, target);
+        ErrorInvalidEnumInfo(funcName, target);
         return false;
     }
 }
 
 bool
 WebGL2Context::ValidateBufferIndexedTarget(GLenum target, const char* info)
 {
     switch (target) {
@@ -75,66 +75,68 @@ WebGL2Context::ValidateBufferUsageEnum(G
 // -------------------------------------------------------------------------
 // Buffer objects
 
 void
 WebGL2Context::CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
                                  GLintptr readOffset, GLintptr writeOffset,
                                  GLsizeiptr size)
 {
+    const char funcName[] = "copyBufferSubData";
     if (IsContextLost())
         return;
 
-    if (!ValidateBufferTarget(readTarget, "copyBufferSubData") ||
-        !ValidateBufferTarget(writeTarget, "copyBufferSubData"))
+    if (!ValidateBufferTarget(readTarget, funcName) ||
+        !ValidateBufferTarget(writeTarget, funcName))
     {
         return;
     }
 
     const WebGLRefPtr<WebGLBuffer>& readBufferSlot = GetBufferSlotByTarget(readTarget);
     const WebGLRefPtr<WebGLBuffer>& writeBufferSlot = GetBufferSlotByTarget(writeTarget);
     if (!readBufferSlot || !writeBufferSlot)
         return;
 
     const WebGLBuffer* readBuffer = readBufferSlot.get();
-    if (!readBuffer)
-        return ErrorInvalidOperation("copyBufferSubData: No buffer bound to readTarget");
-
-    WebGLBuffer* writeBuffer = writeBufferSlot.get();
-    if (!writeBuffer)
-        return ErrorInvalidOperation("copyBufferSubData: No buffer bound to writeTarget");
-
-    if (!ValidateDataOffsetSize(readOffset, size, readBuffer->ByteLength(),
-        "copyBufferSubData"))
-    {
+    if (!readBuffer) {
+        ErrorInvalidOperation("%s: No buffer bound to readTarget.", funcName);
         return;
     }
 
-    if (!ValidateDataOffsetSize(writeOffset, size, writeBuffer->ByteLength(),
-        "copyBufferSubData"))
-    {
+    WebGLBuffer* writeBuffer = writeBufferSlot.get();
+    if (!writeBuffer) {
+        ErrorInvalidOperation("%s: No buffer bound to writeTarget.", funcName);
         return;
     }
 
+    if (!ValidateDataOffsetSize(readOffset, size, readBuffer->ByteLength(), funcName))
+        return;
+
+    if (!ValidateDataOffsetSize(writeOffset, size, writeBuffer->ByteLength(), funcName))
+        return;
+
     if (readTarget == writeTarget &&
-        !ValidateDataRanges(readOffset, writeOffset, size, "copyBufferSubData"))
+        !ValidateDataRanges(readOffset, writeOffset, size, funcName))
     {
         return;
     }
 
     WebGLBuffer::Kind readType = readBuffer->Content();
     WebGLBuffer::Kind writeType = writeBuffer->Content();
 
     if (readType != WebGLBuffer::Kind::Undefined &&
         writeType != WebGLBuffer::Kind::Undefined &&
         writeType != readType)
     {
-        ErrorInvalidOperation("copyBufferSubData: Can't copy %s data to %s data",
-                              (readType == WebGLBuffer::Kind::OtherData) ? "other" : "element",
-                              (writeType == WebGLBuffer::Kind::OtherData) ? "other" : "element");
+        ErrorInvalidOperation("%s: Can't copy %s data to %s data.",
+                              funcName,
+                              (readType == WebGLBuffer::Kind::OtherData) ? "other"
+                                                                         : "element",
+                              (writeType == WebGLBuffer::Kind::OtherData) ? "other"
+                                                                          : "element");
         return;
     }
 
     WebGLContextUnchecked::CopyBufferSubData(readTarget, writeTarget, readOffset,
                                              writeOffset, size);
 
     if (writeType == WebGLBuffer::Kind::Undefined) {
         writeBuffer->BindTo(
@@ -145,64 +147,71 @@ WebGL2Context::CopyBufferSubData(GLenum 
 
 // BufferT may be one of
 // const dom::ArrayBuffer&
 // const dom::SharedArrayBuffer&
 template<typename BufferT>
 void
 WebGL2Context::GetBufferSubDataT(GLenum target, GLintptr offset, const BufferT& data)
 {
+    const char funcName[] = "getBufferSubData";
     if (IsContextLost())
         return;
 
     // For the WebGLBuffer bound to the passed target, read
     // returnedData.byteLength bytes from the buffer starting at byte
     // offset offset and write them to returnedData.
 
     // If zero is bound to target, an INVALID_OPERATION error is
     // generated.
-    if (!ValidateBufferTarget(target, "getBufferSubData"))
+    if (!ValidateBufferTarget(target, funcName))
         return;
 
     // If offset is less than zero, an INVALID_VALUE error is
     // generated.
-    if (offset < 0)
-        return ErrorInvalidValue("getBufferSubData: negative offset");
+    if (offset < 0) {
+        ErrorInvalidValue("%s: Offset must be non-negative.", funcName);
+        return;
+    }
 
     WebGLRefPtr<WebGLBuffer>& bufferSlot = GetBufferSlotByTarget(target);
     WebGLBuffer* boundBuffer = bufferSlot.get();
-    if (!boundBuffer)
-        return ErrorInvalidOperation("getBufferSubData: no buffer bound");
+    if (!boundBuffer) {
+        ErrorInvalidOperation("%s: No buffer bound.", funcName);
+        return;
+    }
 
     // If offset + returnedData.byteLength would extend beyond the end
     // of the buffer an INVALID_VALUE error is generated.
     data.ComputeLengthAndData();
 
     CheckedInt<WebGLsizeiptr> neededByteLength = CheckedInt<WebGLsizeiptr>(offset) + data.LengthAllowShared();
     if (!neededByteLength.isValid()) {
-        ErrorInvalidValue("getBufferSubData: Integer overflow computing the needed"
-                          " byte length.");
+        ErrorInvalidValue("%s: Integer overflow computing the needed byte length.",
+                          funcName);
         return;
     }
 
     if (neededByteLength.value() > boundBuffer->ByteLength()) {
-        ErrorInvalidValue("getBufferSubData: Not enough data. Operation requires"
-                          " %d bytes, but buffer only has %d bytes.",
-                          neededByteLength.value(), boundBuffer->ByteLength());
+        ErrorInvalidValue("%s: Not enough data. Operation requires %d bytes, but buffer"
+                          " only has %d bytes.",
+                          funcName, neededByteLength.value(), boundBuffer->ByteLength());
         return;
     }
 
     // If target is TRANSFORM_FEEDBACK_BUFFER, and any transform
     // feedback object is currently active, an INVALID_OPERATION error
     // is generated.
     WebGLTransformFeedback* currentTF = mBoundTransformFeedback;
     if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER && currentTF) {
-        if (currentTF->mIsActive)
-            return ErrorInvalidOperation("getBufferSubData: Currently bound transform"
-                                         " feedback is active");
+        if (currentTF->mIsActive) {
+            ErrorInvalidOperation("%s: Currently bound transform feedback is active.",
+                                  funcName);
+            return;
+        }
 
         // https://github.com/NVIDIA/WebGL/commit/63aff5e58c1d79825a596f0f4aa46174b9a5f72c
         // Performing reads and writes on a buffer that is currently
         // bound for transform feedback causes undefined results in
         // GLES3.0 and OpenGL 4.5. In practice results of reads and
         // writes might be consistent as long as transform feedback
         // objects are not active, but neither GLES3.0 nor OpenGL 4.5
         // spec guarantees this - just being bound for transform
@@ -213,40 +222,45 @@ WebGL2Context::GetBufferSubDataT(GLenum 
 
     /* If the buffer is written and read sequentially by other
      * operations and getBufferSubData, it is the responsibility of
      * the WebGL API to ensure that data are access
      * consistently. This applies even if the buffer is currently
      * bound to a transform feedback binding point.
      */
 
-    void* ptr = gl->fMapBufferRange(target, offset, data.LengthAllowShared(), LOCAL_GL_MAP_READ_BIT);
+    void* ptr = gl->fMapBufferRange(target, offset, data.LengthAllowShared(),
+                                    LOCAL_GL_MAP_READ_BIT);
     // Warning: Possibly shared memory.  See bug 1225033.
     memcpy(data.DataAllowShared(), ptr, data.LengthAllowShared());
     gl->fUnmapBuffer(target);
 
     if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER && currentTF) {
         BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, currentTF);
     }
 }
 
-void WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset,
-                                     const dom::Nullable<dom::ArrayBuffer>& maybeData)
+void
+WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset,
+                                const dom::Nullable<dom::ArrayBuffer>& maybeData)
 {
     // If returnedData is null then an INVALID_VALUE error is
     // generated.
-    if (maybeData.IsNull())
-        return ErrorInvalidValue("getBufferSubData: returnedData is null");
+    if (maybeData.IsNull()) {
+        ErrorInvalidValue("getBufferSubData: returnedData is null");
+        return;
+    }
 
     const dom::ArrayBuffer& data = maybeData.Value();
     GetBufferSubDataT(target, offset, data);
 }
 
-void WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset,
-                                     const dom::SharedArrayBuffer& data)
+void
+WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset,
+                                const dom::SharedArrayBuffer& data)
 {
     GetBufferSubDataT(target, offset, data);
 }
 
 void
 WebGL2Context::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
                           GLenum type, GLintptr offset)
 {