Changeset 279424 in webkit


Ignore:
Timestamp:
Jun 30, 2021 11:29:02 AM (13 months ago)
Author:
commit-queue@webkit.org
Message:

toDataURL image upside down if premultipliedAlpha=false
https://bugs.webkit.org/show_bug.cgi?id=156129
<rdar://problem/53942867>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> 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):

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/TestExpectations

    r279414 r279424  
    35033503webgl/1.0.x [ Skip ]
    35043504
     3505# Explicitly enable tests which we have fixed and do not have corresponding 1.0.3 test functionality.
     3506webgl/1.0.x/conformance/canvas/to-data-url-test.html [ Pass ]
     3507
    35053508# WebGL conformance test suite 2.0.1 is skipped until 2.0.0 is retired.
    35063509webgl/2.0.y [ Skip ]
     3510
     3511# Explicitly enable tests which we have fixed and do not have corresponding 2.0.y test functionality.
     3512webgl/2.0.y/conformance/canvas/to-data-url-test.html [ Pass ]
    35073513
    35083514# pre-wrap progression. Other rendering engines agree with the result.
  • trunk/Source/WebCore/ChangeLog

    r279420 r279424  
     12021-06-30  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        toDataURL image upside down if premultipliedAlpha=false
     4        https://bugs.webkit.org/show_bug.cgi?id=156129
     5        <rdar://problem/53942867>
     6
     7        Reviewed by Kenneth Russell.
     8
     9        Flip the result `PixelBuffer` of `GraphicsContextGL::paintRenderingResultsToPixelBuffer()`
     10        along the y-axis manually with memcpy.
     11        ReadPixels returns the pixels upside down.
     12        The `PixelBuffer` code-path is only used for reading unpremultiplied
     13        image contents so that `toDataURL()` can encode the premultipliedAlpha=false
     14        WebGL content as was rendered.
     15
     16        Other code-paths, such as Context2D.drawImage and drawing to the document,
     17        use `GraphicsContextGL::paintRenderingResultsToCanvas()`.
     18        In those cases y-flip is done by constructing a `ImageBuffer` for the PixelBuffer
     19        and then using y-flip transform to draw the `ImageBuffer` to the target `ImageBuffer`
     20        using `GraphicsContext`.
     21
     22        Fixes webgl/1.0.x/conformance/canvas/to-data-url-test.html
     23
     24        * platform/graphics/opengl/GraphicsContextGLOpenGL.cpp:
     25        (WebCore::GraphicsContextGLOpenGL::paintRenderingResultsToPixelBuffer):
     26
    1272021-06-30  Antoine Quint  <graouts@webkit.org>
    228
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp

    r278253 r279424  
    4040#include "GraphicsContextGLCV.h"
    4141#endif
     42
     43#include <memory>
    4244
    4345namespace WebCore {
     
    233235    if (contextAttributes().premultipliedAlpha)
    234236        return std::nullopt;
    235     return readRenderingResultsForPainting();
     237    auto results = readRenderingResultsForPainting();
     238    if (results && !results->size().isEmpty()) {
     239        ASSERT(results->format().pixelFormat == PixelFormat::RGBA8 || results->format().pixelFormat == PixelFormat::BGRA8);
     240        // FIXME: Make PixelBufferConversions support negative rowBytes and in-place conversions.
     241        const auto size = results->size();
     242        const size_t rowStride = size.width() * 4;
     243        uint8_t* top = results->data().data();
     244        uint8_t* bottom = top + (size.height() - 1) * rowStride;
     245        std::unique_ptr<uint8_t[]> temp(new uint8_t[rowStride]);
     246        for (; top < bottom; top += rowStride, bottom -= rowStride) {
     247            memcpy(temp.get(), bottom, rowStride);
     248            memcpy(bottom, top, rowStride);
     249            memcpy(top, temp.get(), rowStride);
     250        }
     251    }
     252    return results;
    236253}
    237254
Note: See TracChangeset for help on using the changeset viewer.