Diff
Modified: trunk/LayoutTests/ChangeLog (253609 => 253610)
--- trunk/LayoutTests/ChangeLog 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/LayoutTests/ChangeLog 2019-12-17 05:36:15 UTC (rev 253610)
@@ -1,3 +1,34 @@
+2019-12-16 Said Abou-Hallawa <[email protected]>
+
+ WebGLRenderingContext.texImage2D() should respect EXIF orientation
+ https://bugs.webkit.org/show_bug.cgi?id=205141
+
+ Reviewed by Simon Fraser.
+
+ The test page uses images with different EXIF orientation. The expected
+ page uses a single image with no EXIF orientation then it transforms the
+ <canvas> elements such that it matches the image in the test page.
+
+ WebGLRenderingContext uses a trick when drawing an SVG image or images
+ with EXIF orientation to a WebGL texture. It draws the Image to an Image-
+ Buffer, creates another Image out of the ImageBuffer and then draws the
+ other Image to the WebGL texture.
+
+ But there can be small glitches between drawing an Image directly versus
+ doing the ImageBuffer trick. So the expected page will use an SVG image
+ to ensure the same code path is used for both the test and the expected
+ pages.
+
+ This SVG image includes the jpeg image with no EXIF orientation but as a
+ data uri. Also the script has to wait after loading the SVG image till
+ the bitmap image is loaded from the data uri encoded data.
+
+ * fast/images/exif-orientation-webgl-texture-expected.html: Added.
+ * fast/images/exif-orientation-webgl-texture.html: Added.
+ * fast/images/resources/webgl-draw-image.js: Added.
+ * platform/win/TestExpectations:
+ All webgl tests are skipped on Windows.
+
2019-12-16 Truitt Savell <[email protected]>
REGRESSION: [ Catalina wk1 ] editing/mac/input/firstrectforcharacterrange-styled.html is failing
Added: trunk/LayoutTests/fast/images/exif-orientation-webgl-texture-expected.html (0 => 253610)
--- trunk/LayoutTests/fast/images/exif-orientation-webgl-texture-expected.html (rev 0)
+++ trunk/LayoutTests/fast/images/exif-orientation-webgl-texture-expected.html 2019-12-17 05:36:15 UTC (rev 253610)
@@ -0,0 +1,121 @@
+<!DOCTYPE html>
+<head>
+<style>
+ div.container {
+ display: inline-block;
+ margin-right: 20px;
+ margin-bottom: 10px;
+ width: 100px;
+ vertical-align: top;
+ }
+ div.horizontal {
+ width: 102px;
+ height: 52px;
+ }
+ div.vertical {
+ width: 52px;
+ height: 102px;
+ }
+ canvas {
+ border: 1px solid black;
+ width: 100px;
+ height: 50px;
+ }
+</style>
+</head>
+<script id="vertexShaderSource" type="text/glsl">
+ attribute vec4 a_position;
+ varying vec2 v_texturePosition;
+
+ void main() {
+ v_texturePosition = vec2((a_position.x + 1.0) / 2.0, (a_position.y + 1.0) / 2.0);
+ gl_Position = a_position;
+ }
+</script>
+<script id="fragmentShaderSource" type="text/glsl">
+ precision mediump float;
+
+ varying vec2 v_texturePosition;
+
+ uniform sampler2D texture;
+
+ void main() {
+ gl_FragColor = texture2D(texture, v_texturePosition);
+ }
+</script>
+<script src=""
+<body>
+ <b>WebGLRenderingContext.texImage2D() should rotate the images respecting their EXIF orientation.</b>
+ <br>
+ <br>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas2" style="transform: scaleX(-1);"></canvas>
+ </div>
+ <br>Flipped horizontally
+ </div>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas3" style="transform: rotate(180deg);"></canvas>
+ </div>
+ <br>Rotated 180°
+ </div>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas4" style="transform: scaleX(-1) rotate(180deg);"></canvas>
+ </div>
+ <br>Flipped vertically
+ </div>
+ <br>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas5" style="transform: translate(-25px, 25px) rotate(90deg) scaleY(-1);"></canvas>
+ </div>
+ <br>Rotated 90° CCW and flipped vertically
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas6" style="transform: translate(-25px, 25px) rotate(90deg);"></canvas>
+ </div>
+ <br>Rotated 90° CCW
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas7" style="transform: translate(-25px, 25px) rotate(270deg) scaleY(-1);"></canvas>
+ </div>
+ <br>Rotated 90° CW and flipped vertically
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas8" style="transform: translate(-25px, 25px) rotate(270deg);"></canvas>
+ </div>
+ <br>Rotated 90° CW
+ </div>
+ <br>
+ <script>
+ if (window.testRunner)
+ window.testRunner.waitUntilDone();
+
+ window._onload_ = function() {
+ document.querySelectorAll("canvas").forEach(canvas => {
+ canvas.width = 100 * window.devicePixelRatio;
+ canvas.height = 50 * window.devicePixelRatio;
+ });
+
+ var image = new Image;
+ image.src = "" xmlns='http://www.w3.org/2000/svg' width='100' height='50'><image href='' width='100' height='50'/></svg>";
+ image.decode().then(() => {
+ setTimeout(function() {
+ document.querySelectorAll("canvas").forEach(canvas => {
+ canvas.width = image.width * window.devicePixelRatio;
+ canvas.height = image.height * window.devicePixelRatio;
+ webglDrawImage(canvas, image);
+ });
+
+ if (window.testRunner)
+ window.testRunner.notifyDone();
+ }, 100);
+ });
+ }
+ </script>
+</body>
Added: trunk/LayoutTests/fast/images/exif-orientation-webgl-texture.html (0 => 253610)
--- trunk/LayoutTests/fast/images/exif-orientation-webgl-texture.html (rev 0)
+++ trunk/LayoutTests/fast/images/exif-orientation-webgl-texture.html 2019-12-17 05:36:15 UTC (rev 253610)
@@ -0,0 +1,134 @@
+<!DOCTYPE html>
+<head>
+<style>
+ div.container {
+ display: inline-block;
+ margin-right: 20px;
+ margin-bottom: 10px;
+ width: 100px;
+ vertical-align: top;
+ }
+ div.horizontal {
+ width: 102;
+ height: 52px;
+ }
+ div.vertical {
+ width: 52px;
+ height: 102px;
+ }
+ canvas {
+ border: 1px solid black;
+ }
+ canvas.horizontal {
+ width: 100px;
+ height: 50px;
+ }
+ canvas.vertical {
+ width: 50px;
+ height: 100px;
+ }
+</style>
+</head>
+<script id="vertexShaderSource" type="text/glsl">
+ attribute vec4 a_position;
+ varying vec2 v_texturePosition;
+
+ void main() {
+ v_texturePosition = vec2((a_position.x + 1.0) / 2.0, (a_position.y + 1.0) / 2.0);
+ gl_Position = a_position;
+ }
+</script>
+<script id="fragmentShaderSource" type="text/glsl">
+ precision mediump float;
+
+ varying vec2 v_texturePosition;
+
+ uniform sampler2D texture;
+
+ void main() {
+ gl_FragColor = texture2D(texture, v_texturePosition);
+ }
+</script>
+<script src=""
+<body>
+ <b>WebGLRenderingContext.texImage2D() should rotate the images respecting their EXIF orientation.</b>
+ <br>
+ <br>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas2"></canvas>
+ </div>
+ <br>Flipped horizontally
+ </div>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas3"></canvas>
+ </div>
+ <br>Rotated 180°
+ </div>
+ <div class ="container">
+ <div class ="horizontal">
+ <canvas class="horizontal" id="canvas4"></canvas>
+ </div>
+ <br>Flipped vertically
+ </div>
+ <br>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas5"></canvas>
+ </div>
+ <br>Rotated 90° CCW and flipped vertically
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas6"></canvas>
+ </div>
+ <br>Rotated 90° CCW
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas7"></canvas>
+ </div>
+ <br>Rotated 90° CW and flipped vertically
+ </div>
+ <div class ="container">
+ <div class ="vertical">
+ <canvas class="vertical" id="canvas8"></canvas>
+ </div>
+ <br>Rotated 90° CW
+ </div>
+ <br>
+ <script>
+ if (window.testRunner)
+ window.testRunner.waitUntilDone();
+
+ window._onload_ = function() {
+ var names = [
+ { resource: "resources/exif-orientation-2-ur.jpg", id : "canvas2" },
+ { resource: "resources/exif-orientation-3-lr.jpg", id : "canvas3" },
+ { resource: "resources/exif-orientation-4-lol.jpg", id : "canvas4" },
+ { resource: "resources/exif-orientation-5-lu.jpg", id : "canvas5" },
+ { resource: "resources/exif-orientation-6-ru.jpg", id : "canvas6" },
+ { resource: "resources/exif-orientation-7-rl.jpg", id : "canvas7" },
+ { resource: "resources/exif-orientation-8-llo.jpg", id : "canvas8" },
+ ];
+
+ var drawCount = 0;
+
+ names.forEach(function(name) {
+ var image = new Image;
+ image.src = ""
+ image.decode().then(() => {
+ let canvas = document.getElementById(name.id);
+ canvas.width = image.width * window.devicePixelRatio;
+ canvas.height = image.height * window.devicePixelRatio;
+ webglDrawImage(canvas, image);
+ if (++drawCount == names.length) {
+ if (window.testRunner)
+ window.testRunner.notifyDone();
+ }
+ });
+ });
+ }
+ </script>
+</body>
Added: trunk/LayoutTests/fast/images/resources/webgl-draw-image.js (0 => 253610)
--- trunk/LayoutTests/fast/images/resources/webgl-draw-image.js (rev 0)
+++ trunk/LayoutTests/fast/images/resources/webgl-draw-image.js 2019-12-17 05:36:15 UTC (rev 253610)
@@ -0,0 +1,110 @@
+function webglDrawImage(canvas, image) {
+
+ var gl = canvas.getContext("webgl");
+
+ // Set the clear color.
+ gl.clearColor(0, 0, 0, 1);
+
+ // Create the vertex shader object.
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
+
+ // The source code for the shader is extracted from the <script> element above.
+ gl.shaderSource(vertexShader, document.getElementById("vertexShaderSource").textContent);
+
+ // Compile the shader.
+ gl.compileShader(vertexShader);
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
+ // We failed to compile. Output to the console and quit.
+ console.error("Vertex Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(vertexShader));
+ return;
+ }
+
+ // Do the fragment shader.
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
+ gl.shaderSource(fragmentShader, document.getElementById("fragmentShaderSource").textContent);
+ gl.compileShader(fragmentShader);
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
+ console.error("Fragment Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(fragmentShader));
+ return;
+ }
+
+ // Make the program.
+ var program = gl.createProgram();
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ console.error("Unable to link shaders into program.");
+ return;
+ }
+
+ gl.useProgram(program);
+
+ var textureUniform = gl.getUniformLocation(program, "texture");
+
+ var positionAttribute = gl.getAttribLocation(program, "a_position");
+ gl.enableVertexAttribArray(positionAttribute);
+
+ // The default coordinate space is a square from -1 to 1.
+ // The triangle is three points in that square.
+ var vertices = new Float32Array([
+ -1, -1,
+ 1, -1,
+ 1, 1,
+ 1, 1,
+ -1, 1,
+ -1, -1
+ ]);
+
+ // Create the buffer that will hold the vertex data above.
+ var triangleBuffer = gl.createBuffer();
+
+ // Load the vertex data into the buffer.
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
+
+ var stillToDraw = false;
+
+ var updateTexture = function (texture, data) {
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, data);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ stillToDraw = true;
+ }
+
+ var texture = gl.createTexture();
+ updateTexture(texture, image);
+
+ // Clear to black.
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ var drawFunction = function () {
+ if (!stillToDraw) {
+ window.requestAnimationFrame(drawFunction);
+ }
+
+ // Clear to black.
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.uniform1i(textureUniform, 0);
+
+ // Bind the vertex attributes for the draw operation.
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
+ };
+
+ drawFunction();
+}
Modified: trunk/LayoutTests/platform/win/TestExpectations (253609 => 253610)
--- trunk/LayoutTests/platform/win/TestExpectations 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/LayoutTests/platform/win/TestExpectations 2019-12-17 05:36:15 UTC (rev 253610)
@@ -2014,6 +2014,7 @@
http/tests/canvas/webgl/ [ Skip ]
compositing/webgl/webgl-background-color.html [ Skip ]
compositing/webgl/webgl-reflection.html [ Skip ]
+fast/images/exif-orientation-webgl-texture.html [ Skip ]
fast/images/webgl-teximage2d.html [ Skip ]
#[ Release ] fast/canvas/webgl [ Skip ]
http/tests/security/webgl-remote-read-remote-image-allowed.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (253609 => 253610)
--- trunk/Source/WebCore/ChangeLog 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/Source/WebCore/ChangeLog 2019-12-17 05:36:15 UTC (rev 253610)
@@ -1,3 +1,23 @@
+2019-12-16 Said Abou-Hallawa <[email protected]>
+
+ WebGLRenderingContext.texImage2D() should respect EXIF orientation
+ https://bugs.webkit.org/show_bug.cgi?id=205141
+
+ Reviewed by Simon Fraser.
+
+ If image orientation is not the default, WebGLRenderingContext.texImage2D()
+ needs to draw this image into an ImageBuffer, makes a temporary Image
+ from the ImageBuffer then draw this temporary Image to the WebGL texture.
+
+ Test: fast/images/exif-orientation-webgl-texture.html
+
+ * html/canvas/WebGLRenderingContextBase.cpp:
+ (WebCore::WebGLRenderingContextBase::texSubImage2D):
+ (WebCore::WebGLRenderingContextBase::texImage2D):
+ * platform/graphics/BitmapImage.h:
+ * platform/graphics/Image.h:
+ (WebCore::Image::orientation const):
+
2019-12-16 Ryosuke Niwa <[email protected]>
TextManipulationController should observe newly inserted or displayed contents
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (253609 => 253610)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2019-12-17 05:36:15 UTC (rev 253610)
@@ -4014,7 +4014,7 @@
if (!imageForRender)
return { };
- if (imageForRender->isSVGImage())
+ if (imageForRender->isSVGImage() || imageForRender->orientation() != ImageOrientation::None)
imageForRender = drawImageIntoBuffer(*imageForRender, image->width(), image->height(), 1);
auto texture = validateTextureBinding("texSubImage2D", target, true);
@@ -4569,7 +4569,7 @@
if (!imageForRender)
return { };
- if (imageForRender->isSVGImage())
+ if (imageForRender->isSVGImage() || imageForRender->orientation() != ImageOrientation::None)
imageForRender = drawImageIntoBuffer(*imageForRender, image->width(), image->height(), 1);
if (!imageForRender || !validateTexFunc("texImage2D", TexImage, SourceHTMLImageElement, target, level, internalformat, imageForRender->width(), imageForRender->height(), 0, format, type, 0, 0))
Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (253609 => 253610)
--- trunk/Source/WebCore/platform/graphics/BitmapImage.h 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h 2019-12-17 05:36:15 UTC (rev 253610)
@@ -82,6 +82,7 @@
// FloatSize due to override.
FloatSize size(ImageOrientation orientation = ImageOrientation::FromImage) const override { return m_source->size(orientation); }
+ ImageOrientation orientation() const override { return m_source->orientation(); }
Color singlePixelSolidColor() const override { return m_source->singlePixelSolidColor(); }
bool frameIsBeingDecodedAndIsCompatibleWithOptionsAtIndex(size_t index, const DecodingOptions& decodingOptions) const { return m_source->frameIsBeingDecodedAndIsCompatibleWithOptionsAtIndex(index, decodingOptions); }
DecodingStatus frameDecodingStatusAtIndex(size_t index) const { return m_source->frameDecodingStatusAtIndex(index); }
Modified: trunk/Source/WebCore/platform/graphics/Image.h (253609 => 253610)
--- trunk/Source/WebCore/platform/graphics/Image.h 2019-12-17 03:26:09 UTC (rev 253609)
+++ trunk/Source/WebCore/platform/graphics/Image.h 2019-12-17 05:36:15 UTC (rev 253610)
@@ -116,6 +116,7 @@
float width() const { return size().width(); }
float height() const { return size().height(); }
virtual Optional<IntPoint> hotSpot() const { return WTF::nullopt; }
+ virtual ImageOrientation orientation() const { return ImageOrientation::FromImage; }
WEBCORE_EXPORT EncodedDataStatus setData(RefPtr<SharedBuffer>&& data, bool allDataReceived);
virtual EncodedDataStatus dataChanged(bool /*allDataReceived*/) { return EncodedDataStatus::Unknown; }