haikuwebkit/LayoutTests/fast/canvas/canvas-color-space-display-...

18 lines
599 B
HTML
Raw Permalink Normal View History

Add preliminary support for specifying a color space for 2D canvas https://bugs.webkit.org/show_bug.cgi?id=225286 Reviewed by Dean Jackson. Source/WebCore: 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. Source/WTF: Add new experimental feature, CanvasColorSpaceEnabled, which blocks access to the new ability to specify color spaces for 2D canvas. * Scripts/Preferences/WebPreferencesExperimental.yaml: Tools: * DumpRenderTree/TestOptions.cpp: (WTR::TestOptions::defaults): Add CanvasColorSpaceEnabled for windows. LayoutTests: 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. Canonical link: https://commits.webkit.org/237338@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277024 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-05 16:36:55 +00:00
<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>