Diff
Modified: trunk/LayoutTests/ChangeLog (277023 => 277024)
--- trunk/LayoutTests/ChangeLog 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/LayoutTests/ChangeLog 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1,3 +1,19 @@
+2021-05-05 Sam Weinig <[email protected]>
+
+ Add preliminary support for specifying a color space for 2D canvas
+ https://bugs.webkit.org/show_bug.cgi?id=225286
+
+ Reviewed by Dean Jackson.
+
+ Add basic tests for color space in canvas support.
+
+ * fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled-expected.txt: Added.
+ * fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled.html: Added.
+ * fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled-expected.txt: Added.
+ * fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled.html: Added.
+ * fast/canvas/canvas-color-space-display-p3-expected.html: Added.
+ * fast/canvas/canvas-color-space-display-p3.html: Added.
+
2021-05-05 Chris Lord <[email protected]>
Update WPT OffscreenCanvas tests to respect [EnforceRange]
Added: trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled-expected.txt (0 => 277024)
--- trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled-expected.txt 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,12 @@
+Test that the colorSpace member of CanvasRenderingContext2DSettings is unsupported when CanvasColorSpaceEnabled=false.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testSettings.colorSpace is undefined.
+PASS testSettings.colorSpace is undefined.
+PASS testSettings.colorSpace is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled.html (0 => 277024)
--- trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled.html 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,23 @@
+<!-- webkit-test-runner [ CanvasColorSpaceEnabled=false ] -->
+<html>
+ <script src=""
+</head>
+<body>
+<script>
+ description("Test that the colorSpace member of CanvasRenderingContext2DSettings is unsupported when CanvasColorSpaceEnabled=false.");
+
+ function testColorSpaceUnsupported(settings, expectedColorSpace) {
+ let canvas = document.createElement("canvas");
+ let context = canvas.getContext("2d", settings);
+ window.testSettings = context.getContextAttributes();
+ shouldBeUndefined("testSettings.colorSpace");
+ }
+
+ testColorSpaceUnsupported(undefined);
+ testColorSpaceUnsupported({ colorSpace: "srgb" });
+ testColorSpaceUnsupported({ colorSpace: "foo" });
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled-expected.txt (0 => 277024)
--- trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled-expected.txt 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,12 @@
+Test that the colorSpace member of CanvasRenderingContext2DSettings is supported.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testSettings.colorSpace is "srgb"
+PASS testSettings.colorSpace is "srgb"
+PASS document.createElement("canvas").getContext("2d", { colorSpace: "foo" }) threw exception TypeError: Type error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled.html (0 => 277024)
--- trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled.html 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,27 @@
+<html>
+ <script src=""
+</head>
+<body>
+<script>
+ description("Test that the colorSpace member of CanvasRenderingContext2DSettings is supported.");
+
+ function testColorSpace(settings, expectedColorSpace) {
+ let canvas = document.createElement("canvas");
+ let context = canvas.getContext("2d", settings);
+ window.testSettings = context.getContextAttributes();
+ shouldBeEqualToString("testSettings.colorSpace", "srgb");
+ }
+
+ // Test default value of colorSpace is "srgb".
+ testColorSpace(undefined, "srgb");
+
+ // Test setting colorSpace to "srgb" works.
+ testColorSpace({ colorSpace: "srgb" }, "srgb");
+
+ // Test setting colorSpace to an unsupported value.
+ shouldThrowErrorName(`document.createElement("canvas").getContext("2d", { colorSpace: "foo" })`, "TypeError")
+</script>
+
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3-expected.html (0 => 277024)
--- trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3-expected.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3-expected.html 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,7 @@
+<style>
+ .ref { background-color: #009900; width: 100px; height: 100px; margin-bottom: 0; }
+</style>
+<body>
+ <p>This test passes if the square below looks to be all one color</p>
+ <div class="ref"> </div>
+</body>
Added: trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3.html (0 => 277024)
--- trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-color-space-display-p3.html 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,17 @@
+<style>
+ .ref { background-color: #009900; width: 100px; height: 50px; margin-bottom: 0; }
+</style>
+<body>
+ <p>This test passes if the square below looks to be all one color</p>
+ <div class="ref"> </div>
+ <canvas id="test" width="100" height="50"></canvas>
+ <script>
+ let canvas = document.getElementById("test");
+ let context = canvas.getContext("2d", { colorSpace: "display-p3" });
+
+ context.beginPath();
+ context.rect(0, 0, 100, 50);
+ context.fillStyle = "color(display-p3 0.26374 0.59085 0.16434)";
+ context.fill();
+ </script>
+</body>
Modified: trunk/Source/WTF/ChangeLog (277023 => 277024)
--- trunk/Source/WTF/ChangeLog 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WTF/ChangeLog 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1,3 +1,15 @@
+2021-05-05 Sam Weinig <[email protected]>
+
+ Add preliminary support for specifying a color space for 2D canvas
+ https://bugs.webkit.org/show_bug.cgi?id=225286
+
+ Reviewed by Dean Jackson.
+
+ Add new experimental feature, CanvasColorSpaceEnabled, which blocks
+ access to the new ability to specify color spaces for 2D canvas.
+
+ * Scripts/Preferences/WebPreferencesExperimental.yaml:
+
2021-05-04 Alex Christensen <[email protected]>
Don't iterate NetworkProcessProxy::m_websiteDataStores
Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml (277023 => 277024)
--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml 2021-05-05 16:36:55 UTC (rev 277024)
@@ -245,6 +245,18 @@
"ENABLE(EXPERIMENTAL_FEATURES) && (PLATFORM(GTK) || PLATFORM(WPE))": true
default: false
+CanvasColorSpaceEnabled:
+ type: bool
+ humanReadableName: "Canvas Color Spaces"
+ humanReadableDescription: "Enable use of predefined canvas color spaces"
+ defaultValue:
+ WebKitLegacy:
+ default: false
+ WebKit:
+ default: false
+ WebCore:
+ default: false
+
CaptureVideoInGPUProcessEnabled:
type: bool
humanReadableName: "GPU Process: Video Capture"
Modified: trunk/Source/WebCore/CMakeLists.txt (277023 => 277024)
--- trunk/Source/WebCore/CMakeLists.txt 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/CMakeLists.txt 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1067,6 +1067,7 @@
html/canvas/OffscreenCanvasRenderingContext2D.idl
html/canvas/PaintRenderingContext2D.idl
html/canvas/Path2D.idl
+ html/canvas/PredefinedColorSpace.idl
html/track/AudioTrack.idl
html/track/AudioTrackList.idl
Modified: trunk/Source/WebCore/ChangeLog (277023 => 277024)
--- trunk/Source/WebCore/ChangeLog 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/ChangeLog 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1,3 +1,84 @@
+2021-05-05 Sam Weinig <[email protected]>
+
+ Add preliminary support for specifying a color space for 2D canvas
+ https://bugs.webkit.org/show_bug.cgi?id=225286
+
+ Reviewed by Dean Jackson.
+
+ Tests: fast/canvas/CanvasRenderingContext2DSettings-colorSpace-disabled.html
+ fast/canvas/CanvasRenderingContext2DSettings-colorSpace-enabled.html
+ fast/canvas/canvas-color-space-display-p3.html
+
+ * CMakeLists.txt:
+ * DerivedSources-input.xcfilelist:
+ * DerivedSources-output.xcfilelist:
+ * DerivedSources.make:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ Add new files.
+
+ * html/canvas/CanvasRenderingContext2DSettings.idl:
+ * html/canvas/CanvasRenderingContext2DSettings.h:
+ Add a new setting blocked member to the CanvasRenderingContext2DSettings
+ dictionary for specifying a color space.
+
+ * html/canvas/PredefinedColorSpace.cpp: Added.
+ * html/canvas/PredefinedColorSpace.h: Added.
+ * html/canvas/PredefinedColorSpace.idl: Added.
+ Add a new IDL enumeration to represent the possible color spaces supported.
+ For ports that don't support DisplayP3, trying to use it will result in
+ type error from JS.
+
+ * html/HTMLCanvasElement.cpp:
+ (WebCore::HTMLCanvasElement::reset):
+ Add checks for color space and pixel format to 2d context reset optimation.
+ This can happen if the image buffer is allocated prior to the context being
+ requested (such as via canvas.toDataURL() or canvas.toBlob()).
+
+ (WebCore::HTMLCanvasElement::createImageBuffer const):
+ Pass the correct color space and pixel format (though
+ the later is always BGRA8 at the moment) to the ImageBuffer
+ create function to make a backing store in the right format.
+
+ * html/HTMLVideoElement.cpp:
+ (WebCore::HTMLVideoElement::createBufferForPainting const):
+ * html/HTMLVideoElement.h:
+ Pass color space and pixel format through to ensure the helper
+ buffer matches the correct color space.
+
+ * html/ImageBitmap.cpp:
+ (WebCore::ImageBitmap::createPromise):
+ Pass the existing defaults to HTMLVideoElement::createBufferForPainting.
+ In the future, ImageBitmap will also gain color space and pixel
+ format specificity and this will be updated.
+
+ * html/canvas/CanvasRenderingContext.cpp:
+ (WebCore::CanvasRenderingContext::pixelFormat const):
+ (WebCore::CanvasRenderingContext::colorSpace const):
+ * html/canvas/CanvasRenderingContext.h:
+ Add virtual base implementations of colorSpace and pixelFormat
+ which CanvasRenderingContext2D can override to return the
+ values specified in the CanvasRenderingContext2DSettings.
+
+ * html/canvas/CanvasRenderingContext2D.h:
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::fontProxy const):
+ Fix incorrect formatting.
+
+ (WebCore::CanvasRenderingContext2D::pixelFormat const):
+ (WebCore::CanvasRenderingContext2D::colorSpace const):
+ Add overrides, return m_settings.colorSpace for colorSpace.
+
+ * html/canvas/CanvasRenderingContext2DBase.cpp:
+ (WebCore::CanvasRenderingContext2DBase::drawImage):
+ (WebCore::CanvasRenderingContext2DBase::createCompositingBuffer):
+ (WebCore::CanvasRenderingContext2DBase::createPattern):
+ (WebCore::CanvasRenderingContext2DBase::drawTextUnchecked):
+ Pass along the colorSpace and pixelFormat when creating buffers.
+
+ * html/shadow/DateTimeSymbolicFieldElement.cpp:
+ Add missing includes that are now needed.
+
2021-05-05 Philippe Normand <[email protected]>
[GStreamer][WebRTC] Wrap incoming audio buffers, complying with fastMalloc restrictions
Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (277023 => 277024)
--- trunk/Source/WebCore/DerivedSources-input.xcfilelist 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1098,6 +1098,7 @@
$(PROJECT_DIR)/html/canvas/OffscreenCanvasRenderingContext2D.idl
$(PROJECT_DIR)/html/canvas/PaintRenderingContext2D.idl
$(PROJECT_DIR)/html/canvas/Path2D.idl
+$(PROJECT_DIR)/html/canvas/PredefinedColorSpace.idl
$(PROJECT_DIR)/html/canvas/WebGL2RenderingContext.idl
$(PROJECT_DIR)/html/canvas/WebGLActiveInfo.idl
$(PROJECT_DIR)/html/canvas/WebGLBuffer.idl
Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (277023 => 277024)
--- trunk/Source/WebCore/DerivedSources-output.xcfilelist 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1642,6 +1642,8 @@
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPositionOptions.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPostMessageOptions.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPostMessageOptions.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPredefinedColorSpace.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSPredefinedColorSpace.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProcessingInstruction.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProcessingInstruction.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSProgressEvent.cpp
Modified: trunk/Source/WebCore/DerivedSources.make (277023 => 277024)
--- trunk/Source/WebCore/DerivedSources.make 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/DerivedSources.make 2021-05-05 16:36:55 UTC (rev 277024)
@@ -959,6 +959,7 @@
$(WebCore)/html/canvas/OffscreenCanvasRenderingContext2D.idl \
$(WebCore)/html/canvas/PaintRenderingContext2D.idl \
$(WebCore)/html/canvas/Path2D.idl \
+ $(WebCore)/html/canvas/PredefinedColorSpace.idl \
$(WebCore)/html/canvas/WebGL2RenderingContext.idl \
$(WebCore)/html/canvas/WebGLActiveInfo.idl \
$(WebCore)/html/canvas/WebGLBuffer.idl \
Modified: trunk/Source/WebCore/Sources.txt (277023 => 277024)
--- trunk/Source/WebCore/Sources.txt 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/Sources.txt 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1345,6 +1345,7 @@
html/canvas/PaintRenderingContext2D.cpp
html/canvas/Path2D.cpp
html/canvas/PlaceholderRenderingContext.cpp
+html/canvas/PredefinedColorSpace.cpp
html/canvas/WebGL2RenderingContext.cpp
html/canvas/WebGLBuffer.cpp
html/canvas/WebGLColorBufferFloat.cpp
@@ -3368,6 +3369,7 @@
JSPositionErrorCallback.cpp
JSPositionOptions.cpp
JSPostMessageOptions.cpp
+JSPredefinedColorSpace.cpp
JSProcessingInstruction.cpp
JSProgressEvent.cpp
JSPromiseRejectionEvent.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277023 => 277024)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-05 16:36:55 UTC (rev 277024)
@@ -14321,6 +14321,9 @@
BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScheduledAction.cpp; sourceTree = "<group>"; };
BCA378BB0D15F64200B793D6 /* ScheduledAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScheduledAction.h; sourceTree = "<group>"; };
BCA55912263DBD79007F19B3 /* PixelFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PixelFormat.h; sourceTree = "<group>"; };
+ BCA5591A263F10B9007F19B3 /* PredefinedColorSpace.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PredefinedColorSpace.h; sourceTree = "<group>"; };
+ BCA5591C263F10B9007F19B3 /* PredefinedColorSpace.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PredefinedColorSpace.idl; sourceTree = "<group>"; };
+ BCA5591D263F10B9007F19B3 /* PredefinedColorSpace.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PredefinedColorSpace.cpp; sourceTree = "<group>"; };
BCA83E360D7CDC4E003421A8 /* DataTransfer.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DataTransfer.idl; sourceTree = "<group>"; };
BCA83E4D0D7CE1E9003421A8 /* JSDataTransfer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDataTransfer.cpp; sourceTree = "<group>"; };
BCA83E4E0D7CE1E9003421A8 /* JSDataTransfer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDataTransfer.h; sourceTree = "<group>"; };
@@ -20179,6 +20182,9 @@
7C193BB41F5E0EB70088F3E6 /* Path2D.idl */,
7C7903BA1F86FF3300463A70 /* PlaceholderRenderingContext.cpp */,
7C7903BC1F86FF3400463A70 /* PlaceholderRenderingContext.h */,
+ BCA5591D263F10B9007F19B3 /* PredefinedColorSpace.cpp */,
+ BCA5591A263F10B9007F19B3 /* PredefinedColorSpace.h */,
+ BCA5591C263F10B9007F19B3 /* PredefinedColorSpace.idl */,
D3F3D35B1A69A5060059FC2B /* WebGL2RenderingContext.cpp */,
D3F3D35C1A69A5060059FC2B /* WebGL2RenderingContext.h */,
D3F3D35D1A69A5060059FC2B /* WebGL2RenderingContext.idl */,
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -622,7 +622,7 @@
IntSize newSize(w, h);
// If the size of an existing buffer matches, we can just clear it instead of reallocating.
// This optimization is only done for 2D canvases for now.
- if (m_hasCreatedImageBuffer && oldSize == newSize && m_context && m_context->is2d()) {
+ if (m_hasCreatedImageBuffer && oldSize == newSize && m_context && m_context->is2d() && buffer() && m_context->colorSpace() == buffer()->colorSpace() && m_context->pixelFormat() == buffer()->pixelFormat()) {
if (!m_didClearImageBuffer)
clearImageBuffer();
return;
@@ -957,8 +957,15 @@
auto renderingMode = shouldAccelerate(size()) ? RenderingMode::Accelerated : RenderingMode::Unaccelerated;
// FIXME: Add a new setting for DisplayList drawing on canvas.
auto useDisplayList = m_usesDisplayListDrawing.valueOr(document().settings().displayListDrawingEnabled()) ? ShouldUseDisplayList::Yes : ShouldUseDisplayList::No;
- setImageBuffer(ImageBuffer::create(size(), renderingMode, useDisplayList, RenderingPurpose::Canvas, 1, DestinationColorSpace::SRGB, PixelFormat::BGRA8, hostWindow));
+ auto [colorSpace, pixelFormat] = [&] {
+ if (m_context)
+ return std::pair { m_context->colorSpace(), m_context->pixelFormat() };
+ return std::pair { DestinationColorSpace::SRGB, PixelFormat::BGRA8 };
+ }();
+
+ setImageBuffer(ImageBuffer::create(size(), renderingMode, useDisplayList, RenderingPurpose::Canvas, 1, colorSpace, pixelFormat, hostWindow));
+
if (buffer() && buffer()->drawingContext())
buffer()->drawingContext()->setTracksDisplayListReplay(m_tracksDisplayListReplay);
Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/HTMLVideoElement.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -281,11 +281,11 @@
renderer->updateFromElement();
}
-RefPtr<ImageBuffer> HTMLVideoElement::createBufferForPainting(const FloatSize& size, RenderingMode renderingMode) const
+RefPtr<ImageBuffer> HTMLVideoElement::createBufferForPainting(const FloatSize& size, RenderingMode renderingMode, DestinationColorSpace colorSpace, PixelFormat pixelFormat) const
{
auto* hostWindow = document().view() && document().view()->root() ? document().view()->root()->hostWindow() : nullptr;
auto shouldUseDisplayList = document().settings().displayListDrawingEnabled() ? ShouldUseDisplayList::Yes : ShouldUseDisplayList::No;
- return ImageBuffer::create(size, renderingMode, shouldUseDisplayList, RenderingPurpose::MediaPainting, 1, DestinationColorSpace::SRGB, PixelFormat::BGRA8, hostWindow);
+ return ImageBuffer::create(size, renderingMode, shouldUseDisplayList, RenderingPurpose::MediaPainting, 1, colorSpace, pixelFormat, hostWindow);
}
void HTMLVideoElement::paintCurrentFrameInContext(GraphicsContext& context, const FloatRect& destRect)
Modified: trunk/Source/WebCore/html/HTMLVideoElement.h (277023 => 277024)
--- trunk/Source/WebCore/html/HTMLVideoElement.h 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/HTMLVideoElement.h 2021-05-05 16:36:55 UTC (rev 277024)
@@ -38,6 +38,8 @@
class RenderVideo;
class PictureInPictureObserver;
+enum class DestinationColorSpace : uint8_t;
+enum class PixelFormat : uint8_t;
enum class RenderingMode : bool;
class HTMLVideoElement final : public HTMLMediaElement, public Supplementable<HTMLVideoElement> {
@@ -70,7 +72,7 @@
void webkitRequestFullscreen() override;
#endif
- RefPtr<ImageBuffer> createBufferForPainting(const FloatSize&, RenderingMode) const;
+ RefPtr<ImageBuffer> createBufferForPainting(const FloatSize&, RenderingMode, DestinationColorSpace, PixelFormat) const;
// Used by canvas to gain raw pixel access
void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/ImageBitmap.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -502,7 +502,9 @@
auto sourceRectangle = maybeSourceRectangle.releaseReturnValue();
auto outputSize = outputSizeForSourceRectangle(sourceRectangle, options);
- auto bitmapData = video->createBufferForPainting(outputSize, bufferRenderingMode);
+
+ // FIXME: Add support for color spaces / pixel formats to ImageBitmap.
+ auto bitmapData = video->createBufferForPainting(outputSize, bufferRenderingMode, DestinationColorSpace::SRGB, PixelFormat::BGRA8);
if (!bitmapData) {
resolveWithBlankImageBuffer(scriptExecutionContext, !taintsOrigin(scriptExecutionContext.securityOrigin(), *video), WTFMove(promise));
return;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,11 +28,13 @@
#include "CachedImage.h"
#include "CanvasPattern.h"
+#include "ColorSpace.h"
#include "HTMLCanvasElement.h"
#include "HTMLImageElement.h"
#include "HTMLVideoElement.h"
#include "Image.h"
#include "ImageBitmap.h"
+#include "PixelFormat.h"
#include "SecurityOrigin.h"
#include <wtf/HashSet.h>
#include <wtf/IsoMallocInlines.h>
@@ -80,6 +82,16 @@
m_canvas.derefCanvasBase();
}
+PixelFormat CanvasRenderingContext::pixelFormat() const
+{
+ return PixelFormat::BGRA8;
+}
+
+DestinationColorSpace CanvasRenderingContext::colorSpace() const
+{
+ return DestinationColorSpace::SRGB;
+}
+
bool CanvasRenderingContext::wouldTaintOrigin(const CanvasPattern* pattern)
{
if (m_canvas.originClean() && pattern && !pattern->originClean())
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2021-05-05 16:36:55 UTC (rev 277024)
@@ -42,6 +42,8 @@
class ImageBitmap;
class TypedOMCSSImageValue;
class WebGLObject;
+enum class DestinationColorSpace : uint8_t;
+enum class PixelFormat : uint8_t;
class CanvasRenderingContext : public ScriptWrappable {
WTF_MAKE_NONCOPYABLE(CanvasRenderingContext);
@@ -86,6 +88,9 @@
virtual bool needsPreparationForDisplay() const { return false; }
virtual void prepareForDisplay() { }
+ virtual PixelFormat pixelFormat() const;
+ virtual DestinationColorSpace colorSpace() const;
+
protected:
explicit CanvasRenderingContext(CanvasBase&);
bool wouldTaintOrigin(const CanvasPattern*);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -37,6 +37,7 @@
#include "CSSPropertyNames.h"
#include "CSSPropertyParserHelpers.h"
#include "CSSPropertyParserWorkerSafe.h"
+#include "ColorSpace.h"
#include "Gradient.h"
#include "ImageBuffer.h"
#include "ImageData.h"
@@ -43,6 +44,7 @@
#include "InspectorInstrumentation.h"
#include "NodeRenderStyle.h"
#include "Path2D.h"
+#include "PixelFormat.h"
#include "RenderTheme.h"
#include "RenderWidget.h"
#include "ResourceLoadObserver.h"
@@ -211,7 +213,8 @@
return measureTextInternal(textRun);
}
-auto CanvasRenderingContext2D::fontProxy() -> const FontProxy* {
+auto CanvasRenderingContext2D::fontProxy() -> const FontProxy*
+{
// Intentionally don't update style here, because updating style can cause JS to run synchronously.
// This function is called in the middle of processing, and running arbitrary JS in the middle of processing can cause unexpected behavior.
// Instead, the relevant canvas entry points update style once when they begin running, and we won't touch the style after that.
@@ -243,4 +246,15 @@
drawTextUnchecked(textRun, x, y, fill, maxWidth);
}
+PixelFormat CanvasRenderingContext2D::pixelFormat() const
+{
+ // FIXME: Take m_settings.alpha into account here and add PixelFormat::BGRX8.
+ return PixelFormat::BGRA8;
+}
+
+DestinationColorSpace CanvasRenderingContext2D::colorSpace() const
+{
+ return toDestinationColorSpace(m_settings.colorSpace);
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2021-05-05 16:36:55 UTC (rev 277024)
@@ -61,6 +61,9 @@
bool is2d() const final { return true; }
const FontProxy* fontProxy() final;
+ PixelFormat pixelFormat() const final;
+ DestinationColorSpace colorSpace() const final;
+
void setFontWithoutUpdatingStyle(const String&);
void drawTextInternal(const String& text, float x, float y, bool fill, Optional<float> maxWidth = WTF::nullopt);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1643,7 +1643,7 @@
repaintEntireCanvas = true;
} else if (state().globalComposite == CompositeOperator::Copy) {
if (&sourceCanvas == &canvasBase()) {
- if (auto copy = buffer->copyRectToBuffer(srcRect, DestinationColorSpace::SRGB, *c)) {
+ if (auto copy = buffer->copyRectToBuffer(srcRect, colorSpace(), *c)) {
clearCanvas();
c->drawImageBuffer(*copy, dstRect, { { }, srcRect.size() }, { state().globalComposite, state().globalBlend });
}
@@ -1829,7 +1829,7 @@
RefPtr<ImageBuffer> CanvasRenderingContext2DBase::createCompositingBuffer(const IntRect& bufferRect)
{
- return ImageBuffer::create(bufferRect.size(), isAccelerated() ? RenderingMode::Accelerated : RenderingMode::Unaccelerated, 1, DestinationColorSpace::SRGB, PixelFormat::BGRA8);
+ return ImageBuffer::create(bufferRect.size(), isAccelerated() ? RenderingMode::Accelerated : RenderingMode::Unaccelerated, 1, colorSpace(), pixelFormat());
}
void CanvasRenderingContext2DBase::compositeBuffer(ImageBuffer& buffer, const IntRect& bufferRect, CompositeOperator op)
@@ -2026,7 +2026,7 @@
#endif
auto renderingMode = !drawingContext() || drawingContext()->isAcceleratedContext() ? RenderingMode::Accelerated : RenderingMode::Unaccelerated;
- auto imageBuffer = videoElement.createBufferForPainting(size(videoElement), renderingMode);
+ auto imageBuffer = videoElement.createBufferForPainting(size(videoElement), renderingMode, colorSpace(), pixelFormat());
if (!imageBuffer)
return nullptr;
@@ -2490,7 +2490,7 @@
}
};
- if (c->clipToDrawingCommands(maskRect, DestinationColorSpace::SRGB, WTFMove(paintMaskImage)) == GraphicsContext::ClipToDrawingCommandsResult::FailedToCreateImageBuffer)
+ if (c->clipToDrawingCommands(maskRect, colorSpace(), WTFMove(paintMaskImage)) == GraphicsContext::ClipToDrawingCommandsResult::FailedToCreateImageBuffer)
return;
drawStyle.applyFillColor(*c);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h 2021-05-05 16:36:55 UTC (rev 277024)
@@ -25,10 +25,13 @@
#pragma once
+#include "PredefinedColorSpace.h"
+
namespace WebCore {
struct CanvasRenderingContext2DSettings {
bool desynchronized { false };
+ PredefinedColorSpace colorSpace { PredefinedColorSpace::SRGB };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.idl (277023 => 277024)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.idl 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.idl 2021-05-05 16:36:55 UTC (rev 277024)
@@ -30,4 +30,5 @@
// FIXME: Add support for 'alpha'.
// boolean alpha = true;
boolean desynchronized = false;
+ [EnabledBySetting=CanvasColorSpace] PredefinedColorSpace colorSpace = "srgb";
};
Copied: trunk/Source/WebCore/html/canvas/PredefinedColorSpace.cpp (from rev 277023, trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h) (0 => 277024)
--- trunk/Source/WebCore/html/canvas/PredefinedColorSpace.cpp (rev 0)
+++ trunk/Source/WebCore/html/canvas/PredefinedColorSpace.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PredefinedColorSpace.h"
+
+#include "ColorSpace.h"
+
+namespace WebCore {
+
+DestinationColorSpace toDestinationColorSpace(PredefinedColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case PredefinedColorSpace::SRGB:
+ return DestinationColorSpace::SRGB;
+#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
+ case PredefinedColorSpace::DisplayP3:
+ return DestinationColorSpace::DisplayP3;
+#endif
+ }
+
+ ASSERT_NOT_REACHED();
+ return DestinationColorSpace::SRGB;
+}
+
+}
Copied: trunk/Source/WebCore/html/canvas/PredefinedColorSpace.h (from rev 277023, trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h) (0 => 277024)
--- trunk/Source/WebCore/html/canvas/PredefinedColorSpace.h (rev 0)
+++ trunk/Source/WebCore/html/canvas/PredefinedColorSpace.h 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/EnumTraits.h>
+
+namespace WebCore {
+
+enum class DestinationColorSpace : uint8_t;
+
+enum class PredefinedColorSpace {
+ SRGB
+#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
+ , DisplayP3
+#endif
+};
+
+DestinationColorSpace toDestinationColorSpace(PredefinedColorSpace);
+
+}
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::PredefinedColorSpace> {
+ using values = EnumValues<
+ WebCore::PredefinedColorSpace,
+ WebCore::PredefinedColorSpace::SRGB
+#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
+ , WebCore::PredefinedColorSpace::DisplayP3
+#endif
+ >;
+};
+
+} // namespace WTF
Copied: trunk/Source/WebCore/html/canvas/PredefinedColorSpace.idl (from rev 277023, trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DSettings.h) (0 => 277024)
--- trunk/Source/WebCore/html/canvas/PredefinedColorSpace.idl (rev 0)
+++ trunk/Source/WebCore/html/canvas/PredefinedColorSpace.idl 2021-05-05 16:36:55 UTC (rev 277024)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace
+enum PredefinedColorSpace {
+ "srgb"
+#if defined(ENABLE_DESTINATION_COLOR_SPACE_DISPLAY_P3) && ENABLE_DESTINATION_COLOR_SPACE_DISPLAY_P3
+ , "display-p3"
+#endif
+};
Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp (277023 => 277024)
--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -29,7 +29,9 @@
#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+#include "EventNames.h"
#include "FontCascade.h"
+#include "KeyboardEvent.h"
#include "RenderBlock.h"
#include "RenderStyle.h"
#include <wtf/IsoMallocInlines.h>
Modified: trunk/Tools/ChangeLog (277023 => 277024)
--- trunk/Tools/ChangeLog 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Tools/ChangeLog 2021-05-05 16:36:55 UTC (rev 277024)
@@ -1,3 +1,14 @@
+2021-05-05 Sam Weinig <[email protected]>
+
+ Add preliminary support for specifying a color space for 2D canvas
+ https://bugs.webkit.org/show_bug.cgi?id=225286
+
+ Reviewed by Dean Jackson.
+
+ * DumpRenderTree/TestOptions.cpp:
+ (WTR::TestOptions::defaults):
+ Add CanvasColorSpaceEnabled for windows.
+
2021-05-05 Chris Dumez <[email protected]>
Unreviewed, reverting r276985.
Modified: trunk/Tools/DumpRenderTree/TestOptions.cpp (277023 => 277024)
--- trunk/Tools/DumpRenderTree/TestOptions.cpp 2021-05-05 16:33:23 UTC (rev 277023)
+++ trunk/Tools/DumpRenderTree/TestOptions.cpp 2021-05-05 16:36:55 UTC (rev 277024)
@@ -133,10 +133,11 @@
{ "AsyncClipboardAPIEnabled", false },
{ "AttachmentElementEnabled", false },
{ "CSSContainmentEnabled", false },
+ { "CSSCounterStyleAtRuleImageSymbolsEnabled", false },
{ "CSSCounterStyleAtRulesEnabled", false },
- { "CSSCounterStyleAtRuleImageSymbolsEnabled", false },
{ "CSSLogicalEnabled", false },
{ "CSSOMViewSmoothScrollingEnabled", false },
+ { "CanvasColorSpaceEnabled", true },
{ "ColorFilterEnabled", false },
{ "ContactPickerAPIEnabled", false },
{ "CoreMathMLEnabled", false },