Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (253098 => 253099)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2019-12-04 11:53:59 UTC (rev 253099)
@@ -1,3 +1,15 @@
+2019-12-04 Zan Dobersek <[email protected]> and Chris Lord <[email protected]>
+
+ Implement OffscreenCanvas.transferToImageBitmap
+ https://bugs.webkit.org/show_bug.cgi?id=202572
+
+ Reviewed by Antti Koivisto.
+
+ * web-platform-tests/offscreen-canvas/filter/offscreencanvas.filter.w-expected.txt:
+ * web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.resize-expected.txt:
+ * web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt:
+ * web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt:
+
2019-12-03 Simon Fraser <[email protected]>
Update css/css-values WPT
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/filter/offscreencanvas.filter.w-expected.txt (0 => 253099)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/filter/offscreencanvas.filter.w-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/filter/offscreencanvas.filter.w-expected.txt 2019-12-04 11:53:59 UTC (rev 253099)
@@ -0,0 +1,3 @@
+
+PASS offscreencanvas
+
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.resize-expected.txt (253098 => 253099)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.resize-expected.txt 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.resize-expected.txt 2019-12-04 11:53:59 UTC (rev 253099)
@@ -1,6 +1,6 @@
PASS Verify that writing to the width and height attributes of an OffscreenCanvas works when there is no context attached.
-FAIL Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a 2d context attached. null is not an object (evaluating 'image.width')
+PASS Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a 2d context attached.
PASS Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a webgl context attached.
FAIL Verify that writing to the width or height attribute of a placeholder canvas throws an exception placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined)
FAIL Verify that writing to the width or height attribute of a placeholder canvas throws an exception even when not changing the value of the attribute. placeholder.transferControlToOffscreen is not a function. (In 'placeholder.transferControlToOffscreen()', 'placeholder.transferControlToOffscreen' is undefined)
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt (253098 => 253099)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt 2019-12-04 11:53:59 UTC (rev 253099)
@@ -1,8 +1,8 @@
-FAIL Test that transferToImageBitmap returns an ImageBitmap with correct width and height null is not an object (evaluating 'image.width')
-FAIL Test that transferToImageBitmap returns an ImageBitmap with correct color Type error
+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 Type error
+FAIL Test that transferToImageBitmap preserves transform assert_equals: Green channel of the pixel at (23, 25) expected 255 but got 0
FAIL Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception The object can not be cloned.
-FAIL Test that transferToImageBitmap without a context throws an exception assert_throws: function "function () { offscreenCanvas.transferToImageBitmap(); }" did not throw
+PASS Test that transferToImageBitmap without a context throws an exception
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt (253098 => 253099)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/offscreen-canvas/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.w-expected.txt 2019-12-04 11:53:59 UTC (rev 253099)
@@ -1,12 +1,12 @@
Harness Error (FAIL), message = DataCloneError: The object can not be cloned.
-FAIL Test that transferToImageBitmap returns an ImageBitmap with correct width and height in a worker assert_unreached: error Reached unreachable code
-FAIL Test that transferToImageBitmap returns an ImageBitmap with correct color in a worker Type error
-FAIL Test that call transferToImageBitmap twice returns an ImageBitmap with correct color in a worker Type error
-FAIL Test that call transferToImageBitmap twice on a alpha-disabled context returns an ImageBitmap with correct color in a worker Type error
+PASS Test that transferToImageBitmap returns an ImageBitmap with correct width and height in a worker
+PASS Test that transferToImageBitmap returns an ImageBitmap with correct color in a worker
+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: property 3, expected 255 but got 0
PASS Test that transferToImageBitmap won't change context's property in a worker
-FAIL Test that call transferToImageBitmap preserves transform in a worker Type error
+FAIL Test that call transferToImageBitmap preserves transform in a worker assert_array_equals: property 1, expected 255 but got 0
FAIL Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception in a worker assert_unreached: error Reached unreachable code
-FAIL Test that call transferToImageBitmap without a context throws an exception in a worker assert_true: expected true got undefined
+PASS Test that call transferToImageBitmap without a context throws an exception in a worker
Modified: trunk/Source/WebCore/ChangeLog (253098 => 253099)
--- trunk/Source/WebCore/ChangeLog 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/ChangeLog 2019-12-04 11:53:59 UTC (rev 253099)
@@ -1,3 +1,26 @@
+2019-12-04 Zan Dobersek <[email protected]> and Chris Lord <[email protected]>
+
+ Implement OffscreenCanvas.transferToImageBitmap
+ https://bugs.webkit.org/show_bug.cgi?id=202572
+
+ Reviewed by Antti Koivisto.
+
+ No new tests. Covered by existing tests.
+
+ * html/CanvasBase.cpp:
+ (WebCore::CanvasBase::setImageBuffer const):
+ * html/CanvasBase.h:
+ * html/OffscreenCanvas.cpp:
+ (WebCore::OffscreenCanvas::size const):
+ (WebCore::OffscreenCanvas::setSize):
+ (WebCore::requiresAcceleratedCompositingForWebGL):
+ (WebCore::shouldEnableWebGL):
+ (WebCore::OffscreenCanvas::isWebGLType):
+ (WebCore::OffscreenCanvas::createContextWebGL):
+ (WebCore::OffscreenCanvas::getContext):
+ * html/OffscreenCanvas.h:
+ * html/OffscreenCanvas.idl:
+
2019-12-04 Tim Horton <[email protected]>
Introduce a GPU process
Modified: trunk/Source/WebCore/html/CanvasBase.cpp (253098 => 253099)
--- trunk/Source/WebCore/html/CanvasBase.cpp 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/html/CanvasBase.cpp 2019-12-04 11:53:59 UTC (rev 253099)
@@ -182,12 +182,13 @@
return context && context->callTracingActive();
}
-void CanvasBase::setImageBuffer(std::unique_ptr<ImageBuffer>&& buffer) const
+std::unique_ptr<ImageBuffer> CanvasBase::setImageBuffer(std::unique_ptr<ImageBuffer>&& buffer) const
{
+ std::unique_ptr<ImageBuffer> returnBuffer;
{
auto locker = holdLock(m_imageBufferAssignmentLock);
m_contextStateSaver = nullptr;
- m_imageBuffer = WTFMove(buffer);
+ returnBuffer = std::exchange(m_imageBuffer, WTFMove(buffer));
}
if (m_imageBuffer && m_size != m_imageBuffer->internalSize())
@@ -201,16 +202,17 @@
if (context && m_imageBuffer && previousMemoryCost != m_imageBufferCost)
InspectorInstrumentation::didChangeCanvasMemory(*context);
- if (!m_imageBuffer)
- return;
+ if (m_imageBuffer) {
+ m_imageBuffer->context().setShadowsIgnoreTransforms(true);
+ m_imageBuffer->context().setImageInterpolationQuality(defaultInterpolationQuality);
+ m_imageBuffer->context().setStrokeThickness(1);
+ m_contextStateSaver = makeUnique<GraphicsContextStateSaver>(m_imageBuffer->context());
- m_imageBuffer->context().setShadowsIgnoreTransforms(true);
- m_imageBuffer->context().setImageInterpolationQuality(defaultInterpolationQuality);
- m_imageBuffer->context().setStrokeThickness(1);
- m_contextStateSaver = makeUnique<GraphicsContextStateSaver>(m_imageBuffer->context());
+ JSC::JSLockHolder lock(scriptExecutionContext()->vm());
+ scriptExecutionContext()->vm().heap.reportExtraMemoryAllocated(memoryCost());
+ }
- JSC::JSLockHolder lock(scriptExecutionContext()->vm());
- scriptExecutionContext()->vm().heap.reportExtraMemoryAllocated(m_imageBufferCost);
+ return returnBuffer;
}
size_t CanvasBase::activePixelMemory()
Modified: trunk/Source/WebCore/html/CanvasBase.h (253098 => 253099)
--- trunk/Source/WebCore/html/CanvasBase.h 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/html/CanvasBase.h 2019-12-04 11:53:59 UTC (rev 253099)
@@ -110,7 +110,7 @@
virtual void setSize(const IntSize& size) { m_size = size; }
- void setImageBuffer(std::unique_ptr<ImageBuffer>&&) const;
+ std::unique_ptr<ImageBuffer> setImageBuffer(std::unique_ptr<ImageBuffer>&&) const;
virtual bool hasCreatedImageBuffer() const { return false; }
static size_t activePixelMemory();
Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (253098 => 253099)
--- trunk/Source/WebCore/html/OffscreenCanvas.cpp 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp 2019-12-04 11:53:59 UTC (rev 253099)
@@ -114,42 +114,55 @@
return Exception { NotSupportedError };
}
-RefPtr<ImageBitmap> OffscreenCanvas::transferToImageBitmap()
+ExceptionOr<RefPtr<ImageBitmap>> OffscreenCanvas::transferToImageBitmap()
{
if (!m_context)
- return nullptr;
+ return Exception { InvalidStateError };
+ if (is<OffscreenCanvasRenderingContext2D>(*m_context)) {
+ if (!width() || !height())
+ return { RefPtr<ImageBitmap> { nullptr } };
+
+ if (!m_hasCreatedImageBuffer)
+ return { ImageBitmap::create({ ImageBuffer::create(size(), Unaccelerated), true }) };
+
+ auto buffer = takeImageBuffer();
+ if (!buffer)
+ return { RefPtr<ImageBitmap> { nullptr } };
+
+ return { ImageBitmap::create({ WTFMove(buffer), originClean() }) };
+ }
+
#if ENABLE(WEBGL)
- if (!is<WebGLRenderingContext>(*m_context))
- return nullptr;
+ if (is<WebGLRenderingContext>(*m_context)) {
+ auto webGLContext = &downcast<WebGLRenderingContext>(*m_context);
- auto webGLContext = &downcast<WebGLRenderingContext>(*m_context);
+ // FIXME: We're supposed to create an ImageBitmap using the backing
+ // store from this canvas (or its context), but for now we'll just
+ // create a new bitmap and paint into it.
- // FIXME: We're supposed to create an ImageBitmap using the backing
- // store from this canvas (or its context), but for now we'll just
- // create a new bitmap and paint into it.
+ auto imageBitmap = ImageBitmap::create(size());
+ if (!imageBitmap->buffer())
+ return { RefPtr<ImageBitmap> { nullptr } };
- auto imageBitmap = ImageBitmap::create(size());
- if (!imageBitmap->buffer())
- return nullptr;
+ auto* gc3d = webGLContext->graphicsContext3D();
+ gc3d->paintRenderingResultsToCanvas(imageBitmap->buffer());
- auto* gc3d = webGLContext->graphicsContext3D();
- gc3d->paintRenderingResultsToCanvas(imageBitmap->buffer());
+ // FIXME: The transfer algorithm requires that the canvas effectively
+ // creates a new backing store. Since we're not doing that yet, we
+ // need to erase what's there.
- // FIXME: The transfer algorithm requires that the canvas effectively
- // creates a new backing store. Since we're not doing that yet, we
- // need to erase what's there.
+ GC3Dfloat clearColor[4];
+ gc3d->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, clearColor);
+ gc3d->clearColor(0, 0, 0, 0);
+ gc3d->clear(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT);
+ gc3d->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
- GC3Dfloat clearColor[4];
- gc3d->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, clearColor);
- gc3d->clearColor(0, 0, 0, 0);
- gc3d->clear(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT);
- gc3d->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+ return { WTFMove(imageBitmap) };
+ }
+#endif
- return imageBitmap;
-#else
- return nullptr;
-#endif
+ return Exception { NotSupportedError };
}
void OffscreenCanvas::didDraw(const FloatRect& rect)
@@ -177,6 +190,20 @@
setImageBuffer(ImageBuffer::create(size(), Unaccelerated));
}
+std::unique_ptr<ImageBuffer> OffscreenCanvas::takeImageBuffer() const
+{
+ m_hasCreatedImageBuffer = true;
+
+ // 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;
+
+ return setImageBuffer(ImageBuffer::create(size(), Unaccelerated));
+}
+
void OffscreenCanvas::reset()
{
resetGraphicsContextState();
Modified: trunk/Source/WebCore/html/OffscreenCanvas.h (253098 => 253099)
--- trunk/Source/WebCore/html/OffscreenCanvas.h 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/html/OffscreenCanvas.h 2019-12-04 11:53:59 UTC (rev 253099)
@@ -78,7 +78,7 @@
#if ENABLE(WEBGL)
ExceptionOr<OffscreenRenderingContext> getContext(JSC::JSGlobalObject&, RenderingContextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments);
#endif
- RefPtr<ImageBitmap> transferToImageBitmap();
+ ExceptionOr<RefPtr<ImageBitmap>> transferToImageBitmap();
// void convertToBlob(ImageEncodeOptions options);
void didDraw(const FloatRect&) final;
@@ -109,6 +109,8 @@
void setSize(const IntSize&) final;
void createImageBuffer() const final;
+ std::unique_ptr<ImageBuffer> takeImageBuffer() const;
+
void reset();
std::unique_ptr<CanvasRenderingContext> m_context;
Modified: trunk/Source/WebCore/html/OffscreenCanvas.idl (253098 => 253099)
--- trunk/Source/WebCore/html/OffscreenCanvas.idl 2019-12-04 09:58:21 UTC (rev 253098)
+++ trunk/Source/WebCore/html/OffscreenCanvas.idl 2019-12-04 11:53:59 UTC (rev 253099)
@@ -53,7 +53,7 @@
attribute [EnforceRange] unsigned long height;
[CallWith=GlobalObject, MayThrowException] OffscreenRenderingContext? getContext(OffscreenRenderingContextType contextType, any... arguments);
- ImageBitmap transferToImageBitmap();
+ [MayThrowException] ImageBitmap transferToImageBitmap();
// Promise<Blob> convertToBlob(optional ImageEncodeOptions options);
};