Bug 1382104 - gfxVRPuppet should not expose padding as data. - r=kip
MozReview-Commit-ID: 3NZZIDfjcu8
--- a/dom/vr/test/reftest/change_size.html
+++ b/dom/vr/test/reftest/change_size.html
@@ -25,16 +25,18 @@ If this fails, something is seriously wr
var submitResult = null;
var vrDisplay = null;
var webglCanvas = null;
var gl = null;
var prog = null;
var img = null;
// The resolution is 540 : 300 (the ratio of 2160 * 1200, like Vive and Oculus)
+ const initialWidth = 128;
+ const initialHeight = 128;
const eyeWidth = 270;
const eyeHeight = 300;
function setStatus(text) {
var elem = document.getElementById('status');
elem.innerHTML = text;
}
@@ -101,38 +103,39 @@ If this fails, something is seriously wr
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
// Indicate VRDisplay we're done rendering.
vrDisplay.submitFrame();
if (vrDisplay.getSubmitFrameResult(submitResult)) {
if (!img) {
img = document.createElement("img");
img.onload = function(){
- // img width will not be eyeWidth * 2 (540), it would
- // be 544. It is because D3D11 CopyResource changes
- // the destination image size.
- console.log('heights: ' + img.height + ' ' + eyeHeight);
- if ((img.height == eyeHeight)) {
+ if (img.width == 2*eyeWidth && img.height == eyeHeight) {
webglCanvas.style.display = 'none';
vrDisplay.exitPresent();
//setTimeout(testComplete, 0);
img.onload = null;
testComplete();
+ } else if (img.width != initialWidth || img.height != initialHeight) {
+ document.write('Bad width/height from getSubmitFrameResult: '
+ + img.width + 'x' + img.height);
}
};
img.src = submitResult.base64Image;
document.body.appendChild(img);
} else {
img.src = submitResult.base64Image;
}
}
}
function runTest() {
webglCanvas = document.getElementById('canvas');
+ webglCanvas.width = initialWidth;
+ webglCanvas.height = initialHeight;
gl = WebGLUtil.getWebGL('canvas');
if (!gl) {
setStatus('WebGL context creation failed.');
return;
}
gl.disable(gl.DEPTH_TEST);
prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
if (!prog) {
@@ -159,13 +162,13 @@ If this fails, something is seriously wr
function testComplete() {
document.documentElement.removeAttribute("class");
}
</script>
</head>
<body onload='runTest();'>
- <canvas id='canvas' width='128' height='128'></canvas>
+ <canvas id='canvas'></canvas>
<div id='status'></div>
</body>
</html>
\ No newline at end of file
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -367,27 +367,31 @@ VRDisplayPuppet::SubmitFrame(TextureSour
// Ideally, we should convert the srcData to a PNG image and decode it
// to a Base64 string here, but the GPU process does not have the privilege to
// access the image library. So, we have to convert the RAW image data
// to a base64 string and forward it to let the content process to
// do the image conversion.
char* srcData = static_cast<char*>(mapInfo.pData);
VRSubmitFrameResultInfo result;
result.mFormat = SurfaceFormat::B8G8R8A8;
+ result.mWidth = desc.Width;
+ result.mHeight = desc.Height;
+ result.mFrameNum = mDisplayInfo.mFrameId;
+
// If the original texture size is not pow of 2, CopyResource() will add padding,
// so the size is adjusted. We have to get the correct size by (mapInfo.RowPitch /
// the format size).
- result.mWidth = mapInfo.RowPitch / 4;
- result.mHeight = desc.Height;
- result.mFrameNum = mDisplayInfo.mFrameId;
- nsCString rawString(Substring((char*)srcData, mapInfo.RowPitch * desc.Height));
-
+ nsCString rawString;
+ for (uint32_t i = 0; i < desc.Height; i++) {
+ rawString += Substring(srcData + i*mapInfo.RowPitch, desc.Width*4);
+ }
if (Base64Encode(rawString, result.mBase64Image) != NS_OK) {
MOZ_ASSERT(false, "Failed to encode base64 images.");
}
+
mContext->Unmap(mappedTexture, 0);
// Dispatch the base64 encoded string to the DOM side. Then, it will be decoded
// and convert to a PNG image there.
vm->DispatchSubmitFrameResult(mDisplayInfo.mDisplayID, result);
break;
}
case 2:
{