debugging draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 14 Jun 2016 09:52:53 -0700
changeset 379636 ffe8ab045881e9cbf03a29ff69ffcd63c8b87869
parent 379635 df416eb7d3c02bbc3347237ea89ad305e629acfa
child 379637 be0599af61e3c89fc79e6d874c6f0c54a610aacc
push id21016
push userbmo:jgilbert@mozilla.com
push dateThu, 16 Jun 2016 14:33:55 +0000
milestone50.0a1
debugging MozReview-Commit-ID: EHd7AXDstGf
dom/canvas/WebGL2ContextBuffers.cpp
dom/canvas/test/webgl-mochitest/test_pixel_pack_buffer.html
--- a/dom/canvas/WebGL2ContextBuffers.cpp
+++ b/dom/canvas/WebGL2ContextBuffers.cpp
@@ -226,18 +226,24 @@ WebGL2Context::GetBufferSubDataT(GLenum 
      * 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);
     // Warning: Possibly shared memory.  See bug 1225033.
     memcpy(data.DataAllowShared(), ptr, data.LengthAllowShared());
+    if (data.LengthAllowShared() > 8) {
+        uint8_t arr[8];
+        memcpy(arr, ptr, 8);
+        memcpy(arr, data.DataAllowShared(), 8);
+    }
     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)
--- a/dom/canvas/test/webgl-mochitest/test_pixel_pack_buffer.html
+++ b/dom/canvas/test/webgl-mochitest/test_pixel_pack_buffer.html
@@ -19,29 +19,29 @@ function DrawColors(gl) {
   };
 
   // +---+
   // |G W|
   // |R B|
   // +---+
 
   gl.scissor(0, 0, 1, 1);
-  fnClearColor(gl, RED);
+  fnClearColor(RED);
   gl.clear(gl.COLOR_BUFFER_BIT);
 
   gl.scissor(1, 0, 1, 1);
-  fnClearColor(gl, BLUE);
+  fnClearColor(BLUE);
   gl.clear(gl.COLOR_BUFFER_BIT);
 
   gl.scissor(0, 1, 1, 1);
-  fnClearColor(gl, GREEN);
+  fnClearColor(GREEN);
   gl.clear(gl.COLOR_BUFFER_BIT);
 
   gl.scissor(1, 1, 1, 1);
-  fnClearColor(gl, WHITE);
+  fnClearColor(WHITE);
   gl.clear(gl.COLOR_BUFFER_BIT);
 }
 
 function ClearBufferPair(gl, byteCount) {
   // Using `null` here clears to zero according to WebGL.
   gl.bufferData(gl.PIXEL_PACK_BUFFER, byteCount, gl.STREAM_READ);
 
   var arr = new Uint8Array(byteCount);
@@ -89,94 +89,130 @@ function TestError(gl, refErrVal, str=''
      str + 'Expected error 0x' + refErrVal.toString(16) + ', was 0x' + err.toString(16) +
      '.');
 }
 
 var gl;
 
 (function() {
   var canvas = document.createElement('canvas');
+  document.body.appendChild(canvas);
   canvas.width = 2;
   canvas.height = 2;
+  canvas.style = 'width: 256px; height: 256px; border: 1px solid black;';
 
   var attribs = {
     antialias: false,
+    alpha: false,
   };
   gl = canvas.getContext('webgl2', attribs);
   if (!gl) {
     todo(false, 'WebGL 2 not present, skipping.');
     return;
   }
 
+  ////////
+
+  TestIsUNormColor(RED, new Uint8Array([255, 0, 0, 255]), 0);
+
+  ////////
+
+  gl.clearColor(RED[0], RED[1], RED[2], RED[3]);
+  gl.clearColor(1.0, 0.0, 0.0, 1.0);
+  gl.clear(gl.COLOR_BUFFER_BIT);
+
+  var data = new Uint8Array(16);
+  gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, data);
+  console.log(JSON.stringify(data));
+  TestIsUNormColor(RED, data, 0);
+
+  return;
+
+  ////////
+
   DrawColors(gl);
 
+  ////////
+
+  var data = new Uint8Array(16);
+  gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, data);
+  TestIsUNormColor(RED, data, 0);
+  TestIsUNormColor(BLUE, data, 4);
+  TestIsUNormColor(GREEN, data, 8);
+  TestIsUNormColor(WHITE, data, 12);
+
+  return;
+
+  ////////
+
   var a = gl.createBuffer();
   gl.bindBuffer(gl.PIXEL_PACK_BUFFER, a);
-  var data;
 
   TestError(gl, 0, 'after setup');
 
+  ////////
+
   // Basic
   section('Basic readback');
   data = ClearBufferPair(gl, 16);
   TestError(gl, 0);
   gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, 0);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data.buffer);
   TestError(gl, 0);
   TestIsUNormColor(RED, data, 0);
   TestIsUNormColor(BLUE, data, 4);
   TestIsUNormColor(GREEN, data, 8);
   TestIsUNormColor(WHITE, data, 12);
 
   section('Subrect readback');
   data = ClearBufferPair(gl, 4);
   gl.readPixels(1, 1, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, 0);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data.buffer);
   TestError(gl, 0);
   TestIsUNormColor(WHITE, data, 0);
   TestIsUNormColor(ZERO, data, 4);
 
   section('ReadPixels offset:4');
   data = ClearBufferPair(gl, 16);
   gl.readPixels(1, 1, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, 4);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data.buffer);
   TestIsUNormColor(ZERO, data, 0);
   TestIsUNormColor(WHITE, data, 4);
   TestIsUNormColor(ZERO, data, 8);
   TestIsUNormColor(ZERO, data, 12);
 
   section('ReadPixels offset:5');
   gl.readPixels(1, 1, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, 5);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data.buffer);
   TestError(gl, 0);
   TestIsUNormColor(ZERO, data, 0);
   TestIsUNormColor(WHITE, data, 4); // Should remain from previous read.
   TestIsUNormColor(WHITE, data, 5);
   TestIsUNormColor(ZERO, data, 9);
   TestIsUNormColor(ZERO, data, 12);
 
   section('GetBufferSubData src too small');
   data = ClearBufferPair(gl, 16);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 1, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 1, data.buffer);
   TestError(gl, gl.INVALID_OPERATION);
   TestIsUNormColor(ZERO, data, 0);
   TestIsUNormColor(ZERO, data, 4);
   TestIsUNormColor(ZERO, data, 8);
   TestIsUNormColor(ZERO, data, 12);
 
   section('GetBufferSubData offset:1');
   data = new Uint8Array(15);
   gl.readPixels(1, 1, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, 8);
   TestError(gl, 0);
-  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 1, data);
+  gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 1, data.buffer);
   TestError(gl, 0);
   TestIsUNormColor(ZERO, data, 0);
   TestIsUNormColor(ZERO, data, 3);
   TestIsUNormColor(WHITE, data, 7);
   TestIsUNormColor(ZERO, data, 11);
 })();
 
 </script>