Title: [277011] trunk
Revision
277011
Author
cl...@igalia.com
Date
2021-05-05 02:49:44 -0700 (Wed, 05 May 2021)

Log Message

OffscreenCanvas should preserve context transform after transferToImageBitmap
https://bugs.webkit.org/show_bug.cgi?id=225304

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline transferToImageBitmap tests.

* web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt:
* web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt:

Source/WebCore:

transferToImageBitmap should not affect the state of the canvas
context. Instead of returning the actual canvas buffer, to which the
drawing context is tightly bound, return a copy and clear the
original.

No new tests, rebaselined existing tests.

* html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::transferToImageBitmap):
(WebCore::OffscreenCanvas::takeImageBuffer const):
* html/canvas/CanvasRenderingContext2DBase.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (277010 => 277011)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-05-05 09:49:44 UTC (rev 277011)
@@ -1,3 +1,15 @@
+2021-05-05  Chris Lord  <cl...@igalia.com>
+
+        OffscreenCanvas should preserve context transform after transferToImageBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=225304
+
+        Reviewed by Darin Adler.
+
+        Rebaseline transferToImageBitmap tests.
+
+        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt:
+        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt:
+
 2021-05-04  Tyler Wilcock  <twilc...@protonmail.com>
 
         Import webstorage WPTs

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt (277010 => 277011)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt	2021-05-05 09:49:44 UTC (rev 277011)
@@ -2,7 +2,7 @@
 PASS Test that transferToImageBitmap returns an ImageBitmap with correct width and height
 FAIL Test that transferToImageBitmap returns an ImageBitmap with correct color assert_equals: Alpha channel of the pixel at (50, 25) expected 255 but got 0
 PASS Test that transferToImageBitmap won't change context's property
-FAIL Test that transferToImageBitmap preserves transform assert_equals: Green channel of the pixel at (23, 25) expected 255 but got 0
+PASS Test that transferToImageBitmap preserves transform
 PASS Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception
 PASS Test that transferToImageBitmap without a context throws an exception
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt (277010 => 277011)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt	2021-05-05 09:49:44 UTC (rev 277011)
@@ -4,7 +4,7 @@
 PASS Test that call transferToImageBitmap twice returns an ImageBitmap with correct color in a worker
 FAIL Test that call transferToImageBitmap twice on a alpha-disabled context returns an ImageBitmap with correct color in a worker assert_array_equals: expected property 3 to be 255 but got 0 (expected array [0, 0, 0, 255] got object "0,0,0,0")
 PASS Test that transferToImageBitmap won't change context's property in a worker
-FAIL Test that call transferToImageBitmap preserves transform in a worker assert_array_equals: expected property 1 to be 255 but got 0 (expected array [0, 255, 0, 255] got object "0,0,0,0")
+PASS Test that call transferToImageBitmap preserves transform in a worker
 PASS Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception in a worker
 PASS Test that call transferToImageBitmap without a context throws an exception in a worker
 

Modified: trunk/Source/WebCore/ChangeLog (277010 => 277011)


--- trunk/Source/WebCore/ChangeLog	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/Source/WebCore/ChangeLog	2021-05-05 09:49:44 UTC (rev 277011)
@@ -1,3 +1,22 @@
+2021-05-05  Chris Lord  <cl...@igalia.com>
+
+        OffscreenCanvas should preserve context transform after transferToImageBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=225304
+
+        Reviewed by Darin Adler.
+
+        transferToImageBitmap should not affect the state of the canvas
+        context. Instead of returning the actual canvas buffer, to which the
+        drawing context is tightly bound, return a copy and clear the
+        original.
+
+        No new tests, rebaselined existing tests.
+
+        * html/OffscreenCanvas.cpp:
+        (WebCore::OffscreenCanvas::transferToImageBitmap):
+        (WebCore::OffscreenCanvas::takeImageBuffer const):
+        * html/canvas/CanvasRenderingContext2DBase.h:
+
 2021-05-04  Peng Liu  <peng.l...@apple.com>
 
         [GPUP] Implement SourceBufferPrivateRemote::bufferFull()

Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (277010 => 277011)


--- trunk/Source/WebCore/html/OffscreenCanvas.cpp	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp	2021-05-05 09:49:44 UTC (rev 277011)
@@ -264,11 +264,14 @@
             return { ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer))) };
         }
 
-        auto buffer = takeImageBuffer();
-        if (!buffer)
-            return { RefPtr<ImageBitmap> { nullptr } };
+        // As the canvas context state is stored in GraphicsContext, which is owned
+        // by buffer(), to avoid resetting the context state, we have to make a copy and
+        // clear the original buffer rather than returning the original buffer.
+        auto bufferCopy = buffer()->copyRectToBuffer(FloatRect(FloatPoint(), buffer()->logicalSize()), buffer()->colorSpace(), *drawingContext());
+        downcast<OffscreenCanvasRenderingContext2D>(*m_context).clearCanvas();
+        clearCopiedImage();
 
-        return { ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), originClean() ? SerializationState::OriginClean : SerializationState())) };
+        return { ImageBitmap::create(ImageBitmapBacking(WTFMove(bufferCopy), originClean() ? SerializationState::OriginClean : SerializationState())) };
     }
 
 #if ENABLE(WEBGL)
@@ -478,18 +481,13 @@
 
 RefPtr<ImageBuffer> OffscreenCanvas::takeImageBuffer() const
 {
-    if (!m_detached)
-        m_hasCreatedImageBuffer = true;
+    ASSERT(m_detached);
 
-    // This function is primarily for use with transferToImageBitmap, which
-    // requires that the canvas bitmap refer to a new, blank bitmap of the same
-    // size after the existing bitmap is taken. In the case of a zero-size
-    // bitmap, our buffer is null, so returning early here is valid.
     if (size().isEmpty())
         return nullptr;
 
     clearCopiedImage();
-    return setImageBuffer(m_detached ? nullptr : ImageBitmap::createImageBuffer(*canvasBaseScriptExecutionContext(), size(), RenderingMode::Unaccelerated));
+    return setImageBuffer(nullptr);
 }
 
 void OffscreenCanvas::reset()

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (277010 => 277011)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h	2021-05-05 08:53:30 UTC (rev 277010)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h	2021-05-05 09:49:44 UTC (rev 277011)
@@ -176,6 +176,7 @@
     ExceptionOr<void> drawImage(CanvasImageSource&&, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh);
 
     void drawImageFromRect(HTMLImageElement&, float sx = 0, float sy = 0, float sw = 0, float sh = 0, float dx = 0, float dy = 0, float dw = 0, float dh = 0, const String& compositeOperation = emptyString());
+    void clearCanvas();
 
     using StyleVariant = Variant<String, RefPtr<CanvasGradient>, RefPtr<CanvasPattern>>;
     StyleVariant strokeStyle() const;
@@ -365,7 +366,6 @@
     bool isPointInPathInternal(const Path&, float x, float y, CanvasFillRule);
     bool isPointInStrokeInternal(const Path&, float x, float y);
 
-    void clearCanvas();
     Path transformAreaToDevice(const Path&) const;
     Path transformAreaToDevice(const FloatRect&) const;
     bool rectContainsCanvas(const FloatRect&) const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to