Title: [279424] trunk
- Revision
- 279424
- Author
- [email protected]
- Date
- 2021-06-30 11:29:02 -0700 (Wed, 30 Jun 2021)
Log Message
toDataURL image upside down if premultipliedAlpha=false
https://bugs.webkit.org/show_bug.cgi?id=156129
<rdar://problem/53942867>
Patch by Kimmo Kinnunen <[email protected]> on 2021-06-30
Reviewed by Kenneth Russell.
Flip the result `PixelBuffer` of `GraphicsContextGL::paintRenderingResultsToPixelBuffer()`
along the y-axis manually with memcpy.
ReadPixels returns the pixels upside down.
The `PixelBuffer` code-path is only used for reading unpremultiplied
image contents so that `toDataURL()` can encode the premultipliedAlpha=false
WebGL content as was rendered.
Other code-paths, such as Context2D.drawImage and drawing to the document,
use `GraphicsContextGL::paintRenderingResultsToCanvas()`.
In those cases y-flip is done by constructing a `ImageBuffer` for the PixelBuffer
and then using y-flip transform to draw the `ImageBuffer` to the target `ImageBuffer`
using `GraphicsContext`.
Fixes webgl/1.0.x/conformance/canvas/to-data-url-test.html
* platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
(WebCore::GraphicsContextGLOpenGL::paintRenderingResultsToPixelBuffer):
Modified Paths
Diff
Modified: trunk/LayoutTests/TestExpectations (279423 => 279424)
--- trunk/LayoutTests/TestExpectations 2021-06-30 18:26:44 UTC (rev 279423)
+++ trunk/LayoutTests/TestExpectations 2021-06-30 18:29:02 UTC (rev 279424)
@@ -3502,9 +3502,15 @@
# WebGL conformance test suite 1.0.x is skipped until 1.0.3 is retired.
webgl/1.0.x [ Skip ]
+# Explicitly enable tests which we have fixed and do not have corresponding 1.0.3 test functionality.
+webgl/1.0.x/conformance/canvas/to-data-url-test.html [ Pass ]
+
# WebGL conformance test suite 2.0.1 is skipped until 2.0.0 is retired.
webgl/2.0.y [ Skip ]
+# Explicitly enable tests which we have fixed and do not have corresponding 2.0.y test functionality.
+webgl/2.0.y/conformance/canvas/to-data-url-test.html [ Pass ]
+
# pre-wrap progression. Other rendering engines agree with the result.
webkit.org/b/206168 [ Debug ] fast/dom/insert-span-into-long-text-bug-28245.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (279423 => 279424)
--- trunk/Source/WebCore/ChangeLog 2021-06-30 18:26:44 UTC (rev 279423)
+++ trunk/Source/WebCore/ChangeLog 2021-06-30 18:29:02 UTC (rev 279424)
@@ -1,3 +1,29 @@
+2021-06-30 Kimmo Kinnunen <[email protected]>
+
+ toDataURL image upside down if premultipliedAlpha=false
+ https://bugs.webkit.org/show_bug.cgi?id=156129
+ <rdar://problem/53942867>
+
+ Reviewed by Kenneth Russell.
+
+ Flip the result `PixelBuffer` of `GraphicsContextGL::paintRenderingResultsToPixelBuffer()`
+ along the y-axis manually with memcpy.
+ ReadPixels returns the pixels upside down.
+ The `PixelBuffer` code-path is only used for reading unpremultiplied
+ image contents so that `toDataURL()` can encode the premultipliedAlpha=false
+ WebGL content as was rendered.
+
+ Other code-paths, such as Context2D.drawImage and drawing to the document,
+ use `GraphicsContextGL::paintRenderingResultsToCanvas()`.
+ In those cases y-flip is done by constructing a `ImageBuffer` for the PixelBuffer
+ and then using y-flip transform to draw the `ImageBuffer` to the target `ImageBuffer`
+ using `GraphicsContext`.
+
+ Fixes webgl/1.0.x/conformance/canvas/to-data-url-test.html
+
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
+ (WebCore::GraphicsContextGLOpenGL::paintRenderingResultsToPixelBuffer):
+
2021-06-30 Antoine Quint <[email protected]>
[Model] [iOS] Add support for displaying <model> in fullscreen
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (279423 => 279424)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp 2021-06-30 18:26:44 UTC (rev 279423)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp 2021-06-30 18:29:02 UTC (rev 279424)
@@ -40,6 +40,8 @@
#include "GraphicsContextGLCV.h"
#endif
+#include <memory>
+
namespace WebCore {
void GraphicsContextGLOpenGL::resetBuffersToAutoClear()
@@ -232,7 +234,22 @@
// Reading premultiplied alpha would involve unpremultiplying, which is lossy.
if (contextAttributes().premultipliedAlpha)
return std::nullopt;
- return readRenderingResultsForPainting();
+ auto results = readRenderingResultsForPainting();
+ if (results && !results->size().isEmpty()) {
+ ASSERT(results->format().pixelFormat == PixelFormat::RGBA8 || results->format().pixelFormat == PixelFormat::BGRA8);
+ // FIXME: Make PixelBufferConversions support negative rowBytes and in-place conversions.
+ const auto size = results->size();
+ const size_t rowStride = size.width() * 4;
+ uint8_t* top = results->data().data();
+ uint8_t* bottom = top + (size.height() - 1) * rowStride;
+ std::unique_ptr<uint8_t[]> temp(new uint8_t[rowStride]);
+ for (; top < bottom; top += rowStride, bottom -= rowStride) {
+ memcpy(temp.get(), bottom, rowStride);
+ memcpy(bottom, top, rowStride);
+ memcpy(top, temp.get(), rowStride);
+ }
+ }
+ return results;
}
std::optional<PixelBuffer> GraphicsContextGLOpenGL::readRenderingResultsForPainting()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes